
var openMenu = new Array('','','','','')
timerOn=false
disableMenu=false
drawLoadingDoneOnce=false
timecount=250

i=0

while ((deptChildrenID[0][i] + '' != '')&&(typeof deptChildrenID[0][i]!='undefined')) {
	a=document.getElementById("pMenu" + deptChildrenID[0][i])
	
	if (a!= null) {
		
		a.hasSubMenu=1
		a.level=0
		if ((deptName[deptChildrenID[0][i]]!='<hr>')&&(typeof deptName[deptChildrenID[deptChildrenID[0][i]][0]] !='undefined')) {
			//a.innerHTML=deptName[deptChildrenID[0][i]]
			a.onmouseover = function () {doShowMenu(this.id.substr(5),this.hasSubMenu,this.level)}
			a.onmouseout = function () {doHideMenu(this.id.substr(5), this.level)}
			a.onclick = function () {disableMenu=true;hideByLevel('0'); menuRedirect(deptID[this.id.substr(5)], dURL[this.id.substr(5)])}
			//	if ((a.className.indexOf('Top')<0)&&(a.className.indexOf('BT')<0)) {
			//		//a.innerHTML = "<img class=\"Arrow\" src=\"/shop/assets/images/miscimages/menuarrow3.gif\">" + a.innerHTML
			//		a.innerHTML = "<img src=\"/shop/assets/images/miscimages/menuarrow5.gif\">&nbsp;" + a.innerHTML
			//	}
	
		}
		else if (deptName[deptChildrenID[0][i]]=='<hr>'){
			a.innerHTML='<hr>'
			a.className="barHR"
		}
		else {
			a.hasSubMenu=0
			a.onmouseover = function () {highlightMOver(this.id.substr(5),this.level)}
			a.onmouseout = function () {doHideMenu(this.id.substr(5), this.level)}
			a.onclick = function () { disableMenu=true;hideByLevel('0'); menuRedirect(deptID[this.id.substr(5)], dURL[this.id.substr(5)])}
				//if ((a.className.indexOf('Top')<0)&&(a.className.indexOf('BT')<0)) {
				//	a.innerHTML = "<img src=\"/shop/assets/images/miscimages/menucircle.gif\">&nbsp;" + a.innerHTML
				//	}
	
		}
	
	}
	
	i++
}


if(document.layers){
		thisbrowser="NN4";
		allString = "document.";
		styleString = ""
	}
	if(document.all){
		thisbrowser="IE"
		allString = "document.all.";
		styleString = ".style";
	}
	if(!document.all && document.getElementById){
		thisbrowser="NN6";
		allString = "document.";
		styleString = ".style"
	}

//---------------------------------------------------------------------
function getWindow(a){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	if (a == "H") {return myHeight }
	else {return myWidth }
}
function menuRedirect(deptIDx, url) {
	
	
	if (typeof url =='undefined') {
		urlAdder=''
		qString=(window.location.search.toLowerCase())
		//alert(qString)
		if (qString.indexOf("ts=custom")>=0) {
			urlAdder="http://www.nrsweb.com"	
			//alert("a")
		}
		else if (qString.indexOf("ts=b2b")>=0) {
			urlAdder="http://www.nrsb2b.com"
			//alert("b")
		}
		else if (qString.indexOf("ts=rescue")>=0) {
			urlAdder="http://www.nrsrescue.com"
			//alert("c")
		}
		else if (qString.indexOf("ts=outlet")>=0) {
			urlAdder="http://www.nrsoutlet.com"
			//alert("d")
		}
		//alert("e")
		document.location=urlAdder + '/shop/product_list.asp?deptid=' + deptIDx;
	}
	else {
		if (url.indexOf("?")>=0) {
			str="&tn="
		}
		else {
			str="?tn="
		}
	 document.location=url + str + deptIDx;
	}
}

function hideSelect()
{
	if (document.all){
		ij=0
		if (typeof document.all.formselect!='undefined') {
			if (typeof document.all.formselect.style=='undefined') {
				while (typeof document.all.formselect[ij]!='undefined') {
					document.all.formselect[ij].style.visibility="hidden"
					ij++;
				}
			}
			else {
				document.all.formselect.style.visibility="hidden";
			}
		}
		
		//if (typeof document.all.formselect!='undefined')	{document.all.formselect.style.visibility="hidden";}
	}
}

function unhideSelect()
{
	if (document.all){
		ij=0
		if (typeof document.all.formselect!='undefined'){
			if (typeof document.all.formselect.style=='undefined') {
				while (typeof document.all.formselect[ij]!='undefined') {
					document.all.formselect[ij].style.visibility="visible"
					ij++;
				}		
			}
			else {
				document.all.formselect.style.visibility="visible";
			}
		}
		//if (typeof document.all.formselect!='undefined'){document.all.formselect.style.visibility="visible";}
	}	
}

