﻿// plugin definition
$.fn.MVCFormSubmit = function (options) {
    // Extend our default options with those provided.
    // Note that the first arg to extend is an empty object -
    // this is to keep from overriding our "defaults" object.
    var opts = $.extend({}, $.fn.MVCFormSubmit.defaults, options);
    opts.FormID = '#' + opts.FormID;
    opts.ProgressContentId = '#' + opts.ProgressContentId;
    opts.ReplaceID = '#' + opts.ReplaceID;
    // Our plugin implementation code goes here.
    $(opts.ProgressContentId).show();
    $.ajax({
        type: opts.type,
        url: $(opts.FormID).attr("action"),
        data: $(opts.FormID).serialize(),
        success: function (html) {

            $(opts.ReplaceID).html($.trim(html));
            //$(opts.FormID).valid();
            $(opts.ProgressContentId).hide();
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $(opts.ProgressContentId).hide();

        }
    });

};
// plugin defaults - added as a property on our plugin function
$.fn.MVCFormSubmit.defaults = {
    type: 'POST',
    FormID: '#',
    ProgressContentId: "#AjaxInfo",
    ReplaceID: '#'
};
