//<script language="javascript">
/*=============================================================================
 WebSolvers Framework Library
 Copyright 2003, WebSolvers, Inc., All Rights Reserved.

 Library Browser
 Cross-Browser/Platform common browser library

 Revision History:
 6-26-03 Created

 Requires
	Library.js

  Notes:
	Aterntate DHTML functions to use.
		[document].getElement replaces .getElementById
		[document].newElement replaces .createElement
		[document].newFragment replaces .createDocumentFragment
		[element].replaceElem replaces .replaceChild
		[element].appendElem replaces .appendChild
		[element].getAttribute
		[element].setAttribute
		[element].getClass
		[element].setClass
		[element].getEvent
		[element].setEvent
		[element].clearEvent
=============================================================================

 The WebSolvers Framework Library may be used and/or modified by anyone owning
 the original work as it was incorporated into an original development project
 so long as this copyright notice and the comments above remain intact.

 By using this code you agree to indemnify WebSolvers, Inc. from any liability
 that might arise from its use.

 This code may not be sold exclusively or as a part of other code without prior
 written consent and is expressly forbidden.

 Obtain permission before redistributing this software over the Internet or
 in any other medium. In all cases the copyright and header must remain intact.
============================================================================= */

//======================================================================================
//                                 Internal Routines
//======================================================================================

// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

function bdhtml_NormDoc(doc) {
	if(!doc.parentWindow)
		doc.parentWindow = doc.root.parentWindow;

	if(!doc.getElement)
		doc.getElement = docObject_GetElement;

	if(!doc.newElement)
		doc.newElement = docObject_NewElement;

	if(!doc.newFragment)
		doc.newFragment = docObject_NewFrag;
}

function bdhtml_Norm(elem) {
	if(elem.nodeType && elem.nodeType != 1 && elem.nodeType != 11)
		return;

	if(!elem.getAttribute)
		elem.getAttribute = elemObject_GetAttribute;
	if(!elem.setAttribute)
		elem.setAttribute = elemObject_SetAttribute;

	if(!elem.getClass)
		elem.getClass = elemObject_GetClass;
	if(!elem.setClass)
		elem.setClass = elemObject_SetClass;

	if(!elem.getEvent)
		elem.getEvent = elemObject_GetEvent;
	if(!elem.setEvent)
		elem.setEvent = elemObject_SetEvent;
	if(!elem.clearEvent)
		elem.clearEvent = elemObject_ClearEvent;
}

function dhtmlObject_Container(elem) {
	var ep = elem.getParent();
	var frag = null;
	var child = null;
	var nchild = null;

	if(this.IE) {
		frag = elem.document.newElement("SPAN");
		for(child = 0; child < elem.attributes.length; child++)
			frag.setAttribute(elem.attributes[child].nodeName, elem.attributes[child].nodeValue);

		child = elem.nextSibling;
		while(child.nodeName.toUpperCase() != '/' + elem.nodeName.toUpperCase()) {
			nchild = child.nextSibling;
			frag.appendElem(ep.removeChild(child));
			child = nchild;
		}

		ep.replaceElem(frag, elem);
		ep.removeChild(child);
	} else
		frag = elem;

	return frag;
}

function dhtmlObject_ProcAlign(align) {
	var i = parseInt(align);

	if(isNaN(i)) {
		i = -1;
		if(align && align.length) {
			switch(align.substring(0, 1).toLowerCase()) {
			case "c":
			case "m":
				i = 0;
				break;
			case "r":
			case "b":
			case "d":
			case "v":
				i = 1;
				break;
			}
		}
	} else if(i < -1)
		i = -1;
	else if (i > 1)
		i = 1;

	return i;
}

function docObject_GetElement(id, cascade) {
	var elem = null;
	var i = 0;

	if(dhtml.NN4) {
		elem = this.layers[id];
		if(elem)
			dhtml.normalize(elem, this);
		else if(cascade || cascade != false || cascade != 0) {
			for(i = 0; i < this.layers.length && !elem; i++)
				elem = dhtml.normDoc(this.layers[i].document).getElement(id, true);
		}
	} else if(dhtml.DOM) {
		elem = this.getElementById(id);
		if(elem)
			elem = dhtml.normalize(elem, this);
	}

	return elem;
}

