//Menu
function ToggleAll(item)
{
  var subMenuCount = parseInt(document.getElementById("leftMenu").getAttribute("subMenuCount"));
  for(i=1; i< subMenuCount + 1; i++)
  {
    obj=document.getElementById("subMenu"+i);
    iconObj=document.getElementById("icon"+i);
    if ("subMenu"+i != item)
    {
      obj.style.display="none";
          iconObj.className = "iconexp";
    }
    else
    {
      if (obj.style.display == "")
      {
        obj.style.display="none";
        iconObj.className = "iconexp";
      }
      else
      {
        obj.style.display="";
        iconObj.className = "iconcol";
      }
    }
  }
}

function ToggleSubMenu(tblSubMenuId, thisObject)
{
  var divLeftMenu = document.getElementById("LeftMenuDiv");
  var tables = divLeftMenu.getElementsByTagName("table");
  for(i=0; i < tables.length; i++)
  {
    obj=tables[i];
    if(obj.id == "")
        continue;
    var headerRow = obj.getElementsByTagName("tr")[0];
    var bodyRow = obj.getElementsByTagName("tr")[1];
    if (obj.id != tblSubMenuId)
    {
        bodyRow.style.display="none";
        headerRow.getElementsByTagName("td")[0].className = "iconexp";
    }
    else
    {
        if (bodyRow.style == null || bodyRow.style.display == "none")
        {
            bodyRow.style.display="";
            headerRow.getElementsByTagName("td")[0].className = "iconcol";
        }
        else
        {
            bodyRow.style.display="none";
            headerRow.getElementsByTagName("td")[0].className = "iconexp";
        }
    }
  }
}

var currentMenu;
var timer;
function showMenu(subNav)
{
  clearTimer();
  try
  {
    var obj;
    for(i=1; i < 8; i++)
    {
      obj = document.getElementById("subNav"+i);
      obj.style.display="none";
    }
    if (subNav != "hideAll")
      document.getElementById(subNav).style.display="";
  }
  catch(e){;}
}

function clearTimer()
{
  clearTimeout(timer);
}

function showCurrentNav()
{
  timer = window.setTimeout(function(){showMenu("hideAll")}, 500); 

  //if we need to show again teh currentNavigation
  //timer = window.setTimeout(function(){showMenu("currentMenu")}, 500); 
}

function menuEvents()
{
   // a rule is to use a patter for the body className "xxxxxxxx#" where # is the page number
   currentMenu = "subNav" + document.body.className.substr(8,9);

    var obj;
    var aa;
    for(i=1; i < 8; i++)
    {
      obj = document.getElementById("nav"+i);
      
      if(obj == null)
         obj = document.getElementById("ctl00_ucMenu_nav"+i);
        
        
      eval("obj.onmouseover = function(){showMenu('subNav" + i + "')}");
      obj.onmouseout = showCurrentNav;
      

      obj = document.getElementById("subNav"+i);
      //Top navigation bar: the dropdown menus should only be visible when they are moused over.  None of the dropdowns should be visible when you mouse away. "modification"
      obj.style.display="none";
      obj.onmouseover = clearTimer;
      obj.onmouseout = showCurrentNav;
    }

}


function Browser_IsIE() 
{
    return (/MSIE/.test(navigator.userAgent)); 
}
  
function Browser_IsIE7() 
{
    return (/MSIE 7/.test(navigator.userAgent)); 
}

function Browser_IsFireFox() 
{
    return (/Firefox/.test(navigator.userAgent)); 
}

function Browser_IsSafari() 
{
    return (/Safari/.test(navigator.userAgent)); 
}

function Browser_IsOpera() 
{
    return (/Opera/.test(navigator.userAgent)); 
}

// call the function fixDynamcShadow to adjust the shadow positioning when the onload event is launched
if (window.addEventListener)
  window.addEventListener("load", fixDynamcShadow, false);
else if (window.attachEvent)
  window.attachEvent("onload", fixDynamcShadow);
  
if (window.addEventListener)
  window.addEventListener("resize", adjustIe6FloatLi, false);
