//<file_description>Javascript function to make sure required fields are entered</file_description>
//<project_name>XML Library</project_name>


//<function><name>check</name><Usage>check(formname or form number)</usage>
//<description>The name of every field you want to be required should start with "_REQ_" The ID of the field should be set to the name of the question being asked. If you had a text box asking for a first name, the id should be "First Name" Radio or checkbox lists should all have the same name and the first element should contain the name of the question in the ID. </description></function>
function check(formname) {
  var t;
  var valid = 1;
  var f = document.forms[formname];
  outer_loop:
  for(t in f) {
    if(t.substr(0,5) == "_REQ_") {
      //alert(f[t].type + " " + t);
      if (f[t].type == "text") {
      	var def = "";
        //if (f[t].default != "") def = f[t].default
        
        	 if(f[t].value == def || f[t].value == f[t].id) {
        	   alert("Please fill in " + f[t].id);
        	   window.location.hash=f[t].name;
        	   valid = 0;
        	   break outer_loop;
        	 }     
        	    
       } else if (f[t].type == "select-one") {
       
          if(f[t].selectedIndex==0) {
            alert("Please fill in " + f[t].id);
            window.location.hash=f[t].name;
            valid=0;
            break outer_loop;
          }
          
        } else if (f[t].type == undefined) {
	        
	          var s;
	          valid = 0;
	          for(s=0;s<f[t].length;s++) {
	            if(f[t][s].checked) {
	              valid = 1;
	            }
	          }
						if(valid==0) {
						  alert("Please select an answer to the question \"" + f[t][0].id + "\"");
	            window.location.hash=f[t][0].name;
	            break outer_loop;
	          }   
	          
	      }
      }
    }
  
  
  if(valid==1) document.forms[formname].submit();
}

