/* ************* Top Nav script *************** */
/*  for IE only | not supported by ie5 Mac       */
/* ********************************************* */

var menuNav = {
	addEvent: function(elm, evType, fn, useCapture) {
		// addEvent cross-browser event handling for IE5+, NS6+ and Mozzila/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;
		}	
	},
	
	init: function() {
		var isMac = navigator.userAgent.toLowerCase().indexOf("mac") !=-1;
		if (document.all&&document.getElementById&&!isMac) {
			var globalNav = document.getElementById('globalNav');
			if (globalNav) {
				for (i=0; i<globalNav.childNodes.length; i++) {
					node = globalNav.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							if(this.className.match("hasSub"))
								this.className+=" over";
						}
			 			node.onmouseout=function() {
			 				this.className=this.className.replace(" over", "");
						}
					}
		 		}
			}
			
			var navRoot = document.getElementById('sideNav');
			if (navRoot) {
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						}
			 			node.onmouseout=function() {
			 				this.className=this.className.replace(" over", "");
						}
					}
		 		}
			}
		}

		// set the currently selected category
		var arrClasses = new Array('top', 'side', 'lob');
		var strID, objNav;
		for (i = 0; i < arrClasses.length; i++) {
			strID = eval('strGlobal_' + arrClasses[i] + '_ID');
			objNav = $(arrClasses[i] + 'Cat' + strID);
			if (objNav) objNav.className += " selected";
		}
	}
};

var strGlobal_lob_ID, strGlobal_top_ID, strGlobal_side_ID;

menuNav.addEvent(window, 'load', menuNav.init, false);
/* ********************************************* */

function globalRoll(which,name,status)
{	if (status)
	{	which.src = "images/nav/global/global_" + name + "_on.gif"
	}
	else
	{	which.src = "images/nav/global/global_" + name + "_off.gif"
	}
}


function subRoll(which,name,status)
{	if (status)
	{	which.src = "images/nav/sub/sub_" + name + "_on.gif"
	}
	else
	{	which.src = "images/nav/sub/sub_" + name + "_off.gif"
	}
}


function sideRoll(which,name,status)
{	if (status)
	{	which.src = "images/nav/side/side_" + name + "_on.gif"
	}
	else
	{	which.src = "images/nav/side/side_" + name + "_off.gif"
	}
}


function productRoll(blob,title,description,which,width)
{	partA = "<br /><img src='" + blob + "' alt='' /><br />"
	partB = "<span class='productRollTitle'>" + title + "</span><br />"
	partC = "<span class='productRollDescription'>" + description + "</span>"
	
	wrapperStart = "<table cellspacing='0' width='" + width + "'>" + "<tr><td width='" + width + "' align='left'>"
	wrapperEnd = "</td></tr></table>"
	
	newContent = wrapperStart + partA + partB + partC + wrapperEnd
	document.getElementById("productRollover" + which).innerHTML = newContent
}

function productRollOff(which)
{	newContent = ""
	document.getElementById("productRollover" + which).innerHTML = newContent
}


function checkShoppingForm(frmInput, bSkipQuantityCheck)
{
	var iAddCount = 0;
	var objStockLevel, objItemTitle, objText, iQuantity;
	var bIsWishlist = (frmInput.submitType.value == 'w');

	for(var i = 0; i < frmInput.elements.length; i++)
	{
		objText = frmInput.elements[i];
		if (!objText.value) continue;

		if (objText.name.search(/^q/) != -1) {
			if (objText.value.search(/[^\d]/) != -1) {
				alert("Please enter a valid number.")
				if (objText.type != 'hidden') {
					objText.value = "";
					objText.focus();
				}
				return false;
			}
			iQuantity = parseInt(objText.value);
			if (iQuantity <= 0) continue;
			if (!bSkipQuantityCheck && iQuantity > 4) {
				alert("You may purchase at the most four items at a time.");
				if (objText.type != 'hidden') {
					objText.value = "4";
					objText.focus();
				}
				return false;
			}
			if (!bIsWishlist) {
				eval("objStockLevel = frmInput.s" + objText.name);
				if (parseInt(objStockLevel.value) < iQuantity) {
					eval("objItemTitle = frmInput.t" + objText.name);
					alert(objItemTitle.value + " exceeds available quantity.");
					if (objText.type != 'hidden') {
						objText.value = "";
						objText.focus();
					}
					return false;
				}
			}
			iAddCount++;
		}
	}
	if (!iAddCount) {
		alert('Please enter a quantity next to the shade you would like to purchase and then press the "Add to Shopping Bag" button.');
		return false;
	}
	return true;
}