// JavaScript Document

function validate_contact(){
var why = "";
var show = false;
var feildfocus = false;
boxone=false;boxtwo=false;boxthree=false; boxfour=false;boxfive=false; boxsix=false; 
 if(document.contactUsForm.contact_name.value == ""){
 why+="Please enter the Contact Name\n";
 show = true;
 boxone=true;
 }

if(document.contactUsForm.address.value == ""){
 why+="Please enter your address\n";
 show = true;
 boxtwo=true;
}


if(document.contactUsForm.state.value== ""){
 why+="Please enter a valid state \n";
 show = true;
 boxthree=true;
}


/*
if(document.contactUsForm.post_code.value.length<1 || (CheckPostcode(document.contactUsForm.post_code.value)==false)){
 why+=" Please enter a valid postcode\n";
 show = true;
 boxfour=true;
}



if(CheckPostcode(document.contactUsForm.post_code.value)!="")
*/

if(document.contactUsForm.post_code.value !="")
	{

	if(!CheckPostcode(document.contactUsForm.post_code.value))
	{

 why+=" Please enter a valid postcode\n";
 show = true;
 boxfour=true;
    }
	}




if(document.contactUsForm.country.value== ""){
 why+="Please enter a valid country\n";
 show = true;
 boxfive=true;
}


if(isEmail(document.contactUsForm.email.value)==false){
 why+="Please enter valid Email address\n";
 show = true;
 boxsix=true;
}


if(CheckPostcode(document.contactUsForm.phone_code.value)=='' && CheckPostcode(document.contactUsForm.phone_number.value)==''){
 why+="Please enter valid Phone Number\n";
 show = true;
 boxseven=true;
}

else if(CheckPostcode(document.contactUsForm.phone_code.value)!='' && CheckPostcode(document.contactUsForm.phone_number.value)==''){
 why+="Please enter valid Phone Number\n";
 show = true;
 boxseven=true;
}

else if(CheckPostcode(document.contactUsForm.phone_code.value)=='' && CheckPostcode(document.contactUsForm.phone_number.value)!=''){
 why+="Please enter valid Area Code\n";
 show = true;
 boxseven=true;
}


if(show){
   alert(why);
 

	if(boxseven){
		if(document.contactUsForm.phone_code.value=='') {
   			document.contactUsForm.phone_code.focus();
		} else {
			document.contactUsForm.phone_number.focus();
		}   	
   }
   
  if(boxsix){
   document.contactUsForm.email.focus();}

      if(boxfive){
   document.contactUsForm.country.focus();}
   
    if(boxfour){
   document.contactUsForm.post_code.focus();}
   

     if(boxthree){
   document.contactUsForm.state.focus();} 
 
    if(boxtwo){
   document.contactUsForm.address.focus();}
  
  if(boxone){
   document.contactUsForm.contact_name.focus();}
   
   
   
  return false;
 }

 //document.contactUsForm.submit();
}


function isEmail( strValue) {
 var objRegExp = /^[a-z]\w*([.\-]\w+)*@[a-z]\w*([.\-]\w+)*\.[a-z]{2,3}$/i;
 return objRegExp.test(strValue);
}



function CheckPostcode(TheNumber) {
 var valid = 1
 var GoodChars = "0123456789()-+ "
 var i = 0
 if (TheNumber=="") {
 // Return false if number is empty
 valid = 0
 }
 for (i =0; i <= TheNumber.length -1; i++) {
 if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
 valid = 0
 } // End if statement
 } // End for loop
 return valid
}
