// S.A. Birl
// type="text/javascript" language="JavaScript"
//

var browser=navigator.appName;


// only to be used with <input>
function checkMaxLength(TextField, RemainingField, maxlimit)
{
	if (TextField.value.length > maxlimit)
	{
		// truncate the remaining characters
		TextField.value = TextField.value.substring(0, maxlimit);
	}
	else
	{
		RemainingField.value = maxlimit-TextField.value.length;
	}
}


function ShowHide(thisElement)
{
		document.getElementById(thisElement).innerHTML="Wrong JS Function";
		document.getElementById(thisElement).style.display="table";
}

function HideShow(thisElement)
{
//	alert("thisElement: '" + thisElement + "'");
//	alert("thisElement: '" + document.getElementById(thisElement).style.visibility + "'");
//	alert("thisElement: '" + document.getElementById(thisElement).style.display + "'");
	if (document.getElementById(thisElement).style.display != "none")
	{
		document.getElementById(thisElement).style.display="none";
	}
	else
	{
//		Use 'block' instead of 'inline' to keep background-color
		document.getElementById(thisElement).style.display="block";
	}
}


function HideShowTable(thisElement)
{
	if (document.getElementById(thisElement).style.display != "none")
	{
		document.getElementById(thisElement).style.display="none";
	}
	else
	{
		document.getElementById(thisElement).style.display="table";
	}
}


function HideShowInnerHTML(thisElement, InnerHTML1, InnerHTML2)
{
	document.getElementById(thisElement).style.display="block";

/*
	if (document.getElementById(thisElement).innerHTML == "")
		document.getElementById(thisElement).innerHTML=InnerHTML1;
	else if (document.getElementById(thisElement).innerHTML == InnerHTML2)
		document.getElementById(thisElement).innerHTML=InnerHTML1;
	else if (document.getElementById(thisElement).innerHTML == InnerHTML1)
		document.getElementById(thisElement).innerHTML=InnerHTML2;
	else
		document.getElementById(thisElement).innerHTML="";
*/

	if (document.getElementById(thisElement).innerHTML == InnerHTML2)
		document.getElementById(thisElement).innerHTML=InnerHTML1;
	else
		document.getElementById(thisElement).innerHTML=InnerHTML2;
}


function InnerIFrame(thisElement)
{
}


function HighlightSelection(thisElement)
{
//	alert("thisElement: '" + thisElement + "'");
	document.getElementById(thisElement).style.backgroundColor="#7A7";
}


function UnHighlightSelectionBlack(thisElement)
{
//	alert("thisElement: '" + thisElement + "'");
	document.getElementById(thisElement).style.backgroundColor="#000";
}


function UnHighlightSelectionWhite(thisElement)
{
//	alert("thisElement: '" + thisElement + "'");
	document.getElementById(thisElement).style.backgroundColor="#FFF";
}




//document.write(". " + browser + " .\n");

function MozillaJavaScript()
{
	if (browser=="Microsoft Internet Explorer")
	{
		document.write("<div style=\"padding:5px; border:double 2px #F00;\">The JavaScript in this webpage works best with a <a href=\"http://www.mozilla.org/products/\" target=\"_blank\">Mozilla-based</a> (FireFox, SeaMonkey) web browser.</div> <br/><br/>\n\n");
	}
}

function UNICODE()
{
	if (browser=="Microsoft Internet Explorer")
	{
		document.write("<div style=\"padding:5px; border:solid 2px #F00;\">This webpage uses UNICODE characters that IE may not recognize.  Please consider using the <a href=\"http://www.mozilla.org/products/\" target=\"_blank\">Mozilla</a> (FireFox, SeaMonkey) web browser instead.</div> <br/><br/>\n\n");
	}
}

function Prefetch()
{
	if (browser=="Microsoft Internet Explorer")
	{
		document.write("This webpage contains a PREFETCH directive that IE may not recognize.  Please consider using the <a href=\"http://www.mozilla.org/products/\">Mozilla Suite</a> web browser instead. <br/><br/>\n\n");
	}
}


