/*
  -------------------------------------------------------------------------
                    JavaScript Form Validator 
                                Version 2.0.2
Copyright 2003 JavaScript-coder.com. All rights reserved.
You use this script in your Web pages, provided these opening credit
    lines are kept intact.
The Form validation script is distributed free from JavaScript-Coder.com

You may please add a link to JavaScript-Coder.com, 
making it easy for others to find this script.
Checkout the Give a link and Get a link page:
http://www.javascript-coder.com/links/how-to-link.php

    You may not reprint or redistribute this code without permission from 
    JavaScript-Coder.com.

JavaScript Coder
It precisely codes what you imagine!
Grab your copy here:
http://www.javascript-coder.com/
    -------------------------------------------------------------------------  
*/
function Validator(frmname)
{
  this.formobj=document.forms[frmname];
if(!this.formobj)
{
  alert("BUG: couldnot get Form object "+frmname);
return;
}
if(this.formobj.onsubmit)
{
 this.formobj.old_onsubmit = this.formobj.onsubmit;
 this.formobj.onsubmit=null;
}
else
{
 this.formobj.old_onsubmit = null;
}
this.formobj.onsubmit=form_submit_handler;
this.addValidation = add_validation;
this.setAddnlValidationFunction=set_addnl_vfunction;
this.clearAllValidations = clear_all_validations;
}

function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
for(var itr=0;itr < this.formobj.elements.length;itr++)
{
this.formobj.elements[itr].validationset = null;
}
}
function form_submit_handler()
{
for(var itr=0;itr < this.elements.length;itr++)
{
if(this.elements[itr].validationset &&
   !this.elements[itr].validationset.validate())
{
  return false;
}
}
if(this.addnlvalidation)
{
  str =" var ret = "+this.addnlvalidation+"()";
  eval(str);
    if(!ret) return ret;
}
return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
{
  alert("BUG: the form object is not set properly");
return;
}//if
var itemobj = this.formobj[itemname];
if(!itemobj)
{
  alert("BUG: Couldnot get the input object named: "+itemname);
return;
}
if(!itemobj.validationset)
{
  itemobj.validationset = new ValidationSet(itemobj);
}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
this.error=error;
this.itemobj = inputitem;
this.validate=vdesc_validate;
}
function vdesc_validate()
{
var status = V2validateData(this.desc,this.itemobj,this.error);

if(!status)
 {
    this.itemobj.focus();
    return false;
 }
 else
 {
     return true;
 }
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
this.add= add_validationdesc;
this.validate= vset_validate;
this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
{
   if(!this.vSet[itr].validate())
 {
   return false;
 }
 }
 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
var checkDomain=email.indexOf('yahoo.') + email.indexOf('gmail.') + email.indexOf('aol.') + email.indexOf('msn.') + email.indexOf('hotmail.') + email.indexOf('earthlink.') + email.indexOf('rediffmail.') + email.indexOf('abc.') + email.indexOf('xyz.') + email.indexOf('mail.') + email.indexOf('aim.') + email.indexOf('gmx.') + email.indexOf('inbox.') + email.indexOf('bluebottle.') + email.indexOf('bluestring.') + email.indexOf('zapak.') + email.indexOf('mywaymail.') + email.indexOf('hotpop.') + email.indexOf('lavabit.') + email.indexOf('topmail.') + email.indexOf('yousendit.') + email.indexOf('mail2web.') + email.indexOf('netaddress.') + email.indexOf('lycos.') + email.indexOf('postmaster.') + email.indexOf('zzn.') + email.indexOf('walla.') + email.indexOf(' fastmail.') + email.indexOf('thatweb.') + email.indexOf('mailinator.') + email.indexOf('30gigs.') + email.indexOf('e-mailanywhere.') + email.indexOf('xasamail.') + email.indexOf('excitemail.') + email.indexOf('myrealbox.') + email.indexOf('flashmail.') + email.indexOf('nameplanet.') + email.indexOf('dodgeit.') + email.indexOf('hushmail.') + email.indexOf('mailandnews.') + email.indexOf('caramail.lycos.fr') + email.indexOf('icqmail.') + email.indexOf('thedoghousemail.') + email.indexOf('webmail.earthlink.net') + email.indexOf('eo.yifan.net') + email.indexOf('prontomail.') + email.indexOf('gurlmail.') + email.indexOf('wowmail.') + email.indexOf('indiatimes.') + email.indexOf('sbc.') + email.indexOf('MailStreet.') + email.indexOf('entergroup.') + email.indexOf('Address.') + email.indexOf('AlloyMail.') + email.indexOf('AltaVista.') + email.indexOf('AnimeNation.') + email.indexOf('Asheville.') + email.indexOf('AsianWired.') + email.indexOf('BBoy.') + email.indexOf('BlazeMail.') + email.indexOf('BoarderMail.') + email.indexOf('BoarderZone.') + email.indexOf('Bolt.') + email.indexOf('Budweiser.') + email.indexOf('Canada.') + email.indexOf('Casino.') + email.indexOf('ClassifiedToday.') + email.indexOf('DarkHorseFan.') + email.indexOf('Juno.') + email.indexOf('ListrakInc.') + email.indexOf('MailBoy2004.') + email.indexOf('MassMailer.') + email.indexOf('Northstar.') + email.indexOf('comcast.') + email.indexOf('verizon.') + email.indexOf('frontiernet.') + email.indexOf('optonline.');

if(checkDomain != -77)
{
alert("You have entered an email account from a free email service or one of the high-volume consumer service providers (i.e. AOL, gmail, Yahoo, MSN, Hotmail, Earthlink, SBC, etc). In an effort to provide you with the best possible access to our products, we require that you enter your corporate email address. Please update your email account below and press the submit button. ");
return false;
}


    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;
}
function V2validateData(strValidateStr,objValue,strError) 
{ 

    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) && !((document.getElementById("noEmailVal").value == "yes") &&(objValue.name == "EmailAddress")))
           { 
   alert(strError);
   return false; 
           }//if 
    if(eval(objValue.value.length) == 1)
   {
  alert(strError+" Correctly");
  return false;
   }
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) < eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
{ 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 

case "nonComp": 
           { 
      
             if(!CompCheck(objValue)) 
             {                              
               alert(strError); 
               return false;                 
             }//if 
             break; 
            }//case nonComp 

        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
   
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9x-]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
{ 
  strError = objValue.name+": Only digits allowed "; 
}//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }  
              break;               
           }//numeric
   
