// validators_javascript.js

	function IsNumber(numberStr)
	{
		var ValidChars = "0123456789.,";
		var IsNumber=true;
		var Char;
	   
		for (i = 0; i < numberStr.length && IsNumber == true; i++) { 
			Char = numberStr.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
	         	IsNumber = false;
			}
		}
		return IsNumber;
	}
	
	function IsWholeNumber(numberStr)
	{
		var ValidChars = "0123456789";
		var IsWholeNumber=true;
		var Char;
	   
		for (i = 0; i < numberStr.length && IsWholeNumber == true; i++) { 
			Char = numberStr.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) {
	         	IsWholeNumber = false;
			}
		}
		return IsWholeNumber;
	}

	function IsDate(dateStr) {
		// ******************************************************************
		// This function accepts a string variable and verifies if it is a
		// proper date or not. It validates format matching either
		// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
		// has the proper number of days, based on which month it is.
		
		// The function returns true if a valid date, false if not.
		// ******************************************************************
			
	    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	    var matchArray = dateStr.match(datePat); // is the format ok?
	
	    if (matchArray == null) {
	        return false;
	    }
	
	    month = matchArray[1]; // parse date into variables
	    day = matchArray[3];
	    year = matchArray[5];
	
	    if (month < 1 || month > 12) { // check month range
	        return false;
	    }
	
	    if (day < 1 || day > 31) {
	        return false;
	    }
	
	    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	        return false;
	    }
	
	    if (month == 2) { // check for february 29th
	        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	        if (day > 29 || (day==29 && !isleap)) {
	            return false;
	        }
	    }
	    return true; // date is valid
	}
	
	
	function IsEmail(str) {
		// are regular expressions supported?
		var supported = 0;
		if (window.RegExp) {
			var tempStr = "a";
			var tempReg = new RegExp(tempStr);
			if (tempReg.test(tempStr)) 
				supported = 1;
		}
		if (!supported) {
			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
			
		    // IF EMAIL ADDRESS HAS A '@' CHARACTER
		    if (checkString.indexOf("@") != -1) {
		      at = true;
		
		    // IF EMAIL ADDRESS HAS A '.' CHARACTER
		    } else if (checkString.indexOf(".") != -1) {
		      dot = true;
		    }
		    // PARSE REMAINDER OF STRING
		    for (var i = 0; i < checkString.length; i++) {
		        ch = checkString.substring(i, i + 1)
		        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
		                || (ch == "@") || (ch == ".") || (ch == "_")
		                || (ch == "-") || (ch >= "0" && ch <= "9")) {
		                newstr += ch;
		                if (ch == "@") {
		                    at=true;
		                }
		                if (ch == ".") {
		                    dot=true;
		                }
		        }
		    }
		    if ((at == true) && (dot == true)) {
		        return true;
		    }
		    else {
		      return false;
		    }
		}
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		return (!r1.test(str) && r2.test(str));
	}