// *------------------------------------*
// * eRegistration JavaScript Functions *
// *------------------------------------*
//-------------------*
// Function: saveURL *
//-------------------*
function saveURL(){
 var myURL = document.forms[0].elements["myurl"].value ;
 var myCookie = "EREGURL" ;
 document.cookie = myCookie + "=" + escape(myURL) ;
}
//-------------------*
// Function: AutoTab *
//-------------------*
function AutoTab(field, limit, next, evt) {
evt = (evt) ? evt : event ;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)) ;
if (charCode > 31 && field.value.length == limit) {
	field.form.elements[next].focus() ;
	}
}
//------------------------*
// Function: NumbersOnly  *
//------------------------*
function NumbersOnly(evt) {
evt = (evt) ? evt : event ;
var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)) ;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
	alert("Please enter numbers only in this field.") ;
	return false;
	}
return true;
}
//----------------*
// Function: trim *
//----------------*
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 
//-------------------------------------------------------------------*
// Function: isDate(dateStr)                                         *
//                                                                   *
// This function accepts a string variable and verifies if it is a   *
// proper date or not. It validates format matching 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.          *
//-------------------------------------------------------------------*

function isDate(dateStr) {
	var mydate = trim(dateStr) ;
	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/ ;
	var matchArray = mydate.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Please enter date as mm/dd/ccyy.");
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[5];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
	}
	if (day < 1 || day > 31) { // check day range
		alert("Day must be between 1 and 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn`t have 31 days!") ;
		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)) {
			alert("February " + year + " doesn`t have " + day + " days!");
			return false;
		}
	}
return true; // date is valid
}
