// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.

// Modified 8/27/2009 JAP

// ***** Popup Control *********************************************************

// ***** mt_show_aux *****

function mt_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  var top  = (c["at_position"] == "y") ? p.offsetHeight+29 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }
  
  if (navigator.appName == "Microsoft Internet Explorer")
    top -= 29;
  if (navigator.appName == "Opera")
    top -= 42;
    
  c.style.position   = "absolute";
  c.style.top        = (top-77) +'px';
  if(navigator.userAgent.indexOf('Mac') != -1)
	c.style.top = (top-77) + 'px';
  c.style.left       = '0px';
  c.style.visibility = "visible";
}

// ***** mt_show *****

function mt_show()
{

  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child"]);
  
  var u = document.getElementById('JHeader1_divu');
  var m = document.getElementById('JHeader1_divm');
  var w = document.getElementById('JHeader1_divw');
  var k = document.getElementById('JHeader1_divk');
  var s = document.getElementById('JHeader1_divs');
  
  var selected = "";
  var style = "";
  
  // Find the tab that should be permanently on the page.
  if(document.getElementById('JHeader1_divu').className == "backu2" || document.getElementById('JHeader1_divu').className == "backu3")
  {
	selected = document.getElementById('JHeader1_divu');
	style = "backu3";
  }
  else if(document.getElementById('JHeader1_divm').className == "backm2" || document.getElementById('JHeader1_divm').className == "backm3")
  {
	selected = document.getElementById('JHeader1_divm');
	style = "backm3";
  }
  else if(document.getElementById('JHeader1_divw').className == "backw2" || document.getElementById('JHeader1_divw').className == "backw3")
  {
selected = document.getElementById('JHeader1_divw');
	style = "backw3";
  }
  else if(document.getElementById('JHeader1_divk').className == "backk2" || document.getElementById('JHeader1_divk').className == "backk3")
  {
	selected = document.getElementById('JHeader1_divk');
	style = "backk3";
  }
  else if(document.getElementById('JHeader1_divs').className == "backs2" || document.getElementById('JHeader1_divs').className == "backs3")
  {
	selected = document.getElementById('JHeader1_divs');  
	style = "backs3";
  } 
  
  // Change the background of the moused over link to have the tab image and change the permanent tab's background to the underlined image.
 
 
 if(this["at_parent"] == "underwear" && document.getElementById('JHeader1_divu').className != "backu2")
  {
	document.getElementById('JHeader1_divu').className='backu';
	if(selected != "")
		selected.className = style;
  }
  else if(this["at_parent"] == "men" && document.getElementById('JHeader1_divm').className != "backm2")
  {
	document.getElementById('JHeader1_divm').className='backm';
	if(selected != "")
		selected.className = style;
  }
  else if(this["at_parent"] == "women" && document.getElementById('JHeader1_divw').className != "backw2")
  {
	document.getElementById('JHeader1_divw').className='backw';
	if(selected != "")
		selected.className = style;
  }
  else if(this["at_parent"] == "kids" && document.getElementById('JHeader1_divk').className != "backk2")
  {
	document.getElementById('JHeader1_divk').className='backk';
	if(selected != "")
		selected.className = style;
  }
  else if(this["at_parent"] == "sale" && document.getElementById('JHeader1_divs').className != "backs2")
  {
	document.getElementById('JHeader1_divs').className='backs';
	if(selected != "")
		selected.className = style;
  }
  
  var myObj = document.getElementById('repShipments__ctl0_repLineItem__ctl0_ItemQuantity');
  if (myObj != null)
  	myObj.style.visibility = 'hidden';

  mt_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
  
  clearTimeout(u["at_timeout"]);
  clearTimeout(m["at_timeout"]);
  clearTimeout(w["at_timeout"]);
  clearTimeout(k["at_timeout"]);
  clearTimeout(s["at_timeout"]);
  
  // remove the background of any links that have the tab "stuck" on after the timeout.
  if(this["at_parent"] != "underwear" && document.getElementById('JHeader1_divu').className == "backu")
  {
	document.getElementById('JHeader1_divu').className='';
  }
  else if(this["at_parent"] != "men" && document.getElementById('JHeader1_divm').className == "backm")
  {
	document.getElementById('JHeader1_divm').className='';
  }
  else if(this["at_parent"] != "women" && document.getElementById('JHeader1_divw').className == "backw")
  {
	document.getElementById('JHeader1_divw').className='';
  }
  else if(this["at_parent"] != "kids" && document.getElementById('JHeader1_divk').className == "backk")
  {
	document.getElementById('JHeader1_divk').className='';
  }
  else if(this["at_parent"] != "sale" && document.getElementById('JHeader1_divs').className == "backs")
  {
	document.getElementById('JHeader1_divs').className='';
  }
}

