
/*·························  © Webacumen 2007. All rights reserved  ··········································

Project			:	standard website template 
Module Name		:	view.js
Purpose			:	
············································································································
Revision History

Date			Rev			CA Number		Changes Made
06/10/06		1			D001/0000		Initial Review
21/12/06		2			D001/0000		Changed onSetScreen to reload after setting the cookie
··········································································································*/
var mobjUrlTimer = null;
var mstrUrlHash = "";
var mstrUrlDash = "";
var mobjBtn = null;
var mstrBtnClassName = "";
var mstrScr = "lsscreen";
var mstrFnt = "";
var mstrRes = "";

function onPageLoad()
{
	try
	{
		var strHref = window.location.href;
		var intIdx = strHref.lastIndexOf("?");

		if (intIdx > -1)
		{window.location.href=strHref.replace("?prm=", "#");}
		else
		{mobjUrlTimer = window.setInterval("onTimerUrlCheck()", 10);}
	}
	
	catch(exception)
	{
		onErrorHandler("onPageLoad: " + exception.message, "view.js", 0);
	}
}

function onTimerUrlCheck()
{
	try
	{
		var strHash = window.location.hash.replace("#", "");

		if (mstrUrlHash != strHash)
		{
			mstrUrlHash = strHash;
			dnaFetch("POST", "fldsys/controller.asmx/"+mstrMethod+"?prm="+mstrUrlHash, dnaUrlCatch, "");
		}
	}
	
	catch(exception)
	{
		onErrorHandler("onTimerUrlCheck: " + exception.message, "view.js", 0);
	}
}

function setMenu(strBtn)
{
	try
	{
		var objBtn = document.getElementById(strBtn);
		var strUl = "";
		var objUl = null;

		if(mobjBtn != null){mobjBtn.className = mstrBtnClassName;}
		if (objBtn != null)
		{
			mstrBtnClassName = objBtn.className;
			objBtn.className = mstrBtnClassName + "Sel";
			mobjBtn = objBtn;
			if (mstrBtnClassName == "aCat")
			{
				strUl = objBtn.id.replace("mnu", "ul");
				objUl = document.getElementById(strUl);
				if(objUl != null)
				{
					if (objUl.className == "ulSubOf")
					{
						objUl.className = "ulSubOn";
						objBtn.style.backgroundImage = "url(fldimg/caton.jpg)";
					}
					objUl = null;
				}
			}
			else if (mstrBtnClassName == "aSub")
			{
				strUl = objBtn.parentNode.parentNode.id
				objUl = document.getElementById(strUl);
				if(objUl != null && objUl.className == "ulSubOf")
				{
					objUl.className = "ulSubOn";
					strBtn = objUl.id.replace("ul", "mnu");
					objBtn = document.getElementById(strBtn);
					if(objBtn != null){objBtn.style.backgroundImage = "url(fldimg/caton.jpg)";}
				}

			}
		}
		objBtn = document.getElementById("findtop");
		if(objBtn != null){objBtn.scrollIntoView(true);}
		objBtn = null;
	}

	catch(exception)
	{
		onErrorHandler("setMenu: " + exception.message, "view.js", 0);
	}
}

function changeUlState(objBtn)
{
	try
	{
		var objUl = null;
		var strUl = "";
		var strCl = "";

		if (objBtn != null && objBtn.className == "aCatSel")
		{
			strUl = objBtn.id.replace("mnu", "ul");
			objUl = document.getElementById(strUl);
			if(objUl != null)
			{
				if (objUl.className == "ulSubOn")
				{
					objBtn.style.backgroundImage = "url(fldimg/catof.jpg)";
					strCl = "ulSubOf";
				}
				else
				{
					objBtn.style.backgroundImage = "url(fldimg/caton.jpg)";
					strCl = "ulSubOn";
				}
				//else {strCl = "ulSubOn"; objBtn.className = "aCatSel";}
				objUl.className = strCl;
				objUl = null;
			}
		}
		// objBtn.className = "aCat";
		objBtn = null;
	}

	catch(exception)
	{
		onErrorHandler("changeUlState: " + exception.message, "view.js", 0);
	}
}

