<!--
/* This file contains javascript general to most dialogs. */

var helpName = 'webhelp';
var helpStyle = 'toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=650,height=375';

/* detect browser version */
var isNew = 0;
var isNetscape = 0;
var isIE = 0;
var isNS4 = 0;
var isIE4 = 0;
var isIE5 = 0;
var isUnix = 0;

var appName = navigator.appName;
var appVersion = parseInt(navigator.appVersion);

if (appVersion > 5) {
	isNew = 1;
}
else if (appName == "Netscape") {
	isNetscape = 1;
	if (appVersion == 4) {
		isNS4 = 1;
	}
}
else if (appName == "Microsoft Internet Explorer") {
	isIE = 1;
	if (appVersion == 4) {
		isIE4 = 1;
		if (msieversion() == 5)
		{
			// Note, for IE 5, both isIE4 and isIE5 will be true.
			isIE5 = 1;
		}
	}
}

/* Find out if we are running on Unix */
var platform = (navigator.platform).substring (0, 5);
if (platform == "SunOS") {
	isUnix = 1;
}
else if (platform == "HP-UX") {
	isUnix = 1;
}
else if (platform == "Linux") {
	isUnix = 1;
}
else {
	platform = (navigator.platform).substring (0, 3);
	if (platform == "AIX") {
		isUnix = 1;
	}
}

function msieversion()
{
   var ua = window.navigator.userAgent
   var msie = ua.indexOf ( "MSIE " )

   if ( msie > 0 )      // If Internet Explorer, return version number
      return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
   else                 // If another browser, return 0
      return 0
}

/* return DOM element */
function getElement(name) {
  // Get the element
  if (isNS4)
    return eval("document." + name);
  else if (isIE4)
    return eval("document.all." + name);
  else
  {
    element = document.getElementById(name);
    if (element != null && element != undefined)
      return element;
    else
      return eval("document." + name);
  }
}

/* return Style object */
function getStyle(name)
{
	var numStyleSheets = document.styleSheets.length;
	for (ssIdx = 0; ssIdx < numStyleSheets; ssIdx++)
	{
		var theRules = (document.styleSheets[ssIdx].rules || document.styleSheets[ssIdx].cssRules);
		var numRules = theRules.length;
		for (rulesIdx = 0; rulesIdx < numRules; rulesIdx++)
		{
			if (theRules[rulesIdx].selectorText.toLowerCase() == name.toLowerCase())
				return theRules[rulesIdx];
		}
	}
	return null;
}

/* show an element */
function showElement(name) {
	element = getElement(name);
	if (element != null && element != undefined) {
		if (isNS4)
			element.visibility = "visible";
		else
			element.style.visibility = "visible";
	}
}

/* hide an element */
function hideElement(name) {
	element = getElement(name);
	if (element != null && element != undefined) 
	{
		if (isNS4)
			element.visibility = "hidden";
		else
			element.style.visibility = "hidden";
	}
}

/* write an element */
function writeElement(name, contents)
{
	element = getElement(name);
	if (element != null && element != undefined) 
	{
		if (isNS4)
		{
			//alert(element.name);
            // In Netscape, positioned elements are documents
            element.document.open();
            element.document.write(contents);
            element.document.close();
		}
		else 
		{
			element.innerHTML = contents;
		}
	}
}

/* switch image where elementName is part of DOM, imageName is defined in current page */
function switchImage(elementName, imageName)
{
	element = getElement(elementName);
	if (element != null && element != undefined) {
		image = eval(imageName);
		element.src = image.src;
	}
}

var currentLayer = null;

/* switch a layer and its tab image */
function switchLayer(newLayer) {
	if (currentLayer == newLayer) {
		return;
	}

	if (currentLayer != null) {
		switchImage(currentLayer + "_image", currentLayer + "_off");
		hideElement(currentLayer + "_layer");
	}

	if (newLayer != null) {
		switchImage(newLayer + "_image", newLayer + "_on");
		showElement(newLayer + "_layer");
	}

	currentLayer = newLayer;
}

function addSpacer(lines) {
	if (isNS4 && !isUnix) {
		/* Use for NS Win32 */
		ems = lines * 3 / 2;
	}
	else {
		/* Use for NS Unix and MSIE */
		ems = lines * 2 + 1;
	}

	document.write("<DIV ID=\"foo\" style='position:relative;margin-top:");
	document.write(ems);
	document.writeln("em;' ALIGN=\"left\">&nbsp;</DIV>");
}

/* return the form in the specified layer */
function getForm(formName, layerName) {
	if (isNS4)
		return eval("document." + layerName + ".document." + formName);
	else
		return eval("document." + formName);
}

