
//Div Tag Highlight Script
function highlightRow(obj, over) {
   rowObj = obj.parentElement;
   for (i = 0; i < rowObj.childNodes.length; i++) {
      rowObj.childNodes[i].style.color = (over) ? '#cccccc' : '#000000';
      rowObj.childNodes[i].style.backgroundColor = (over) ? '#999999' : '#cccccc';
   }
}

function highlightRow1(obj, over) {
   rowObj = obj.parentElement;
   for (i = 0; i < rowObj.childNodes.length; i++) {
      rowObj.childNodes[i].style.color = (over) ? '#ffffff' : '#000000';
      rowObj.childNodes[i].style.backgroundColor = (over) ? '#cccccc' : '#ffffff';
   }
}
//Show and Hide Div 
function showHideEx()
{
	if (document.getElementById("href_ex").innerText=="Hide Extras")
	{
		document.getElementById("div_extras").style.display="none";
		document.getElementById("div_extras1").style.display="none";
	}
	else
	{
		document.getElementById("div_extras").style.display="";
		document.getElementById("div_extras1").style.display="";
		document.getElementById("calculator").style.display="none";
		document.getElementById("name").style.display="none";
		document.getElementById("testdrive").style.display="none";
	}
	document.getElementById("href_ex").innerText!="Show Extras"?document.getElementById("href_ex").innerText="Show Extras":document.getElementById("href_ex").innerText="Hide Extras";
	
}

function showHideEx1()
{
	
	document.getElementById("href_ex").innerText="Hide Extras";
	document.getElementById("div_extras").style.display="none";
	document.getElementById("div_extras1").style.display="none";
	document.getElementById("href_ex").innerText!="Show Extras"?document.getElementById("href_ex").innerText="Show Extras":document.getElementById("href_ex").innerText="Hide Extras";
	
}

function showHide()
{
	if (document.getElementById("href_Link").innerText=="Hide Search")
	{
		document.getElementById("div_Search").style.display="none";
	}
	else
	{
		document.getElementById("div_Search").style.display="";
	}
	document.getElementById("href_Link").innerText!="Show Search"?document.getElementById("href_Link").innerText="Show Search":document.getElementById("href_Link").innerText="Hide Search";
	
}
function showHide1()
{
	
	document.getElementById("href_Link").innerText="Hide Search";
	document.getElementById("div_Search").style.display="none";
	document.getElementById("href_Link").innerText!="Show Search"?document.getElementById("href_Link").innerText="Show Search":document.getElementById("href_Link").innerText="Hide Search";
	
}

//Test Drive

function showHideQ()
{
		document.getElementById("quote").style.display="";
		document.getElementById("calculator").style.display="none";
		document.getElementById("name").style.display="none";
		document.getElementById("testdrive").style.display="none";
}

//Payment Calculator

function showHideC()
{
		document.getElementById("quote").style.display="none";
		document.getElementById("calculator").style.display="";
		document.getElementById("name").style.display="none";
		document.getElementById("testdrive").style.display="none";
}

function showHideName()
{
		document.getElementById("quote").style.display="none";
		document.getElementById("calculator").style.display="none";
		document.getElementById("name").style.display="";
		document.getElementById("testdrive").style.display="none";
}

function showHideTest()
{
		document.getElementById("quote").style.display="none";
		document.getElementById("calculator").style.display="none";
		document.getElementById("name").style.display="none";
		document.getElementById("testdrive").style.display="";
		
}

function showcolor(obj)
{
	document.getElementById("int").style.backcolor="Blue";
}

//Put Div Tag

function PutInnerHTML(Obj,clea)
{

	document.getElementById("div_inner").innerHTML=Obj.innerHTML;
	//showHide();
	
	chkbox(document.getElementById("chkload").value);	
	
	//document.Form1.opt_options[document.getElementById("chkload").value].disabled = false;
	
	
	if (document.getElementById("hidquick").value == 0 )
	{
	
	document.getElementById("quote").style.display="none";
	
	document.getElementById("calculator").style.display="none";
	//alert('ok5');
	document.getElementById("name").style.display="none";
	//alert('ok6');
	document.getElementById("testdrive").style.display="none";
	
	}

}

function adminPutInnerHTML(Obj)
{
	document.getElementById("div_inner").innerHTML=Obj.innerHTML;
	//showHide();
}

function init() {
	if (window.initDetails) initDetails();
}

//Onload Default Tag is Option Div

