﻿     function show_other_details(){
       var company = document.getElementById("company");
       var other_details = document.getElementById("other_detail_div");
       var sel = company.options[company.selectedIndex].value;
       if (sel=='Other'){
         other_details.style.display="inline";
       }else{
         other_details.style.display="none";
       }
     }
      function validateFormfs(){
         //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_company_namefs_error = document.getElementById("company_namefs_error");
       var err_phonefs_error = document.getElementById("phonefs_error");
        var err_email_error = document.getElementById("email_error");
        var email_phonefs = document.getElementById("email_and_phonefs");
        var other_details_div = document.getElementById("other_detail_div");
        var other_details_error = document.getElementById("other_details_error");
       if(other_details_div.style.display != "none"){
          
          if(isEmpty(document.flu_shot_form.other_detail.value)){
          goAhead=false;
          other_details_error.style.visibility="visible";
          document.flu_shot_form.other_details.setFocus();
          return;
         }else{
           other_details_error.style.visibility="hidden";
         }
        }
        if(isEmpty(document.flu_shot_form.my_namefs.value)){
          goAhead=false;
          err_name_error.style.visibility="visible";
          document.flu_shot_form.my_namefs.setFocus();
          return;
         }else{
           err_name_error.style.visibility="hidden";
         }
         if(isEmpty(document.flu_shot_form.company_namefs.value)){
          goAhead=false;
          err_company_namefs_error.style.visibility="visible";
          document.flu_shot_form.company_namefs.setFocus();
          return;
         }else{
           err_company_namefs_error.style.visibility="hidden";
         }
        if(isEmpty(document.flu_shot_form.phonefs) && isEmpty(document.flu_shot_form.email)){
          goAhead=false;
          email_phonefs.style.visibility="visible";
        }else{
          email_phonefs.style.visibility="hidden";
          if(!isphonefs(document.flu_shot_form.phonefs)){
            goAhead=false;
            err_phonefs_error.style.visibility="visible";
            document.flu_shot_form.phonefs.setFocus();
          }else{
            err_phonefs_error.style.visibility="hidden";
          }
          if(!isEmail(document.flu_shot_form.email.value)){
            goAhead=false;
            err_email_error.style.visibility="visible";
          }else{
            err_email_error.style.visibility="hidden";
          }
        }
        if(goAhead){
          document.flu_shot_form.submit();
        }
      }

       function isEmpty(inputStr){
        if ( null == inputStr || "" == inputStr )
          {
            return true;
          }else{
             return false;
          }
      }
      function isEmail(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 isphonefs(phonefs){
      //phonefs is an input element
      if ((phonefs.value==null)||(phonefs.value=="")){
        //alert("Please Enter your phonefs Number")
        phonefs.focus();
        return false;
      }else{
        var output = phonefs.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;
     }
