﻿// JScript 文件
var IsIE = false;
if (window.ActiveXObject){ 
     IsIE = true; 
}

function newXMLHttpRequest()
{
  var xmlreq = false;
  if (window.XMLHttpRequest)
  {
    // 在非Microsoft浏览器中创建XMLHttpRequest对象
    xmlreq = new XMLHttpRequest();   
  } 
  else if (window.ActiveXObject)
  {
    //通过MS ActiveX创建XMLHttpRequest
    try
    {
      // 尝试按新版InternetExplorer方法创建
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    }
     catch (e1)
     {
      // 创建请求的ActiveX对象失败
      try
       {
        // 尝试按老版InternetExplorer方法创建
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      }
       catch (e2)
       {
        // 不能通过ActiveX创建XMLHttpRequest
      }
    }
  }
  return xmlreq;
}

function Ajax_getNodes(parentNode, path)
{
	if (parentNode == null)
		return null;
    else if(IsIE)
        return parentNode.selectNodes(path);
    else
        return parentNode.getElementsByTagName(path);
}

function Ajax_getNode(parentNode, path)
{
	if (parentNode == null)
		return null;
    else if(IsIE)
        return parentNode.selectSingleNode(path);
    else
        return parentNode.getElementsByTagName(path)[0];
}

function Ajax_GetNodeText(node)
{
	if (node == null)
		return "";
    else if(IsIE)
        return node.text;
    else
        return node.textContent;
}

function Ajax_GetNodeAttribute(node, attributeName)
{
	if (node == null)
		return "";
    var attribute = node.getAttributeNode(attributeName);
    if (attribute != null)
    	return attribute.value;
   	else
   		return "";
}

function $(id)
{
    return document.getElementById(id);
}

String.prototype.trim = function() 
{ 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}  

