﻿var hoverClass = "AspNet-Menu-Hover";
var topmostClass = "AspNet-Menu";
var userAgent = navigator.userAgent; 
var versionOffset = userAgent.indexOf("MSIE"); 
var isIE = (versionOffset >= 0); 
var isPreIE7 = false; 
var fullVersionIE = ""; 
var majorVersionIE = ""; 

if (isIE) 
{ 
    fullVersionIE = parseFloat(userAgent.substring(versionOffset+5, userAgent.length)); 
    majorVersionIE = parseInt('' + fullVersionIE); 
    isPreIE7 = majorVersionIE < 7; 
} 

function Hover__AspNetMenu(element)
{
//    AddClassUpward__CssFriendlyAdapters(element.firstChild /* gets the inner SPAN or A */, topmostClass, hoverClass);
    AddClass__CssFriendlyAdapters(element, hoverClass);
}

function Unhover__AspNetMenu(element)
{
//    RemoveClassUpward__CssFriendlyAdapters(element.firstChild /* gets the inner SPAN or A */, topmostClass, hoverClass);
    RemoveClass__CssFriendlyAdapters(element, hoverClass);
}

function SetHover__AspNetMenu()
{
    var menus = document.getElementsByTagName("ul");
    for (var i=0; i<menus.length; i++)
    {
        if(menus[i].className == topmostClass)
        {
            var items = menus[i].getElementsByTagName("li");
            for (var k=0; k<items.length; k++)
            {
                items[k].onmouseover = function() { Hover__AspNetMenu(this); }
                items[k].onmouseout = function() { Unhover__AspNetMenu(this); }
            }
        }
    }
}

//window.onload = SetHover__AspNetMenu;

function SetupMenuForIE6() {
      //if (isPreIE7) {
            SetHover__AspNetMenu();
     //}
}

function ShowLevel3Menu(oControl, iType){
    //if (oControl.children.length > 1){
    if (child_nodes_length(oControl) > 1){
        //oControl.children[1].style.display = "block";
        child_nodes(oControl ,1).style.display = "block";
    }
    else if (iType == 1){
        //oControl.nextSibling.children[1].style.display = "block";
        child_nodes(node_after(oControl), 1).style.display = "block";
    }
    else if (iType == 2){
        //oControl.parentNode.previousSibling.children[1].children[1].style.display = "block";
        child_nodes(child_nodes(node_before(oControl.parentNode), 1) , 1).style.display = "block";
    }
}
function HideLevel3Menu(oControl, iType){
   //if (oControl.children.length > 1){
   if (child_nodes_length(oControl) > 1){
      //oControl.children[1].style.display = "none";
      child_nodes(oControl ,1).style.display = "none";
   }
   else if (iType == 1){
       //oControl.nextSibling.children[1].style.display = "none";
       child_nodes(node_after(oControl), 1).style.display = "none";
   }
   else if (iType == 2){
        //oControl.parentNode.previousSibling.children[1].children[1].style.display = "none";
        child_nodes(child_nodes(node_before(oControl.parentNode), 1) , 1).style.display = "none";
    }
}
function first_child( par )
{
    if(par.firstChild){
      var res=par.firstChild;
      while (res) {
        if (!is_ignorable(res)) return res;
        res = res.nextSibling;
      }
    }
  return null;
}
function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}
function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}
function child_nodes( par , nr)
{
    if(par.firstChild){
      var res=par.firstChild;
      while (res) {
        if (!is_ignorable(res)){ 
            return next_siblings(res, nr);
        }
        res = res.nextSibling;
      }
    }
  return null;
}
function child_nodes_length( par)
{
    var iLength=0;
    if(par.firstChild){
      var res=par.firstChild;
      while (res) {
        if (!is_ignorable(res)){ 
            iLength++;
        }
        res = res.nextSibling;
      }
    }
  return iLength;
}
function next_siblings( sib , nr)
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) {
        if(nr > 1){
            return next_siblings(sib, nr-1);
        }else{
            return sib;
        }
    }
  }
  return null;
}
