function addItemToQuickList( item, qty ) {
	var url='quicklistAdd.php?productID=' + item + '&qty=' + qty;
	var x = window.open( url, 'QuickWindow', 'width=400,height=400,scrollbars=no');
}

function validateUSNumber( item ) {
	var CleanedString="";
	var index = 0;
	var LimitCheck;
	var InitialString = item.value

	if (item.value == '') return true;
	//Get the length of the inputted string, to know how many characters to check
	LimitCheck = InitialString.length;

	//Walk through the inputted string and collect only number characters, appending them to CleanedString
	while (index != LimitCheck) {
		if (isNaN(parseInt(InitialString.charAt(index)))) { }
		else { CleanedString = CleanedString + InitialString.charAt(index); }
		index = index + 1;
	}

	//If CleanedString is exactly 10 digits long, then format it and allow form submission
	if (CleanedString.length == 10) {
		item.value = CleanedString.substring(0,3) + "-" + CleanedString.substring(3,6) + "-" + CleanedString.substring(6,10);
	}
	//If CleanedString is not 10 digits longs, show an alert and cancel form submission
	else {
		CleanedString = InitialString;
		alert("Please enter only your ten digit phone number.");
		if (document.all) {
			item.focus();
			item.select();
		}
		return false
	}
}

//
function viewOrder( type, options, orderid ) {
	var url=BaseURL+'viewOrder.php?type=' + type + '&options=' + options + '&orderid=' + orderid;
	var x = window.open( url, 'orderWindow', 'toolbar=yes,width=800,height=600,scrollbars=1,resizable=1');
}

/* lingje 2-2-06 added function viewQuote */
function viewQuote( type, options, orderid ) {
	var url=BaseURL+'viewQuote.php?type=' + type + '&options=' + options + '&orderid=' + orderid;
	var x = window.open( url, 'orderWindow', 'width=800,height=550,scrollbars=1,resizable=1');
}

function viewInvoice(invoiceid ) {
	var url=BaseURL+'viewInvoice.php?invoiceid=' + invoiceid;
	var x = window.open( url, 'invoiceWindow', 'width=800,height=550,scrollbars=1,resizable=1');
}


function removeItem( id ) {
	if (confirm('Really remove this category from the database?')) {
		document.rmItemForm.remove.value = "Remove";
		document.rmItemForm.submit();
	} else {
		return false;
	}
}

/* used in changeorder.tpl */
function check() {
	if (document.changeorderform.reqdate.value == '') {
		alert("Please enter a request date.");
		return false;
	} else {
		return true;
	}
}

/* used when entering addresses i.e. registration,checkout */
function toggleStateInput(show,name) {
	switch (show) {
		
		case "select" :
		if(document.getElementById("stateSelect").style.display != '')
		{
			document.getElementById("stateSelect").options[0].selected=true;
			document.getElementById("stateSelect").name = name;
			document.getElementById("stateSelect").style.display = '';
			document.getElementById("stateInput").name = "alt"+name;
			document.getElementById("stateInput").style.display = 'none';
		}
		break;
		
		case "input" :
		if(document.getElementById("stateInput").style.display != '')
		{	
			document.getElementById("stateInput").name = name;
			document.getElementById("stateInput").style.display = '';
			document.getElementById("stateSelect").name = "alt"+name;
			document.getElementById("stateSelect").style.display = 'none';
		}
		break;
	
	}
}


/* used when entering addresses in shipto maintenance */
function toggleStateInputShipto(show,name,id) {
	switch (show) {
		
		case "select" :
		if(document.getElementById("stateSelect_"+id).style.display != '') {
			document.getElementById("stateSelect_"+id).options[0].selected=true;
			document.getElementById("stateSelect_"+id).name = name;
			document.getElementById("stateSelect_"+id).style.display = '';
			document.getElementById("stateInput_"+id).name = "alt"+name;
			document.getElementById("stateInput_"+id).style.display = 'none';
		}
		break;
		
		case "input" :
		if(document.getElementById("stateInput_"+id).style.display != '') {
			document.getElementById("stateInput_"+id).name = name;
			document.getElementById("stateInput_"+id).style.display = '';
			document.getElementById("stateSelect_"+id).name = "alt"+name;
			document.getElementById("stateSelect_"+id).style.display = 'none';
		}
		break;
	}
}

/* provides hover support for li elements in lists */
function startList(listID) {
	if (document.all&&document.getElementById(listID)) {
		navRoot = document.getElementById(listID);
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" hover";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" hover", "");
				}
			}
		}
	}
}

function startLists() {
	startList("categorylisting");
	startList("browsecategories");		
}

function addEvent(elm, evType, fn, useCapture)
// cross-browser event handling for IE5+, NS6+ and Mozilla/Gecko
// By Scott Andrew
{
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
}

addEvent(window,"load",startLists);