  


$().ready(function() {
    // validate the comment form when it is submitted
	
    $('#state').change(function(){
           
        if($('#country').val()=='US' && $('#state').val()==''){          
            $('#erState').show();
        }
        else{
            $('#erState').hide(); 
        }
    });
        
        
       
        
        
    jQuery.validator.addMethod("chkState", 
        function(value, element) {
            return ($("#state").val() != "")?true:true;
        }, 
        "Please select your state."
        );
        
     
       
        
    // validate signup form on keyup and submit
    $("#signupForm").validate({
            
        rules: {
            name: {
                required: true
            },
			                        			
            password: {
                required: true,
                minlength: 5
            },
            confirm_password: {
                required: true,
                minlength: 5,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true,
                remote : "rpc.php?action=sign_up&mode=check_email"
            },
            company_name:{
                required: true
            }
            ,
            company_web_site: 
            {
                required:true
                        
            },

            country:"required",
            state:{
                chkState:true 
            },
            sec_code:{
                required:true,
                remote : "rpc.php?action=sign_up&mode=sec_code_check"
            },
            agree: "required"
                        
        },
        messages: {
            name: {
                required :"Please enter your name"
            },
			
            password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            },
            confirm_password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long",
                equalTo: "Please enter the same password as above"
            },
            email:{ 
                required:"Please enter a valid e-mail address",
                remote:"E-mail address already exists."
                                            
                        
            },
            company_name:  "Please enter your company name",
            //                        company_role:  "Please select your company role",
            //                        company_web_site :"Please enter your company web site",
                        
            company_web_site: 
            {
                required:"Please enter your company web site"
                        
            },
            country:    "Please select your country",
                       
            sec_code:{
                required:"Please enter security code",
                remote:"Please enter characters you see in the above image"
            },
            agree: "To proceed with the purchase, Please accept the terms and conditions"
        }
        ,
        errorPlacement: function(error, element) {
                     
            error.appendTo( element.next() ).addClass('error');     

        },
    
        submitHandler:  function(form) {
            
      
            if($('#country').val()=='US' && $('#state').val()==''){
                               
                $('#erState').show(); 
                

            
            }else{
                
                
               var company_role_other = "";
                if($('#role_other').is(':visible')){
                    company_role_other = $.URLEncode($('#company_role_other').val());
                }
                
                         var state = "";
                if($('#listate').is(':visible')){
                    state = $('#state').val();
                }
                
				
			               
                jQuery.ajax({
                    type: 'POST',
                    url: 'rpc.php',
                    data: 'action=sign_up&mode=sign_up&name='+$.URLEncode($('#name').val())+'&country='+$('#country').val()+'&state='+state+
                    '&company_name='+$.URLEncode($('#company_name').val())+'&company_web_site='+$.URLEncode($('#company_web_site').val())+
                    '&company_role='+($('#company_role').val())+'&company_role_other='+company_role_other+'&email='+$.URLEncode($('#email').val())+'&password='+$.URLEncode($('#password').val())+'&user_cat_id='+$('#user_cat_id').val(),
                
                         
              
                    success: function(data){
                    
                
                  
                        if($.trim(data) == 'true'){
                       
                            document.location.href = 'checkout.html';
                       
                            //                       $('#sign_up_error').hide();
                            //                        $("#register_user_email").html($('#email').val());
                            //                        $('#sing_up_message_box').modal({
                            //                          containerCss: {
                            //                                width: 430,
                            //                                height: 480,
                            //                                margin:0
                            //                            }
                            //                        });
                            return false;
                        }else{
                            $('#sign_up_error').html(data);
                            $('#sign_up_error').show();
                        }
                    }
                });
            
            } //end if
                        
        }
    
    
    });
	
	
});


