﻿      function validateFormri(){
         //The requirement is a name and a phone number or email address
        var goAhead=true;
        var err_name_error = document.getElementById("name_error");
        var err_phoneri_error = document.getElementById("phoneri_error");
        var err_emailri_error = document.getElementById("emailri_error");
        var email_phoneri = document.getElementById("email_and_phoneri");
        if(isEmpty(document.request_form.my_nameri.value)){
          goAhead=false;
          err_name_error.style.visibility="visible";
          document.request_form.my_nameri.setFocus();
          return;
         }else{
           err_name_error.style.visibility="hidden";
         }
        if(isEmpty(document.request_form.phoneri) && isEmpty(document.request_form.emailri)){
          goAhead=false;
          email_phoneri.style.visibility="visible";
        }else{
          email_phoneri.style.visibility="hidden";
          if(!isphoneri(document.request_form.phoneri)){
            goAhead=false;
            err_phoneri_error.style.visibility="visible";
            document.request_form.phoneri.setFocus();
          }else{
            err_phoneri_error.style.visibility="hidden";
          }
          if(!isemailri(document.request_form.emailri.value)){
            goAhead=false;
            err_emailri_error.style.visibility="visible";
          }else{
            err_emailri_error.style.visibility="hidden";
          }  
        }
        var hha = document.getElementById("hha");
        if(hha.checked==true){
          var county = document.getElementById("county").value;
          if(null == county || "" == county){
            goAhead=false;
            alert("You must specify a county when Home Health Services is checked.");
          }
        }
        if(goAhead){
          document.request_form.submit();
        }
      }
      function isChecked(string){
        //string should be the id of a checkbox element
        var el = document.getElementById(string);
        if (el.checked==true){
          //alert(el.checked); //This does work
          //el.style.color="#FF0000"; //These don't work right now, but I don't have time to fix it yet.
          //el.style.background="#000000";
        }else{
          //el.style.color="#000000";
          //el.style.background="#FFFFFF";
        }
      }
      function showCounty(){
        var hha = document.getElementById("hha");
        if(hha.checked==true){
          document.getElementById("county_span").style.visibility = "visible";
        }else{
          document.getElementById("county").value="";
          document.getElementById("county_span").style.visibility = "hidden";
        }
        isChecked("hha");
      }
       function isEmpty(inputStr){
        if ( null == inputStr || "" == inputStr )
          {
            return true;
          }else{
             return false;
          }
      }
      function isemailri(string) {
      if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
      else
        return false;
      }

    function isphoneri(phoneri){
      //Phone is an input element
      if ((phoneri.value==null)||(phoneri.value=="")){
        //alert("Please Enter your Phone Number")
        phoneri.focus();
        return false;
      }else{
        var output = phoneri.value.split("-");
        if(output.length != 3){
          return false;
        }
        for(x=0; x<output.length; x++){
          if(x==0 || x==1){//check areacode and prefix
            if(output[x].length != 3){
              return false;
            }
          }
          if(x==2){ //check exchange
            if(output[x].length != 4){
              return false;
            }
          }
          if(! isNumeric(output[x])){
            return false;
          }
        }
      }
      return true;
     }
     function isNumeric(sText){
       var ValidChars = "0123456789.";
       var IsNumber=true;
       var Char;
       for (i = 0; i < sText.length && IsNumber == true; i++)
          {
          Char = sText.charAt(i);
          if (ValidChars.indexOf(Char) == -1)
             {
             IsNumber = false;
             }
          }
       return IsNumber;
     }
