// CreateLayer and DestroyLayer Functions
// enables you to dynamically create a layer after the page has been loaded, can only truely delete layers in IE
// 19990326

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/
if(is.ns6){
if (!document.childNodes[0].insertAdjacentHTML){

HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
{
	switch (where){
	case 'beforeBegin':
		this.parentNode.insertBefore(parsedNode,this)
		break;
	case 'afterBegin':
		this.insertBefore(parsedNode,this.firstChild);
		break;
	case 'beforeEnd':
		this.appendChild(parsedNode);
		break;
	case 'afterEnd':
		if (this.nextSibling){
		this.parentNode.insertBefore
		(parsedNode,this.nextSibling);
		} else {
		this.parentNode.appendChild(parsedNode)
		}
		break;
	}
}

HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr){

	var r = this.ownerDocument.createRange();
	r.setStartBefore(this);
	var parsedHTML = r.createContextualFragment(htmlStr);
	this.insertAdjacentElement(where,parsedHTML)
}


HTMLElement.prototype.insertAdjacentText = function(where,txtStr){

	var parsedText = document.createTextNode(txtStr)
	this.insertAdjacentElement(where,parsedText)
}
}
}

function createLayer(id,nestref,left,top,width,height,content,bgColor,visibility,zIndex) {
	if (is.ns) {
		if(is.ns4){
				//
				if (nestref) {
					var lyr = eval("document."+nestref+".document."+id+" = new Layer(width, document."+nestref+")")
				}
				else {
					var lyr = document.layers[id] = new Layer(width)
					eval("document."+id+" = lyr")
				}
				lyr.name = id
				lyr.left = left
				lyr.top = top
				if (height!=null) lyr.clip.height = height
				if (bgColor!=null) lyr.bgColor = bgColor
				lyr.visibility = (visibility=='hidden')? 'hide' : 'show'
				if (zIndex!=null) lyr.zIndex = zIndex
				if (content) {
					lyr.document.open()
					lyr.document.write(content)
					lyr.document.close()
				}
			//
		}
		if (is.ns6){
			var str = '\n<DIV id='+id+' style="position:absolute; left:'+left+'; top:'+top+'; width:'+width
			if (height!=null) {
				str += '; height:'+height
				str += '; clip:rect(0,'+width+','+height+',0)'
			}
			if (bgColor!=null) str += '; background-color:'+bgColor		
			if (zIndex!=null) str += '; z-index:'+zIndex
			if (visibility) str += '; visibility:'+visibility
			str += ';">'+((content)?content:'')+'</DIV>'
			if (nestref) {
			
				index = nestref.lastIndexOf(".")
				var nestlyr = (index != -1)? nestref.substr(index+1) : nestref
				document.getElementById(nestlyr).insertAdjacentHTML("beforeEnd",str);
			}
			else {
				document.body.insertAdjacentHTML("beforeEnd",str)
			}
		}
	}		
	else if (is.ie) {
		var str = '\n<DIV id='+id+' style="position:absolute; left:'+left+'; top:'+top+'; width:'+width
		if (height!=null) {
			str += '; height:'+height
			str += '; clip:rect(0,'+width+','+height+',0)'
		}
		if (bgColor!=null) str += '; background-color:'+bgColor		
		if (zIndex!=null) str += '; z-index:'+zIndex
		if (visibility) str += '; visibility:'+visibility
		str += ';">'+((content)?content:'')+'</DIV>'
		if (nestref) {
			index = nestref.lastIndexOf(".")
			var nestlyr = (index != -1)? nestref.substr(index+1) : nestref
			document.all[nestlyr].insertAdjacentHTML("beforeEnd",str);
		}
		else {
			document.body.insertAdjacentHTML("beforeEnd",str)
		}
	}
}
function destroyLayer(id,nestref) {
	if (is.ns) {
		if (nestref) eval("document."+nestref+".document."+id+".visibility = 'hide'")
		else document.layers[id].visibility = "hide"
	}
	else if (is.ie) {
		document.all[id].innerHTML = ""
		document.all[id].outerHTML = ""
	}
}

