<!--
	/* This script file contains common functions used throughout UBAHWeb project. */

	/***** Define regular expressions. *****/
	var charexp = /[a-zA-Z0-9]/                                             // alpha or numeric values only.
	var intexp = /[0-9]/		                                        // numeric values only.
	var inputexp = /./                                                      // any character
	var zipexp = /^\d{5}$|^\d{5}[\-\s]?\d{4}$/                              // zip code or zip plus 4
	var emailexp = /^[-a-zA-Z_0-9\.]+@[-a-zA-Z_0-9\.]+\.[a-zA-Z\.]{2,5}$/i  // e-mail address
	var moneyexp = /^\d{0,4}(\.\d{2})?$/				     	// valid currency format.
	var daysInMonth = new Array();
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;   // must programmatically check this
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;
	var defaultEmptyOK = false;

	/***** Verify that input meets reqular expression criteria *****/
	function isValid(str) {
		return emailexp.test(str)
	}

	/***** Verify that input meets reqular expression criteria *****/
	function hasChar(str) {
		return charexp.test(str)
	}

	/***** Verify that input meets reqular expression criteria *****/
	function hasInt(str) {
		return intexp.test(str)
	}

	/***** Verify that input meets reqular expression criteria *****/
	function hasInput(str) {
		return inputexp.test(str)
	}

	/***** Verify that input meets reqular expression criteria *****/
	function isMoney(str) {
		return moneyexp.test(str)
	}

	/***** Remove all non numeric values. *****/
	function stripNonDigits(str) {
		return str.replace(/[^0-9]/g,"")
	}

	/***** Check required inputs for null values. *****/
	function CheckNull(ctrl)	{
	if (!hasChar(ctrl.value)) {
		return false;
		}
	else 	{
		return true;
		}
	}

	/***** Check required inputs for integer values. *****/
	function CheckInt(ctrl)	{
	if (!hasInt(ctrl.value)) {
		return false;
		}
	else 	{
		return true;
		}
	}

	/***** Check required inputs for currency format. *****/
	function CheckMoney(ctrl)	{
	if (!isMoney(ctrl.value)) {
		return false;
		}
	else 	{
		return true;
		}
	}

	function roundOff(value, precision) {
		value = "" + value //convert value to string
		precision = parseInt(precision);

		var whole = "" + Math.round(value * Math.pow(10, precision));
		result = whole / Math.pow(10, precision);

		result = "" + result;
		var decPoint = result.indexOf('.');
		if (decPoint == -1) {
			result += "."
			for (var i = 0; i < precision; i++) {
				result += "0";
			}
		} else {
			whole = result.substr(0,decPoint) + ".";
			var decPart = result.substr(decPoint+1);
			decPoint = precision - decPart.length;
			if (decPoint > 0) {
				for (var i = 0; i < decPoint; i++) {
					result += "0";
				}
			}
		}
	}