function loa()
	{
		//alert(document.getElementById("quick").value);
		if (document.getElementById("loadvalue").value == 0)
			{
		document.getElementById("div_options").style.display="none";
		document.getElementById("opt_fea").style.display="none";
		document.getElementById("opt_none").style.display="none";
		}
		
		PutInnerHTML(div_Opt);
		hideObject();
	}
	
	
	
	function features_view()
	{	
		//alert(document.getElementById("loadvalue").value);
		//alert('ok');
		var vid = getQueryVariable("VEHID");
			
		showObject();
			
		/*var oPopup = window.createPopup();
		var oPopBody = oPopup.document.body;
	    oPopBody.style.backgroundColor = "lightyellow";	    
	    oPopBody.style.color = "red";
	    oPopBody.style.border = "solid black 1px";
	    oPopBody.innerHTML = "<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please Wait.</b>";
	    oPopup.show(190, 260, 180, 25, document.body);*/
		
		if(vid != 'fail')
			VehicleDetails_ajax.getfeature(vid,getfeature_callback);
			

	}
	
	function getfeature_callback(response)
	{
		var features = response.value;
		
		//alert(features[0]);
		
		if(features != null)
		{				
			document.getElementById("div_inner").innerHTML = features[0];
			document.getElementById("div_Opt").innerHTML = features[0];
			document.getElementById("div_general").innerHTML = features[1];
			document.getElementById("div_des").innerHTML = features[2];
			document.getElementById("div_war").innerHTML = features[3];
			document.getElementById("div_safety").innerHTML = features[4];
			document.getElementById("div_Comf").innerHTML = features[5];
			document.getElementById("div_Ext").innerHTML = features[6];
			
			if (document.getElementById("loadvalue").value == 0)
			{
			document.getElementById("opt_fea").style.display="";
			document.getElementById("opt_none").style.display="";
			document.getElementById("div_options").style.display="";
			}
		
			hideObject();			
		}
		
		if(response.error != null)
			alert(response.error);

	}

	function getQueryVariable(variable) 
	{
		var query = window.location.search.substring(1);		
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
			return pair[1];
			}
		} 
		return "fail";
	}
		
//Calculate MSRP value and Options Value(CheckBox)

//function chg(msvalue,chkbox,ruletype,ruleopt,obj,content)
function chg(contvalue,msvalue,chkbox,ruletype,ruleopt,obj)
	{
		
		
		if (chkbox != false)
			{
				
				//document.getElementById("txtcont").value= document.getElementById("txtcont").value + '&&' + document.getElementById("cont"+arr1[j]).innerText
				document.getElementById("txtcont").value= contvalue + '&&' + document.getElementById("txtcont").value
			}
		else
			{
			}
			
		try
		{
		//alert('RuleType'+ ruletype);
		//alert('RuleOptions'+ ruleopt);
		
		
		chkbox?AddAmount(msvalue):DeleteAmount(msvalue);
					
		
		if ((ruleopt!='')||(ruleopt!=null))
		{	
		
			var str_option=new String();
			var arr=new Array();
			var arr_RuleType=new Array();
			
			var str_andor =new String();
			var str_RuleType =new String();
			str_option=ruleopt;	
			arr=str_option.split("#");
			str_RuleType= ruletype;
			arr_RuleType=str_RuleType.split("#"); 
			/*for(k=0;k<arr_RuleType.length;k++)
			{
				//alert(arr_RuleType[k]);
				if (arr_RuleType[k]=="100007")
				{
					
					for(i=0;i<document.getElementsByName("opt1").length;i++)
					{	
					
						document.getElementsByName("opt1").item(i).disabled=obj.checked;
					}
					for(i=0;i<document.getElementsByName("opt").length;i++)
					{	
					
						document.getElementsByName("opt").item(i).disabled=obj.checked;
					}
					break;
				}
			}*/
			obj.disabled=false;
			//var chr = '';
			for(i=0;i<arr.length-1;i++)
			{
				
				str_andor=arr[i];
				var arr1=new Array();
				
				if ((str_andor.indexOf("AND")<0)&&(str_andor.indexOf("OR") >-1))  
				{
					
					arr1=str_andor.split("OR"); 	
					//alert(arr1.length);
					var arrlen;
					arrlen=arr1.length-(arr1.length-1)
					//alert(arrlen);
					for(j=0;j<arrlen;j++)
					{	
					
						if (typeof(document.getElementById("chkbox"+arr1[j]))=='object')
						{	
							chkbox?AddAmount(document.getElementById("msrp"+arr1[j]).innerText):DeleteAmount(document.getElementById("msrp"+arr1[j]).innerText);
							
							document.getElementById("chkbox"+arr1[j]).checked=chkbox;
							document.getElementById("chkbox"+arr1[j]).disabled=chkbox;
							
						}
					}
					
				}
				else 
				{
					arr1=str_andor.split("AND");
					
					//alert(document.getElementById("chkbox"+arr1[j]).checked);
					
					for(j=0;j<arr1.length;j++)
					{		
						
						
						if (typeof(document.getElementById("chkbox"+arr1[j]))=='object')
						{
						
							//alert("chkbox"+arr1[j]);					
							//chkbox?AddAmount(document.getElementById("msrp"+arr1[j]).innerText):DeleteAmount(document.getElementById("msrp"+arr1[j]).innerText);
							//alert(document.getElementById("cont"+arr1[j]).innerText+'\n');
							if (arr_RuleType[i] != 100007)
								{
									document.getElementById("chkbox"+arr1[j]).checked=chkbox;
									document.getElementById("chkbox"+arr1[j]).disabled=chkbox;
								}
							else 
								{
									//
									//alert(document.getElementById("chkbox"+arr1[j]).checked);
									if (document.getElementById("chkbox"+arr1[j]).checked !=false)
										{
											//alert('inner');
											DeleteAmount(document.getElementById("msrp"+arr1[j]).innerText);	
										}
									//alert(document.getElementById("msrp"+arr1[j]).innerText);
								 document.getElementById("chkbox"+arr1[j]).checked=false;
								 }
							//if (confirm('Are You Sure You Wish to LogOut' ))
							//chr = chr +"\n"+ document.getElementById("cont"+arr1[j]).innerText;
																				
							//alert(document.getElementById("cont"+arr1[j]).innerText);
						}
						
						
					}
					
				}
				
			} 
			 
		}
		/*var con="By adding "+content+"you also do the following\n - Add"+chr;
		if (confirm(con))
		{
			alert('ok');
		}
		else
		{
			alert('not ok');
		}*/
		document.getElementById("div_Opt").innerHTML=document.getElementById("div_inner").innerHTML;
		}
		catch (e) {}
			//alert(e.description);}
	}
	
	function AddCheckAmount()
	{
		
	}
	function MSRP()
	{
		var doc=document.forms[0];
		if (doc.txtOMSRP.value == '')
			{
				msrp = 0;
			}
		else
			{
				msrp=doc.txtOMSRP.value;
				msrp=stripp(msrp);
			}
		return msrp;
	}		
	function Inv()
	{
		var doc=document.forms[0];
		
		if (doc.txtOInv.value == '')
			{
				inv = 0;
			}
		else
			{
				inv=doc.txtOInv.value;
				inv=stripp(inv);
			}
			
		return inv;
	}	
