////////////////////Ajax////////////Class///////////////////
//Power By WeisNet CopyRight @2006
//Edit Section for 56best
/////////////////////////////////////////////////

var Try = {
    these: function() {
        var returnValue;
        for (var i = 0; i < arguments.length; i++) {
            var lambda = arguments[i];
            try {
                returnValue = lambda();
                break;
            } catch (e) {}
        }
    //alert(123);
    return returnValue;
    }
}

function grr(rp) {
    if(RegExp.$1)/(.*)/.exec("");
    var re=new RegExp("<result>(.*)<\/result>");
    re.exec(rp);
    if(RegExp.$1) return RegExp.$1;
    return "";
}

function crr(rp) {
    if(RegExp.$1)/(.*)/.exec("");
    var re=new RegExp("<content>(.*)<\/content>");
    re.exec(rp);
    if(RegExp.$1) return RegExp.$1;
    return "";
}

var Ajax = function() {}
//var xhr ;这样定义不行
Ajax.prototype.Init = function(){
    return Try.these(
    function() {return new ActiveXObject("Msxml2.XMLHTTP")},
    function() {return new ActiveXObject("Microsoft.XMLHTTP")},
    function() {return new XMLHttpRequest()}
    ) || false;
}

Ajax.prototype.Config = {
    Result:"",
    SucInfo:"",
    FaildInfo:"",
    Url:"",
    returnType:"Compare", //输入Compare是比较返回的字符是否一致,要指定Result值,//其他返回内容
    loadFunc:function(ty) {
        if (typeof AjaxFunction == 'function')
            AjaxFunction(ty);
    }
}

var aj = new Ajax();

Ajax.prototype.Action = function(url) { //同步
    url = url + '&e='+Math.random();
    var xhr = aj.Init();
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            if (xhr.status == 200)
            {
                aj.FuncResult(aj.Config.Spn,xhr);
            }
        }
    }
    xhr.open("POST",url,false);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

    xhr.send(null);

}

Ajax.prototype.Actionfor = function(url,spn) { //异步

    url = url + '&e='+Math.random();
    var xhr = aj.Init(); //这样写是为了多异步执行

    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            if (xhr.status == 200)
            {
                aj.FuncResult(spn,xhr);
            }
        }
    }
    xhr.open("GET",url,true);

    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(null);
}

Ajax.prototype.ActionAlert = function(url) //执行alert提示框的同步
{
    url = url + '&e='+Math.random();
    var xhr = aj.Init(); //这样写是为了多异步执行

    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4)
        {
            if (xhr.status == 200)
            {
                aj.AlertResult(xhr);
            }
        }
    }
    xhr.open("GET",url,false);

    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(null);
}

Ajax.prototype.onResult = function(v) {
    return v==aj.Config.Result;
}

Ajax.prototype.FuncResult = function(spn,xhr)
{   //alert(spn.id);

    if (aj.Config.returnType=='Compare')
    {
        if (aj.onResult(grr(xhr.responseText)))
        {

            spn.innerHTML = aj.Config.SucInfo;
            aj.Config.loadFunc(aj.Config.Result);
            if (aj.Config.Url!='')
            {
                window.location.href = aj.Config.Url;
            }
        }
        else
        {

            spn.innerHTML = aj.Config.FaildInfo;

        }
    }
    else
    {
        spn.innerHTML = crr(xhr.responseText);
        aj.Config.loadFunc(aj.Config.Result);
    }

}


Ajax.prototype.AlertResult = function(xhr)
{
    if (aj.Config.returnType=='Compare')
    {
        if (aj.onResult(grr(xhr.responseText)))
        {
            alert(aj.Config.SucInfo);
        }
        else
        {
            alert(aj.Config.FaildInfo);
        }
    }
    else
    {
        alert(crr(xhr.responseText));
    }
}

Ajax.prototype.ActionXML = function(url,oDoc,spn) {  //异步

      url = url + '&e='+Math.random();
      var xhr = aj.Init();  //这样写是为了多异步执行 
      
      xhr.onreadystatechange = function()
      {
			if (xhr.readyState == 4) 
			{
				if (xhr.status == 200)
				{
					aj.FuncXML(xhr,oDoc,spn);     
				} 
			}
      }
      xhr.open("GET",url,true);
      
      xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xhr.send(null); 
    
}

Ajax.prototype.FuncXML = function(xhr,oDoc,spn)
{
	//alert(54545)
	//alert(crr(xhr.responseText));
	oDoc.loadXML(crr(xhr.responseText)); 
			
	items1 = oDoc.selectNodes("/CGG/linkAndName/Link"); 
	items2 = oDoc.selectNodes("/CGG/linkAndName/Name");
    //alert(items1[0])
	var itemsLength=items1.length; 
	spn.innerHTML = "";
    for(var i=0;i<itemsLength;i++) 
    {   
	    spn.innerHTML += '<a href="'+items1[i].text+'">'+items2[i].text+'</a>&nbsp; ';
    } 
    aj.Config.loadFunc(aj.Config.Result);
}
///////////////////////////////////////////////////////////////

var WebServices = function() {}
    WebServices.Config = {

}