jQuery(function ($) {
   
      
    $("#logout_preview").click(function () {
       
       
       $.ajax({
            type: "GET",
            url: 'rpc.php',
            data: "action=profile&mode=logout",
            success: function(data){
                redirecting();
            }
        });

        function redirecting() {
         document.location.href = 'home.html';
        }
       

    });

    $("#form_login_preview").validate({
        errorElement:"em",
        rules:{
            login_email: {
                required : true,
                email : true
            },
            login_password:{
                required : true
            },
            chk_agree:{
                required:true
            }
        },
           
       
      
        messages: {
            login_email : {
                required : "Enter e-mail",
                email : "Enter Valid e-mail"
            },
            login_password:{
                required : "Enter Password"
            },
            chk_agree:{
                required:'Please accept the Terms and Conditions'
            }
        },
        errorPlacement: function(error, element) {
            if ( element.is(":checkbox") ){
                error.appendTo('#errord');
            }else{
                error.appendTo( element.next('span') ).addClass('error');
            }
        },
        submitHandler: function(form) {
            $.ajax({
                type: 'POST',
                url: 'rpc.php',
                dataType: 'json',
                data: 'action=sign_up&mode=preview_login&email='+$.URLEncode($('#login_email').val())+'&password='+$.URLEncode($('#login_password').val()),
                success: function(data){
                    if($.trim(data.msg) == 'true'){
                        $.blockUI({
                            message: '<h1>Please Wait...</h1>'
                            
                        });
                        
                        document.location.href = data.redirect_url;
                    }else{
                        $('#login_error').html(data.msg);
                        $('#login_error').show();
                    }
                }
            })

            function redirecting() {
                document.location.href = 'index.php?action=profile_update';
            }


        }

    });

});