//Remove $ from amount
function AddAmount(msvalue)
{
		
		msvalue1=msvalue;
		
		var doc=document.forms[0];
		msvalue=stripp(msvalue);
		var amt = parseInt(msvalue) + parseInt(MSRP());	
		
		if (document.getElementById("hid_optvalue").value == 0)
			{
			
			document.getElementById('txtOMSRP').value = formatCurrency(amt);
			}
		else
			{
				amt=0;
			}
		
				if ( doc.txtBMSRP.value == '')
			{
				bas = 0;
			}
		else
			{
				bas=doc.txtBMSRP.value;
				bas=stripp(bas);
			}
		
		
		amt = parseInt(bas) + parseInt(amt);
		
		if (document.getElementById('txtDMSRP').value != 0)
			{
				msvalue = document.getElementById('txtDMSRP').value;
				msvalue=stripp(msvalue);
				amt = amt + parseInt(msvalue);
				
				document.getElementById('txttotmsrp').value =formatCurrency(amt); 
				document.getElementById('lblmsrp').innerHTML=document.getElementById('txttotmsrp').value;
				
				//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';
			}
		else
			{
				
				document.getElementById('txttotmsrp').value = formatCurrency(amt); 
				document.getElementById('lblmsrp').innerHTML=document.getElementById('txttotmsrp').value;
				//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';
			}
			
			if (document.getElementById('hid_invoice').value == 1)
			{
			
			
			msvalue1=stripp(msvalue1);
			var Iamt = parseInt(msvalue1) + parseInt(Inv());
			if (document.getElementById("hid_optvalue").value == 0)
			{
			document.getElementById('txtOInv').value = formatCurrency(Iamt);
			}
		else
			{
				Iamt=0;
			}		
			
			if (doc.txtBInv.value == '')
				{
					whol = 0;
				}
			else
				{
					whol=doc.txtBInv.value;
					whol=stripp(whol);
				}
			Iamt = parseInt(whol) + parseInt(Iamt);
			if (document.getElementById('txtDInv').value != 0)
				{
					msvalue1 = document.getElementById('txtDInv').value;
					msvalue1=stripp(msvalue1);
					
					
					Iamt = Iamt + parseInt(msvalue1);
					document.getElementById('txttotInv').value =formatCurrency(Iamt); 
				}
			else
				{
					document.getElementById('txttotInv').value = formatCurrency(Iamt); 
				//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';
				}
		}
		
		
}
function formatCurrency(num) 
	{
		num = num.toString().replace(/\$|\,/g,'');
			if(isNaN(num))
			num = "0";
			sign = (num == (num = Math.abs(num)));
			num = Math.floor(num*100+0.50000000001);
			cents = num%100;
			num = Math.floor(num/100).toString();
			if(cents<10)
				cents = "0" + cents;
				for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
				num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
				return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
function DeleteAmount(msvalue)
{
	msvalue1=msvalue;
	if (document.getElementById('txtOMSRP').value != 0)
	
		{
			msvalue=stripp(msvalue);
			amt=parseInt(MSRP()) - parseInt(msvalue);
			if (document.getElementById("hid_optvalue").value == 0)
			{
			document.getElementById('txtOMSRP').value = formatCurrency(amt);
			}
		else
			{
				amt=0;
			}
			
			//document.getElementById('txtOMSRP').value = '$ ' + amt;	
			if (document.getElementById('txttotmsrp').value != 0)
				{
				whvalue=stripp(document.getElementById('txtBmsrp').value);
				amt= amt +  parseInt(whvalue) ;
				if (document.getElementById('txtDMSRP').value != 0)
					{
					msvalue = document.getElementById('txtDMSRP').value;
					msvalue=stripp(msvalue);
					amt = amt + parseInt(msvalue);
					
					document.getElementById('txttotmsrp').value=formatCurrency(amt);
					document.getElementById('lblmsrp').innerHTML=document.getElementById('txttotmsrp').value;
					//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';	
					}
				else
					{
					document.getElementById('txttotmsrp').value=formatCurrency(amt);
					document.getElementById('lblmsrp').innerHTML=document.getElementById('txttotmsrp').value;
					//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';	
					}
				}
		}
	
	if (document.getElementById('hid_invoice').value == 1)
	{
		if (document.getElementById('txtOInv').value != 0)
	
		{
		
			msvalue1=stripp(msvalue1);
			amt1=parseInt(Inv()) - parseInt(msvalue1);
			if (document.getElementById("hid_optvalue").value == 0)
			{
			document.getElementById('txtOInv').value = formatCurrency(amt1);
			}
		else
			{
				amt1=0;
			}
			
			//document.getElementById('txtOMSRP').value = '$ ' + amt;	
			if (document.getElementById('txttotInv').value != 0)
				{
				whvalue=stripp(document.getElementById('txtBInv').value);
				amt1= amt1 +  parseInt(whvalue) ;
				if (document.getElementById('txtDInv').value != 0)
					{
					msvalue1 = document.getElementById('txtDInv').value;
					msvalue1=stripp(msvalue1);
					amt1 = amt1 + parseInt(msvalue1);
					
					document.getElementById('txttotInv').value=formatCurrency(amt1);
					//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';	
					}
				else
					{
					document.getElementById('txttotInv').value=formatCurrency(amt1);
					//document.getElementById('txttotmsrp').value = '$ ' + amt + '.00';	
					}
				}
		}
	}
		
}
function stripp(whvalue1)
	{
		s = whvalue1;
		filteredValues = "$,";     // Characters stripped out
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
			}
		whvalue1 = returnString;
		return whvalue1;
	}

