	function trim(str) {     
		if(!str || typeof str != 'string')         
		return null;     
		return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); 
	}

	function validateForm(){
	
	var nameField1 = trim(document.getElementById("firstName").value);
	var nameField2 = trim(document.getElementById("lastName").value);
	var mail = trim(document.getElementById("mail").value);
	var phone = trim(document.getElementById("phone").value);
	if(nameField1==null || nameField1.length == 0){
		alert('First Name cannot be left empty');
		return false;
	}
	if(nameField2==null || nameField2.length == 0){
		alert('Last Name cannot be left empty');
		return false;
	}
	if(mail==null || mail.length == 0){
		alert('Email id cannot be left empty');
		return false;
	}
	if(isNaN(phone)){
		alert('Please enter a valid phone number');
		return false;
	}

	if(emailCheck(mail)){
			return true;
		}
		return false;
	}
	
	function emailCheck (emailStr) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	alert("Ths username contains invalid characters.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	alert("Ths domain name contains invalid characters.");
	return false;
	   }
	}
	if (user.match(userPat)==null) {
	alert("The username doesn't seem to be valid.");
	return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	alert("Destination IP address is invalid!");
	return false;
	   }
	}
	return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	alert("The domain name does not seem to be valid.");
	return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("The address must end in a well-known domain or two letter " + "country.");
	return false;
	}
	if (len<2) {
	alert("This address is missing a hostname!");
	return false;
	}

	return true;
	}
	function process(){
	var obj1 = document.getElementById("contactForm");
	obj1.style.visibility="hidden";
	var obj2 = document.getElementById("wait");
	obj2.style.visibility="visible";
	//var obj3 = document.getElementById("mailsent");
	//obj3.style.visibility="visible";
	setTimeout('sendMail()', 2000);

	}
	function sendMail(){
		var object2 = document.getElementById("wait");
		object2.style.visibility="hidden";
		var xmlObj = obtainXmlHttpObj();
		if(xmlObj){
				firstName1	= encodeURIComponent(document.getElementById("firstName").value);
				lastName1 	= encodeURIComponent(document.getElementById("lastName").value);
				phone1 		= encodeURIComponent(document.getElementById("phone").value);
				mail1 		= encodeURIComponent(document.getElementById("mail").value);
				comment 	= encodeURIComponent(document.getElementById("comment").value);
				company 	= encodeURIComponent(document.getElementById("company").value);
				url 		= encodeURIComponent(document.getElementById("url").value);
				subject 	= encodeURIComponent(document.getElementById("subject").value);
				captcha		= document.getElementById("captcha").value;
			xmlObj.onreadystatechange = function(){
											if(xmlObj.readyState == 4){
											var obj1 = document.getElementById("contactForm");
											obj1.style.top="-20px";
											obj1.style.visibility="visible";
											
											
												if(xmlObj.responseText=="1"){
													
													var obj3 = document.getElementById("mailsent");
													obj3.innerHTML="Thank you. An email has been sent to us. We will be contacting you soon.";
													obj3.style.visibility="visible";
													}
												else if(xmlObj.responseText=="2"){
													var obj3 = document.getElementById("mailsent");
													obj3.innerHTML="<span class='error'>Please Type the letters correctly as Shown in the figure.</span>";
													obj3.style.visibility="visible";
													}
													
											}
					}
					xmlObj.open("GET","mailer.php?firstName=" + firstName1 +"&lastName="+ lastName1 + "&phone=" +phone1 + "&mail=" + mail1 +"&comment=" +comment+"&captcha="+captcha+"&company=" +company +"&url=" +url +"&subject=" +subject, true);
				xmlObj.send(null);

			
			
		}
		
	
	}

	function obtainXmlHttpObj(){
	var xmlHttp;
		if(window.ActiveXObject){
			try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				xmlHttp = false;
			}
		}else{
			try{
				xmlHttp=new XMLHttpRequest();
				}catch(e){
					xmlHttp = false;
				}
		}
		if(!xmlHttp)
			alert('Your browser does not support Ajax');
		else
			return xmlHttp;
					
	}
	
	function resetAll(){
		var allinput	=	document.getElementsByTagName('input');
		
		var length	=	allinput.length;
		
		for(i=0;i<length-2;i++)
		allinput[i].value="";
		
		return true;
		
		}