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="688"';
	if (width >= 688) 
	{
		var newwidth = 'width="688"';
	}
	document.getElementById("loadarea2").innerHTML = '<img ' + newwidth + ' src="' + url + '">';
}

// 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="688"';
	if (width >= 688) 
	{
		var newwidth = 'width="688"';
	}
	document.getElementById("loadarea2").innerHTML = '<img ' + newwidth + ' src="' + url + '/' + imgstr + '">';
}

// 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, down_payment, interest, years)
{
	var x = ((principal - down_payment) * interest / (12 * (1 - Math.pow(1 + (interest / 12), (-years * 12)))));
	return Math.floor(x * 100) / 100
}

function ShowPayments()
{
	var x = CalculatePayments(document.jsForm.jsPrincipal.value, document.jsForm.jsDownPayment.value, document.jsForm.jsInterest.value / 100, document.jsForm.jsYears.value);
	if (isNaN(x)) 
	{
		document.jsForm.jsResult.value = 'Could not compute';
	}
	else 
	{
		document.jsForm.jsAmtFin.value = document.jsForm.jsPrincipal.value - document.jsForm.jsDownPayment.value;
		document.jsForm.jsResult.value = x;
	}
}

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 = "";
		
	}
	
}

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;
var zxcDelay = 10;
var zxcAddCursor = true;

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];
}

