﻿function __firefox(){ 
HTMLElement.prototype.__defineGetter__("runtimeStyle", __element_style); 
window.constructor.prototype.__defineGetter__("event", __window_event); 
Event.prototype.__defineGetter__("srcElement", __event_srcElement); 
} 
function __element_style(){ 
return this.style; 
} 
function __window_event(){ 
return __window_event_constructor(); 
} 
function __event_srcElement(){ 
return this.target; 
} 
function __window_event_constructor(){ 
if(document.all){ 
return window.event; 
} 
var _caller = __window_event_constructor.caller; 
while(_caller!=null){ 
var _argument = _caller.arguments[0]; 
if(_argument){ 
var _temp = _argument.constructor; 
if(_temp.toString().indexOf("Event")!=-1){ 
return _argument; 
} 
} 
_caller = _caller.caller; 
} 
return null; 
} 
if(window.addEventListener){ 
__firefox(); 
} 
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}
//FireFox Support:innerText Event
function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__(     "innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__(     "innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}


function getXmlHttp()
{
    var xmlObj = null;
    try{
            xmlObj = new ActiveXObject("Msxml2.XmlHttp"); 
        } catch(error){
                            try{
                                    xmlObj = new ActiveXObject("Microsoft.XmlHttp");
                                }catch(error1){
                                                    try{
                                                            xmlObj = new XMLHttpRequest();
                                                          }catch(error2){alert("Your Browser Cant Support This Ajax Frame!");this.close();return;}
                                                    }}
    return xmlObj;
} 


function loadXML(xmlSource)
{
        var doc;
        // IE
        if (window.ActiveXObject)
        {
                doc = new ActiveXObject("Microsoft.XMLDOM");
                doc.async=false;
                try{
                   doc.loadXML(xmlSource);
                 }catch(e){
                     var oParser=new DOMParser();
                     doc=oParser.parseFromString(xmlSource,"text/xml");
                 }
                return doc;
        }
        //    Mozilla
        else if (document.implementation &&  document.implementation.createDocument)
        {
            doc= document.implementation.createDocument("","",null);
            try{
                   doc.loadXML(xmlSource);
                 }catch(e){
                     var oParser=new DOMParser();
                     doc=oParser.parseFromString(xmlSource,"text/xml");
                 }
           return doc;
        }
        else
        {
            alert('Your Browser Cant Support This Ajax Frame!');
        }
        return doc; 
}
function  parseXML(st){
        if (isIE()){
            var  result  =   new  ActiveXObject( " microsoft.XMLDOM " );
            result.loadXML(st);
        } else {
                        var  parser  =   new  DOMParser();
                        var  result  =  parser.parseFromString(st,  " text/xml " );
                    }
        return  result;
}
if(!isIE())
{
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";}
   }
}
}
function $(objName)
{
    return document.getElementById(objName);
} 



