// JavaScript Document

function getMake() {
	if(document.inventory.model.value!="") {
		$.get("intranet/get-make.php", { model:document.inventory.model.value }, function(data) {
				var listitems=data.split("|"); 
				with(document.inventory.make) {
					options.length=2;
					for(var i=0;i<listitems.length-1;i++) {
						options[i+2]=new Option(listitems[i],listitems[i],false,false);
					}
				}
				$("#makes").css({display:"block"});
			  } );
	}
}
function getModel(trailertype) {
	$.get("intranet/get-model.php", { ttype:trailertype }, function(data) {
				var listitems=data.split("|"); 
				with(document.inventory.model) {
					options.length=2;
					for(var i=0;i<listitems.length-1;i++) {
						options[i+2]=new Option(listitems[i],listitems[i],false,false);
					}
				}
				$("#models").css({display:"block"});
			  } );
}
function getModelYear() {
	if(document.inventory.model.value!="" && document.inventory.make.value!="") {
		$.get("intranet/get-year.php", { make:document.inventory.make.value,model:document.inventory.model.value }, function(data) {
				var listitems=data.split("|"); 
				document.inventory.syear.options.length=2;
				document.inventory.eyear.options.length=2;
				for(var i=1;i<listitems.length-1;i++) {
					document.inventory.syear.options[i+1]=new Option(listitems[i],listitems[i],false,false);
					document.inventory.eyear.options[i+1]=new Option(listitems[i],listitems[i],false,false);
				}
				$("#years").css({display:"block"});
			  } );
	}
}
function showSubmit() {
	if(document.inventory.model.value!="" && document.inventory.make.value!="" && document.inventory.syear.value!="" && document.inventory.eyear.value!="") {
		if(document.inventory.syear.value>document.inventory.syear.value) {
			alert("The starting year must be prior to or equal to the ending year.");
		} else {
			$("#submits").css({display:"block"});
		}
	}
}

function getLimitedInventory(mynewused,mymake,mymodel,mysyear,myeyear,mycrit,mydirection) {
	$.get("includes/inventory.php", { newused:mynewused,make:mymake,model:mymodel,syear:mysyear,eyear:myeyear,crit:mycrit,direction:mydirection }, function(data) {
		var listitems=data.split("|"); 
		$("#inventory").empty();
		$("#inventory").append("<tr><th width=\"3%\">&nbsp;</th><th width=\"30%\"><a href=\"javascript:getLimitedInventory('"+mynewused+"','"+mymake+"','"+mymodel+"','"+mysyear+"','"+myeyear+"','stockno','"+((mycrit=='stockno')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Inventory No</a></th><th width=\"25%\"><a href=\"javascript:getLimitedInventory('"+mynewused+"','"+mymake+"','"+mymodel+"','"+mysyear+"','"+myeyear+"','make','"+((mycrit=='make')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Make</a></th><th width=\"25%\"><a href=\"javascript:getLimitedInventory('"+mynewused+"','"+mymake+"','"+mymodel+"','"+mysyear+"','"+myeyear+"','model','"+((mycrit=='model')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Model</a></th><th width=\"10%\"><a href=\"javascript:getLimitedInventory('"+mynewused+"','"+mymake+"','"+mymodel+"','"+mysyear+"','"+myeyear+"','year','"+((mycrit=='year')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Year</a></th><th width=\"3%\">&nbsp;</th></tr>");
		for(var i=0;i<listitems.length-1;i++) {
			$("#inventory").append(listitems[i]);
		}
	  } );
	$("#data").css({display:"block"});
}

function getInventory(mynewused,mycrit,mydirection) {
	$.get("includes/inventory.php", { newused:mynewused,crit:mycrit,direction:mydirection }, function(data) {
		var listitems=data.split("|"); 
		$("#inventory").empty();
		$("#inventory").append("<tr><th width=\"3%\">&nbsp;</th><th width=\"30%\"><a href=\"javascript:getInventory('"+mynewused+"','stockno','"+((mycrit=='stockno')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Inventory No</a></th><th width=\"25%\"><a href=\"javascript:getInventory('"+mynewused+"','make','"+((mycrit=='make')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Make</a></th><th width=\"25%\"><a href=\"javascript:getInventory('"+mynewused+"','model','"+((mycrit=='model')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Model</a></th><th width=\"10%\"><a href=\"javascript:getInventory('"+mynewused+"','year','"+((mycrit=='year')?((mydirection=="ASC")?"DESC":"ASC"):"ASC")+"')\">Year</a></th><th width=\"3%\">&nbsp;</th></tr>");
		for(var i=0;i<listitems.length-1;i++) {
			$("#inventory").append(listitems[i]);
		}
	  } );
	$("#makes").css({display:"none"});
	$("#years").css({display:"none"});
	$("#submits").css({display:"none"});
}

$(document).ready(function() {
	$(".stripme tr").mouseover(function() {
		$(this).addClass("over");
	}).mouseout(function() {
		$(this).removeClass("over");
	});
	$(".stripeme tr:even").addClass("alt");
});
