// ------------------------------------------------ //
// -----------Validation.js v2.0----------------//
// --------written by brent.knop-------------//
// ----------------------------------------------- //

function Validate(f)
{
  var e = "";
  for(i=0;i<f.length;i++)
  {
    if (f[i].type == "text" || f[i].type == "select-one")
    {
      if(f[i].className.match(/Required/g))
      {    
          if(f[i].name.match(/email/))
          {
            var RegEx = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            if(!RegEx.test(f[i].value)) {
              e += "Null or invalid entry for email address.\n";
              f[i].className += " ErrorClass";
            }
          }
          else if(f[i].name.match(/phone/))
          {
            if(!f[i].value.match(/\(\d{3}\)\s\d{3}-\d{4}/))
            {
              e += "Invalid entry for phone number.  Hint : \(123\) 456-7891.\n";
              f[i].value = "(xxx) xxx-xxxx";
              f[i].className += " ErrorClass";
            }
          }
          else if(f[i].name.match(/date/))
          {
              if(!f[i].value.match(/\d{1,2}\/\d{1,2}\/\d{4}/))
              {
                e += "Invalid entry for \"" + f[i].name + "\".  Hint : MM/DD/YYYY\n";
                f[i].value = "MM/DD/YYYY";
                f[i].className += " ErrorClass";
              }
          }
          else
          {
            if(f[i].value == "" || f[i].value == "default")
            {
              e += "Please fill out the required field \"" + f[i].name + "\".\n";
              f[i].className += " ErrorClass";
            } 
          }
        }      
      } 
      else if (f[i].type == "checkbox" && f[i].className.match(/Required/g))
      {
        if (!f[i].checked == true)
        {
          e += "Please make a selection for \"" + f[i].name + "\".\n";    
        }
      }  
    }
  
  if(e.length > 0)
  {
    alert(e);
    return false;
  }
  else
  {          
    return true;
  }
}

function FormatPhone(f) {
  var FormattedPhone = f.value.replace(/\D/ig, ""); 
  if(!FormattedPhone.match(/\d{10,10}/)) {
    f.value = "(xxx) xxx-xxxx";
    f.className += " ErrorClass";
    return;
  }      
  f.value =  "(" + FormattedPhone.substring(0,3) + ") " + FormattedPhone.substring(3,6) + "-" + FormattedPhone.substring(6,10);
}

function FormatDate(f) {
  var tmp = f.value.split(/\D/);
  if(tmp.length<3 || tmp[0].length > 2 || tmp[1].length > 2 || tmp[2].length > 4) {
    f.value = "MM/DD/YYYY";
    f.className += " ErrorClass";
    return;            
  }
  f.value = tmp[0] + "/" + tmp[1] + "/" + tmp[2];
}


// This is to prevent the radio buttons on the PGIP page from overlapping. 
// Written by Barry Chapman 08.12.08

function clearButtons(buttonGroup){ 
   for (i=0; i < buttonGroup.length; i++) { 
    if (buttonGroup[i].checked == true) { 
    buttonGroup[i].checked = false 
	}
   }
}

















