// JavaScript Document
var popup;
function submitfrm2(frm)
{
	if(frm.txtvin.value.split(" ").join("")=="")
	{
		alert("Please enter VIN.");
		frm.txtvin.focus();
		return false;
	}
	//if(frm.txtvin.value.length != 17)
	if(trim(frm.txtvin.value).length!=17)
	{
		alert("Please enter 17 char VIN.");
		frm.txtvin.focus();
		return false;
	}
	if(frm.cboyear.value == 0)
	{
		alert("Please select year.");
		frm.cboyear.focus();
		return false;
	}
 	if(frm.cbomakeid.value == 0)
	{
		alert("Please select make.");
		frm.cbomakeid.focus();
		return false;
	}
	if(frm.cbomodelid.value == 0)
	{
		alert("Please select model.");
		frm.cbomodelid.focus();
		return false;
	}
	if(frm.cbotrimid.value == 0)
	{
		alert("Please select trim.");
		frm.cbotrimid.focus();
		return false;
	}
	if(frm.cbobodystyleid.value == 0)
	{
		alert("Please select bodystyle.");
		frm.cbobodystyleid.focus();
		return false;
	}
	if(frm.cbodoorid.value == 0)
	{
		alert("Please select door.");
		frm.cbodoorid.focus();
		return false;
	}
	if(frm.cboenginetypeid.value == 0)
	{
		alert("Please select engine type.");
		frm.cboenginetypeid.focus();
		return false;
	}
	if(frm.cbotransmissionid.value == 0)
	{
		alert("Please select transmission.");
		frm.cbotransmissionid.focus();
		return false;
	}
	if(frm.cbofueltypeid.value == 0)
	{
		alert("Please select fuel type.");
		frm.cbofueltypeid.focus();
		return false;
	}
	if(frm.cbodrivetypeid.value == 0)
	{
		alert("Please select drive type.");
		frm.cbodrivetypeid.focus();
		return false;
	}
	if(frm.cboexteriorcolorid.value == 0)
	{
		alert("Please select exterior color.");
		frm.cboexteriorcolorid.focus();
		return false;
	}
	if(frm.cbointeriorcolorid.value == 0)
	{
		alert("Please select interior color.");
		frm.cbointeriorcolorid.focus();
		return false;
	}		
	if(frm.cboconditionid.value == 0)
	{
		alert("Please select condition.");
		frm.cboconditionid.focus();
		return false;
	}
	if(trim(frm.txtbasicprice.value).length==0)
	{
		alert("Please enter basic price.");
		frm.txtbasicprice.focus();
		return false;
	}
	if(!checkPrice_withdollar(trim(frm.txtbasicprice.value)))
	{
		alert("Please enter numeric value in basic price.");
		document.frm.txtbasicprice.focus();
		return false;	
	}
	/*if (!(checkFloat(frm.txtbasicprice.value)))
	{
		alert("Please enter numeric value in basic price.");
		document.frm.txtbasicprice.focus();
		return false;	
	}*/
	if(trim(frm.txtmileage.value).length==0)
	{
		alert("Please enter mileage.");
		frm.txtmileage.focus();
		return false;
	}
	/*if(trim(frm.txtvin.value).length==0)
	{
		alert("Please enter VIN.");
		frm.txtvin.focus();
		return false;
	}*/
	if(trim(frm.mode.value)=="add")
	{		
		changeadditionalservice();
	}

	frm.action="sellcar3.php";
	frm.submit();

}

function getvindetail(frm)
{
	if(frm.txtvin.value.split(" ").join("")=="")
	{
		alert("Please enter VIN.");
		frm.txtvin.focus();
		return false;
	}
	//if(frm.txtvin.value.length != 17)
	if(trim(frm.txtvin.value).length!=17)
	{
		alert("Please enter 17 char VIN.");
		frm.txtvin.focus();
		return false;
	}
	
	frm.action="sellcar2.php";
	frm.submit();
}

function resetvin(frm)
{
	frm.txtvin.readOnly=false;
	frm.btngetvehicle.style.display='';
	frm.btnreset.style.display='none';
	document.getElementById("tdallfields").style.display="none";
}

function setaction(actiontype)
{	
	document.frm.action = "sellcar_db.php";	
	
	if (actiontype=="sold")
	{
		document.frm.mode.value = "sold";
		document.frm.submit();		
	}
	if(actiontype=="active")
	{
		document.frm.mode.value = "active";
		document.frm.submit();		
	}
	
}

function Buynow(packageid, packageprice, featuredadweeks,  banneradweeks,  totalimages, totalday, isloggedin, usertypeid)
{
	if (isloggedin == '1')
	{
		if (usertypeid == '3')
			document.frm.action = "newcar2.php";
		else if (usertypeid == '2')
			document.frm.action = "sellcar2.php";
	}
	else
		document.frm.action = "new_user.php";

	//document.frm.action = "sellcar2.php";	
	
	document.frm.txtpackageid.value = packageid;
	document.frm.txtpackageprice.value = packageprice;
	document.frm.txtfeaturedadweeks.value = featuredadweeks;
	document.frm.txtbanneradweeks.value = banneradweeks;
	document.frm.txttotalimages.value = totalimages;
	document.frm.txttotalday.value = totalday;	
	
	document.frm.submit();		
}

