
String.prototype.trim=function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }
  return elements;
}
function $n()
{
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementsByName(element);

    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

//得到obj 在整个文档的LEFT
function $X(inputObj)
{
      var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
	  }
	  return returnValue;
}
//得到obj 在整个文档的TOP
function $Y(inputObj)
{
      var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null){
	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
	  }
	  return returnValue;
}
var Tools=new Object();
Tools.Com={
    hide:function()
    {
        for(var i=0;i<arguments.length;i++)
        {
            var item=$(arguments[i])
            if(item)
            {
                item.style.display="none";
            }
        }
    },
    show:function()
    {
        for(var i=0;i<arguments.length;i++)
        {
            var item=$(arguments[i])
            if(item)
            {
                item.style.display="";
            }
        }
    },
    //删除某元素的所有子结点
    removeChildAll:function()
    {
      for(var i=0;i<arguments.length;i++)
        {
            var obj=$(arguments[i]);
            if(!obj)
                continue;
            var k=obj.childNodes[0];
            while(k)
            {
                var next=k.nextSibling;
                obj.removeChild(k);
                k=next;
            }
        }
  
    },
    //得到某个x,y下的某个元素
    getObjXY:function(element,x,y)
    {
        if(!Position.within(element,x,y))
        {
            return false;
        }
        var obj=element;
        var tempobj=false;
        while(obj)
        {
            var iscontinue=false;
            for(var i=0;i<obj.childNodes.length;i++)
            {
                var temp_c=obj.childNodes[i];
                if(temp_c && temp_c.nodeType!=1)
                    continue;
                if(Position.withinIncludingScrolloffsets(temp_c,x,y))
                {
                    
                    obj=temp_c;
                    tempobj=obj;
                    iscontinue=true;
                    break;
                }
            }
            if(!iscontinue)
            {
                break;
            }
        }
        tempobj=tempobj?tempobj:element;
        return tempobj;
    }
}
Tools.Cookie ={
 Set:function(name,value,expires,path,domain,secure){
expires = expires * 60*60*24*1000;
		var today = new Date();
		var expires_date = new Date( today.getTime() + (expires) );
	    var cookieString = name + "=" +escape(value) + 
	       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
	       ( (path) ? ";path=" + path : "") + 
	       ( (domain) ? ";domain=" + domain : "") + 
	       ( (secure) ? ";secure" : ""); 
	    document.cookie = cookieString; 
},
Del:function(name,path,domain,secure)
{
    if(GetCookie(name))
    {
        var cookieString=name+"=;expires=Thu, 01-Jan-70 00:00:01 GMT;"+
            ( (path) ? ";path=" + path : "") + 
	        ( (domain) ? ";domain=" + domain : "") + 
	        ( (secure) ? ";secure" : "");
	   document.cookie=cookieString; 
    }
},
Get:function(name){
	   var start = document.cookie.indexOf(name+"="); 
	   var len = start+name.length+1; 
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return ""; 
	   if (start == -1) return ""; 
	   var end = document.cookie.indexOf(";",len); 
	   if (end == -1) end = document.cookie.length; 
	   var result = unescape(document.cookie.substring(len,end));
	   return result==null?"":result; 
	} 
}
Tools.XML={
//得到节点的Text值
getText:function(obj)
{
    if(!obj)
    {
        return "";
    }
    if(obj.textContent)
    {
        return obj.textContent;
    }
    
    if(obj.firstChild)
    {
        obj=obj.firstChild;    
    }
    if(obj.nodeValue)
    {
        return obj.nodeValue;
    }
    if(obj.data)
    {
        return obj.data;
    }
    return "";
    
},
//得到某个属性
getAttribute:function(node,name)
{
    if(!node || !name)
    {
        return false;
    }
    if(!node.attributes)
    {
        return false;
    }
    for(var i=0;i<node.attributes.length;i++)
    {
        if(node.attributes[i].nodeName.toLowerCase()==name.toLowerCase())
        {
            return node.attributes[i];
        }
    }
    return false;    
}
}

var Ajaxs={reqList:[],
//创建一个XMLHTTP对象，兼容不同的浏览器
 getAjax:function()
{
    var ajax=false; 
    try 
    { 
     ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
     if(!ajax) ajax = new ActiveXObject("Mxsml2.XMLHTTP.3.0");
    } 
    catch (e)
     { 
      try 
      { 
      ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
      } 
     catch (E)
      { 
      ajax = false; 
      } 
    }
    if (!ajax && typeof XMLHttpRequest!='undefined') 
    { 
     ajax = new XMLHttpRequest(); 
    } 
    return ajax;
},
//封装XMLHTTP向服务器发送请求的操作
//url:向服务器请求的路径；method：请求的方法，即是GET还是POST；callback：当服务器成功返回结果时，调用的函数
//data：向服务器请求时附带的数据；urlencoded：url是否编码；callback2;当服务器返回错误时调用的函数
send:function(url, method, callback, data, urlencoded, callback2)
 { 
    var req=this.getAjax();  //得到一个XMLHTTP的实例
	//当XMLHTTP的请求状态发生改变时调用
    req.onreadystatechange = function() 
    {
	// 当请求已经加载
    if (req.readyState == 4) 
    {
			// 当请求返回成功
			if (req.status < 400) 
			{
			// 当定义了成功回调函数时，执行成功回调函数
			if(callback)
				callback(req,data);
			} 
			// 当请求返回错误
			else 
			{
				alert("当加载数据时发生错误 :\n" + req.status+ "/" + req.statusText);
				//当定义了失败回调函数时，执行失败回调函数
				if (callback2) 
				callback2(req,data);
			}
			//服务器已经进行了处理，更改界面提示信息
			Ajaxs.afterLoading();
			//删除XMLHTTP，释放资源
			try {
				delete req;
				req = null;
			} catch (e) {}
		}
	}
	//如果以POST方式回发服务器
	if (method=="POST")
	 {
		req.open("POST", url, true);
		//请求需要编码
		if (urlencoded) 
		    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		req.send(data);
		this.reqList.push(req);
	}
	//以GET方式请求
	 else 
	{
		req.open("GET", url, true);
		req.send(null);
		this.reqList.push(req);
	}
	//正在向服务器发送请求，页面显示正在加载的提示
	this.loading();	
	return req;
},
//全部清除XMLHTTP数组元素，释放资源
clearReqList:function() 
{
	var ln = this.reqList.length;
	for (var i=0; i<ln; i++) {
		var req = this.reqList[i];
		if (req) 
		{
		try 
		{
			delete req;
		} catch(e) {}
		}
	}
	this.reqList = [];
},
//进一步封装XMLHTTP以POST方式发送请求时的代码
//clear：是否清除XMLHTTP数组的所有元素；其他参数的意义参见this.send
POST:function(url, data, callback, clear, callback2) 
{
	if (clear)
		this.clearReqList();
	this.send(url, "POST", callback, data, true, callback2);
},
//进一步封装XMLHTTP以GET方式发送请求时的代码
GET:function(url, callback, args, clear, callback2) 
{
	if (clear)
		this.clearReqList();
	return this.send(url, "GET", callback, args, false, callback2);
},
//向服务器发送请求过程中，显示页面加载提示
loading:function()
{
var div = $("loadingflag");
if(div)
div.style.display ="";
},
//服务器处理完成后，页面加载提示消失
afterLoading:function()
{
var div = $("loadingflag");
if(div)
div.style.display ="none";
}
}
