/* ------~------~----~---~-----------~------~-----
 *
 *  Here's the home of common JavaScript functions.
 *
 * ~-*/

/**
 * Checks for valid numeric strings.
 */
function numericDecimalOnly(evt)
{
	var strValidChars = "0123456789.";
	var strChar;
	var strString	= evt.value;
	var dotCtr	= 0;
	var strOut	= '';

	if (strString.length == 0) return;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length; i++)
	{
		strChar = strString.charAt(i);
		if (strChar == '.') {
			dotCtr++;
		}
		
		if (strValidChars.indexOf(strChar) == -1)
		{
			evt.value = strOut;
			return;
		}
		
		if (dotCtr > 1) {
			evt.value = strOut;
			return;
		}
		
		strOut	+= strChar;
	}
}

function isNumberKey(evt)
{
	evt.value = evt.value.replace(/[^0-9]/g, "");
}

/**
 * This function shows our Ajax image turning round.
 */
function showAjaxTurningImage(sw, divName, alignment)
{
	if (divName == undefined || divName == 1) {
		divName		= "divAjaxProcessingPleaseWait";
	}
	if (alignment == undefined) {
		alignment	= "center";
	}
	if (sw == 0) {
		hideAjaxTurningImage(divName);
		return;
	}
	
	document.getElementById(divName).style.display	= 'inline';
	
	if (alignment == "center" || alignment == "left" || alignment == "right") {
		document.getElementById(divName).align		= alignment;
	}
}

/**
 * This function hides our Ajax image turning round.
 */
function hideAjaxTurningImage(divName)
{
	if (divName == undefined) {
		divName		= "divAjaxProcessingPleaseWait";
	}
	document.getElementById(divName).style.display = 'none';
}


/**
 * Javascript Date Validator
 *	isDate()
 *		Returns: True on success
 *			 String on error
 */

// Declaring valid date character, minimum year and maximum year
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

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 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function isDate(strYear, strMonth, strDay){
	var daysInMonth = DaysArray(12)
	var errMsg	= "";
	
	month	= parseInt(strMonth)
	day	= parseInt(strDay)
	year	= parseInt(strYear)
	
	if (strDay=="" || isNaN(strDay) || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		errMsg	+= " valid day";
	}
	if (strMonth=="" || isNaN(strMonth) || month<1 || month>12){
		errMsg	+= (errMsg == "" ? "" : ", ");
		errMsg	+= " valid month";
	}
	if (strYear=="" || isNaN(strYear) || year<minYear || year>maxYear){
		errMsg	+= (errMsg == "" ? "" : ", ");
		errMsg	+= " valid year";// between "+minYear+" and "+maxYear;
	}
	if (errMsg == "") {
		if (isInteger(strMonth+strDay+strYear)==false){
			errMsg	= " valid date"
		}
	}
	
	if (errMsg == "") {
		return true;
	} else {
		return "Please enter a "+errMsg;
	}
}
// end of file.