/*(function($){
    $.fn.extend({
        center: function () {
            return this.each(function() {
                var top = ($(window).height() - $(this).outerHeight()) / 2;
                var left = ($(window).width() - $(this).outerWidth()) / 2;
                $(this).css({position:'fixed', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
            });
        }
    }); 
})(jQuery);*/

(function(){
    jQuery.fn.center = function(){
        return this.each(function(){
            var element = jQuery(this), win = jQuery(window);
            centerElement();
            
            jQuery(window).bind('resize',function(){
                centerElement();
            });

            function centerElement(){
                var elementWidth, elementHeight, windowWidth, windowHeight, X2, Y2;
                elementWidth = element.outerWidth();
                elementHeight = element.outerHeight();
                windowWidth = win.width();
                windowHeight = win.height();    
                X2 = (windowWidth/2 - elementWidth/2) + "px";
                Y2 = (windowHeight/2 - elementHeight/2) + "px";
                jQuery(element).css({
                    'left':X2,
                    'top':Y2,
                    'position':'fixed'
                });                     
            } //centerElement function
        });
    }
})();

$(function(){
    $("#maskDiv").click(function(e){
       	$('#errorDiv').hide();
        $("#popupDiv").hide();
        $("#infoDiv").hide();
        $(this).hide();
    });
})

$(function(){
    $("#maskPopupDiv").click(function(e){
        $(this).hide();
        $('#errorPopupDiv').hide();
    });
})

$(function(){
    $("#errorDiv").click(function(e){
        $(this).hide();
        $('#maskDiv').hide();
    });
})

$(function(){
    $("#infoDiv").click(function(e){
        $(this).hide();
        $('#maskDiv').hide();
    });
})

$(function(){
    $("#errorPopupDiv").click(function(e){
        $(this).hide();
        $('#maskPopupDiv').hide();
    });
})

$(function(){
    $("#closePopup").click(function(e){
    	$("#popupDiv").hide();
        $('#maskDiv').hide();
    });
})



function loadPopup(url, params) {
    var api = $('#popupContentDiv').jScrollPane({showArrows:false}).data('jsp');
    api.getContentPane().load(url, params,
        function() {
            $('#popupDiv').center();
            $('#popupDiv').show();
            $('#maskDiv').show();
        	api.reinitialise();
        });
}

function sendMsg(msg) {
    $("#errorMsg").text(msg);
    $('#errorDiv').center();
    $('#errorDiv').show();
    $('#maskDiv').show();
}

function sendInfoMsg(msg) {
    $("#infoMsg").text(msg);
    $('#infoDiv').center();
    $('#infoDiv').show();
    $('#maskDiv').show();
}

function sendPopupMsg(msg) {
    $("#errorMsg").text(msg);
    $('#errorPopupDiv').center();
    $('#errorPopupDiv').show();
    $('#maskPopupDiv').show();
}
