function ScrollToElement(id) {
	var myDiv = document.getElementById('scrollarea');
	var scrollToObj = document.getElementById(id);

	var ver = getInternetExplorerVersion();
	if (ver > -1) {
		if (ver >= 8.0)
			myDiv.scrollTop = scrollToObj.offsetTop - 110;
		else
			myDiv.scrollTop = scrollToObj.offsetTop;
		}
	else {
		myDiv.scrollTop = scrollToObj.offsetTop - 110;
		}
}


function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function getInternetExplorerVersion() {
	var rv = -1; // Return value assumes failure.    
	if (navigator.appName == 'Microsoft Internet Explorer') {        
		var ua = navigator.userAgent;        
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");        
		if (re.exec(ua) != null) 
			rv = parseFloat(RegExp.$1);    
		}    
	
	return rv;
}

function getElementsByClassName(needle) { 
   var my_array = document.getElementsByTagName("*"); 
   var retvalue = new Array(); 
   var i; 
   var j; 

   for (i=0,j=0;i<my_array.length;i++) { 
      var c = " " + my_array[i].className + " "; 
      if (c.indexOf(" " + needle + " ") != -1) retvalue[j++] = my_array[i]; 
   } 
   return retvalue; 
} 

function unSelectAllColours() 
{ 
   var divs = getElementsByClassName('colouroptionselected') 
   for(i=0; i <divs.length;i++) 
   { 
      if(divs[i].className == 'colouroptionselected') 
      { 
         divs[i].className = 'colouroption'; 
      } 
   } 
   //alert(classname); 
} 

function selectColour(id){
    var selObj = document.getElementById(id);
    selObj.className = 'colouroptionselected'
    }

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;


if (keycode == 13)
   {
   myField.Form.submit();
   }
}

function redirectToListingsDD(qsString, formObject){
    var selObj = document.getElementById(formObject);
    var intValue = selObj.options[selObj.selectedIndex].value;
    if(intValue>0){
        window.location.href = 'listing.asp?'+qsString+'='+intValue
        }
    else{
        alert('Please choose a brand');
        }
    }
    
function popupWindow(URL, Name, width, height) {
    window.open(URL, Name, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height)
}

function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  
  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();
  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);
  // Overseas Territories
  pcexp.push (/^([A-Z]{4})(\s*)(1ZZ)$/i);
  // Load up the string to check
  var postCode = toCheck;
  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      // Load new postcode back into the form element
      valid = true;     
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid) {return postCode;} else return false;
}


function postcodeRedirect(TextboxName){
    
    var strValue = document.getElementById(TextboxName).value;

    if (checkPostCode(strValue)) {
        window.location.href='postcode.asp?postcode='+strValue
        } 
    else {
        alert ("Postcode has invalid format")
        }
    }


function postit(Postcode){ //check postcode format is valid
 test = Postcode; 
 size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {
  test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {
  test = test.substr(0,size-1);size = test.length
  }
 document.details.pcode.value = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  document.details.pcode.focus();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   document.details.pcode.focus();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   document.details.pcode.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.details.pcode.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.details.pcode.focus();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   document.details.pcode.focus();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   document.details.pcode.focus();
   return false;
  }
return true;
}
//  End -->
    
function showPostcodeWarning(){
    alert('THIS PRODUCT IS ONLY AVAILABLE TO CERTAIN POSTCODES.\nPLEASE ENTER YOUR POSTCODE IN THE BOX ON THE LEFT TO\nCHECK YOU CAN HAVE THIS PRODUCT DELIVERED TO YOU');
    }
    
function clearTextBoxDefaultValue(id, defaultValue){
    var strValue = document.getElementById(id).value;
    
    if(strValue==defaultValue){
        document.getElementById(id).value = '';
        }
    }

function checkSearchBlank(){
    var myString = trim(document.searchForm.search.value);
    if (myString.length<3){
        alert('Please enter a minimum of 3 characters in the product search.');
        if(myString.length==0){
            document.searchForm.search.value = '';
            }
        else{
            document.searchForm.search.value = myString;
            }
        return false;
        }
    }

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}


function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseEnter (element, evt) {
  if (element.contains && evt.fromElement) {
    return !element.contains(evt.fromElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}

function showMiniBasket(){
    var basketDiv = document.getElementById('minicart');
    if(basketDiv.style.display=='none'){
        basketDiv.style.display = 'block'
    }  
}

function hideMiniBasket(){   
    var basketDiv = document.getElementById('minicart');
    if(basketDiv.style.display=='block'){
        basketDiv.style.display = 'none'
    } 
}

function brandDDRedirect(){
    selObj = document.getElementById('ddlBrandId');
    if(selObj.options[0].selected!=true){
        window.location.href=selObj.options[selObj.selectedIndex].value;
        }
}

function catSearchRedirect(){
    var selObj
    
    // Check Collection DD
    selObj = document.getElementById('csColID');
    if(selObj.options[0].selected!=true){
        window.location.href=selObj.options[selObj.selectedIndex].value;
        }

    // Check Sub Cat DD
    selObj = document.getElementById('csSubCatID');
    if(selObj.options[0].selected!=true){
        window.location.href=selObj.options[selObj.selectedIndex].value;
        }

    // Check Colour DD
    selObj = document.getElementById('csColourID');
	if(selObj==null) {
	    selObj = document.getElementById('csSizeID');
		}
    if(selObj.options[0].selected!=true){
        window.location.href=selObj.options[selObj.selectedIndex].value;
        }
}

function catSearchReset(ElementID){
    var selObj = document.getElementById(ElementID);
	if(selObj!=null){
		selObj.options[0].selected = true;   
		//selObj.className = 'dropdowngrey';
		selObj.disabled=true;
	}
}

function catSearchResetAll() {
    var selObj = document.getElementById('csColID');
    selObj.options[0].selected = true;  
	selObj.disabled=false;

	selObj = document.getElementById('csSubCatID');
    selObj.options[0].selected = true;  
	selObj.disabled=false;

	selObj = document.getElementById('csColourID');
	if(selObj!=null){
		selObj.options[0].selected = true;  
		selObj.disabled=false;
	}
	
	selObj = document.getElementById('csSizeID');
	if(selObj!=null){
		selObj.options[0].selected = true;  
		selObj.disabled=false;
	}
}

function setSearchResetOnLoad() {
	var ddCat = document.getElementById('csSubCatID');
	var ddColour = document.getElementById('csColourID');

	if(ddColour==null){
		ddColour = document.getElementById('csSizeID');
		}
		
	var ddCollection = document.getElementById('csColID');
	
	if(ddCat.selectedIndex>0){
			catSearchReset('csColourID')
			catSearchReset('csSizeID')
			catSearchReset('csColID')
		}
	else if(ddColour.selectedIndex>0){
			catSearchReset('csSubCatID')
			catSearchReset('csColID')
		}
	else if(ddCollection.selectedIndex>0){
			catSearchReset('csSubCatID')
			catSearchReset('csColourID')
			catSearchReset('csSizeID')
		}
	}

<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->