// ***** mt_hide *****

function mt_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child"]);
  
  var u = document.getElementById('JHeader1_divu');
  var m = document.getElementById('JHeader1_divm');
  var w = document.getElementById('JHeader1_divw');
  var k = document.getElementById('JHeader1_divk');
  var s = document.getElementById('JHeader1_divs');

  if (c.className != "NAVshow")
  {
	c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
  }
	  
  var selected = document.getElementById('JHeader1_divu');
  var style = "";
  
  // change the background of the underlined tab back to the un-underlined tab image.
  if(document.getElementById('JHeader1_divu').className == "backu3")
  {
	selected = document.getElementById('JHeader1_divu');
	style = "backu2";
  }
  else if(document.getElementById('JHeader1_divm').className == "backm3")
  {
	selected = document.getElementById('JHeader1_divm');
	style = "backm2";
  }
  else if(document.getElementById('JHeader1_divw').className == "backw3")
  {
	selected = document.getElementById('JHeader1_divw');
	style = "backw2";
  }
  else if(document.getElementById('JHeader1_divk').className == "backk3")
  {
	selected = document.getElementById('JHeader1_divk');
	style = "backk2";
  }
  else if(document.getElementById('JHeader1_divs').className == "backs3")
  {
	selected = document.getElementById('JHeader1_divs');  
	style = "backs2";
  } 
  
  if(this["at_parent"] == "underwear" && document.getElementById('JHeader1_divu').className != "backu2")
  {
	u["at_timeout"] = setTimeout("document.getElementById('JHeader1_divu').className=''; if(" + selected.id + " != '') " + selected.id + ".className = '" + style + "';", 333);		
  }
  else if(this["at_parent"] == "men" && document.getElementById('JHeader1_divm').className != "backm2")
  {
	m["at_timeout"] = setTimeout("document.getElementById('JHeader1_divm').className=''; if(" + selected.id + " != '') " + selected.id + ".className = '" + style + "';", 333);
  }
  else if(this["at_parent"] == "women" && document.getElementById('JHeader1_divw').className != "backw2")
  {
	w["at_timeout"] = setTimeout("document.getElementById('JHeader1_divw').className=''; if(" + selected.id + " != '') " + selected.id + ".className = '" + style + "';", 333);
  }
  else if(this["at_parent"] == "kids" && document.getElementById('JHeader1_divk').className != "backk2")
  {
	k["at_timeout"] = setTimeout("document.getElementById('JHeader1_divk').className=''; if(" + selected.id + " != '') " + selected.id + ".className = '" + style + "';", 333);
  }
  else if(this["at_parent"] == "sale" && document.getElementById('JHeader1_divs').className != "backs2")
  {
    s["at_timeout"] = setTimeout("document.getElementById('JHeader1_divs').className=''; if(" + selected.id + " != '') " + selected.id + ".className = '" + style + "';", 333);
	//document.getElementById('JHeader1_divs').className='';
	//if(selected != "")
	//	selected.className = style;
  }
   var myObj = document.getElementById('repShipments__ctl0_repLineItem__ctl0_ItemQuantity');
   if (myObj != null)
   	myObj.style.visibility = 'visible';
  
}

// ***** mt_click *****

function mt_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child"]);

  if (c.style.visibility != "visible") mt_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** mt_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function mt_attach(parent, child, showtype, position, cursor)
{

 var p = document.getElementById(parent);
 var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = mt_click;
      p.onmouseout  = mt_hide;
      c.onmouseover = mt_show;
      c.onmouseout  = mt_hide;
      break;
    case "hover":
      p.onmouseover = mt_show;
      p.onmouseout  = mt_hide;
      c.onmouseover = mt_show;
      c.onmouseout  = mt_hide;
      break;
  }
 }
   
