// Function extensions for DOM Objects

// XBrowser Haxies
if(navigator.vendor=="Apple Computer, Inc.")
{
   var HTMLConstructors={Html: "html", Head: "head", Link: "link", Title: "title", Meta: "meta", Base: "base", IsIndex: "isindex", Style: "style", Body: "body", Form: "form",
Select: "select", OptGroup: "optgroup", Option: "option", Input: "input",
TextArea: "textarea", Button: "button", Label: "label", FieldSet: "fieldset",
Legend: "legend", UList: "ul", OList: "ol", DList: "dl", Directory: "dir",
Menu: "menu", LI: "li", Div: "div", Paragraph: "p", Heading: "h1", Quote: "q",
Pre: "pre", BR: "br", BaseFont: "basefont", Font: "font", HR: "hr", Mod: "ins",
Anchor: "a", Image: "img", Object: "object", Param: "param", Applet: "applet",
Map: "map", Area: "area", Script: "script", Table: "table", TableCaption: "caption",
TableCol: "col", TableSection: "tbody", TableRow: "tr", TableCell: "td",
FrameSet: "frameset", Frame: "frame", IFrame: "iframe"};

   for(var i in HTMLConstructors)
      window["HTML" + i + "Element"]=document.createElement(HTMLConstructors[i]).constructor;

   function HTMLElement(){}
   HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
   var HTMLDocument = document.constructor;
   var HTMLCollection = document.links.constructor;
   var HTMLOptionsCollection = document.createElement("select").options.constructor;
   var Text = document.createTextNode("").constructor;
   var Node = Text;
}

// Make sure document.getElementById() is available
if(document.all && !document.getElementById)
{
   document.getElementById=function(id)
   {
      return document.all[id];
   }
}

// Function copies attributes/properties of passed super class to the subclass
Object.prototype.inheritsFrom=function(superClass)
{
   for(tempProperty in superClass)
      this[tempProperty]=superClass[tempProperty];
};

// Returns an array of elements whose class name contains tempClassName
document.getElementsByClassName=function(tempClassName)
{
   var elementArray=document.getElementsByTagName("*");

   var returnElements=new Array();

   for(var i=0; i<elementArray.length; i++)
      if(elementArray[i].className!="")
         if(elementArray[i].classNameExists(tempClassName))
            returnElements.push(elementArray[i]);

   return returnElements;
};

// Returns true if tempClassName exists in Element's className
Object.prototype.classNameExists=function(tempClassName)
{
   var classArray=this.className.split(" ");

   for(var i=0; i<classArray.length; i++)
      if(classArray[i]==tempClassName)
         return true;

   return false;
};

// Returns true if tempClassName is added to the Element's className
Object.prototype.addClassName=function(tempClassName)
{
   if(!this.classNameExists(tempClassName))
   {
      this.className+=" " + tempClassName;

      return true;
   }

   return false;
};

// Returns true if tempClassName was removed from Element's className
Object.prototype.removeClassName=function(tempClassName)
{
   return (this.replaceClassName(tempClassName, ""));
};

// Returns true if oldClassName was replaced with newClassName
Object.prototype.replaceClassName=function(oldClassName, newClassName)
{
   if(this.classNameExists(oldClassName))
   {
      this.className=this.className.replace(oldClassName, newClassName);

      return true;
   }

   return false;
};

// Specifically for HTMLSelectElement
Object.prototype.getIndexByValue=function(tempValue)
{
   for(var i=0; i<this.options.length; i++)
      if(this.options[i].value==tempValue)
         return i;

   return -1;
};

Object.prototype.getIndexByText=function(tempText)
{
   for(var i=0; i<this.options.length; i++)
      if(this.options[i].text==tempText)
         return i;
   
   return -1;
}

// X-Broswer overrides
if(!window.XMLHttpRequest)
{
   function XMLHttpRequest()
   {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
      try{ return new XMLHttpRequest(); } catch(e) {}

      return null;
   }
}

if(!window.addEventListener){    Object.prototype.addEventListener=function(eventType, listener, useCapture)
    {       this.attachEvent("on" + eventType, listener);    }}

/*if(!HTMLElement.prototype.removeEventListener)
{
   // Specifically for HTMLElement
   document.getElementById('body').constructor.prototype.removeEventListener=function(eventType, listener, useCapture)
   {      this.detachEvent("on" + eventType, listener);   }
}*/