function gettingShippingInfo() {
	newDiv = document.createElement("div");
	newDiv.id = "loadingShippingInfo";
	newDiv.innerHTML = "Retrieving Shipping Information, Please Wait.";
	document.body.appendChild(newDiv);
}
function waitPopUp(text) {
	newDiv = document.createElement("div");
	newDiv.id = "loadingShippingInfo";
	newDiv.innerHTML = text;
	document.body.appendChild(newDiv);
}
function addItemToQuickList( item, qty ) {
	var url='quicklistAdd.php?productID=' + item + '&qty=' + qty;
	var x = window.open( url, 'QuickWindow', 'width=900,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, jdlOrderID,customer_id ) {
	var url=BaseURL+'viewOrder.php?type=' + type + '&options=' + options + '&orderid=' + orderid + '&jdlorderid=' + jdlOrderID
	if( customer_id != null )
		url += '&customer_id='+customer_id;
	var x = window.open( url, 'orderWindow', 'width=800,height=550,scrollbars=1,resizable=1');
}

function invoicePrompt() {
	var url=BaseURL+'invoicePrompt.php';
	var x = window.open( url, 'invoicePromptWindow', 'width=800,height=550,scrollbars=1,resizable=1');
}

function viewTerms() {
	var url=BaseURL+'terms.php';
	var x = window.open( url, 'orderWindow', 'width=800,height=550,scrollbars=1,resizable=1');
}
function viewReturnsPolicy() {
	var url=BaseURL+'returns.php';
	var x = window.open( url, 'orderWindow', '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;
	}
}

function setHiddenAction(id, val) {
  document.getElementById(id).value = val;
  return true;
}



var myrules = {
	'#homepagemenu li' : function(element){
		element.onmouseover = function(){
			Element.addClassName(element, "hover");
			var subnav;
			if(subnav = element.getElementsByTagName("ul")[0]) {
				Element.show(subnav);
			}
		}, 
		element.onmouseout = function(){
			Element.removeClassName(element, "hover");			
			var subnav;
			if(subnav = element.getElementsByTagName("ul")[0]) {
				Element.hide(subnav);
			}
		}
	},
	'#categorylisting li' : function(element){
		element.onmouseover = function(){
			Element.addClassName(element, "hover");
		}, 
		element.onmouseout = function(){
			Element.removeClassName(element, "hover");
		}
	},
	'#myAccountMenu li' : function(element){
		element.onmouseover = function(){
			Element.addClassName(element, "hover");
		}, 
		element.onmouseout = function(){
			Element.removeClassName(element, "hover");
		}
	}	
	
};
Behaviour.register(myrules);

if(typeof sIFR == "function"){

// This is the preferred "named argument" syntax
	sIFR.replaceElement(named({sSelector:"#content h1", sFlashSrc:BaseURL+"script/sifr/tradegothic.swf", sColor:"#22772D", sLinkColor:"#22772D", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", sWmode:"transparent", sFlashVars:""}));
};


//this code allows you to dynamically add scripts to the page
function includeJavascript(url) {
	var e = document.createElement("script");
	e.src = url;
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
}

//Define function and establish listener to convert textareas to htmlarea
function getHTMLEditors() {
	var editors = document.getElementsByClassName("htmleditor");
	if(editors.length>0) {
		includeJavascript(BaseURL+"script/htmlarea/htmlarea.js");
		includeJavascript(BaseURL+"script/htmlarea/htmlareaconfig.js");
	} else {
		return false
	}
}
Event.observe(window, 'load', getHTMLEditors);

