/**
 * DHTML email validation script.
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID");
		   return false;;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    return false;
		 }

 		 return true	;				
	}

function ValidateForm(){
	var first_name = document.contactform.first_name;
	var last_name = document.contactform.last_name;
	var phone = document.contactform.phone;
	var emailID=document.contactform.email_address;
	var websites = document.contactform.websites;
	var expectation = document.contactform.expectation;
	var service = document.contactform.service;
	//alert('hi');return false;
	if((first_name.value==null)||(first_name.value=="")){
		alert("Please Enter your First Name");
		first_name.focus();
		return false;
	}
	if((last_name.value==null)||(last_name.value=="")){
		alert("Please Enter your Last Name");
		last_name.focus();
		return false;
	}
	if(((phone.value==null) || (phone.value==""))){
		alert("Please Enter your phone number");
		phone.focus();
		return false;
	}
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.focus();
		return false;
	}
	if((websites.value==null)||(websites.value=="")){
		alert("Please Enter your website(s)");
		websites.focus();
		return false;
	}
	if((expectation.value==null)||(expectation.value=="")){
		alert("Please describe what you expect from Search Engine Marketing");
		expectation.focus();
		return false;
	}
	var form = document.contactform;
	var count = 0;
	for(var i = 0; i < form.elements.length; i++) {
            if(form.elements[i].type == "checkbox" && form.elements[i].checked == false){
		count++;
            }

    	}

	if(count == 7) {
		alert('Please select at least one services you are interested in');
		return false;
	}
	
	return true; 
 }
