// THIS SCRIPT ALLOWS CONSISTENT CODING OF DYNAMIC LAYER POSITIONING ACROSS BROWSERS.
// THIS DOES NOT NEED TO BE MODIFIED WHEN UPDATING CONTENT ON THE SITE.

function Div(id)// dHTML cross-browser API object
{	this.id = id;
	this.alias = (document.getElementById) ? document.getElementById(this.id).id : (document.layers) ? mapNN(this.id) : "document.all." + this.id;
	this.styleAlias = (document.getElementById || document.all) ? this.alias + ".style" : this.alias;
	this.documentObject = (document.getElementById) ? document.getElementById(this.id) : eval(this.alias);
	this.styleObject = (document.getElementById) ? this.documentObject.style : eval(this.styleAlias);
	
		
	function mapNN(name,alias) {
		alias = ((alias)? alias : "window")+ ".document.layers";
		var layers = eval(alias), i;
		
		for(i = 0; i < layers.length; i++) {	
			if (layers[i].name == name) return alias + "." + name;
			if(layers[i].document.layers.length > 0) {
				alias = mapNN(name, alias + "." + layers[i].name);
				if(alias != null) return alias;
			}
		}
		
		return null;
	}
}
Div.prototype.getId = function(){
	return this.id;
}

Div.prototype.isVisible = function() {	
	return (this.styleObject.visibility == "visible" || this.styleObject.visibility == "show");
}

Div.prototype.setVisible = function(bool){
	this.styleObject.visibility = (document.all || document.getElementById)? 
										((bool) ? "visible" : "hidden") : 
										((bool) ? "show" : "hide");
}

Div.prototype.getLeft = function(){
	return (document.getElementById)? 
				 (document.all || !this.documentObject.parentNode)?
					this.documentObject.offsetLeft : 
					(this.documentObject.offsetLeft - this.documentObject.parentNode.offsetLeft) 
				:(document.all)?
					this.styleObject.pixelLeft : 
					this.styleObject.left;
}

Div.prototype.setLeft = function(x){
	if(!isNaN(x)) this.styleObject.left = (document.getElementById)? new String(x + "px") : x;
}

Div.prototype.getTop = function()
{	return (document.getElementById) ? 
				 (document.all || !this.documentObject.parentNode)?
					this.documentObject.offsetTop : 
					(this.documentObject.offsetTop - this.documentObject.parentNode.offsetTop) 
				:(document.all)?
					this.styleObject.pixelTop : 
					this.styleObject.top;
}

Div.prototype.setTop = function(y){	
	if(!isNaN(y)) this.styleObject.top = (document.getElementById)?  (y + "px") : y;
}

Div.prototype.moveTo = function(x, y){	
	this.setLeft(x);
	this.setTop(y);
}

Div.prototype.getHeight = function(){
	return (document.getElementById)? 
				this.documentObject.offsetHeight : 
				(document.all)? 
					 (this.styleObject.pixelHeight)?
						 this.styleObject.pixelHeight : 
						 eval("document.all." + this.id + ".clientHeight")
					:(this.styleObject.clip)? 
						(this.styleObject.clip.bottom - this.styleObject.clip.top) :
						(this.documentObject.height) ? 
							this.documentObject.height :
							-1;
}

Div.prototype.setHeight = function(newHeight){
	if(!isNaN(newHeight))
		(document.getElementById)?
			this.styleObject.height = (newHeight + "px") :
			(document.all)?
				this.styleObject.pixelHeight = newHeight :
				this.styleObject.clip.bottom += (newHeight - this.getHeight());
}

Div.prototype.getWidth = function() {
	return (document.getElementById)?
	 			this.documentObject.offsetWidth :
				(document.all)? 
					 (this.styleObject.pixelWidth)?
						 this.styleObject.pixelWidth : 
						 eval("document.all." + this.id + ".clientWidth")
					:(this.styleObject.clip)?
						 (this.styleObject.clip.right - this.styleObject.clip.left) :
						 (this.documentObject.width)? 
						 	this.documentObject.width :
							-1;
}

Div.prototype.setWidth = function(newWidth){
	if(!isNaN(newWidth))
		(document.getElementById)?
			this.styleObject.width = (newWidth + "px") :
			(document.all)?
				this.styleObject.pixelWidth = newWidth :
				this.styleObject.clip.right = newWidth;
}

// NS 4: all style info lost. Use <span style= around the content.
Div.prototype.setContent = function(str)
{	// even if NS 4, store the text here for later retrieval by getContent()
	
	if(document.all)
		eval("document.all." + this.id + ".innerHTML = str;");
	else
	{	this.documentObject.innerHTML = str;
			
		if(document.layers)
		{	thisDoc = this.documentObject.document;
			thisDoc.open();
			thisDoc.write(this.getContent());
			thisDoc.close();
		}
	}
}

function genDivs()	{
	for (i=0; i < arguments.length; i++) window[arguments[i]] = new Div(arguments[i]);
}


