// wait.js

(function($){

document.documentElement.className += ' wait';
var requestCount = 1;
var lastWait = 0;

if (window.parent != window && window.parent.postMessage) {
	parent.postMessage('PUT wait\n\ntrue', '*');
}

function removeWait() {
	$(function() {
		setTimeout(function() {
			requestCount--;
			if (requestCount < 1) {
				var myWait = ++lastWait;
				setTimeout(function() {
					if (myWait == lastWait && requestCount < 1) {
						requestCount = 0;
						$(document.documentElement).removeClass("wait");
						if (window.parent != window && window.parent.postMessage) {
							parent.postMessage('PUT wait\n\nfalse', '*');
						}
					}
				}, 400); // give browser a chance to draw the page
			}
		}, 0);
	});
}

$(removeWait);

$(window).bind("beforeunload unload", function() {
	if (requestCount > 0 && window.parent != window && window.parent.postMessage) {
		parent.postMessage('PUT wait\n\nfalse', '*');
	}
	requestCount++;
	$(document.documentElement).addClass("wait");
});

$(document).ajaxSend(function(event, xhr, options){
	requestCount++;
	$(document.documentElement).addClass("wait");
});

$(document).ajaxComplete(removeWait);

$(window).bind('message', function(event) {
	var data = event.originalEvent.data;
	var source = event.originalEvent.source;
	if (data.indexOf('PUT wait\n\n') == 0) {
		$('iframe').each(function(){
			if (this.contentWindow == source) {
				var bool = data.substring(data.indexOf('\n\n') + 2);
				if (bool == 'true') {
					requestCount++;
					$(document.documentElement).addClass("wait");
				} else {
					removeWait();
				}
			}
		});
	}
});

})(window.jQuery);


@@ -112,117 +112,8 @@
 0;%0A%0A
-if (window.parent != window && window.parent.postMessage) %7B%0A%09parent.postMessage('PUT wait%5Cn%5Cntrue', '*');%0A%7D%0A%0A
 func
@@ -411,135 +411,8 @@
 %22);%0A
-%09%09%09%09%09%09if (window.parent != window && window.parent.postMessage) %7B%0A%09%09%09%09%09%09%09parent.postMessage('PUT wait%5Cn%5Cnfalse', '*');%0A%09%09%09%09%09%09%7D%0A
 %09%09%09%09
@@ -562,140 +562,8 @@
 ) %7B%0A
-%09if (requestCount %3E 0 && window.parent != window && window.parent.postMessage) %7B%0A%09%09parent.postMessage('PUT wait%5Cn%5Cnfalse', '*');%0A%09%7D%0A
 %09req
@@ -739,33 +739,32 @@
 ss(%22wait%22);%0A%7D);%0A
-%0A
 $(document).ajax
@@ -792,329 +792,60 @@
 %0A%0A$(
-window).bind('message', function(event) %7B%0A%09var data = event.originalEvent.data;%0A%09var source = event.originalEvent.source;%0A%09if (data.indexOf('PUT wait%5Cn%5Cn') == 0) %7B%0A%09%09$('iframe').each(function()%7B%0A%09%09%09if (this.contentWindow == source) %7B%0A%09%09%09%09var bool = data.substring(data.indexOf('%5Cn%5Cn') + 2);%0A%09%09%09%09if (bool == 'true') %7B%0A%09%09%09%09
+document).bind('calliOpenDialog', function(event) %7B%0A
 %09req
@@ -857,20 +857,16 @@
 ount++;%0A
-%09%09%09%09
 %09$(docum
@@ -908,61 +908,59 @@
 %22);%0A
-%09%09%09%09%7D else %7B%0A%09%09%09%09%09removeWait();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%7D%0A%7D
+%7D);%0A$(document).bind('calliCloseDialog', removeWait
 );%0A%0A

Reset cursor after dialog closes