// This library supports Netscape Navigator 4.X, Microsoft Internet Explorer 4.X and 5.x and .
// This is just a basic library for retrieving browser information,
// writing HTML to DOM object and locating DOM objects.

// The following objects are available for use:
//	-> browser
//		The browser object has the following properties:
//			major - (int) Integer version number of the user agent.
//			minor - (float) The complete version number of the user agent.
//			ns - (boolean) flag to indicate netscape browser.
//			ns2 - (boolean) flag to indicate netscape 2.X browser.
//			ns3 - (boolean) flag to indicate netscape 3.X browser.
//			ns4 - (boolean) flag to indicate netscape 4.X browser or higher.
//			mz5 - (boolean) flag to indicate mozilla 5.0 browser or higher (Netscape 6 and Mozilla).
//			ie - (boolean) flag to indicate I.E. browser.
//			ie3 - (boolean) flag to indicate I.E. 3.X browser.
//			ie4 - (boolean) flag to indicate I.E. 4.X browser or higher.
//			op3 - (boolean) flag to indicate Opera browser.
//			document - (String) string defining the property name of a document.
//			style - (String) string defining the property name for reference the style of an object.
//			layerDocument - (String) string defining the property name of a layer's document.
//			layer - (String) string defining the property name for accessing layers by ID.
//
// The following methods are available for use:
//	->	getWindowHeight()
//			Returns the height of the window.
//	->	getWindowWidth()
//			Returns the width of the window.
//	->	getLayer(layerID)
//			Retrieves the layer specified by the supplied ID.
//	->	getStyle(layerID)
//			Retrieves the style associated with layer specified by the supplied ID.
//	->	getLayerDocument(layerID)
//			Retrieves the document property of the layer specified by the supplied ID.
//	->	getLayerDocumentFromLayer(targetLayer)
//			Retrieves the document property of the supplied layer.
//	->	writeHTMLToLayerDocument(targetLayerDocument,html)
//			Writes HTML in to the supplied layer document.
//	->	writeHTMLToLayer(targetLayer,html)
//			Writes HTML in to the supplied layer.
//	->	writeHTML(layerID,html)
//			Writes HTML in to the the layer specified by the supplied ID.
//	->	moveLayerTo(targetLayer,x,y)
//			Moves the targetLayer to the absolute position specified.
//	->	moveLayerRelativeToLayer(srcLayer,targetLayer,dx,dy)
//			Moves the targetLayer to the page location of the srcLayer.  Also allows for an additional offset.

//========================================================
// START Function declaration section.
//========================================================

// Some sample userAgent values.
// in mozilla m17: userAgent=mozilla/5.0 (x11; u; linux 2.2.12 i686; en-us; m17) gecko/20000807
// in NS 4.75: userAgent=mozilla/4.75 [en] (xll; u; linux 2.2.12 i686)
// in NS 6.0: userAgent=mozilla/5.0 (x11; u; linux 2.2.12 i686; en-us; m18) gecko/20001117 netscape6/6.0

function _getAgent()
{
	var agent;

	agent=navigator.appName.toLowerCase();
	this.major=parseInt(navigator.appVersion);
	this.minor=parseFloat(navigator.appVersion);
	this.ns=(agent.indexOf('netscape')!=-1);
	this.ns2=(this.ns&&(this.major==2));
	this.ns3=(this.ns&&(this.major==3));
	this.ns4=(this.ns&&(this.major==4));
	this.mz5=(this.ns&&(this.major>=5));
	this.ie=(agent.indexOf("microsoft")!=-1);
	this.ie3=(this.ie&&(this.major==3));
	this.ie4=(this.ie&&(this.major>=4));
	this.op3=(agent.indexOf("opera")!=-1);

	if (this.ns4)
	{
		// document.layers["draglayer"].left = 100;
		this.document="document";
		this.style="";
		this.layerDocument=".document";
		this.layer="document.layers";
		this.sizeInfo="window.inner";
	}
	else if (this.ie4)
	{
		// document.all["draglayer"].style.pixelLeft = 100;
		this.document="document.all";
		this.style=".style";
		this.layerDocument="";
		this.layer="document.frames";
		this.sizeInfo="document.body.client";
	}
	else if (this.mz5)
	{
		// Set mozilla stuff.
		// document.getElementById("draglayer").style.left = 100 + "px";
	}
}

