<!--//
// validateThis, 01-22-2009 j.hart
//
// Written to address the lack of
// built-in form valdiation in the CMS.
//
// Usage:
// 1) Required field IDs must end with "_R":
//	<input type="text" name="fieldname" id="fieldname_R" />
// 2) Call this script on the page, anywhere above the form:
//	<script type="text/javascript" src="/resources/validateThis.js"></script>
// 3) Call the function from the form tag:
//	<form name="form" id="form-id" onsubmit="return validateThis('form-id');" action="blah" method="post">
//-->

function validateThis(formID){
   var missedFieldFlag = 0;
   var fields = document.getElementById(formID).elements;
   
   for(var counter=0; counter<fields.length; counter++){
      if(fields[counter].id.indexOf("_R") != -1){
         if(fields[counter].value == ""){
                        fields[counter].style.backgroundColor = "yellow";
                        missedFieldFlag = 1;
                 }
      }
   }
   if(missedFieldFlag == 1){
      alert('All highlighted fields are required.\nPlease complete these to continue.');
      return false;
   }
   else{
      return true;
   }
}