function changeadditionalservice()
{	
	var additionalrate = 0;
	var additionalserviceids = "0";	
	var additionalservicename = "";	
	var additionalservices = "0:0:";			
	
	if (typeof(document.frm.chkadditionalserviceid.length) != "undefined")
	{
		for(var i=0;i<document.frm.chkadditionalserviceid.length;i++)
		{
			if(document.frm.chkadditionalserviceid[i].checked)
			{
				var v = document.frm.chkadditionalserviceid[i].value.split('|');
				
				var serviceid = v[0];
				var servicerate = v[1];
				var servicename = v[2];
				
				additionalserviceids = additionalserviceids + ',' + serviceid + "," + servicename;
				additionalservices = additionalservices + ',' + serviceid + ':' +  servicerate + ':' +  servicename;
				additionalrate = additionalrate + eval(servicerate);	
			}	
		}
	}
	else
	{	
		if(document.frm.chkadditionalserviceid.checked)
		{
			var v = document.frm.chkadditionalserviceid.value.split('|');
			
			var serviceid = v[0];
			var servicerate = v[1];		
	
			additionalserviceids = additionalserviceids + ',' + serviceid;				
			additionalservices = additionalservices + ',' + serviceid + ':' +  servicerate;
			additionalrate = additionalrate + eval(servicerate);				
		}
	}	

	document.frm.txtadditionalservices.value = additionalservices;
	document.frm.txtadditionalserviceids.value = additionalserviceids;	
	document.frm.txtadditionalamount.value = eval(additionalrate);
	document.frm.txtnetamount.value = eval(document.frm.txtpackageprice.value) + eval(additionalrate);	
}

function submitfrm3(frm)
{
	if(trim(frm.mode.value)=="add")
	{
		if(frm.txtnetamount.value != "0")				
			frm.action = "sellcar4.php";
		else
			frm.action = "sellcar_db.php";
	}
	else
		frm.action = "sellcar3_db.php";

	frm.submit();
}

function submitfrm3back(frm)
{
	frm.action = "sellcar2.php";	
	frm.submit();
}

function submitfrm4(frm)
{
	if(trim(frm.txtbillfirstname.value).length==0)
	{
		alert("Please enter first name.");
		frm.txtbillfirstname.focus();
		return false;
	}
	if(trim(frm.txtbilllastname.value).length==0)
	{
		alert("Please enter last name.");
		frm.txtbilllastname.focus();
		return false;
	}
	if(trim(frm.txtbilladdress.value).length==0)
	{
		alert("Please enter address.");
		frm.txtbilladdress.focus();
		return false;
	}
	if(trim(frm.txtbillcity.value).length==0)
	{
		alert("Please enter city.");
		frm.txtbillcity.focus();
		return false;
	}
	if(trim(frm.txtbillzipcode.value).length==0)
	{
		alert("Please enter zip code.");
		frm.txtbillzipcode.focus();
		return false;
	}
	if(trim(frm.txtbillphone.value).length==0)
	{
		alert("Please enter phone.");
		frm.txtbillphone.focus();
		return false;
	}
	if(trim(frm.txtbillemail.value).length==0)
	{
		alert("Please enter email.");
		frm.txtbillemail.focus();
		return false;
	}
	if(!isEmail(trim(frm.txtbillemail.value)))
	{
		alert("Please enter valid email.");
		frm.txtbillemail.focus();
		return false;
	}
	if(frm.cardtype.value == 0)
	{
		alert("Please select card type.");
		frm.cardtype.focus();
		return false;
	}
	if(trim(frm.txtccnumber.value).length==0)
	{
		alert("Please enter credit card number.");
		frm.txtccnumber.focus();
		return false;
	}
	if(trim(frm.txtcvvno.value).length==0)
	{
		alert("Please enter C.V.V. number.");
		frm.txtcvvno.focus();
		return false;
	}
}

function submitfrm4back(frm)
{
	frm.action = "sellcar3.php";	
	frm.submit();
}

function playvideo(file,strname)
{
	var intWidth = 450;
	var intHeight = 420;
	var intLeft = ((screen.availWidth - intWidth) / 2) + 1;
	var intTop = ((screen.availHeight - intHeight) / 2) + 1;
	var url = "video.php?f="+file;
	
	if(popup)
	{
		if(!popup.closed)
		{
			popup.close();				
		}
	}
	
	popup = window.open(url, strname, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+intWidth+',height='+intHeight+',left='+intLeft+', top='+intTop+',screenX='+intLeft+',screenY='+intTop+'');
}

function popupimage(file,strname)
{
	var intWidth = 653;
	var intHeight = 500;
	var intLeft = ((screen.availWidth - intWidth) / 2) + 1;
	var intTop = ((screen.availHeight - intHeight) / 2) + 1;

	var url = file;
	
	if(popup)
	{
		if(!popup.closed)
		{
			popup.close();				
		}
	}
	
	popup = window.open(url, strname, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+intWidth+',height='+intHeight+',left='+intLeft+', top='+intTop+',screenX='+intLeft+',screenY='+intTop+'');
}

function helptext(id)
{
	var object = document.getElementById(id);
	if(object.className == "div-helptext-visible"){
		object.className = "div-helptext-invisible";
	}
	else{
		object.className = "div-helptext-visible";
	}
}

