
// Change models based on make selection
// Ajax function. This is a re-write from the one
// before. This one works in all browsers.
var xmlHttp

function showModels(str) {
	if (str.length==0) { 
  		document.getElementById("txtHint").innerHTML="";
  		return;
  	}
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="makemodel.php";
	url=url+"?make="+str;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState==4) { 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}catch (e){
 	 	// Internet Explorer
  		try {
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}catch (e){
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}

// A little less java and ajax to
// show images from thumbnail view
function showImage(url, imgstr) { 
	var newImg = new Image();
	newImg.src = url+'/'+imgstr;
	var height = newImg.height;
	var width = newImg.width;
	var newwidth = 'width="300"';
	var newheight = 'height="250"';
	if(width >= 300) {
		var newwidth = 'width="300"';
	}
	document.getElementById("loadarea2").innerHTML = '<img '+newwidth+' '+newheight+' src="'+url+'" class="showimg">';
}
// A little less java and ajax to
// show images from thumbnail view
function showImage2(url, imgstr) { 
	var newImg = new Image();
	newImg.src = url+'/'+imgstr;
	var height = newImg.height;
	var width = newImg.width;
	var newwidth = 'width="300"';
	var newheight = 'height="250"';
	if(width >= 300) {
		var newwidth = 'width="300"';
	}
	document.getElementById("loadarea2").innerHTML = '<img '+newwidth+' '+newheight+' src="'+url+'/'+imgstr+'" class="showimg">';
}
// Little function to show and hide
// divs as needed
function toggleDiv(divid){
   if(document.getElementById(divid).style.display == 'none'){
     document.getElementById(divid).style.display = 'block';
   }else{
     document.getElementById(divid).style.display = 'none';
   }
}

// Monthly payment calculator
function CalculatePayments(principal, illinois, cook, chicago, down_payment, bank_value, trade_value, interest, years, doc, title, register) {
	
	var to_tax = principal - (-doc) - trade_value;
	var total = principal - (-doc) - (-to_tax * illinois) - (-to_tax * chicago) - (-to_tax * cook) - (-title) - (-register);
	var financed = total - (-bank_value) - trade_value - down_payment;
	var monthly = (financed * Math.pow(1+(interest/100/12), years)) * (interest/100/12) / (1 - Math.pow(1+(interest/100/12), years));
	return Math.ceil(Math.abs(monthly)*100)/100;
	
	// var payoff = -bank_value;
	//var docfee = 0 - doc;
	//var fees = 0 - title - register;
	//var x =((((principal - docfee - down_payment - payoff - trade_value) * (1 + (illinois + cook + chicago))) - fees) * interest / (12.123 * (1 - Math.pow(1 + (interest / 12.123), (-years * 12.123)))));
	//var makeup = x * (1.008);
	//return Math.floor(makeup * 100) / 100
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
	
function ShowPayments() {
	var x = CalculatePayments(document.jsForm.jsPrincipal.value, document.jsForm.jsSalesTax.value / 100, document.jsForm.jsCookCounty.value / 100, document.jsForm.jsChicago.value / 100, document.jsForm.jsDownPayment.value, document.jsForm.jsBankValue.value, document.jsForm.jsTradeValue.value, document.jsForm.jsInterest.value, document.jsForm.jsYears.value * 12, document.jsForm.docfee.value, document.jsForm.titlefee.value, document.jsForm.jsRegister.value);
	
	var to_tax = document.jsForm.jsPrincipal.value - (-document.jsForm.docfee.value) - document.jsForm.jsTradeValue.value;
	var total = document.jsForm.jsPrincipal.value - (-document.jsForm.docfee.value) - (-to_tax * document.jsForm.jsSalesTax.value / 100) - (-to_tax * document.jsForm.jsChicago.value / 100) - (-to_tax * document.jsForm.jsCookCounty.value / 100) - (-document.jsForm.titlefee.value) - (-document.jsForm.jsRegister.value);
	var financed = total - (-document.jsForm.jsBankValue.value) - document.jsForm.jsTradeValue.value - document.jsForm.jsDownPayment.value;
	var y = Math.ceil(Math.abs(financed));
	
	if (isNaN(x)) {
		document.jsForm.jsResult.value = 'Could not compute';
	}else{
		document.jsForm.jsResult.value = x;
		document.jsForm.jsLoan.value = addCommas(y);
	}
}

function moveOnMax(field,nextFieldID){
  if(field.value.length >= field.maxLength){
    document.getElementById(nextFieldID).focus();
  }
}
function numbersonly(myfield, e, dec){
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}
function data_copy() {
	if(document.form1.copy[0].checked){
		document.form1.coxstreetnumber.value=document.form1.streetnumber.value;
		document.form1.coxstreetname.value=document.form1.streetname.value;
		document.form1.coxstreettype.value=document.form1.streettype.value;
		document.form1.coxaptsuite.value=document.form1.aptsuite.value;
		document.form1.coxcity.value=document.form1.city.value;
		document.form1.coxstate.value=document.form1.state.value;
		document.form1.coxpostal.value=document.form1.postal.value;
		document.form1.coxhmphone1.value=document.form1.hmphone1.value;
		document.form1.coxhmphone2.value=document.form1.hmphone2.value;
		document.form1.coxhmphone3.value=document.form1.hmphone3.value;
		document.form1.coxaddressyears.value=document.form1.addressyears.value;
		document.form1.coxaddressmonths.value=document.form1.addressmonths.value;
		document.form1.coxhousestatus.value=document.form1.housestatus.value;
	}else{
		document.form1.coxstreetnumber.value="";
		document.form1.coxstreetname.value="";
		document.form1.coxstreettype.value="";
		document.form1.coxaptsuite.value="";
		document.form1.coxcity.value="";
		document.form1.coxstate.value="";
		document.form1.coxpostal.value="";
		document.form1.coxhmphone1.value="";
		document.form1.coxhmphone2.value="";
		document.form1.coxhmphone3.value="";
		document.form1.coxaddressyears.value="";
		document.form1.coxaddressmonths.value="";
		document.form1.coxhousestatus.value="";
	
	}

}
<!--

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj){
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	if(document.getElementById('cox').checked) {
		// Enter name of mandatory fields
		var fieldRequired = Array("firstname", "lastname", "emailaddress", "ssn1", "ssn2", "ssn3", "birthdate1", "birthdate2", "birthdate3"
		, "streetnumber", "streetname", "city", "state", "postal", "hmphone1", "hmphone2", "hmphone3", "addressyears", "housestatus", "housepay"
		, "employedstatus", "employername", "workphone1", "workphone2", "workphone3", "employertimeyears", "income", "coxrelationship"		
		,"coxfirstname", "coxlastname", "coxssn1", "coxssn2", "coxssn3", "coxbirthdate1", "coxbirthdate2", "coxbirthdate3"
		, "coxstreetnumber", "coxstreetname", "coxcity", "coxstate", "coxpostal", "coxhmphone1", "coxhmphone2", "coxhmphone3", "coxaddressyears", "coxaddressmonths", "coxhousestatus", "coxhousepay"
		, "coxemployedstatus", "coxemployername", "coxworkphone1", "coxworkphone2", "coxworkphone3", "coxemployertimeyears", "coxincome", "methodid");
		// Enter field description to appear in the dialog box
		var fieldDescription = Array("First Name", "Last Name", "Email Address", "Social Security 1", "Social Security 2", "Social Security 3"
		, "Birth Date Month", "Birth Date Day", "Birth Date Year", "Street Number", "Street Name", "City", "State", "Postal/Zip", "Home Phone Area Code", "Home Phone Prefix", "Home Phone Suffix"
		, "Years at address", "Housing Status", "Mtg Payment or Rent", "Employment Status", "Employers Name", "Work Phone Area Code", "Work Phone Prefix", "Work Phone Suffix"
		, "Years employed", "Income", "Co-Applicants Relationship"		
		,"Co-Applicants First Name", "Co-Applicants Last Name", "Co-Applicants Social Security 1", "Co-Applicants Social Security 2", "Co-Applicants Social Security 3"
		, "Co-Applicants Birth Date Month", "Co-Applicants Birth Date Day", "Co-Applicants Birth Date Year", "Co-Applicants Street Number", "Co-Applicants Street Name", "Co-Applicants City", "Co-Applicants State", "Co-Applicants Postal/Zip", "Co-Applicants Home Phone Area Code", "Co-Applicants Home Phone Prefix", "Co-Applicants Home Phone Suffix"
		, "Co-Applicants Years at address", "Co-Applicants Months atr address", "Co-Applicants Housing Status", "Co-Applicants Mtg Payment or Rent", "Co-Applicants Employment Status", "Co-Applicants Employers Name", "Co-Applicants Work Phone Area Code", "Co-Applicants Work Phone Prefix", "Co-Applicants Work Phone Suffix"
		, "Co-Applicants Years employed", "Co-Applicants Income", "Contact Method");
	}else{
		// Enter name of mandatory fields
		var fieldRequired = Array("firstname", "lastname", "emailaddress", "ssn1", "ssn2", "ssn3", "birthdate1", "birthdate2", "birthdate3"
		, "streetnumber", "streetname", "city", "state", "postal", "hmphone1", "hmphone2", "hmphone3", "addressyears", "housestatus", "housepay"
		, "employedstatus", "employername", "workphone1", "workphone2", "workphone3", "employertimeyears", "income", "methodid");
		// Enter field description to appear in the dialog box
		var fieldDescription = Array("First Name", "Last Name", "Email Address", "Social Security 1", "Social Security 2", "Social Security 3"
		, "Birth Date Month", "Birth Date Day", "Birth Date Year", "Street Number", "Street Name", "City", "State", "Postal/Zip", "Home Phone Area Code", "Home Phone Prefix", "Home Phone Suffix"
		, "Years at address", "Housing Status", "Mtg Payment or Rent", "Employment Status", "Employers Name", "Work Phone Area Code", "Work Phone Prefix", "Work Phone Suffix"
		, "Years employed", "Income", "Contact Method");
		
	}
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == 0){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
// -->

// Function to open new window
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos) {
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}else if((pos!="center" && pos!="random") || pos==null){
		LeftPosition=0;TopPosition=20;
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		nav_welcome_over = newImage("{$templateurl}/images/nav_welcome_over.gif");
		nav_listinventory_over = newImage("{$templateurl}/images/nav_listinventory_over.gif");
		nav_searchinventory_over = newImage("{$templateurl}/images/nav_searchinventory_over.gif");
		nav_contactus_over = newImage("{$templateurl}/images/nav_contactus_over.gif");
		findus_over = newImage("{$templateurl}/images/findus_over.gif");
		nav_specials_over = newImage("{$templateurl}/images/nav_specials_over.gif");
		moreinfo_over = newImage("{$templateurl}/images/moreinfo_over.gif");
		searchbutton_over = newImage("{$templateurl}/images/searchbutton_over.gif");
		submit_on = newImage("{$templateurl}/images/submit_on.gif");
		reset_on = newImage("{$templateurl}/images/reset_on.gif");
		getdirections_over = newImage("{$templateurl}/images/getdirections_over.gif");
		preloadFlag = true;
	}
}
var zxcZIndex=0;         // the base Z-Index for the images
var zxcDelay=10;         //  the global zoom speed may be specified in addition to the call
var zxcAddCursor=true;   // true to add a 'hand'/'pointer' cursor to the Zoom Image, false for no cursor

