var menuTimer;

function hideMenu(parentDivID) {
	var subMenu = document.all ? document.all[parentDivID + "-sub"] : document.getElementById(parentDivID + "-sub");
	var menuButton = document.all ? document.all[parentDivID + "-button"] : document.getElementById(parentDivID + "-button");
	var parentDiv = document.all ? document.all[parentDivID] : document.getElementById(parentDivID);
	
	if ((subMenu) && (menuButton) && (parentDiv))
	{
		if (menuTimer)
		{ 
		clearTimeout(menuTimer);
		menuTimer = null; 
		}
		menuButton.className = "heading-link";
		parentDiv.className = "toolbar-menu";
		subMenu.style.display = "none";
	}
}

function MenuTimeout(parentDivID) {
	var subMenu = document.all ? document.all[parentDivID + "-sub"] : document.getElementById(parentDivID + "-sub");
	var menuButton = document.all ? document.all[parentDivID + "-button"] : document.getElementById(parentDivID + "-button");
	var parentDiv = document.all ? document.all[parentDivID] : document.getElementById(parentDivID);
	
	if ((subMenu) && (parentDiv))
	{
		if (menuTimer)
		{ 
		clearTimeout(menuTimer);
		menuTimer = null; 
		}
		myInstance = "hideMenu('" + parentDivID + "');";
		menuTimer = setTimeout(myInstance,50);
	}
}

function showMenu(parentDivID) {
	var subMenu = document.all ? document.all[parentDivID + "-sub"] : document.getElementById(parentDivID + "-sub");
	var menuButton = document.all ? document.all[parentDivID + "-button"] : document.getElementById(parentDivID + "-button");
	var parentDiv = document.all ? document.all[parentDivID] : document.getElementById(parentDivID);
	//var promoDiv = document.all ? document.all["promotions-div"] : document.getElementById("promotions-div");


	if ((subMenu) && (menuButton) && (parentDiv))
	{
		if (menuTimer)
		{ 
		clearTimeout(menuTimer);
		menuTimer = null; 
		}
		subMenu.style.display = "block";
		menuButton.className = "heading-link-over";
		parentDiv.className = "toolbar-menu-over";
		
	}
}


function loginToggle(loginDivID,linkElmID)
{
	loginDiv = document.all ? document.all[loginDivID] : document.getElementById(loginDivID);
	linkElm = document.all ? document.all[linkElmID] : document.getElementById(linkElmID);
	loginSection = document.all ? document.all["login-section"] : document.getElementById("login-section");
	//promoDiv = document.all ? document.all["menu-promo"] : document.getElementById("menu-promo");

	
	if (loginDiv.style.display != "none")
	{
	loginSection.style.width = "220px";
	//promoDiv.style.display = "block";
	loginDiv.style.display = "none";
	linkElm.style.display = "block";
	} else {
	loginSection.style.width = "480px";
	//promoDiv.style.display = "none";
	loginDiv.style.display = "block";
	linkElm.style.display = "none";
	}
}


function ShowandHide(div1ID, div2ID)
{
    if(document.getElementById(div1ID).style.display != 'none')
    {
        hidediv(div1ID);
        showdiv(div2ID);
    }
    else
    {
        showdiv(div1ID);
        hidediv(div2ID);
    }
}

function hidediv(id)
{
    //safe function to hide an element with a specified id
    if (document.getElementById) //DOM3 = IE5, NS6
    {
        document.getElementById(id).style.display = 'none';
    }
    else
    {
        if (document.layers) //Netscape 4
        {
	        document.id.display = 'none';
        }
        else //IE 4
	    {
	        document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id)
{
    //safe function to show an element with a specified id		  
    if (document.getElementById) //DOM3 = IE5, NS6
    {
        document.getElementById(id).style.display = 'block';
    }
    else
    {
        if (document.layers) //Netscape 4
        {
	        document.id.display = 'block';
        }
        else //IE 4
        {
	        document.all.id.style.display = 'block';
        }
    }
}

function ClearDefaultText(ctrl,text)
{
    if(ctrl.value && ctrl.value == text)
    {
        ctrl.value = "";
        ctrl.style.color = "#000000";
    }
}

function InitDefaultText(ctrl,text)
{
    if(ctrl.value == "")
    {
        ctrl.value = text;
        ctrl.style.color = "";
        
        if(text == "Password")
        {
            ShowPasswordText(ctrl);
        }
    }
}

function ClearPasswordText(ctrl1, ctrl2)
{
    hidediv(ctrl1);
    showdiv(ctrl2);
    GetMyElementByID(ctrl2).focus();
}

function InitPasswordText(ctrl1, ctrl2)
{
    if(GetMyElementByID(ctrl2).value == "")
    {
        hidediv(ctrl2);
        showdiv(ctrl1);
    }
}

function GetMyElementByID(id)
{
    //safe function to show an element with a specified id		  
    if (document.getElementById) //DOM3 = IE5, NS6
    {
        return document.getElementById(id);
    }
    else
    {
        if (document.layers) //Netscape 4
        {
	        return document.id;
        }
        else //IE 4
        {
	        return document.all.id;
        }
    }
}







function fireClickEventByName($controlName)
{ 
	var $control = document.all ? document.all[$controlName] : document.getElementById($controlName); 
	fireClickEvent($control);
}
function fireClickEvent($control)
{ 
	if (document.all) 
	{ 
	$control.click();
	} 
	else 
	{ 
	var $clickEvent = window.document.createEvent("MouseEvent"); 
	$clickEvent.initEvent("click", true, true); 
	$control.dispatchEvent($clickEvent); 
	}
}
function EnterPressed($buttonSubmit, $event)
{ 
	var $res = true;
	if($buttonSubmit != '' && $buttonSubmit != null){
		var $key;
		if (! $event) { $event = window.event; }
		$key = $event.keyCode ? $event.keyCode : $event.which;
		if($key == 13)
		{
		var $controlSubmit = document.all ? document.all[$buttonSubmit] : document.getElementById($buttonSubmit);

		fireClickEvent($controlSubmit);
		return false; 
		}
	}
	return $res;
}

function ShowHidePanel(panel,link)
{    
    if (document.getElementById(panel).style.display=="none")
    {
       document.getElementById(panel).style.display="block";
       document.getElementById(link).innerHTML='&#187';
    }
    else
    {
        document.getElementById(panel).style.display="none";
        document.getElementById(link).innerHTML='&#171';
    }
}