﻿///<summary>
///This library will consist of various functions that will deal with form validation
///these functions will include key trapping, number / email validation
///as well as other useful functions
///</summary>


///<summary>
///to see if the phone value of the textfield is a valid format
///</summary>       
function isGoodPhone(args)
{
    var numericExpression1 = /^[0-9{\d-}{\d.}{\d(}{\d)} ]+$/;

     if(!args.value.match(numericExpression1) && args.value !== '')
     {
          alert('Incorrect Phone Number Format');
          setValue(args);
          args.focus();
     }
     return true;
}

 function isAlphaNumeric(args,valClientID)
      {
          var numericExpression1 = /^[0-9A-Za-z{\d-} ]+$/;

         if(!args.value.match(numericExpression1) && args.value !== '')
         {
              alert('Incorrect VIN / HIN Format \n Only letters, numbers and dashes are allowed');
              args.value = "";
              document.getElementById(valClientID).style.display = "block";
              document.getElementById(valClientID).innerText = "Please enter your VIN / HIN number";
              args.focus();
         }
          return;
      }

      
///<summary>
///Check if the value of the passed textField contains non-numbers
///</summary>       
function numberTest(args,msg)
{

    var numericExpression = /^[0-9]+$/;

     if(!args.value.match(numericExpression) || args.value == '')
     {
        if(msg != null)
        {
            window.alert(msg);
        }
        return false;
     }
     return true;

}
  
  
///<summary>
///This will remove the google stylesheet crap of yellowing the input fields
///</summary>     
function removeGoogleAutoFormat()
{
  if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }//-->

  }   

///<summary>
///Something to do if its firefox
///useful when doing stylesheet shifting etc...
///</summary>  
function browserCheck()
{
if(navigator.userAgent.indexOf("Firefox")!=-1)
{
    var versionindex=navigator.userAgent.indexOf("Firefox")+8
    }
    if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
    {
        //firefox specific code here
    }
}
  
  
///<summary>
///check to see if the passsed string is valid e-mail or not
///</summary>  
///<param value="str">string to check if valid e-mail</param>
function isValidEmail(str) 
{
return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
  
     