   // nReload and NewVerifyImage were provided by http://www.tectite.com/
   var nReload = 5;
   function NewVerifyImage() {
      if (nReload <= 2) {
         if (nReload <= 0) {
            alert("Sorry, too many reloads.");
            return;
         }
         else {
            alert("Only " + nReload + " more reloads are allowed");
         }
      }
      nReload--;
      // This code now works in both IE and FireFox
      var e_img;
      e_img = document.getElementById("vimg");
      if (e_img) {
         // FireFox attempts to "optimize" by not reloading
         // the image if the URL value doesn't actually change.
         // So, we make it change by adding a different
         // count parameter for each reload.
         e_img.setAttribute("src",e_img.src+'?count='+nReload);
      }
   }
   function RecordPosition(pName, pElement) {
      if ( pElement.offsetTop < iMinOffsetTop ) {
        iMinOffsetTop = pElement.offsetTop;
        iMinElementName = pName;
      }
   }
   function AddLabel(pElement) {
      var myclass = pElement.className;
      if (myclass) {
         myclass = ' ' + myclass + ' ';
         if (myclass.indexOf(' valueisinerror ')==-1) {
            //alert(myclass + 'AL: valueisinerror does not appear in class');
            pElement.className = pElement.className + ' valueisinerror';
         }
         else {
            //alert(myclass + 'AL: valueisinerror appears in class');
            // its class already has valueisinerror
         }
      }
      else {
         //alert('AL: element does not have a class');
         // element does not have a class
         pElement.className = 'valueisinerror';
      }
   }
   function RemoveLabel(pElement) {
      var myclass = pElement.className;
      if (myclass) {
         myclass = ' ' + myclass + ' ';
         if (myclass.indexOf(' valueisinerror ')==-1) {
            // element does not have a class of valueisinerror
            //alert(myclass + 'RL: valueisinerror does not appear in class');
         }
         else {
            // its class has valueisinerror
            //alert(myclass + 'RL: valueisinerror appears in class');
            myclass = myclass.replace(' valueisinerror ', '');
            pElement.className = myclass.substring(1, myclass.length-2);
         }
      }
      else {
         //alert('RL: element does not have a class');
         // element does not have a class
      }
   }
   function FixTheRadiosClass(pSpanId, pIsOK) {
      //alert('FTRC');
      var tSpanElement = document.getElementById(pSpanId);
      if ( pIsOK ) {
         //alert("OK");
         RemoveLabel(tSpanElement);
      }
      else {
         //alert("bad");
         AddLabel(tSpanElement);
         RecordPosition(pSpanId, tSpanElement);
      }
      return pIsOK;
   }
   function FixTheLabelsClass(pName, pElement, pIsOK) {
      var labels = document.getElementsByTagName('label');
      // alert('LENGTH' + labels.length);
      for (i=0; i<labels.length; i++) {
         var tElement = labels[i];
         // grim: the first does not work in IE as it always gives null
         // and I understand that the second does not work in Safari
         // so try both! 
         if(tElement.getAttribute('for')==pName || 
                  tElement.attributes['for'].nodeValue==pName) {
            // alert(pName);
            if ( pIsOK ) {
               // alert("OK");
               RemoveLabel(tElement);
            }
            else {
               // alert("bad");
               AddLabel(tElement);
               RecordPosition(pName, tElement);
            }
            return pIsOK;
         }
         else {
            // alert("no for");
         }
      }
      return pIsOK;
   }
   function MatchesRegex(pName, pElement, pRegex) {
      return FixTheLabelsClass(pName, pElement, pRegex.test(pElement.value));
   }
   function NotMatchesRegex(pName, pElement, pRegex) {
      return FixTheLabelsClass(pName, pElement, ! pRegex.test(pElement.value));
   }
   function EqualsValue(pName, pElement, pValue) {
      return FixTheLabelsClass(pName, pElement, pElement.value == pValue);
   }
   function NotEqualsValue(pName, pElement, pValue) {
      return FixTheLabelsClass(pName, pElement, pElement.value != pValue);
   }
   function IsRequired(pName, pElement) {
      // alert("about to call FixTheLabelsClass");
      return FixTheLabelsClass(pName, pElement, pElement.value.length != 0);
   }
   function IsRequiredRadio(pSpanId, pTargetElements) {
      for ( var tButtonNumber = 0; tButtonNumber<pTargetElements.length; 
            tButtonNumber++) {
         if( pTargetElements[tButtonNumber].checked ) {
            return FixTheRadiosClass(pSpanId, true);
         } 
      }
      return FixTheRadiosClass(pSpanId, false);
   }
   // need to add variables for the regular expressions
   function IsRequiredEmail(pName, pElement) {
      return MatchesRegex(pName, pElement, 
                          /^([a-zA-Z0-9])+([a-zA-Z0-9\\.\\\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+$/);
   }
   function IsOptionalEmail(pName, pElement) {
      return MatchesRegex(pName, pElement, 
                          /^ *$|^([a-zA-Z0-9])+([a-zA-Z0-9\\.\\\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+$/);
   }
   function IsRequiredCheckbox(pName, pElement) {
      return FixTheLabelsClass(pName, pElement, pElement.checked);
   }
   function IsRequiredSelect(pName, pElement) {
      return FixTheLabelsClass(pName, pElement, pElement.selectedIndex>0);
   }
   function IsNotTooBig(pName, pElement, pLower) {
      // 8192 is a constant in formmail.php
      return FixTheLabelsClass(pName, pElement, pElement.value.length>=pLower && pElement.value.length<=8192);
   }
   function SortOutFocus() {
      // alert("myresult is false" + iMinOffsetTop);
      window.scrollTo(0, iMinOffsetTop);
      // alert("setting focus" + iMinElementName);
      var myMinElement = document.getElementById(iMinElementName);
      myMinElement.focus();
      // alert("focus is set");
   }

