// JavaScript Document

function getmake(caryear,vehtype){
var theresponse
var url="../dealerfiles/ajax.asp";
url=url+"?getwhat=Make";
url=url+"&caryear="+caryear;
url=url+"&vehtype="+vehtype;
new Ajax(url, {
		method: 'get',
		onComplete: function(theresponse){
		if (theresponse != ''){
				var x
				var theresponse_array = theresponse.split("|");
				document.search3.make.options.length=theresponse_array.length+1;
				document.search3.make.options[0].value="";
				document.search3.make.options[0].text="-Select-";
				for (x in theresponse_array){
					var thevalue = theresponse_array[x];
					if (x < theresponse_array.length){
						document.search3.make.options[parseInt(x)+1].value=thevalue;
						document.search3.make.options[parseInt(x)+1].text=thevalue;
					}
				}	
        }else{
			document.search3.make.options.length=1;
			document.search3.make.options[0].value="";
			document.search3.make.options[0].text="-None Found-";
		}
     }}).request();
}

function gemodel(caryear,vehtype,make){
var theresponse
var url="../dealerfiles/ajax.asp";
url=url+"?getwhat=model";
url=url+"&caryear="+caryear;
url=url+"&vehtype="+vehtype;
url=url+"&make="+make;

new Ajax(url, {
		method: 'get',
		onComplete: function(theresponse){
if (theresponse != ''){
				var x
				var theresponse_array = theresponse.split("|");
				document.search3.model.options.length=theresponse_array.length+1;
				document.search3.model.options[0].value="";
				document.search3.model.options[0].text="-Select-";
				for (x in theresponse_array){
					var thevalue = theresponse_array[x];
					if (x < theresponse_array.length){
						document.search3.model.options[parseInt(x)+1].value=thevalue;
						document.search3.model.options[parseInt(x)+1].text=truncate(thevalue,12);
					}
				}	
        }else{
			document.search3.model.options.length=1;
			document.search3.model.options[0].value="";
			document.search3.model.options[0].text="-None Found-";
		}
	 }}).request();
}

function truncate(x, maxlen)
{
/* given a string and a maximum length for the string, this routine
returns the same string truncated to the maximum length. In addition,
if the string was truncated, "..." is added to the end, again not to
exceed the maximum length.

E.g. ellipsis("abcdef", 4) = "a..."
ellipsis("abcdef", 6) = "abcdef"
*/

if (x.length <= maxlen)
return x
else if (maxlen < 4)
return x.substring(0, maxlen) // no room for ellipsis
else return x.substring(0, maxlen-3) + "...";
}