// functions for compatibility

var emptyElements = {HR: true, BR: true, IMG: true, INPUT: true};
var specialElements = {TEXTAREA: true};

function setInnerText(sText)
{
	return String(sText).replace(/\&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<BR>");
}

function getInnerText(myDOM)
{
	if(myDOM.innerText)
		return myDOM.innerText;
   var r = myDOM.ownerDocument.createRange();
   r.selectNodeContents(myDOM);
   return r.toString();
}

function getOuterHTML(node)
{
	if(node.outerHTML)
		return node.outerHTML;
		
	var html = '';
	switch (node.nodeType)
	{
		case Node.ELEMENT_NODE:
			html += '<';
		      html += node.nodeName;
		      if (!specialElements[node.nodeName])
		      {
				for (var a = 0; a < node.attributes.length; a++)
					html += ' ' + node.attributes[a].nodeName.toUpperCase() + '="' + node.attributes[a].nodeValue + '"';
        			
        			if (!emptyElements[node.nodeName])
        			{
        				html += '>';
          				html += node.innerHTML;
					html += '<\/' + node.nodeName + '>';
        			}
        			else
        			{
					html += '/>';
        			}
      		}
			else switch (node.nodeName)
			{
			  case 'TEXTAREA':
			    for (var a = 0; a < node.attributes.length; a++)
				if (node.attributes[a].nodeName.toLowerCase() != 'value')
				  html += ' ' + node.attributes[a].nodeName.toUpperCase() + '="' + node.attributes[a].nodeValue + '"';
				else
				  var content = node.attributes[a].nodeValue;
			    html += '>';
			    html += content;
			    html += '<\/' + node.nodeName + '>';
			    break;
			}
		break;
  	  case Node.TEXT_NODE:
	      html += node.nodeValue;
	      break;
  	  case Node.COMMENT_NODE:
		html += '<!' + '--' + node.nodeValue + '--' + '>';
		break;
  	}
  	return html;
}

Array.prototype.exists = function (x)
{
    for (var i = 0; i < this.length; i++) {
        if (this[i] == x) return true;
    }
    return false;
}

Array.prototype.remove = function(x)
{
   for (var i = 0; i < this.length; i++)
   {
   	if (this[i] == x)
   		return this.splice(i,1);
   }
   return this;
}