// window.onerror = null;
var DOM = (document.getElementById)?true:false;
var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4 && !DOM);
var IE4 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4);
var layerType = NS4?'layer':'div';
var menuOn = 0;
var layerOn, mainRef;
var mainIndex, subIndex;
var temp, searchLocation, windowWidth, allCatWidth, allTopWidth, railWidth, leftWidth, rightWidth, smWidth=160, center, loc, font, sl, pressed=false, itemstring;
var Xpos, Ypos;
var cursorWidth = 67, cursorHeight = 11;
var menuTimer = null;
var layerText, styleText, leftText, topText, appVer=navigator.appVersion; 
var rtimer;

if(navigator.appName == "Netscape") 
{
  layerText="document.layers";
  styleText="";
  leftText='.left';
  topText='.top';
  windowWidth = window.innerWidth - 16;
}
else
{
  layerText="document.all";
  styleText=".style";
  leftText='.pixelLeft';
  topText='.pixelTop';
  windowWidth = document.body.clientWidth;
  if(parseFloat(appVer.substr(appVer.indexOf("MSIE ")+5, 5))>=5)  
    windowWidth = windowWidth-16;
}

function setLink(index)
{
  mainIndex=index;
  subIndex=-2;
}

function intersect(A1, A2, B1, B2)
{
  if( (A1<B1 && B1<A2) || (A1<B2 && B2<A2) )
    return true;
  else if( (B1<A1 && A1<B2) || (B1<A2 && A2<B2) )
    return true;
  else 
    return false;
}

function DisplayMenu(layerNumber, src){
  var i;

  if(menuTimer != null) 
    {
      clearTimeout(menuTimer);

      if(layerOn!=layerNumber)
        hideMenu(layerOn);	
    }
    
  if(IE4)
    mainRef = src;

  if(!pressed)
    {
      mainIndex=layerNumber;
      subIndex=-1;  
    }

  if(eval('main['+layerNumber+'].sub==1')) 
    {
      if(NS4 && intersect(searchLocation+98, searchLocation+210, eval('sub'+layerNumber+'.left'), eval('sub'+layerNumber+'.left')+eval('sub'+layerNumber+'.smWidth')))
	eval(layerText+'["searchbox"]'+styleText+'.visibility="hidden"');
      
      if(DOM)
	{
	  document.getElementById('bg'+layerNumber).style.visibility='visible';
	  document.getElementById('sub'+layerNumber).style.visibility='visible';
	}
      else if(IE4)
	{
	  eval(layerText+'["'+'bg'+layerNumber+'"]'+styleText+'.visibility="visible"');
	  eval(layerText+'["'+'sub'+layerNumber+'"]'+styleText+'.visibility="visible"');
	}
      else if(NS4)
	{
	  eval(layerText+'["'+'bg'+layerNumber+'"]'+styleText+'.visibility="visible"');
	  for(i=0; i<eval('sub'+layerNumber+'.length'); i++)
	    eval(layerText+'["'+'sub'+layerNumber+i+'"]'+styleText+'.visibility="visible"');
	}
    }
  layerOn = layerNumber;
}

function hideMenu(layerNumber)
{
  var i;

  if (menuOn == 0) 
    {
      if(NS4)
	eval(layerText+'["searchbox"]'+styleText+'.visibility="visible"');
      
      if(eval('main['+layerNumber+'].sub==1'))
	{
	  if(DOM)
	    {
	      document.getElementById('bg'+layerNumber).style.visibility='hidden';
	      document.getElementById('sub'+layerNumber).style.visibility='hidden';
	    }
	  else if(IE4)
	    {
	      eval(layerText+'["'+'bg'+layerNumber+'"]'+styleText+'.visibility="hidden"');
	      eval(layerText+'["'+'sub'+layerNumber+'"]'+styleText+'.visibility="hidden"');
	    }
	  else if(NS4)
	    {
	      eval(layerText+'["'+'bg'+layerNumber+'"]'+styleText+'.visibility="hidden"');
	      for(i=0; i<eval('sub'+layerNumber+'.length'); i++)
		eval(layerText+'["'+'sub'+layerNumber+i+'"]'+styleText+'.visibility="hidden"');
	    }
	}

      if(DOM)
	document.getElementById('myCursor').style.visibility='visible';
      else
	eval(layerText+'["myCursor"]'+styleText+'.visibility="visible"');
    }
}

