

/* ****************************************
 * Förvarning innan man blir utslängd
 ****************************************** */

var stayLoggedIn=0;
var ctime;
var warnWindow;
if(document.getElementById('sesTimeOut') != null){
	var timeOut = eval(document.getElementById('sesTimeOut').innerHTML)*1000;    
	var warningTimeOut = eval(document.getElementById('sesWarnTimeOut').innerHTML)*1000; 
	var textWarningTimeOut = document.getElementById('textWarnTimeOut').innerHTML; 

	if (warningTimeOut > 0)
	{
		if (document.title.indexOf('Dexter - Logga in') !=-1)
		{
	   //setTimeout("alert('Du är på inloggningssidan redan');",5000); 
		} 
		else
		{
				//stayLoggedIn = 0;
	    	setTimeout("warnforLogoutFunction();",timeOut - warningTimeOut);  //330000-300000
	    	ctime = setTimeout("logoutFunction();",timeOut);
		}
	}
}

/* ****************************************
 * Utloggning om ingen ny aktivering gjorts.
 ****************************************** */
function logoutFunction()
{
	alert ('Du är nu utloggad!');
	window.location = "default.asp?page=auth/common/login"
	/*
	if (stayLoggedIn==0)
   {
   window.location = "default.asp?page=auth/common/login"
   }
else 
   {
   clearTimeout(ctime);
   setTimeout("warnforLogoutFunction();",timeOut - warningTimeOut);
   ctime = setTimeout("logoutFunction();",timeOut);
   stayLoggedIn=0;
   } */
}

/* ****************************************
 * Varning innan man blir utloggad.
 ****************************************** */
function warnforLogoutFunction()
{
	alert(textWarningTimeOut);

/*if (confirm("Dexter har av säkerhetsskäl funktionalitet för automatisk utloggning. Tryck på OK för att förbli inloggad. Har du inte tryckt OK innan kl   Trycker du Avbryt blir du utloggad direkt.")) 

   {
   //if yes
     stayLoggedIn = 1; // do not logout
   }
     else 
   { // if no
      stayLoggedIn = 0;
      window.location = "default.asp?page=auth/common/login"
   }*/
}


/*********************************************************  */
/**
 * Create the menu and the sub menus
 */
function createMenu(sStylePath)
{
	iMenuElementWidth = calcMenuElementWidth();

	var iMenuStartPositionX = calcMenuStartPositionX();
	var iMenuStartPositionY = iMenuBgHeight - iMenuElementHeight;
	var sHTML = "";
	var iCounter = 0;
	var iSubMenuMinWidth = iMenuElementWidth - 12; //12 = (borders 2 x 2 px) + cellpadding 4 px
	var iSeparator = 1; //last item added is a separator = 1 => Do not add another separator.
		
	//Menu
	sHTML += "<div id=\"Menu\" class=\"clsMenu\" style=\"left: " + iMenuStartPositionX + "px; top: " + iMenuStartPositionY + "px\">\n";
	sHTML += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>\n";

	for (i = 1; i <= a_sMenuElement.length; i++)
	{
		if (a_iMenuVisible[i - 1] == "1") //if the element should be visible
		{
			sHTML += "<td><img src=\"" + sStylePath + "/images/menu_item_left.gif\" width=\"4\" height=\"" + iMenuElementHeight + "\"></td><td width=\"" + iMenuElementWidth + "\" height=\"" + iMenuElementHeight + "\" align=\"center\" class=\"clsMenuElement\">";
			if (eval("a_sSubMenu_" + i + ".length") == 0) //if no sub menu should be displayed
			{
				sHTML += "<img src=\"" + sStylePath + "/images/menu_item_top_trans.gif\" width=\"7\" height=\"4\" border=\"0\"><br>";
				
				if (a_sMenuLink[i - 1].length > 0)
				{
					if (a_sMenuLink[i - 1].substr(0, 4) == "help")
						sHTML += "<a href=\"javascript:void(0)\" onClick=\"openWindowHelp()\">";
					else
						sHTML += "<a href=\"" + a_sMenuLink[i - 1] + "\">";
				}
			}
			else
				sHTML += "<img src=\"" + sStylePath + "/images/menu_item_top.gif\" width=\"7\" height=\"4\" border=\"0\"><br><a href=\"#\" onMouseOver=\"showMenu('SubMenu_" + i + "')\" onMouseOut=\"hideMenu('SubMenu_" + i + "')\">";

			sHTML += a_sMenuElement[i - 1];
			
			if (a_sMenuLink[i - 1].length > 0)
				sHTML += "</a></td><td><img src=\"" + sStylePath + "/images/menu_item_right.gif\" width=\"4\" height=\"" + iMenuElementHeight + "\"></td><td width=\"" + iMenuElementPadding + "\"></td>\n";
			else
				sHTML += "</td><td><img src=\"" + sStylePath + "/images/menu_item_right.gif\" width=\"4\" height=\"" + iMenuElementHeight + "\"></td><td width=\"" + iMenuElementPadding + "\"></td>\n";
		}
	}
	sHTML += "<td></td></tr></table></div>\n\n";	
	
	//Sub menus
	for (i = 1; i <= a_sMenuLink.length; i++)
	{
		if (a_iMenuVisible[i - 1] == 1) //if the element should be visible
		{
			iCounter++;
			if (eval("a_sSubMenu_" + i + ".length") > 0)
			{
				iSeparator = 1; //never add separator at first row
				sHTML += "<div id=\"SubMenu_" + i + "\" class=\"clsSubMenu\" style=\"left: " + (iMenuStartPositionX + ((iCounter - 1) * (iMenuElementWidth + iMenuElementPadding + 8))) + "px; top: " + iMenuBgHeight + "px\" onMouseOver=\"showMenu('SubMenu_" + i + "')\" onMouseOut=\"hideMenu('SubMenu_" + i + "')\">\n";
				sHTML += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
				sHTML += "<tr><td width=\"" + iMenuElementWidth + "\" height=\"1\"></td></tr>\n";
				for (j = 0; j < eval("a_sSubMenu_" + i + ".length"); j++)
				{
					if (eval("a_sSubMenuLink_" + i + "[" + j + "]") == "" 
						&& j + 1 != eval("a_sSubMenu_" + i + ".length") 
						&& iSeparator == 0) //if no href, not last menuitem and separator allowed then show separator
					{
						sHTML += "<tr><td><hr class=\"clsRulerSubMenu\"></td></tr>\n";
						iSeparator = 1;
					}
					if (eval("a_sSubMenuLink_" + i + "[" + j + "]") != "")
					{
						if (eval("a_sSubMenuLink_" + i + "[" + j + "].substr(0, 4)") == "help") //show help link
						{
							sHTML += "<tr><td onMouseOver=\"setSubMenuBgColorHover(this)\" onMouseOut=\"setSubMenuBgColor(this)\"><a href=\"javascript:void(0)\" onClick=\"openWindowHelp()\">" + eval("a_sSubMenu_" + i + "[" + j + "]") + "</a></td></tr>\n";
						}
						else{
							if (eval("a_sSubMenuLink_" + i + "[" + j + "].substr(0, 10)") == "NotAllowed") //show not allowed link
							{
								sHTML += "<tr><td onMouseOver=\"setSubMenuBgColorHover(this)\" onMouseOut=\"setSubMenuBgColor(this)\"><a href=\"javascript:notAllowed()\">" + eval("a_sSubMenu_" + i + "[" + j + "]") +" (X)"+ "</a></td></tr>\n";
							}
							else
							{
								sHTML += "<tr><td onMouseOver=\"setSubMenuBgColorHover(this)\" onMouseOut=\"setSubMenuBgColor(this)\"><a href=\"" + eval("a_sSubMenuLink_" + i + "[" + j + "]") + "\">" + eval("a_sSubMenu_" + i + "[" + j + "]") + "</a></td></tr>\n";
							}
						}
						iSeparator = 0; //separator is allowed after this menuitem
					}
				}
				sHTML += "</table></div>\n\n";
			}
		}
	}
	//alert(sHTML); //only for debugging	
	document.write(sHTML);
}

