var ie=document.all && !window.opera;
var dom=document.getElementById;
var ns6=dom&&!document.all;
var lastTabSelected = 0;
var lastRelatedRow = 0;

//	Timer-related variables and methods
var lngTimeOutValue=0;
var timeoutID = -1;
var HelpWin;

function setTimeOut(value)
{
	lngTimeOutValue = value*60000;
}
function startTimer()
{
	clearTimer();
	if (lngTimeOutValue > 0 && top.Header)
	{
   	if (top.Header.startTimer && top.Header.divLoginStatus && 
          top.Header.divLoginStatus.value == "1")
      {
		   timeoutID = setTimeout("logUserOut()",lngTimeOutValue);
      }
	}
}
function disableTimer()
{
	clearTimer();
	lngTimeOutValue = 0;
}
function clearTimer()
{
	if ( timeoutID != -1 )
		clearTimeout(timeoutID);
}
function getLocalMessage(messageID,defaultMessage)
{
	var strMessage = "";
	if ( defaultMessage )
		strMessage = defaultMessage;
	if ( document.getElementById('LocalMessages') && messageID && messageID != '' )
	{
		var arrData = document.getElementById('LocalMessages').value.split('|');
		var i = 0;
		for (i=0; i<arrData.length-1; i+=2)
		{
			if ( arrData[i] == messageID )
			{
				strMessage = arrData[i+1];
				break;
			}
		}
	}	
	return strMessage;
}
//	Functions used to display a localized error message
function displayMessage(messageID,defaultMessage)
{
	alert(getLocalMessage(messageID,defaultMessage));
}
//	Functions used to refresh a frame
function refreshAppArea()
{
	if ( top.AppArea )
		top.AppArea.location.href = top.AppArea.location.href;
}
function refreshNavigation()
{
	if ( top.AppArea && top.AppArea.Navigation )
		top.AppArea.Navigation.location.href = top.AppArea.Navigation.location.href;
}
function refreshWorkArea()
{
	if ( top.AppArea && top.AppArea.WorkArea )
		top.AppArea.WorkArea.location.href = top.AppArea.WorkArea.location.href;
}
function refreshHeader()
{
	if ( top.Header )
	{
		top.Header.updateApplicationMenu("Administration");
		top.Header.updateModuleMenu(true,true);
	}
}
//	Method that checks to see if the navigation needs to be refreshed
function checkRefreshNavigation()
{
	if ( document.getElementById('RefreshNavigation') && document.getElementById('RefreshNavigation').value == "1" )
		refreshNavigation();		
}
function displayModulePage(aspPage,scriptCode,helpFile,helpTopic)
{
	if ( helpFile )
		setHelpFile( helpFile );
	if ( helpTopic )
		setHelpTopic( helpTopic );
	if ( scriptCode && scriptCode != '' )
	{
		eval(scriptCode);
		return false;		// indicates that we only ran a script, but didn't redirect
	}
	else
	{
		if ( top.AppArea.location.href != aspPage )
			top.AppArea.location.href = aspPage;
		return true;		// indicates that we redirected to a new page
	}
}
//	Functions that determine the position of any element
function findPosX(obj)
{
	var curLeft = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curLeft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curLeft +=  obj.x;
			
	return curLeft;
}
function findPosY(obj)
{
	var curTop = 0;
	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curTop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curTop +=  obj.y;
			
	return curTop;
}
//	Functions used to toggle display of an element
function toggleDiv(someDiv, someIMG) 
{
	if ( someIMG.attributes['canexpand'] == null ||
		(someIMG.attributes['canexpand'].value.toLowerCase() != "none" &&
		 someIMG.attributes['canexpand'].value.toLowerCase() != "empty") )
	{
		if (someDiv.className == 'hide') 
			someDiv.className = 'show';
		else 
			someDiv.className = 'hide';
		toggleIMG(someIMG);
	}
}
function toggleIMG(someIMG) 
{
	if ( window.divToggleImages )
	{
		var	strImages = window.divToggleImages.value;
		var	strImageArray = strImages.split(",");	
		var imgOne = someIMG.src.toUpperCase();
		var imgTwo;
		var iCount = 0;
		for (iCount=0; iCount<strImageArray.length-1;iCount++)
		{
			imgTwo = strImageArray[iCount].toUpperCase();
			if ( imgOne.match(imgTwo) )
			{
				if ( iCount % 2 == 0 )
					someIMG.src = strImageArray[iCount+1];
				else
					someIMG.src = strImageArray[iCount-1];
				break;
			}
		}
		if ( someIMG.src.toUpperCase() == imgOne )
			someIMG.src = imgTwo;
	}
}
function showInitialPage()
{
	if ( document.getElementById('activeTab') )
	{
		selectTab(document.getElementById(document.getElementById('activeTab').value),document.getElementById(document.getElementById('activeDiv').value));
	}
}
//	Function used to manage the "property-sheet" like display
function selectTab(tabSelected, relatedRow) 
{
	if ( tabSelected && relatedRow )
	{
		if ( tabSelected.className != "activetab" )
		{
			if ( document.getElementById('activeTab') )
			{
				if ( document.getElementById(document.getElementById('activeTab').value) )
					document.getElementById(document.getElementById('activeTab').value).className = 'inactivetab';
				document.getElementById('activeTab').value = tabSelected.id;			
			}
			if ( document.getElementById('activeDiv') )
			{
				if ( document.getElementById(document.getElementById('activeDiv').value) )
					document.getElementById(document.getElementById('activeDiv').value).className = 'hide';
				document.getElementById('activeDiv').value = relatedRow.id;			
			}							

			tabSelected.className = "activetab";
			relatedRow.className = "show";
			
			lastTabSelected = tabSelected;
			lastRelatedRow = relatedRow;
			
			startTimer();
		} else
			lastTabSelected = tabSelected;
	}
}
function loadAppArea(moduleName)
{
	if ( moduleName && moduleName != "" && top.Header && top.Header.divSubModuleMenu )
	{
		if ( top.Header.divSubModuleMenu.attributes['servicename'] && 
			 top.Header.divSubModuleMenu.attributes['servicename'].value != moduleName )
		{
			top.Header.divSubModuleMenu.attributes['servicename'].value = moduleName;
			top.Header.selectMenuTab(top.Header.document.getElementById("Menu_"+moduleName));
			top.Header.updateSubModuleMenu();
		}			
	}
}
function updateSubMenu(menuType)
{
	if ( menuType && menuType != "" && top.Header && top.Header.selectSubMenuTab )
		top.Header.selectSubMenuTab(top.Header.document.getElementById("subMenuItem"+menuType));
}
function setupWebService(serviceURL,serviceName,div,serviceAvailableMethod,reConnect)
{	
	if ( div )
	{
		if ( div[serviceName] == null || reConnect )
		{
			if ( serviceAvailableMethod != null )
			{
				//document.body.style.cursor = "wait";
				div.onserviceavailable = serviceAvailableMethod
			}
			div.useService(serviceURL+serviceName+".asmx?WSDL",serviceName);
		}
		else if ( serviceAvailableMethod != null )
			serviceAvailableMethod();
	}
}

