﻿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";}
       }
    }
}

var moz = (typeof document.implementation != 'undefined')   && (typeof document.implementation.createDocument != 'undefined'); 
var ie = (typeof window.ActiveXObject != 'undefined');
var XMLHttpRequesta = function()
{
	var A=null;
	try
	{
	A=new ActiveXObject("Msxml2.XMLHTTP")
	} catch(e) { 
	try
	{
	A=new ActiveXObject("Microsoft.XMLHTTP")
	} catch(oc) {
	A=null
	}
	}
	if ( !A && typeof XMLHttpRequest != "undefined" ) 
	{
	A=new XMLHttpRequest()
	}
	return A
}
function getHttpHtml(url)
{
	var myGet=new XMLHttpRequesta();
	myGet.open("GET",url,false);
	myGet.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
	myGet.send(null);
	return myGet.responseText;
}

function getUsedHits()
{
	var tNum = getHttpHtml("/app/Count/index.asp?"+Math.random());
	var re = /^[0-9]+.?[0-9]*$/;   //判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/   
     if (!re.test(tNum)) tNum = 0;
	SetHtml("UsedHits",tNum)
}

function getXml(url)
{
	var myGet=new XMLHttpRequesta();
	if (moz)
	{
		  var oDoc = document.implementation.createDocument("text/xml", "", null);
	}
    else if (ie)
    {
      var oDoc = new ActiveXObject("MSXML2.DOMDocument");
      oDoc.async = false;   while( oDoc.readyState != 4) {};//创建IE下XML文档对象 } 
      
    }
	myGet.open("GET",url,false);
	myGet.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
	myGet.send(null);
	oDoc.loadXML(myGet.responseText);
	return oDoc;
}


function loadXML(fileName) {
 // 定义一个xml dom对象
 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async = false
 xmlDoc.load(fileName);
 
 return xmlDoc;
}

function GetXmlDoc(url,post){
	var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
	var oDoc = new ActiveXObject("MSXML2.DOMDocument");
	oHttpReq.open("post", url+post, false);
	var number = Math.random();
	oHttpReq.send("random="+number);
	result = oHttpReq.responseText;			
	oDoc.loadXML(result);
	return oDoc;
}



function SetHtml(elementId,innerHtml,showLength)
{
	if(showLength)
	{
		if(document.getElementById(elementId))
		{
			document.getElementById(elementId).innerHTML=innerHtml.left(showLength);
				document.getElementById(elementId).title=innerHtml;
		}
	}
	else
	{
		if(document.getElementById(elementId))
			document.getElementById(elementId).innerHTML=innerHtml;
	}
}

function GetParam(param){
	var strUrl=window.location.href;
	strUrl=strUrl.replace('#','');
	var pos=strUrl.indexOf('?');
	strPost=strUrl.substring(pos+1,strUrl.length);
	strPost='&'+strPost;
	strPost=strPost.toLowerCase();
	param=param.toLowerCase();
	var start=strPost.indexOf('&'+param+'=');
	if(start==-1)
		return "";
	strPost=strPost.substring(start+param.length+2,strPost.length);
	var end=strPost.indexOf('&');
	if(end==-1)
		end=strPost.length;
	return strPost.substring(0,end);
}
