AccountHistory = {
    
    Initialize : function()
    {
        if($(".firstStepCenter").length == 0)
        {
            $(".billingInfo .button").bind("click", function(event) {
                event.preventDefault();
                var inputElement = $("#"+$(event.target).attr("id").replace("Modify", ""));
                var buttonElement = $(event.target);
                switch($(event.target).val())
                {
                    case "Módosítom":
                        inputElement.attr("disabled", "");
                        inputElement.focus();
                        buttonElement.val("Mentem");
                        break;
                    
                    case "Mentem":
                        if(inputElement.val() == null || inputElement.val() == "" ||inputElement.val().lenght < 3) {
                            alert("A megadott adat nem érvényes.");
                        }
                        else{
                            buttonElement.val("Módosítom");
                            inputElement.attr("disabled", "disabled");
                            
                            $.ajax({
                                type: "POST",
                                url: "Components/AccountHistory/AccountHistoryActionHandler.php",
                                data: "action=Save" + inputElement.attr("id") + "&billingValue=" + encodeURIComponent(inputElement.val()),
                                dataType: "json",
                                success: function(response) { }
                            });
                        }
                        break;
                }
            });
        }
        else
        {
            $("#SaveBillinginfoButton").bind("click", function(event) {
                event.preventDefault();
                var pars = "&name=" + encodeURIComponent($("#BillingName").val());
                    pars += "&zip=" + encodeURIComponent($("#BillingZip").val());
                    pars += "&city=" + encodeURIComponent($("#BillingCity").val());
                    pars += "&address=" + encodeURIComponent($("#BillingAddress").val());
                    pars += "&phone=" + encodeURIComponent($("#BillingPhone").val());
                    
                $.ajax({
                    type: "POST",
                    url: "Components/AccountHistory/AccountHistoryActionHandler.php",
                    data: "action=Save" + pars,
                    dataType: "json",
                    success: function(response) { window.location = window.location; }
                });
            });
            
        }
    }
    
};

