$(document).ready(function() {
    $("#PreviousOrderLink").click(function() {
        var url = "Ajax.aspx?CN=8662B6F080B5&EN=37F76E2E4DE3&TYPE=POST";
        $.ajax({
            type: "POST",
            url: url,
            cache: false,
            success: function(msg) {
                $("#PreviousOrderDetails").html("");
                $("#PreviousOrderDetails").append(msg);
            }
        });
    });

    $("#AccountInformationLink").click(function() {
        var url = "Ajax.aspx?CN=188CD230D6FB&EN=2130560020B5&TYPE=POST";
        $.ajax({
            type: "POST",
            url: url,
            cache: false,
            success: function(msg) {
                $("#AccountInformationDetails").html("");
                $("#AccountInformationDetails").append(msg);
            }
        });
    });
    
    $(".removeElement").click(function(){
        PostRemoveItem($(this).val());        
    });
    
    
    function PostRemoveItem(element) {
        var url = "Ajax.aspx?CN=8715082B6D9F&EN=A144507A5A29&TYPE=POST";
        var data = getFormDataFromListElement('List_' + element);
        alert(data);
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            success: function(msg) {
                $('#List_' + element).remove();
                $('#CurrentOrderItem_' + element).remove();
            }
        });
    }
    
    function getFormDataFromListElement(elementName) {
        //Add a new form to the DOM and hide it
        $('body').append('<form id="tempForm" style="visibility:hidden;"></form>');

        //Clone the element into the new form.
        $('#tempForm').html($('#' + elementName).clone());

        //Serialize the form data
        var data = $('#tempForm').serialize();

        //Remove the form from the DOM
        $('#tempForm').remove();

        return data;

    }
    
});


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// JAVASCRIPT 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//function RemoveLineItemFromOrder(lineNumber) {
//    //List_A0FBBD829729
//    alert(lineNumber);
//}