/** * Formal Forms - Covidien Standard Code for Ajax Form Submission with Formalized UI * */
$.fn.activateForm = function (target, options, hideForm) {
    var thisDiv = this;
    $('.formFail', this).hide();
    $('.formSuccess', this).hide();
    $('.formInProcess', this).hide();
    $('form', thisDiv).validate({
        submitHandler: function (form) {
            var method = $('form', thisDiv).attr('method') == undefined ? 'post' : $('form', thisDiv).attr('method');
            var parms = $('form', thisDiv).serialize();
            //$(':submit', thisDiv).fadeOut('slow');
            $('.formInProcess', thisDiv).show();
            for (key in options) {
                parms = parms + '&' + key + '=' + options[key];
            }
            $.ajax({
                type: 'post',
                url: target,
                data: parms,                
                complete: function () {
                    $('.formInProcess', thisDiv).hide('slow');
                    if (hideForm) {
                        $('form', thisDiv).hide();
                    }
                    //if (!hideForm) {
                    //	$(':submit',thisDiv).show('slow');
                    //}
                    //else {
                    //	$('form',thisDiv).hide();							
                    //}
                },
                error: function (request, textStatus, exception) {
                    //$('.formFail',thisDiv).append(textStatus);
                    //alert(request);
                    $('.formFail', thisDiv).show();
                },
                success: function (results) {
                    $('.formSuccess', thisDiv).show('slow');
                    $('.formResults', thisDiv).html(results);
                }
            });
            return false;
        }
    });
    return thisDiv;
};	
