/**
* This file is referenced by the xsl for both nodes and scenarios
*/

var hwndPublicHelp = null;

function openHelp() {
	hwndPublicHelp = window.open("help.do", "", "width=500,height=480,scrollbars=yes,resizable=yes");
}

// This MUST be defined as it is referenced by RichTextEditor when dictionary terms are created

function openDictionary(strUrl, iWidth, iHeight)
{
   if(strUrl != null)
   {
      if(iWidth && iHeight)
      {
         window.open(strUrl, "", "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes");
      }
      else 
      {
         // Use default	
         window.open(strUrl, "", "width=400,height=500,scrollbars=yes,resizable=yes");
      }
   }
}
// This MUST be defined as it is referenced by RichTextEditor when links are created
// TODO - is it really? need to check...
function openStandard(strUrl)
{
   if(strUrl != null)
   {
      window.open(strUrl);
   }
}

function getSelectValue(select)	{
	idx = select.selectedIndex;
	return select.options[idx].value;
}

/*
TODO - What uses the following functions, are they necessary?
*/

var MS = navigator.appVersion.indexOf("MSIE")
var NS6 = (navigator.appName=="Netscape" && (document.getElementById!=undefined));
var NS4 = (document.layers);
var IE = (navigator.appName=="Microsoft Internet Explorer");

window.isIE4 = (MS>0) && (parseInt(navigator.appVersion) >= 4)


function getLayer(layername) {
	 if (IE||NS4) return (NS4) ? findLayer(layername) : document.all[layername];
	 else if (NS6) return document.getElementById(layername);
}

function getLayerStyle(layername) {
	 layer = getLayer(layername);
	 if (layer == null)
	 	alert('Internal Javascript error - could not find layer '+layername);
	 else
	 	return layer.style;
}

function findLayer(layername, obj) {
	 // recursive function to find the layer
	 var i=0;
	 var perObj = null;
	 var tmpObj = (obj) ? obj.document.layers : document.layers;
	 for(i=0; i<tmpObj.length; i++) {
		 if (tmpObj[i].id==layername) 
		 	return tmpObj[i];
		 perObj = findLayer(layername, tmpObj[i])
		 if (perObj) return perObj;
	 }
	 return false;
}

function showHideLayer(layerName, show) {
	showHideLayerNoDisplay(layerName, show)
	layer = getLayerStyle(layerName);
	if (show) {
		layer.display = '';
	} else {
		layer.display = 'none';
	}
}

function showHideLayerNoDisplay(layerName, show) {
	layer = getLayerStyle(layerName);
	if (show) {
		layer.visibility = 'visible';
		layer.position = 'static';
	} else {
		layer.visibility = 'hidden';
		layer.position = 'absolute';
	}
}

/* new window function */

function newWindow(url, width, height, wname) {
	// Calculate the screen coordinates to open a new window - window should appear in the middle of the screen
	var left = ((screen.width - width) / 2);
	var top = ((screen.height - height) / 2);

	// If window name is not passed in use default value
	if (!wname) {
		wname = "blank";
	}
	// Open new window and then focus on it 
	newWin = window.open(url, wname, "'menubar=no,location=no,resizable=yes,scrollbars=no,status=no,left=" + left + ",top=" + top + ", width=" + width + ", height=" + height + "'");
	if (window.focus) {
		newWin.focus();
	}
}