jQuery(document).ready(function(){
	jQuery(".link").click(function () {
		openWaitDialog();
	});
});

function showWaitDialog() {
	//avoid attempt to show it if it is already shown
	
	var browserName=navigator.appName;
	
	if (!(browserName=="Microsoft Internet Explorer")){
		if (!waitDialogShown) {
			Richfaces.showModalPanel('wait-dialog');
			waitDialogShown = true;
		}
	}
}

function onRequestStart() {
	openWaitDialog();
}

function onRequestEnd() {
	closeWaitDialog();
}

function openWaitDialog() {
	var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = jQuery("#boxWaitDialogImg").height() + 20;
    var popupWidth = jQuery("#boxWaitDialogImg").width() + 20;

    jQuery("#boxWaitDialog").css({
    	"opacity": "0.7",
        "height": windowHeight
    }).show();
    
    jQuery("#boxWaitDialogImg").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    }).show();
    
    waitDialogShown = true;
}

function closeWaitDialog() {
	jQuery("#boxWaitDialog, #boxWaitDialogImg").hide();
}