//-------------------------------------------------------
// Returns the window height.
//-------------------------------------------------------
function getWindowHeight()
{
	return eval(browser.sizeInfo+"Height");
}
	
//-------------------------------------------------------
// Returns the window windth.
//-------------------------------------------------------
function getWindowWidth()
{
	return eval(browser.sizeInfo+"Width");
}

//-------------------------------------------------------
// Returns the layer in the specified ID.
// In I.E. this is A.K.A. the frame.
//-------------------------------------------------------
function getLayer(layerID)
{
	return eval(browser.layer+'["'+layerID+'"]');
}

//-------------------------------------------------------
// Returns the style of the layer in the specified ID.
//-------------------------------------------------------
function getStyle(layerID)
{
	return eval(browser.document+'["'+layerID+'"]'+browser.style);
}

//-------------------------------------------------------
// Returns the document contained in the specified layer ID.
// In I.E. this is A.K.A. the frame's document.
//-------------------------------------------------------
function getLayerDocument(layerID)
{
	return eval(browser.document+'["'+layerID+'"]'+browser.layerDocument);
}

//-------------------------------------------------------
// Returns the document contained in the specified layer.
// In I.E. this is A.K.A. the frame's document.
//-------------------------------------------------------
function getLayerDocumentFromLayer(targetLayer)
{
	if (browser.ie4)
	{
		return targetLayer;
	}
	else if (browser.ns4)
	{
		return targetLayer.document;
	}
	else if (browser.mz5)
	{
		// Set mozilla stuff.
	}
	return targetLayer;
}

//-------------------------------------------------------
// Writes the supplied HTML to the specified layer document.
//-------------------------------------------------------
function writeHTMLToLayerDocument(targetLayerDocument,html)
{
	if (browser.ie4)
	{
		targetLayerDocument.innerHTML=html;
	}
	else if (browser.ns4)
	{
		targetLayerDocument.close();
		targetLayerDocument.open();
		targetLayerDocument.write(html);
		targetLayerDocument.close();
	}
	else if (browser.mz5)
	{
		// Set mozilla stuff.
	}
}

//-------------------------------------------------------
// Writes the supplied HTML to the specified layer document.
//-------------------------------------------------------
function writeHTMLToLayer(targetLayer,html)
{
	writeHTMLToLayerDocument(getLayerDocumentFromLayer(targetLayer),html);
}

//-------------------------------------------------------
// Writes the supplied HTML string to the specified ID.
//-------------------------------------------------------
function writeHTML(layerID,html)
{
	writeHTMLToLayerDocument(getLayerDocument(layerID),html);
}

//-------------------------------------------------------
// Moves the targetLayer to the page location of the srcLayer.
// Also allows for an offset.
//-------------------------------------------------------
function moveLayerTo(targetLayer,x,y)
{
	if (browser.ie4)
	{
		targetLayer.style.left=x;
		targetLayer.style.top=y;
	}
	else if (browser.ns4)
	{
		targetLayer.moveTo(x,y);
	}
	else if (browser.mz5)
	{
		// Set mozilla stuff.
	}
}

//-------------------------------------------------------
// Moves the targetLayer to the page location of the srcLayer.
// Also allows for an offset.
//-------------------------------------------------------
function moveLayerRelativeToLayer(srcLayer,targetLayer,dx,dy)
{
	var parentLayer;

	if (browser.ie4)
	{
		parentLayer=srcLayer.offsetParent;
		if (parentLayer==null)
		{
			// Absolutely position the target layer.
			targetLayer.style.left=srcLayer.offsetLeft+document.body.clientLeft+dx;
			targetLayer.style.top=srcLayer.offsetTop+document.body.clientTop+dy;
		}
		else
		{
			dx+=srcLayer.offsetLeft;
			dy+=srcLayer.offsetTop;
			moveLayerRelativeToLayer(parentLayer,targetLayer,dx,dy);
		}
	}
	else if (browser.ns4)
	{
		targetLayer.moveTo(srcLayer.pageX+dx,srcLayer.pageY+dy);
	}
	else if (browser.mz5)
	{
		// Set mozilla stuff.
	}
}

//========================================================
// END Function declaration section.
//========================================================

//========================================================
// START Global variable section.
//========================================================

// Borwser object contains browser specific information.
var browser=new _getAgent();

//========================================================
// END Global variable section.
//========================================================

