// JavaScript Document

function getmake(caryear,vehtype){
var theresponse
var theurl="../dealerfiles/ajax.asp"
+"?getwhat=Make"
+"&caryear="+caryear
+"&vehtype="+vehtype

$.ajax({
  url: theurl,
  success: function(data) {
    $('.result').html(data);
    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-";
	}
  }
});

}


function getmake2(caryearfrom,caryearto,vehtype){
var theresponse
var theurl="../dealerfiles/ajax.asp"
+"?getwhat=Make2"
+"&caryearfrom="+caryearfrom
+"&caryearto="+caryearto
+"&vehtype="+vehtype;

$.ajax({
  url: theurl,
  success: 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 MAKE";
				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="NO MATCHES - SELECT ANOTHER DATE RANGE";
		}
  }
});

}

function getmodel(caryear,vehtype,make){
var theresponse
var theurl="../dealerfiles/ajax.asp"
+"?getwhat=model"
+"&caryear="+caryear
+"&vehtype="+vehtype
+"&make="+make;

$.ajax({
  url: theurl,
  success: function(theresponse) {
    $('.result').html(data);
    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-";
		}
  }
});


}


function getmodel2(caryearfrom,caryearto,vehtype,make){
var theresponse
var theurl="../dealerfiles/ajax.asp"
	+"?getwhat=model"
	+"&caryearfrom="+caryearfrom
	+"&caryearto="+caryearto
	+"&vehtype="+vehtype
	+"&make="+make

$.ajax({
  url: theurl,
  success: 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 MODEL";
				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";
		}
  }
});


}


function getbodytype2(caryearfrom,caryearto,bodytype,make,model){
var theresponse
var theurl="../dealerfiles/ajax.asp"
	+"?getwhat=bodytype"
	+"&caryearfrom="+caryearfrom
	+"&caryearto="+caryearto
	+"&bodytype="+bodytype
	+"&make="+make
	+"&model="+model

$.ajax({
  url: theurl,
  success: function(theresponse) {
    if (theresponse != ''){
				var x
				var theresponse_array = theresponse.split("|");
				document.search3.bodytype.options.length=theresponse_array.length+1;
				document.search3.bodytype.options[0].value="";
				document.search3.bodytype.options[0].text="SELECT BODY TYPE";
				for (x in theresponse_array){
					var thevalue = theresponse_array[x];
					if (x < theresponse_array.length){
						document.search3.bodytype.options[parseInt(x)+1].value=thevalue;
						document.search3.bodytype.options[parseInt(x)+1].text=truncate(thevalue,12);
					}
				}	
        }else{
			document.search3.bodytype.options.length=1;
			document.search3.bodytype.options[0].value="";
			document.search3.bodytype.options[0].text="NONE FOUND";
		}
  }
});


}


function getoptlabel(vehtype){
	var theresponse
	var theurl="../dealerfiles/ajaxopt.asp"
	+"?getwhat=OptLabel"
	+"&vehtype="+vehtype

	$.ajax({
  		url: theurl,
  		success: function(data) {
    		$('.result').html(data);
    		if (theresponse != ''){
				var x
				var theresponse_array = theresponse.split("|");
				for (x in theresponse_array){
					var thevalue = theresponse_array[x];
					document.getElementById('caropt'[x]).innerHTML = "<strong>" +thevalue +"</strong>";
				}
			}
  		}
	});

}


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) + "...";
}
