function createXMLHttp() {
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	} else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	throw new Error("XMLHttp object could be created.");
}

function _sendRequest(url,func,isxml,ispost)
{
	var xhr=createXMLHttp();
	if(!ispost)ispost=null;
	xhr.open(ispost?"POST":"GET",url,true);
	if(func){
		xhr.onreadystatechange=function(){
			if(xhr.readyState==4){
				func(isxml&&xhr.responseXML?xhr.responseXML:xhr.responseText)
			}
		}
	}
	if(is_ie >=7 )
	{
		ispost = null;
	}
	xhr.send(ispost)
}
function ajaxRead(file,fun){
	var xmlObj = createXMLHttp();

	xmlObj.onreadystatechange = function(){
		if(xmlObj.readyState == 4){
			if (xmlObj.status ==200){
				obj = xmlObj.responseXML;
				eval(fun);
			}
			else{
				alert("读取文件出错,错误号为 [" + xmlObj.status  + "]");
			}
		}
	}
	xmlObj.open ('GET', file, true);
	xmlObj.send (null);
}

function getRequestBody(oForm) {
	var aParams = new Array();
	for (var i=0 ; i < oForm.elements.length; i++) {
		/*
		if (oForm.elements[i].type == "checkbox" && oForm.elements[i].checked == false)
		{
			continue;
		}
		*/
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";
		sParam += encodeURIComponent(oForm.elements[i].value);
		aParams.push(sParam);
	}
	return aParams.join("&");
}


function getSpecificNodeValue(doc, tagname, index)
{
	try{
		var oNodes = doc.getElementsByTagName(tagname);
		if (oNodes[index] != null && oNodes[index] != undefined)
		{
			if (oNodes[index].childNodes.length > 1) {
				return oNodes[index].childNodes[1].nodeValue;
			} else {
				return oNodes[index].firstChild.nodeValue;    		
			}
		}
	}
	catch(e){}
	return '';
}

function getSingleNodeValue(doc, tagname)
{
	try{
		var oNodes = doc.getElementsByTagName(tagname);
		if (oNodes[0] != null && oNodes[0] != undefined)
		{
			if (oNodes[0].childNodes.length > 1) {
				return oNodes[0].childNodes[1].nodeValue;
			} else {
				return oNodes[0].firstChild.nodeValue;    		
			}
		}
	}
	catch(e){}
	return '';
}

var YPXHR = function(url, method, params, onComplete, onFailure, loading) {  
    var me = this;
    var getHTTPObject = function() {
        var xmlhttp = false;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    xmlhttp = false;
                }
            }
        }
        return xmlhttp;
    };

    var completeRequest = function() {
        if (me.XHR.readyState == 4) {
            if (me.XHR.status == 200 || me.XHR.status == 304) {
                if (onComplete) {
                    onComplete(me.XHR);
                }
            }
            else {
                if (onFailure) {
                    onFailure(me.XHR)
                };
            }
        }
    };

    var process = function() {
        if (loading) {
            loading();
        }
        var query = '';
        for (var i in params) {
            //query+= i + '='+escape(params[i]) + '&';
            //query+= i + '='+encodeURIComponent(params[i]) + '&';
            query += i + '=' + params[i] + '&';
        }
        me.XHR.onreadystatechange = completeRequest;
        if ('post' == me.method) {
            me.XHR.open("POST", url, true);
            me.XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            me.XHR.send(query);
        }
        else {
            url += '?' + query + 'random=' + Math.random();
            me.XHR.open("GET", url, true);
            me.XHR.send(null);
        }
    };
    me.XHR = getHTTPObject();
    me.method = ('get' == method.toLowerCase()) ? 'get' : 'post';
    process();
};
