﻿function jAjaxSubmit(form, e, waitPanelId, targetToUpdate, methodName) {

    if (!$.browser.msie) {
        e.stopPropagation();
    }
    var isValid = true;

    if (typeof methodName != 'undefined') {
        isValid = methodName(form, null);
    }

    if (isValid) {
        // create the form body
        var body = $(form).serialize();
        renderContent2(targetToUpdate, waitPanelId, form.action, body, form.method);
    }
    return false;
}

function renderContent(elementId, waitElementId, url, params, callback) {
    renderContent2(elementId, waitElementId, url, params, "GET", callback);
}

function renderContent2(elementId, waitElementId, url, params, actionType, callback) {

    $("#" + waitElementId).show();

    $.ajax({
        type: actionType,
        dataType: "html",
        url: url,
        data: params,
        success: function(result) {
            $("#" + elementId).html(result);
            $("#" + waitElementId).hide();
            parent.tb_remove();
            
            if (typeof callback != 'undefined')
                callback();

        },
        error: function(error) {
            $("#" + waitElementId).hide();
            alert(error);
            //TODO:// write your log here
        }
    });
}   