if(!nmdgf.dom) {
	nmdgf.dom = {};
}else if(typeof nmdgf.dom !== 'object'){
	throw new Error('nmdgf.dom has already been initialized, and is not an object');
}

nmdgf.dom = {

	_animState : {},

	focusableTags : {
		"button" :true,
		"select" :true,
		"textarea" :true,
		"input" :true,
		"iframe" :true
	},

	disable : function(id) {
		var el = nmdgf.byId(id);
		el.disabled = true;
		nmdgf.addClass(el, 'readonly');
	},

	enable : function(id) {
		var el = nmdgf.byId(id);
		el.disabled = false;
		nmdgf.removeClass(el, 'readonly');
	},

	getListAttributeOrdered : function(listId, attribute) {
		var itemIds = [];
		var items = nmdgf.byId(listId).getElementsByTagName('li');
		for ( var i = 0; i < items.length; i++) {
			var choiceId = items[i].getAttribute(attribute);
			if (choiceId !== undefined) {
				itemIds.push(choiceId);
			}
		}
		return itemIds;
	},

	evaluateScripts : function(html) {
		var re = /<script\b.*?>([\s\S]*?)<\//ig;
		var match;

		while (match = re.exec(html)) {
			eval(match[1]);
		}
	},

	createNodeFromString : function(string) {
		var newNode = document.createElement('div');
		newNode.innerHTML = string;
		var child = YAHOO.util.Dom.getFirstChild(newNode);
		var newNode = null;
		return child;
	},

	focusFirstInput : function(root) {
		var el = nmdgf.dom.getFirstDescendantBy(root, function(el) {
			return nmdgf.dom.isFocusable(el);
		});
		if (el != null) {
			try {
				el.focus();
			} catch (exception) {
				// Ignore focus exception
			}

		}
	},

	isFocusable : function(el) {
		return el.focus && el.type !== "hidden" && !el.disabled
				&& nmdgf.dom.focusableTags[el.tagName.toLowerCase()];
	},

	getFirstDescendantBy : function(rootEl, method) {
		return YAHOO.util.Dom.getElementBy(method, '*', rootEl);
	},

	isVisible : function(el) {
		return nmdgf.byId(el).style.display != 'none';
	},

	show : function(el, animate) {
		animate = animate || false;
		el = nmdgf.byId(el);

		if(animate) {
			var og,
				anim,
				state = this._animState,
				og = state[el.id] || {};

			if(og.animating !== true) {
				anim = new YAHOO.util.Anim(el, {
					height: { from: 0, to: og.height }
				}, .5, YAHOO.util.Easing.easeIn);
				anim.onComplete.subscribe(function() {
					el.style.overflow = og.overflow;
					state[el.id].animating = false;
				});
				el.style.display = '';
				state[el.id].animating = true;
				anim.animate();
			}
		}else if(el) {
			el.style.display = '';
		}
	},

	hide : function(el, animate) {
		animate = animate || false;
		el = nmdgf.byId(el);

		if(el && animate) {
			var region,
				height,
				anim,
				state = this._animState,
				og = state[el.id] || {};

			if(og.animating !== true) {
				region = YAHOO.util.Region.getRegion(el);

				state[el.id] = {
					height : region.height,
					overflow : el.style.overflow,
					animating : false
				};

				anim = new YAHOO.util.Anim(el, {
					height: { to: 0 }
				}, .5, YAHOO.util.Easing.easeOut);
				el.style.overflow = 'hidden';
				anim.onComplete.subscribe(function() {
					el.style.display = 'none';
					state[el.id].animating = false;
				});
				state[el.id].animating = true;
				anim.animate();
			}
		}else if(el) {
			el.style.display = 'none';
		}
	},

	htmlEntityDecode : function(val) {
		var txtArea = document.createElement('textarea');
		txtArea.innerHTML = val.replace(/</g,"<").replace(/>/g,">");
		val = txtArea.value;
		txtArea = null;
		return val;
	},

	removeElement : function(el) {
		el.parentNode.removeChild(el);
	}

};

