// Global for browser version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4));
// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object();

// Generate a modal dialog.
function openDialog(url, width, height, returnFunc, args) 
{
	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) 
	{
		// Initialize properties of the modal dialog object.
		dialogWin.returnFunc = returnFunc;
		dialogWin.returnedValue = "";
		dialogWin.args = args;
		dialogWin.url = url;
		dialogWin.width = width;
		dialogWin.height = height;
		// Keep name unique so Navigator doesn't overwrite an existing dialog.
		dialogWin.name = (new Date()).getSeconds().toString();
		// Assemble window attributes and try to center the dialog.
		if (Nav4) 
		{
			// Center on the main window.
			dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2);
			dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2);
			var attr = "screenX=" + dialogWin.left + ",screenY=" + dialogWin.top + ",resizable=no,width=" + dialogWin.width + ",height=" + dialogWin.height;
		} 
		else 
		{
			// The best we can do is center in screen.
			dialogWin.left = (screen.width - dialogWin.width) / 2;
			dialogWin.top = (screen.height - dialogWin.height) / 2;
			var attr = "left=" + dialogWin.left + ",top=" + dialogWin.top + ",resizable=no,width=" + dialogWin.width + ",height=" + dialogWin.height;
		}
		// Generate the dialog and make sure it has focus.
		dialogWin.win=window.open(dialogWin.url, dialogWin.name, attr);
		dialogWin.win.focus();
	} 
	else 
	{
		dialogWin.win.focus();
	}
}

// Event handler to inhibit Navigator form element and Internet Explorer
// link activity when dialog window is active.
function deadend() 
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		dialogWin.win.focus();
		return false;
	}
}

function showMessageBox(id, height)
{
	var c = document.getElementById(id);
	if(c != null)
	{
		c.style.display = "block";
		c.style.visibility = "";
		c.style.width = "50%";
		//c.style.height = height;
		//c.style.backgroundColor="red";
		//c.style.top = "85px";
		c.style.position = "absolute";
	}
}

// Since links in Internet Explorer 4 can't be disabled, preserve IE link onclick 
// event handlers while they're "disabled." Restore when reenabling the main window.
var IELinkClicks = new Array();
var linkHrefs	 = new Array();
var linkTargets = new Array();
// Disable form elements and links in all frames for IE.
function disableForms() 
{
	for (var i = 0; i < document.forms.length; i++) 
	{
		for (var j = 0; j < document.forms[i].elements.length; j++) 
		{
			if(document.forms[i].elements[j] != null)
			{
				if(document.forms[i].elements[j].attributes["skip"] == null)
				{
					document.forms[i].elements[j].disabled = true;
					document.forms[i].elements[j].onclick = deadend;
					if(document.forms[i].elements[j].tagName == "SELECT")
					{
						//if(document.forms[i].elements[j].size > 1)
						//{
							document.forms[i].elements[j].style.display = "none";
						//}
					}
				}
			}
		}
	}
	for (i = 0; i < document.links.length; i++) 
	{
			if(document.links[i].attributes["skip"] == null)
			{
				if(document.links[i].onclick != null)
				{
					//alert(document.links[i].onclick);
					IELinkClicks[i] = document.links[i].onclick;
				}
				else
					IELinkClicks[i] = "null";

				if(document.links[i].href != null)					
					linkHrefs[i] = document.links[i].href;
				else
					linkHrefs[i] = "null";
					
				if(document.links[i].target != null)
					linkTargets[i] = document.links[i].target;
				else
					linkTargets[i] = "null";
				
				document.links[i].onclick = deadend;
				document.links[i].href = "#";
				document.links[i].target = "";
			}
	}
}

// Restore IE form elements and links to normal behavior.
function enableForms() 
{
	for (var i = 0; i < document.forms.length; i++) 
	{
		for (var j = 0; j < document.forms[i].elements.length; j++) 
		{
			document.forms[i].elements[j].disabled = false;
			if(document.forms[i].elements[j].tagName == "SELECT" && document.forms[i].elements[j].attributes["skip"] == null)
			{
				//if(document.forms[i].elements[j].size > 1)
				//{
					document.forms[i].elements[j].style.display = "";
				//}
			}
			
		}
		for (i = 0; i < document.links.length; i++) 
		{
				
				if(document.links[i].attributes["skip"] == null)
				{
					
					
					if(IELinkClicks[i] != null && IELinkClicks[i] != "null") document.links[i].onclick = IELinkClicks[i];
						
					if(linkHrefs[i] != null && linkHrefs[i] != "null") document.links[i].href = linkHrefs[i];
					if(linkTargets[i] != null && linkTargets[i] != "null") document.links[i].target = linkTargets[i];
				}
		}
		
	}

}

// Grab all Navigator events that might get through to form elements while 
// dialog is open. For Internet Explorer, disable form elements.
function blockEvents() 
{
	if (Nav4) 
	{
		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 (Nav4) 
   {
		window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS);
		window.onclick = null;
		window.onfocus = null;
	} 
	else 
	{
		enableForms();
	}
}

function checkModal() 
{
	if (dialogWin.win && !dialogWin.win.closed) 
	{
		dialogWin.win.focus();
	}
}
