
// validate a text field to be longer than 3 alphanumeric char.
function chk_textField(friendlyName, fieldName, minLen, isRequired) {
	var textBox = eval("document.frmMain." + fieldName);
	
	if (textBox.value.length < minLen) {
		if (isRequired == true) {
			errmsg += "Invalid data for " + friendlyName + ".\n";
			return 1;
		} else {
			return 0;
		}
	} else {
		return 0;
	} // end if
} // end chk_Description

// validate a numeric filed to be a number greater than x 
// and that the total length is NOT greater than y.
function chk_numericField(friendlyName, fieldName, isRequired) {
	var textBox = eval("document.frmMain." + fieldName);
	if (textBox.value.length < 1) {
		if (isRequired == true) {
			errmsg += "Numeric data required for " + friendlyName + ".\n";
			return 1;
		} else {
			return 0;
		}
	} else {
		var num = parseInt(textBox.value);
		if (isNaN(num)) {
			errmsg += "Invalid numeric data entered for " + friendlyName + ".\n";
			return 1;
		} else {
			return 0;
		} // end if
	}
} // end chk_numericFields

// validate select list 
function chk_selectList(friendlyName, fieldName, isRequired) {
	var selectList = eval("document.frmMain." + fieldName);
	if (selectList.value == "") {
		if (isRequired == true) {
			errmsg += "Please make a slection for " + friendlyName + ".\n";
			return 1;
		} else {
			return 0;
		}
	} else {
		return 0;
	} // end if
} // end chk_selectList

// validate radio box 
function chk_radioBox(friendlyName, fieldName, isRequired) {
	var radioBox = eval("document.frmMain." + fieldName);
	if (isRequired == true) {
		if (radioBox.checked == false) {
			errmsg += "Please make a selection for " + friendlyName + ".\n";
			return 1;
		} else {
			return 0;
		}
	} else {
		alert("step5");
		return 0;
	} // end if
	alert("step6");
} // end chk_radioBox

// validate the Date Needed is NOT in the passed.
function chk_validDate(friendlyName, fieldName) {
	var fld_mm = eval("document.frmMain" + "." + fieldName + "_Month");
	var fld_dd = eval("frmProject" + "." + fieldName + "_Day");
	var fld_yyyy = eval("frmProject" + "." + fieldName + "_Year");
	
	var mm = parseInt(fld_mm.value);
	var dd = parseInt(fld_dd.value);
	var yyyy = parseInt(fld_yyyy.value);
	
	// check month lengths and leap year days
	if (!checkMonthLength(mm, dd)) {
		fld_mm.style.backgroundColor = "yellow";
		fld_dd.style.backgroundColor = "yellow";
		errmsg += "Invalid days for Month for " + friendlyName + ".\n";
		return 1;
	} // end if
  
	if (mm == 2) {
		if (!checkLeapMonth(mm, dd, yyyy)) {
			fld_mm.style.backgroundColor = "yellow";
			fld_dd.style.backgroundColor = "yellow";
			errmsg += "Invalid days for Month.\n";
			return 1;
		} // end if
	} // end if
	
	return 0;
} // end chk_DateNeeded

// check the entered month for too high a value
function checkMonthLength(mm, dd) {
  if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {
	return false;
  } else if (dd > 31) {
	return false;
  } // end if
  return true;
} // end checkMonthLength

// check the entered February date for too high a value
function checkLeapMonth(mm, dd, yyyy) {
  if (yyyy % 4 > 0 && dd > 28)  {
	return false;
  } else if (dd > 29) {
    return false;
  } // end if
  return true;
} // end checkLeapMonth

//-->
