var myTWin = window.myTWin;
var modalWin = null;

function OpenMyWin(url, winName, modal, vArguments, sFeatures, frontend) {
	if (modal != null) {
		var dFeatures = 'dialogHeight: 600px; dialogWidth: 800px; center: Yes; help: Yes; resizable: Yes; status: No; scroll: Yes;';

		if (url == null || url == '') {
			alert("Invalid URL input.");
			return false;
		}
		if (vArguments == null || vArguments == '') {
			vArguments = '';
		}
		if (sFeatures == null || sFeatures == '') {
			sFeatures = dFeatures;
		}
		if (window.navigator.appVersion.indexOf("MSIE") != -1) {
			window.showModalDialog(url, vArguments, sFeatures);
			return false;
		}
		sFeatures = sFeatures.replace(/ /gi, '');
		aFeatures = sFeatures.split(";");
		sWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,scrollbars=yes,";
		for (x = 0; x < aFeatures.length; x++) {
			aTmp = aFeatures[x].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 "status":
					sWinFeat += "status=" + sVal + ",";
					break;
				case "center":
					if (sVal.toLowerCase() == "yes") {
						sWinFeat += "screenY=" + ((screen.availHeight - parseInt(pHeight)) / 2) + ",";
						sWinFeat += "screenX=" + ((screen.availWidth -  parseInt(pWidth)) / 2) + ",";
					}
					break;
			}
		}
		modalWin = window.open(String(url) , "", sWinFeat);
		if (vArguments != null && vArguments != '') {
			modalWin.dialogArguments = vArguments;
		}
	}
	else {
		var retValue = true;

		if (frontend == null) {
			width = 800;
			height = 620;
			var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes,z-lock=yes";
		}
		else {
			width = 700;
			height = 520;
			var sOptions = "location=no,menubar=no,toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=no,z-lock=yes";
		}

		var iLeft = (screen.width  - width) / 2;
		var iTop  = (screen.height - height) / 2;
		sOptions += ",width=" + width;
		sOptions += ",height=" + height;
		sOptions += ",left=" + iLeft;
		sOptions += ",top=" + iTop;

		if (myTWin != null && !myTWin.closed) {
			myTWin.focus();
			myTWin.location.href = url;
		}
		else {
			myTWin = window.open(url, winName, sOptions);
			if (typeof(myTWin) == "undefined" || myTWin == null) {
				retValue = false;
			}
			else {
				myTWin.focus();
			}
		}
	}
}

function checkFocus() {
	if (window.navigator.appVersion.indexOf("MSIE") == -1) {
		if (modalWin != null && !modalWin.closed) {
			self.blur();
			modalWin.focus();
		}
	}
}