function ReloadingCountdown(RefreshSeconds, UpdateDelayMilliseconds, thisElement, HistoryGoBack)
{
	// Because the webpage will refresh itself and recall this function
	// there's no need to re-assign SecondsLeft after reaching 0

	var SecondsLeft = RefreshSeconds;

	// This is for some of my pages where I only called this function with 3 variables before I expanded it out to 4
	HistoryGoBack+=0;


/* *** DOH! I Forgot!  This interferes with RECURSIVE calls! ***

	// Ive decieded to change the UpdateDelayMilliseconds to seconds rather than milliseconds
//	if (UpdateDelayMilliseconds > 1000)
//	{
//		Update/=1000;
//	}

	// If I do enter the parameter as seconds, convert to milliseconds
	if (UpdateDelayMilliseconds < 300)
	{
		UpdateDelayMilliseconds*=1000;
	}
*/

	document.getElementById(thisElement).innerHTML="This page should reload in " + SecondsLeft + " seconds. (" + UpdateDelayMilliseconds/1000 + ")";


	if (UpdateDelayMilliseconds < 1000)
	{
		UpdateDelayMilliseconds=1000;
	}

	SecondsLeft-= parseInt(UpdateDelayMilliseconds/1000);

	// when used with setTimeout, this statement cause the webpage to refresh without any information
	//document.write("Page reload in " + SecondsLeft + " seconds.");

	if (SecondsLeft >= 0)
	{
		// If our Update counter exceeds the number of seconds left, half the Update counter
		if ( (UpdateDelayMilliseconds > 1000) && ((UpdateDelayMilliseconds/1000) >= SecondsLeft) )
		{
			UpdateDelayMilliseconds/=2;
		}

		// If under 10 seconds then update counter faster
		if ( (SecondsLeft < 11) && (UpdateDelayMilliseconds > 1000) )
		{
			UpdateDelayMilliseconds=1000;
		}

		setTimeout("ReloadingCountdown(" + SecondsLeft + ", " + UpdateDelayMilliseconds + ", '" + thisElement + "', '" + HistoryGoBack + "');", UpdateDelayMilliseconds);
	}
	else
	{
		if (HistoryGoBack == 0)
		{
			document.getElementById(thisElement).innerHTML="Oops!  Looks like the auto-reload didnt work.  Time for you to work that finger muscle.";
		//	window.location.reload();
		}
	//	else if (HistoryGoBack == -1)
	//	{
	//		window.history.back();
	//	}
		else
		{
		//	var temp = 0 + HistoryGoBack;
		//	document.getElementById(thisElement).innerHTML="<a href=\"javascript:history.go(" + HistoryGoBack + ");\">Oops!  Looks like the auto-goback didnt work.  (" + HistoryGoBack + ")</a>";

		// Somehow none of these work

		//	history.go('' + temp);
		//	history.go(temp);
		//	history.go(HistoryGoBack);
		//	window.history.go(HistoryGoBack);
		//	window.history.go(temp);
	//		window.history.go( parseInt(temp) );
		//	window.history.go('' + temp + '');
		//	window.history.go(0 + temp);
		//	window.history.back(HistoryGoBack);


			// But this one does!
			// Because we're going back 1 more than we're supposed to,
			// increase HistoryGoBack by 1 to offset the -1 later.
			HistoryGoBack++;
			window.history.go(HistoryGoBack-1);
		}
	}
}
// ENDS function ReloadingCountdown(RefreshSeconds, UpdateDelayMilliseconds, thisElement, HistoryGoBack)



// Use this with the <IMG> tag
function EnlargeIMGThumb(thisElement, LargeImage)
{
	document.getElementById(thisElement).src=LargeImage;
}


// Use this with the <DIV> tag
function EnlargeDIVThumb(thisElement, LargeImage)
{
	document.getElementById(thisElement).style.backgroundRepeat="no-repeat";
	document.getElementById(thisElement).style.backgroundImage=LargeImage;
}





function ResizeFooterSmall()
{
	document.getElementById('CGIsubfooter').style.display = "none";
}


function ResizeFooterLarge()
{
	document.getElementById('CGIsubfooter').style.display = "inline";
}





function BackgroundHighlight(thisElement, Color)
{
	document.getElementById(thisElement).style.backgroundColor=Color;
}

