/*****************************************************************************
AUTHOR: Karen Gayda
MODIFIED: Owen Gunter

DATE: 01/08/2000
*******************************************************************************/

function validateDate(strValue) {
/************************************************
DESCRIPTION: Validates that a string contains only 
    valid dates with 2 digit month, 2 digit day, 
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and 
    string parsing to validate date.
    Ex. dd/mm/yy or dd-mm-yy or dd.mm.yy
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
	var objRegExp = /^\d{2}(\-|\/|\.)\d{2}\1\d{2}$/
	//check to see if in correct format
	
	if (0 == strValue.length) return true;
	
	if (!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	else {
		var strSeparator = strValue.substring(2,3) //find date separator
		var arrayDate = strValue.split(strSeparator); //split date into day, month, year
		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31, '03' : 31, '04' : 30, '05' : 31, '06' : 30, '07' : 31,
							'08' : 31, '09' : 30, '10' : 31, '11' : 30, '12' : 31}
		    
		var nDay = parseInt(arrayDate[0], 10);    // specify radix to remove problems with '08' and '09' which would octal!
		         
		//check if month value and day value agree
		if (arrayLookup[arrayDate[1]] != null) {
			if (nDay <= arrayLookup[arrayDate[1]] && nDay != 0) 
			return true; //found in lookup table, good date
		}
		    
		//check for February
		var nYear = 2000 + parseInt(arrayDate[2]);
		nMonth = parseInt(arrayDate[1], 10);
		if ((2 == nMonth) && (LeapYear(nYear) && nDay <= 29 || nDay <=28 && nDay !=0))
			return true; //Feb. had valid number of days
	}
	return false; //any other values, bad date
}

function LeapYear(nYear)
{
    return ((nYear % 4 == 0) && (nYear % 100 != 0)) || (nYear % 400 == 0);
}

function validateTime(strValue)
{
	//var objRegExp = /^\d{2}(\-|\:|\.)\d{2}$/
	
	// 21/02/01 Ian - changed to not to accept for - or .
	//var objRegExp = /^\d{2}(\:)\d{2}$/
	var objRegExp = /(^\d{2}|^\d{1})(\:)\d{2}$/
	  
	//check to see if in correct format
	if (!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	else {
	    if (strValue.substring(2,3) == ":" ){
			var strSeparator = strValue.substring(2,3)		//find time separator
		}
		else {
			var strSeparator = strValue.substring(1,2)		//find time separator
		}		
		
		var arrayTime = strValue.split(strSeparator);	//split time into hours:minutes
		var nHour = parseInt(arrayTime[0], 10);			// specify radix to remove problems with '08' and '09' which would octal!
		var nMinute = parseInt(arrayTime[1], 10);
		return (nHour < 24 && nMinute < 60);
	}
}

function validateCurrency(strValue)
{
	var objRegExp = /-?[0-9](|\.[0-9]{2})$/;   
	
	return objRegExp.test(strValue);
}

function isNumeric(szValue)
{
	var objRegExp  = /(^\d*$)/;
	return objRegExp.test(szValue);
}

