/* ***************************************************************************
** MM_ FUNCTIONS ********************************************************** */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/* ***************************************************************************
** UTILITY FUNCTIONS ****************************************************** */
//Convenience function to set a radio button value (they're annoying to work with in JS).
function setRadioButtonValue(strButtonName, strValue) {
    var buttons = document.getElementsByName(strButtonName);
    for (var i=0; i<buttons.length; i++) {
        if (buttons[i].value == strValue) {
            buttons[i].checked=true;
        }
    }
}

//Convenience function to get a radio button value (they're annoying to work with in JS).
function getRadioButtonValue(strButtonName) {
    var buttons = document.getElementsByName(strButtonName);
    var val = '';
    for (var i=0; i<buttons.length; i++) {
        if (buttons[i].checked) {
            val = buttons[i].value;
        }
    }
    return val;
}

//Convenience function to modify the style of the specified element.  If element cannot be found,
// this function is a no-op.  Not all styles are supported: this is a convenience function just for
// our most commonly-accessed ones.
function setStyle(elementID, styleKey, styleValue) {
    var element = document.getElementById(elementID);
    if (element) {
        switch(styleKey) {
            case "visibility":
                element.style.visibility = styleValue;
                break;
            case "height":
                element.style.height = styleValue;
                break;
            case "display":
                element.style.display = styleValue;
                break;
        }
    }
}

//Convenience function to set the arrow pointer image to the currently selected nav node.
//If on another node's page, it will hide that node's arrow and show the currently hovered-on one.
//If element cannot be found, this function is a no-op.
function setOnArrow(elementID, arrowImg) {
    var element = document.getElementById(elementID);
    if (element) {
        element.src = arrowImg;
    }
}

//Convenience function to set the className of the specified element.  If element cannot be
// found, this function is a no-op.
function setClassName(elementID, newClass) {
    var element = document.getElementById(elementID);
    if (element) {
        element.className = newClass;
    }
}

//Returns true if the passed str contains only 0-9.  Returns false otherwise.
function isInteger(str) {
    var digits = "0123456789";
    var eachChr;
   
    //If passed a null string or empty string, return false.
    if (!str) { return false; }
    if (str.length == 0) { return false; }

    //walk each char.  If any aren't digits, return false immed.
    for (var i=0; i<str.length; i++) {
        eachChr = str.charAt(i);
        if (digits.indexOf(eachChr) < 0) {
            return false;
        }
    }
    //if we reach this point, it was nothing but digits.  return true.
    return true;
}

/* ***************************************************************************
** CUSTOM NAVIGATION FUNCTIONS ******************************************** */

//set this var to false to suppress closing of the subNav section.
var blnNavTimer = false;

//Individual pages should override this variable with the actual navNodes JSON.
var navNodes = [];
//Individual pages should override these variables with the actual default OIDs.
var defaultNavId = "";
var defaultSubNavId = "";
var defaultSubSubNavId = "";
var arrowIndicatorImgOn = "/images/pnav_indicatorarrow_on.gif";
var arrowIndicatorImgOff = "/images/pnav_indicatorarrow.gif";

//To be called when the top nav (Headwear, etc.) is moused-over.
function onMouseOverNav(navId) {
    //suppress the hiding of the nav section
    blnNavTimer = false;
    //Hide all nav sections, except the requested one.  Swap ON/OFF images (except the default one).
    for (var i=0; i<navNodes.length; i++) {
        setStyle("subNav_"+navNodes[i].OID, "visibility", (navNodes[i].OID==navId)?"visible":"hidden");
        //Show the current node's indicator arrow and hide the others
        setOnArrow("navArrowImage_"+navNodes[i].OID, (navNodes[i].OID==navId)?arrowIndicatorImgOn:arrowIndicatorImgOff);
    }
}

//To be called when any of the nav is moused-out: top nav, or the subNav section/div.
function onMouseOutNav() {
    blnNavTimer = true;
    setTimeout('revertNavToDefault()',1000);
}

//To be called when the subNav (Knit, Mens, etc.) is moused-over.
function onMouseOverSubNav(navId, subNavId) {
    //Find the current top-level nav, and walk its subnavs
    for (var i=0; i<navNodes.length;i++) {
        //hide all subNav sections, except the requested one.
        if (navNodes[i].OID == navId) {
            for (var j=0; j<navNodes[i].SubNavs.length; j++) {
                setStyle("subSubNav_"+navNodes[i].SubNavs[j].OID, "height", (navNodes[i].SubNavs[j].OID==subNavId)?"25px":"0px");
            }
        }
    }
}

//Sets the page to its default state, depending on the specified default OIDs.
function revertNavToDefault() {
    if(blnNavTimer) {
        //Hide all top nav sections, except the default one.
        for (var i=0; i<navNodes.length; i++) {
            setStyle("subNav_"+navNodes[i].OID, "visibility", (navNodes[i].OID==defaultNavId)?"visible":"hidden");
            //Show the current node's indicator arrow and hide the others
            setOnArrow("navArrowImage_"+navNodes[i].OID, (navNodes[i].OID==defaultNavId)?arrowIndicatorImgOn:arrowIndicatorImgOff);
            //Hide all subnav sections, except the default one.
            for (var j=0; j<navNodes[i].SubNavs.length; j++) {
                setStyle("subSubNav_"+navNodes[i].SubNavs[j].OID, "height", (navNodes[i].SubNavs[j].OID==defaultSubNavId)?"25px":"0px");
            }
        }
    }
}

//Called when page is loaded.  Based on default nav values, sets appropriate images and divs to their "startup" settings.
function initializeDefaultNavElements()
{
    //Use the "revert" function to make the appropriate nav items hidden or visible.
    blnNavTimer = true;
    revertNavToDefault();
}


