function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function isValidName(val) {
	 validRegExp = /^[a-zA-Z ]+$/i;
   // search email text for regular exp matches
   val = trim(val);
    if (val.search(validRegExp) == -1) {
      return false;
    } 
    return true; 	
}
function isValidEmail(strEmail){
  validRegExp = /^[\w\.-]+@[a-z,A-Z,0-9-]+[\.]{1}[a-zA-Z]{2,}[[\.]?[a-zA-Z]{0,2}$/i;
   // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) {
      return false;
    } 
    return true; 
}
document.write('<script type="text/javascript" src="imat/jscript/jquery.js"></script>'); 
//var xmlhttp = new XMLHttpRequest();
var str='';

function validateContact(){
	var result_ajax = '';
	var email 	 = document.contact.email.value;
	var name 	 = document.contact.name.value;
	
	var phone 	 = document.contact.phone.value;
	var address	 = document.contact.address.value;
	var fax	 = document.contact.fax.value;
	var comments = escape(document.contact.comments.value);
	var flag = true;
	document.getElementById('email_err').innerHTML ='';
	document.getElementById('name_err').innerHTML ='';	
	//document.getElementById('hphone_err').innerHTML ='';
	if (!isValidName(name)  && name.length == 0){
		document.getElementById('name_err').innerHTML='Invalid Name';
		flag = false;
	}

	if (!isValidEmail(email) || email.length<3) {
		document.getElementById('email_err').innerHTML=' Invalid Email';
		flag = false;
	}
	/*if (hphone.length>1){
		if(hphone.length<6 || !isValidPhone(hphone)) {
		document.getElementById('hphone_err').innerHTML='Invalid Phone No.';
		flag = false;
		}
	}*/
	
	if (flag) {
		
		querystring ="email="+email+"&name="+name+"&address="+address+"&fax="+fax+"&comments="+comments+"&phone="+phone;
		url= 'contactus.php?option=contactus&'+querystring;	
		
		$.ajax({
		   type: "POST",
		   url: url,
		   data: querystring,
		   success: function(mytext){
			   	document.contact.reset();
				document.getElementById("contact_us").innerHTML = mytext;
		   }
		 });
	}
	return false;
}
/*function httpcontactchange(){	
	if (xmlhttp.readyState == 4){
		mytext = xmlhttp.responseText;
		document.contact.reset();
		document.getElementById("contact_us").innerHTML = mytext;
		mytext="";
	}
}
*/