function setMenuDrp(strBtn)
{
	try
	{
		var objBtn = document.getElementById(strBtn);

		if(mobjBtn != null){mobjBtn.className = mstrBtnClassName;}
		if (objBtn != null)
		{
			mstrBtnClassName = objBtn.className;
			objBtn.className = mstrBtnClassName + "Sel";
			mobjBtn = objBtn;
			if (mstrBtnClassName == "aCat")
			{
				strBtn = objBtn.id.replace("mnu", "drp");
				objBtn = document.getElementById(strBtn);
				if(objBtn != null && objBtn.className == "aDrp aDrpDn")
				{
					objBtn.focus();		//needed because IE6 is complete pants
					onDrpBtnClick(objBtn);
				}
			}
			else if (mstrBtnClassName == "aSub" )
			{
				strBtn = objBtn.parentNode.parentNode.id.replace("ul", "drp");
				objBtn = document.getElementById(strBtn);
				if(objBtn != null && objBtn.className == "aDrp aDrpDn")
				{
					objBtn.focus();		//needed because IE6 is complete pants
					onDrpBtnClick(objBtn);
				}
			}
		}
		objBtn = document.getElementById("findtop");
		if(objBtn != null)
		{
			objBtn.scrollIntoView(true);
		}
		objBtn = null;
	}

	catch(exception)
	{
		onErrorHandler("setMenu: " + exception.message, "view.js", 0);
	}
}

function onDrpBtnClick(objBtn)
{
	try
	{
		var strUl = objBtn.id.replace("drp", "ul");
		var objUl = document.getElementById(strUl);

		if(objBtn != null)
		{
			if(objBtn.className == "aDrp aDrpDn")
			{
				objBtn.className = "aDrp aDrpUp";
				if(objUl != null)
				{objUl.className = "ulSubOn";}
			}
			else
			{
				objBtn.className = "aDrp aDrpDn";
				if(objUl != null)
				{objUl.className = "ulSubOf";}
			}
		}
	
		/*
		var strUl = objBtn.id.replace("drp", "ul");
		var objUl = document.getElementById(strUl);

		if(objBtn != null)
		{
			if(objBtn.className == "aDrp aDrpDn")
			{
				objBtn.className = "aDrp aDrpUp";
				if(objUl != null)
				{objUl.className = "ulSubOn";}
			}
			else
			{
				objBtn.className = "aDrp aDrpDn";
				if(objUl != null)
				{objUl.className = "ulSubOf";}
			}
		}
		*/
	}
	
	catch(exception)
	{
		onErrorHandler("onDrpBtnClick: " + exception.message, "view.js", 0);
	}
}

function onSetScreen(strRes)
{
	try
	{
		onGetScreenCookie();
		mstrRes = strRes;
		onSetScreenCookie();
	}
	
	catch(exception)
	{
		onErrorHandler("onSetScreen: " + exception.message, "view.js", 0);
	}
}

function showPref()
{
	try
	{
		var objDiv = document.getElementById("divRes");

		if(objDiv != null)
		{
			if(objDiv.style.display == "block")
			{objDiv.style.display = "none";}
			else
			{objDiv.style.display = "block";}
		}
		objDiv = document.getElementById("divTxt");
		if(objDiv != null)
		{objDiv.style.display = "none";}	//hide font
		objDiv = null;
	}
	
	catch(exception)
	{
		onErrorHandler("showPref: " + exception.message, "view.js", 0);
	}
}

function onSetText(strFnt)
{
	try
	{
		onGetScreenCookie();
		mstrFnt = strFnt;
		onSetScreenCookie();
	}
	
	catch(exception)
	{
		onErrorHandler("onSetText: " + exception.message, "view.js", 0);
	}
}

function showText()
{
	try
	{
		var objDiv = document.getElementById("divTxt");

		if(objDiv != null)
		{
			if(objDiv.style.display == "block")
			{objDiv.style.display = "none";}
			else
			{objDiv.style.display = "block";}
		}
		objDiv = null;
		objDiv = document.getElementById("divRes");
		if(objDiv != null)
		{objDiv.style.display = "none";}
		objDiv = null;
	}
	
	catch(exception)
	{
		onErrorHandler("showText: " + exception.message, "view.js", 0);
	}
}

function onGetScreenCookie()
{
	try
	{
		var strCookie = document.cookie;
		var aryData = null;
		var strFnt = "";
		var strRes = "";
		mstrFnt = "11";
		mstrRes = "1024x768";
		
		intIdx = strCookie.indexOf(mstrScr);
		if (intIdx > -1)
		{
			strCookie = strCookie.substring(intIdx+mstrScr.length+1);
			intIdx = strCookie.indexOf(";");
			if (intIdx > -1)
			{strCookie = strCookie.substring(0, intIdx);}
			aryData = strCookie.split("&");
			strFnt = aryData[0];
			strRes = aryData[1];
			mstrFnt = strFnt.replace("fnt=", "");
			mstrRes = strRes.replace("res=", "");
		}
	}
	
	catch(exception)
	{
		onErrorHandler("onGetScreenCookie: " + exception.message, "view.js", 0);
	}
}

function onSetScreenCookie()
{
	try
	{
		document.cookie = mstrScr+"=fnt=" + mstrFnt + "&res=" + mstrRes + ";";
		document.location.reload();
	}
	
	catch(exception)
	{
		onErrorHandler("onSetScreenCookie: " + exception.message, "view.js", 0);
	}
}