else if (window.attachEvent)
  window.attachEvent("onresize", adjustIe6FloatLi);
  
 
 function adjustIe6FloatLi()
 {
   if ((Browser_IsIE() || Browser_IsIE7()) &&document.getElementById("main") != null && document.getElementById("main") != "undefined")
     document.getElementById("main").className="hintToAdjustThefloatLiElementsInTheMainNavigationUlUnderIE6";
 }
 
function fixDynamcShadow()
{
  var heightFix;
  try
  {
    if (document.getElementById("rightBgTable") != null && document.getElementById("rightBgTable") != "undefined")
    {
      if((Browser_IsIE() || Browser_IsOpera()) && !Browser_IsIE7())
      {
        heightFix = 600 - document.getElementById("rightBgTable").offsetParent.offsetTop;
        document.getElementById("rightBgdTdFix").height = heightFix;
        document.getElementById("rightBgTdDynamic").height = document.getElementById("content").offsetHeight - heightFix  + 15;
      }
      else if(Browser_IsSafari())
      {
        heightFix = 600 - document.getElementById("rightBgTable").offsetParent.offsetTop - 2;
        document.getElementById("rightBgdTdFix").height = heightFix;
        document.getElementById("rightBgTdDynamic").height = document.getElementById("content").offsetHeight - heightFix + 11;
      }
      else //Browser_IsFireFox()
      {
        heightFix = 600 - document.getElementById("rightBgTable").offsetParent.offsetTop;
        document.getElementById("rightBgdTdFix").height = heightFix;
        document.getElementById("rightBgTdDynamic").height = document.getElementById("content").offsetHeight - heightFix;
      }
     }
    menuEvents();
  }
  catch(e){;}
}

// Forgot Password
function RetrievePassword() {
	IE = browser.IsIE();
	NS = browser.IsNetscape();
	bVer = browser.Version; 
	var newWin=null;
	var loc = ApplicationPath + "/pages/safe_register/gemprint_registry/ForgotPassword.aspx";
	var name = "popupwin";
	var width = "375";
	var height = "200";
	var _params = "width="+width+",height="+height+",resizable=no,status=no,scrollbars=no";
	if (bVer >= 4) {
		_left = ( (screen.width-width) >>1 );
		_top = ( (screen.height-height) >>1 );
	} else {
		_left = ( (800-width) >>1 );
		_top = ( (600-height) >>1 );
	}
	if (IE) _params += ",top=" + _top + ",left=" + _left;
	else if (NS) _params += ",screenX=" + _left + ",screenY=" + _top;
	newWin = window.open(loc, name, _params);
	if ( newWin!=null && !(IE && bVer<5) )
		newWin.focus();
}

//Terms of conditions and privacy
function ShowDialog(url)
{   
    var height = "800px";
    var width = "1000px";
    var openParams = "width=" + width + ",height=" + height + ",resizable=yes,status=no";
	var modalDialogParams = "dialogWidth:" + width + ";dialogHeight:" + height + ";center:yes;help:no;resizable:yes;status:no;scroll:yes";
    if(!browser.IsOpera())
	    window.showModalDialog(ApplicationPath + url, '', modalDialogParams); 
    else
        window.open(ApplicationPath + url, '', '_blank', openParams); 
    
}


//Alert + Redirection
function AlertAndRedirect(msg, url)
{
    var x = alert(msg);
    window.location.href = ApplicationPath + url;
    
}

var manager;
function pageLoad()
{
    manager = Sys.WebForms.PageRequestManager.getInstance(); 
    manager.add_endRequest(endRequest);
    manager.add_beginRequest(OnBeginRequest);
}

function OnBeginRequest(sender, args)
{
    $get('ParentDiv').style.display ='block'; 
} 

function endRequest(sender, args)
{
    $get('ParentDiv').style.display ='none'; 
}   

//function OnBeginRequest(sender, args)
//{
//    $get('ParentDiv').className ='Background'; 
//} 

//function endRequest(sender, args)
//{
//    $get('ParentDiv').className ='';
//}  

function OpenPDFPrinter(url)
{
    var height = "800px";
    var width = "1000px";
    var openParams = "width=" + width + ",height=" + height + ",resizable=1,status=0,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no";
	//var modalDialogParams = "dialogWidth:" + width + ";dialogHeight:" + height + ";center:yes;help:no;resizable:yes;status:no;scroll:yes";
    
    window.open(url, null, openParams); 
        
} 

