var customModalDialog = new Object;

customModalDialog.value = "";
customModalDialog.eventHandler = "";
customModalDialog.window = null;
customModalDialog.parentIsDisabled = false;
customModalDialog.interval = "";

customModalDialog.disableEvent = function customModalDisableEvent()
{
	if (customModalDialog.parentIsDisabled == true) 
	{
		customModalDialog.window.focus();
		return false;
	}
}
customModalDialog.disableParent = function customModalDisableParent()
{
	document.oncontextmenu = customModalDialog.disableEvent;
	document.onkeypress = customModalDialog.disableEvent;

	document.addEventListener( 'mousedown', customModalDialog.disableEvent, true ) ;
	document.addEventListener( 'click', customModalDialog.disableEvent, true ) ;

	for (i = 0; i < document.all.length; i++)
	{
		document.all[i].onclick = customModalDialog.disableEvent;
		document.all[i].onmousedown = customModalDialog.disableEvent;
		if (document.all[i].tagName == "A") {document.all[i].href = "javascript:customModalDialog.disableEvent;" + document.all[i].href;}
	}
}

customModalDialog.watcher = function customModalDialogWatcher()
{
	if (customModalDialog.window.closed == true)
	{
		customModalDialog.parentIsDisabled = false;

		window.clearInterval(customModalDialog.interval);

		try {
			eval(customModalDialog.eventHandler);
		}
		catch (e) {alert(e);}
	}
}
customModalDialog.showModalDialog = function showCustomModalDialog(pageUrl, varArgIn, varIEOptions, varNonIEOptions, dialogWidth, dialogHeight, eventHandler)
{
	var isIE;
	var sOptions = "";

	customModalDialog.eventHandler = eventHandler;

	if (window.showModalDialog) {isIE=true;}else{isIE=false;}

	var iTop  = (screen.height - dialogHeight) / 2 ;
	var iLeft = (screen.width  - dialogWidth)  / 2 ;
	
	if (!isIE) {
		sOptions  = ",location=no,status=1,menubar=no,toolbar=no,dependent=yes,dialog=yes,minimizable=no,alwaysRaised=yes"

		if (dialogWidth != "") {sOptions = sOptions + ",width="  + dialogWidth}
		if (dialogHeight != "") {sOptions = sOptions + ",height=" + dialogHeight}
		if (iTop != "") {sOptions = sOptions + ",top="  + iTop}
		if (iLeft != "") {sOptions = sOptions + ",left=" + iLeft}
		
		sOptions = sOptions + varNonIEOptions;
	}else{
		sOptions = sOptions + "dialogWidth:" + dialogWidth + "px;";
		sOptions = sOptions + "dialogHeight:" + dialogHeight + "px;";
		varIEOptions = sOptions + varIEOptions
	}

	if (!isIE)
	{
		customModalDialog.window = window.open( '', 'CustomDialogNonIE', sOptions, true ) ;
		customModalDialog.window.moveTo( iLeft, iTop ) ;
		customModalDialog.window.resizeTo( dialogWidth, dialogHeight ) ;
		customModalDialog.window.focus() ;
		if (varArgIn != "") {
			customModalDialog.window.location.href = varArgIn ;
		}else{
			customModalDialog.window.location.href = pageUrl ;
		}
	} else {
		customModalDialog.window = window.showModalDialog(pageUrl, varArgIn, varIEOptions);
	}

	if (varArgIn != "") {customModalDialog.dialogArguments = varArgIn ;}

	if (!isIE) {
		customModalDialog.window.oncontextmenu = new Function("return false;");
		customModalDialog.interval = window.setInterval("customModalDialog.watcher();",100)
	}else{
		eval(customModalDialog.eventHandler);
	}
	
	if (!isIE)
	{
		customModalDialog.parentIsDisabled = true;
		customModalDialog.disableParent();
	}
}