<!-- hide JS code
//This file local.js 
//The file contains functions for patient registration input validation
//Writtten by WT 
//April 2007


function validInput(myform)  // validate user input
{
         var form_name=myform.name; 
         if (isBlank(myform.realname.value))    // first name valid?
          {
            alert("Please enter your name:");
            myform.realname.focus();
            return false;
          }

         if (isBlank(myform.address.value))    // address valid?
          {
            alert("Please enter your address:");
            myform.address.focus();
            return false;
          }

         if (isBlank(myform.city.value))    // city valid?
          {
            alert("Please enter city:");
            myform.city.focus();
            return false;
          }
         if (isBlank(myform.state.value))    // state valid?
          {
            alert("Please enter state:");
            myform.state.focus();
            return false;
          }

         if (isBlank(myform.zip.value))    // zip valid?
          {
            alert("Please enter zip code:");
            myform.zip.focus();
            return false;
          }

         if (isBlank(myform.home_phone.value) || !isPhone(myform.home_phone.value))
          {
             alert("Please enter phone number in the format of 123-456-7890:");
             myform.home_phone.focus();
             return false;
          }
         if (!isBlank(myform.cell_phone.value))
          {
            if (!isPhone(myform.cell_phone.value))  // phone format?
            {
               alert("Please enter cell phone number in the format of 123-456-7890:");
               myform.cell_phone.focus();
               return false;
            }
          } 

        if (!validateEMail(myform.email.value)){
          myform.email.focus();
          return false; 
        }  
         var rgroup=myform.dates;
         var msg="Please choose the date you would like to attend:";  
         if (!validRadio(rgroup,msg))
           {
             rgroup[0].focus(); 
             return false;
           }       

        return true;
}//end of input vlidation

function validAsk(myform)  // validate user input
{
         var form_name=myform.name; 
         if (isBlank(myform.realname.value))    // first name valid?
          {
            alert("Please enter your name:");
            myform.realname.focus();
            return false;
          }

         var rgroup=myform.Status;
         var msg="Please check your status:";  
         if (!validRadio(rgroup,msg))
           {
             rgroup[0].focus(); 
             return false;
           }       

         if (myform.Status[5].checked==true){
            if (isBlank(myform.Other_Lic_Type.value) && isBlank(myform.Other_Type.value)){
              alert("You checked Other, please specify your status:");
              myform.Other_Lic_Type.focus(); 
              return false;
            }
         }
         if (isBlank(myform.Unit_Specialty.value))    // first name valid?
          {
            alert("Please enter Unit/Specialty:");
            myform.Unit_Specialty.focus();
            return false;
          }

          if (!validateEMail(myform.email.value)){
             myform.email.focus();
             return false; 
          }  

        return true;
}//end of input validation




function validateText(text,msg) // valid the Text field
  {
  if (isBlank(text))               // text field blank?
    {
    alert(msg);
    return false
    }
  return true
  }

function isBlank(testStr) // check if a field is blank
{
  
  if (testStr.length == 0)                     // nothing entered?
    return true
  for (var i = 0; i <= testStr.length-1; i++)  // all spaces?
    if (testStr.charAt(i) != " ")
      return false
  return true 
}

function isDate(myDate) // check if a field is blank
{
  
  if (!myDate.match(/\d{2}\/\d{2}\/\d{4}/))                     // mm/dd/yyyy
  {
     return false;
  }else{
     return true;
  } 
}

function isPhone(phone) // check if a field is blank
{
  
  if (!phone.match(/\d{3}-\d{3}-\d{4}/))                     // 123-456-7890
  {
     return false;
  }else{
     return true;
  } 
}


function validRadio(radiogroup,msg)
{
    var itemchecked=false;
    for (var j=0; j<radiogroup.length; j++){
            if (radiogroup[j].checked){
                itemchecked=true;
                break
            }
     }
     if(!itemchecked) { // if nothing is checked for Seen radio button
//      alert("Please choose an answer for "+el[i].name+".");
        alert(msg)   
        return false;
     }
     return true;
}


function validateEMail(email) // Check if email is valid, not use here
  {
  if (isBlank(email))                       // email blank?
    {
    alert("Please enter your valid email address. A vaild email address should be in the format of emailname@somewhere.com")
    return false
    }
  var atsignPos = email.indexOf("@", 0)     // check for @
  if (atsignPos == -1)  
    {
    alert("Please Eenter a valid email address in the format of emailname@somewhere.com:")
    return false
    }
  if (email.indexOf(".", atsignPos) == -1)  // check for . after @      
    {
    alert("Please enter a valid email domain after @:")
    return false
    }
  return true
  }


function validateSelect(item,msg) //check if a selection is valid, working properly
{
     if (item.selectedIndex==0) //check if only the first item on the list is selected which starts with "Select..."
          {
             alert(msg); 
             item.focus();
             return false; 
          }
     return true;   
}   


// end JS hide -->