// Zoom In/Zoom Out zxcPart2 (15-04-2006)
// by Vic Phillips http://www.vicsjavascripts.org.uk
//

// Functional Code - N0 NEED to Change

var zxcOOPCnt=0;
var zxcCursor=document.all?'hand':'pointer';
zxcZIndex=zxcZIndex||1;
var zxcZIndx=zxcZIndex;
zxcDelay=zxcDelay||10;

function zxcZoom(zxcobj,zxcph,zxcmw,zxcmh,zxcspd,zxcopt){
 if (typeof(zxcobj)=='string'){ zxcobj=document.getElementById(zxcobj); }
 var zxcphoto;
 if (zxcobj.tagName.toUpperCase()=='IMG'){
  zxcphoto=zxcph||zxcobj.src;
  if (zxcphoto.length<5){ zxcphoto=zxcobj.src; }
 }
 var zxcspd=zxcspd||1;
 var zxcopt=zxcopt||null;
 if (!zxcobj.zxcoop){ zxcobj.zxcoop=new zxcOOPZoom(zxcobj,zxcphoto,zxcmw,zxcmh,zxcspd,zxcopt,zxcopt); }
 clearTimeout(zxcobj.zxcoop.to);
 zxcobj.zxcoop.inc*=-1
 if (zxcobj.zxcoop.large.load){ zxcobj.src=zxcobj.zxcoop.large.src; }
 zxcZIndx++;
 zxcStyle(zxcobj,{zIndex:(zxcZIndx+'')});
 zxcobj.zxcoop.zoom();
}

