function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(contactname.value,"Please enter a contact name")==false)
  {contactname.focus();return false;}
  
  if (validate_required(email.value,"Please enter an email address")==false)
  {email.focus();return false;}
  
  if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;}

  if (validate_required(tel.value,"Please enter a telephone number")==false)
  {tel.focus();return false;}
  
  if (validate_required(collection_country.value,"Please enter a collection country")==false)
  {collection_country.focus();return false;}
  
  if (validate_required(destination_country.value,"Please enter a destination country")==false)
  {destination_country.focus();return false;}
  
  //check if they have been left with default text
  if (collection_country.value == "Enter Collection Country")
  {alert("Please enter a collection country");collection_country.focus();return false;}
  
  if (destination_country.value == "Enter Destination Country")
  {alert("Please enter a destination country");destination_country.focus();return false;}
  
  /*
  
  
  if (validate_required(collection_town.value,"Please enter a collection town")==false)
  {collection_town.focus();return false;}
  
  if (validate_required(collection_postcode.value,"Please enter a collection postcode")==false)
  {collection_postcode.focus();return false;}
  
  if (validate_required(destination_country.value,"Please enter a destination country")==false)
  {destination_country.focus();return false;}
  
  if (validate_required(destination_town.value,"Please enter a destination town")==false)
  {destination_town.focus();return false;}
  
  if (validate_required(destination_postcode.value,"Please enter a destination postcode")==false)
  {destination_postcode.focus();return false;}
  
   if (validate_required(ship_details.value,"Please enter the shipment details")==false)
  {ship_details.focus();return false;}
  
  
  if (randomcode.value.substring(0,3) != securitycode.value) {
  	alert("The security code does not match");
  	securitycode.focus();
  	return false;
  }
  */
  if (validate_required(code.value,"Please enter the numbers from the displayed image")==false)
  {code.focus();return false;}  
  
  checkcode(code.value);
  return false;
  
  }
}


function validate_required(field, alerttext) {
	if (field == null || field == "") {
		alert(alerttext);
		return false;
	}
}

function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function ClearInput(value, id){ 
	var input = document.getElementById(id); 
	if(value == input.value){
		input.value = ''; 
	} else {
		input.value = input.value; 
	}
}


var url = '/includes/captcheck.php?code=';
var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed
var result;
        
function getHTTPObject()
{
try {
req = new XMLHttpRequest();
  } catch (err1)
  {
  try {
  req = new ActiveXObject("Msxml12.XMLHTTP");
  } catch (err2)
  {
  try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3)
    {
req = false;
    }
  }
}
return req;
}

var http = getHTTPObject(); // We create the HTTP Object        

function handleHttpResponse() {
if (http.readyState == 4) {
    captchaOK = http.responseText;
    if(captchaOK != 1) {
     		return "fail";
     		return false;
      } else {
      	return "pass";
      	return true;
      }
     
   } else {
  }
}

function checkcode(thecode) {
	http.onreadystatechange = function(){
	if(http.readyState == 4){
		captchaOK = http.responseText;
    	if(captchaOK == 1) {
    		document.getElementById("quickquote").submit();
    	} else {
    		alert('Your security code does not match, please check and try again')
    		return false;
    	}
		}
	}
	http.open("GET", url + escape(thecode), true);
	http.send(null);
}