$(document).ready(function() {
    $("#pb_buy").click(function() {
        $("#dialog_box").dialog("open").dialog({
            "width": 450,
            "height": 230,
            "title": "Sign Up",
            "modal": true
        });
        
        return false;
    });
    
    $("#cansel_link").click(function() {
        $("#dialog_box").dialog("close");
        
        return false;
    });
    
    $("#ok_link").click(function() {
        var email=$("#email").val();
        
        if(email!='') {
            $("#loader").show();
            
            JsHttpRequest.query(
                '/script/ajax.php',
                {
                    "email": email,
                    "action": 'newsletter'
                },
                function(result, errors) {
                    $("#debug").html(errors);
                    $("#loader").hide();
                    if (result) {
                        if(!result["err"]) {
                            $("#error").html("");
                            $("#dialog_box").dialog("close");
                            $("#ok_box").dialog("open").dialog({
                                "width": 300,
                                "height": 100,
                                "title": "Thank you for signing up!",
                                "modal": true
                            });
                        } else {
                            $("#error").html(result["err"]);
                        }
                    }
                },
                true
            );
        }
        
        return false;
    });
});
