/*
  -------------------------------------------------------------------------
required
req     The field should not be empty
maxlen=???
maxlength=???   checks the length entered data to the maximum. For example, if the maximum size permitted is 25, give the validation descriptor as "maxlen=25"
minlen=???
minlength=???   checks the length of the entered string to the required minimum. example "minlen=5"
alphanumeric /
alnum   Check the data if it contains any other characters other than alphabetic or numeric characters
num
numeric     Check numeric data
alpha
alphabetic  Check alphabetic data.
email   The field is an email field and verify the validity of the data.
lt=???
lessthan=???    Verify the data to be less than the value passed. Valid only for numeric fields.
example: if the value should be less than 1000 give validation description as "lt=1000"
gt=???
greaterthan=???     Verify the data to be greater than the value passed. Valid only for numeric fields.
example: if the value should be greater than 10 give validation description as "gt=10"
regexp=???  Check with a regular expression the value should match the regular expression.
example: "regexp=^[A-Za-z]{1,20}$" allow up to 20 alphabetic characters.
dontselect=??   This validation descriptor is valid only for select input items (lists) Normally, the select list boxes will have one item saying 'Select One' or some thing like that. The user should select an option other than this option. If the index of this option is 0, the validation description should be "dontselect=0"
    -------------------------------------------------------------------------
*/

var re_alphabetic = "[^A-Za-zá-úà-ùÁ-ÚÀ-Ùä-üÄ-Üâ-ûÂ-ÛçÇñÑ ]";
var re_numeric = "[^0-9]";
var re_alphanumeric = "[^A-Za-zá-úà-ùÁ-ÚÀ-Ùä-üÄ-Üâ-ûÂ-ÛçÇñÑ0-9 ]";
var re_alnumhyphen = "[^A-Za-zá-úà-ùÁ-ÚÀ-Ùä-üÄ-Üâ-ûÂ-ÛçÇñÑ0-9\-_]";

function isEmail(email)
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return(filter.test(email));
}

function validateEmailv2(email)
{
// a very simple email validation checking.
// you can add more complex email checking if it helps
//    if(email.length <= 0)
//    {
//      return true;
//    }
//    var splitted = email.match("^(.+)@(.+)$");
//    if(splitted == null) return false;
//    if(splitted[1] != null )
//    {
//      var regexp_user=/^\"?[\w-_\.]*\"?$/;
//      if(splitted[1].match(regexp_user) == null) return false;
//    }
//    if(splitted[2] != null)
//    {
//      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
//      if(splitted[2].match(regexp_domain) == null)
//      {
//        var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
//        if(splitted[2].match(regexp_ip) == null) return false;
//      }// if
//      return true;
//    }
//    return false;
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) return (true);
    else return (false);
}

function V2validateData(strValidateStr,objValue)
{
    var epos = strValidateStr.search("=");
    var  command  = "";
    var  cmdvalue = "";
    if(epos >= 0)
    {
     command  = strValidateStr.substring(0,epos);
     cmdvalue = strValidateStr.substr(epos+1);
    }
    else
    {
     command = strValidateStr;
    }
    switch(command)
    {
        case "req":
        case "required":
         {
           if(eval(objValue.value.length) == 0)
           {
              return false;
           }//if
           break;
         }//case required
        case "length":
        case "len":
          {
             if(eval(objValue.value.length) !=  eval(cmdvalue))
             {
               return false;
             }//if
             break;
          }//case length
        case "maxlength":
        case "maxlen":
          {
             if(eval(objValue.value.length) >  eval(cmdvalue))
             {
               return false;
             }//if
             break;
          }//case maxlen
        case "minlength":
        case "minlen":
           {
             if(eval(objValue.value.length) <  eval(cmdvalue))
             {
               return false;
             }//if
             break;
            }//case minlen
        case "alnum":
        case "alphanumeric":
           {
              var charpos = objValue.value.search(re_alphanum);
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                return false;
              }//if
              break;
           }//case alphanumeric
        case "num":
        case "numeric":
           {
              var charpos = objValue.value.search(re_numeric);
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                return false;
              }//if
              break;
           }//numeric
        case "alphabetic":
        case "alpha":
           {
              var charpos = objValue.value.search(re_alphabetic);
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                return false;
              }//if
              break;
           }//alpha
        case "alnumhyphen":
            {
              var charpos = objValue.value.search(re_alnumhyphen);
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                return false;
              }//if
            break;
            }
        case "email":
          {
               if(!validateEmailv2(objValue.value))
               {
                 return false;
               }//if
           break;
          }//case email
        case "lt":
        case "lessthan":
         {
            if(isNaN(objValue.value))
            {
              return false;
            }//if
            if(eval(objValue.value) >=  eval(cmdvalue))
            {
              return false;
             }//if
            break;
         }//case lessthan
        case "gt":
        case "greaterthan":
         {
            if(isNaN(objValue.value))
            {
              return false;
            }//if
             if(eval(objValue.value) <=  eval(cmdvalue))
             {
               return false;
             }//if
            break;
         }//case greaterthan
        case "regexp":
         {
            if(objValue.value.length > 0)
            {
                if(!objValue.value.match(cmdvalue))
                {
                  return false;
                }//if
            }
           break;
         }//case regexp
        case "dontselect":
         {
            if(objValue.selectedIndex == null)
            {
              alert("BUG: dontselect command for non-select Item");
              return false;
            }
            if(objValue.selectedIndex == eval(cmdvalue))
            {
              return false;
             }
             break;
         }//case dontselect
    }//switch
    return true;
}
/*
    Copyright 2003 JavaScript-coder.com. All rights reserved.
*/