/* copy form data from one form to another */
function copyFormData(targetForm, sourceForm)
{
	for (var i = 0; i < sourceForm.elements.length; i++) {
		element = sourceForm.elements[i]
		type = sourceForm.elements[i].type
		if (type == "text" || type == "textarea") {
			name = sourceForm.elements[i].name
			targetForm.elements[name].value = sourceForm.elements[i].value
		}
		else if (type == "checkbox") {
			name = sourceForm.elements[i].name
			if (sourceForm.elements[i].checked)
				targetForm.elements[name].value = sourceForm.elements[i].value
		}
		else if (type == "radio") {
			name = sourceForm.elements[i].name
			if (sourceForm.elements[i].checked)
				targetForm.elements[name].value = sourceForm.elements[i].value
		}
		else if (type == "select-one") {
			name = sourceForm.elements[i].name
			selectedIndex = sourceForm.elements[i].selectedIndex
			if (sourceForm.elements[i].options[selectedIndex].value != "")
				targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].value
			else
				targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].text
		}
		else if (type == "select-multiple") {
			// FIXME_CWP - this code only handles the first selection from
			// a selection of type select-multiple.  Currently, there are
			// no cases where this is used.  Before multiple selections
			// are properly handled, a suitable delimiter must be decided
			// upon.
			// The main reason this was done was because Netscape interprets
			// a select box of size > 1 as a select-multiple
			name = sourceForm.elements[i].name
			selection = sourceForm.elements[i].options;

			selectedIndex = -1;
			for (var j = 0; j < selection.length; j++) {
				if (selection[j].selected) {
					selectedIndex = j;
					break;
				}
			}

			if (sourceForm.elements[i].options[selectedIndex].value != "")
				targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].value
			else
				targetForm.elements[name].value = sourceForm.elements[i].options[selectedIndex].text

			//alert("selectedIndex: " + selectedIndex + "\n" + targetForm.elements[name].value);
		}
	}
}

function openHelp(url) {
  var wn = this.window.open(
    url,
    helpName,
    helpStyle);

//  if (isNetscape()){
  //Restore hidden or minimized window (does not work in IE)
//    wn.focus()
//  }
}


// Handle Netscape resize/reload problem.  Should always force reload
// on resize within NS, but it only works on Windows versions.
if(document.layers)
{
//	origWidth=innerWidth;
//	origHeight=innerHeight;
//	onresize=function() { if (innerWidth != origWidth || innerHeight != origHeight) location.reload() }
	onresize=resizeOccurred;
}

var initialWidth = this.outerWidth;
var initialHeight = this.outerHeight;
//alert("Initial size \nNow my outer width: " + this.outerWidth +
//	    "\n and my outer height: " +this.outerHeight);

function resizeOccurred(e)
{
    //alert("You resized me! \nNow my outer width: " + this.outerWidth +
	//    "\n and my outer height: " +this.outerHeight);
	if (this.outerWidth != initialWidth || this.outerHeight != initialHeight)
	{
		// Only reload if the width or height actually have changed, otherwise
		// we get continuous redrawing.
		window.location.reload (true);
	}
}

function cancelDialog()
{
	window.location.href = getTrkTop().frames["menu"].inetBinPath + "?action=closeWindow";
}

function reloadQueries(queryFolder, deleteQuery)
{
	if (getTrkTop().frames["TRKCONTENT"].whichPage == "pg_qryview") {
		if (deleteQuery)
		{
			if (getTrkTop().frames["TRKCONTENT"].qryViewType == "public")
			{
				getTrkTop().frames["TRKCONTENT"].location.href = getTrkTop().frames["menu"].inetBinPath + "?action=detailView&type=4";
				getTrkTop().frames["navigation"].document.applets[0].reloadQueries(pubQuery, null, null, false);
			}
			else if (getTrkTop().frames["TRKCONTENT"].qryViewType == "private")
			{
				getTrkTop().frames["TRKCONTENT"].location.href = getTrkTop().frames["menu"].inetBinPath + "?action=detailView&type=3";
				getTrkTop().frames["navigation"].document.applets[0].reloadQueries(prvQuery, null, null, false);
			}
		}
		else
		{
			if (queryFolder == pubQuery && getTrkTop().frames["TRKCONTENT"].qryViewType == "public")
				getTrkTop().frames["TRKCONTENT"].location.href = getTrkTop().frames["menu"].inetBinPath + "?action=detailView&type=4";
			else if (queryFolder == prvQuery && getTrkTop().frames["TRKCONTENT"].qryViewType == "private")
				getTrkTop().frames["TRKCONTENT"].location.href = getTrkTop().frames["menu"].inetBinPath + "?action=detailView&type=3";

			getTrkTop().frames["navigation"].document.applets[0].reloadQueries(queryFolder, null, null, false);
		}
	}
	else {
		getTrkTop().frames["navigation"].document.applets[0].reloadQueries(queryFolder, pubQuery, prvQuery, deleteQuery);
	}
}

function verifyPage(e){
	if (trkVerify(e))
		submitPage(getForm("iForm","iFormDiv"), "Wait...", getForm("iForm","iFormDiv").submitButton);
}

function submitPage(theForm, theText, theButton){
	if (theForm.submitState.value != "busy"){
		theButton.value = theText;
		theForm.submitState.value = "busy";
		theForm.submit();
	}
}

function getTrkTop()
{
    // Return if we are already at trktop
    if (window.name == "trktop")
    {
        return window;
    }
    var w = window;
    // See if we are an opened window, use opener if we are
    //  Else use our parent
    if (window == window.parent)
    {
        if (isNetscape)
        {
            if (window.opener != undefined && window.opener != null)
            {
                w = window.opener;
            }
            else
            {
                return window;
            }
        }
        else
        {
            if (window.opener != null)
            {
                w = window.opener;
            }
            else
            {
                return window;
            }
        }
    }
    else
    {
        w = window.parent;
    }
    // Now look up our parent hierarchy for trktop
    while (w != w.parent)
    {
        if (w.name == "trktop")
        {
            return w;
        }
        w = w.parent;
    }
    return w;
}

function toggleBoxEnablement(radioElement)
{
	var boxElement = document.forms['createRelForm'].elements['relatedIDs'];
	boxElement.disabled = (radioElement.value == "current");
}

// -->
