function DateValidation(me,errMsg){
	var val = me.value;
    if (ValidatorTrim(val).length == 0)
        return true;  
    if (isDate(val)){
		return true;
    } else {
		alert(errMsg);
		return false;
    }
}

function RegValidation(me, regExp, errMsg) {
    //var value = ValidatorGetValue(val.controltovalidate);
    var val = me.value;
    if (ValidatorTrim(val).length == 0)
        return true;        
    var rx = new RegExp(regExp);
    var matches = rx.exec(val);
    //return (matches != null && val == matches[0]);
    if (!(matches != null && val == matches[0])) {
		alert(errMsg);
		return false;
    }else {
		return true;
    }
}

function ValidatorTrim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

/*
Note: This function is called using 'onChange' event
for individual control. It does not set the focus back
into the control that has invalid data. If a focus needs
to be set to the control having invalid data, 
 1> Modify epzbTextBox control to call this
	function using 'onBlur' event
 2> Get the ControlId of the control having invalid data
 as follows
	var ControlId = item(ValidatorId).controltovalidate;
	After getting ControlId, set the focus if there is an error.
	i.e. item(ControlId).focus();
*/
function DisplayErrMsg(ValidatorId){
	if (typeof(Page_Validators) == "undefined") {
		return;
	}
	with(document.all){
		var strMsg = item(ValidatorId).isvalid ? "" : item(ValidatorId).errormessage;
		//alert(item(ValidatorId).controltovalidate);
		var ControlId = item(ValidatorId).controltovalidate;
		if(!(strMsg == "")) {
			alert(strMsg);
			item(ControlId).focus();
		}
	}
}

function valDateFun(o, args) {
	var val = args.Value;
	args.IsValid=isDate(val);
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
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 stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

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(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

/*function IsValidDate(source, arguments){
	alert("One");
	alert(arguments.value);
	if (isAlphabetic(arguments.value) == false || chkdate1(arguments.value) == false) {
		arguments.IsValid = false;
	}
	else 
		arguments.IsValid = true;
}

function chkdate1(val) {
	var strDate;
	strDate = val;
	alert("one");
	if (strDate.length < 1) 
		return true;
	var strDateArray, strDay, strMonth, strYear;
	var intday, intMonth, intYear, intElementNr;
	var booFound = false;
	strYear=""
	var strSeparatorArray = new Array("-"," ","/",".");
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
				return false;
			else {
				strMonth = strDateArray[0];
				strDay = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	   }
	}
	if (booFound == false) 
	{
		if(strDate.length == 8)
		{
				strMonth = strDate.substr(0, 2);
				strDay = strDate.substr(2, 2);
				if (strDate.length == 6) strYear = strDate.substr(2);
									else strYear = strDate.substr(4);
		}
		else
			return false;
    }
    if(strYear.length > 4) return false;
	intYear = parseInt(strYear, 10);
	if(intYear > 3000) return false;
	if (strYear!="") {							
    
					if (strYear.length == 2) {
						if (intYear > 50)
							strYear = '19' + strYear;
						else 
							strYear = '20' + strYear;
					}
					if (strYear.length == 1)
						strYear = '200' + intYear;	
						if (strYear.length == 3)
						return false;	
		}
	intday = parseInt(strDay, 10);
	if (isNaN(intday))
		return false;
	if (intday < 1) 
		return false;
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
		return false;
	if (intMonth>12 || intMonth<1)
		return false;
	if (isNaN(intYear))
		return false;
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31))
		return false;
	
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30))
			return false;
	if (intMonth == 2){
		if ((intYear % 4) == 0) {
			if (intday > 29) 
				return false;
		}
		else {
			if (intday > 28) 
				return false;
		}
	}	
	//Format Day and month to 2 digit
	if(strMonth.length < 2){
		strMonth = '0' + strMonth
	}
	if(strDay.length < 2){
		strDay = '0' + strDay
	}
    if(strYear.length > 4) return false;
	//datefield.value = strMonth + "/" + strDay + "/" + strYear;
}*/