if(typeof Error=="undefined")
{
  function Error(message)
  {
    if(message)this.message=message;
    
    if(typeof Error.__initialized=="undefined")
    { 
      Error.prototype.name="Error";
      Error.prototype.message="An unexpected error has occurred";
      Error.prototype.toString=function()
      {
        return this.name+": "+this.message;
      }      
      Error.__initialized=true;
    }
  }

  if(typeof SyntaxError=="undefined")
  {
    function SyntaxError(message)
    {
      Error.call(this,message);

      if(typeof SyntaxError.__initialized=="undefined")
      { 
        SyntaxError.prototype.name="SyntaxError";
        SyntaxError.__initialized=true;
      }
    }
  }  
  if(typeof TypeError=="undefined")
  {
    function TypeError(message)
    {
      Error.call(this,message);

      if(typeof TypeError.__initialized=="undefined")
      { 
        TypeError.prototype.name="TypeError";
        TypeError.__initialized=true;
      }
    }
  }  
}

function ArrayUtil()
{
  if (!ArrayUtil.__initialized)
  {
	ArrayUtil.indexOf=function(o)
	{ 
	  // Use: ArrayUtil.indexOf.call(myArray,o);
		var result=-1, i;
		for(i=0;i<this.length;++i)
		{
			if(this[i]==o)
			{
			result=i; break;
			}
		}
		return result;    
	}
	ArrayUtil.contains=function(o)
	{
	  // Use: ArrayUtil.contains.call(myArray,o);
		var result=false, i;
		for(i=0;!result&&i<this.length;++i)
		{
			result=(this[i]==o);
		}
		return result;    
	}
	ArrayUtil.remove=function(o)
	{
	  // Use: ArrayUtil.remove.call(myArray,o);
		var i=ArrayUtil.indexOf.call(this,o), result;
		if(result=(i>=0))
			this.splice(i,1);
		return result;
	}
    
    ArrayUtil.__initialized=true;
  }
}
new ArrayUtil();

if(typeof Node=="undefined")
{
  var Node=
    {
    ELEMENT_NODE: 1,
    ATTRIBUTE_NODE: 2,
    TEXT_NODE: 3,
    CDATA_SECTION_NODE: 4,
    ENTITY_REFERENCE_NODE: 5,
    ENTITY_NODE: 6,
    PROCESSING_INSTRUCTION_NODE: 7,
    COMMENT_NODE: 8,
    DOCUMENT_NODE: 9,
    DOCUMENT_TYPE_NODE: 10,
    DOCUMENT_FRAGMENT_NODE: 11,
    NOTATION_NODE: 12
    }
}

function Flags(value)
{
  this.value=(value)?value:0;
  if(typeof Flags.__initialized=="undefined")
  {
    Flags.prototype.includeValue=function(value)
    {
      this.value|=value;
      return this;
    }
    Flags.prototype.excludeValue=function(value)
    {
      this.value&=~value; 
      return this;
    }
    Flags.prototype.setValue=function(value)
    {
      this.value=value;
      return this;
    }
    Flags.prototype.containsValue=function(value)
    {
      return (this.value&value)==value;
    }
    Flags.__initialized=true;
  }
}
Flags.DEFAULT_VALUE=0;

