var ModalDialog = new Object() ;

ModalDialog.Show = function(dialogURL, dialogName, dialogWidth, dialogHeight, dialogArguments, returnFunction) {
	
	ModalDialog.ReturnFunction = returnFunction;
	ModalDialog.ReturnedValue = "";
	
	if (document.all) { //check for IE
	
		ModalDialog.ReturnedValue = showModalDialog(dialogURL, dialogArguments, "dialogWidth:"+ dialogWidth +"px; dialogHeight:"+ dialogHeight +"px; scroll:yes; status:no; help:no; resizable:yes;");
		if (typeof(ModalDialog.ReturnedValue) != "undefined") ModalDialog.ReturnFunction();
	
	} else { //non-IE functional code
		
		var iTop = (screen.height - dialogHeight)/2;
		var iLeft = (screen.width  - dialogWidth)/2;
		
		var sOption  = "location=no,menubar=no,resizable=yes,toolbar=no,dependent=yes,dialog=yes,minimizable=no,modal=yes,scrollbars=yes,alwaysRaised=yes,"+
			"width="+ dialogWidth +",height=" + dialogHeight +",top="  + iTop +",left=" + iLeft;
	
		var oWindow = window.open(dialogURL, dialogName, sOption, true);
		oWindow.moveTo(iLeft, iTop);
		oWindow.resizeTo(dialogWidth, dialogHeight);
		oWindow.focus();
		oWindow.dialogArguments = dialogArguments;
		
		this.Window = oWindow;
		
		window.top.captureEvents( Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.top.parent.addEventListener('mousedown', this.CheckFocus, true);
		window.top.parent.addEventListener('mouseup', this.CheckFocus, true);
		window.top.parent.addEventListener('click', this.CheckFocus, true);
		window.top.parent.addEventListener('focus', this.CheckFocus, true);
	}	
}

ModalDialog.CheckFocus = function() {
	if (ModalDialog.Window && !ModalDialog.Window.closed) {
		ModalDialog.Window.focus();
		return false;
	} else {
		window.top.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.top.parent.removeEventListener('onmousedown', ModalDialog.CheckFocus, true);
		window.top.parent.removeEventListener('mouseup', ModalDialog.CheckFocus, true);
		window.top.parent.removeEventListener('click', ModalDialog.CheckFocus, true);
		window.top.parent.removeEventListener('onfocus', ModalDialog.CheckFocus, true);
	}
}