function docObject_NewElement(name) {
	var elem = null;
	var param = new Array();

	if(dhtml.DOM) {
		switch(name.toLowerCase()) {
		case "input":
			if(docObject_NewElement.arguments.length > 1)
				param[0] = docObject_NewElement.arguments[1];
			else
				param[0] = "text";

			if(dhtml.mozilla) {
				elem = this.createElement("input");
				elem.type = param[0];
			} else
				elem = this.createElement('<INPUT TYPE="' + param[0] + '">');
			break;
		case "iframe":
			if(docObject_NewElement.arguments.length > 1)
				param[0] = docObject_NewElement.arguments[1];
			else
				param[0] = "newIFrame";

			if(docObject_NewElement.arguments.length > 2)
				param[1] = docObject_NewElement.arguments[2];
			else
				param[1] = param[0];

			if(dhtml.mozilla) {
				elem = this.createElement("iframe");
				elem.id = param[0];
				elem.name = param[1];
			} else if(dhtml.ID && dhtml.major == 5) {
				elem = this.createElement("DIV");
				elem.style.display = "none";
				this.body.appendChild(elem);
				elem.innerHTML = '<IFRAME NAME="' + param[1] + '" ID="' + param[0] + '"></IFRAME>';
				this.body.removeChild(elem);
				elem = elem.removeChild(elem.firstChild);
			} else
				elem = this.createElement('<IFRAME NAME="' + param[1] + '" ID="' + param[0] + '"></IFRAME>');
			break;
		default:
			elem = this.createElement(name);
		}
	}

	if(elem)
		elem = dhtml.normalize(elem, this);

	return elem;
}

function docObject_NewFrag() {
	var frag = null;

	if(dhtml.mozilla)
		frag = this.newElement("SPAN");
	else
		frag = dhtml.normalize(this.createDocumentFragment(), this);

	if(frag)
		frag._dhtmlFrag = true;

	return frag;
}

function elemObject_GetAttribute(name) {
	var i = 0;

	if(this.attributes) {
		for(i = 0; i < this.attributes.length; i++)
			if(this.attributes[i].nodeName == name)
				return this.attributes[i].nodeValue;
	} else if(this[name])
		return this[name];
	else
		return null;
}

function elemObject_SetAttribute(name, value) {
	var i = 0;
	if(this.attributes) {
		for(i = 0; i < this.attributes.length; i++)
			if(this.attributes[i].nodeName == name)
				this.attributes[i].nodeValue = value;
	} else
		this[name] = value;
}

function elemObject_GetClass() {
	if(this.className)
		return this.className;
	else
		return this.getAttribute("class");
}

function elemObject_SetClass(value) {
	if(this.className)
		this.className = value;
	else
		this.setAttribute("class", value);
}

function elemObject_GetEvent(name) {
	if(dhtml.IE || dhtml.mozilla)
		return eval("this.on" + name.toLowerCase());
	else if(dhtml.NN4 && this._layer)
		return eval("this.on" + name.toLowerCase());
	else
		return eval("this.on" + name.toLowerCase());
}

function elemObject_SetEvent(name, func) {
	if(!func)
		this.clearEvent(name);
	if(dhtml.IE)
		eval("this.on" + name.toLowerCase() + "=func");
	else if(dhtml.mozilla)
		this.addEventListener(name.toLowerCase(), func, false);
	else if(dhtml.NN4 && eval("Event." + name.toUpperCase())) {
		if(this._layer) {
			eval("this.captureEvents(Event." + name.toUpperCase() + ");");
		}
		eval("this.on" + name.toLowerCase() + "=func");
	}
}

function elemObject_ClearEvent(name) {
	if(dhtml.IE)
		eval("this.on" + name.toLowerCase() + "=null");
	else if(dhtml.mozilla)
		this.removeEventListener(name.toLowerCase());
	else if(dhtml.NN4) {
		eval("this.document.releaseEvents(Event." + name.toUpperCase() + ");");
		eval("this.document.on" + name.toLowerCase() + "=null");
	}
}

//======================================================================================
//                                Initialization code
//======================================================================================
if(dhtml) {
	dhtml.addNormDoc(bdhtml_NormDoc);
	dhtml.addNorm(bdhtml_Norm);
	dhtml._quickNorm = bdhtml_Norm;
}