function setMenuTimer() 
{
 menuTimer = setTimeout("menuTimerOut()", 700)
}

function menuTimerOut() 
{    
 if(menuOn == 0)
  hideMenu(layerOn)
}
  
function subMenuIn(main, sub, src) 
{
  clearTimeout(menuTimer);
  menuOn = 1;
  
  if(DOM)
    {
      document.getElementById('myCursor').style.visibility='hidden';
      document.getElementById('sCursor').style.left=eval('sub'+main+'.left');
      document.getElementById('sCursor').style.top=eval('sub'+main+'['+sub+'].top');
      document.getElementById('sCursor').style.visibility='visible';
    }
  else
    {
      eval(layerText+'["myCursor"]'+styleText+'.visibility="hidden"');
      eval(layerText+'["sCursor"]'+styleText+leftText+'=sub'+main+'.left');
      eval(layerText+'["sCursor"]'+styleText+topText+'=sub'+main+'['+sub+'].top');
      eval(layerText+'["sCursor"]'+styleText+'.visibility="visible"');
    }

  if(!pressed)
    {
      mainIndex=main;
      subIndex=sub;
    } 
}
 
function subMenuOut(main, sub, src) 
{
  menuOn = 0;	

  if(DOM)
    document.getElementById('sCursor').style.visibility='hidden';
  else
    eval(layerText+'["sCursor"]'+styleText+'.visibility="hidden"');
  
  menuTimer = setTimeout("hideMenu(layerOn)", 700);
}



function handleResize()
{
  clearTimeout(rtimer);
  rtimer=setTimeout('window.location=window.location;',500);
}


function getAllCatWidth(fo, obj)
{
  var result = 0.0;
  var c, code;
  var r, i, j;

  smWidth=160;
  for(i=0; i<obj.length; i++)
    {
      r=0.0;
      for(j=0; j<obj[i].title.length; j++)
	{
	  c=obj[i].title.charAt(j);
	  code=obj[i].title.charCodeAt(j);
	  
	  if(fo==10)
	    {  
	      if(c=='f' || c=='i' || c=='j' || c=='l' || c=='t' || c=='I')
		r+=.5;
	      else if(c=='r')
		r+=.62;
	      else if(c=='s')
		r+=.75;
	      else if(c=='c' || c=='k' || c=='v' || c=='y' || c=='z' || c=='J' || c=='Z' || (code>=48 && code<=57))
		r+=.88;
	      else if(c=='A' || c=='B' || c=='C' || c=='D' || c=='H' || c=='K' || c=='N' || c=='P' || c=='R' || c=='S' || c=='U' || c=='V' || c=='X')
		r+=1.125;
	      else if(c=='G' || c=='O' || c=='Q')
		r+=1.25;
	      else if(c=='w' || c=='M')
		r+=1.37;
	      else if(c=='m')
		r+=1.5;
	      else
		r+=1;
	    }
	  else
	    {
	      if(c=='i' || c=='j' || c=='l' || c=='I')
		r+=.43;
	      else if(c=='f' || c=='t')
		r+=.57;
	      else if(c=='r')
		r+=.72;
	      else if(c=='w' || c=='y' || c=='F')
		r+=.86;
	      else if(c=='A' || c=='B' || c=='C' || c=='D' || c=='G' || c=='H' || c=='K' || c=='N' || c=='P' || c=='R' || c=='S' || c=='U' || c=='V' || c=='X')
		r+=1.15;
	      else if(c=='O' || c=='Q')
		r+=1.3;
	      else if(c=='w' || c=='M')
		r+=1.45;
	      else if(c=='m')
		r+=1.58;
	      else
		r+=1;
	    }

	  if(c=='&' && obj[i].title.charAt(j+1)=='q' && obj[i].title.charAt(j+2)=='u' &&  obj[i].title.charAt(j+3)=='o' &&  obj[i].title.charAt(j+4)=='t' &&  obj[i].title.charAt(j+5)==';')
	    j=j+5;
	}
      
      if(fo==10)
	r=r*8.03;
      else
	r=r*6.9;
     
      obj[i].width=Math.round(r)+10;
      result=result+Math.round(r)+10;
      smWidth=Math.max(smWidth, Math.round(r));
    } 

  return result;
}


