function doSearch(inputObj){
  window.location = "/Pages/Search.aspx?search=" + escape(inputObj.value);
  
}
function inputDoSearch(inputObj,e){
  var keycode;  

  if (window.event) 
    keycode = window.event.keyCode; 
  else if (e)
    keycode = e.which;  
  else 
    return true;
  
  if (keycode == 13) {
    doSearch(inputObj);
    return false;
  }
}



var activeSubMenu;

// call on mouseover menu items
function menuIn(mainmenuIndex){
  var submenus = $('subMenus').select('div.subMenu'); 
  $('subMenus').style.visibility='visible';

  submenus.each(function(submenu){
    submenu.style.display='none';
  });
  
  $('sub'+mainmenuIndex).style.display='block';
  Position.absolutize($('sub'+mainmenuIndex));
  activeSubMenu = $('sub'+mainmenuIndex);
}


function menuAreaOut(e){

  getEventCoordinates(e);

  if(typeof activeSubMenu != 'undefined'){
    // check if we should close the active submenu
    var withinMainmenus = Position.within($('mainmenus'), tempX, tempY);
    
    var withinSubMenu = Position.within(activeSubMenu, tempX, tempY);
    
    var withinDescendants = false;

    // for FF and safari we need to check descendant elements too
    if (!withinMainmenus && !withinSubMenu){
      activeSubMenu.descendants().each(function(descendant){
        var withinDescendant = Position.within(descendant, tempX, tempY);
        if (withinDescendant){
          withinDescendants = true;
        }
      });
    }
    
    if (!(withinMainmenus || withinSubMenu || withinDescendants)){
      activeSubMenu.style.display = 'none';
      $('subMenus').style.visibility='hidden';
    }
  }
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false
    
var tempX = 0
var tempY = 0
function getEventCoordinates(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
}  
