if(window.Event){//
    /*
				IE5	   MacIE5	 Mozilla	Konqueror2.2	    Opera5
    event			 yes	    yes		   yes		  yes			 yes
    event.returnValue		 yes	    yes		   no		 no		       no
    event.cancelBubble		  yes	     yes	    no		  no			no
    event.srcElement		yes	   yes		  no		no		      no
    event.fromElement		 yes	    yes		   no		 no		       no

    */
    Event.prototype.__defineSetter__("returnValue",function(b){
	if(!b)this.preventDefault();
	return b;
	});
    Event.prototype.__defineSetter__("cancelBubble",function(b){
	if(b)this.stopPropagation();
	return b;
	});
    Event.prototype.__defineGetter__("srcElement",function(){
	var node=this.target;
	//while(node.nodeType!=1)node=node.parentNode;
	return node;
	});
    Event.prototype.__defineGetter__("fromElement",function(){
	var node;
	if(this.type=="mouseover")
	    node=this.relatedTarget;
	else if(this.type=="mouseout")
	    node=this.target;
	if(!node)return;
	while(node.nodeType!=1)node=node.parentNode;
	return node;
	});
    Event.prototype.__defineGetter__("toElement",function(){
	var node;
	if(this.type=="mouseout")
	    node=this.relatedTarget;
	else if(this.type=="mouseover")
	    node=this.target;
	if(!node)return;
	while(node.nodeType!=1)node=node.parentNode;
	return node;
	});
    Event.prototype.__defineGetter__("offsetX",function(){
	return this.layerX;
	});
    Event.prototype.__defineGetter__("offsetY",function(){
	return this.layerY;
	});
    }
if(window.Document){
    /*
				IE5	   MacIE5	 Mozilla	Konqueror2.2	    Opera5
    document.documentElement	yes	   yes		  yes		 yes			no
    document.activeElement	  yes	     null	 no	       no		     no

    */
    }
if(window.Node){// \u4FEE\u6B63Node\u7684DOM
    /*
				IE5	   MacIE5	 Mozilla	Konqueror2.2	    Opera5
    Node.contains		 yes	    yes		   no		 no		       yes
    Node.replaceNode		yes	   no		 no	       no		     no
    Node.removeNode		   yes	      no	    no		  no			no
    Node.children		 yes	    yes		   no		 no		       no
    Node.hasChildNodes		  yes	     yes	    yes		   yes			  no
    Node.childNodes		   yes	      yes	     yes	    yes			   no
    Node.swapNode		 yes	    no		  no		no		      no
    Node.currentStyle		 yes	    yes		   no		 no		       no

    */
    Node.prototype.replaceNode=function(Node){// \u66FF\u6362\u6307\u5B9A\u8282\u70B9
	this.parentNode.replaceChild(Node,this);
	}
    Node.prototype.removeNode=function(removeChildren){// \u5220\u9664\u6307\u5B9A\u8282\u70B9
	if(removeChildren)
	    return this.parentNode.removeChild(this);
	else{
	    var	range=document.createRange();
	    range.selectNodeContents(this);
	    return this.parentNode.replaceChild(range.extractContents(),this);
	    }
	}
    Node.prototype.swapNode=function(Node){// \u4EA4\u6362\u8282\u70B9
	var nextSibling=this.nextSibling;
	var parentNode=this.parentNode;
	node.parentNode.replaceChild(this,Node);
	parentNode.insertBefore(node,nextSibling);
	}
    }