function getCatLocation()
{
  var i;
  var cur = 10;
  var ex = Math.round((railWidth-allCatWidth-10)/main.length/2);
  
  if(ex<0)
    ex=0;	  

  for(i=0; i<main.length; i++)
    {
      main[i].location=cur+ex;
      cur=cur+main[i].width+ex+ex;
    }
}


function getTopLocation()
{
  var i;
  var cur = 15;
  var ex = Math.round((railWidth-allTopWidth-15)/myTop.length/2);  

  if(ex<0)
    ex=0;

  for(i=0; i<myTop.length; i++)
    {
      myTop[i].location=cur+ex;
      cur=cur+myTop[i].width+ex+ex;
    }
}



function handleMove(e)
{
  Xpos = (navigator.appName == "Netscape") ? (e.pageX - cursorWidth) : (event.clientX - cursorWidth);
  Ypos = (navigator.appName == "Netscape") ? e.pageY : event.clientY; 

  if(Ypos<51)
    {
      if(DOM)
	document.getElementById('myCursor').style.visibility='visible';
      else
	eval(layerText+'["myCursor"]'+styleText+'.visibility="visible"');

      if(Xpos<leftWidth)
	Xpos=leftWidth;
      if(Xpos>leftWidth+railWidth-cursorWidth*2)
	Xpos=leftWidth+railWidth-cursorWidth*2;

      if(DOM)
	document.getElementById('myCursor').style.left=Xpos;
      else
	eval(layerText+'["myCursor"]'+styleText+leftText+'='+Xpos);
      
      if(Ypos<27)
	{
	  if(DOM)
	    document.getElementById('myCursor').style.top=3;
	  else
	    eval(layerText+'["myCursor"]'+styleText+topText+'=3');
	}
      else
	{
	  if(DOM)
	    document.getElementById('myCursor').style.top=28;
	  else
	    eval(layerText+'["myCursor"]'+styleText+topText+'=28');
	}
    }
}

function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); }
function openMail(host) { var mailwindow = window.open("http://" + host +"/.sc/ms/em", "EmailFriend", "width=500,height=400,resizable,scrollbars,status"); if(!isIE4()) mailwindow.focus(); }

