// JavaScript Document
loadimg = '<div align="center"><img src="http://imgs.indiaautomobile.com/ajax-loader.gif"></div>';

function namecheck(obj)
{
	if (IsEmpty(obj,'text'))
	{alert("Please enter your name.");obj.focus();return false;}

	if(!ValidateNo(obj.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{alert("Special characters are not allowed.");obj.focus();return false;}
	
	return true;
}

function mailidcheck(obj1)
{		
	if (IsEmpty(obj1,'text'))
	{alert("Please enter your email ID.");obj1.focus();return false;}
	
	if (!(IsEmpty(obj1,'text')))
	{	
		if(emailCheck(obj1.value)==false)
		{
			alert ("Please enter a valid email ID.");obj1.focus();return false;
		}
	}
	return true;
}


var http;
function getHTTPObject() {
	var xmlhttp;
	try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} 
	catch (e) {
		try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} 
		catch (E) {xmlhttp = false;}
	}	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {xmlhttp = new XMLHttpRequest();} 
		catch (e) {xmlhttp = false;}
	}
	return xmlhttp;
}

function contactinfo()
{
	http = new getHTTPObject();
	if (IsEmpty(document.frm_continfo.contname,'text'))
	{alert("Please enter your name.");document.frm_continfo.contname.focus();return false;}

	if(!ValidateNo(document.frm_continfo.contname.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{alert("Special characters are not allowed.");document.frm_continfo.contname.focus();return false;}
		
	if (IsEmpty(document.frm_continfo.contphone,'text'))
	{alert("Please enter your mobile number.");document.frm_continfo.contphone.focus();return false;}
	
	if (!ValidateNo(document.frm_continfo.contphone.value,"1234567890"))
		{alert("The mobile number typed is incorrect.");document.frm_continfo.contphone.focus();return false;}
	
	var mob = document.frm_continfo.contphone.value;
	if(mob.length < 10 || mob<9000000000)
	{alert("The mobile number typed is incorrect.");document.frm_continfo.contphone.focus();return false;}
	
	if (IsEmpty(document.frm_continfo.contemail,'text'))
	{alert("Please enter your email ID.");document.frm_continfo.contemail.focus();return false;}
	
	if (!(IsEmpty(document.frm_continfo.contemail,'text')))
	{	
		if(emailCheck(document.frm_continfo.contemail.value)==false)
		{
			alert ("Please enter a valid email ID.");document.frm_continfo.contemail.focus();return false;
		}
	}

	datapack = "option=site&page=enquiryinfo&pop=1&notemplate=yes"+
		"&contname="+document.frm_continfo.contname.value+
		"&contphone="+document.frm_continfo.contphone.value+
		"&contemail="+document.frm_continfo.contemail.value+
		"&toemail="+document.frm_continfo.toemail.value+
		"&strmakesms="+document.frm_continfo.strmakesms.value+
		"&strmodelsms="+document.frm_continfo.strmodelsms.value+
		"&posteddate="+document.frm_continfo.posteddate.value+
		"&listingid="+document.frm_continfo.listingid.value+
		"&username="+document.frm_continfo.username.value+
		"&strusertype="+document.frm_continfo.strusertype.value+
		"&phstring="+document.frm_continfo.phstring.value;

	var urltoget = "index.php?"+datapack;
	document.getElementById("contdiv").innerHTML = loadimg ;
	if (http){
		http.open("POST", urltoget, true);
		http.send("s=1");
		http.onreadystatechange = handleinfo;
	}

	return false;
}

function handleinfo(){
	if (http.readyState == 4){
		if (http.responseText.indexOf("!@#@!") != -1)
		{
			txtsep = http.responseText.split("!@#@!");
			document.getElementById("msgdiv").style.display ="";
			document.getElementById("msgdiv").innerHTML = txtsep[0] ;
			document.getElementById("contdiv").style.display = "none";
			document.getElementById("contdiv").innerHTML = txtsep[1] ;
			document.getElementById('rundealthanks1').src="index.php?option=listing&page=afterleadlogin&notemplate=yes";
			setTimeout("divmessage()",5000);
		}
		else
		{
			document.getElementById("emaildiv").innerHTML = http.responseText;
			document.getElementById("msgdiv").style.display = "none";
		}
	}
}
function divmessage(){
	document.getElementById("msgdiv").style.display = "none";
	document.getElementById("contdiv").style.display = "";
	collapse1.slideit();
}
	
function emailseller(frm_email)
{
	http = new getHTTPObject();
	var obj=frm_email.strname;
	if(!namecheck(obj)){return false};
	var obj1=frm_email.stremail;
	if(!mailidcheck(obj1)){return false};

	if(IsEmpty(frm_email.strephone,'text') && IsEmpty(frm_email.stremobile,'text') && IsEmpty(frm_email.strestd,'text'))
	{alert("Please enter any one of your contact numbers.");frm_email.strestd.focus();return false;}

    if (!IsEmpty(frm_email.strephone,'text') || !IsEmpty(frm_email.strestd,'text'))
	     {
		if (!IsEmpty(frm_email.strestd,'text'))
		{
		if (!ValidateNo(frm_email.strestd.value,"1234567890"))
		{alert("This STD Code does not exist.");frm_email.strestd.focus();return false;}

		var stcod=frm_email.strestd.value;
			
		if (stcod.length<2 || stcod<10)
		{alert("This STD Code does not exist.");frm_email.strestd.focus();return false;}
		} 
		
		if (IsEmpty(frm_email.strestd,'text'))
		{
		alert ("Please enter your STD Code.");
		frm_email.strestd.focus();
		return false;
		}

		if (!ValidateNo(frm_email.strephone.value,"1234567890"))
		{alert("Invalid phone number.");frm_email.strephone.focus();return false;}
		var lancod=frm_email.strephone.value;
		
		if((stcod.length+lancod.length) != 10)
		 {
			alert("The number you have typed is inappropriate for the STD Code entered.");frm_email.strephone.focus();return false;
		 }

	}
	
	if (!IsEmpty(frm_email.stremobile,'text'))
	{
		if (!ValidateNo(frm_email.stremobile.value,"1234567890"))
		{alert("The mobile number typed is incorrect.");frm_email.stremobile.focus();return false;}
		var mobno=frm_email.stremobile.value;
		
		if (mobno<9000000000 || mobno.length<10)
		{ alert("The mobile number typed is incorrect.");frm_email.stremobile.focus(); return false;}
	}
	
	if (IsEmpty(frm_email.txteqmsg,'textarea'))
	{alert("Please enter your message.");frm_email.txteqmsg.focus();return false;}
	
	if (IsEmpty(frm_email.randword,'text'))
	{alert("Please enter the verification code.");frm_email.randword.focus();return false;}
	
	datapack = "option=site&page=enquirymail_ajax&pop=1&notemplate=yes"+
		"&strname="+frm_email.strname.value+
		"&stremail="+frm_email.stremail.value+
		"&strestd="+frm_email.strestd.value+
		"&toemail="+frm_email.toemail.value+
		"&strephone="+frm_email.strephone.value+
		"&seccode="+frm_email.seccode.value+
		"&stremobile="+frm_email.stremobile.value+
		"&randword="+frm_email.randword.value+
		"&username="+frm_email.username.value+
		"&listingid="+frm_email.listingid.value+
		"&txteqmsg="+frm_email.txteqmsg.value;
	var urltoget = "index.php?"+datapack;
	document.getElementById("emaildiv").innerHTML =loadimg;
	if (http){
		http.open("POST", urltoget, true);
		http.send("z=1");
		http.onreadystatechange = handleinfo1;
	}
	return false;
}

function handleinfo1(){
	if (http.readyState == 4){
		if (http.responseText.indexOf("!@#@!") != -1)
		{
			txtsep = http.responseText.split("!@#@!");
			document.getElementById("msgdiv1").style.display ="";
			document.getElementById("msgdiv1").innerHTML = txtsep[0] ;
			document.getElementById("emaildiv").style.display = "none";
			document.getElementById("emaildiv").innerHTML = txtsep[1] ;
			document.getElementById('rundealthanks1').src="index.php?option=listing&page=afterleadlogin&notemplate=yes";
			setTimeout("divmessage1()",5000);
		}
		else
		{
			document.getElementById("emaildiv").innerHTML = http.responseText;
			document.getElementById("msgdiv1").style.display = "none";
		}
	}
}
function divmessage1(){
	document.getElementById("msgdiv1").style.display = "none";
	document.getElementById("emaildiv").style.display = "";
	collapse2.slideit();
}


function smsseller(frm_sms)
{
	http=new getHTTPObject();

	var obj=frm_sms.strsname;
	if(!namecheck(obj)){return false};
	var obj1=frm_sms.strsmail;
	if(!mailidcheck(obj1)){return false};

	/*
	if (IsEmpty(frm_sms.smsname,'text'))
	{alert("Please enter your name.");frm_sms.smsname.focus();return false;}

	if(!ValidateNo(frm_sms.smsname.value,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "))
	{alert("Special characters are not allowed.");frm_sms.smsname.focus();return false;}
		
	if (IsEmpty(frm_sms.smsemail,'text'))
	{alert("Please enter your email ID.");frm_sms.smsemail.focus();return false;}
	
	if (!(IsEmpty(frm_sms.smsemail,'text')))
	{	
		if(emailCheck(frm_sms.smsemail.value)==false)
		{
			alert ("Please enter a valid email ID.");frm_sms.smsemail.focus();return false;
		}
	}
	*/

	if(IsEmpty(frm_sms.strsphone,'text') && IsEmpty(frm_sms.strsmobile,'text') && IsEmpty(frm_sms.strsstd,'text'))
	{alert("Please enter any one of your contact numbers.");frm_sms.strsstd.focus();return false;}

    if (!IsEmpty(frm_sms.strsphone,'text') || !IsEmpty(frm_sms.strsstd,'text'))
	     {
		if (!IsEmpty(frm_sms.strsstd,'text'))
		{
		if (!ValidateNo(frm_sms.strsstd.value,"1234567890"))
		{alert("This STD Code does not exist.");frm_sms.strsstd.focus();return false;}

		var stcod=frm_sms.strsstd.value;
			
		if (stcod.length<2 || stcod<10)
		{alert("This STD Code does not exist.");frm_sms.strsstd.focus();return false;}
		} 
		
		if (IsEmpty(frm_sms.strsstd,'text'))
		{
		alert ("Please enter your STD Code.");
		frm_sms.strsstd.focus();
		return false;
		}

		if (!ValidateNo(frm_sms.strsphone.value,"1234567890"))
		{alert("Invalid phone number.");frm_sms.strsphone.focus();return false;}
		var lancod=frm_sms.strsphone.value;
		
		if((stcod.length+lancod.length) != 10)
		 {
			alert("The number you have typed is inappropriate for the STD Code entered.");frm_sms.strsphone.focus();return false;
		 }

	}
	
	if (!IsEmpty(frm_sms.strsmobile,'text'))
	{
		if (!ValidateNo(frm_sms.strsmobile.value,"1234567890"))
		{alert("The mobile number typed is incorrect.");frm_sms.strsmobile.focus();return false;}
		var mobno=frm_sms.strsmobile.value;
		
		if (mobno<9000000000 || mobno.length<10)
		{ alert("The mobile number typed is incorrect.");frm_sms.strsmobile.focus(); return false;}
	}
	
	if (IsEmpty(frm_sms.smsmessage,'textarea'))
	{alert("Please enter your message.");frm_sms.smsmessage.focus();return false;}
	
	if (IsEmpty(frm_sms.randwordsms,'text'))
	{alert("Please enter the verification code.");frm_sms.randwordsms.focus();return false;}

	datapack = "option=site&page=enquirysms&pop=1&notemplate=yes"+
		"&strsname="+frm_sms.strsname.value+
		"&strsmail="+frm_sms.strsmail.value+
		"&strsstd="+frm_sms.strsstd.value+
		"&toemail="+frm_sms.toemail.value+
		"&seccodesms="+frm_sms.seccodesms.value+
		"&strsphone="+frm_sms.strsphone.value+
		"&strsmobile="+frm_sms.strsmobile.value+
		"&username="+frm_sms.username.value+
		"&tomobileno="+frm_sms.tomobileno.value+
		"&randwordsms="+frm_sms.randwordsms.value+
		"&listingid="+frm_sms.listingid.value+
		"&smsmessage="+frm_sms.smsmessage.value;
	document.getElementById("smsdiv").innerHTML = loadimg ;
	var urltoget = "index.php?"+datapack;
	if (http){
		http.open("POST", urltoget, true);
		http.send("q=1");
		http.onreadystatechange = handleinfo2;
	}
	return false;
}

function handleinfo2(){
	if (http.readyState == 4){

		if (http.responseText.indexOf("!@#@!") != -1)
		{
			txtsep = http.responseText.split("!@#@!");
			document.getElementById("msgdiv2").style.display ="";
			document.getElementById("msgdiv2").innerHTML = txtsep[0] ;
			document.getElementById("smsdiv").style.display = "none";
			document.getElementById("smsdiv").innerHTML = txtsep[1] ;
			document.getElementById('rundealthanks1').src="index.php?option=listing&page=afterleadlogin&notemplate=yes";
			setTimeout("divmessage2()",5000);
		}
		else
		{
			document.getElementById("smsdiv").innerHTML = http.responseText;
			document.getElementById("msgdiv2").style.display = "none";
		}

	}
}
function divmessage2(){
	document.getElementById("msgdiv2").style.display = "none";
	document.getElementById("smsdiv").style.display = "";
	collapse3.slideit();
}

function trimnumber(s)
{
	while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
	document.frm_email.strestd.value = s;
}

function trimnumber1(s)
{
	while (s.substr(0,1) == '0' && s.length>1) { s = s.substr(1,9999); }
	document.frm_sms.strsstd.value = s;
}

function contactincr(listid)
{
	if (document.getElementById("imm1").src.indexOf("images/downgreen.gif") != -1)
	{
		http=new getHTTPObject();
		var urltoget = "index.php?option=listing&page=viewlisting_contactincrement&notemplate=yes&listingid="+listid;
		if (http){
			http.open("POST", urltoget, true);
			http.send("w=1");
			http.onreadystatechange = handlecontincr;
		}
	}
}

function handlecontincr()
{
	if (http.readyState == 4){
		return true;
	}
}


function EnableDisableAll(frm,Opt){
//if(!frm) return;

	if(!Opt) Opt=0;
	for(var i=0; i<frm.elements.length; i++){
		frm.elements[i].disabled = Opt;
	}
}

function callpage(listid, module, hideownerdet, hidefeatopt)
{
	http = new getHTTPObject();
	loadimg = '<div align="center"><img src="http://imgs.indiaautomobile.com/ajax-loader.gif"></div>';
	var urltoget = "index.php?option=listing&page="+module+"&notemplate=yes&listingid="+listid;
	if (http){
		switch (module)
		{
			case 'viewlisting_continfo':
				document.getElementById("contdiv").innerHTML = loadimg;
				if(hideownerdet==0)
					{
					document.getElementById('ownerdet').style.display='none';
					document.getElementById('ownerdet1').style.display='none';
					}
				if(hidefeatopt==0)
					{
					document.getElementById('featopt').style.display='none';
					}
				http.onreadystatechange = handlecont;
				break;
			case 'viewlisting_emailseller':
				document.getElementById("emaildiv").innerHTML = loadimg;
				if(hideownerdet==0)
					{
					document.getElementById('ownerdet').style.display='none';
					document.getElementById('ownerdet1').style.display='none';
					}
				if(hidefeatopt==0)
					{
					document.getElementById('featopt').style.display='none';
					}
				http.onreadystatechange = handleemail;
				break;
			case 'viewlisting_smsseller':
				document.getElementById("smsdiv").innerHTML = loadimg;
				if(hideownerdet==0)
					{
					document.getElementById('ownerdet').style.display='none';
					document.getElementById('ownerdet1').style.display='none';
					}
				if(hidefeatopt==0)
					{
					document.getElementById('featopt').style.display='none';
					}
				http.onreadystatechange = handlesms;
				break;
		}
		http.open("POST", urltoget, true);
		http.send("a=1");
	}
}


function handlecont(){
	if (http.readyState == 4){
			document.getElementById("contdiv").innerHTML = http.responseText;
	}
}

function handleemail(){
	if (http.readyState == 4){
			document.getElementById("emaildiv").innerHTML = http.responseText;
	}
}

function handlesms(){
	if (http.readyState == 4){
			document.getElementById("smsdiv").innerHTML = http.responseText;
	}
}