var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");

function XMLHttpSynchroSave(url, content)
{
	var ret = false;
	var result = XMLHttpSynchroPost(url, content);
	if (null!=result)
	{
		if (result.selectSingleNode("messages/code").text=="1000")
		{
			alert("保存成功。");
			ret = true;
		}
		else
			alert(result.selectSingleNode("messages/remarks").text);
	}
	
	return ret;
}

function XMLHttpSynchroPost(url, content)
{
	xmlhttp.open("POST",url, false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(content);

	var result = null;
	if (xmlhttp.status==200)
		result = xmlhttp.responseXML;
	else
		document.writeln(xmlhttp.responseText);

	return result;
}

function XMLHttpPost(url, content)
{
	xmlhttp.open("POST",url, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(content);
}

function OnXMLHttpPostResult()
{
	var result = null;
	if (xmlhttp.status==200)
		result = xmlhttp.responseXML;
	else
		document.writeln(xmlhttp.responseText);

	return result;
}

function OnXMLHttpSaveResult()
{
	var ret = false;
	var result = OnXMLHttpPostResult();
	if (null!=result)
	{
		if (result.selectSingleNode("messages/code").text=="1000")
		{
			alert("保存成功。");
			ret = true;
		}
		else
			alert(result.selectSingleNode("messages/remarks").text);
	}
	
	return ret;
}

var oTimer = null;
var nTimesOfTimeOut = 0;
var const_MaxTimes_Of_Timeout = 10;
var const_MinTimes_Of_ShowProgress = 1;
var const_Interval_Of_Timer = 1000;
var oProgressFilter = null;

function OnServerConnecting(sDescription, sUrl, sContent, sFnOnServerConnected)
{
	//显示提示框
	pnlProgressBar.style.visibility = "hidden";
	pnlProgressBar.style.display = "block";
	pnlProgressBar.style.left = (document.body.clientWidth - pnlProgressBar.clientWidth) / 2;
	pnlProgressBar.style.top = (document.body.clientHeight - pnlProgressBar.clientHeight) / 2 - 50;
	pnlBarDesc.innerText = sDescription;
	if (pnlProgressBar.filters.length>0)
		pnlProgressBar.filters[0].apply();
	pnlProgressBar.style.visibility = "visible";
	if (pnlProgressBar.filters.length>0)
		pnlProgressBar.filters[0].play();
	
	if (pnlGuide.filters.length>0)
		pnlGuide.filters[0].enabled = true;
	nTimesOfTimeOut = 0;
	if (null!=oProgressFilter)
		oProgressFilter.apply();
	if ("skyblue"==pnlBarClock.style.backgroundColor)
		pnlBarClock.style.backgroundColor = "gold";
	else
		pnlBarClock.style.backgroundColor = "skyblue";
	if (null!=oProgressFilter)
		oProgressFilter.play();
	XMLHttpPost(sUrl, sContent);
	oTimer = window.setInterval("OnServerConnected(\"" + sFnOnServerConnected + "\")", const_Interval_Of_Timer);
}

function OnServerConnected(sFnOnServerConnected)
{
	if (null!=oProgressFilter)
		oProgressFilter.apply();
	if ("skyblue"==pnlBarClock.style.backgroundColor)
		pnlBarClock.style.backgroundColor = "gold";
	else
		pnlBarClock.style.backgroundColor = "skyblue";
	if (null!=oProgressFilter)
		oProgressFilter.play();
		
	nTimesOfTimeOut++;
	if (nTimesOfTimeOut>const_MaxTimes_Of_Timeout //超时
	 || (nTimesOfTimeOut>const_MinTimes_Of_ShowProgress && 4==xmlhttp.readyState))
	{
		window.clearInterval(oTimer);

		//关闭提示框
		pnlProgressBar.style.display = "none";

		if (pnlGuide.filters.length>0)
			pnlGuide.filters[0].enabled = false;

		if (nTimesOfTimeOut++>const_MaxTimes_Of_Timeout)
			alert("连接服务器超时。请重试。"); //超时
		else
		{
			var result = OnXMLHttpPostResult();
			if (result!=null)
				eval(sFnOnServerConnected + "(result)");
			else
				alert("系统异常。数据返回失败。请重试。");
		}
	}
}
