/*
Notes:
1. edge & help attributes do not work.
2. "height" and "width" must be entered before "center"
3. When using "center=yes" you do not need "left" and "top"
4. Minimize button not hidden, but when clicked the window will not disappear
5. Tweaked from original at http://www.codingforums.com/archive/index.php/t-29864
*/

var defaultFeatures = 'dialogHeight: 450px; dialogWidth: 600px; dialogTop: 10px; dialogLeft: 10px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;';

var modalWindowEmulator = null;
var modalWindowReturnValue = null;

if (typeof window.showModalDialog == 'undefined') {
	window.showModalDialog = function(sURL, vArguments, sFeatures) {
		if (sURL == null || sURL == '') {
			alert ("Invalid URL input.");
			return false;
		}
		if (vArguments == null || vArguments == '') {
			vArguments='';
		}
		if (sFeatures == null || sFeatures == '') {
			sFeatures = defaultFeatures;
		}
		sFeatures = sFeatures.replace(/ /gi,'');
		var raFeatures = sFeatures.split(";");
		sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,";
		for (var feat in raFeatures) {
			aTmp = raFeatures[feat].split(":");
			sKey = aTmp[0].toLowerCase();
			sVal = aTmp[1];
			switch (sKey) {
				case "dialogheight":
					sWinFeat += "height=" + sVal + ",";
					pHeight = sVal;
					break;
				case "dialogwidth":
					sWinFeat += "width=" + sVal + ",";
					pWidth = sVal;
					break;
				case "dialogtop":
					sWinFeat += "screenY=" + sVal + ",";
					break;
				case "dialogleft":
					sWinFeat += "screenX=" + sVal + ",";
					break;
				case "resizable":
					sWinFeat += "resizable=" + sVal + ",";
					break;
				case "scroll":
					sWinFeat += "scrollbars=" + sVal + ",";
					break;
				case "status":
					sWinFeat += "status=" + sVal + ",";
					break;
				case "center":
					if ( sVal.toLowerCase() == "yes" ) {
						sWinFeat += "screenY=" + ((screen.availHeight - pHeight) / 2) + ",";
						sWinFeat += "screenX=" + ((screen.availWidth - pWidth) / 2) + ",";
					}
					break;
			}  // End Case
		}  // End Loop
		modalWindowEmulator = window.open(String(sURL), "", sWinFeat);
		//if (vArguments != null && vArguments != '') {
			modalWindowEmulator.dialogArguments = vArguments;
		//}
		modalWindowEmulator.isEmulator = true;
		modalWindowEmulator.focus();
	} // End function definition
}  // End if

function checkFocus() {
	// In the BODY tag, add onFocus="checkFocus();" so non-IE browsers
	// can at least attempt to keep the dialog on top (keep it "modal").
	if (modalWindowEmulator != null && !modalWindowEmulator.closed) {
		self.blur();
		modalWindowEmulator.focus();
	}
}

function closeModalDialog() {
	if (modalWindowEmulator != null) {
		// We used an emulation of a modal dialog (non-IE), so the opened
		// window has called this routine as its last task.  We need to
		// close the window as our first task.
		modalWindowEmulator.close();
		modalWindowEmmulator = null;
	}
}

