/*************************************************************************
	dw_write.js	
	write to positioned div (absolute or relative)
	Designed specifically for writing to layer in table (for ns4).
	For writing to absolute-positioned layer you can also	use dw_core.js.
	version date: June 2002
	
	This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-2 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.	
*************************************************************************/

// constructor function (x,y optional)
function writeObj(id,wd,ht,x,y) {
	if (!id) return;	// for when writeObj used as prototype
	if (document.getElementById||document.all) {
		this.el = (document.getElementById)? document.getElementById(id): document.all[id];
		this.css = this.el.style;	this.doc = this.el;
		this.css.width=wd+"px"; this.css.height=ht+"px";
  } else if (document.layers) {
		var lyrRef = getLyrRef(id,document);	// in case id nested
		// create layer inside to write to
		// in case id relative positioned
		this.el = new Layer(wd,lyrRef);	
		lyrRef.resizeTo(wd,ht);
		this.el.visibility = "inherit";	// new Layer initially hidden
		this.doc = this.el.document;	// write to inner layer
		// use outer layer for shifting, show/hide
		this.css = this.el.parentLayer; 
	} else return null; // (if not ...byId or ...all or ...layers)
	var px = (document.layers)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.obj = id+"Object"; eval(this.obj+"=this");	// used by banner
}

//  Methods
function dw_writeLyr(cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}

function dw_show() { this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }

function dw_shiftTo(x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

function dw_shiftBy(x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

// assign methods
writeObj.prototype.writeLyr = dw_writeLyr;
writeObj.prototype.show = dw_show;
writeObj.prototype.hide = dw_hide;
writeObj.prototype.shiftTo = dw_shiftTo;
writeObj.prototype.shiftBy = dw_shiftBy;

// credit to http://www.13thparallel.org for the following 2 functions
// returns amount of vertical scroll
function getScrollY() {
	var scroll_y = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		scroll_y = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scroll_y = document.body.scrollTop; 
	else if (window.pageYOffset)
		scroll_y = window.pageYOffset;
	else if (window.scrollY)
		scroll_y = window.scrollY;
	return scroll_y;
}

function getScrollX() {
	var scroll_x = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		scroll_x = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scroll_x = document.body.scrollLeft; 
	else if (window.pageXOffset)
		scroll_x = window.pageXOffset;
	else if (window.scrollX)
		scroll_x = window.scrollX;
	return scroll_x;
}


// get reference to nested layer for ns4
// from dhtmllib.js by Mike Hall of www.brainjar.com
function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
	  	theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0) 
	    	if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
					return theLyr;
	  }
		return null;
  }
}