if (NS4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = handleMove;

for(i=0; i<main.length; i++)
{
  if(main[i].sub==1)
    {
      getAllCatWidth(9, eval('sub'+i));
      eval('sub'+i+'.smWidth='+smWidth);
    }
}

font=10;
allCatWidth = getAllCatWidth(10, main);
allTopWidth = getAllCatWidth(9, myTop);

railWidth = Math.max(535, allCatWidth);
railWidth = Math.max(railWidth, windowWidth-70);
leftWidth = Math.max(5, Math.round((windowWidth-railWidth-58)/2));
rightWidth = Math.max(5, Math.round((windowWidth-railWidth-58)/2)-1); 
center = leftWidth + Math.round(railWidth/2);

getCatLocation();
getTopLocation();

if(ot=='f')
  {
    myTop[4].url=myTop[3].url+'/co3';
    myTop[4].title="My Account";
  }

if(IE4)
  sl=18;
else if(DOM)
  sl=10;
else 
  sl=13;

document.writeln('<table cellpadding=0 cellspacing=0 border=0 valign=bottom><tr><td bgcolor=#999999 align=right><img src='+idomain+'/ac/b.gif height=1 width='+leftWidth+'><img src='+idomain+'/c3/vlb.gif width=1 height=52></td><td><table cellpadding=0 cellspacing=0 border=0><tr><td bgcolor=#999999 height=1><img src='+idomain+'/ac/b.gif width='+railWidth+' height=1></td></tr><tr><td bgcolor=#666666 height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#7f7f7f height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=white height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#cccccc height=20><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=white height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#7f7f7f height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#333333 height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#999999 height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=white height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#cccccc height=20><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=white height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#7f7f7f height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td bgcolor=#666666 height=1><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr></table></td><td bgcolor=#999999><img src='+idomain+'/c3/rhb.gif width=58 height=52><img src='+idomain+'/ac/b.gif width='+(rightWidth-2)+' height=1><img src='+idomain+'/c3/vlbr.gif width=2 height=52></td></tr></table>');

temp=Math.max(leftWidth, myTop[0].location-38);
if(NS4)
  document.writeln('<layer id=myCursor Z-INDEX=3 top=3 left='+temp+'>');
else
  document.writeln('<div id=myCursor style="position: absolute; Z-INDEX: 3; top: 3; left: '+temp+'; width: 134;  height: 22;">'); 
document.writeln('<img src='+idomain+'/c3/3d.gif width=134 height=22></'+layerType+'>');

if(NS4)
  document.writeln('<layer id=sCursor Z-INDEX=3 top=0 left=0 visibility=hidden>');
else
  document.writeln('<div id=sCursor style="position: absolute; Z-INDEX: 3; top: 0; left: 0; width: 160; height: 17; visibility: hidden;">'); 
document.writeln('<img src='+idomain+'/c3/3ds.gif width=160 height=17></'+layerType+'>');

if(topHTML=="")
{
  for(i=0; i<myTop.length; i++)
  {
    if(NS4)
      document.writeln('<layer id=myTop'+i+' Z-INDEX=5 top=4 left='+myTop[i].location+' onmouseover="setLink('+"'"+i+"'"+');"><table cellspacing=0 cellpadding=0 border=0 width='+myTop[i].width+' height=20>');
    else
      document.writeln('<div id=myTop'+i+' style="position: absolute; Z-INDEX : 5; top: 4; left: '+myTop[i].location+';"><table cellspacing=0 cellpadding=0 border=0 width='+myTop[i].width+' height=20 onmouseover="setLink('+"'"+i+"'"+');">');
 
    document.writeln('<tr><td align=center nowrap><a class=GB9 href='+myTop[i].url+'>'+myTop[i].title+'</a></td></tr></table></'+layerType+'>');  
  }
}
else
{
  if(NS4)
    document.writeln('<layer id=customtop Z-INDEX=5 top=5 left=20>');
  else
    document.writeln('<div id=customtop style="position: absolute; Z-INDEX : 5; top: 5; left: 20;">');
 
  document.writeln(topHTML+'</'+layerType+'>');
}


for(i=0; i<main.length; i++)
{
  if(NS4)
    document.writeln('<layer id=main'+i+' Z-INDEX=5 top=27 left='+main[i].location+' onmouseover="DisplayMenu('+"'"+i+"'"+', this);" onmouseout=setMenuTimer();><table cellspacing=0 cellpadding=0 border=0 width='+main[i].width+' height=24>');
  else
    document.writeln('<div id=main'+i+' style="position: absolute; Z-INDEX : 5; top: 27; left: '+main[i].location+';"><table cellspacing=0 cellpadding=0 border=0 width='+main[i].width+' height=24 onmouseover="DisplayMenu('+"'"+i+"'"+', this);" onmouseout=setMenuTimer(); onclick=getDestination(null);>'); 
  
  document.writeln('<tr><td align=center nowrap><a class=GB10 href="'+menuBase+main[i].url+'">'+main[i].title+'</a></td></tr></table></'+layerType+'>');

  if(IE4)
    eval(layerText+'["'+'main'+i+'"]'+styleText+'.cursor="hand"');
}


for(i=0; i<main.length; i++)
{
  if(main[i].sub==1)
    {
      smWidth=eval('sub'+i+'.smWidth');
      loc = Math.max(leftWidth, main[i].location+Math.round(main[i].width/2)-Math.round(smWidth/2));
      eval('sub'+i+'.left=loc');

      if(NS4)
	document.writeln('<layer id=bg'+i+' Z-INDEX=2 top=51 left='+loc+' visibility=hidden>');
      else
	document.writeln('<div id=bg'+i+' style="position: absolute; Z-INDEX : 2; top: 51; left: '+loc+'; visibility: hidden;">');   
      
      document.writeln('<table cellspacing=0 cellpadding=1 border=0 bgcolor=#666666 width='+smWidth+'><tr><td><table cellspacing=0 cellpadding=0 border=0 bgcolor=#cccccc width=100%%>');
      
      for(j=0; j<eval('sub'+i+'.length'); j++)
	document.writeln('<tr bgcolor=black><td><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr bgcolor=white><td><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr><tr><td height=15><img src='+idomain+'/ac/b.gif width=1 height=1></td></tr>');
      document.writeln('</table></td></tr></table></'+layerType+'>');
      
      if(NS4)
	{
	  for(j=0; j<eval('sub'+i+'.length'); j++)
	    {
	      eval('sub'+i+'['+j+'].top='+(j*17+53));   
	      document.writeln('<layer id=sub'+i+j+' Z-INDEX=5 TOP='+eval(j*17+53)+' LEFT='+loc+' VISIBILITY=hidden onmouseover="subMenuIn('+"'"+i+"', '"+j+"', this)"+'" onmouseout="subMenuOut('+"'"+i+"'"+", '"+j+"', this)"+'"><table cellspacing=0 cellpadding=0 border=0 width='+smWidth+' height=17><tr><td align=center><a class=G9 href="'+menuBase+eval('sub'+i+'['+j+'].url')+'">'+eval('sub'+i+'['+j+'].title')+'</a></td></tr></table></'+layerType+'>');	 
	    }
	}
      else
	{
	  document.writeln('<div id=sub'+i+' style="position: absolute; Z-INDEX : 5; top: 51; left: '+loc+'; visibility: hidden;"><table cellspacing=0 cellpadding=0 border=0 width='+smWidth+'>');
	  
	  for(j=0; j<eval('sub'+i+'.length'); j++)
	    {
	      eval('sub'+i+'['+j+'].top='+(j*17+52));
	      document.writeln('<tr><td height=17 align=center nowrap onmouseover="subMenuIn('+"'"+i+"', '"+j+"', this)"+'" onmouseout="subMenuOut('+"'"+i+"'"+", '"+j+"', this)"+'" onclick=getDestination(null)><a class=G9 href="'+menuBase+eval('sub'+i+'['+j+'].url')+'">'+eval('sub'+i+'['+j+'].title')+'</a></td></tr>');
	    }

	  document.writeln('</tr></table></div>');
	  
	  if(IE4)
	    eval(layerText+'["'+'sub'+i+'"]'+styleText+'.cursor="hand"');
	}
    }
}

searchLocation = Math.max(180, Math.round(windowWidth*.32));
if(priceMode=='2' || priceMode=='3')
  itemstring='<td width=180 height=20 align=center><font class=num2>Call '+phone+' to order</font></td>';
else
  itemstring='<td align=right valign=middle width=70><a href='+sc+'><img src='+idomain+'/ac/cart.gif ALT=\"view shopping cart\" width=23 height=20 border=0></a></td><td width=70><a class=s href='+sc+'>&nbsp;Items:&nbsp;'+items+'</a></td>';

document.writeln('<table valign=top cellspacing=0 cellpadding=0 border=0 bgcolor=black width='+eval(leftWidth+railWidth+59+rightWidth)+'><tr>'+itemstring+'<td><img src='+idomain+'/ac/b.gif width=330 height=1></td>'+loginlink+'</tr></table>');

searchLocation = Math.max(180, Math.round(windowWidth*.35));

if(NS4)
  document.writeln('<layer id=searchbox1 Z-INDEX=1 top=51 left='+searchLocation+'>');
else
  document.writeln('<div id=searchbox1 style="position: absolute; Z-INDEX: 1; top: 51; left: '+searchLocation+'">');

document.writeln('<table cellspacing=0 cellpadding=0 border=0 height=25><tr><td class=search valign=middle nowrap>Product Search:&nbsp;</td></tr></table></'+layerType+'>');

if(NS4)
  document.writeln('<layer id=searchbox Z-INDEX=1 top=52 left='+(searchLocation+95)+'>');
else
  document.writeln('<div id=searchbox style="position: absolute; Z-INDEX: 1; top: 52; left: '+(searchLocation+95)+'">');

document.writeln('<form method=get action='+sch+'><table cellspacing=0 cellpadding=0 border=0><tr><td><input type=text name=search class=searchbox size='+sl+' maxlength=50>&nbsp;<select name=searchtype><option value=and>Match all words<option value=or>Match any word</select></td><td><input type=image src='+idomain+'/c3/bgo.gif width=27 height=23 value=go name=go border=0></td></tr></table></form></'+layerType+'>');

document.writeln('<table valign=top cellspacing=0 cellpadding=0 border=0 width='+eval(leftWidth+railWidth+59+rightWidth)+'>');


if(NS4)
{
  for(i=0; i<eval(layerText+'.length'); i++)
    {
      eval(layerText+'['+i+'].captureEvents(Event.MOUSEUP)');
      eval(layerText+'['+i+'].onmouseup=getDestination');
    }
}


function getDestination(e)
{	
  setTimeout("G2()", 180);
  pressed=true;
}

function G2()
{
  if(subIndex==-1)
    window.location=menuBase+main[parseInt(mainIndex)].url;
  else if(subIndex>=0)
    window.location=menuBase+eval('sub'+mainIndex+'['+subIndex+'].url');
}













