
/*********************
Maxtext v1.2
© 2002 Robert K. Davis
**********************/
function textlen(x,y){ // form item, maxlength
  var thelength = x.value.length;
  window.status=thelength + ' of ' + y + ' maximum characters.';
}

function maxtext(x,y){ // form item, maxlength
	var tempstr = x.value
	  if(tempstr.length>y){
	    x.value = tempstr.substring(0,y);
	  }
	  textlen(x,y);
}
/*********************/

// return isValidDate(this.date.value);
// MM/DD/YYYY format
	
function isValidDate(dateStr) {
	//alert(dateStr)
	// Checks for the following valid date formats:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Also separates date into month, day, and year variables
	
	// To require a 2 digit year entry, use this line instead:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
	
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
	alert("Date is not in a valid format.")
	return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	alert("Month must be between 1 and 12.");
	return false;
	}
	if (day < 1 || day > 31) {
	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
}

function CompareDates(from, to) {
	if (Date.parse(from) <= Date.parse(to)) {
		//alert("The dates are valid.");
		return true;
	}
	else {
		if (from == "" || to == "" || from == "--" || to == "--") {
			alert("Both dates must be entered.");
			return false;
		} else {
			alert("To date must occur after the from date.");
			return false;
		}
	}
}

function CompareDateToCurrent(dtCompare, dtFormat) {
	if (dtFormat == ''){
		dtFormat = "MM-dd-yyyy";	
	}
	//var Today = formatDate(new Date(),dtFormat);
	var Today = new Date();
//	alert(Date.parse(dtCompare))
//	alert(Date.parse(Today))
	
	if (Date.parse(dtCompare) <= Date.parse(Today)) {
		//alert("The dates are valid.");
		return true;
	}
	else {
		//alert("Date must occur before today");
		return false;
	}
}




//toggle help display
function toggleDisplay ( elem, elemDisplay ) {
	
	//var items = Array ( 'showTax', 'showFare');
	
	elem	=	document.getElementById ( elem );	
	elemDisplay = document.getElementById ( elemDisplay );	
	
	var state = ( elem.style.display == "block" ) ? "none":"block";
	var stateDisplay = ( elem.style.display == "block" ) ? "Show":"Hide";
	
	/*
	for ( i=0; i<items.length; i++ ) {
		document.getElementById ( items[i] ).style.display = "none";	
	}
	*/
	elemDisplay.innerText = stateDisplay;
	elem.style.display = state;	
}//end toggle help display



// accept only numeric numbers and decimal
// function nonKeys(what,objEvent,limit)
function nonKeys(what,objEvent)
{//function to check nonnomeric values
	var iKeyCode;  	
	iKeyCode = objEvent.keyCode;
	//if (what.value.length >=limit)
	//return false
	// Ascii 48 - 57 = 0-9
	// ascii 46 = . (period)
	if((iKeyCode>=48 && iKeyCode<=57) || iKeyCode == 46) return true;
	return false;
}


// accept only numeric numbers and colon
// function nonKeys(what,objEvent,limit)
function TimeKeys(what,objEvent)
{//function to check nonnomeric values
	var iKeyCode;  	
	iKeyCode = objEvent.keyCode;
	//if (what.value.length >=limit)
	//return false
	
	// Ascii 48 - 57 = 0-9
	// ascii 58 = : (colon)
	if((iKeyCode>=48 && iKeyCode<=57) || iKeyCode == 58) return true;
	return false;
}

<!-- Original:  Sandeep Tamhankar (stamhankar@hotmail.com) -->
<!-- Web Site:  http://207.20.242.93 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function IsValidTime(timeStr) {
	
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.
	
	// alert(timeStr)
	
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	
	// .Pattern = "(([01]+[\d]+)|(2[0-4])):[0-5]+[0-9]+"
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		alert("Time is not in a valid format.");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];
	
	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }
	
	if (hour < 0  || hour > 23 ) {
		//alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
		alert("Hour must be between 0 and 23");
		return false;
	}
	
	
	/*
	if (hour < 1  || hour > 12) {
		//alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
		alert("Hour must be between 1 and 12");
		return false;
	}
	
	
	if (hour <= 12 && ampm == null) {
		alert("You must specify AM or PM.");
		
		if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
			alert("You must specify AM or PM.");
		return false;		
	   }
	   
	}
	*/
	
	if  (hour > 12 && ampm != null) {
		alert("Time must be in standard time.");
		//alert("You can't specify AM or PM for military time.");
		return false;
	}
	
	if (minute<0 || minute > 59) {
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	if (second != null && (second < 0 || second > 59)) {
		alert ("Second must be between 0 and 59.");
		return false;
	}
	return false;
}


/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/*
<!--SAMPLE FORM -------------------------------->
<form name="formcheck" onsubmit="return formCheck(this);">
First Name: <input type=text name="FirstName" size="25"><br>
Last Name: <input type=text name="LastName" size="25"><br>
<input type=submit value="Submit Form">
</form>
*/

function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("FirstName", "LastName");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}



//-->