<!-- Begin global_form_validation.js

//-------------------------------------------------
// function isValidText(_form_elText)
// notes: takes in a text field and checks if null, returns true/false
//-------------------------------------------------
function isValidText(_form_elText) {
  if ((_form_elText.value.length==0) || (_form_elText.value==null)) {
    return true;
  }
  else { return false; }
}	

//-------------------------------------------------
// function isValidCheckbox(_form_elCheckbox)
// notes: takes in set of checkboxes checks if one checkbox is selected, returns true/false
//-------------------------------------------------
function isValidCheckbox(_form_elCheckbox) {
  var filledIn = false;
  for (var counter=0; counter<_form_elCheckbox.length; counter++)
  if (_form_elCheckbox[counter].checked == true)
    filledIn = true;
    if (filledIn == false) {
      return false;
    }
    return true;
}


function checkboxLimit(_objCB,_thisCB,maxCount) {
  var countChecked = 0
  for (var counter=0; counter<_objCB.length; counter++) {
	  if (_objCB[counter].checked == true)
  	  countChecked++
	}
	if (countChecked > maxCount) {
		_thisCB.checked = false;
	}
}


//-------------------------------------------------
// function isValidDate(_form_elText)
// notes: takes in a text field and tests its value for valid date (including leap year), returns true/false
//-------------------------------------------------
function isValidDate(_form_elText) {
  var myDate = new String(_form_elText.value);
  var delimiterFirstInstance;
  var delimiterSecondInstance;
  var delimiterType;
  var monthPart;
  var dayPart;
  var yearPart;

  //accepts delimiting characters of either "/" or "-"

  delimiterFirstInstance = myDate.indexOf("/");
  if (delimiterFirstInstance == -1) {
   //check for the other allowed delimiter
   delimiterFirstInstance = myDate.indexOf("-");
   //if it is still not found, return false
   if (delimiterFirstInstance == -1) {
    return false;
   } delimiterType = "-";
  } else { delimiterType = "/";
  }

  delimiterSecondInstance = myDate.indexOf(delimiterType,
(delimiterFirstInstance + 1));
  if (delimiterSecondInstance == -1) {
   return false;
  }


  monthPart = myDate.substring(0, delimiterFirstInstance);
  if(validateMonth(monthPart) == false) {
   return false;
  }
  yearPart = myDate.substring((delimiterSecondInstance + 1),
   (myDate.length));

  if(validateYear(yearPart) == false) {
   return false;
  }

  dayPart = myDate.substring((delimiterFirstInstance + 1),
   (delimiterSecondInstance));
  if(validateDay(monthPart, dayPart, yearPart) == false) {
   return false;
  } else { return true;
  }
 }

 function validateDay(m, d, y) {
  if((isNaN(d)) || d == "") {
   return false;
  }

  var mo = parseInt(m, 10);
  var da = parseInt(d, 10);
  var ye = parseInt(y, 10);

  if (da < 1) {
   return false;
  }

  if ((mo == 4) || (mo == 6) || (mo == 9) || (mo == 11)) {
   //it is a 30 day month
   if (da > 30) {
    return false;
   }
  } else if(mo == 2) {
   // it is february (either 28 or 29 depending on leap year)
   if (isLeapYear(ye) == true) {
    if (da > 29) {
    //leap years have 29 days in february
     return false;
    }
   } else {
    if (da > 28) {
    //non leap years have 28 days in february
     return false;
    }
   }
  } else {
   // it is a 31 day month
   if (da > 31) {
    return false;
   }
  }
  //if we made it through all of the above without falling out,
  //it must be a valid day for the given month and year
  return true;
 }

 function validateMonth(mnth) {
  if((isNaN(mnth)) || mnth == "") {
   return false;
  }
  var intMonth = parseInt(mnth, 10);
  if((intMonth < 1) || (intMonth > 12)) {
   return false; //month must be between 1 and 12 (inclusive)
  } else { return true;
  }
 }

 function validateYear(yr) {
  if((isNaN(yr)) || yr == "") {
   return false;
  }
  var intYear = parseInt(yr, 10);
  if((intYear < 1970) || (intYear > 9999)) {
   return false; //year must be between 1970 and 9999 (inclusive)
  } else { return true;
  } 
 }

 function isLeapYear(yr) {
   /* classic leap year calculation:
    if the year is:
     evenly divisible by 4 and not evenly divisible by 100
     or
     evenly divisible by 400
    then it is a leap year,
    Otherwise it is not a leap year
   */

     if (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0)) {
         return true;
   } else { return false;
   } 
 }


//-------------------------------------------------
// function isValidTime(_form_elText)
// notes: takes in a text field and tests its value for valid time (allows military time), returns true/false
//-------------------------------------------------
function isValidTime(_form_elText) {
  var sTmp = new String(_form_elText.value);
	
	iTmp1 = sTmp.indexOf(":") 
	
	if (iTmp1 == -1) { 
		bValid = false 
	} else { 
   sTmp1 = sTmp.substr(0 , iTmp1) 
   sTmp2 = sTmp.substr(iTmp1 + 1) 
	 bValid = ((!isNaN(sTmp1)) && (!isNaN(sTmp2)) && (sTmp1>=0) && (sTmp1<24) && (sTmp2>=0) && (sTmp2<60))
	}
 return bValid 
} 


//-------------------------------------------------
// function isValidEmail(_form_elText)
// notes: takes in a text field and tests its value for valid email address
//-------------------------------------------------
function isValidEmail(_form_elText){
  var strEmail = new String(_form_elText.value);
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(strEmail)) {
		return false;
	}
	else {
		return true;
	}
}

// End -->