case "alphaSpace": 
           { 
   var name= objValue.value;
   var charpos = objValue.value.search("[^A-Za-z ]"); 
var countSpace=0;
if(name.length > 0 && charpos >= 0)
{
alert(strError);
return false;
}
else
{
for(i=0;i<name.length;i++)
{
if(name[i]==" ")
{
countSpace++;
if((i==0)||(i==name.length-1))
{
alert(strError);
return false;
}
}
}
if(countSpace>1)
{
alert(strError);
return false;
} 

}    
    
              break; 
           }//alphaSpace
   
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              {                   
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//alpha 
case "alnumhyphen":
{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if  
break;
}
        case "email": 
          {
   if(document.getElementById("noEmailVal").value == "no")
       {
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
   }
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
{ 
               if(!strError || strError.length ==0) 
{ 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        
case "regexp": 
         { 
    if(objValue.value.length > 0)
{
if(!objValue.value.match(cmdvalue)) 
{                                                                    
alert(strError); 
return false;                   
}
if(!phoneNumberCheck(objValue))
{
alert(strError); 
return false;
}
}
break; 
         }//case regexp   


        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
    }//switch 
    return true; 
}

function CompCheck(obj)
{
var nonCompValues = new Array("null","none","na","n/a","n\a");
var email = obj.value;
email = trimSpace(email);
email = email.toLowerCase();
var i;
for(i=0; i<nonCompValues.length; i++)
{
if(email == nonCompValues[i])
{
return false;
}
}
return true;
}


function trimSpace(x)
{

  var emptySpace = / /g;
  var trimAfter = x.replace(emptySpace,"");
return(trimAfter);

}


function phoneNumberCheck(objValue)
{
var charpos = objValue.value.search("[^0-9x-]"); 
if(charpos >= 0) 
      {                  
        return false; 
      } 
  
   else if((objValue.value.length >17)||(objValue.value.length <10))
    {
    return false; 
     }
else 
     {
   if(objValue.value.length >10)
   {
   var countDash=0;
   var countX=0;
   var posDash=0;
      var i;
   var b=objValue.value.indexOf('x');
   for(i=0; i<objValue.value.length;i++)
   {
   if(objValue.value.charAt(i)=='-')
{
countDash++; 
if(i!=3)
{
if(i!=7)
{
return false;
}
else if((posDash!=3)&&(i==7))
{
return false;
}
else if((posDash==3)&&(i==7)&&(b<12)&&(b!=-1))
{
   return false;
                     } 
  else if((posDash==3)&&(i==7)&&(objValue.value.length<12))
{
    return false;
  }
  else if((posDash==3)&&(i==7)&&(objValue.value.length>=13)&&(b!=12))
    {
  return false;
  }

 }

 else
     {
        posDash=3;
     }
   }

   if(objValue.value.charAt(i)=='x')
   {
countX++;  
      }
   }//end of 'for' loop

   if((countDash==0)&&(countX==0))
    {
   return false;
    }

    else if((countDash>2)||(countX>1))
    {
      return false;
   }

    else if(((countDash==0)||(countDash==1))&&(b==12))
        {
            return false;
   }   
  
    else if(b==(objValue.value.length-1))   
   {
  return false;  
   }

    else if((b!=-1)&&(b<10))
   {
   return false;
   }

    else if((b!=-1)&&(objValue.value.length-b)>5)
      {
  return false;
  }
 
  if(((objValue.value.indexOf("0000000000"))!=-1)||((objValue.value.indexOf("1111111111"))!=-1)||((objValue.value.indexOf("2222222222"))!=-1)||((objValue.value.indexOf("3333333333"))!=-1)||((objValue.value.indexOf("4444444444"))!=-1)||((objValue.value.indexOf("5555555555"))!=-1)||((objValue.value.indexOf("6666666666"))!=-1)||((objValue.value.indexOf("7777777777"))!=-1)||((objValue.value.indexOf("8888888888"))!=-1)||((objValue.value.indexOf("9999999999"))!=-1)||((objValue.value.indexOf("000-000-0000"))!=-1)||((objValue.value.indexOf("111-111-1111"))!=-1)||((objValue.value.indexOf("222-222-2222"))!=-1)||((objValue.value.indexOf("333-333-3333"))!=-1)||((objValue.value.indexOf("444-444-4444"))!=-1)||((objValue.value.indexOf("555-555-5555"))!=-1)||((objValue.value.indexOf("666-666-6666"))!=-1)||((objValue.value.indexOf("777-777-7777"))!=-1)||((objValue.value.indexOf("888-888-8888"))!=-1)||((objValue.value.indexOf("999-999-9999"))!=-1))
  {  
return false;   
  } 
  
           }
  
      if(objValue.value.length==10)
      {
    var m=objValue.value.indexOf('x');   
    var n=objValue.value.indexOf('-');   
   if((m>=0)||(n>=0))
      {
  return false;
  }

    if(((objValue.value.indexOf("0000000000"))!=-1)||((objValue.value.indexOf("1111111111"))!=-1)||((objValue.value.indexOf("2222222222"))!=-1)||((objValue.value.indexOf("3333333333"))!=-1)||((objValue.value.indexOf("4444444444"))!=-1)||((objValue.value.indexOf("5555555555"))!=-1)||((objValue.value.indexOf("6666666666"))!=-1)||((objValue.value.indexOf("7777777777"))!=-1)||((objValue.value.indexOf("8888888888"))!=-1)||((objValue.value.indexOf("9999999999"))!=-1))
  { 
return false;  
  } 
 
  } //end of if(objValue.value.length==10) 
  
  var newregExp = /^[\d]*[\d](0{9})|[\d]*[\d](0{2})-(0{3})-(0{4})$/
  var checkPhone = objValue.value.search(newregExp);
  if(checkPhone >= 0)
{
   return false;
}

      }//end of else
 
  return true;  
}





/*
Copyright 2003 JavaScript-coder.com. All rights reserved.
*/