// javascript utility functions
function isInteger(fld)
{
	//alert("@isInt=");
	var valu = fld.value;
	var errMsg = "";
	if (valu == "")
	{
		fld.value = "0";
		return true;
	}
	if (isNaN(valu))
		errMsg = "Invalid entry - must be a number";
	else if (valu.indexOf("-") >= 0)
		errMsg = "Invalid entry - may not be negative";
	else if (valu.indexOf(".") >= 0)
		errMsg = "Invalid entry - decimal point not allowed";
	if (errMsg.length > 0)
	{
		alert(errMsg);
		fld2 = fld;			// copy value to a "global" variable for following "setTimeout" line
		setTimeout("fld2.focus()", 1); 	// must do as workaround because focus() fails in FireFox
	}
	return (errMsg.length == 0);
}

function isPositiveIntegerValue(valu)
{
	if (isNaN(valu))
		return false;
	if (valu.indexOf("-") >= 0  ||  valu.indexOf(".") >= 0)
		return false;
	return true;
}

function trim(sValue)
{
	while (sValue.charAt(0) == ' ')
	{
		sValue = sValue.substring(1, sValue.length);
	}
	while (sValue.charAt(sValue.length - 1) == ' ')
	{
		sValue = sValue.substring(0, sValue.length - 1);
	}
	return sValue;
}

function replaceAll(src,find,replace)
{
	//alert("@replaceAll(" + src + "," + find + "," + replace + ")");
	ndx = 0;
	while (true)
	{
		ndx = src.indexOf(find, ndx);
		//alert("ndx=" + ndx);
		if (ndx < 0)
			break;
		left = src.substr(0,ndx);
		src = left + replace + src.substr( ndx + find.length);
		//alert("src=[" + src + "]");
		ndx += replace.length - find.length + 1;
	}
	//alert("@end of replaceAll, src=[" + src + "]");
	return src;
}

function newWindowGoogleSearch(searchText)
{
	//alert("@newWindowGoogleSearch");
	searchText = replaceAll(searchText," ","+");
	url = "http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=L5q&q=" + searchText + "&btnG=Search";
	openWindow3( url, "google", 640);
}
function openDocWindow(url)
{
	openDocWindowWidth( url, 640)
}
function openDocWindowWidth(url, width)
{
	openWindow3(url, "docwin", width);
}
function openWindow3(url, windowName, width)
{
	openWindow6( url, windowName, 20, 20, width, 660);
}
function openWindow6(url, windowName, left, top, width, height)
{
	if ( isNaN(left) ) left = 20;
	if (left < 0) left = 0;
	if (left > 600) left = 600;
	if ( isNaN(top) ) top = 20;
	if (top < 0) top = 0;
	if (top > 600) top = 600;
	if ( isNaN(width) ) width = 640;
	if (width < 500) width = 500;
	if (width > 1024) width = 1024;
	if ( isNaN(height) ) height = 600;
	if (height < 300) height = 300;
	if (height > 1024) height = 1024;
	chrome = "top=" + top + ",left=" + left;
	chrome += ",scrollbars=1,title=0,address=0,status=0,toolbar=0,resizable=1,width=" + width + ",height=" + height;
	windo = window.open(url, windowName, chrome)
	windo.focus();
}

function showMovie ( movieFileName )
{
	var objMasterOverlay = document.getElementById ( 'masteroverlay' );
	var id = document.getElementById ( "div_movie" );
	if ( id )
	{
		if ( movieFileName != '' )
		{
			if ( objMasterOverlay != null )
				objMasterOverlay.style.display = 'block';
			id.style.display = "block";
			flowplayer("player",
						"flowplayer/flowplayer-3.1.5.swf",
						  {
							clip:
							{
							  url: movieFileName,
							  autoPlay: true
							},
							onFinish: function() { this.unload(); }
						  }  );
		}
		else
		{
		  if ( $f() != undefined )
			$f().unload();
		  if ( objMasterOverlay != null )
			objMasterOverlay.style.display = 'none';
		  id.style.display = "none";
		}
	}
}

// This function returns Internet Explorer's major version number, or 0 if not IE.
// It works by finding the "MSIE " string and extracting the version number following the space 
// (up to the decimal point thus ignoring the minor version number).
function ieVersion()
{
	var ua = window.navigator.userAgent;
	var msie = ua.indexOf( "MSIE " );
	var version = 0;
	if ( msie > 0 )      // If Internet Explorer, get the version number
		version = parseInt(ua.substring (msie+5, ua.indexOf (".", msie )));
	//alert("ieVersion=" + version);
	return version;
}

// general-purpuse "hard" delay -- use with extreme caution and only to resolve bad timing juju!!
/**function pauseMilliseconds(millis) --> currently unused
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while (curDate - date < millis);
}
*/


