
var httpRequest = false;

if (window.XMLHttpRequest) {
	if (typeof XMLHttpRequest != 'undefined') {
		try {
			httpRequest = new XMLHttpRequest();
		} catch (e) {
			httpRequest = false;
		}
	}
} else if (window.ActiveXObject) {
	try {
		httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
		try {
			httpRequest = newActiveXObject('Microsoft.XMLHTTP');
		} catch (e) {
			httpRequest = false;
		}
	}
}


function searchUpdate(elementID, elementCounter, changedElement) {
		
		if (elementID[elementCounter] == "column_left_search_manufacturer") var scriptURL = "/includes/menu/searchManufacturer.php?";
		if (elementID[elementCounter] == "column_left_search_make") var scriptURL = "/includes/menu/searchMakes.php?";
		if (elementID[elementCounter] == "column_left_search_model") var scriptURL = "/includes/menu/searchModel.php?";
		
		scriptURL += "&search_startYear=" + document.getElementById("search_startYear").value;
		scriptURL += "&search_endYear=" + document.getElementById("search_endYear").value;
		scriptURL += "&search_manufacturer=" + document.getElementById("search_manufacturer").value;
		scriptURL += "&search_make=" + document.getElementById("search_make").value;
		scriptURL += "&search_model=" + document.getElementById("search_model").value;
		scriptURL += "&rvType=" + document.getElementById("rvType").value;
		

		httpRequest.open("GET", scriptURL, true);
		httpRequest.send(null);
		httpRequest.onreadystatechange = function() { checkState(elementID, elementCounter, changedElement); };
		
		function checkState(elementID, elementCounter, changedElement) {
			 if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					var mainbodyContent = httpRequest.responseText;
					
					document.getElementById(elementID[elementCounter]).innerHTML = mainbodyContent;
					//alert(elementCounter+1+":"+elementID.length);
					if (elementCounter+1 < elementID.length) {
						
						searchUpdate(elementID, elementCounter+1, changedElement);	
					}
				} //End status if
			} //End readyState If
		} //End CheckState-Function
}

function preownedUpdate(loadUnit) {
	
		if (loadUnit == "") {
			var preOwnedType = document.getElementById("preOwnedRvType").value;
		} else {
			var preOwnedType = loadUnit;
			document.getElementById("preOwnedRvType").value = loadUnit;
		}
		
		document.getElementById("rv_image_preowned").innerHTML = '<img src="/images/RVs/RVMain/'+preOwnedType.replace(" ", "")+'.png" width="160px" alt="'+preOwnedType+'" border="0" />';
		
		
		if (preOwnedType != "") {
			httpRequest.open("GET", "/includes/functions/loadPreowned.php?type="+preOwnedType, true);
			httpRequest.send(null);
			httpRequest.onreadystatechange = function() { checkState(); };
		}
	
		function checkState() {
			 if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					var mainbodyContent = httpRequest.responseText;
					
					document.getElementById("preownedDiv").innerHTML = mainbodyContent;
					LyteBox();
				} //End status if
			} //End readyState If
		} //End CheckState-Function
}

 ////////Specs
function specsSelect(el_id) {
	
		if (el_id == "") {
			var specsType = document.getElementById("specsRvType").value;
		} else {
			var specsType = el_id;
			document.getElementById("specsRvType").value = specsType;
		}
		
		document.getElementById("rv_image_specs").innerHTML = '<img src="/images/RVs/RVMain/'+specsType.replace(" ", "")+'.png" width="160px" alt="'+specsType+'" border="0" />';
		document.getElementById("specsDIV").innerHTML = "";
		
		if (specsType != "") {
			
			httpRequest.open("GET", "/includes/functions/loadSpecs.php?type="+specsType, true);
			httpRequest.send(null);
			httpRequest.onreadystatechange = function() { checkState(); };
		}
	
		function checkState() {
			 if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					var mainbodyContent = httpRequest.responseText;
					
					document.getElementById("specsDIV").innerHTML = mainbodyContent;
				} //End status if
			} //End readyState If
		} //End CheckState-Function
}

function changePage(newPage, refreshDrops) {
		
		if (newPage == 0) newPage = document.getElementById("curPage").value;
		
		var newInvURL = "&type="+document.getElementById("newType").value;
		newInvURL += "&year="+document.getElementById("newYear").value;
		newInvURL += "&manuf="+document.getElementById("newManuf").value;
		newInvURL += "&make="+document.getElementById("newMake").value;
		newInvURL += "&model="+document.getElementById("newModel").value;
		
		httpRequest.open("GET", "/includes/functions/loadNewInv.php?newPage="+newPage+newInvURL, true);
		httpRequest.send(null);
		httpRequest.onreadystatechange = function() { checkState(refreshDrops); }
		
		function checkState(refreshDrops) {
			 if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					var mainbodyContent = httpRequest.responseText;
					
					document.getElementById("newInv_results").innerHTML = mainbodyContent;
					updateNewDrops(refreshDrops);
				} //End status if
			} //End readyState If
		} //End CheckState-Function
}

function updateNewDrops(refreshDrops) {
	//alert(refreshDrops);
	if (refreshDrops == 0) { var page = "year.php"; var type = document.getElementById("newType").value; }
	if (refreshDrops == 1) { var page = "manuf.php"; var type = document.getElementById("newYear").value+"_"+document.getElementById("newType").value; }
	if (refreshDrops == 2) { var page = "make.php"; var type = document.getElementById("newManuf").value+"_"+document.getElementById("newYear").value+"_"+document.getElementById("newType").value; }
	if (refreshDrops == 3) { var page = "model.php"; var type = document.getElementById("newMake").value+"_"+document.getElementById("newManuf").value+"_"+document.getElementById("newYear").value+"_"+document.getElementById("newType").value; }
	
	if (refreshDrops != 4) { 
		httpRequest.open("GET", "/includes/functions/newinv/"+page+"?type="+type, true);
		httpRequest.send(null);
		httpRequest.onreadystatechange = function() { checkState(refreshDrops); }
	}
	
	function checkState(refreshDrops) {
		 if (httpRequest.readyState == 4) {
			if (httpRequest.status == 200) {
				var mainbodyContent = httpRequest.responseText;
				
				if (refreshDrops == 0) { var el = "year_drop"; }
				if (refreshDrops == 1) { var el = "manuf_drop"; }
				if (refreshDrops == 2) { var el = "make_drop"; }
				if (refreshDrops == 3) { var el = "model_drop"; }

				//alert(el);
				document.getElementById(el).innerHTML = mainbodyContent;
				updateNewDrops(refreshDrops+1);
			} //End status if
		} //End readyState If
	} //End CheckState-Function
}

function loadSpecials() {
		
		httpRequest.open("GET", "/includes/functions/homeSpecials.php", true);
		httpRequest.send(null);
		httpRequest.onreadystatechange = function() { checkState(); }
		
		function checkState() {
			
			 if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) {
					var mainbodyContent = httpRequest.responseText;
					
					document.getElementById("homeSpecials").innerHTML = mainbodyContent;
				} //End status if
			} //End readyState If
		} //End CheckState-Function
}