﻿
function mailpage() {
    mail_str = "mailto:?subject=Recommended Link&body=I saw this link for the Heart Partners of Indiana website and thought of you. Please take a look at it when you have chance.%0A%0A";
    mail_str += "If you want to learn more about heart health, click the link below.%0A%0A";
    mail_str += location.href + "%0A%0A";
    mail_str += "Take care.";

    location.href = mail_str;
}

function deleteModule(moduleId) {
    $.ajax({
        type: "POST",
        url: "/Services/Services.asmx/DeleteModule",

        // Pass the "Count" parameter, via JSON object.
        data: "{'moduleId':'" + moduleId + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $("#" + moduleId).hide();
        }
    });
}

function moveModuleToZone(moduleId, zoneId) {
    $.ajax({
        type: "POST",
        url: "/Services/Services.asmx/MoveModuleToZone",

        // Pass the "Count" parameter, via JSON object.
        data: "{'moduleId':'" + moduleId + "','zoneId':'" + zoneId + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        }
    });
};

var $U =
{
    focus: function(c) {
        c = $('#' + c)[0];

        try {
            c.select();
        }
        catch (e) {
        }

        try {
            c.focus();
        }
        catch (e) {
        }
    },

    disableInputs: function(target, disable) {
        $(target).find('input,textarea,select').each(
                                                        function() {
                                                            $(this).attr('disabled', disable);
                                                        }
                                                    );
    },

    showProgress: function(message, target) {
        $('#progressBox').remove();
        $('<div id=\"progressBox\" class=\"modalBox\" style=\"z-index:1002\"></div>').appendTo('body');

        var modal = $('#progressBox');
        var messageHtml = '<div class=\"progressSmall\">' +
                            '    <span style=\"padding-left:15px\">' + message + '</span>' +
                            '</div>';

        modal.html(messageHtml);

        var x;
        var y;

        if (target) {
            var elm = $(target);
            var pos = elm.offset();

            x = pos.left;
            y = (pos.top + elm[0].offsetHeight);
        }

        if ((!x) && (!y)) {
            $U.center(modal);
        }
        else {
            $U.setLocation(modal, x, y)
        }

        modal.fadeIn('normal');
    },

    hideProgress: function() {
        $('#progressBox').fadeOut('normal',
                                    function() {
                                        $('#progressBox').remove();
                                    }
                                 );
    },

    confirm: function(title, message, okHandler) {
        $('#confirmationBox').empty().append('<div class=\"confirmMessage\">' + message + '</div>').css('display', '');
        $('#confirmationBox').dialog(
                                        {
                                            modal: true,
                                            resizable: false,
                                            title: title,
                                            width: 460,
                                            overlay: {
                                                opacity: 0.5,
                                                background: '#999'
                                            },
                                            buttons:
                                            {
                                                "Ok": function() {
                                                    okHandler();
                                                    $(this).dialog('close');
                                                },
                                                "Cancel": function() {
                                                    $(this).dialog('close');
                                                }
                                            },
                                            close: function() {
                                                $(this).dialog('destroy');
                                            }
                                        }
                                    );
    },

    confirmWithId: function(title, message, okHandler, id) {
        $('#confirmationBox').empty().append('<div class=\"confirmMessage\">' + message + '</div>').css('display', '');
        $('#confirmationBox').dialog(
                                        {
                                            modal: true,
                                            resizable: false,
                                            title: title,
                                            width: 460,
                                            overlay: {
                                                opacity: 0.5,
                                                background: '#999'
                                            },
                                            buttons:
                                            {
                                                "Ok": function() {
                                                    okHandler(id);
                                                    $(this).dialog('close');
                                                },
                                                "Cancel": function() {
                                                    $(this).dialog('close');
                                                }
                                            },
                                            close: function() {
                                                $(this).dialog('destroy');
                                            }
                                        }
                                    );
    },

    messageBox: function(title, message, isError, onOk) {
        var className = isError ? 'errorMessage' : 'notifyMessage';

        $('#messageBox').empty().append('<div class=\"' + className + '\">' + message + '</div>').css('display', '');
        $('#messageBox').dialog(
                                {
                                    modal: true,
                                    resizable: false,
                                    title: title,
                                    width: 460,
                                    overlay: {
                                        opacity: 0.5,
                                        background: '#999'
                                    },
                                    buttons:
                                    {
                                        "Ok": function() {
                                            if (typeof (onOk) == 'function') {
                                                onOk();
                                            }

                                            $(this).dialog('close');
                                        }
                                    },
                                    close: function() {
                                        $(this).dialog('destroy');
                                    }
                                }
                            );
    },

    blockUI: function() {
        var dimBackground = $('#dimBackground');
        var width = $(document).width() + 'px';
        var height = $(document).height() + 'px';

        dimBackground.css({ width: width, height: height, opacity: 0.5 });

        $U.setLocation(dimBackground, 0, 0);
        dimBackground.show();
    },

    unblockUI: function() {
        $('#dimBackground').hide();
    },

    center: function(e) {
        var x = (($U.getViewPortWidth() - e[0].offsetWidth) / 2);
        var y = (($U.getViewPortHeight() - e[0].offsetHeight) / 2) + $U.getViewPortScrollY();

        $U.setLocation(e, x, y);
    },

    setLocation: function(e, x, y) {
        e.css({ position: 'absolute', left: (x + 'px'), top: (y + 'px') });
    },

    getViewPortWidth: function() {
        var width = 0;

        if ((document.documentElement) && (document.documentElement.clientWidth)) {
            width = document.documentElement.clientWidth;
        }
        else if ((document.body) && (document.body.clientWidth)) {
            width = document.body.clientWidth;
        }
        else if (window.innerWidth) {
            width = window.innerWidth;
        }

        return width;
    },

    getViewPortHeight: function() {
        var height = 0;

        if (window.innerHeight) {
            height = (window.innerHeight);
        }
        else if ((document.documentElement) && (document.documentElement.clientHeight)) {
            height = document.documentElement.clientHeight;
        }

        return height;
    },

    getContentHeight: function() {
        if (document.body) {
            if (document.body.scrollHeight) {
                return document.body.scrollHeight;
            }

            if (document.body.offsetHeight) {
                return document.body.offsetHeight;
            }
        }

        return 0;
    },

    getViewPortScrollX: function() {
        var scrollX = 0;

        if ((document.documentElement) && (document.documentElement.scrollLeft)) {
            scrollX = document.documentElement.scrollLeft;
        }
        else if ((document.body) && (document.body.scrollLeft)) {
            scrollX = document.body.scrollLeft;
        }
        else if (window.pageXOffset) {
            scrollX = window.pageXOffset;
        }
        else if (window.scrollX) {
            scrollX = window.scrollX;
        }

        return scrollX;
    },

    getViewPortScrollY: function() {
        var scrollY = 0;

        if ((document.documentElement) && (document.documentElement.scrollTop)) {
            scrollY = document.documentElement.scrollTop;
        }
        else if ((document.body) && (document.body.scrollTop)) {
            scrollY = document.body.scrollTop;
        }
        else if (window.pageYOffset) {
            scrollY = window.pageYOffset;
        }
        else if (window.scrollY) {
            scrollY = window.scrollY;
        }

        return scrollY;
    }
};