var Ajaxs=new Array();

function Ajax(recvType,statusId){

var aj=new Object();

aj.statusId=statusId?document.getElementById(statusId):null;

aj.targetUrl='';

aj.sendString='';

aj.recvType=recvType?recvType:'XML';

aj.resultHandle=null;

aj.createXMLHttpRequest=function(){

var request=null;

if(window.XMLHttpRequest){

request=new XMLHttpRequest();

if(request.overrideMimeType){

request.overrideMimeType('text/xml');


} 

} else if(window.ActiveXObject){

var versions=new Array('Microsoft.XMLHTTP','MSXML.XMLHTTP','Microsoft.XMLHTTP','Msxml2.XMLHTTP.7.0','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP');

for(var i=0;

i<versions.length;

i++){

try{

request=new ActiveXObject(versions[i]);

if(request){

return request;


} 

} catch(e){


} 

} 

} return request;


} ;

aj.XMLHttpRequest=aj.createXMLHttpRequest();

aj.processHandle=function(){

if(aj.statusId){

aj.statusId.style.display='';


} if(aj.XMLHttpRequest.readyState==1&&aj.statusId){

aj.statusId.innerHTML='正在连接……';


} else if(aj.XMLHttpRequest.readyState==2&&aj.statusId){

aj.statusId.innerHTML='连接成功……';


} else if(aj.XMLHttpRequest.readyState==3&&aj.statusId){

aj.statusId.innerHTML='数据交互中……';


} else if(aj.XMLHttpRequest.readyState==4){

if(aj.XMLHttpRequest.status==200){

for(var k in Ajaxs){

if(Ajaxs[k]==aj.targetUrl){

Ajaxs[k]=null;


} 

} if(aj.statusId){

aj.statusId.innerHTML='';

aj.statusId.style.display='none';


} var ret;

if(aj.recvType=='HTML'){

ret=unescape(aj.XMLHttpRequest.responseText);

aj.resultHandle(ret,aj);


} else if(aj.recvType=='XML'){

try{

ret=unescape(aj.XMLHttpRequest.responseXML.lastChild.firstChild.nodeValue);


} catch(e){


} aj.resultHandle(ret,aj);


} 

} else{

if(aj.statusId){

aj.statusId.innerHTML='加载数据失败，请检查网络原因或者联系管理员！';


} 

} 

} 

} ;

aj.in_array=function(needle,haystack){

if(typeof needle=='string'){

for(var i in haystack){

if(haystack[i]==needle){

return true;


} 

} 

} return false;


} ;

aj.get=function(targetUrl,resultHandle,resend){

if(!aj.XMLHttpRequest){

alert("Can't create XMLHttpRequest object.");

return;


} if(!(typeof resend=='boolean'?resend:false)){

if(aj.in_array(targetUrl,Ajaxs)){

return false;


} else{

Ajaxs.push(targetUrl);


} 

} if(typeof targetUrl=='string'){

aj.targetUrl=targetUrl;


} if(typeof resultHandle=='function'){

aj.resultHandle=resultHandle;


} aj.XMLHttpRequest.onreadystatechange=aj.processHandle;

if(window.XMLHttpRequest){

aj.XMLHttpRequest.open('GET',aj.targetUrl);

aj.XMLHttpRequest.send(null);


} else{

aj.XMLHttpRequest.open('GET',aj.targetUrl,true);

aj.XMLHttpRequest.send();


} 

} ;

aj.post=function(targetUrl,sendString,resultHandle,resend){

if(!aj.XMLHttpRequest){

alert("Can't create XMLHttpRequest object.");

return;


} if(!(typeof resend=='boolean'?resend:false)){

if(aj.in_array(targetUrl,Ajaxs)){

return false;


} else{

Ajaxs.push(targetUrl);


} 

} if(typeof targetUrl=='string'){

aj.targetUrl=targetUrl;


} if(typeof sendString=='string'){

aj.sendString=encodeURI(encodeURI(sendString));


} if(typeof resultHandle=='function'){

aj.resultHandle=resultHandle;


} aj.XMLHttpRequest.onreadystatechange=aj.processHandle;

aj.XMLHttpRequest.open('POST',aj.targetUrl);

aj.XMLHttpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

aj.XMLHttpRequest.send(aj.sendString);


} ;

return aj;


} 
