function processContact(obj){
	
	document.getElementById("success_message").style.display = "none";	
	document.getElementById("error_message").style.display = "none";	
	
	var representative = obj.representative;
	var company = obj.company;
	var email = obj.email;
	
	var title = obj.title;
	var state = obj.state;
	var city = obj.city;
	
	var country = obj.country;
	var phone = obj.phone;
	var notes = obj.notes;

	
	if(representative.value.trim() == ''){
		errshowDiv('representative');
		representative.focus();
		return;
	}
	errhideDiv('representative');
	
	if(company.value.trim() == ''){
		errshowDiv('company');
		company.focus();
		return;
	}
	errhideDiv('company');	
	
	if(email.value.trim() == ''){
		errshowDiv('email');
		email.focus();
		return;
	}else if(!emailAddresscheck(email.value)){
		alert("Please provide valid email address.");
		email.focus();
		return;
	}
	errhideDiv('email');	
	
	var postdata = "representative="+representative.value;
	postdata += "&company="+company.value;
	postdata += "&city="+city.value;
	postdata += "&state="+state.value;
	postdata += "&country="+country.value;
	postdata += "&email="+email.value;
	postdata += "&phone="+phone.value;
	postdata += "&notes="+notes.value;
	
	doRequest("../index.php?action=contact","POST",postdata,_contact_handle);
}

function _contact_handle(){
	 if((http.readyState == 4)&&(http.status == 200)){
		var response = http.responseText;	
		if(response == 1){
			document.getElementById("success_message").style.display = "";	
			document.getElementById("contactForm").style.display = "none";	
			document.getElementById("welcome_note").style.display = "none";	
		}else if(response == 2){
			document.getElementById("error_message").style.display = "";	
		}
	 }
}


function emailAddresscheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ 
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		
		return false
	 }

	 return true					
}

function errhideDiv(divid){
	document.getElementById("sp_"+divid).style.display = "none";
}

function errshowDiv(divid){
	document.getElementById("sp_"+divid).style.display = "";
}