function drawLoading(parentID) {	
	//LBdy=document.getElementById("Bdy")
	//if (drawLoadingDoneOnce==true) {
	//	LMenu=document.getElementById("loading")
	//	LMenu.parentNode.removeChild(LMenu)
	//}
	//else { 
	//	drawLoadingDoneOnce=true }
	//parentM=document.getElementById('pMenu' + parentID)
	//LMenu=document.createElement("DIV")
	//LMenu.innerHTML="**Loading " + deptName[parentID] + "**"
	//LMenu.id="loading"
	//LMenu.className='menu'
	//LMenu.className='loading'
	//LBdy.appendChild(LMenu)
	//LMenu=document.getElementById("loading")
	//eval('LMenu' + styleString).visibility = "visible"
	//eval('LMenu' + styleString).position = "absolute"
	//	if (thisbrowser=="IE") {
	//		eval('LMenu' + styleString).pixelLeft = getPos('L',parentM) + getPos('W',parentM)-5// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
	//		eval('LMenu' + styleString).pixelTop =  getPos('T',parentM) + getscrolltop() -2
	//	}
	//	else {
	//		pl=getPos('L',parentM) + getPos('W',parentM)-5
	//		pt=getPos('T',parentM) + getPos('H', parentM) - 24
	//		eval('LMenu' + styleString).left = pl + 'px'// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
	//		eval('LMenu' + styleString).top =  (pt) +'px'
	//	}
		
	//a.width=200
	//a.innerHTML="<span style=\"position: absolute;right: 150px;color=#7c1e1f;\">&nbsp;**Loading**</span>" + a.innerHTML
}

function doShowMenu(parentID, hasSubMenu, parentLevel) { //actions to perform when Menu is mousedOver
		stopTime()
		highlightMOver(parentID, parentLevel)
		timerID=setTimeout('showSubMenu(' + parentID + ',' + hasSubMenu + ',' + parentLevel + ')' , timecount)
		timerOn=true
}

