function getHTTPObject() {
	var xmlhttp;
/*@cc_on
	@if (@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@else
		xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
var makeurl = "pullmodels.asp?make=";
var modelurl = "pullcapacities.asp?model=";
var modelCapurl = "pullModelCapacities.asp?make=";
var isWorking = false;
var isCapWorking = false;
var http = getHTTPObject();
var httpCap = getHTTPObject();
function changeListBgColor() {
	if( document.cartdsp.capacity.length < 6 ) { document.cartdsp.capacity.length = 5; }
}
function handleModelCapHttpResponse() {
	if (httpCap.readyState == 4) {
		isCapWorking = false;
		if (httpCap.responseText.indexOf('invalid') == -1) {
			//alert(httpCap.responseText);
			results = httpCap.responseText.split("|");
			thedropdown = document.cartdsp.capacity;
			//document.cartdsp.capacity.style.backgroundColor="#EEFEE7";
			//highlightBg = setInterval("changeListBgColor()", 600);
			thedropdown.options.length = 0;
			var x = 0;
			var counter = 1;
			thedropdown.options[0] = new Option("Select an Item","");
			while(x<results.length-1) {
				thedropdown.options[counter] = new Option(results[x+1],results[x]);
				x++; x++; counter++; }
			isCapWorking = false;
			fade('capacity', 238, 254, 231, 255, 255, 255);
		}
		if((!results) || results == "") { thedropdown.options[0] = new Option("Not Applicable",""); }
	}
}

function pullModelCapacities() {
	var dropdownValue = document.getElementById("make").value;
	httpCap.open("GET", modelCapurl + escape(dropdownValue), true);
	isCapWorking = true;
	httpCap.onreadystatechange = handleModelCapHttpResponse;
	httpCap.send(null);
}

function handleModelHttpResponse() {
	if (http.readyState == 4) {
		isWorking = false;
		if (http.responseText.indexOf('invalid') == -1) {
			//alert(http.responseText);
			results = http.responseText.split("|");
			thedropdown = document.cartdsp.model;
			thedropdown.options.length = 0;
			document.cartdsp.capacity.length = 0; // Also Remove Capacities because they changed Make
			document.cartdsp.capacity.options[0] = new Option("Capacity","");
			document.cartdsp.model.style.backgroundColor="#EEFEE7";
			document.cartdsp.capacity.style.backgroundColor="#EEFEE7";
			changeListBgColor();
			var x = 0;
			var counter = 1;
			thedropdown.options[0] = new Option("Select a Model","");
			while(x<results.length-1) {
				thedropdown.options[counter] = new Option(results[x+1],results[x]);
				x++; x++; counter++;
			}
			pullModelCapacities();
			fade('model', 238, 254, 231, 255, 255, 255);
			fade('capacity', 238, 254, 231, 255, 255, 255);
			isWorking = false;
		}
		if((!results) || results == "") { thedropdown.options[0] = new Option("None Available",""); }
	}
}

function handleCapacityHttpResponse() {
	if (http.readyState == 4) {
		isWorking = false;
		if (http.responseText.indexOf('invalid') == -1) {
			//alert(http.responseText);
			results = http.responseText.split("|");
			thedropdown = document.cartdsp.capacity;
			document.cartdsp.capacity.style.backgroundColor="#EEFEE7";
			changeListBgColor();
			thedropdown.options.length = 0;
			var x = 0;
			var counter = 1;
			thedropdown.options[0] = new Option("Select an Item","");
			while(x<results.length-1) {
				thedropdown.options[counter] = new Option(results[x+1],results[x]);
				x++; x++; counter++; }
			isWorking = false;
		fade('capacity', 238, 254, 231, 255, 255, 255); 
		}
		if((!results) || results == "") { thedropdown.options[0] = new Option("Not Applicable",""); }
	}
}
function updateDropdowns(dropdownName) {
	if(document.getElementById(dropdownName).value != "") {
		if (!isWorking) {
			var dropdownValue = document.getElementById(dropdownName).value;
			var dropdownDom = document.getElementById(dropdownName);
			if(dropdownName == "make") {
				document.cartdsp.makeLabel.value = dropdownDom.options[dropdownDom.selectedIndex].text;
				http.open("GET", makeurl + escape(dropdownValue), true);
				isWorking = true;
				http.onreadystatechange = handleModelHttpResponse;
				http.send(null);
			} else if(dropdownName == "model") {
				document.cartdsp.modelLabel.value = dropdownDom.options[dropdownDom.selectedIndex].text;
				http.open("GET", modelurl + escape(dropdownValue), true);
				isWorking = true;
				http.onreadystatechange = handleCapacityHttpResponse;
				http.send(null);
			} 
		}
	}
}
