function Guestbook_LoadMessages(page) {
    var params = new Object();
    params["module"] = 'Guestbook';
    params["action"] = 'List';
    params["page"] = page;
    $.get(baseUrl, params,
        function (data, textStatus) {
            $("#GuestContent").html(data);
        }
        );
    return false;
}

function Guestbook_AddMessage() {
    if ($('#htmlarea').val() == '') {
        alert('Введите сообщение');
        return false;
    }
    var options = {
        target:        '#Messages',   // target element(s) to be updated with server response
        beforeSubmit:  Guestbook_AddMessageFormRequest,  // pre-submit callback
        success:       Guestbook_AddMessageFormResponse,  // post-submit callback
        resetForm:     true,
        clearForm:     true,
        type:          'POST'
    //dataType:      "json"        // 'xml', 'script', or 'json' (expected server response type)

    };

    // bind to the form's submit event
    $("#AddMessageForm").ajaxSubmit(options);
    return false;
}

// pre-submit callback
function Guestbook_AddMessageFormRequest(formData, jqForm, options) {
    $('#addcomment').attr('disabled', true);
    $('#htmlarea').attr('disabled', true);
    $('#progressbar').show();
    return true;
}

// post-submit callback
function Guestbook_AddMessageFormResponse(responseText, statusText) {
    Guestbook_LoadMessages(0);
    $('#progressbar').hide();
    $('#htmlarea').removeAttr('disabled');
    $('#addcomment').removeAttr('disabled');
}

function GuestbookResponseForm(id, page) {
    $('.responseFormArea').hide();
    $('#htmlarea').attr('id', 'htmlareaForm');
    $('#divResponseForm' + id).remove();
    f = $('#divResponseForm').clone();
    f.attr('id', 'divResponseForm' + id);
    f.find('form').attr('class', 'responseForm' + id);
    f.find('#htmlareaResponse').attr('id', 'htmlarea');
    f.find('#submitFormButton').click(function() {
        return GuestbookAddResponse(id, page)
        });
    f.find('#responceId').val(id);
    //alert(f.html());
    $('#responseFormArea' + id).append(f);
    $('#responseFormArea' + id).show();
    f.show();
    return false;
}

function GuestbookAddResponse(id, page) {
    if ($('#htmlarea').val() == '') {
        alert('Введите сообщение');
        return false;
    }

    var options = {
        target:        '#Messages',   // target element(s) to be updated with server response
        beforeSubmit:  function (formData, jqForm, options) {
                            return true;
                        },  // pre-submit callback
        success:       function (responseText, statusText) {
                            Guestbook_LoadMessages(page);
                        },  // post-submit callback
        resetForm:     true,
        clearForm:     true,
        type:          'POST'
    //dataType:      "json"        // 'xml', 'script', or 'json' (expected server response type)

    };

    // bind to the form's submit event
    $(".responseForm" + id).ajaxSubmit(options);
    return false;
}