/*	function roundOff(value, precision) {
		value = "" + value //convert value to string
		precision = parseInt(precision);

		var whole = "" + Math.round(value * Math.pow(10, precision));

		var decPoint = whole.length - precision;

		if(decPoint != 0) {
			result = whole.substring(0, decPoint);
			result += ".";
			result += whole.substring(decPoint, whole.length);
		} else {
			result = whole;
		}
		return result;
	}
*/
	// isDate (STRING year, STRING month, STRING day)
	//
	// isDate returns true if string arguments year, month, and day
	// form a valid date.
	//

	function isDate (year, month, day)
	{
	    // catch invalid years (not 2- or 4-digit) and invalid months and days.
	    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

	    // Explicitly change type to integer to make code work in both
	    // JavaScript 1.1 and JavaScript 1.2.
	    var intYear = parseInt(year);
	    var intMonth = parseInt(month);
	    var intDay = parseInt(day);

	    // catch invalid days, except for February
	    if (intDay > daysInMonth[intMonth]) return false;

	    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

	    return true;
	}

	// daysInFebruary (INTEGER year)
	//
	// Given integer argument year,
	// returns number of days in February of that year.

	function daysInFebruary (year)
	{
	    // February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
	    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
	}

	// isMonth (STRING s [, BOOLEAN emptyOK])
	//
	// isMonth returns true if string s is a valid
	// month number between 1 and 12.

	function isMonth (s)
	{
	   if (!hasChar(s))
	       if (isMonth.arguments.length == 1) return defaultEmptyOK;
	       else return (isMonth.arguments[1] == true);
	    return isIntegerInRange (s, 1, 12);
	}



	// isDay (STRING s [, BOOLEAN emptyOK])
	//
	// isDay returns true if string s is a valid
	// day number between 1 and 31.

	function isDay (s)
	{
	    if (!hasChar(s))
	       if (isDay.arguments.length == 1) return defaultEmptyOK;
	       else return (isDay.arguments[1] == true);
	    return isIntegerInRange (s, 1, 31);
	}

	// isYear (STRING s [, BOOLEAN emptyOK])
	//
	// isYear returns true if string s is a valid
	// Year number.  Must be 2 or 4 digits only.
	//
	// For Year 2000 compliance, you are advised
	// to use 4-digit year numbers everywhere.

	function isYear (s)
	{
	    if (!hasChar(s))
	       if (isYear.arguments.length == 1) return defaultEmptyOK;
	       else return (isYear.arguments[1] == true);
	    if (!isNonnegativeInteger(s)) return false;
	    return ((s.length == 2) || (s.length == 4));
	}

	// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
	//
	// isIntegerInRange returns true if string s is an integer
	// within the range of integer arguments a and b, inclusive.


	function isIntegerInRange (s, a, b)
	{
	   if (!hasChar(s))
	       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
	       else return (isIntegerInRange.arguments[1] == true);

	    // Catch non-integer strings to avoid creating a NaN below,
	    // which isn't available on JavaScript 1.0 for Windows.
	    if (!hasInt(s)) return false;

	    // Now, explicitly change the type to integer via parseInt
	    // so that the comparison code below will work both on
	    // JavaScript 1.2 (which typechecks in equality comparisons)
	    // and JavaScript 1.1 and before (which doesn't).
	    var num = parseInt (s);
	    //parseInt returns incorrect values for 08 and 09 strings for some reason.
	    if (s == "08") num = 8;
	    if (s == "09") num = 9;

	    return ((num >= a) && (num <= b));
	}

	// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
	//
	// Returns true if string s is an integer >= 0.

	function isNonnegativeInteger (s)
	{
	    var secondArg = defaultEmptyOK;

	    if (isNonnegativeInteger.arguments.length > 1)
	        secondArg = isNonnegativeInteger.arguments[1];

	    // The next line is a bit byzantine.  What it means is:
	    // a) s must be a signed integer, AND
	    // b) one of the following must be true:
	    //    i)  s is empty and we are supposed to return true for
	    //        empty strings
	    //    ii) this is a number >= 0

	    return (isSignedInteger(s, secondArg)
	         && ( (!hasChar(s) && secondArg)  || (parseInt (s) >= 0) ) );
	}

	// isSignedInteger (STRING s [, BOOLEAN emptyOK])
	//
	// Returns true if all characters are numbers;
	// first character is allowed to be + or - as well.
	//
	// Does not accept floating point, exponential notation, etc.
	//
	// We don't use parseInt because that would accept a string
	// with trailing non-numeric characters.
	//
	// EXAMPLE FUNCTION CALL:          RESULT:
	// isSignedInteger ("5")           true
	// isSignedInteger ("")            defaultEmptyOK
	// isSignedInteger ("-5")          true
	// isSignedInteger ("+5")          true
	// isSignedInteger ("", false)     false
	// isSignedInteger ("", true)      true

	function isSignedInteger (s)

	{
	   if (!hasChar(s))
	       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
	       else return (isSignedInteger.arguments[1] == true);

	    else {
	        var startPos = 0;
	        var secondArg = defaultEmptyOK;

	        if (isSignedInteger.arguments.length > 1)
	            secondArg = isSignedInteger.arguments[1];

	        // skip leading + or -
	        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
	           startPos = 1;
	        return (hasInt(s.substring(startPos, s.length), secondArg))
	    }
	}


	function ret_getElementById(tagId)
	{
		/*  Returns a reference to a form object */
		var obj;
		if(document.all)
			obj=document.all[tagId];
		else
			obj=document.getElementById(tagId);
		if(obj && obj.length && obj[0].id==tagId)
			obj=obj[0];
		return obj;
	}

	function buildQueryStringFromForm(theFormName) {
		theForm = ret_getElementById(theFormName);
		var qs = '';
		for (e=0;e<theForm.elements.length;e++) {
			if (theForm.elements[e].name!='' && theForm.elements[e].name.substring(0,2)!= '__') {
				qs+=(qs=='')?'?':'&';
				qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value);
			}
			}
		return qs;
	}

	function textboxSelect(oTextbox, iStart, iEnd) {
		switch(arguments.length) {
			case 1:
				oTextbox.select();
				break;

			case 2:
				iEnd = oTextbox.value.length;
				/* falls through */

			case 3:
				if (isIE) {
					var oRange = oTextbox.createTextRange();
					oRange.moveStart("character", iStart);
					oRange.moveEnd("character", -oTextbox.value.length + iEnd);
					oRange.select();
				} else if (isMoz){
					oTextbox.setSelectionRange(iStart, iEnd);
				}
		}

		oTextbox.focus();
   }

   function HideObj(ObjIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(ObjIDName).style.visibility = "hidden";
		}
		else if (ie4) {
			document.all[ObjIDName].style.visibility = "hidden";
		}
		else if (ns) {
			document.layers[ObjIDName].visibility = "hidden";
		}
   }

   function ShowObj(ObjIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(ObjIDName).style.visibility = "visible";
		}
		else if (ie4) {
			document.all[ObjIDName].style.visibility = "visible";
		}
		else if (ns) {
			document.layers[ObjIDName].visibility = "visible";
		}
  }

  function ClearObj(ObjIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(ObjIDName).innerHTML = "";
			document.getElementById(ObjIDName).style.left = -400;
			document.getElementById(ObjIDName).style.top = -1000;
		}
		else if (ie4) {
			document.all[ObjIDName].innerHTML = "";
			document.all[ObjIDName].style.left = -400;
			document.all[ObjIDName].style.top = -1000;
		}
		else if (ns) {
			document.layers[ObjIDName].innerHTML = "";
			document.layers[ObjIDName].left = -400;
			document.layers[ObjIDName].top = -1000;
		}
  }

	/* Begin Flash Detection Script */
	var MM_contentVersion = 7;
	var plugin = (navigator.mimeTypes &&
	navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0; if ( plugin ) {
			var words = navigator.plugins["Shockwave Flash"].description.split(" ");
			for (var i = 0; i < words.length; ++i)
			{
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i];
			}
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0
	&& (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</scr' + 'ipt\> \n');
	}
	/* End Flash Detection Script */

	function RunFlash(flashID, containerobj) {
		var oDiv = ret_getElementById(containerobj);
		if ( MM_FlashCanPlay ) {
			switch (flashID) {
				case 100:
					oDiv.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="745" HEIGHT="330" id="edcMain" VIEWASTEXT>'
						+ '<PARAM NAME="movie" VALUE="flash/ubamchristmas.swf"> <PARAM NAME="quality" VALUE="high"> <PARAM NAME="bgcolor" VALUE="#FFFFFF"> <param name="wmode" value="transparent">'
						+ '<EMBED src="flash/ubamchristmas.swf" quality="high" bgcolor="#FFFFFF" WIDTH="745" HEIGHT="330" NAME="edcMain" ALIGN="" wmode="transparent" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
						+ '</EMBED></OBJECT>';
					break;
				case 200:
					break;
				case 300:
					oDiv.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="729" HEIGHT="90" id="c365banner" VIEWASTEXT>'
						+ '<PARAM NAME="movie" VALUE="flash/c365_banner.swf"> <PARAM NAME="quality" VALUE="high"> <PARAM NAME="bgcolor" VALUE="#FFFFFF"> <param name="wmode" value="transparent">'
						+ '<EMBED src="flash/c365_banner.swf" quality="high" bgcolor="#FFFFFF" WIDTH="729" HEIGHT="90" NAME="c365banner" ALIGN="" wmode="transparent" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
						+ '</EMBED></OBJECT>';
					break;
				default :
					oDiv.innerHTML = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="745" HEIGHT="228" id="edcMain" VIEWASTEXT>'
						+ '<PARAM NAME="movie" VALUE="flash/edc.swf"> <PARAM NAME="quality" VALUE="high"> <PARAM NAME="bgcolor" VALUE="#FFFFFF"> <param name="wmode" value="transparent">'
						+ '<EMBED src="flash/edc.swf" quality="high" bgcolor="#FFFFFF" WIDTH="745" HEIGHT="228" NAME="edcMain" ALIGN="" wmode="transparent" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'
						+ '</EMBED></OBJECT>';
			}
		}
		else {
			// No flash capabilities display something else.
			switch (flashID) {
				case 100:
					oDiv.innerHTML = '<img src="images/mainSub.jpg" border="0">';
					break;
				case 200:
					break;
				default :
					oDiv.innerHTML = '';
			}
		}
	}

	/*  Get left pixel position of an object. */
	function DL_GetElementLeft(eElement)
	{
		if (!eElement && this)
		{
			eElement = this;
		}

		var nLeftPos = eElement.offsetLeft;
		var eParElement = eElement.offsetParent;
		while (eParElement != null)
		{
			nLeftPos += eParElement.offsetLeft;
			eParElement = eParElement.offsetParent;
		}
		return nLeftPos;
	}

	/*  Get top pixel position of an object. */
	function DL_GetElementTop(eElement)
	{
		if (!eElement && this)
		{
			eElement = this;
		}

		var nTopPos = eElement.offsetTop;
		var eParElement = eElement.offsetParent;
		while (eParElement != null)
		{
			nTopPos += eParElement.offsetTop;
			eParElement = eParElement.offsetParent;
		}
		return nTopPos;
	}
	function HideDiv(DivIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(DivIDName).style.visibility = "hidden";
		}
		else if (ie4) {
			document.all[DivIDName].style.visibility = "hidden";
		}
		else if (ns) {
			document.layers[DivIDName].visibility = "hidden";
		}
	}

	function ShowDiv(DivIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(DivIDName).style.visibility = "visible";
		}
		else if (ie4) {
			document.all[DivIDName].style.visibility = "visible";
		}
		else if (ns) {
			document.layers[DivIDName].visibility = "visible";
		}
	}

	function ClearDiv(DivIDName) {
		// Browser capability sniffing
		var ie=false, ie4=false, ns=false;
		if (document.getElementById) { ie=true; }
		else if (document.all) { ie4=true; }
		else if (document.layers) { ns=true; }
		if (ie) {
			document.getElementById(DivIDName).innerHTML = "";
			document.getElementById(DivIDName).style.left = -400;
		}
		else if (ie4) {
			document.all[DivIDName].innerHTML = "";
			document.all[DivIDName].style.left = -400;
		}
		else if (ns) {
			document.layers[DivIDName].innerHTML = "";
			document.layers[DivIDName].left = -400;
		}
	}


//-->
