﻿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() {
        $('#progressBox').remove();
        $('#ajaxWait').remove();
        $('<div id=\"progressBox\" class=\"ui-widget-overlay\" style=\"z-index:1002\"></div>').appendTo('body');

        var modal = $('#progressBox');
        var messageHtml = '<div id=\"ajaxWait\"><img src=\"/Content/img/wait.gif\" alt=\"Wait...\" /></div>';

        $(messageHtml).appendTo('body');

        modal.fadeIn('normal');
    },

    hideProgress: function() {
        $('#progressBox').fadeOut('normal',
            function() {
                $('#ajaxWait').remove();
                $('#progressBox').remove();
            }
        );
    },
    
    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'); 
                }
            }
        );
    },
};
