function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

function getMakesYears(type) {
	setTimeout("addScript('"+type+"','makes')",100); 
	setTimeout("addScript('"+type+"','years')",500); 
}

function getMakesModels(type) {
	setTimeout("addScript('"+type+"','makes')",100); 
	setTimeout("addScript('"+type+"','models')",500); 
}

function getModelsYears(type) {
	setTimeout("addScript('"+type+"','models')",100); 
	setTimeout("addScript('"+type+"','years')",500); 
}

function addScript(type,section) {

	if (type == 'used') {
		boxtype = 'U';
		
		if (document.vehSelectU.make) {
			makeval = '&make='+document.vehSelectU.make.value;
		} else {
			makeval = '';
		}
		if (document.vehSelectU.model) {
			modelval = '&model='+document.vehSelectU.model.value;
		} else {
			modelval = '';
		}
		if (document.vehSelectU.year) {
			yearval = '&year='+document.vehSelectU.year.value;
		} else {
			yearval = '';
		}
		
	} else {
		boxtype = 'N';
		
		if (document.vehSelectN.make) {
			makeval = '&make='+document.vehSelectN.make.value;
		} else {
			makeval = '';
		}
		if (document.vehSelectN.model) {
			modelval = '&model='+document.vehSelectN.model.value;
		} else {
			modelval = '';
		}
		if (document.vehSelectN.year) {
			yearval = '&year='+document.vehSelectN.year.value;
		} else {
			yearval = '';
		}
	}
	

	
	var obj=new JSONscriptRequest(JSONUrl+'load_search.php?acttype=init_search&search_type='+type+'&select_style='+select_style+'&section='+section+makeval+modelval+yearval);

	obj.buildScriptTag(); // Build the script tag
	obj.addScriptTag(); // Execute (add) the script tag
}//end addScript

function specout(data) {
	document.getElementById('inner_'+data.sres.search_type+'_'+data.sres.section+'').innerHTML=data.sres.output;
}

function loadAll() {
	addScript('used','makes');
	addScript('used','models');
	addScript('used','years');
	addScript('new','makes');
	addScript('new','models');
	addScript('new','years');
}