﻿
// outer element prototypes for mozilla

OuterHtmlPrototype();


function OuterHtmlPrototype()
{
		// This function is used to generate a html string for the text properties/methods
		// It replaces '\n' with "<BR"> as well as fixes consecutive white spaces
		// It also repalaces some special characters
		function convertTextToHTML(s) {
			s = s.replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<BR>");
			while (/\s\s/.test(s))
				s = s.replace(/\s\s/, "&nbsp; ");
			return s.replace(/\s/g, " ");
		}



		HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
			 var r = this.ownerDocument.createRange();
			 r.setStartBefore(this);
			 var df = r.createContextualFragment(sHTML);
			 this.parentNode.replaceChild(df, this);

			 return sHTML;
		});

		HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
			switch (this.tagName) {
				case "AREA":
				case "BASE":
				case "BASEFONT":
				case "COL":
				case "FRAME":
				case "HR":
				case "IMG":
				case "BR":
				case "INPUT":
				case "ISINDEX":
				case "LINK":
				case "META":
				case "PARAM":
					return false;
			}
			return true;
		});

		HTMLElement.prototype.__defineGetter__("outerHTML", function () {
			var attr, attrs = this.attributes;
			var str = "<" + this.tagName;
			for (var i = 0; i < attrs.length; i++) {
				attr = attrs[i];
				if (attr.specified)
					str += " " + attr.name + '="' + attr.value + '"'; 
			}
			if (!this.canHaveChildren)
				return str + ">";

			return str + ">" + this.innerHTML + "</" + this.tagName + ">";
		});	
		
}
/////////////////