if(window.HTMLElement){
  HTMLElement.prototype.__defineGetter__("all2",function(){
	var a=this.getElementsByTagName("*");
	var node=this;
	a.tags=function(sTagName)
	{
	  return node.getElementsByTagName(sTagName);
	}
	return a;
});
	
  HTMLElement.prototype.__defineGetter__("parentElement",function(){
	if(this.parentNode==this.ownerDocument)return null;
	return this.parentNode;
	});
    HTMLElement.prototype.__defineGetter__("children",function(){
	var tmp=[];
	var j=0;
	var n;
	for(var	i=0;i<this.childNodes.length;i++){
	    n=this.childNodes[i];
	    if(n.nodeType==1){
		tmp[j++]=n;
		if(n.name){
		    if(!tmp[n.name])
			tmp[n.name]=[];
		    tmp[n.name][tmp[n.name].length]=n;
		    }
		if(n.id)
		    tmp[n.id]=n;
		}
	    }
	return tmp;
	});
    HTMLElement.prototype.__defineGetter__("currentStyle", function(){
	return this.ownerDocument.defaultView.getComputedStyle(this,null);
	});
    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__("outerHTML",function(){
	var attr;
	var 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+">";
	});
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
	switch(this.tagName.toLowerCase()){
	    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.__defineSetter__("innerText",function(sText){
	var parsedText=document.createTextNode(sText);
	this.innerHTML=parsedText;
	return parsedText;
	});
    HTMLElement.prototype.__defineGetter__("innerText",function(){
	var r=this.ownerDocument.createRange();
	r.selectNodeContents(this);
	return r.toString();
	});
    HTMLElement.prototype.__defineSetter__("outerText",function(sText){
	var parsedText=document.createTextNode(sText);
	this.outerHTML=parsedText;
	return parsedText;
	});
    HTMLElement.prototype.__defineGetter__("outerText",function(){
	var r=this.ownerDocument.createRange();
	r.selectNodeContents(this);
	return r.toString();
	});
    HTMLElement.prototype.attachEvent=function(sType,fHandler){
	var shortTypeName=sType.replace(/on/,"");
	fHandler._ieEmuEventHandler=function(e){
	    window.event=e;
	    return fHandler();
	    }
	this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
	}
    HTMLElement.prototype.detachEvent=function(sType,fHandler){
	var shortTypeName=sType.replace(/on/,"");
	if(typeof(fHandler._ieEmuEventHandler)=="function")
	    this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
	else
	    this.removeEventListener(shortTypeName,fHandler,true);
	}
    HTMLElement.prototype.contains=function(Node){
	do if(Node==this)return	true;
	while(Node=Node.parentNode);
	return false;
	}
    HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
      var obj;
	switch(where){
	    case "beforeBegin":
		obj=this.parentNode.insertBefore(parsedNode,this);
		break;
	    case "afterBegin":
		obj=this.insertBefore(parsedNode,this.firstChild);
		break;
	    case "beforeEnd":
		obj=this.appendChild(parsedNode);
		break;
	    case "afterEnd":
		if(this.nextSibling)
		    obj=this.parentNode.insertBefore(parsedNode,this.nextSibling);
		else
		    obj=this.parentNode.appendChild(parsedNode);
		break;
	    }
	    return obj;
	}
    HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){
	var r=this.ownerDocument.createRange();
	r.setStartBefore(this);
	var parsedHTML=r.createContextualFragment(htmlStr);
	this.insertAdjacentElement(where,parsedHTML);
	}
    HTMLElement.prototype.insertAdjacentText=function(where,txtStr){
	var parsedText=document.createTextNode(txtStr);
	this.insertAdjacentElement(where,parsedText);
	}
    HTMLElement.prototype.attachEvent=function(sType,fHandler){
	var shortTypeName=sType.replace(/on/,"");
	fHandler._ieEmuEventHandler=function(e){
	    window.event=e;
	    return fHandler();
	    }
	this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
	}
    HTMLElement.prototype.detachEvent=function(sType,fHandler){
	var shortTypeName=sType.replace(/on/,"");
	if(typeof(fHandler._ieEmuEventHandler)=="function")
	    this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
	else
	    this.removeEventListener(shortTypeName,fHandler,true);
	}

  HTMLElement.prototype.all=function(sID)
  {
    var oElements=this.getElementsByTagName("*");
    var oArr = new Array();
    for(var i=0; i<oElements.length;++i)
    {
      if(oElements[i].id == sID || oElements[i].name==sID)
        oArr[oArr.length] = oElements[i];
    }
    if(oArr.length==1)
      return oArr[0];
    else
    if(oArr.length>1)
      return oArr;
    else
      return null;
	}
}
if(window.HTMLElement)  //firefox
{
    HTMLSelectElement.prototype.optionss=function(optext)
    {
      for(var i=0; i<this.length; ++i)
      {
        if(this.options[i].text == optext)
          return this.options[i];
      }
      return false;
    }
	  XMLDocument.prototype.__defineGetter__("xml", function ()
		{
			return (new XMLSerializer()).serializeToString(this);
		});
	  Element.prototype.__defineGetter__("xml", function ()
		{
			return (new XMLSerializer()).serializeToString(this);
		});		
		
	  XMLDocument.prototype.loadXML=function(str_url)
		{
		  // parse the string to a new doc
		  var doc2 = (new DOMParser()).parseFromString(str_url, "text/xml");
		  // remove all initial children
		  while (this.hasChildNodes())
		  {
		  	this.removeChild(this.lastChild);
		  }
		  // insert and import nodes
		  for (var i = 0; i < doc2.childNodes.length; i++)
		  {
		  	this.appendChild(this.importNode(doc2.childNodes[i], true));
		  }
		  try
		  {
		  	doc2.childNodes[0].xml;
		  	return true;
		  }
		  catch (ex)
		  {
		  	return false;
		  }
		};
	  XMLDocument.prototype.createNode = function (stype, name, ns)
	  {
      if(stype=="element")
          return (ns == null || ns == "") ? this.createElement(name)
          	: this.createElementNS(ns, name);
      else if(stype=="attribute")
      		return (ns == null || ns == "") ? this.createAttribute(name)
          	: this.createAttributeNS(ns, name);
      else
          return this.createTextNode("");
    }

  XMLDocument._mozHasParseError = function (oDoc)
  {
      return (!oDoc.documentElement) ||
      	oDoc.documentElement.localName == "parsererror"
      		&& oDoc.documentElement.getAttribute("xmlns") ==
      			"http://www.mozilla.org/newlayout/xml/parsererror.xml";
  }

  XMLDocument.prototype.__defineGetter__("parseError", function ()
  	{
			var hasError = XMLDocument._mozHasParseError(this);
			var res = {errorCode:0, filepos:0, line:0, linepos:0, reason:"", srcText:"", url:""};
			if (hasError)
			{
				res.errorCode= -1;
				try
				{
					res.srcText = this.getElementsByTagName("sourcetext")[0].firstChild.data;
					res.srcText = res.srcText.replace(/\n\-\^$/, "");
				}
				catch (ex)
				{
					res.srcText = "";
				}
				try
				{
					var s = this.documentElement.firstChild.data;
					res.reason = s;
					//var re = /XML Parsing Error\:(.+)\nLocation\:(.+)\nLine Number(\d+)\,Column(\d+)/;
					//var a = re.exec(s);
					//res.reason = a[1];
					//res.url=a[2];
					//res.line=a[3];
					//res.linepos=a[4];
				}
				catch (ex)
				{
					res.reason = "uknown";
				}
			}
			return res;
		});
  // 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";}
    }
    // 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";}
    }
  }

}

