// Support V1.8
// José Proença
// 2006-08-20
var SupportShowItemIDArray = new Array();
var SupportShowItemTimerArray = new Array();
function SupportShowItemFindIdx(id)
{
	var bFound = false;
	var n = SupportShowItemIDArray.length-1;
	while ((n>=0) && !bFound)
	{
		if (SupportShowItemIDArray[n] == id)
			bFound = true;
		else
			n--;
	}
	if (bFound)
		return n;
	else
		return null;
}
function SupportShowItemOffsetSaveSelect(itemId, placeitemId, xOffSet, yOffSet, show, saveSelects)
{
	var container;
	var bShow;
	var nDelay = 0;
	var nIdx = SupportShowItemFindIdx(itemId + "_" + placeitemId);
	if (nIdx && SupportShowItemTimerArray[nIdx] >= 0)
	{
		window.clearTimeout(SupportShowItemTimerArray[nIdx]);
		SupportShowItemTimerArray[nIdx] = -1;
	}
	
	if (typeof(show) == "number")
	{
		if (show >= 0)
		{
			bShow = true;
			nDelay = show;
		}
		else
		{
			bShow = false;
			nDelay = -show;
		}	
	}
	else
		bShow = show;
	var control = document.getElementById(itemId);
	if (control)
	{
		if (nDelay > 0)
		{
  			var nTimer = window.setTimeout("SupportShowItemOffsetSaveSelect('"+itemId+"','"+placeitemId+"',"+xOffSet+","+yOffSet+","+bShow+","+saveSelects+");", nDelay);
			if (nIdx)
				SupportShowItemTimerArray[nIdx] = nTimer;
			else
			{
				SupportShowItemTimerArray[SupportShowItemIDArray.length] = nTimer;
				SupportShowItemIDArray[SupportShowItemIDArray.length] = itemId + "_" + placeitemId;
			}
		}
		else
		{
			if (bShow)
				container = document.getElementById(placeitemId);
			if (container)
			{
				control.style.left = SupportGetAbsoluteLeft(container) + xOffSet;
				control.style.top = SupportGetAbsoluteTop(container) + yOffSet;
				control.style.display = bShow ? "block" : "none";
			}
			else
				control.style.display = bShow ? "inline" : "none";
				
			if (saveSelects)
			{
				var bVisibility = bShow ? 'hidden' : 'visible';
				var arrElements=document.getElementsByTagName('select');
				for(var i=0;i<arrElements.length;i++)
					arrElements[i].style.visibility=bVisibility;
			}
		}
	}
}
function SupportShowItemOffset(itemId, placeitemId, xOffSet, yOffSet, show)
{
	return SupportShowItemOffsetSaveSelect(itemId, placeitemId, xOffSet, yOffSet, show, false)
}
function SupportShowItem(itemId, placeitemId, show)
{
	return SupportShowItemOffset(itemId, placeitemId, 0, 0, show);
}
function SupportGetAbsoluteTop(item)
{
	var nTop = 0;
	if (item)
		do
			nTop += item.offsetTop;
		while ((item = item.offsetParent) && ((item.style == null) || (item.style.position=="static") || (item.currentStyle && item.currentStyle.position=="static")));
	return (nTop)
}
function SupportGetAbsoluteLeft(item)
{
	var nLeft = 0;
	if (item)
		do
			nLeft += item.offsetLeft;
		while ((item = item.offsetParent) && ((item.style == null) || (item.style.position=="static") || (item.currentStyle && item.currentStyle.position=="static")));
	return (nLeft)
}
function SupportValidateRequiredFields(arIDs)
{
	var bValidate = true;
	if (arIDs)
	{
		var control;
		for (n in arIDs)
		{
			if (arIDs[n])
			{
				control = document.getElementById(arIDs[n]);
				bValidate = bValidate && (SupportStringTrim(control.value) != "");
			}
		}
	}
	return bValidate;
}
function SupportStringTrim(strValue)
{
	var strTrimmed = strValue;
	if (strTrimmed)
	{
		if (strTrimmed.length > 0)
			while (strTrimmed.substr(0, 1) == ' ')
				strTrimmed = strTrimmed.substr(1);
		if (strTrimmed.length > 0)
			while (strTrimmed.substr(strTrimmed.length - 1, 1) == ' ')
				strTrimmed = strTrimmed.substr(0, strTrimmed.length - 1);
	}
	return strTrimmed;
}
// Body onload utility (supports multiple onload functions)
// Call the following with your function as the argument: SupportSafeAddBodyOnload(yourfunctioname);
var SupportSafeBodyOnloadFunctions = new Array();
function SupportSafeBodyOnload()
{
	for (var i=0; i < SupportSafeBodyOnloadFunctions.length; i++)
		SupportSafeBodyOnloadFunctions[i]();
}
function SupportSafeAddBodyOnload(f)
{
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
	{
		window.onload = SupportSafeBodyOnload;
		SupportSafeBodyOnloadFunctions[SupportSafeBodyOnloadFunctions.length] = f;
	}
	else if  (window.onload)
	{
		if (window.onload != SupportSafeBodyOnload)
		{
			SupportSafeBodyOnloadFunctions[0] = window.onload;
			window.onload = SupportSafeBodyOnload;
		}		
		SupportSafeBodyOnloadFunctions[SupportSafeBodyOnloadFunctions.length] = f;
	}
	else
		window.onload = f;
}
// Body unload utility (supports multiple unload functions)
// Call the following with your function as the argument: SupportSafeAddBodyUnload(yourfunctioname);
var SupportSafeBodyUnloadFunctions = new Array();
function SupportSafeBodyUnload()
{
	for (var i=0; i < SupportSafeBodyUnloadFunctions.length; i++)
		SupportSafeBodyUnloadFunctions[i]();
}
function SupportSafeAddBodyUnload(f)
{
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	if (IEmac && IE4)  // IE 4.5 blows out on testing window.Unload
	{
		window.Unload = SupportSafeBodyUnload;
		SupportSafeBodyUnloadFunctions[SupportSafeBodyUnloadFunctions.length] = f;
	}
	else if  (window.Unload)
	{
		if (window.Unload != SupportSafeBodyUnload)
		{
			SupportSafeBodyUnloadFunctions[0] = window.Unload;
			window.Unload = SupportSafeBodyUnload;
		}		
		SupportSafeBodyUnloadFunctions[SupportSafeBodyUnloadFunctions.length] = f;
	}
	else
		window.Unload = f;
}
function SupportMakeURLAbsolute(URL)
{
	var strAbsUrl = URL;
	var nSlash = URL.indexOf("/");
	var nProtocolSeparator = URL.indexOf("://");
	if ((nSlash <= 0) || (nProtocolSeparator < 0))
	{
		if (nSlash != 0)
			URL = "/"+URL;
		strAbsUrl = window.location.protocol + "//" + window.location.host + URL;
	}
	
	return strAbsUrl;
}
function SupportExitedElement(e, element)
{
	if (!e) var e = window.event;
	var oTo = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (oTo != null && oTo != element)
		oTo = oTo.parentNode
	return (oTo != element)
}
// DEBUG helper function
function DebugPrint(Message)
{
	var oOutDiv = document.getElementById("_DEBUGOUTPUT");
	if (!oOutDiv)
	{
		oOutDiv = document.createElement("<div id=_DEBUGOUTPUT></div>");
		document.body.appendChild(oOutDiv);
	}
	oOutDiv.innerHTML = new Date().toLocaleTimeString() + ": "+ Message + "<br>" + oOutDiv.innerHTML;
}
