// global.js
// site-wide functionality

/**********************************************************************
   Faceted Nav Search
 *********************************************************************/
    <!--//							
    function setGradient(color) {
      document.body.className=color;
    }						
    function displaySearch(display) {
      var searchForm=document.getElementById("searchForm");	
	  if(document.getElementById("search_input").value == '')
		searchForm.style.visibility=display;
    }			   
    //-->

/**********************************************************************
   Popups and New Windows
 *********************************************************************/

// openExternalLink(url) - use to open all off-site links
// ie: <a href="http://url.here" onclick="openExternalLink(this.href); return false;">
function openExternalLink(url) {
   return window.open(url, 'external', 'directories,location,menubar,resizable,scrollbars,status,toolbar');
}

/**********************************************************************
   Preload images for rollovers, whatever
 *********************************************************************/

function preloadImages() {
	document.preload = new Array();
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			document.preload[i] = new Image();
			document.preload[i].src = preloadImages.arguments[i];
		}
	}
}

/**********************************************************************
   Account DHTML menu
 *********************************************************************/

var accountMenuTimeout = null;

function showAccountMenu() {
   if (accountMenuTimeout) {
      clearTimeout(accountMenuTimeout);
   }
   //hide other menus
   hideEditorPickMenu();
   
   var accountLink = document.getElementById('accountLink');
   var menu = document.getElementById('globalNavAccount');
   setStyleForDropDownMenu(accountLink, menu);
}

function delayHideAccountMenu() {
   accountMenuTimeout = setTimeout('hideAccountMenu()', 30);
}

function hideAccountMenu() {
   document.getElementById('globalNavAccount').style.visibility = 'hidden';
}

function getOffsetTop(element, deep) {
	return getOffsetProperty(element, 'Top', deep);
}

function getOffsetLeft(element, deep) {
	return getOffsetProperty(element, 'Left', deep);
}

function getOffsetProperty(element, property, deep) {
   var offsetValue = 0;
   offsetProperty = 'offset' + property;
   
   do {
      offsetValue += element[offsetProperty];
      element = element.offsetParent;
   } while (deep == true && element != document.body && element != null);
   return offsetValue;
}

function getInnerWidth(win) {
  var winWidth;
  if (document.compatMode == "CSS2Compat" || (navigator.userAgent.indexOf('Gecko') != -1 && navigator.userAgent.indexOf('KHTML') == -1)) {
     winWidth = parseInt(win.document.defaultView.getComputedStyle(document.documentElement, null).getPropertyValue("width"));
  }
  else if (document.compatMode == "CSS1Compat") {
     winWidth = win.document.documentElement.clientWidth;
  }
  else if (navigator.appName == 'Netscape') {
     winWidth = win.innerWidth;
  }
  else {
     winWidth = win.document.body.clientWidth;
  }
  return winWidth;
}


// setNavHeight(elementToMatch,offsetLength) - use to match product section nav height to another element's height
// parameters: 
// elementToMatch - id of another element on page that you wish to match (if it's taller)
// offsetLength - offset to add to height of elementToMatch, good for margins and the like
// ie: <body onload="setNavHeight('rightColmn,9)">
// added by sbond@NOSPAMblastradius.com

function setNavHeight(elementToMatch,offsetLength) {
	var navCol = document.getElementById('productNav');
	var etm = document.getElementById(elementToMatch);
	var etmTotalHeight = etm.offsetHeight + parseInt(offsetLength);
	
	if(etmTotalHeight > navCol.offsetHeight) {
		navCol.style.height = etmTotalHeight + 'px';
	}
}


var globalEditorPickTimeout = null;

function showEditorPickMenu() {
   if (globalEditorPickTimeout) {
      clearTimeout(globalEditorPickTimeout);
   }
   //hide other menus
   hideAccountMenu();

   var editorPickLink = document.getElementById('editorPickLink');
   var menu = document.getElementById('globalEditorPickNav');
   setStyleForDropDownMenu(editorPickLink, menu);
}

function delayHideEditorPickMenu() {
   globalEditorPickTimeout = setTimeout('hideEditorPickMenu()', 30);
}

function hideEditorPickMenu() {
   document.getElementById('globalEditorPickNav').style.visibility = 'hidden';
}

function setStyleForDropDownMenu(link, menu) {
   var linkTop = parseInt(getOffsetTop(link, true));
   var linkLeft = parseInt(getOffsetLeft(link, true));
   menu.style.top = (linkTop - 23 - (linkTop <= 23 ? -8 : 24)) + 'px';
   menu.style.left = (linkLeft - parseInt((getInnerWidth(top) - 783)/ 2) - 7) + 'px';
   menu.style.visibility = 'visible';
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	return result;
}

function validateForm(theForm)
{
	if (!validRequired(theForm.Ntt,"Search"))
		return false;
	return true;
}

function showHideSearch(action){
  if(action=="hide"){
    document.getElementById("searchBySize").style.display = 'none';
  }
  if(action=="show"){
    document.getElementById("searchBySize").style.display = 'block';  }
	}