function zxcOOPZoom(zxcobj,zxcph,zxcmw,zxcmh,zxcspd,zxcopt){
 this.obj=zxcobj;
 this.objS=zxcobj.style;
 this.clone=zxcobj.cloneNode(true);
 this.zxcspd=zxcspd;
 this.zxct=zxcPos(zxcobj)[1];
 this.zxcl=zxcPos(zxcobj)[0];
 zxcStyle(this.obj,{position:'absolute',zIndex:(zxcZIndex*1+1+''),width:zxcobj.offsetWidth+'px',height:zxcobj.offsetHeight+'px',left:this.zxcl+'px',top:this.zxct+'px'});
 if (zxcAddCursor){ zxcStyle(this.obj,{cursor:zxcCursor}); }
 this.minw=zxcobj.offsetWidth;
 this.minh=zxcobj.offsetHeight;
 this.center=zxcopt;
 this.maxw=zxcmw;
 this.maxh=zxcmh||zxcmw*this.minh/this.minw;
 this.thumb=zxcobj.src;
 this.large=new Image();
 this.large.obj=this.obj;
 if (zxcph){ this.large.onload=function(){ this.load=true; this.obj.src=this.src; }; this.large.src=zxcph; }
 zxcobj.parentNode.insertBefore(this.clone,zxcobj);
 this.inc=((this.maxw-this.minw)/100);
 this.inc=-this.inc*this.zxcspd;
 this.ratio=(this.maxh/this.maxw);
 this.ref='zxc'+zxcOOPCnt;
 window[this.ref]=this;
 this.to=null;
 zxcOOPCnt++;
}

