
function isEmpty(inputStr) {
	/*
		Pass a field's value to this function
		and it returns true if it is empty.
		
		Example:
		isEmpty(document.frmMyForm.txtMyTextField.value)
	*/
	if (inputStr == "" || inputStr == null) {
		return true
	}
	return false
}/////////////////////////////////////////////////////////////////////////////////////////////////

function hasData(inputStr){
	/*
		Pass a field's value to this function
		and it returns true if it has data.
		
		Example:
		hasData(document.frmMyForm.txtMyTextField.value)
	*/
	if (inputStr == "" || inputStr == null) {
		return false
	}
	return true
}/////////////////////////////////////////////////////////////////////////////////////////////////

function selectField(objField) {
	/*
		Pass a field object to this function
		to simulatiously bring focus to and
		select the field.
		
		Example:
		selectField(document.frmMyForm.txtMyTextField)
	*/
	objField.focus()
	objField.select()
}/////////////////////////////////////////////////////////////////////////////////////////////////

function IsValidTime(timeStr) {
	/*
		Checks if time is in HH:MM:SS AM/PM format.
		The seconds and AM/PM are optional.
		
		USE:
		Call the IsValidTime() function passing the time string to it.
		
		RETURNS:
		True if the time is valid.
		False if the time is invalid.
		
		Example:
		IsValidTime(document.frmMyForm.txtMyTimeEntryField.value)
			or
		IsValidTime('11:57 PM')
	*/
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	
	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)");
		return false;
	}
	if (hour <= 12 && ampm == null) {
		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("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 true;
}/////////////////////////////////////////////////////////////////////////////////////////////////

function isValidEmail(objEmailField) {
	/*
		This function checks the value of a field for
		valid email address format.
		
		USE:
		Pass the field object as an argument to the function.
		
		RETURNS:
		True if valid.
		False if invalid.
		
		Example:
		isValidEmail(document.frmMyForm.txtEmailAddress)
	*/
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objEmailField.value)){
		return (true)
	}
		objEmailField.focus();
		objEmailField.style.background = "#ffff00";
		alert("Please enter a valid email address.")
		return (false)
}/////////////////////////////////////////////////////////////////////////////////////////////////

function getSelectedIndex(objRadioButtonGroup){
	/*
		This function takes a radio button group and
		returns the index of the checked button.  If
		no button is checked, it returns -1.
		
		Example:
		getSelectedIndex(document.frmMyForm.rbtMyRadioGroup)
	*/
	if(objRadioButtonGroup.length == undefined){
		if(objRadioButtonGroup.checked){
			return 0;
		}else{
			return -1
		}
	}else{
		for (var i = 0; i < objRadioButtonGroup.length; i++) {
			if (objRadioButtonGroup[i].checked) {
				return i
			}
		}
	}
	return -1
}/////////////////////////////////////////////////////////////////////////////////////////////////


function dateHasPassed() {
	var objForm = document.frmMyForm
	
	var strYearInput = objForm.txtYear.value
	var strMonthInput = objForm.txtMonth.value
	var strDayInput = objForm.txtDay.value

	var dtmCurrentDateTime = new Date();
	var dtmToday = new Date(dtmCurrentDateTime.getYear(),dtmCurrentDateTime.getMonth(),dtmCurrentDateTime.getDate());

	// strMonthInput-1 -- javascript month array is zero-based
	var date = new Date(strYearInput,strMonthInput-1,strDayInput);
	
	if (date < dtmToday) {
		alert("Before today")
	} else if (date > dtmToday){
		alert("After today")
	} else {
		alert("Today")
	}
	
}///////////////////////////////////////////////////////////////////////////////
