var httpe = false;
if(navigator.appName == "Microsoft Internet Explorer") {
  httpe = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  httpe = new XMLHttpRequest();
}

function show999()
{
	document.getElementById('s999').style.top = document.getElementById('imgdp').offsetTop -495 + "px";
    document.getElementById('s999').style.left = document.getElementById('imgdp').offsetLeft - 365 + "px";
	document.getElementById('s999').style.display="";
}
function close999()
{
	document.getElementById('s999').style.display="none";
}
function showTab(id)
{
	for(var i=1;i<=2;i++)
	{
		eval("document.getElementById('emi"+i+"')").style.display="none";
		eval("document.getElementById('emititle"+i+"')").className="plus"+i;
	}
	
	eval("document.getElementById('emi"+id+"')").style.display="";
	eval("document.getElementById('emititle"+id+"')").className="plus"+id+"on";
}
function doValidate()
{
	tbname=document.frm1.tbName.value;
	tbEmail=document.frm1.tbEmail.value;
	tbmobile=document.frm1.tbMobile.value;	
	add=document.frm1.tbAddress.value;
	if (tbname=="")
	{
	alert("Enter your name")
	document.frm1.tbName.focus();   
	return false;
	}  
 
	if(tbEmail== "" )
	{
		alert("Please Enter Your Email");
		document.frm1.tbEmail.focus();		
		return false;
	}
	else
	{
		elen= tbEmail.length;
		efirstchar = tbEmail.substring(0, 1);
		elastchar  = tbEmail.substring(elen-1, elen);

		atPos = tbEmail.indexOf("@",1)	
		if (atPos == -1) 
		{
			alert("Enter valid Email Id");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("@",atPos+1) != -1) 
		{
			alert("Enter valid Email Id");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select(); 
			return false;
		}
		periodPos = tbEmail.indexOf(".",atPos)
		if (periodPos == -1) 
		{	
			alert("Enter valid Email Id");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (periodPos+3 > elen)	
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("..",1) != -1)
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("@.",1) != -1) 
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf(".@",1) != -1)
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("-@",1) != -1)
	 	{
		 	alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("@-",1) != -1)
	 	{
		 	alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("-.",1) != -1)
	 	{
		 	alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf(".-",1) != -1)
	 	{
		 	alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}
		if (tbEmail.indexOf("--",1) != -1)
		{
		 	alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}        
		if((efirstchar<"a" || efirstchar>"z") && (efirstchar<"A" || efirstchar>"Z"))
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();
			return false;
		}

		if((elastchar<"a" || elastchar>"z") && (elastchar<"A" || elastchar>"Z"))
		{
			alert("Enter valid EmailId");
			document.frm1.tbEmail.focus();
			document.frm1.tbEmail.select();	
			return false;
		}

    	for (var i = 1; i < elen; i++)
		{
			var ch = tbEmail.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && (ch != "@") && (ch != ".") && (ch !="-"))
			{	
				alert("Enter valid EmailId");
				document.frm1.tbEmail.focus();
				document.frm1.tbEmail.select();
				return false;
			}
		}
	}	

	if (tbmobile=="")
	{
	alert("Enter your phone number")
	document.frm1.tbMobile.focus();    
	return false;
	} 

	var params="id="+Math.random() + "&tbname="+ escape(encodeURI(tbname)) +"&tbemail=" + escape(encodeURI(tbEmail)) + "&tbmobile=" + escape(encodeURI(tbmobile)) + "&txtAdd=" + escape(encodeURI(add)) + "&emi=" + escape(encodeURI("1"));
	httpe.open('POST','/test-ride-handler.asp',true);
	httpe.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	httpe.setRequestHeader("Content-length", params.length);
	httpe.setRequestHeader("Connection", "close");

	    httpe.onreadystatechange = function() {
	      if(httpe.readyState == 4)      
	      alert(httpe.responseText);
		  document.frm1.reset();
		  close999();
	};
    httpe.send(params);
	return false;
}

