var gdialogWin = new Object();
var objNonModal;


function centerWindow(windowWidth, windowHeight) {
	var retval;
	retval = "top=" + ((screen.availHeight - windowHeight) /2) + "px,";
	retval += "left=" + ((screen.availWidth - windowWidth) /2) + "px,";
	retval += "height=" + windowHeight + "px,";
	retval += "width=" + windowWidth + "px,";

	return retval;
}

function standardPopupFeatures(windowWidth, windowHeight) {
	return "scrollbars,resizable,toolbar=0,status=0,menubar=0,dependent," +  
		   centerWindow(windowWidth, windowHeight);
}

function standardModalFeatures(windowWidth, windowHeight) {		
	return "center:yes;help:no;scroll:yes;resizable:yes;status:no;" +  
		"dialogWidth:" + windowWidth + "px;" +
		"dialogHeight:" + windowHeight + "px;";
}

function showHelp(url,target,windowWidth,windowHeight) {

	if (!target) target='_blank';
	if (!windowWidth) windowWidth=580;
	if (!windowHeight) windowHeight=750;
	
	var features=standardPopupFeatures(windowWidth, windowHeight);

	return detectPopup(url, target, features);
}

function showPopup(url,target,features) {

	if (!target) target='_blank';
	if (!features) {
		features=standardPopupFeatures(750, 580);
	}
	return detectPopup(url, target, features);
}

function detectPopup(url,target,features){
    var oWin = window.open(url,target,features);
	if (oWin==null || typeof(oWin)=="undefined" ||
	    oWin.document==null || typeof(oWin.document)=="undefined") {
		alert("The application has tried to open a popup window that could not be opened.\n\n" + 
		      "Your browser may be configured to block popup windows.");
	}
	return oWin;
}

function showModal(url,features,returnFunc,arguments) {
	if(isExp && ExpVer && ExpVer >= 5){
	    return showModalDialog(url,arguments,features);
	}else if(!gdialogWin.window || (gdialogWin.window && gdialogWin.window.closed)) {
		// Initialize properties of the modal dialog object.
		gdialogWin.returnFunc = returnFunc;
		gdialogWin.returnValue = "";
		gdialogWin.arguments = arguments;
		gdialogWin.url = url;
		gdialogWin.target = "_blank";
		
		gdialogWin.window=showPopup(url,gdialogWin.target,features);
		gdialogWin.window.focus();

	} else {
		gdialogWin.window.focus();
	}
	return false;
}

// Event handler to inhibit Navigator form element 
// and IE link activity when dialog window is active.
function deadend() {
	if (gdialogWin.window && !gdialogWin.window.closed) {
		gdialogWin.window.focus();
		return false;
	}
}

// Since links in IE4 cannot be disabled, preserve 
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks;

// Disable form elements and links in all frames for IE.
function disableForms() {
	IELinkClicks = new Array();

	if (frames.length > 0) {	
		for (var h = 0; h < frames.length; h++) {
			IELinkClicks[h] = new Array();
			disableDocForms(frames[h].document, true, h);
		}
	} 
	else {
		IELinkClicks[0] = new Array()
		disableDocForms(document, true, 0);
	}
}
function disableDocForms(objDoc, Status, Frame) {
var i;
	for (i=0; i < objDoc.forms.length; i++) {
		for (var j=0; j < objDoc.forms[i].elements.length; j++) {
			objDoc.forms[i].elements[j].disabled = Status;
		}
	}
}

// Restore IE form elements and links to normal behavior.
function enableForms() {
	if (frames.length > 0) {
		for (var h = 0; h < frames.length; h++) {
			disableDocForms(frames[h].document, false, h);
		}
	} 
	else {
		disableDocForms(document, false, 0);
	}
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function blockEvents() {
	if (document.layers) {
		window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.onclick = deadend;
	} else {
		disableForms();
	}
	window.onfocus = checkModal;
}
// As dialog closes, restore the main window's original
// event mechanisms.
function unblockEvents() {
	if (document.layers) {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.onclick = null;
		window.onfocus = null;
	} else {
		enableForms();
	}
}
// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModal() {
	if (gdialogWin.window && !gdialogWin.window.closed) {
		setTimeout("finishChecking()", 50);
		return true;
	} 
}
function finishChecking() {
   if (gdialogWin.window && !gdialogWin.window.closed) {
      gdialogWin.window.focus();
   }
}
