// usage: <form action="/cgi-bin/dbform.cgi" method="POST" onsubmit="return checkform(this);">

function checkForm ( form )
{

   if (form.Name.value == "") {
        alert("Name is a required field.  Please re-submit the form including your name.");
        form.Name.focus();
        return false;
   }

   if (form.Province[0].selected) {
        alert("PROVINCE is a required field.  Please select a PROVINCE from the drop down list.");
        form.Province.focus();
        return false;
   }


    if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(form.Email.value)) {
        alert("The \"email\" field must be valid.");
        form.Email.focus();
        return false;
    }

  ///////////////////////////////////////////////////////////////
  // This block of code finds out which radio button is checked
  // and stores the value in variable [i]
  //////////////////////////////////////////////////////////////

  var posform = document.forms[0]
  for (var i = 0; i < posform.Position.length; i++) {
     if (form.Position[i].checked) {
        break;
     }
  }

  var wsetting = document.forms[0]
  for (var z = 0; z < wsetting.WorkSetting.length; z++) {
     if (form.WorkSetting[z].checked) {
        break;
     }
  }

  var academicbkg = document.forms[0]
  for (var y = 0; y < academicbkg.AcademicBackground.length; y++) {
     if (form.AcademicBackground[y].checked) {
        break;
     }
  }

  //////////////////////////////////////////////////////////////////////////////
  // This block of code checks to see if Other is selected as the Position.
  // If Other is selected it makes sure that a value other than the default N/A
  // value is entered
  /////////////////////////////////////////////////////////////////////////////


  if (form.Position[i].value == "Other" && form.otherposition.value == "N/A" || form.otherposition.value=="" ) {
        alert( "You selected your current position as other.  Please specify your position" );
        form.otherposition.focus();
        return false ;
  }


  if (form.WorkSetting[z].value == "Other" && form.otherworksetting.value == "N/A" || form.otherworksetting.value=="" ) {
        alert( "You selected your work setting as other.  Please specify your work setting." );
        form.otherworksetting.focus();
        return false ;
  }

  if (form.AcademicBackground[y].value == "Other" && form.otheracademicbackground.value == "N/A" || form.otheracademicbackground.value=="" ) {
        alert( "You selected your academic background as other.  Please specify your academic background." );
        form.otheracademicbackground.focus();
        return false ;
  }




  if (form.health_care_profession.value == "") {
        alert( "Health Care Profession is a required field.  Please re-submit the form including your Health Care Profession." );
        form.health_care_profession.focus();
        return false ;
  }

  return true ;
}

//===========================================================================


