function initPage()
{
	var nav = document.getElementById("navigation");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i = 0; i < nodes.length; i++)
		{		
				nodes[i].onmouseover = function () 
				{
					this.className += " hover";
				}
				nodes[i].onmouseout = function ()
				{
					this.className = this.className.replace(" hover", "");
				}
		}
	}
}
if (window.attachEvent)
	window.attachEvent("onload", initPage);

function _term_add_ul_html_tags(unorderedList) {
	var tmp = document.getElementById(unorderedList).value;
	var l = unorderedList.length - 1;
	var i;
	var c = "";
	var a = "";
	var r = "";

	for(i = 0; i <= l; i++) {
		c = tmp.substring(i, i);
		a = tmp.charCodeAt(i);
		r = "CHAR[" + c + "] ASCII[" + a + "]";
	}
	alert(r);
}

function _term_checkEMail(myemail) {
	if (myemail == "" || myemail.length < 6) {
		// Has to be at least a@b.xx
		return -1;
	}

	var at_pos = myemail.indexOf("@");

	if (at_pos == -1) {
		// Didn't find the "@"
		return -1;
	}

	var dot_pos = myemail.indexOf(".");

	if (dot_pos == -1) {
		// Didn't find the "."
		return -1;
	}

	var the_rest = myemail.substring(dot_pos + 1);

	if (the_rest == "" || the_rest.length < 2) {
		return -1;
	}

	// Looks like a valid email address.
	return 1;
}

function _term_submit_work_order_verify() {
	var _term_work_order_form_issue = document.getElementById("tgt_work_order_form_issue").value;

	if (_term_work_order_form_issue == "") {
		alert("Please enter an issue before submitting.");
		document.getElementById("tgt_work_order_form_issue").select();
		return;
	}

	document.tgt_work_order_form.submit();
}

function _term_verify_global_del(id) {
	var answer = confirm ("Are you sure you want to delete global " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-del-global.php?id=" + id;
	} else {
		return;
	}
}

function _term_verify_client_del(clientid, user) {
	var answer = confirm ("Are you sure you want to delete " + user + "?");
	if (answer) {
		window.location = "client-del.php?clientid=" + clientid;
	} else {
		return;
	}
}

function _term_verify_user_del(usrid, user) {
	var answer = confirm ("Are you sure you want to delete " + user + "?");
	if (answer) {
		window.location = "user-del.php?userid=" + usrid + "&user=" + escape(user);
	} else {
		return;
	}
}

function _term_verify_contact_del(id) {
	var answer = confirm ("Are you sure you want to delete contact " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-del-contact.php?id=" + id;
	} else {
		return;
	}
}

function _term_verify_wo_del(id) {
	var answer = confirm ("Are you sure you want to delete work order " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-del-wo.php?id=" + id;
	} else {
		return;
	}
}

function _term_verify_wo_det_del(wid, id) {
	var answer = confirm ("Are you sure you want to delete work order detail " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-del-wo-detail.php?wid=" + wid + "&id=" + id;
	} else {
		return;
	}
}

function _term_verify_wo_cc_del(wid, id) {
	var answer = confirm ("Are you sure you want to delete work order credit card submittal " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-cc-del.php?wid=" + wid + "&id=" + id;
	} else {
		return;
	}
}

function _term_verify_wo_check_del(wid, id) {
	var answer = confirm ("Are you sure you want to delete work order check entry " + id + "?");
	if (answer) {
		window.location = "https://www.treasurevalleysolar.com/tvsgreentech/w/admin-check-del.php?wid=" + wid + "&id=" + id;
	} else {
		return;
	}
}

function _term_verify_category_del(categoryid, category) {
	var answer = confirm ("Are you sure you want to delete the category " + category + "?");
	if (answer) {
		window.location = "category-del.php?categoryid=" + categoryid + "&category=" + escape(category);
	} else {
		return;
	}
}

function _term_verify_category_image_del(categoryid, category, fileid) {
	var answer = confirm ("Are you sure you want to remove the image from category " + category + "?");
	if (answer) {
		window.location = "category-image-del.php?categoryid=" + categoryid + "&category=" + escape(category) + "&fileid=" + fileid;
	} else {
		return;
	}
}

function _term_verify_product_del(productid, product) {
	var answer = confirm ("Are you sure you want to delete the product " + product + "?");
	if (answer) {
		window.location = "product-del.php?productid=" + productid + "&product=" + escape(product);
	} else {
		return;
	}
}

function _term_verify_product_image_del(productid, product, fileid) {
	var answer = confirm ("Are you sure you want to remove the image from product " + product + "?");
	if (answer) {
		window.location = "product-image-del.php?productid=" + productid + "&product=" + escape(product) + "&fileid=" + fileid;
	} else {
		return;
	}
}

function _term_verify_vendor_del(vendorid, vendor) {
	var answer = confirm ("Are you sure you want to delete the vendor " + vendor + "?");
	if (answer) {
		window.location = "vendor-del.php?vendorid=" + vendorid + "&vendor=" + escape(vendor);
	} else {
		return;
	}
}

function _term_verify_oem_del(oemid, oem) {
	var answer = confirm ("Are you sure you want to delete the OEM " + oem + "?");
	if (answer) {
		window.location = "oem-del.php?oemid=" + oemid + "&oem=" + escape(oem);
	} else {
		return;
	}
}

function _term_verify_catalog_del(catalogid, catalog) {
	var answer = confirm ("Are you sure you want to delete the catalog " + catalog + "?");
	if (answer) {
		window.location = "catalog-del.php?catalogid=" + catalogid + "&catalog=" + escape(catalog);
	} else {
		return;
	}
}

function _term_verify_catalog_image_del(catalogid, catalog, fileid) {
	var answer = confirm ("Are you sure you want to remove the image from catalog " + catalog + "?");
	if (answer) {
		window.location = "catalog-image-del.php?catalogid=" + catalogid + "&catalog=" + escape(catalog) + "&fileid=" + fileid;
	} else {
		return;
	}
}

function _term_populate_billing(myType) {
	var elemID = myType + "_first_name";
	document.getElementById("billing_first_name").value = document.getElementById(elemID).value;

	elemID = myType + "_last_name";
	document.getElementById("billing_last_name").value = document.getElementById(elemID).value;

	elemID = myType + "_email";
	document.getElementById("billing_email").value = document.getElementById(elemID).value;

	elemID = myType + "_phone";
	document.getElementById("billing_phone").value = document.getElementById(elemID).value;

	elemID = myType + "_cell";
	document.getElementById("billing_cell").value = document.getElementById(elemID).value;

	elemID = myType + "_fax";
	document.getElementById("billing_fax").value = document.getElementById(elemID).value;
}

function _term_ClipBoard() {
	var Copied = document.getElementById("recurring_work_order").createTextRange();
	Copied.execCommand("Copy");
}

