﻿// JScript File
var lastMenuDisplayed = null;
var lastMenuSender = null;
function menuOver(sender, menuToDisplay){
    
    try{
    
        if(lastMenuDisplayed != null){
            var lastMenu = $get(lastMenuDisplayed);
            lastMenu.style.zIndex = 1;
            RemoveClassName(lastMenu, "displayVisible");
            AddClassName(lastMenu, "displayHidden");
        }
        if(lastMenuSender != null){
            RemoveClassName($get($get(lastMenuSender).parentElement.id), "butOn");
            AddClassName($get($get(lastMenuSender).parentElement.id), "butOff");
            RemoveClassName($get(lastMenuSender), "mouseOn");
            AddClassName($get(lastMenuSender), "mouseOff");
        }
        lastMenuDisplayed = menuToDisplay;
        lastMenuSender = sender;
    }catch(err){
      //  alert("Off " + err.message);
        
    }

    var myMenu = $get(menuToDisplay);
    var myAdminMenu = $get(sender);
    try{
        myMenu.style.zIndex = 9999;
        if(myMenu.className!=null){
            RemoveClassName(myMenu, "displayHidden");
        }
    }catch(err){
        //alert("7 " + err.message);
    }
        
    try{
        AddClassName(myMenu, "displayVisible");
    }catch(err){
        //alert("2 " + err.message);
    }
    try{
        //var myMenuLocation = Sys.UI.DomElement.getBounds(myMenu);
        var myAdminItemLocation = Sys.UI.DomElement.getBounds(myAdminMenu);
        Sys.UI.DomElement.setLocation(myMenu, myAdminItemLocation.x, myAdminItemLocation.y+myAdminItemLocation.height);
    }catch(err){
        //alert("5");
    }

    //alert(myAdminMenu.parentElement.id);
    RemoveClassName($get(myAdminMenu.parentElement.id), "butOff");
    AddClassName($get(myAdminMenu.parentElement.id), "butOn");
    RemoveClassName($get(lastMenuSender), "mouseOff");
    AddClassName($get(lastMenuSender), "mouseOn");
}



function Browser() {
  var ua, s, i;
  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;
  ua = navigator.userAgent;
  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  // Treat any other "Gecko" browser as Netscape 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var browser = new Browser();

if (browser.isIE)
  document.onmousedown = delayMenuOff;
else
  document.addEventListener("mousedown", delayMenuOff, true);

function delayMenuOff(){
    setTimeout ( menuOff, 200 );
}

function menuOff(){
    if(lastMenuDisplayed!=null){
        var lastMenu = $get(lastMenuDisplayed);
        RemoveClassName(lastMenu, "displayVisible");
        AddClassName(lastMenu, "displayHidden");
    }
    if(lastMenuSender!=null){
        RemoveClassName($get($get(lastMenuSender).parentElement.id), "butOn");
        AddClassName($get($get(lastMenuSender).parentElement.id), "butOff");
        RemoveClassName($get(lastMenuSender), "mouseOn");
        AddClassName($get(lastMenuSender), "mouseOff");
    }
}



// ----------------------------------------------------------------------------
// HasClassName
//
// Description : returns boolean indicating whether the object has the class name
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function HasClassName(objElement, strClass)
   {
   // if there is a class
   if ( objElement.className )
      {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');
      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();
      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {
            // we found it
            return true;
            }
         }
      }
   // if we got here then the class name is not there
   return false;
   }
// HasClassName
// ----------------------------------------------------------------------------
// AddClassName
//
// Description : adds a class to the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
//
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to add
//
function AddClassName(objElement, strClass, blnMayAlreadyExist)
   {
   // if there is a class
   if ( objElement.className )
      {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');
      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
         {
         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();
         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
            {
            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
               {
               // remove array item
               arrList.splice(i, 1);
               // decrement loop counter as we have adjusted the array's contents
               i--;
               }
            }
         }
      // add the new class to end of list
      arrList[arrList.length] = strClass;
      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      // assign modified class name attribute
      objElement.className = arrList.join(' ');
      }
   // if there was no class
   else
      {
      // assign modified class name attribute      
      objElement.className = strClass;
      }
   }
// AddClassName
// ----------------------------------------------------------------------------
// RemoveClassName
// Description : removes a class from the class attribute of a DOM element
//    built with the understanding that there may be multiple classes
// Arguments:
//    objElement              - element to manipulate
//    strClass                - class name to remove
//
function RemoveClassName(objElement, strClass)
   {
   // if there is a class
   if ( objElement.className )
      {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');
      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();
      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
         {
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
            {
            // remove array item
            arrList.splice(i, 1);
            // decrement loop counter as we have adjusted the array's contents
            i--;

            }
         }
      // assign modified class name attribute
      objElement.className = arrList.join(' ');
      }
   // if there was no class
   // there is nothing to remove
   }
// 
// RemoveClassName
// ----------------------------------------------------------------------------