﻿// switch the active tab in the navigation menu
// newClassName: the new class the menu should get
// newTab: the type of tab that becomes active
function SwitchMenuStyle(newClassName, newTab) {
    var sMenu = document.getElementById("switchmenu");
    if (sMenu != null)
        sMenu.className = newClassName;
    if (newTab != null)
        document.cookie = 'SNP08AT='+ newTab +'; path=/';
}
// Set the tab the next page needs to open
function SetTabInCookie(newTab) {
    if (newTab != null)
        document.cookie = 'SNP08AT=' + newTab + '; path=/';
}
// Show the active tab if a value is available in the cookie
function ShowLastMenuTab() {
    var cookieValue = null;
    var nameEQ = "SNP08AT=";
    var ca = document.cookie.split(';');
    
    // try to get the value of the cookie
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) cookieValue = c.substring(nameEQ.length, c.length);
    }
    
    // if a cookie value is found, set the navigation meny
    if (cookieValue != null) {
        // get the navigation menu
        var sMenu = document.getElementById("switchmenu");
        var newClassName = null;

        if (sMenu != null) {
            switch (cookieValue) {
                case "navigate":
                    if (sMenu.className.indexOf('Suggest') >= 0) { newClassName = "showNavigateSuggestFilter"; } else { newClassName = "showNavigate"; }
                    break;
                case "filter":
                    if (sMenu.className.indexOf('Suggest') >= 0) { newClassName = "showFilterSuggestNavigate"; } else { newClassName = "showFilter"; }
                    break;
            }
        
            if (newClassName != null) {
                SwitchMenuStyle(newClassName, cookieValue);
            }
        }
    }
}
// open or close a tree (e.g. the worldpart = country tree)
function OpClWp(id) {
    var e = document.getElementById(id);
    if (e.style.display == 'none')
        e.style.display = 'block';
    else
        e.style.display = 'none';
}
// finds an absolute element position X
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
// finds an absolute element position X
function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
//shows the help div
function showHelp(obj)
{
    var xPosition = findPosX(obj); 
    var yPosition = findPosY(obj); 
    
    var divNavigationInfoOverlay = document.getElementById('NavigationInfoOverlay');
    var divNavigationInfo = document.getElementById('NavigationInfo');
    
    // scroll to the top of the page  
    divNavigationInfo.className='navigationInfoActiv'; 
    
	divNavigationInfoOverlay.style.top = yPosition + "px"
	divNavigationInfoOverlay.style.left = xPosition + 84 + "px"
	divNavigationInfoOverlay.style.position = "absolute";
}
function hideHelp(obj)
{
    obj.className='navigationInfo';
}