/*
	**************************************************************
*/

//Payment Calculator Function

/*function calculat()
	{
		var doc=document.forms[0];
		
		if (doc.Payment1_txtprice.value == '')
			{
				pri = 0;
			}
		else
			{
				pri=doc.Payment1_txtprice.value;
			}
		if (doc.txtdown.value == '')
			{
				dow = 0;
			}
		else
			{
				dow=doc.txtdown.value;
			}
		s = pri;
		filteredValues = "$,";     // Characters stripped out
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
			}
		pri = returnString;
		yrs = eval (doc.drploan.options[doc.drploan.selectedIndex].text);
		rte = eval (doc.drpinterest.options[doc.drpinterest.selectedIndex].text)/1200;
		pmt=(rte+(rte/(Math.pow((1+rte),(yrs))-1)))*parseInt(pri);
		pmt = pmt*100;pmt=Math.round(pmt);pmt=pmt/100;
		document.getElementById("txtmonth").value= '$' + pmt;
}*/

function strReplace(replacedvar)
{
		replacedvar = replacedvar.Replace("$" , " ")
		replacedvar = replacedvar.Replace("," , " ")
		
			//var doc=document.forms[0];
			//	dow=doc.txtdown.value;
			
			//	alert(dow);
			//	dow=doc.Replace("$","");
			//	alert(dow);
			//	dow=doc.Replace(",","");
			//	alert(dow);
}


function calculat()
	{
		var doc=document.forms[0];
		
		
		if (doc.Payment1_txtprice.value == '')
			{
				pri = 0;
			}
		else
			{
				pri=doc.Payment1_txtprice.value;
			}
		if (doc.txtdown.value == '')
			{
				dow = 0;
			}
		else
			{
				dow=doc.txtdown.value;
				
				alert(dow);
				dow=doc.Replace("$","");
				alert(dow);
				dow=doc.Replace(",","");
				alert(dow);
			}
			
		s = pri;
		filteredValues = "$,";     // Characters stripped out
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
			}
		pri = returnString;
		yrs = eval (doc.drploan.options[doc.drploan.selectedIndex].text);
		rte = eval (doc.drpinterest.options[doc.drpinterest.selectedIndex].text)/1200;
		pmt=(rte+(rte/(Math.pow((1+rte),(yrs))-1)))*parseInt(pri);
		pmt = pmt*100;pmt=Math.round(pmt);pmt=pmt/100;
		document.getElementById("txtmonth").value= '$' + pmt;
}
/*
	**************************************************************
*/

function checkNumberEntry(input, min, max, msg) {
			
			
        var str = input;
		
	if (str == null || input.length == 0) {
		msg = msg + " is blank.  You must fill in this field to calculate.";
		alert(msg);
		return false;
	}

        for (var i = 0; i < str.length; i++) {
            var curr_ch = str.substring(i, i + 1)
            if ((curr_ch < '0' || curr_ch > '9') && curr_ch != '.') {
	        msg = msg + " should only contain digits.  You entered: " + input;
                alert(msg);
                return false;
            }
        }
        var num = input;
       /* if ((min != -9999) && num<min) {
	    msg = msg + " that's too low: " + input + ".  You should only enter values greater than " + min + ".";
            alert("You have entered a " + msg);
            return false;
        }*/

        if  ((max != -9999) && num > max) {
	    msg = msg + " that's high: " + input + ".  You should only enter values less than " + max + ".";
            alert("You have entered a " + msg);
            return false;
        }
        input = str;
        return true;
}
function myRound(val) {

	val = val * 100;
	val = Math.round(val);
        return val / 100;
}

