 function email(str) {
	    var error = "";
  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){  
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	
	
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	
	
		       error = "Invalid E-mail\n";
		   return error;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	

		     error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){	 
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	

		      error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){	
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	

		   error = "Invalid E-mail\n";
		   return error;
		 }
		
		 if (str.indexOf(" ")!=-1){
		     error = "Invalid E-mail\n";
		document.getElementById("emailadd").style.backgroundColor = '#d9e2f1';	

		   return error;
		 }

		   return error; 
}

function validate_contactform() {
var reason = "";


	reason += email(document.contactform.emailadd.value);
	reason += validatefirstName();	
  	reason += validatesurname();
	reason += validatehometel();
	reason += validatemobtel();
	reason += validateaddress();
	reason += validatecompany();
	reason += validatecontactTime();
	reason += validatecontactNo();
  	reason += validateenquiry();
	
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
else
{
   document.contactform.submit();
   }


}
function validatefirstName() {
    var error = "";
 
    if (document.contactform.firstName.value == "") 
	{	
		document.getElementById("firstName").style.backgroundColor = '#d9e2f1';
        error = "Please specify your first name.\n";
    } 
    return error;  

}
function validatesurname() {
    var error = "";
 
    if (document.contactform.surname.value == "") 
	{	
		document.getElementById("surname").style.backgroundColor = '#d9e2f1';
        error = "Please specify your surname.\n";
    } 
    return error;  
	
	
}

function validatehometel() {
    var error = "";
 
    if (document.contactform.hometel.value == "") 
	{	
		document.getElementById("hometel").style.backgroundColor = '#d9e2f1';
        error = "Please specify your home telephone number.\n";
    } 
    return error;  
	
	
}

function validatemobtel() {
    var error = "";
 
    if (document.contactform.mobtel.value == "") 
	{	
		document.getElementById("mobtel").style.backgroundColor = '#d9e2f1';
        error = "Please specify your mobile telephone number.\n";
    } 
    return error;  
	
	
}

function validateaddress() {
    var error = "";
 
    if (document.contactform.address.value == "") 
	{	
		document.getElementById("address").style.backgroundColor = '#d9e2f1';
        error = "Please specify your address.\n";
    } 
    return error;  
	
	
}

function validatecompany() {
    var error = "";
 
    if (document.contactform.company.value == "") 
	{	
		document.getElementById("company").style.backgroundColor = '#d9e2f1';
        error = "Please specify your company.\n";
    } 
    return error;  
	
	
}
function validatecontactTime() {
    var error = "";
 
    if (document.contactform.contactTime.value == "") 
	{	
		document.getElementById("contactTime").style.backgroundColor = '#d9e2f1';
        error = "Please specify your prefered contact time.\n";
    } 
    return error;  
		
}

function validatecontactNo() {
    var error = "";
 
    if (document.contactform.contactNo.value == "Please Select") 
	{	
		document.getElementById("contactNo").style.backgroundColor = '#d9e2f1';
        error = "Please specify your prefered contact method.\n";
    } 
    return error;  
		
}


function validateenquiry() {
    var error = "";
 
    if (document.contactform.enquiry.value == "") 
	{	
		document.getElementById("enquiry").style.backgroundColor = '#d9e2f1';
        error = "Please specify your message.\n";
    } 
    return error;  
}
	 
//function validatecheck() {
//    var error = "";
// 
// if (document.form.checkbox.checked == false)
//    {
//        document.getElementById("checkbox").style.backgroundColor = '#d9e2f1';	
//		error= "Please accept the Terms and Conditons\n";
//   
//    } 
//    return error;  
//}	

