// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  © Copyright 2000, Calypso Systems, Inc.
//  All Rights Reserved.
//
//  Description:	Netscape 4.x Function Library
//
//  Who                     When         What
//  ------------------------------------------------
//  lGoodman@calsys.com     01/17/00     Created
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var csxHoverLayers = new Object();
var csxHoverAnchors = new Object();

function testFunction(a)
{
	return 100;
}
Layer.prototype.hide=function()
{
	this.visibility="hide";
}
Layer.prototype.inherit=function()
{
	this.visibility="inherit";
}

Layer.prototype.show=function()
{
	this.visibility="show";
}

Layer.prototype.setInnerHTML=function(sText)
{
	
		var l = xAll(this.name);
		if(!l)
		{
			l=this;
		}
		if (l.layCover)
		{
			var lLast = l.layCover
		}
		
		if (l.layScrollBar)
		{
			
				l.layCover = new Layer(this.width,l.layContain);
				l.layCover.clip.top = l.clip.top;
				l.layCover.clip.left = l.clip.left;
				l.layCover.clip.height = l.clip.height;
				l.layCover.clip.width = l.clip.width;
			
		}
		else
		{
			l.layCover = new Layer(this.clip.width);
		}
		l.layCover.bgColor = l.bgColor;
		l.layCover.left = l.pageX;
		l.layCover.top = l.pageY;
		l.layCover.pageX = l.pageX;
		l.layCover.pageY = l.pageY;
		
		var oDoc = l.layCover.document;
		oDoc.open ();
		applyStyle(oDoc);
		oDoc.writeln(sText);
		oDoc.close();
		
		l.layCover.show();
		if (lLast)
		{
			lLast.inherit()
			lLast.document.open();
			lLast.document.write("");
			lLast.document.close();
		}
		else
		{
			l.hide();
		}
		
		if (l.layScrollBar)
		{
			scrollUpdateScrollBar(l.layCover)
		}
		
	}
	
Layer.prototype.describe = function()
{
	var oLay = this;
	var sOut = "";
	sOut += "name:" + oLay.name + " ";
	sOut += "test:" + oLay.test + " ";
	sOut += "left:" + oLay.left + " ";
	sOut += "top:" + oLay.top + " ";
	//sOut += "clip.bottom:" + oLay.clip.bottom + " ";
	//sOut += "clip.top:" + oLay.clip.top + " ";
	//Out += "clip.height:" + oLay.clip.height + " ";
	//sOut += "clip.left:" + oLay.clip.left + " ";
	//sOut += "clip.right:" + oLay.clip.right + " ";
	//sOut += "clip.width:" + oLay.clip.width + " ";
	sOut += "pageX:" + oLay.pageX + " ";
	sOut += "pageY:" + oLay.pageY + " ";
	sOut += "clip:" + oLay.clip.toString() + " ";
	sOut += "visibility:" + oLay.visibility + " ";
	sOut += "x:" + oLay.x + " ";
	sOut += "y:" + oLay.y + " ";
	sOut += "zIndex:" + oLay.zIndex + " ";
	sOut += "document.width:" + oLay.document.width + " ";
	sOut += "document.height:" + oLay.document.height + " ";
	sOut += "width:" + oLay.width + " ";
	sOut += "height:" + oLay.height + " ";
	return sOut;	
}

var xAll = function (sName)
{
	return xAll[sName];
}

xAll.refreshFields = function(oLayPass)
{
	sRet = "";
	var oDoc;
	if (!oLayPass) 
	{oDoc = window.document;}
	else
	{
		oDoc = oLayPass.document;
	}
	if (oDoc)
	{
		// Process this document for fields
		for(var iForm =0; iForm<oDoc.forms.length;iForm++)
		{
			var oForm = oDoc.forms[iForm];
			for(var iEl =0; iEl<oForm.elements.length;iEl++)
			{
				var oEl = oForm.elements[iEl];
				xAll[oEl.name] = oEl;
				window[oEl.name] = oEl;
				sRet += oEl.name + "\n";
			}
		}
		
		// Process any children
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			var oLay = oDoc.layers[i];
			if(oLay)	{sRet += this.refreshFields(oLay)}	
		}
	}

	return sRet;
}

xAll.refreshLayers = function(oLayPass)
{
	sRet = "";
	var oDoc;
	if (!oLayPass) 
	{oDoc = window.document;}
	else
	{
		oDoc = oLayPass.document;
	}
	if (oDoc)
	{
		
		// Process any children
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			var oLay = oDoc.layers[i];
			//sRet += "Layer '" + oLay.name + "' pageX:" + oLay.pageX + " pageY:" + oLay.pageY + "\n";
			sRet += "Layer '" + oLay.describe() + "'\n";
			xAll[oLay.name] = oLay;
			window[oLay.name] = oLay;
			if(oLay)	{sRet += this.refreshLayers(oLay)}	
		}
	}

	return sRet;
}