function DomUtil() 
{
  this._disabled=null;
  if(typeof DomUtil.__initialized=="undefined")
  {
    DomUtil.prototype.getElementById=function(obj)
    {
      var result;
      if(typeof obj=="string")
      {
        result=document.getElementById(obj);
        if(result&&result.id!=obj)// IE6 fixup
          result=obj;
      }
      else result=obj;
      return result;        
    }
    DomUtil.prototype.getElementsByTagName=function(name)
    {
      if(name=="*"&&document.all)return document.all;// IE6 fixup
      else document.getElementsByTagName(name);
    }
    DomUtil.prototype.disableForm=function(obj)
    {
      var form=this.getElementById(obj);
      if(form.nodeName=="FORM")
      {
        for(var i=0;i<form.elements.length;++i)
          form.elements[i].disabled=true;
        form.disabled=true;
      }
    }
    DomUtil.prototype.enableForm=function(obj)
    {
      var form=this.getElementById(obj);
      if(form.nodeName=="FORM")
      {
        for(var i=0;i<form.elements.length;++i)
          form.elements[i].disabled=undefined;
        form.disabled=undefined;
      }
    }
    DomUtil.prototype.disableElement=function(obj)
    {
      var elm=this.getElementById(obj);
      if(!this._disabled)this._disabled=new Object();
      var disabledElm=this._disabled[elm.id];
      if(!disabledElm)
        this._disabled[elm.id]=new DisabledDomElement(elm);
    }
    DomUtil.prototype.enableElement=function(obj)
    {
      var disabledElm, elm=this.getElementById(obj);
      if(this._disabled)
      {
        disabledElm=this._disabled[elm.id];
        if(disabledElm)
        {
          disabledElm.restore(elm);
          this._disabled[elm.id]=undefined;
          elm.disabled=undefined;      
          if (elm.nodeName=="INPUT"&&elm.type.toUpperCase()=="CHECKBOX")
          {
            if(elm.parentNode.nodeName=="SPAN")
              elm.parentNode.disabled=undefined;
          }
        }
      }
    }
    DomUtil.prototype.getOffsetLeft=function(obj)
    {
      var elm=this.getElementById(obj);
      if(!elm)throw new SyntaxError("invalid object");
      var result=elm.offsetLeft;
      while(elm=elm.offsetParent)
      {
        result+=elm.offsetLeft;
      }
      return result;
    }
    DomUtil.prototype.getOffsetTop=function(obj)
    {
      var elm=this.getElementById(obj);
      if(!elm)throw new SyntaxError("invalid object");
      var result=elm.offsetTop;
      while(elm=elm.offsetParent)
      {
        result+=elm.offsetTop
      }
      return result;
    }
    DomUtil.prototype.getOffsetWidth=function(obj)
    {
      var elm=this.getElementById(obj);
      if(!elm)throw new SyntaxError("invalid object");
      return elm.offsetWidth;
    }
    DomUtil.prototype.getOffsetHeight=function(obj)
    {
      var elm=this.getElementById(obj);
      if(!elm)throw new SyntaxError("invalid object");
      return elm.offsetHeight;
    }
    
    DomUtil.__initialized=true;
  }
}
var DomUtil=new DomUtil();

function StringBuffer()
{
  this._buffer=new Array();
  if(typeof StringBuffer.__intialized=="undefined")
  {
    StringBuffer.prototype.append=function(s)
    {
      this._buffer.push(s);
      return this;
    }
    StringBuffer.prototype.toString=function()
    {
      return this._buffer.join("");
    }
    StringBuffer.__intialized=true;    
  }
}

function DisabledDomElement(elm)
{
  var sub, i;
  this.elmId=elm.id;
  this.elm=elm;
  if (typeof elm.disabled!="undefined")
  {
    this.disabled=elm.disabled;
    elm.disabled=true;
  }
  if (elm.onclick)
  {
    this.onclick=elm.onclick;
    elm.onclick=null;
  }
  if (elm.ondblclick)
  {
    this.ondblclick=elm.ondblclick;
    elm.ondblclick=null;
  }
  if (elm.onmouseup)
  {
    this.onmouseup=elm.onmouseup;
    elm.onmouseup=null;
  }
  if (elm.onmousedown)
  {
    this.onmousedown=elm.onmousedown;
    elm.onmousedown=null;
  }
  if (elm.onmouseover)
  {
    this.onmouseover=elm.onmouseover;
    elm.onmouseover=null;
  }
  if (elm.onmousemove)
  {
    this.onmousemove=elm.onmousemove;
    elm.onmousemove=null;
  }
  if (elm.onmouseout)
  {
    this.onmouseout=elm.onmouseout;
    elm.onmouseout=null;
  }
  if (elm.href&&elm.tagName=="A")
  {
    this.href=elm.href;
    elm.href='#__disabled__';
  }  
  if(elm.hasChildNodes())
  {
    this.childElements=new Array();
    for(i=0;i<elm.childNodes.length;++i)
    {
      if(elm.childNodes[i].nodeType==Node.ELEMENT_NODE)
      { // Recursive!        
        this.childElements[this.childElements.length]=new DisabledDomElement(elm.childNodes[i]);
      }
    }
  }
  if(typeof DisabledDomElement.__initialized=="undefined")
  {
    DisabledDomElement.prototype.restore=function(elm)
    {
      var dd, i;
      
      if (elm==this.elm)
      {
        if (this.onclick) elm.onclick=this.onclick;
        if (this.ondblclick) elm.ondblclick=this.ondblclick;
        if (this.onmouseup) elm.onmouseup=this.onmouseup;
        if (this.onmousedown) elm.onmousedown=this.onmousedown;
        if (this.onmouseover) elm.onmouseover=this.onmouseover;
        if (this.onmousemove) elm.onmousemove=this.onmousemove;
        if (this.onmouseout) elm.onmouseout=this.onmouseout;
        if (this.href) elm.href=this.href;
        if (typeof this.disabled!="undefined") elm.disabled=this.disabled;
        
        if(this.childElements)
        {
          for(i=0;i<this.childElements.length;++i)
          {
            this.childElements[i].restore(DomUtil.getElementById(this.childElements[i].elm));
          }
        }
      }
    }
    DisabledDomElement.__initialized=true;  
  }
}


