/**
	If someone can tell me why the hell mootools doesn't let people
	insert html directly in the dom....grrr. so boring....
*/

Element.HtmlToDom = function(el, html) {
	if (Browser.Engine.trident) {
		var div = document.createElement('div');
		div.innerHTML = html.stripScripts();
		var fragment = document.createDocumentFragment();		
		while (div.firstChild) { fragment.appendChild(div.firstChild); }
		return fragment;
	} else {
		var range = el.ownerDocument.createRange();
		range.selectNodeContents(el);
		range.collapse(true);
		
		return (range.createContextualFragment(html.stripScripts()));
	}
}

Element.implement({
	replace: function(content) {
		var el = Element.HtmlToDom(this, content);		
		this.parentNode.replaceChild(el, this);
		content.stripScripts(true);
	},
	
	replaceHTML: function(content) {		
		this.set('html', content);		
		content.stripScripts(true);
	},	
	
	append: function(position, content) {
		var el = Element.HtmlToDom(this, content);
		var inserter = Element.Inserters[position];
			
		inserter(el, this);
		content.stripScripts(true);
	},
	
	appendTop: function(content) { this.append('top', content); },
	
	appendBottom: function(content) { this.append('bottom', content); },
	
	appendAfter: function(content) { this.append('after', content); },
	
	appendBefore: function(content) { this.append('before', content); }	
});	


String.implement({
	
	extractId: function() {
		return this.replace(/(.*)-([0-9]+)$/, "$2")
	}
	
});