﻿function initXMLHttpObject() { 
	try {
		xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
    } catch (e) {
    	try {
    		xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
    	} catch (e) {
    		try {
    			xmlHttpObject = new XMLHttpRequest();
    		} catch (e) {}
    	}
	}
	return xmlHttpObject;
}

function newsqlExec(callbackFunc,condition,asyn,headtype) {
	xmlHttpObj = new initXMLHttpObject();
	with (xmlHttpObj) {
		if (asyn && (typeof callbackFunc == "function"))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 			onreadystatechange = function() {callbackFunc(xmlHttpObj)};
		open('POST',condition,asyn);
        setRequestHeader("Content-Type","application/x-www-form-urlencoded;"+headtype);
        try {
        	send(null);
        } catch (e){alert("连接失败,请重新登陆!");return;}
        var headStr =new String(getAllResponseHeaders());
        if (headStr.indexOf("Server")==-1) {
        	alert("连接已中断,请重新登陆!");
        	return;
        }
        if (!asyn && (typeof callbackFunc == "function"))
        	callbackFunc(xmlHttpObj);
	}
}

//用Ajax发送:backfunction－－返回处理的函数，condition－－传送的url
function sqlExec(backfunction,condition) {
	XMLHttpObj = new initXMLHttpObject();
	XMLHttpObj.open('POST',condition,false);
	XMLHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	XMLHttpObj.send(null);	
	if (((XMLHttpObj.readyState==4) || (XMLHttpObj.readystate==4)) && XMLHttpObj.status==200){		
		backfunction(XMLHttpObj.responseText);
	}
}

//返回直接执行
function DoDealBack(datastr)
{
	//alert(datastr);
	eval(datastr);
}

//不大于0就返回0的处理函数--CheckPositiveNumber(num)
function CheckPositiveNumber(num)
{
	if(num>0)
	{
		return num;
	}else{
		return 0;
	}	
}

//分离串
function splixmlstr(splby,splfrom){
	var Rword = "";
	var splfroml = splfrom.length;
	var splbyl = splby.length;
//	alert("splfroml--" + splfroml);
//	alert("splbyl--" + splbyl);
	if(splfroml>(2 * splbyl + 5)){
		var b = splfrom.indexOf("<" + splby + ">");
		var e = splfrom.indexOf("</" + splby + ">");
//		alert("b--" + b);
//		alert("e--" + e);
		if(b>0&&e>0){
			Rword = splfrom.substring((splbyl + 2 + b),e);
		}
	}
	return Rword;
}