function doHideMenu(parentID, parentLevel) {
	highlightMOut(parentID, parentLevel)
	stopTime()
	timerID=setTimeout('hideByLevel(' + 0 + ')' , timecount); 
	timerOn = true; 
}
function doHideMenuHR(parentID, parentLevel) {
	stopTime()
	timerID=setTimeout('hideByLevel(' + 0 + ')' , timecount); 
	timerOn = true; 
}
function startTime() { 
	if (timerOn == false) { 
		timerID=setTimeout( "HideMenu(menuBar)" , timecount); 
		timerOn = true; 
	} 
}
function stopTime() { 
	if (timerOn) { 
		clearTimeout(timerID); 
		timerID = null; 
		timerOn = false; 
	} 
}
//---------------------------------------------------------------------
function showSubMenu(parentID, hasSubMenu, parentLevel) {
	
	if (disableMenu==false) {
		
		
		LBdy=document.getElementById("Bdy")
		hideByLevel(parentLevel) //hide submenus that are below the current menu
		hideSelect()
		
		a=document.getElementById('img' +parentID)
		if ( a != null) {	eval('a' + styleString).visibility = "visible" }
		
		if (hasSubMenu != 0) {//if it has sub menus
			openMenu[parentLevel]=parentID; //indicate the current MenuID for the current level
			overDiv=document.createElement("DIV")
			overDiv.className='menu'
			overDiv.id='Menu' + parentID
			i=0
			while (deptChildrenID[parentID][i] + '' != '' && i < 50) {
			menuItemID=deptChildrenID[parentID][i]
			newDiv=document.createElement("DIV")
			newDiv.id='pMenu' + menuItemID
			//newDiv.innerHTML='<a class="navSideItem" href="/shop/product_list.asp?deptid=' + deptID[menuItemID] + '">' + deptName[menuItemID] + '</a>'
			newDiv.className='menuItem'
			if ((deptName[menuItemID] =='<hr>' )||(deptName[menuItemID]=='-')) {
					newDiv.className='barHRTN'
					newDiv.innerHTML='<hr>'
				}
			else {			
				if (typeof dURL[menuItemID]=='undefined') {
					newDiv.innerHTML='<a class="navSideItem" href="/shop/product_list.asp?deptid=' + deptID[menuItemID] + '">' + deptName[menuItemID] + '</a>'	
				}
				else {
					(dURL[menuItemID].indexOf('?')>1)?qStr="&tn=":qStr="?tn=";			
					newDiv.innerHTML='<a class="navSideItem" href="' + dURL[menuItemID] + qStr + deptID[menuItemID] + '">' + deptName[menuItemID] + '</a>'	
				}
			}
			
			
			
			
			newDiv.level=parentLevel+1
			newDiv.hasSubMenu=0
			if (deptChildrenID[menuItemID][0] + '' != '') {//see if this menu item has children
				newDiv.hasSubMenu=1
				//newDiv.innerHTML += "&nbsp;&nbsp;<img class=\"Arrow\" src=\"/shop/assets/images/miscimages/menuarrow.gif\" width=\"5\" height=\"10\">"
				newDiv.innerHTML = "<img class=\"Arrow\" src=\"/shop/assets/images/miscimages/menuarrow.gif\" width=\"5\" height=\"10\">" + newDiv.innerHTML
				//newDiv2=document.createElement("DIV")
				//newDiv2.className='Arrow'
				//newDiv2.innerHTML += "<img src=\"/shop/assets/images/miscimages/menuarrow.gif\" width=\"5\" height=\"10\">"
			} 
			
			if ((deptName[menuItemID] !='<hr>' )&&(deptName[menuItemID]!='-')) {
				newDiv.onmouseover = function () {doShowMenu(this.id.substr(5),this.hasSubMenu,this.level)}
				newDiv.onmouseout = function () {doHideMenu(this.id.substr(5), this.level)}
				newDiv.onclick = function () {disableMenu=true;hideByLevel('0');menuRedirect(deptID[this.id.substr(5)], dURL[this.id.substr(5)])}
			}
			else {
				newDiv.onmouseover = function () {stopTime()}
				newDiv.onmouseout = function () {doHideMenuHR(this.id.substr(5), this.level)}
			}
			overDiv.appendChild(newDiv)
			

			//if (deptChildrenID[menuItemID][0] + '' != '') { overDiv.appendChild(newDiv2) }
			
			i++
			}
			LBdy.appendChild(overDiv)
	
			
			parentM=eval('document.getElementById(\'pMenu' + parentID + '\')')
			LMenu=eval('document.getElementById(\'Menu' + parentID + '\')')
			eval('LMenu' + styleString).visibility = "visible"
			if ((parentLevel == 0) && ((parentM.className.indexOf('Top')>=0)||(parentM.className.indexOf('BT')>=0))) { //if dropping from above menu
				if (thisbrowser=="IE") {
					
					eval('LMenu' + styleString).pixelLeft = getPos('L',parentM)-5// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
					eval('LMenu' + styleString).pixelTop =  getPos('T',parentM) + getscrolltop() + parentM.offsetHeight
				}
				else {
					pl = getPos('L',parentM)
					pt = getPos('T',parentM) + (LBdy.scrollTop) + parentM.offsetHeight
					eval('LMenu' + styleString).left = (pl-5) + 'px'// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
					eval('LMenu' + styleString).top =  pt +'px'
				}
			}
			else {
				if (thisbrowser=="IE") {
					eval('LMenu' + styleString).pixelLeft = getPos('L',parentM) + getPos('W',parentM)-5// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
					th=getPos("H",LMenu)
					eval('LMenu' + styleString).pixelTop =  getPos('T',parentM) + getscrolltop() -2 -(th/2) +10
				}
				else {	
					pl=getPos('L',parentM) + getPos('W',parentM)-5
					//pt=getPos('T',parentM) + getPos('H', parentM) - 24 - (getPos('H',LMenu)/2) + 15
					
					//WorkAround For Non IE Browsers when scrolled down part way
					pt=getPos('T',parentM) + getPos('H', parentM) - 24 - (getPos('H',LMenu)/2) + 15 + getscrolltop()
					
					eval('LMenu' + styleString).left = pl + 'px'// + Bdy.scrollTop //+ parentID.offsetHeight  + Bdy.scrollLeft + parentID.offsetWidth //parentID.getBoundingClientRect().left
					eval('LMenu' + styleString).top =  (pt) +'px'
				}
			}
			//reposition menu if it is off screen
			wh=getWindow("H")
			ww=getWindow("W")
			mh=getPos("H",LMenu)
			mt=getPos("T",LMenu)
			mw=getPos("W",LMenu)
			ml=getPos("L",LMenu)
			
			mtNonIE = LMenu.offsetTop; //WorkAround For Non IE Browsers when scrolled down part way
		
			if (thisbrowser=="IE") {			
				if (mh + mt > wh) { eval('LMenu' + styleString).pixelTop=wh - mh + getscrolltop()}
				if ((wh<mh)||(mt<0)) { eval('LMenu' + styleString).pixelTop = getscrolltop()}
				 if (mw + ml > ww) { eval('LMenu' + styleString).pixelLeft=getPos('L',parentM) - mw }
			}
			else {
				if (mh + mt - getscrolltop() > wh) { 	
						eval('LMenu' + styleString).top = (wh - mh+getscrolltop()) + 'px' 
						}
				if ((wh<mh)||(mt-getscrolltop()<0)) { 
					//eval('LMenu' + styleString).top = 0 + getscrolltop() + 'px' 
					//WorkAround For Non IE Browsers when scrolled down part way
					eval('LMenu' + styleString).top = mtNonIE + 'px'
					}
				if (mw + ml > ww) { 
					eval('LMenu' + styleString).left=(getPos('L',parentM) - mw) + 'px' 
					}
			}
		}
	}
}
//---------------------------------------------------------------------
function hideSubMenu(MenuID) {
if (MenuID!=0) {
	a=document.getElementById('img' +MenuID)
	if (a != null) {	eval('a' + styleString).visibility = "hidden" }
	
	LMenu=document.getElementById('Menu' + MenuID)	
	upLevID=LMenu.id.substr(4)
	b=document.getElementById('pMenu' + upLevID)
	if (b !=null) {
		if (b.className=='barSelected') {	b.className='bar'	}//change upper menu to normal State
		else if (b.className=='barTopSelected') {	b.className='barTop'	}//change upper menu to normal State
		else if  (b.className=='menuItemSelected'){ b.className='menuItem' }
	}
	LMenu.parentNode.removeChild(LMenu)
}
}
//---------------------------------------------------------------------
function hideByLevel(parentLevel) {//hide submenus that are below (higher level number) the current menu
	i=0
	unhideSelect()
	while (i < 5) {
		if (i>=parentLevel) { 
			if (openMenu[i] != '') { hideSubMenu(openMenu[i]) } //Hide the open Menu by ID
			openMenu[i]='' //Remove the just closed menu from the openMenu list
		}
	i++;}}