xAll.refresh = function(oLayPass)
{
	var sRet = "";
	sRet += "Fields\n"
	sRet += "-----------------------------\n"
	sRet += this.refreshFields();
	sRet += "-----------------------------\n"
	sRet += "\n"
	sRet += "Layers\n"
	sRet += "---------------------------------------------------\n"
	sRet += this.refreshLayers();
	sRet += "---------------------------------------------------\n"
	window.status ="Done"
}



function describeFields(oLayPass, iIndent)
{
	var oDoc;
	var sOut = "";
	if (!iIndent)
	{
		iIndent=0;
	}
	if (!oLayPass) 
	{
		oDoc = window.document;
		sOut += "Window\n";
	}
	else
	{
		oDoc = oLayPass.document;
		sOut += "Layer:" + oLayPass.name + "\n";
	}

	if (oDoc)
	{
		// Process this document for fields
		for(var iForm =0; iForm<oDoc.forms.length;iForm++)
		{
			var oForm = oDoc.forms[iForm];
			sOut += "  Form:" + oForm.name + "\n"
			for(var iEl =0; iEl<oForm.elements.length;iEl++)
			{
				var oEl = oForm.elements[iEl];
				sOut += "    Element:" + oEl.name + "\n"
			}
		}
		
		// Process any children
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			var oLay = oDoc.layers[i];
			if(oLay)
			{
				sOut += describeFields(oLay)
			}	
		}
	}
	return sOut;
}
var xCmd = new xCommand();

function xCommand()
{
	this.supports = new Object();
	this.supports.redirect = true;
	this.supports.setFocus = true;
	this.supports.outerHTML = true;
	this.supports.innerHTML = true;
	this.supports.executeJavascript = true;
	this.supports.innerText = true;
	this.supports.alert = true;
}

// Redirect
xCommand.prototype.redirect = function(sUrl)
{
	alert("redirect");
	window.navigate(sUrl);
}

// setFocus
xCommand.prototype.setFocus = function(sElementName)
{
	alert("focus");
	document.all(sElementName).focus();
}

// outerHTML
xCommand.prototype.outerHTML = function(sElementName,sNewValue)
{
	// Set the innerhtml in NS
	xAll(sElementName).setInnerHTML(sNewValue);
}

// innerHTML
xCommand.prototype.innerHTML = function(sElementName,sNewValue)
{
	xAll(sElementName).setInnerHTML(sNewValue);
}

// innerText
xCommand.prototype.innerText = function(sElementName,sNewValue)
{
	alert("innerText");
	document.all(sElementName).innerText = sNewValue;
}

// executeJavascript
xCommand.prototype.executeJavascript = function(sScript)
{
	eval(sScript);
}

// alert
xCommand.prototype.alert = function(sAlertText)
{
	alert(sAlertText);
}


function xLayer()
{
	

}


function hoverLink(lAction, sName,lSource,sClass)
{
	var oAnc = findAnchor(sName + "A");
	//var oAnc = csxHoverAnchors[sName + "A"];
	
	//var oLayHover = findLayer(sName + "X");	
	var oLayHover=csxHoverLayers[sName + "X"];
	var lState = oAnc.state;
	if (!lState)
	{
		lState = 0;
	}
	// lAction Over=1   Out=0
	// lSource 0:Native  1:Normal  2:Hover
	// State 0:Native, 1:Normal Showing, 2:Hover Showing
	// Mouse Over -> Show Hover
	
	if(lAction==1)
	{
		if (lState==0 && lSource==0)
		{
			// Show The Hover
			if(!oLayHover.setUp)
			{
				oLayHover.x=oAnc.x;
				oLayHover.y=oAnc.y;
				oLayHover.setUp= true;
				oLayHover.zIndex=500;
				
			}
			oLayHover.x=oAnc.x;
			oLayHover.y=oAnc.y;
			
			if (oLayHover.visibility != "show")
			{
				oLayHover.visibility = "show";
				var oTemp = findLayer(sName + "D");	
				if(oTemp)oTemp.visibility = "hide";
				
			}
		}
	}
		
	// Mouse Out
	if (lAction==0)
	{	 oLayHover.visibility = "hide" 
		 oLayHover.x = 0;
		 oLayHover.y = 0;
		 var oTemp = findLayer(sName + "D");	
			if(oTemp)oTemp.visibility = "show";
	}
}


function findLayer(sName, oLayPass)
{
	var oDoc;
	if (!oLayPass) 
	{
		oDoc = window.document;
	}
	else
	{
		oDoc = oLayPass.document;
	}

	if (oDoc)
	{
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			var oLay = oDoc.layers[i];
			if (oLay.name == sName)
			{
				return oLay;
			}
			else
			{
				if(oLay)
				{
					var oRet = findLayer(sName,oLay);
					if (oRet) 
					{
						return oRet;
					}
				}
			}	
		}
	}
}