function computeField(input) {

        if (input.value != null && input.value.length != 0)
            input.value = "" + eval(input.value);
        compute(input.form);
}
function compute(form) 

	{
		
		var doc=document.forms[0];		
		//alert(doc.Payment1_txtprice.value);
		//alert(doc.Payment1_txtprice.value);
		
		var Price;
									
		if (doc.txtprice.value == '')
			{
				Price = 0;
			}
		else
			{
				Price=doc.txtprice.value;
			}
		if (doc.txtdown.value == '')
			{
				dow = 0;
			}
		else
			{
				dow=doc.txtdown.value;
			}
		s = Price;
		filteredValues = "$,";     // Characters stripped out
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
		var c = s.charAt(i);
		if (filteredValues.indexOf(c) == -1) returnString += c;
			}
			
		Price = returnString;


        //var Price = form.price.value;
	//var interest = form.Interest.value;
	var interest = doc.drpinterest.options[doc.drpinterest.selectedIndex].text
	var interest = doc.txtinterestRate.value;
	
	
	//alert(doc.drpinterest.options[doc.drpinterest.selectedIndex].text);
	
	var months = doc.drploan.options[doc.drploan.selectedIndex].text
	//alert(months);
	//var months = form.Months.value;

        if (!checkNumberEntry(Price, 0, -9999, "Price")) {
            //form.payment.value = "Invalid";
            return;
        }
        if (!checkNumberEntry(dow, 0, parseFloat(Price), "Down Payment")) {
            //form.payment.value = "Invalid";
            return;
        }
        if (!checkNumberEntry(months, 1, -9999, "# of Months")) {
            //form.payment.value = "Invalid";
            return;
        }
        if (!checkNumberEntry(interest, 1, 99, "% Interest Rate")) {
            //form.payment.value = "Invalid";
            return;
        }

        Price = Price - dow;
        interest = (interest / 100.0) / 12;

        var pow = 1;
        for (var j = 0; j < months; j++)
            pow = pow * (1 + interest);

	var pmt = (Price * pow * interest) / (pow - 1);	

        //document.getElementById("txtmonth").value = myRound(pmt);
		  document.getElementById("txtmonth").value = formatCurrency(pmt);

}

///////////////////////////////////////

//Interior Color function

 function chkbox(obj,id,imgchk,optid,extco,intco,imgvalue)
  {
	
	try	
	 {	 	
		
	  for(i=0;i<document.Form1.opt_options.length;i++)
		{
	     document.Form1.opt_options[i].disabled=obj.checked
		}
					
	  document.getElementById("chkload").value = id;
	  obj.disabled=false;
	  if ( imgchk == 1 ) 
		{
	     if ( obj.checked == true )
		  {
			document.getElementById('txtext').value = document.getElementById(extco).innerText;
			
		    //if ( document.getElementById('noimage').value == 1 )
		    
		    if ( imgvalue == 1 )
		    {
		    
			 //document.getElementById('vehimg').src = document.getElementById('chkimg').value + '.jpg'
			 
			 document.getElementById('vehimg').src = 'images/image300/noimagesmall.jpg'
			 
			}
		   else				
			{
		     document.getElementById('vehimg').src = document.getElementById('chkimg').value + optid + '.jpg'	
			}
		  }
		else
		  {
		  
		   document.getElementById('vehimg').src = document.getElementById('imgmain').value 	
		  }
	   }
     }
   	catch (e) {}	
  }	
  
  
  //Preview Template
  
  function preview()
	{
	  temp = document.getElementById('drptemp').options[document.getElementById('drptemp').selectedIndex].value;
	  if (temp != 0 )
		{
		temp = document.getElementById('drptemp').options[document.getElementById('drptemp').selectedIndex].text;
	      //temp = 'template/' + temp + '.html'
	      temp = 'templates/' + temp + '/' + temp + '.html'
		  window.open(temp,'','height=640,width=1000,scrollbars=yes,status=yes');
		}
	  else
	    {
		  alert('Select Template');
		}
	}
	
	//Hide a Car
	
	
function CheckAll() 
{
if (confirm('Do you want to Hide all Vehicles?' ))
 { 
 var i;
  document.forms[0].txt1.value = '';
    for (i=0; i < document.forms[0].elements.length; i++) 
  {
   if ((document.forms[0].elements[i].type == 'checkbox') &&  (document.forms[0].elements[i].name.indexOf('dgrcar') > -1)) 
   {
    document.forms[0].elements[i].checked = true;
    document.forms[0].txt1.value += document.forms[0].elements[i].value + '-';
   }
  }
   document.forms[0].checkAll.checked = true;
   return true;
  }
 else
  {
   return false;
  } 
}

