function ckDHTMLObj() {
	this.mouseX = 0; //see trackMousePosition() 
	this.mouseY = 0;

	return this;
	
}

ckDHTMLObj.prototype = {
	
	getTopPos : function(oEl) {
		var returnValue = parseInt(oEl.offsetTop);

		while((oEl = oEl.offsetParent) != null){
			if(oEl.tagName!='HTML') {
				returnValue += oEl.offsetTop;
				if(document.all)returnValue+=oEl.clientTop;
			}
		} 
		return returnValue;

	},
	
	getLeftPos : function(oEl) {
		var returnValue = parseInt(oEl.offsetLeft);
		while((oEl = oEl.offsetParent) != null){
		  	if(oEl.tagName!='HTML'){
		  		returnValue += oEl.offsetLeft;
		  		if(document.all)returnValue+=oEl.clientLeft;
		  	}
	  	}
	  	return returnValue;
	},
	
	getRightPos : function(oEl) {
		var leftPos = this.getLeftPos(oEl);
		return leftPos + (oEl.offsetWidth); //untested
	},
	
	
	hitTest : function (oTarget,mouseX, mouseY) {
		//oTarget is a reference to an HTML element on the screen
		var bHit = false;
		if (oTarget) {
			var mouseX = this.getMouseX();
			var mouseY = this.getMouseY();
			
			var leftPosEl = this.getLeftPos(oTarget);
			var topPosEl = this.getTopPos(oTarget);
			var widthEl = oTarget.offsetWidth;
			var heightEl = oTarget.offsetHeight;
			
			bHit = (mouseX > leftPosEl && mouseX < (leftPosEl + widthEl) && mouseY > topPosEl && mouseY < (topPosEl + heightEl))
		}
		return bHit;		
	},
	
	seekWithin : function(oContainer,tagName,id) {
		//given an outer container and a tagname, find the element with the specified id.  
		var oEl = null;
		if (oContainer) {
			var aEl = oContainer.getElementsByTagName(tagName.toUpperCase());
			for (var index=0; index < aEl.length; index++) {
				if (aEl[index].id==id) {
					oEl = aEl[index];
					break;
				}
			}	
		}
		return oEl;
	},
	
	seekParentTag: function(oObj,tagName) {
		if (oObj) {
			try {
				tagName = tagName.toUpperCase();
				var oParent = oObj.parentNode; //parentNode required for Firefox compatibility
				while (oParent && oParent.tagName.toUpperCase() != tagName) {
					oParent = oParent.parentNode;
				}
			
			} catch(e) {
				throwConsoleError("oDHTML.seekParentTag",e)
			}
			return oParent;
		}
	},
	
	isChildOfParentID: function(oObj,parentID) {
		var bChild = false;
		var oParent;
		if (oObj) {
			try {
				oParent = oObj.parentNode;
				while (oParent && !bChild) {
					bChild = (oParent.id == parentID) 
					oParent = oParent.parentNode;
				}		
			} catch(e) {}
		}
		return bChild;
	},

	
	_recordMousePos : function(e){
		if (!e) var e = (window.event||window.Event);

		if(typeof(e.pageX) != 'undefined') {
			oDHTML.mouseX = e.pageX; //assumes global oDHTML object
			oDHTML.mouseY = e.pageY;
		} else {
			oDHTML.mouseX = e.clientX + document.body.scrollLeft;
			oDHTML.mouseY = e.clientY + document.body.scrollTop;
		}
	},
	
	trackMousePosition : function() {
		//must be called before attempting to retrieve mouseX or mouseY properties. This is so we're not constantly tracking when we don't need to be
		//if(window.Event && document.captureEvents) document.captureEvents(Event.MOUSEMOVE); //Tell Mozilla to start listening...not needed
		addEvent(document,"mousemove",this._recordMousePos);
		
	},


	createContentFromObject : function(oTemplate,oObj) {
		//given an outer "template" container of HTML, duplicate it and fill with content from the object.  The tag "id" attributes must correspond to the object properties
		var aEl, oEl;
		var oNewResult = oTemplate.cloneNode(true);

		var aTagNames = Array("A","H1","H2","H3","DIV","IMG","SPAN","B","TD","INPUT");
		for (var tagIndex=0;tagIndex < aTagNames.length; tagIndex++) {
			aEl = oNewResult.getElementsByTagName(aTagNames[tagIndex]);

			for (var index=0; index < aEl.length; index++) {
				if ((oEl = aEl[index]) && (oObj[oEl.id])) {

					switch (aTagNames[tagIndex]) {
						case "DIV" :
						case "SPAN" : 
						case "H1" :
						case "H2" : 
						case "H3" :
						case "B" :
						case "TD" :
							if (oObj[oEl.id] != "") oEl.innerHTML = oObj[oEl.id];
							else oEl.style.display="none";
							break;
						case "INPUT" :
							if (oEl.type=="text" || oEl.type=="checkbox") oEl.value = oObj[oEl.id];
							break;
						case "IMG" :
							oEl.src = oObj[oEl.id];
							break;
						case "A" :
							if (oObj[oEl.id] != "") {
								oEl.setAttribute("href",oObj[oEl.id]);
							} else {
								oEl.removeAttribute("href");
								oEl.style.display="none";
							}
							break;
					}
					//may need to clear ID for IE who doesn't like having the same IDs all over the place??? Doesn't seem to work in IE9.  Need to test with this added
					oEl.removeAttribute("id");
				}
			}
		}
		oNewResult.style.display="block";	
						
		return oNewResult;
	},
	
	updateContent : function(oUpdates) {
		var oEl;
		var sClass;
		var aAttributes;
		var bClassChange;
		
		if (oUpdates) for (var key in oUpdates) {
			if (oEl = document.getElementById(key)) {
				if (oUpdates[key]) {
					aAttributes = oUpdates[key].split("|");
			
					switch (oEl.tagName.toUpperCase()) {
						case "DIV" :
						case "SPAN" :
						case "TD" :
						case "B" :
						case "P" :
							for (var index=0; index < aAttributes.length; index++) {
								switch (index) {
									case 0 : oEl.innerHTML = aAttributes[index];break; 
									case 1 : oEl.className = aAttributes[index];break;
									case 2 : oEl.style.display = aAttributes[index];break;
								}
							}
							break;
						case "INPUT" :
							if (oEl.type=="hidden" || oEl.type=="text") oEl.value = oUpdates[key];
							break;
						case "IMG" :
							for (var index=0; index < aAttributes.length; index++) {
								switch (index) {
									case 0 : oEl.src = aAttributes[index]; break;
									case 1 : 
										oEl.alt = aAttributes[index]; 
										oEl.title = aAttributes[index];
										break;
									case 2 : oEl.style.display=aAttributes[index]; break;
								}
							}
							break;
					}
				}
			}
		}
	}
	
	
}

