﻿// JScript 文件
/*
    //AJAX 异步刷新
    //By:Pengyj
    //Date:2006-12-30
*/
function XmlHttpHelper(){
}
XmlHttpHelper.__getXmlHttpObj = function(){
    try{
        return new ActiveXObject("MSXML2.XMLHTTP");
    }
    catch(e){
        return new XMLHttpRequest();
    }
};
XmlHttpHelper.transmit = function(async, httpMethod, responseType, url, callback, postData){
    httpMethod = httpMethod.toLowerCase();
    if(responseType != null) responseType = responseType.toLowerCase();
    var xmlhttp = this.__getXmlHttpObj();
    xmlhttp.open(httpMethod, url, async);
    if(!async && httpMethod == "post")
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    if(async){
xmlhttp.onreadystatechange = function(){
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
        try{
            if(typeof(callback) == "function"){
                switch(responseType){
                    case "text":
                    callback(xmlhttp.responseText);
                    break;
                    case "xml":
                    callback(xmlhttp.responseXML);
                    break;
                    default:
                    callback(null);
                }
            }
        }
        finally{
            xmlhttp = null;
        }
    }
}
xmlhttp.send(postData);
}
else{
xmlhttp.send(postData);
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
    switch(responseType){
        case "text":
        return xmlhttp.responseText;
        case "xml":
        return xmlhttp.responseXML;
        default:
        return null;
    }
}
else{
    return null;
}
}
};

XmlHttpHelper.trim = function(s)
{
	s += "";
	return s.replace(/^\s+|\s+$/g,'');
};
