﻿function ShowHideContent()
{
 	if ( contentVisible )
 	{
 		HideContent();
		contentVisible = 0;
 	}
 	else
 	{
 		ShowContent();
		contentVisible = 1;
 	}
 	SetCookie();
}

function ShowContent()
{
 	document.getElementById("layoutContent").style.display = "";
 	var mainElement = document.getElementById("layoutMain");
 	mainElement.className = "Content " + mainElement.className;
 	mainElement.style.width = mainWidth + "px";
	document.getElementById("layoutPage").style.width = mainWidth + "px";
	var contentElement = document.getElementById("showHideContent")
	if ( contentElement ) contentElement.className = "hideContent";
}

function HideContent()
{
 	document.getElementById("layoutContent").style.display = "none";
 	var mainElement = document.getElementById("layoutMain");
 	mainElement.className = mainElement.className.substr(8);
 	mainElement.style.width = contentWidth + mainWidth + "px";
	document.getElementById("layoutPage").style.width = contentWidth + mainWidth + "px";
	var contentElement = document.getElementById("showHideContent")
	if ( contentElement ) contentElement.className = "showContent";
}

function DoHeading(wID, hID)
{
 	if ( hID != headingID )
 	{
 		expandedItem = 0;
 		headingID = hID;
 		SetCookie();
 	}
 	if ( wID ) 
 	{
 		switch( wID )
 		{
 		case -2:
 			document.location = "../system/index.aspx";
 			break;
 		case -1:
 			if ( confirm( "Do you really want to log off?" )) document.location = "../system/logoff.aspx";
 			return;
 		default:
 			document.location = "../pages/" + wID + ".aspx";
 			break;
 		}
 	}
 	else
 	{
 		document.location.reload();
 	}
}

function ContentClick(x)
{
 	if ( expandedItem )
 	{
 		CollapseItem( expandedItem );
 		if ( expandedItem == x )
 		{
 			expandedItem = 0;
 			SetCookie();
 			return;
 		}
 	}
 	ExpandItem( x );
 	expandedItem = x;
 	SetCookie();
}

var eintID = 0;
var cintID = 0;
var expandElement = null;
var collapseElement = null;

function ExpandItem(x)
{
	document.getElementById("ind" + x).className = "contentHeadExpand";
	expandElement = document.getElementById("ind" + x + "i").lastChild;
	eintID = window.setInterval("DoExpandElement();", 10 );
}

function DoExpandElement()
{
	expandElement.style.display = "block";
	expandElement = expandElement.previousSibling;
	if ( expandElement == null ) window.clearInterval(eintID);
}

function CollapseItem(x)
{	
	document.getElementById("ind" + x).className = "contentHeadCollapse";
	collapseElement = document.getElementById("ind" + x + "i").firstChild;
	cintID = window.setInterval("DoCollapseElement();", 10 );
}

function DoCollapseElement()
{
	collapseElement.style.display = "none";
	collapseElement = collapseElement.nextSibling;
	if ( collapseElement == null ) window.clearInterval(cintID);
}

function ItemClick(id,newwnd)
{
	var url = "../pages/" + id + ".aspx";
	if ( newwnd ) window.open( url); else document.location = url;
}

function SetCookie()
{
	document.cookie = "Layout=Heading=" + headingID + "&Content=" + contentVisible + "&Expand=" + expandedItem + ";path=/";
}

