/** * Formal Forms - Covidien Standard Code for Ajax Form Submission with Formalized UI * */
$.fn.activateForm = function(target, options, hideForm, spotLight) {
    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) {
                        $(':submit', thisDiv).show('slow');
                    }
                    else {
                        $('form', thisDiv).hide();
                    }
                },
                error: function(request, textStatus, exception) {
                    $('.formFail', thisDiv).append(textStatus);
                    $('.formFail', thisDiv).show();
                    $('div#Rich_Description', thisDiv).hide();
                },
                success: function(results) {
                    var spotLightTag = '';
                    $('.formInProcess', thisDiv).hide('slow');
                    $('form', thisDiv).hide('slow');
                    $('.formResults', thisDiv).html(results);
                    if (spotLight != '') {
                        var axel = Math.random() + "";
                        var a = axel * 10000000000000;
                        spotLightTag = "<img src='" + spotLight + a + "?' width='1' height='1' alt='' />";
                        $('.formSuccess', thisDiv).append(spotLightTag).show('slow');
                    }
                    $('div.Rich_Description', thisDiv).hide();
                    //Google has not released reporting for this yet
                    //pageTracker._trackEvent('B4DTracking', 'successful_submission', 'share_site');
                    //var myEventObject = pageTracker._createEventTracker('B4DShareSiteObject');
                    //myEventObject._trackEvent('B4DTracking', 'successful_submission', 'share_site');
                }
            });
            return false;
        }
    });
    return thisDiv;
};		$.fn.activateFormHttps = function(options, hideForm, spotLight) {
var target = 'https://www.bariatrics4diabetes.com/colondisease/RosettaPatientSignUp.aspx';
// var target = 'https://tamans-ww01d/authoringpreviewprod/colondiseasecs4/RosettaPatientSignUp.aspx
    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) {
                        $(':submit', thisDiv).show('slow');
                    }
                    else {
                        $('form', thisDiv).hide();
                    }
                },
                error: function(request, textStatus, exception) {
                    $('.formFail', thisDiv).append(textStatus);
                    $('.formFail', thisDiv).show();
                    $('div#Rich_Description', thisDiv).hide();
                },
                success: function(results) {
                    var spotLightTag = '';
                    $('.formInProcess', thisDiv).hide('slow');
                    $('form', thisDiv).hide('slow');
                    $('.formResults', thisDiv).html(results);
                    if (spotLight != '') {
                        var axel = Math.random() + "";
                        var a = axel * 10000000000000;
                        spotLightTag = "<img src='" + spotLight + a + "?' width='1' height='1' alt='' />";
                        $('.formSuccess', thisDiv).append(spotLightTag).show('slow');
                    }
                    $('div.Rich_Description', thisDiv).hide();
                    //Google has not released reporting for this yet
                    //pageTracker._trackEvent('B4DTracking', 'successful_submission', 'share_site');
                    //var myEventObject = pageTracker._createEventTracker('B4DShareSiteObject');
                    //myEventObject._trackEvent('B4DTracking', 'successful_submission', 'share_site');
                }
            });
            return false;
        }
    });
    return thisDiv;
};
