/**************************************************************************************
   Developed for: Allegiance
   Developed by:  Kevin Scott
   Development date: 06/09/2006
   Description:  This java script file is responsible for providing a dynamic drop down
   		 list for buttons.
   Modified date: 10/17/2006
**************************************************************************************/

function getBrowser() {

  this.Type = "UnKnown";
  var uAgent = navigator.userAgent;
  var checkBrowser = "";

  checkBrowser = "Opera";
  if (uAgent.indexOf(checkBrowser) >= 0) {
    this.Type = checkBrowser;
    return;
  }
  
  checkBrowser = "Netscape";
  if (uAgent.indexOf(checkBrowser) >= 0) {
    this.Type = checkBrowser;
    return;
  }

  // Firefox is netscape as well
  checkBrowser = "Gecko";
  if (uAgent.indexOf(checkBrowser) >= 0) {
    this.Type = "Netscape";
    return;
  }

  checkBrowser = "MSIE";
  if (uAgent.indexOf(checkBrowser) >= 0) {
    this.Type = "IE";
    return;
  }
  
  
}

var webBrowser = new getBrowser();





function hideDropMenu(dropDownList)
{
	//pause(.2);
	
	var hideList = document.getElementById(dropDownList + '_List');
	//alert('Focused: ' + hideList.focus());
	hideList.style.visibility = "hidden";
	
	
}
   var x_Top_Left;
   var y_Top_Left;
   var windowHeight;
   var windowWidth;
   
   
   
   
   
function showDropMenu(dropDownList, menuWidth)
{
	
	var menuItem = document.getElementById(dropDownList);
	var showList = document.getElementById(dropDownList + '_List');
	
	var x, y; //position of menu
    var maxX, maxY;	 //max position size
	
	
	
	showList.style.width = menuWidth + 'px';
	x = getOffsetLeft(menuItem);
    y = getOffsetTop(menuItem) + menuItem.offsetHeight;

    // Adjust position to fit in window.

    if (webBrowser.Type == "IE") {
      maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
        (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
      maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
        (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
    }
    if (webBrowser.Type == "Opera") {
      maxX = document.documentElement.scrollLeft + window.innerWidth;
      maxY = document.documentElement.scrollTop  + window.innerHeight;
    }
    if (webBrowser.Type == "Netscape") {
      maxX = window.scrollX + window.innerWidth;
      maxY = window.scrollY + window.innerHeight;
    }
    
	maxX -= showList.offsetWidth;
    maxY -= showList.offsetHeight;

    if (x > maxX)
	{
      x = Math.max(0, x - menuItem.offsetWidth - menuItem.subMenu.offsetWidth
        + (menu.offsetWidth - menuItem.offsetWidth));
	}
	  
      y = Math.max(0, Math.min(y, maxY));

    y = y - 3;

    // Show the Menu.
    showList.style.left       = x + "px";
    showList.style.top        = y + "px";
	showList.style.visibility = "visible";
	//alert(webBrowser.Type);
	
    //x_Top_Left = x;
    //y_Top_Left = y;	
	//windowHeight = showList.clientHeight;
    //windowWidth = showList.clientWidth;
	
	
}


//Gest X element relative to the page
function getOffsetLeft(el) {

  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getOffsetLeft(el.offsetParent);

  return x;
}

//Gest Y element relative to the page
function getOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getOffsetTop(el.offsetParent);
  return y;
}


function pause(seconds)
{
	var miliseconds = seconds * 1000;
	var date = new Date();
	var curDate = date; 
	while(curDate-date < miliseconds)
	{
		curDate = new Date();
	}
} 





