function findAnchor(sName, oLayPass)
{
	
	var oDoc;
	if (!oLayPass) 
	{
		oDoc = window.document;
	}
	else
	{
		oDoc = oLayPass.document;
	}

	if (oDoc)
	{
		
		for(var i = 0; i<oDoc.anchors.length; i++)
		{
			if(oDoc.anchors[i].name ==sName)
			{
				return oDoc.anchors[i];
			}
		}
		
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			
			var oLay = oDoc.layers[i];
			if(oLay)
			{
				var oRet = findAnchor(sName,oLay);
				if (oRet) 
				{
					return oRet;
				}
			}
		}
	}
}

function findImage(sName, oLayPass)
{
	
	var oDoc;
	if (!oLayPass) 
	{
		oDoc = window.document;
	}
	else
	{
		oDoc = oLayPass.document;
	}
	
	if (oDoc)
	{	
	if(oLayPass)
	{	
	
	}
		for(var vImg in oDoc.images)
		{
			if(oDoc.images[vImg].name ==sName)
			{
				return oDoc.images[vImg];
			}
		}
		/*
		for(var i = 0; i<oDoc.images.length; i++)
		{
			if(oDoc.images[i].name ==sName)
			{
				return oDoc.images[i];
			}
		}
		*/
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			
			var oLay = oDoc.layers[i];
			if(oLay)
			{
				var oRet = findImage(sName,oLay);
				if (oRet) 
				{
					return oRet;
				}
			}
		}
	}
}


function nextLinkName()
{
	if (!window.linkCounter)
	{
		window.linkCounter = 1;
	}
	else
	{
		window.linkCounter++;
	}
	return "csxLink" + window.linkCounter;

}




function describeAnchors(sIndent,oLayPass)
{
	var oDoc;
	var sOut="";
	if (!sIndent)
	{
		sOut = "Document Layers\n";
		sIndent = " ";
	}
	
	if (!oLayPass) 
	{
		oDoc = window.document;
	}
	else
	{
		oDoc = oLayPass.document;
	}

	if (oDoc)
	{
		for(var i = 0; i<oDoc.anchors.length; i++)
		{
			var oAnc = oDoc.anchors[i];
			//if(oAnc)
			{
			sOut = sOut + sIndent + " Anchor " + i + ":" + oAnc.name + " x:" + oAnc.x + " y:" + oAnc.y + "\n"; //" href:" + oAnc.href + " text:" + oAnc.text + "\n";
			}
		}
		
		for(var i = 0; i<oDoc.layers.length; i++)
		{
			var oLay = oDoc.layers[i];
			sOut = sOut + sIndent + "Layer " + i + ":" + oLay.name + "\n";
			if(oLay)
			{
				sOut += describeAnchors(sIndent + "  ", oLay);
			}
		}
	}
	return sOut;
}

function describeLayer(oLay)
{
	var sOut = "Describe Layer\n";
	if (!oLay)
		sOut +="Invalid Layer"
	else
	{
	sOut += "name:" + oLay.name + "\n";
	sOut += "left:" + oLay.left + "\n";
	sOut += "top:" + oLay.top + "\n";
	sOut += "bgColor:" + oLay.bgColor + "\n";
	sOut += "clip.bottom:" + oLay.clip.bottom + "\n";
	sOut += "clip.top:" + oLay.clip.top + "\n";
	sOut += "clip.height:" + oLay.clip.height + "\n";
	sOut += "clip.left:" + oLay.clip.left + "\n";
	sOut += "clip.right:" + oLay.clip.right + "\n";
	sOut += "clip.width:" + oLay.clip.width + "\n";
	sOut += "pageX:" + oLay.pageX + "\n";
	sOut += "pageY:" + oLay.pageY + "\n";
	sOut += "visibility:" + oLay.visibility + "\n";
	sOut += "x:" + oLay.x + "\n";
	sOut += "y:" + oLay.y + "\n";
	sOut += "zIndex:" + oLay.zIndex + "\n";
	sOut += "document.width:" + oLay.document.width + "\n";
	sOut += "document.height:" + oLay.document.height + "\n";
	sOut += "width:" + oLay.width + "\n";
	sOut += "height:" + oLay.height + "\n";
}
	return sOut;	
}
function describeLayers(sIndent,oLayPass)
{
	var oDoc;
	var sOut="";
	if (!sIndent)
	{
		sOut = "Document Layers\n";
		sIndent = " ";
	}
	
	if (!oLayPass) 
	{
		oDoc = window.document;
	}
	else
	{
		oDoc = oLayPass.document;
	}

	if (oDoc)
	{
		for(var i = 0; i<oDoc.layers.length; i++)
		//var i = 0;
		//for (var vKey in oDoc.layers)
		{
			//i++;
			var oLay = oDoc.layers[i];
			sOut = sOut + sIndent + i + ":" + oLay.describe() + "\n";
			if(oLay)
			{
				sOut += describeLayers(sIndent + "  ", oLay);
			}
		}
	}
	return sOut;
}


