function $E(data) {
	var el;
	if ('string'==typeof data) {
		el=document.createTextNode(data);
	} else {
		el=document.createElement(data.tag);
		delete(data.tag);

		if ('undefined'!=typeof data.children) {
			if ('string'==typeof data.children ||
				'undefined'==typeof data.children.length
			) {
				el.appendChild($E(data.children));
			} else {
				for (var i=0, child=null; 'undefined'!=typeof (child=data.children[i]); i++) {
					el.appendChild($E(child));
				}
			}
			delete(data.children);
		}

		for (attr in data) {
			el[attr]=data[attr];
		}
	}

	return el;
}

Object.extend(String.prototype, {

	stripTags : function(include) {
		var extra;

		if (include) {
		    if (typeof include == 'object' && include.constructor == Array) {
		        extra = include.join('|');
		    } else if (typeof include == 'string') {
				extra = include;
			}
		}
		return this.replace(new RegExp('(<\\/?' + (extra ? '\\b(' + extra + ')\\b' : '') + '[^>]*>)', 'gi'), '');
	},

	trim: function(nbsp) {
		return this.replace(new RegExp('^[\s'+(nbsp?'\xA0':'')+']+', 'g'),'').replace(new RegExp('[\s'+(nbsp?'\xA0':'')+']+$', 'g'),'');
	}

});

function getParent(child, targetTag) {
	if (child == null) { return null; }

	if (typeof targetTag == 'object' && targetTag.constructor == Array) { //array
		targetTag = targetTag.join('|');
	} else if (typeof targetTag == 'object' && !targetTag) { //null
		return child.parentNode;
	}

	if (child.nodeType == 1 && child.tagName.match(new RegExp('^('+targetTag+')$','i'))) { return child; }
	else { return getParent(child.parentNode, targetTag); }
}
