<!--
	function validateSearchForm(){
		//if(document.getElementById("postcode")){		
		if(document.searchForm.postcode){		
			if ( document.getElementById("postcode").value == '' || document.getElementById("postcode").value == 'Postcode' || document.getElementById("postcode").value == 'Your postcode' ) {
				alert('Please enter your postcode. If you do not have a postcode then enter "DE1 2BH" and select "National" as your radius.');
				//document.getElementById("postcode").focus();
				return;
			}
			if (checkPostCode(document.getElementById("postcode").value) == false){
				alert('Please enter a valid Postcode');
				document.getElementById("postcode").focus();
				return;
			}
			else{
				document.getElementById("postcode").value = checkPostCode(document.getElementById("postcode").value);
				document.cookie = "postcode=" + document.getElementById('postcode').value;
			}
		}
		if(document.getElementById("variantsearch")){
			if(document.getElementById("variantsearch").value == 'Variant (e.g. GTI)')
				document.getElementById("variantsearch").value = '';
			if(document.getElementById("keywordsearch").value == 'Keywords (e.g. Black)')
				document.getElementById("keywordsearch").value = '';
		}
		document.searchForm.submit();			
	}

	function setSelectedMakeModel(make, model){
    var options
    var searchForm = document.forms['searchForm'];
    options = searchForm.make;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == make){
        options.selectedIndex = i;
        i = options.length;
      }
    }
		UsedCarPopulateModel(searchForm.make, searchForm.model);

    options = searchForm.model;
    for(i=0; i<options.length; i++){
      if(options.options[i].value == model){
        options.selectedIndex = i;
        i = options.length;
      }
    }

	}
	function removeShowroomAdvert(OrderID, Vendor){
		var cookieName = '';
		var cookieArray = (unescape(document.cookie)).split(';');
		var valuesArray = '';
		var orderArray = '';
		var dealerArray = '';
		
		//Loop around the cookies
		for ( i=0; i<cookieArray.length; i++ ){
			//Get the cookie name
			cookieName = trim(cookieArray[i].substr(0, cookieArray[i].indexOf('=')));
			//Get the OrderID and the Dealer (Unique key)
			var orderValue = cookieArray[i].substr(cookieArray[i].indexOf('OrderID='));
			valuesArray = orderValue.split('&');
			
			if ( valuesArray.length > 1 ){
				orderArray = valuesArray[0].split('=');
				dealerArray = valuesArray[1].split('=');
				if ( orderArray[1] == OrderID)
					deleteCookie(cookieName, '\/', '');
			}						
		}
	}

function checkPostCode (toCheck) {

  // 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 (/^([a-z]{1,2}[0-9]{1,2})(\s*)([0-9]{1}[abdefghjlnpqrstuwxyz]{2})$/i);

  // Expression for postcodes: ANA NAA, and AANA  NAA
  pcexp.push (/^([a-z]{1,2}[0-9]{1}[a-z]{1})(\s*)([0-9]{1}[abdefghjlnpqrstuwxyz]{2})$/i);
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/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 both 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();
      
      // 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;
}

//-->