/**
 * Calculate the width of the menu elements, with regard to the longest word
 */
function calcMenuElementWidth()
{
	var iMaxChars = 0;
	
	for (i = 1; i <= a_sMenuElement.length; i++)
	{
		if (a_sMenuElement[i - 1].length > iMaxChars)
			iMaxChars = a_sMenuElement[i - 1].length;
	}
	return ((iMaxChars * 8) + 4);
}

/**
 * Calculate horizontal start position for menu
 */
function calcMenuStartPositionX()
{
	var iVisible = 0;
	
	for (i = 0; i < a_iMenuVisible.length; i++)
	{
		if (a_iMenuVisible[i] == 1)
			iVisible++;
	}
	return (iMenuEndPositionX - (iVisible * (iMenuElementWidth + 8)));
}

/**
 * Show sub menu
 */
function showMenu(sSubMenu)
{
	if (document.all) //IE
	{
		hideFormElement("SELECT"); // Hide SELECT elements
		document.all[sSubMenu].style.visibility = 'visible';
	}
	else if (document.getElementById) //NS6
	{
		document.getElementById(sSubMenu).style.visibility = 'visible';
	}
}

/**
 * Hide sub menu
 */
function hideMenu(sSubMenu)
{
	if (document.all) //IE
	{
		showFormElement("SELECT"); //Show hidden SELECT elements
		document.all[sSubMenu].style.visibility = 'hidden';
	}
	else if (document.getElementById) //NS6
	{
		document.getElementById(sSubMenu).style.visibility = 'hidden';
	}
}

/**
 * Open help window
 */
function openWindowHelp()
{
	window.open('Default.asp?page=' + sMenuElementHelp, 'winHelp', 'width=500, height=500');
}

/**
 * Not allowed to se the page due to low sequrity level on loginmethod.
 */
function notAllowed()
{
	alert(iMenuNotAllowed);
}

/**
 * Set sub menu background color
 */
function setSubMenuBgColor(oSubMenu)
{
	oSubMenu.style.background = sSubMenuBgColor;
}

/**
 * Set sub menu background color when hovering
 */
function setSubMenuBgColorHover(oSubMenu)
{
	oSubMenu.style.background = sSubMenuBgColorHover;
}

/**
 * Hide specific type of form elements
 */
function hideFormElement(tagName) {
	for (i = 0; i < document.all.tags(tagName).length; i++) {
		obj = document.all.tags(tagName)[i];
		obj.style.visibility = "hidden";
	}
}

/**
 * Show specific type of hidden form elements
 */
function showFormElement(tagName) {
	for (i = 0; i < document.all.tags(tagName).length; i++) {
		obj = document.all.tags(tagName)[i];
		obj.style.visibility = "visible";
	}
}