function getCookie(name,defaultValue)
{
	var cookies = document.cookie;
	var cookieName = name;
	var cookieValue = "";
	if ( defaultValue != null )
		cookieValue = defaultValue;
	if ( cookies )
	{
		if (cookies.length > 0)
		{
			var start = cookies.indexOf(cookieName+"=");
			if (start != -1)
			{
				start += cookieName.length + 1;
				finish = cookies.indexOf(";", start);
				if (finish == -1)
					finish = cookies.length;
				cookieValue = unescape(cookies.substring(start,finish));
			}
		}
	}
	
	return cookieValue;
}

function setCookie(name,value,expirationDate)
{
	if ( document.cookie )
	{
		if ( expirationDate == null )
		{
			expirationDate = new Date();
			expirationDate.setFullYear(expirationDate.getFullYear()+1);
		}
		document.cookie = name + "=" + escape(value) + "; expires=" + expirationDate.toGMTString();
	}
}

//------------------------------------ getIntValue -------------------------------------
function getIntValue(elementName)
{
	var intReturn = 0;
	if ( document.getElementById(elementName) )
	{
		var strData = document.getElementById(elementName).value;
		if ( strData != "" )
			intReturn = strData * 1;
	}
	return intReturn;
}

//	Help functions

function onHelp(helpDir)
{
	var chmFile = window.divHelpFile.value;
	var chmTopic = window.divHelpTopic.value;
	if ( chmFile != "" )
	{
		if ( chmTopic != "" )
			chmFile = chmFile + "#" + chmTopic;
					
		if ( HelpWin )
			HelpWin.close();

		if ( helpDir )
			HelpWin = window.open(helpDir+chmFile);
		else
			HelpWin = window.open(chmFile);
	} else
		alert("Help is currently unavailable for this Module.");
}
function setHelp(helpFile,helpTopic)
{
	if ( helpFile != "" || helpTopic != "" )
	{
		setHelpFile(helpFile);
		setHelpTopic(helpTopic);
	}
}
function setHelpFile(helpFile)
{	
	if ( top.Header && top.Header.divHelpFile && helpFile )
	{
		if ( helpFile != "" )
			top.Header.divHelpFile.value = helpFile;
	}
}
function setHelpTopic(helpTopic)
{
	if ( top.Header && top.Header.divHelpTopic && helpTopic )
	{
		if ( helpTopic != "" )
			top.Header.divHelpTopic.value = helpTopic;
		else
			top.Header.divHelpTopic.value = "Welcome.htm";
	}
}
function getQueryItem(item) 
{
	var value = "";
	var qs = location.search.substr(1).split("&");
	for(var i = 0; i < qs.length; i++) 
	{
		if ( qs[i].split("=")[0] == item )
		{
			value = qs[i];
			break;
		}
	}
	return value;
}
function setValue(name,value)
{
	if ( document.getElementById(name) )
		document.getElementById(name).value = value;
}
function setText(name,value)
{
	if ( document.getElementById(name) )
	{
		if ( document.all )
			document.getElementById(name).innerText = value;
		else
			document.getElementById(name).textContent = value;
	}
}
function setHtml(name,value)
{
	if ( document.getElementById(name) )
		document.getElementById(name).innerHTML = value;
}
function getValue(name,defaultValue)
{
	var data = "";
	if ( document.getElementById(name) )
		data = document.getElementById(name).value;
	else
		data = defaultValue;
	return data;
}
function getText(name,defaultValue)
{
	var data = "";
	if ( document.getElementById(name) )
	{
		if ( document.all )
			data = document.getElementById(name).innerText;
		else
			data = document.getElementById(name).textContent;
	}
	else
		data = defaultValue;
	return data;
}
function showProcessingMessage(message,disable)
{
	document.body.style.cursor="wait";
	if ( disable )
	{
		document.body.disable=true;
	}
	var msg = document.getElementById('WaitMessage')
	if ( msg )
	{
		var iebody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
		//	Center the DIV on the page
		var scroll_top=(ie)? iebody.scrollTop : window.pageYOffset;
		var docwidth=(ie)? iebody.clientWidth : window.innerWidth;
		var docheight=(ie)? iebody.clientHeight: window.innerHeight;
		var objwidth=300;//msg.offsetWidth;
		var objheight=80;//msg.offsetHeight;
		msg.style.left=docwidth/2-objwidth/2+"px";
		msg.style.top=scroll_top+docheight/2-objheight/2+"px";
				
		msg.className = "show";
		var txt = document.getElementById('WaitText');
		if ( txt )
			txt.innerText = message;
	}
}
function hideProcessingMessage()
{
	var msg = document.getElementById('WaitMessage')
	if ( msg )
		msg.className = "hide";
	document.body.style.cursor="";
	document.body.disable=false;
}

