function popDrop(val) {
	document.getElementById("series").options.length = 0;
	document.getElementById("model").disabled = false;
	document.getElementById("series").disabled = false;
	
	if (document.getElementById("category").value == ""){
	document.getElementById("series").options.length = 0;
	document.getElementById("series").disabled = true;
	document.getElementById("model").disabled = true;
	var opt1 = document.createElement("option");
	document.getElementById("series").options.add(opt1);
    opt1.text = "Select Category";
    opt1.value = "";
	document.getElementById("model").options.length = 0;
	var opt2 = document.createElement("option");
	document.getElementById("model").options.add(opt2);
    opt2.text = "Select Series";
    opt2.value = "";
	}else{
	
	var opt4 = document.createElement("option");
	document.getElementById("series").options.add(opt4);
    opt4.text = "All";
    opt4.value = "";
	
	dd = eval(val);

	for(x=0;x<dd.length;x++) {
       	var opt = document.createElement("option");
		document.getElementById("series").options.add(opt);
       	opt.text = dd[x];
       	opt.value = dd[x];
	}
	
	popDrop2(document.getElementById("series").value)

}
}

function popDrop2(val) {
	document.getElementById("model").options.length = 0;
	document.getElementById("model").disabled = false;
	var opt3 = document.createElement("option");
	document.getElementById("model").options.add(opt3);
    opt3.text = "All";
    opt3.value = "";
	
	if (document.getElementById("series").value == ""){
	document.getElementById("model").options.length = 0;
	document.getElementById("model").disabled = true;	
	var opt1 = document.createElement("option");
	document.getElementById("model").options.add(opt1);
    opt1.text = "All";
    opt1.value = "";
	}else{
	dd = eval(val);

	for(x=0;x<dd.length;x++) {
       	var opt = document.createElement("option");
		document.getElementById("model").options.add(opt);
       	opt.text = dd[x];
       	opt.value = dd[x];
	}
}
}

function popDrop3(val) {
	document.getElementById("series").options.length = 0;
	document.getElementById("series").disabled = false;
	
	if (document.getElementById("category").value == ""){
	document.getElementById("series").options.length = 0;
	document.getElementById("series").disabled = true;
	var opt1 = document.createElement("option");
	document.getElementById("series").options.add(opt1);
    opt1.text = "Select Category";
    opt1.value = "";
	var opt2 = document.createElement("option");
    opt2.text = "Select Series";
    opt2.value = "";
	}else{
	
	var opt4 = document.createElement("option");
	document.getElementById("series").options.add(opt4);
    opt4.text = "All";
    opt4.value = "";
	
	dd = eval(val);

	for(x=0;x<dd.length;x++) {
       	var opt = document.createElement("option");
		document.getElementById("series").options.add(opt);
       	opt.text = dd[x];
       	opt.value = dd[x];
	}

}
}

function submitProductSearch(selectbox){
	if (document.getElementById("model").value != ""){
		document.getElementById("product").action = "product-details.asp?prodId="+document.getElementById(selectbox).value+"";
 		document.getElementById("product").submit();
	}else if (document.getElementById("model1").value != ""){
		document.getElementById("product").action = "product-details.asp?prodId="+document.getElementById(selectbox).value+"";
 		document.getElementById("product").submit();
	}else {
		document.getElementById("product").action = "product-results.asp";
 		document.getElementById("product").submit();
	}
}

function submitKBSearch(selectbox){
	if (document.getElementById("model").value != ""){
		document.getElementById("kb").action = "kb-results.asp?prodId="+document.getElementById(selectbox).value+"";
 		document.getElementById("kb").submit();
	}else if (document.getElementById("model1").value != ""){
		document.getElementById("kb").action = "kb-results.asp?prodId="+document.getElementById(selectbox).value+"";
 		document.getElementById("kb").submit();
	}else {
		document.getElementById("kb").action = "kb-results.asp";
 		document.getElementById("kb").submit();
	}
}

function showModelDesc(propId){
	propId = propId.replace(/-/, "")
	if (propId != ""){
	document.getElementById("modelInfo").innerHTML = "<b>Selected model info:</b><br/><br/>" + eval("desc" + propId);
	}
}

function addProduct(){
	var model = document.getElementById("product").value;
	var serial = document.getElementById("serial").value;
	var notes = document.getElementById("notes").value;
	var custID = document.getElementById("custID").value;
	if (model == "") {
	alert("Please select a model")	
	}else if (serial == "") {
	alert("Please enter a valid serial number")	
	}else{
	URL = "login.asp?action=addproduct&product="+model+"&serial="+serial+"&notes="+notes+"&custID="+custID+"";
	alert(URL);
	document.location.href = URL;
	}
}

//Determines whether the input field has been completed, based on whether the default still exists
function isFilled(field) {
	if (field.value.length < 1 || field.value == "") {
		return false;
	} else {
		return true;
	}
}

//Determines whether the email field has been completed correctly, based on the existence of certain characters
function isEmail(field) {
	if (field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1)
	{
		return false;
	} else {
		return true;
	}
}

//Draws upon the previous two functions to validate all form fields, based on whether the class "required" or "email" is present
function validateForm(whichform) {	
	for (var i=0; i<whichform.elements.length; i++) {
		var element = whichform.elements[i];
		if (element.className.indexOf("required") != -1) {
			if (!isFilled(element)) {
				alert("Please fill in your "+element.name+".");
				return false;
			}
		}
		if (element.className.indexOf("email") != -1) {
			if (!isEmail(element)) {
				alert("Please enter a valid e-mail address.");
				return false;
			}
		}
	}
	return true;
}

function validateQuestion(whichform){
if (document.getElementById("model2").value != "" && document.getElementById("series2").value != ""){
	alert("Please only select a product or series");
	return false;
}else if (document.getElementById("model2").value == "" && document.getElementById("series2").value == ""){
	alert("Please select a product or series");
	return false;
}else{
for (var i=0; i<whichform.elements.length; i++) {
		var element = whichform.elements[i];
		if (element.className.indexOf("required") != -1) {
			if (!isFilled(element)) {
				alert("Please fill in your "+element.name+".");
				return false;
			}
		}
		if (element.className.indexOf("email") != -1) {
			if (!isEmail(element)) {
				alert("Please enter a valid e-mail address.");
				return false;
			}
		}
	}
	return true;
}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=400,left = 440,top = 312');");
}
