//<script>

/*---------- Condense these if possible: see navleft.asp ----------*/

function shopByBrand(){
	var gSBB = document.getElementById("ShopBB").ShopBBoption[document.getElementById("ShopBB").ShopBBoption.selectedIndex].value;
	if (gSBB.indexOf("/")>0||gSBB.indexOf(".asp")>0){
		var gRoot="";
		var locShID="?";
	}else{
		var gRoot=gDeptRoot;
		var locShID="&";
	}
	locShID += gShID;
	gSBB=gRoot+gSBB+locShID;
	top.location.href=gSBB;
}

function shopByVBrand(){
	var gSBB = document.getElementById("ShopBVB").ShopBBoption[document.getElementById("ShopBVB").ShopBBoption.selectedIndex].value;
	if (gSBB.indexOf("/")>0||gSBB.indexOf(".asp")>0){
		var gRoot="";
		var locShID="?";
	}else{
		var gRoot=gDeptRoot;
		var locShID="&";
	}
	locShID += gShID;
	gSBB=gRoot+gSBB+locShID;
	top.location.href=gSBB;
}

function shopByKW(){
	var gSBB = document.getElementById("ShopKW").ShopBBoption[document.getElementById("ShopKW").ShopBBoption.selectedIndex].value;
	if (gSBB.indexOf("/")>0||gSBB.indexOf(".asp")>0){
		var gRoot="";
		var locShID="?";
	}else{
		var gRoot=gSearchRoot;
		var locShID="&";
	}
	locShID += gShID;
	gSBB=gSearchRoot+gSBB+locShID;
	top.location.href=gSBB;
}






/*------  Condense these if possible: see navleft.asp ------*/

function EcatalogDropdown() {
 var url = document.formA.listA.options[document.formA.listA.selectedIndex].value;
 var specs = "menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=800,height=600,left=0,top=0";
 window.open(url,"",specs);
}
function EcatalogDropdown2() {
 var url = document.formB.listB.options[document.formB.listB.selectedIndex].value;
 var specs = "menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=800,height=600,left=0,top=0";
 window.open(url,"",specs);
}



/*---------- Popup Window for Large Image, Desc, etc: Products, Families, static pages ----------*/

var win = null;
function NewWindow(mypage,myname,w,h){
  if (win != null && !win.closed)
    win.close();
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',fixed'+(arguments[4]?","+arguments[4]:"");
win = window.open(mypage,myname,settings);
}



/*-------- Main Navigation Menu ---------*/

sfHover = function() {
	if (document.getElementById("nav")==undefined) return;
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



/*************************************************
   The following functions were made by Brandon
 *************************************************/


// returns a number representing the first character that is different between the two strings
function getFirstDifference( str1, str2 )
{
	if (typeof(str2)!="string"&&typeof(str1)=="string") return str1.length;
	var maxLen=(str1.length>str2.length?str2.length:str1.length);

	for (var i=0; i<maxLen; i++)
		if (str1.charAt(i)!=str2.charAt(i)) return i;
}

// Function pushUnique is used to add a unique string to an array
// It is used quite often
// Do not delete
function pushUnique(arr,str)
{
	for (var i = 0; i < arr.length; i++)
	{
		if (arr[i]==str) return false;
	}
	if (ltrim(str)=="") return false;
	arr.push(str);
	return arr.length;
}


/*-------- Probably Needed Here ----------*/

// VERY necessary, do not delete
function getBrowser()
{
	var tmp = navigator.userAgent;
	if (tmp.indexOf("Opera")>-1) return "Opera";
	if (tmp.indexOf("Firefox")>-1) return "Firefox";
	if (tmp.indexOf("Netscape")>-1) return "Netscape";
	if (tmp.substr(tmp.length-1)!=")")
		tmp = tmp.substr(tmp.lastIndexOf(" ")+1)
	else
		tmp = navigator.appName;
	return tmp;
}




/*-------- Where is this used??? ----------*/

// Function ltrim is used to remove beginning spaces from a string
// Probably not all that important, but it's used in a lot of places
// So be sure to remove all references to it
function ltrim(str)
{
	if (typeof(str)!="string") return str;
	if (str!=undefined)
		var ret=str;
	else
		return "";
	while (ret.charAt(0)==" "||ret.charCodeAt(0)==160)
		ret=ret.substr(1);
	return ret;
}





/*-------- Probably should go here ----------*/

// Function errorTrap is used to hide JS errors from normal users
// and to alert developers when they happen
window.onerror=errorTrap;
function errorTrap(eMsg,eURL,eLine)
{
	if (getCookie("debugmode")=="true")
		alert("Error: "+eMsg+" on line "+eLine+" in "+eURL+".");
	window.event.returnValue=true;
}




/*-------- Probably should go here ----------*/

// Function xString is used to make a repetition of a specified string (i.e. space)
function xString(str,len)
{
	var ret="";
	for (var i=0; i<len; i++)
		ret+=str;
	return ret;
}



/*-------- Probably should go here ----------*/

// The following prototypes are used in other functions
// It is a little more difficult to remove references to them
// So alter with caution
Array.prototype.split=function(str)
{
	var ret = new Array();
	for (var i=0; i<this.length; i++)
		ret.push( this[i].split(str) );
	return ret;
}



/*-------- Probably should go here ----------*/

// Returns the index of the Specified string (after fromno)
// If strict is set to true, it will match case
Array.prototype.indexOf=function(str,fromno,strict)
{
	if (!fromno) fromno = 0;
	if (!strict) strict = false;
	for (var i=fromno; i<this.length; i++)
		if (strict?this[i]==str:this[i].toLowerCase()==str.toLowerCase())
			return i;
	return -1;
}
Array.prototype.sortChildren=function(sortBy)
{
	var ret = new Array();
	var tmp = new Array();
	for (var i=0; i<this.length; i++)
	{
		tmp = this[i];
		tmp.sort(sortBy);
		ret.push(tmp);
	}
	return ret;
}
String.prototype.toProperCase = function()
{
	if (this.indexOf(" ")>-1)
	{
		var strs = this.split(" ");
		for (var i=0; i<strs.length; i++)
			strs[i]=strs[i].toProperCase();
		return strs.join(" ");
	}
	if (this.match(/[^A-Za-z ]/)) return this;
  return this.toLowerCase().replace(/^(.)|\s(.)/g, 
      function($1) { return $1.toUpperCase(); });
}

// THIS FUNCTION SETS THE TARGET PAGE AFTER LOGGING IN
// DO NOT DELETE - USED IN HEADER FILE
function contTarget() {
  var curPage = window.location.href;
  var removeText = curPage.substr(curPage.indexOf("mscssid="),curPage.length); 
  removeText = removeText.substr(0,removeText.indexOf("&") + 1);
  curPage = curPage.replace(removeText,"");
  curPage = curPage.replace(/\&/g,"%26");
  document.getElementById("myAccount").href = document.getElementById("myAccount").href + "&target=" + curPage; 
}



//</script>
