String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
return this.replace(/(\s*$)/g, "");
}

Date.prototype.format = function(format) //author: meizz
{
  var o = {
    "M+" : this.getMonth()+1, //month
    "d+" : this.getDate(),    //day
    "h+" : this.getHours(),   //hour
    "m+" : this.getMinutes(), //minute
    "s+" : this.getSeconds(), //second
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
    "S" : this.getMilliseconds() //millisecond
  }
  if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,
      RegExp.$1.length==1 ? o[k] : 
        ("00"+ o[k]).substr((""+ o[k]).length));
  return format;
}

function GetXmlObject(){
	var a=["MSXML4.DOMDocument", "MSXML3.DOMDocument", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XmlDom"];
	var o = null;
	for(var i=0; i<a.length; i++){
		try{
			o = new ActiveXObject(a[i]);
			break;
		}catch(e){}
	}
	return o;
}

var GetNodeValue = function(obj)
{
    var str = "";
    if(window.ActiveXObject)    //IE
    {
        str = obj.text;
    }
    else //Mozilla
    {
        try
        {
            str = obj.childNodes[0].nodeValue;
        }
        catch(ex)
        {
            str = "";
        }
    }
    return str;
}

if(document.implementation && document.implementation.createDocument)
{
    XMLDocument.prototype.loadXML = function(xmlString)
    {
        var childNodes = this.childNodes;
        for (var i = childNodes.length - 1; i >= 0; i--)
            this.removeChild(childNodes[i]);

        var dp = new DOMParser();
        var newDOM = dp.parseFromString(xmlString, "text/xml");
        var newElt = this.importNode(newDOM.documentElement, true);
        this.appendChild(newElt);
    };

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var oNSResolver = this.createNSResolver(this.documentElement)
          var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
          var aResult = [];
          for( var i = 0; i < aItems.snapshotLength; i++)
          {
             aResult[i] =  aItems.snapshotItem(i);
          }
          return aResult;
       }

       // prototying the Element
       Element.prototype.selectNodes = function(cXPathString)
       {
          if(this.ownerDocument.selectNodes)
          {
             return this.ownerDocument.selectNodes(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var xItems = this.selectNodes(cXPathString, xNode);
          if( xItems.length > 0 )
          {
             return xItems[0];
          }
          else
          {
             return null;
          }
       }
       
       // prototying the Element
       Element.prototype.selectSingleNode = function(cXPathString)
       {    
          if(this.ownerDocument.selectSingleNode)
          {
             return this.ownerDocument.selectSingleNode(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

	HTMLElement.prototype.insertAdjacentHTML=function(where, html) 
	{ 
		var e=this.ownerDocument.createRange(); 
		e.setStartBefore(this); 
		e=e.createContextualFragment(html); 
		switch (where) 
		{ 
			case 'beforeBegin': this.parentNode.insertBefore(e, this);break; 
			case 'afterBegin': this.insertBefore(e, this.firstChild); break; 
			case 'beforeEnd': this.appendChild(e); break; 
			case 'afterEnd': 
			if(!this.nextSibling) this.parentNode.appendChild(e); 
			else this.parentNode.insertBefore(e, this.nextSibling); break; 
		} 
	}
}
  if(typeof(HTMLElement)!="undefined" && !window.opera)
  {   
      HTMLElement.prototype.__defineGetter__("outerHTML",function()
      {   
          var a=this.attributes, str="<"+this.tagName,   i=0;for(;i<a.length;i++)
          if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
          if(!this.canHaveChildren)   return   str+" />";
          return str+">"+this.innerHTML+"</"+this.tagName+">";
      });   
      HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
      {   
          var d = document.createElement("DIV"); d.innerHTML = s;
          for(var i=0; i<d.childNodes.length; i++)
                this.parentNode.insertBefore(d.childNodes[i], this);
          this.parentNode.removeChild(this);
      });
      HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
      {
          return   !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
      });
  }