function contact_form_submit_new(){

if (document.getElementById('firstname').value =="" || document.getElementById('lastname').value =="" || document.getElementById('email').value =="" || document.getElementById('phone').value =="" ){
alert("You forgot a required field.");
return;
}else{

if (document.thecontactform.custentity_client_interested_in.selectedIndex==0){
alert("Please select an interest.");
}else{

if (echeck(document.getElementById('email').value)!=false){
 
 if (document.thecontactform.custentity_referred_by.selectedIndex==0){
	document.thecontactform.custentity_referred_by.selectedIndex=2;
	document.thecontactform.custentity_referred_by.value="2";
	document.thecontactform.submit();
	//clearfields()
	}else{
  	document.thecontactform.submit();
	//clearfields()
	}
}
}
}

}
function clearfields(){
alert("Thank you for your inquiry. An Office Evolution representative will contact you shortly.");
document.getElementById('firstname').value =""; 
document.getElementById('lastname').value =""; 
document.getElementById('email').value =""; 
document.getElementById('phone').value =""; 
document.getElementById('zipcode').value =""; 
document.getElementById('comments').value ="";
document.getElementById('companyname').value ="";
document.thecontactform.custentity_client_interested_in.selectedIndex=0;
document.thecontactform.custentity_referred_by.selectedIndex=0;
document.getElementById('themessage').style.display="block";

}
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 email address. Please re-enter email addrress.")
return false
}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

if (str.indexOf(" ")!=-1){
alert("Invalid email address. Please re-enter email addrress.")
return false
}

return true					
}