function SelectAll(CheckBoxControl) 
{
 if (CheckBoxControl.checked == true) 
 {
  var i;
  document.forms[0].txt1.value = '';
  for (i=0; i < document.forms[0].elements.length; i++) 
  {
   if ((document.forms[0].elements[i].type == 'checkbox') &&  (document.forms[0].elements[i].name.indexOf('dgrcar') > -1)) 
   {
    document.forms[0].elements[i].checked = true;
    document.forms[0].txt1.value += document.forms[0].elements[i].value + '-';
   }
  }
 } 
 else 
 {
  var i;
  for (i=0; i < document.forms[0].elements.length; i++) 
  {
   if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('dgrcar') > -1)) 
   {
    document.forms[0].elements[i].checked = false;
    document.forms[0].txt1.value = '';
   }
  }
 }
}
//-->
		
		
		function SelectOneAlert()
			{
				if (document.forms[0].txt1.value == '')
								{
									alert('Select Vehicle  to Hide');
									return false;
								}
							else
								{
									if (confirm('Do you want to Hide a Vehicle?'))
										{
											return true;
										}
									else
										{
											return false;
										}
								}
			}
		
        function CheckChanged()
			{
				var frm = document.Form1;
				var boolAllChecked;
				boolAllChecked=true;
				for(i=0;i< frm.length;i++)
					{
						e=frm.elements[i];
						if ( e.type=='checkbox' && e.name.indexOf('ChkId') != -1 )
						if(e.checked== false)
							{
								var j=1;
								boolAllChecked=false;
								break;
							}
					}	
				for(i=0;i< frm.length;i++)
					{
						e=frm.elements[i];
						if ( e.type=='checkbox' && e.name.indexOf('checkAll') != -1 )
							{
								if( boolAllChecked==false)
									{
										e.checked= false ;
										document.forms[0].txt1.value = '';
										if( j==1)
											{
												var i;
												document.forms[0].txt1.value = '';
												for (i=0; i < document.forms[0].elements.length; i++)
													{	
														if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('ChkId') != -1 ))
															{
																var check;
																check=document.forms[0].elements[i].checked;
																if (check==true)
																	{
																		document.forms[0].txt1.value += document.forms[0].elements[i].value + '-';
																	}
															}
													}
											}
									}
								else 
									{
										e.checked= true;
										var i;
										document.forms[0].txt1.value = '';
										for (i=0; i < document.forms[0].elements.length; i++)
											{
												if ((document.forms[0].elements[i].type == 'checkbox') &&  (document.forms[0].elements[i].name.indexOf('dgrcar') > -1))
													{
														document.forms[0].txt1.value += document.forms[0].elements[i].value + '-';
													}
											}
										break; 
									} 
								 }
							}
		} 
         
         
         //Phone Validation
			function fncheck(obj)
	            {
	                 alert("hello");
                }
           function fnnamechk(obj)
	            {
	                 obj.value=trimString(obj.value);
	                 //alert(obj);
                     //Page_ClientValidate();
                 }
           function trimString (str)
                  {
	                   var str1;
                       str1=str;
                       return str1.replace(/^\s+/g, '').replace(/\s+$/g, '');
                  }
           function stripCharsNotInBag (s, bag)
			{
			   var i;
			   var returnString = "";
			   for (i = 0; i < s.length; i++)
				{   
			       var c = s.charAt(i);
			       if (bag.indexOf(c) != -1) returnString += c;
				}
			   return returnString;
			}
			function inputPhone(oControl,lExt)
			{
            // strip out any non-valid characters
	           cPhone = stripCharsNotInBag(oControl.value,'0123456789()-');
	           
           // check for empties
	            if (cPhone == '')
		            {
                       oControl.value = cPhone;
	                   return null;
	                }
			// check if the first char is a 1, remove it after there are 2 chars
	            if ((cPhone.length == 2) && (cPhone.substring(0,1) == '1'))
                        cPhone = cPhone.substring(1,cPhone.length);
            // strip all formatting chars
	            cPhone = stripCharsNotInBag(cPhone,'0123456789');
	            if (cPhone != '1')
		            {
                    // add the formatting chars back in
	                    cPhone = '('+cPhone;
	                    if (cPhone.length > 3)
                        cPhone = cPhone.substring(0,4)+')'+cPhone.substring(4,cPhone.length);
	                    if (cPhone.length > 7)
                        cPhone = cPhone.substring(0,8)+'-'+cPhone.substring(8,cPhone.length);
                    // check for extension
	                    if ((cPhone.length > 13) || ((cPhone.length==13) && (lExt) && (oControl.value.substring(oControl.value.length-1,oControl.value.length).toLowerCase()=='x')))
	                       {
	                           if (lExt)
	                               cPhone = cPhone.substring(0,13); //+' x'+cPhone.substring(13,cPhone.length);
                               else
	                               cPhone = cPhone.substring(0,13);
	                        }
			          }

            // return the new value
           oControl.value = cPhone;
}

	

         //Alphabets Validation
         
         //Character Validation
	function validate(field,name,num) {
var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. "
if (num == "1")
	{
		valid ="1234567890.$"
	}
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
	if (num == "1")
	{
		alert(name+" accepts only numbers!");		
		field.focus();
		field.select();
	}
	else
	{
		alert(name+" accepts only characters!");		
		field.focus();
		field.select();
	}


   }
}         


  
  
  //Email Validation
  
  
   function emailsplit(email)
	{
	
	
		if (email != '')
			{
		
		var arr=new Array();
		var str_email =new String();
		
		str_email=email;
		
		arr=str_email.split(";");
				
		if (arr.length > 1)
		 {
		 
			for(i=0;i<arr.length;i++)
			 {
				
			 	str_email=emailCheck(arr[i]);
			 	
			 	if (str_email == false)
					{		
						if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
						{
								if (document.getElementById("GetaQuote1:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("GetaQuote1:email").value='';
										return false;
									}	
									if (document.getElementById("TestDrive1:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("TestDrive1:email").value='';
										return false;
									}		
						}
						else
						{
							if (document.getElementById("hidquick").value == 1)
								{
								
									if (document.getElementById("GetaQuote2:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("GetaQuote2:email").value='';
										return false;
									}		
								}
						}
								
						
								
									
							if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
						{
								if (document.getElementById("Name1:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("Name1:email").value='';
										return false;
									}		
						}
						else
						{
							if (document.getElementById("hidquick").value == 2)
								{
								
									if (document.getElementById("Name2:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("Name2:email").value='';
										return false;
									}		
								}
						}
								
						
					}			
			}
		}
		else
			{
			
				str_email=emailCheck(email);
				if (str_email == false)
					{
						if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
						{
								if (document.getElementById("GetaQuote1:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("GetaQuote1:email").value='';
										return false;
									}		
									if (document.getElementById("TestDrive1:email").value != '' )
							{
						alert(email+' Is Invalid');
						//document.getElementById("TestDrive1:email").value='';
						return false;
						}
						}
						else
						{
							if (document.getElementById("hidquick").value == 1)
								{
								
									if (document.getElementById("GetaQuote2:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("GetaQuote2:email").value='';
										return false;
									}	
										
								}
						}
						
						
							if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
						{
								if (document.getElementById("Name1:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("Name1:email").value='';
										return false;
									}		
						}
						else
						{
							if (document.getElementById("hidquick").value == 2)
								{
								
									if (document.getElementById("Name2:email").value != '' )
									{
										alert(email+' Is Invalid');
										//document.getElementById("Name2:email").value='';
										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("Invalid Email");
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;
}


//Required Validation

function checkGetrequired(fname,lname,email,phone) {
var pass=true;
var name;

//alert(fname.length);
if (fname.length == 0) 
//if (fname.length == 0 )
	{
		pass=false
		name="First name"
	}
else if (lname.length == 0 )
	{
	pass=false
	name = "Last name"
	}
else if (email.length == 0 )
	{
		pass=false
		name = "Email"
	}
else if (phone.length == 0 )
	{
		pass=false
		name = "Phone"
	}

if (!pass) {
//shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Enter "+name);
return false;
}
else

return true;

}


function checkNamerequired(fname,lname,email,pay,phone) {
var pass=true;
var name;

if (fname.length == 0)
	{
		pass=false
		name="First name"
	}
else if (lname.length == 0 )
	{
	pass=false
	name = "Last name"
	}
else if (email.length == 0 )
	{
		pass=false
		name = "Email"
	}
else if (phone.length == 0 )
	{
		pass=false
		name = "Phone"
	}
else if (pay.length == 0 )
	{
		pass=false
		name = "Desired Payment"
	}



if (!pass) {
//shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Enter "+name);
return false;
}
else
return true;
}

function checkTestrequired(fname,lname,email,drp,phone) {
var pass=true;
var name;

if (fname.length == 0)
	{
		pass=false
		name="Enter First name"
	}
else if (lname.length == 0 )
	{
	pass=false
	name = "Enter Last name"
	}
else if (email.length == 0 )
	{
		pass=false
		name = "Enter Email"
	}
else if (phone.length == 0 )
	{
		pass=false
		name = "Enter Day Phone"
	}
else if (drp == "Select One" )
	{
		pass=false
		name = "Select Preferred Contact"
	}



if (!pass) {
//shortFieldName=tempobj.name.substring(8,30).toUpperCase();

	alert(name);


return false;
}
else
return true;
}


//new window Script

var newwindow;
function poptastic(url)
{
	//alert(url);
	if (url != 'http://')
		{
		newwindow=window.open(url,'name','height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes');
		if (window.focus) {newwindow.focus()}
	}
	else
	{
	alert('Select Template');
	}
}


function hideObject() {
	
	
	if (ns4) {
		document.getElementById('splashScreen').visibility = "hide";
		}
	if (ie4 || upLevel) {
	//alert(document.getElementById('splashScreen').style.visibility);
			document.getElementById('splashScreen').style.visibility = "hidden";
	//		alert(document.getElementById('splashScreen').style.visibility);
		
		}
	}
	
function showObject() {
	//alert('show');
	if (ns4) 
		{
			document.getElementById('splashScreen').visibility = "show";
			obj=document.getElementById('splashScreen');
			obj.visibility = "show";
		}
	else if (ie4 || upLevel) 
		{
			document.getElementById('splashScreen').style.visibility = "visible";
			obj=document.getElementById('splashScreen');
			obj.style.visibility = "visible";
				
		}
	}
	

function getalery(formname)
	{
	
	
		if (formname == 'Get')
		{
		var Phone=new String();
		if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
						{
					 Phone = document.getElementById("GetaQuote1:txtphone").value;
							 
		 if (Phone.length != 13)
			{
				
				if (document.getElementById("GetaQuote1:txtphone").value != '' )
					{
						document.getElementById("GetaQuote1:txtphone").value = '';
						alert('Invalid Phone Number');	
						return false;
					}
				}
			}
		else
			{
				if (document.getElementById("hidquick").value == 1)
				{
			
					Phone = document.getElementById("GetaQuote2:txtphone").value;
							 
					if (Phone.length != 13)
						{
							if (document.getElementById("GetaQuote2:txtphone").value != '' )
								{
									document.getElementById("GetaQuote2:txtphone").value = '';
									alert('Invalid Phone Number');	
									return false;
								}
						}
				}
			}
		}
		if (formname == 'Test')
		{
		
		var Phone=new String();
		 Phone = document.getElementById("TestDrive1:txtdphone").value;
		 
		 if (Phone.length != 13)
			{
				
				if (document.getElementById("TestDrive1:txtdphone").value != '' )
					{
						document.getElementById("TestDrive1:txtdphone").value = '';
						alert('Invalid Phone Number');	
						return false;
					}
			}
		}
		
		if (formname == 'Teste')
		{
		
		var Phone=new String();
		 Phone = document.getElementById("TestDrive1:txtephone").value;
		
		 if (Phone.length != 13)
			{
				
				if (document.getElementById("TestDrive1:txtephone").value != '' )
					{
						document.getElementById("TestDrive1:txtephone").value = '';
						alert('Invalid Phone Number');	
						return false;
					}
			}
		}
		
		if (formname == 'Name')
		{
		//alert('ok');
		var Phone=new String();
		if ((document.getElementById("hidquick").value == null) || (document.getElementById("hidquick").value == 0))
		{
		
		 Phone = document.getElementById("Name1:txtphone").value;
		 
		 if (Phone.length != 13)
			{
				
				if (document.getElementById("Name1:txtphone").value != '' )
					{
						document.getElementById("Name1:txtphone").value = '';
						alert('Invalid Phone Number');	
						return false;
					}
			}
		}
		}
		else
		{
		
		if (document.getElementById("hidquick").value == 2)
				{
			 Phone = document.getElementById("Name2:txtphone").value;
		 
		 if (Phone.length != 13)
			{
				
				if (document.getElementById("Name2:txtphone").value != '' )
					{
						document.getElementById("Name2:txtphone").value = '';
						alert('Invalid Phone Number');	
						return false;
					}
			}
		}
		}
		
		
 	}
 	
 	function adminchk()
 	{
  		if (document.getElementById("chkhtml").checked !=false)
 			{
 				document.getElementById("chkhtml").checked =true
 				//document.getElementById("chktext").disabled =true
 				document.getElementById("chkxml").disabled =true
 				return true;
 			}
 		else if ((document.getElementById("chkhtml").checked ='false') && (document.getElementById("chkxml").disabled ='true'))
 			{
 				document.getElementById("chkhtml").checked =false
 				//document.getElementById("chktext").disabled =false
 				document.getElementById("chkxml").disabled =false
 				return true;
 			}
 		}
 		
 		/*function adminchktex()
 		{
 		if (document.getElementById("chktext").checked !=false)
 			{
 				document.getElementById("chktext").checked =true
 				document.getElementById("chkhtml").disabled =true
 				document.getElementById("chkxml").disabled =true
 				return true;
 			}
 		else if ((document.getElementById("chkhtml").disabled ='true') && (document.getElementById("chktext").checked ='false') && (document.getElementById("chkxml").disabled ='true'))
 			{
 				document.getElementById("chktext").checked =false
 				document.getElementById("chkhtml").disabled =false
 				document.getElementById("chkxml").disabled =false
 				return true;
 			}
 		}*/
 		function adminchkxm()
 		{
 		if (document.getElementById("chkxml").checked !=false)
 			{
 				document.getElementById("chkxml").checked =true
 				document.getElementById("chkhtml").disabled =true
 				//document.getElementById("chktext").disabled =true
 				return true;
 			}
 		else if ((document.getElementById("chkhtml").disabled ='true') && (document.getElementById("chkxml").checked ='false'))
 			{
 				document.getElementById("chkxml").checked =false
 				document.getElementById("chkhtml").disabled =false
 				//document.getElementById("chktext").disabled =false
 				return true;
 			}
 		}

	//document.getElementById("div_Opt").innerHTML=document.getElementById("div_inner").innerHTML;
	
	//Admin Email Check''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
	
function emailsplit1(email,nam)
	{
		
			
		if (email != '')
			{
				var arr=new Array();
				var str_email =new String();
				str_email=email;
				arr=str_email.split(";");
				//if (arr.length > 1)
				  //{
		 			for(i=0;i<arr.length;i++)
					  {
						str_email=emailCheck(arr[i]);
			 		 	if (str_email == false)
							{		
								if ((document.getElementById("txtmail").value != '') && (nam == 'txtmail'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtmail").value='';
										return false;
									}	
								if ((document.getElementById("txtmailname").value != '') && (nam == 'txtmailname'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtmailname").value='';
										return false;
									}		
								if ((document.getElementById("txtmailtest").value != '') && (nam == 'txtmailtest'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtmailtest").value='';
										return false;
									}		
								if ((document.getElementById("txtxmlget").value != '') && (nam == 'txtxmlget'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtxmlget").value='';
										return false;
									}		
								if ((document.getElementById("txtxmlname").value != '') && (nam == 'txtxmlname'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtxmlname").value='';
										return false;
									}		
								if ((document.getElementById("txtxmltest").value != '') && (nam == 'txtxmltest'))
									{
										alert(email+' Is Invalid');
										document.getElementById("txtxmltest").value='';
										return false;
									}		
							}
				    }			
				}
			}
			
					