    var digTemplate = /^[\d]*[\.]*[\d]*$/

function doSendCHD() 
 {
	 toSend = true;
	 with (document.CHDForm) {
		 if (!checkNum(age,20,100,"Age"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkNum(choles,129,325,"Cholesterol"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkNum(HDL,20,100,"HDL"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkNum(sistol,85,210,"Systolic Blood Pressure"))
		 {
			 errCode = 1;
			 toSend = false;
		 }

  // also make sure that radio buttons are selected.

		 if (!checkRadio(gender,"Gender"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkRadio(smoker,"Smoking"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkRadio(medication,"Medication for high blood pressure"))
		 {
			 errCode = 1;
			 toSend = false;
		 }


		 return toSend;
	 }  // with
 }
 

function doSendLDL() 
 {
	 toSend = true;
	 with (document.LDLForm) {
		 if (!checkNum(choles,129,325,"Cholesterol"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkNum(HDL,20,100,"HDL"))
		 {
			 errCode = 1;
			 toSend = false;
		 }
		 if (!checkNum(trig,20,400,"Triglycerides"))
		 {
			 errCode = 1;
			 toSend = false;
		 }


		 return toSend;
	 }  // with
 }



function doSendOvul() 
{
	 toSend = true;
	 with (document.ovalForm) {
		 if (!checkNum(periodLen,21,35,"Period Length"))
		 {
			 errCode = 1;
			 toSend = false;

		 }
		 return toSend;
	 } // with
} // doSendOvul

function doSendVAG()
{
   theRetValue = true;
	errorStr = "";
     with (document.VAGForm) {
		 for (idx=1;idx<=20 ;idx++ )
		 {
              theField = eval("q" + idx);
			  radChecked = false
          	  for (i=0; i < theField.length ; i++) {
	        	 if (theField[i].checked) {
					 radChecked = true;
				 }
			  }
			  if (!radChecked) {
					   if (errorStr) {
					      errorStr = errorStr + "," + idx;
					   } else {
					      errorStr = idx;
					   }
			  }
		 }
		 if (errorStr) {
			 alert("יש להשלים את השאלות הבאות \n" + errorStr);
             theRetValue = false;
		 }
	 }  // with
   return theRetValue
}

   function doSendBAC() 
   {
	  errCode = 0;
	  errStr = "";
	  theRetValue = true;
      with (document.BACForm) {
		  for (idx=1; idx <= 3; idx++)
		  {
			  theField=eval("drinkNum" + idx);
			  if (theField.value)
			  {
			      theVolField=eval("volume" + idx);
//				  alert(theVolField.selectedIndex);
				  if( theVolField.selectedIndex == 0) {

					  errStr += "יש למלא את גודל הכוס למשקה מספר " + idx + "\n";
				  }
			      theAlcField=eval("alcohol" + idx);
				  
				  if( theAlcField.selectedIndex == 0) {

					  errStr += "יש למלא את סוג המשקה למשקה מספר " + idx + "\n";
				  }

			  }

		  }  // for
         if (!theweight.value)
         {
			errStr += "יש למלא את שדה המשקל "+ "\n";
         }
	  }  // with
      if (errStr)
      {
			  alert(errStr);
              theRetValue = false;
     }

     return theRetValue
   }

function doSendQuest(numOfQ)
{
   theRetValue = true;
	errorStr = "";
     with (document.VAGForm) {
		 for (idx=1;idx<=numOfQ ;idx++ )
		 {
              theField = eval("q" + idx);
			  radChecked = false
          	  for (i=0; i < theField.length ; i++) {
	        	 if (theField[i].checked) {
					 radChecked = true;
				 }
			  }
			  if (!radChecked) {
					   if (errorStr) {
					      errorStr = errorStr + "," + idx;
					   } else {
					      errorStr = idx;
					   }
			  }
		 }
		 if (errorStr) {
			 alert("יש להשלים את השאלות הבאות \n" + errorStr);
             theRetValue = false;
		 }
	 }  // with
   return theRetValue
}

function hltVAGq(theID) {
//	alert(theID);
    theTR = myGetID(theID);
    theTR.style.background = "#999999";

}


function checkNum(theField, minVal, maxVal,strName) 
{
//	alert(theField)
   theRetValue = true;
   if (theField.value && digTemplate.test(theField.value))
   {
	   tmpVal = theField.value-0;
	   if (tmpVal < minVal || tmpVal > maxVal)
	   {
            theRetValue = false;
            theField.value = ""
	        theField.select()
            errCode = 3
	   }
   } else {
       errCode = 2
       theField.value = ""
	   theField.select()
	   theField.focus()
       theRetValue = false;
   }
   if (!theRetValue)
   {
	        alert ("Legal ["+strName+"] values are between " + minVal + " and " + maxVal)
   }
   document.retVal = theRetValue;
   return theRetValue
}

 function checkRadio(theField, strName)
 {
	 selVal = -1;
	 for (i=0; i < theField.length ; i++)
	 {
		 if (theField[i].checked)
		 {
	        selVal = i;
		 }
	 }
	 if (selVal < 0)
	 {
		 theRetValue = false;
		 alert ("Please select one of the options of the [" + strName + "] field");
	 } else {
		 theRetValue = true;
	 }
   document.retVal = theRetValue;
   return theRetValue
 } // checkRadio
