/*
'Author					: Stefan Kruger
'Date Created			: 28-Jul-2005
'Last Changed by		: Stefan Kruger
'Date Changed			: 28-Jul-2005
'Version				: 1.0.28072005
'Comments:
'Date:			Desc:
'--------------------------------------------------------------------------------------------
'28-Jul-2005	Code update run completed

'ToDoList:
'Date:			Desc:																Status:
'------------------------------------------------------------------------------------------------

*/

//////////////////////////////////////////////////////////////////////////////////////////////
//PAGE INIT DEFINITIONS
//////////////////////////////////////////////////////////////////////////////////////////////

var loaded = false;
var actualwidth = -1;
var menuwidth = 492;
var menuheight = 33;
var scrollspeed = 4;

/*
Write hidden div used in Mozilla browser scrolling.
*/
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100;left:-1000"></span>')

//////////////////////////////////////////////////////////////////////////////////////////////
//PREDEFINED USER FUNCTIONS USED IN THE POST-LOADING OF MENUS
//////////////////////////////////////////////////////////////////////////////////////////////

/*
This function is called on successful loading of the tab page
*/
var tabLoader = function (oXML,outputDiv) {
	//Check for expiry of content before loading

	if (oXML.responseText.substr(2,35) == "<!-- Message box start delimiter-->"){
		expireSession();
	}
	else {
		var retar = new Array()
		retar = (oXML.responseText).split("|^^|")
		//alert(retar);
		if (retar.length == 2) {
			if (retar[0] == 1){
				toggleArrows(true);
			}
			else if (retar[0] == 0){
				toggleArrows(false);
			}
			//Display tabcontent in both the Mozilla temp span and the actual output div
			document.getElementById("temp").innerHTML = retar[1]
			outputDiv.innerHTML = retar[1];
			//The scroll width for case IE (direct from output div) or Mozilla (from the hidden temp div)
			actualwidth = document.all? outputDiv.offsetWidth : document.getElementById("temp").offsetWidth
		}
		else {
			alert ("Invalid length of tab menu returned.");
		}
		loaded = true;
		try {CollectGarbage();}
		catch (ex) {}
		//This can be used to periodically refresh the tab menu if needed.
		//setTimeout("getTabMenu(true)",10000);
	}
	regularCursor();
	oXML = null;
};

/*
This function is used when displaying a loaded section menu
*/
var completedLoadMenu = function (oXML,outputDiv) {
	//Check for expiry of content before loading

	if (oXML.responseText.substr(2,35) == "<!-- Message box start delimiter-->"){
		expireSession();
		regularCursor();
		oXML = null;
	}
	else {
		completedSingleLoad(oXML,outputDiv);
	}
};

//////////////////////////////////////////////////////////////////////////////////////////////
//MENU FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////

/*
The actual tab loading/clearing function
loadOrUnload = true --> load
loadOrUnload = false --> unload (for Logoff)
*/
function getTabMenu(loadOrUnload){
	if (document.getElementById("tabcontent")) {
		if (loadOrUnload) {
			var page = "tabs.asp";
			var data = "";
			loaded = false;
			genericSubmit(page,data,null,'tabcontent',tabLoader,tabloadingstring,false);
		}
		else {
			document.getElementById("tabcontent").innerHTML = "";
		}
	}
}

/*
This function loads a section menu for a TABID that is specified
*/
function loadMenu(tabid){
	var page = "menu.asp"
	var data = "tabid=" + tabid
	genericSubmit(page,data,null,'menucontent',completedLoadMenu,regularloadingstring,false);
	document.getElementById("ShowSubMenu").value = "True";
}

//////////////////////////////////////////////////////////////////////////////////////////////
//TAB SCROLLING FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////

/*
The scroll arrow display toggling function
onOrOff = true --> Display arrows
onOrOff = false --> Hide arrows
*/
function toggleArrows(onOrOff) {
	var display
	//Set up display mode
	if (onOrOff) {
		display = 'visible'
	}
	else {
		display = 'hidden'
	}
	//Set styles if available
	try {
		document.getElementById("leftarrow").style.visibility = display;
		document.getElementById("rightarrow").style.visibility = display;
	}
	catch (ex) {}
}

/*
Move tabs left
*/
function moveleft(){
	if (loaded){
		if (parseInt(document.getElementById("tabcontent").style.left) > (menuwidth - actualwidth)){
			document.getElementById("tabcontent").style.left = parseInt(document.getElementById("tabcontent").style.left) - scrollspeed
		}
		lefttime = setTimeout("moveleft()",15)
	}
}

/*
Move tabs right
*/
function moveright(){
	if (loaded){
		if (parseInt(document.getElementById("tabcontent").style.left) < 0){
			document.getElementById("tabcontent").style.left = parseInt(document.getElementById("tabcontent").style.left) + scrollspeed
		}
		righttime = setTimeout("moveright()",15)
	}
}
