﻿ function ShowOthertxt(whereuhear,txtOther)
 {

 if(whereuhear.value=='7')
 {
 txtOther.disabled='';
 }
 else
 {
  txtOther.disabled='disabled';
 }
  }
  
   function isEmpty(mytext) 
    {
        var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc. 
        if ((mytext.value.length==0) || (mytext.value==null) || ((mytext.value.search(re)) > -1)) 
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    
  function validate(fname,fnameError,lname,lnameError,company,
                        companyError,address1,addressError,city,cityError,state,stateError,
                        zipcode,zipcodeError,email,emailError,emailformatError,
                        password,passwordError,confirmpassword,confirmpasswordError,passwordmatchError,
                        usertype,errusertype,whereuhear,txtOther,errwhereuhear,phone,errPhone,divError,errzip,errpasslength)
                {
                        
                        var error,flag=false;
                        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                        var regphone=/^[2-9]\d{2}-\d{3}-\d{4}$/;
                        var regpassword=/^[A-Za-z\d\W_]{6,20}$/;
                        var regzip =/^\s*\d+\s*$/;
                        error= "<ul>";     
                        if(usertype.value=='--- Select ---')
                            {
                                error=error+'<li>'+errusertype +'</li>';
                                if(flag==false)
                                usertype.focus();
                                flag =true;
                                
                            }
                                           
                        if(fname.value=="" || fname.value==null || isEmpty(fname))
                            {
                                error=error+'<li>'+fnameError +'</li>';
                                if(flag==false)
                                fname.focus();
                                flag =true;
                            }
                        if(lname.value=="" || lname.value==null || isEmpty(lname))
                            {
                                error=error+'<li>'+lnameError+'</li>';
                                if(flag==false)
                                lname.focus();
                                flag =true;                                
                            }
                        if(company.value=="" || company.value==null || isEmpty(company))
                            {
                                error=error+'<li>'+companyError+'</li>';
                                if(flag==false)
                                company.focus();
                                flag =true;                                
                            }
                        if(address1.value=="" || address1.value==null || isEmpty(address1))
                            {
                                error=error+'<li>'+addressError+'</li>';
                                if(flag==false)
                                address1.focus();
                                flag =true;
                            }
                        if(city.value=="" || city.value==null || isEmpty(city))
                            {
                                error=error+'<li>'+cityError+'</li>';
                                if(flag==false)
                                city.focus();
                                flag =true;
                            }
                        if(state.value =="" || state.value==null || isEmpty(state))
                            {
                                error=error+'<li>'+stateError+'</li>';
                                if(flag==false)
                                state.focus();
                                flag =true;
                            }
                        if(zipcode.value =="" || zipcode.value==null || isEmpty(zipcode))
                            {
                                error=error+'<li>'+zipcodeError+'</li>';
                                if(flag==false)
                                zipcode.focus();
                                flag =true;
                            }
                       else if (zipcode.value.search(regzip)==-1)
                          {
                                error=error+'<li>'+errzip+'</li>';
                                if(flag==false)
                                zipcode.focus();
                                flag =true;
                          }
                            if(phone.value !=""  && regphone.test(phone.value)==false)
                            {
                                error=error+'<li>'+errPhone+'</li>';
                                if(flag==false)
                                phone.focus();
                                flag =true;
                            }
                        if(email.value =="" || email.value==null || isEmpty(email))
                            {
                                error=error+'<li>'+emailError+'</li>';
                                if(flag==false)
                                email.focus();
                                flag =true;
                            }                        
                        else if(reg.test(email.value)==false)
                            {
                                error=error+'<li>'+emailformatError+'</li>';
                                if(flag==false)
                                email.focus();
                                flag =true;
                            }
                        if(password.value =="" || password.value==null || isEmpty(password))
                            {
                                error=error+'<li>'+passwordError+'</li>';
                                if(flag==false)
                                password.focus();
                                flag =true;
                            }
                        else if(regpassword.test(password.value)==false)
                        {
                                error=error+'<li>'+errpasslength+'</li>';
                                if(flag==false)
                                password.focus();
                                flag =true;
                        }
                        if(confirmpassword.value =="" || confirmpassword.value==null || isEmpty(confirmpassword))
                            {
                                error=error+'<li>'+confirmpasswordError+'</li>';
                                if(flag==false)
                                confirmpassword.focus();
                                flag=true;
                            }
                        if(confirmpassword.value !=password.value)
                            {
                                error=error+'<li>'+passwordmatchError+'</li>';
                                if(flag==false)
                                confirmpassword.focus();
                                flag=true;
                            }
                        if(whereuhear.value =='--- Select ---' || (whereuhear.value =='7' && (txtOther.value=="" || txtOther.value==null || isEmpty(txtOther))))
                            {
                                error=error+'<li>'+errwhereuhear+'</li>';
                                if(flag==false)
                                whereuhear.focus();
                                flag=true;
                            }
                        error =error +"</ul>";
                        if(flag==true)
                            {
                                divError.innerHTML = error;
                                return false;
                            }
                            return true;
                }
                        
  
