/*******************************************************************************
* Menu
*******************************************************************************/

var selectedTabId = 0;
var selectedSubMenu = null;
var selectedMenuImage = null;
var killMenuTimer = 0;
var menuImageCache = new Array();

function PreloadImage(tabId, src)
{
    menuImageCache[tabId + "_0"] = null;

    menuImageCache[tabId + "_1"] = new Image();
    menuImageCache[tabId + "_1"].src = src.replace("moveover=0", "moveover=1").replace("&amp;", "&");
}

function SwitchImage(obj, tabId, selected)
{
    if (selected)
    {
        if (menuImageCache[tabId + "_0"] == null)
        {
            menuImageCache[tabId + "_0"] = new Image();
            menuImageCache[tabId + "_0"].src = obj.src.replace("&amp;", "&");
        }
        
        obj.src = menuImageCache[tabId + "_1"].src;
    }
    else
    {
        obj.src = menuImageCache[tabId + "_0"].src;
    }
}

function OverTopMenu(tabId)
{
    // Clear Timer
	clearTimeout(killMenuTimer);

    // Is a new Tab selected?
    if (tabId != selectedTabId)
    {
        // Hide the previously selected Menu
        if (selectedTabId != 0)
        {
            KillMenu();
        }

        // Show the new Menu    
    	if (tabId != null)
    	{
		    ShowMenu(tabId);
		}
	}
}

function OutTopMenu()
{
    // Hide the menu
    if (selectedSubMenu != null)
    {
	    killMenuTimer = setTimeout("KillMenu()", 500);
	}
	else
	{
	    KillMenu();
	}
}

function ShowMenu(tabId)
{
    // Set TabId
    selectedTabId = tabId;
    
    // Select Elements
    selectedSubMenu = document.getElementById("_ctl0_menu_" + selectedTabId);
    selectedMenuImage = document.getElementById("_ctl0_menuimg_" + selectedTabId);

	// Get the desired position for the SubMenu
	var newLeft = 0;
	var newTop = 0;
	
	if (navigator.appName.toLowerCase() == "netscape")
	{
		newTop = document.getBoxObjectFor(selectedMenuImage).y - 40;
		newLeft = document.getBoxObjectFor(selectedMenuImage).x - 0;
	}
	else
	{
		newTop = selectedMenuImage.getBoundingClientRect().top - 42 +  bdy.scrollTop;
		newLeft = selectedMenuImage.getBoundingClientRect().left +  bdy.scrollLeft-2;
	}

    // Change TopMenu Image
    if (selectedMenuImage != null)
    {
	    SwitchImage(selectedMenuImage, selectedTabId, true);
	}
	
	// Show SubMenu
	if (selectedSubMenu != null)
	{
		selectedSubMenu.style.left = newLeft + "px";
		selectedSubMenu.style.top = newTop + "px";
		selectedSubMenu.style.visibility = "visible"; 
	}
	
	// ?
	if (document.getElementById("docomboboxm_oCbx_button"))
	{
		document.getElementById("docomboboxm_oCbx_button").style.top = -100000;
	}
}

function KillMenu()
{
	// Reset TopMenu Image
    if (selectedMenuImage != null)
    {
	    SwitchImage(selectedMenuImage, selectedTabId, false);
	    selectedMenuImage = null;
    }

    // Hide SubMenu
    if (selectedSubMenu != null)
    {
		selectedSubMenu.style.visibility = "hidden"; 
	    selectedSubMenu = null;		
    }
	
	// Reset SelectedTabId
	selectedTabId = 0;
}

/*******************************************************************************
* DODropDown
*******************************************************************************/

var oSelectedDropDown = null;
var nHideTimerId = 0;

function OnOverComboBoxArrow(strName, nWidth)
{
	oSelectedDropDown =  document.getElementById(strName + "_Content");
	oSelectedDropDown.style.visibility = "visible";
}

function NavigateToTab(nTabId)
{
	strLocation = document.location.toString();
	strLocation = strLocation.substring(0, strLocation.lastIndexOf("DesktopDefault.aspx"));
	strLocation = strLocation + "DesktopDefault.aspx/tabid-" + nTabId + "/";
	document.location = strLocation;
}

function HideComboBox(strName)
{
	document.getElementById(strName + "_Content").style.visibility = "hidden";
	oSelectedDropDown = null;
}

function OnOutComoBoxArrow(strName)
{
	nHideTimerId = setTimeout("HideComboBox('" + strName + "')", 1000);
}

function OnOverComboBoxItem(obj)
{
	clearTimeout(nHideTimerId);
	obj.className = "DO_ComboBoxItem_Selected";
}

function OnOutComboBoxItem(obj)
{
	obj.className = "DO_ComboBoxItem_NotSelected";
}

function OnClickComboBoxItem(strLink, strTarget)
{
	if (strTarget == "")
	{
		document.location = strLink;
	}
	else if (strTarget == "_blank")
	{
		open(strLink, "", "");
	}

	if(oSelectedDropDown != null)
	{
		oSelectedDropDown.style.visibility = "hidden";
	}
}

function ReplaceTagFromString(strString, strTag, strStringToReplace)
{
	while (strString.indexOf(strTag) > -1)
	{
		strString = strString.replace(strTag, strStringToReplace);
	}
	
	return strString;
}

function GetStringAsHTML(strString)
{
	return escape(strString);
}

function GetTabIdFromUrl(strUrl)
{
	nPos = strUrl.indexOf("tabid-");
	
	if (nPos > 0)
	{
		strUrl = strUrl.substring(nPos+6, nPos+1000);
		nPos = strUrl.indexOf("/");
		strUrl = strUrl.substring(0, nPos);
	}
	
	return strUrl;
}