//---------------------------------------------------------------------
function debug(str){
document.getElementById("x").innerHTML+=str + '<br>'
}
//---------------------------------------------------------------------
function getPos(pos,el) {
	var x,w,y,h; 
	if (document.getBoxObjectFor) { 
		var bo = document.getBoxObjectFor(el); 
		
		x = bo.x; 
		w = bo.width;	
		y = bo.y;	
		h = bo.height;	
			} 
	else if (el.getBoundingClientRect) { 
		var rect = el.getBoundingClientRect(); 
		x = rect.left; 
		w = rect.right - rect.left;	
		y = rect.top;	
		h = rect.bottom - rect.top;	
	} 
	if (pos=='L') {	return x;	}
	else if (pos=='T') { return y; }
	else if (pos=='W') { return w; }
	else if (pos=='H') { return h; }
}

function getscrolltop() {
if (document.body.scrollTop==0) {
	LastPos=document.documentElement.scrollTop}	
else
	{LastPos=document.body.scrollTop}
return LastPos
}

function highlightMOver(parentID, parentLevel) {
	a=document.getElementById('pMenu' + parentID)
	if (parentLevel==0) {
		if (a.hasSubMenu==1) {
			c=document.getElementById('img' +parentID)
			if ( c != null) {	eval('c' + styleString).visibility = "visible" }
		}
				
		if (a.className.indexOf('Top')>=0) { a.className='barTopOver' }
		else if (a.className.indexOf('bar')>=0){(a.className='barOver')}
	}
	else {
		a.className='menuItemOver'
		upLevID=a.parentNode.id.substr(4)
		b=document.getElementById('pMenu' + upLevID)
		eval('b' + styleString).visibility = "visible" 
		if (parentLevel==1) {
			if (b.className.indexOf('Top')>=0) { b.className='barTopSelected' }
			else if(b.className.indexOf('bar')>=0){(b.className='barSelected')}
		}
		else {
		b.className='menuItemSelected';
		}
	}
}
function highlightMOut(parentID, parentLevel) {
a=document.getElementById("pMenu" + parentID);
openMenu[parentLevel]==a.id.substr(5)?sText="Selected":sText='';
if (parentLevel==0) {
	if (a.className.indexOf('Top')>=0) { a.className='barTop'+sText }
	else if (a.className.indexOf('bar')>=0)	{
		(a.className='bar'+sText);
		if (sText=='') {
			a=document.getElementById('img' +parentID)
			if (a != null) {	eval('a' + styleString).visibility = "hidden" }
			}
		}
}
else {
a.className='menuItem' +sText;
}
}

