/**************************************************************************************
   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));

    // Show the Menu.
    showList.style.left       = x + "px";
    showList.style.top        = y + "px";
	showList.style.visibility = "visible";

	
	
}


//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();
	}
} 



/***********************************************************
   Used to get the user photo from the database and show it.
***********************************************************/
function showPhoto(photoName, photoLocation, dirNav)
{

    var photoImg = document.getElementById('ajaxPhotoImg');
    if(photoName != '')
    {
       document.images['ajaxPhotoImg'].src = '' + dirNav + 'Images/UserPhotos/' + photoName;

       //alert('show photo');
       var photoArea = document.getElementById('ajaxPhoto');

	   var menuItem = document.getElementById(photoLocation);

	
	   var x, y; //position of menu
       var maxX, maxY;	 //max position size
	

	   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 -= photoArea.offsetWidth;
       maxY -= photoArea.offsetHeight;

       if (x > maxX)
	   {
          x = Math.max(0, x - menuItem.offsetWidth - menuItem.subMenu.offsetWidth
             + (menu.offsetWidth - menuItem.offsetWidth));
	   }
	  

       x = x + 44;
       y = y - 117;

       // Show the Menu.
       photoArea.style.left       = x + "px";
       photoArea.style.top        = y + "px";
       pause(.5);
	   photoArea.style.visibility = "visible";   
	}
}

/************************************************
   Used to hide the user photo from the database.
************************************************/
function hidePhoto()
{
   var photoArea = document.getElementById('ajaxPhoto');
   photoArea.style.visibility = "hidden";
}

