zxcOOPZoom.prototype.setTimeOut=function(zxcf,zxcd){
 this.to=setTimeout("window."+this.ref+"."+zxcf,zxcd);
}

zxcOOPZoom.prototype.zoom=function(){
 this.w=parseInt(this.objS.width)+this.inc; this.h=parseInt(this.objS.width)*this.ratio;
 zxcStyle(this.obj,{width:(this.w)+'px',height:(this.h)+'px'});
 this.w=parseInt(this.objS.width); this.h=parseInt(this.objS.height);
 if (this.center){ zxcStyle(this.obj,{top:(this.zxct-(this.h-this.minh)/2)+'px',left:(this.zxcl-(this.w-this.minw)/2)+'px'}); }
 if ((this.inc>0&&this.w<this.maxw)||(this.inc<0&&this.w>this.minw)){ this.setTimeOut('zoom();',zxcDelay); }
 else {
  if (this.inc>0){ zxcStyle(this.obj,{width:this.maxw+'px',height:this.maxh+'px'}); }
  else {
   zxcStyle(this.obj,{zIndex:zxcZIndex,width:this.minw+'px',height:this.minh+'px',top:(this.zxct)+'px',left:(this.zxcl)+'px'});
   zxcZIndx--;
   this.obj.src=this.thumb;
  }
 }
}

function zxcStyle(zxcele,zxcstyle){
 for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; }
}

function zxcPos(zxc){
 zxcObjLeft=zxc.offsetLeft;
 zxcObjTop=zxc.offsetTop;
 while(zxc.offsetParent!=null){
  zxcObjParent=zxc.offsetParent;
  zxcObjLeft+=zxcObjParent.offsetLeft;
  zxcObjTop+=zxcObjParent.offsetTop;
  zxc=zxcObjParent;
 }
 return [zxcObjLeft,zxcObjTop];
}