var intStatusCode = null;
var xoDoc = null;

function zAjax_CallBackFunc(strContent,objValue,IsType)
{
	if (objValue != "" && objValue != null && strContent != null)
	{
		zAjax_SetValue(objValue,strContent,1);
	}
	if (strContent != null)
	{
		switch(IsType)
		{
			case 0:
				eval(strContent);
				break;
		}
	}
}

/*
strURL 跳转地址
strParameter 参数
objValue 返回内容显示区域
intStyle
IsMethod 0:get;1:post	
isHintInfo:是否隐藏提示信息
IsType:返回类型;0:javascript;1:HTML;2:xml;
returnFun:返回调用的函数
*/
function zAjax_LoadPage(strURL,strParameter,objValue,intStyle,IsMethod,isHintInfo,IsType,returnFun) 
{
	var sValue = new Win_Waite();

	if(document.getElementById("hidenPages"))
	{
		if(document.getElementById("hidenPages").style.display == "")
		{
			onloadLayer(sValue,"Indication");
		}
	}
	
	var objXMLHTTP = zAjax_InitObject();
	
	var sRetrun = null;
	if (IsMethod == 0)
	{
		strURL = strURL+"?"+strParameter;
	}
	if (zAjax_Check(objXMLHTTP,strURL)) {
			objXMLHTTP.onreadystatechange = function() {
				zAjax_ReadingBuffer(objXMLHTTP,objValue,IsType,returnFun);
			}
		try {
			if (isHintInfo == 1)
			{
				zAjax_SetValue("Loading data ...",0);
			}
		
			if (IsMethod == 0)
			{
				objXMLHTTP.open("GET",strURL,true);
				objXMLHTTP.send(null);
			}
			else
			{
				objXMLHTTP.open("POST",strURL,true);
				objXMLHTTP.setRequestHeader("content-type","application/x-www-form-urlencoded");
				objXMLHTTP.send(strParameter);
			}

		} catch(e) {
			zAjax_SetValue(objValue,"",0);
		}
	}
}


function zAjax_InitObject() {
	var objAjax = null;
	
	if (window.XMLHttpRequest) {
		objAjax = new XMLHttpRequest();
		
		if (objAjax.overrideMimeType) {
			objAjax.overrideMimeType("text/xml");
		}
	} else if (window.ActiveXObject) {
		try {
			objAjax = new ActiveXObject("MSXML2.XMLHTTP");
		} catch (e) {
			try {
				objAjax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				
			}
		}
	}
	
	return(objAjax);
}

function zAjax_Check(objReading,strURL) {
	var bolResult = true;
	
	if (objReading == null) {
		zAjax_ShowMessage("Failed to init initialize the ActiveX Object.");
		bolResult = false;
	} else if (strURL == "" || strURL == null) {
		zAjax_ShowMessage("The URL is incorrect!");
		bolResult = false;
	}
	
	return(bolResult);
}

function zAjax_ReadingBuffer(objReading,objValue,IsType,returnFun) {
	var strContent = null;
	
	if (objReading.readyState == 4) {
		zAjax_SetStatus(objReading.status);
		if ((objReading.status >= 200 && objReading.status <300) || objReading.status == 0 || objReading.status == undefined) {
			strContent = objReading.responseText;
			if (strContent != null)
			{
				if(document.getElementById("hidenPages"))
				{
					if(document.getElementById("hidenPages").style.display == "")
					{
						closeWin();
					}
				}
				//alert(strContent)
				//判断是否有权限
				try{
					if(IsType == 2)
					{	
						if(strContent != "")
						{
							if(strContent.indexOf("<?xml") >= 0)
							{
								var Xmls = new DomParseXml();
								var iT = Xmls.getValue("Result",strContent);
								if (iT == "-500")
								{
									zAjax_NoPower();	
									return;
								}
							}
						}
					}
				}
				catch(e)
				{
					//
					
				}
				
				if(IsType == 2)
				{
					var XmlDom = new DomParseXml();
						xoDoc = XmlDom.getXMLDocument();
					var iIE = window.Event?false:true;
					var bolLoad;
							
					if (iIE)
					{
						xoDoc.loadXML(strContent);
					}
					else
					{
						var dp = new DOMParser();
						var newDOM = dp.parseFromString(strContent, "text/xml");
						var newElt = xoDoc.importNode(newDOM.documentElement, true);
						xoDoc.appendChild(newElt);
					}
					var iResult = DomParseXmls.onlyValue(xoDoc);
						
					if (iResult != -1)
					{
						eval(returnFun+"(xoDoc)");
					}
				}
				else
				{
					zAjax_CallBackFunc(strContent,objValue,IsType)
				}
			}
		} 
		else {
		
			zAjax_Error(objReading.status);
		}
	}
}

function zAjax_SetStatus(intStatus) {
	intStatusCode = intStatus;
}

function zAjax_GetStatus() {
	return(intStatusCode);
}

function zAjax_Error(intStatus) {
	switch (intStatus) {
		case 302:
			zAjax_ShowMessage("The object has been moved.");
			break;
		case 400:
			zAjax_ShowMessage("HTTP Error 400 - Bad Request.");
			break;
		case 401:
			zAjax_ShowMessage("HTTP Error 401 - Unauthorized.");
			break;
		case 403:
			zAjax_ShowMessage("HTTP Error 403 - Forbidden.");
			break;
		case 404:
			zAjax_ShowMessage("HTTP Error 404 - Web site not found.");
			break;
		case 500:
			zAjax_ShowMessage("HTTP Error 500 - Internal server error.");
			break;
		case 12029:
			break;
		default:
			alert(intStatus)
			//zAjax_ShowMessage("Failure to do the operation.");
			break;	
	}
	
	return(null);
}

function zAjax_SetValue(objContent,strContent,intStyle) {
	var objTarget = document.getElementById(objContent);
	if (objTarget) {
	
		if (strContent != "" && strContent != null) {
			if (intStyle != 0) {
				strContent = zAjax_FormatContent(strContent,intStyle);
			}
			
			objTarget.innerHTML = strContent;
		}
	}
	
	return(null);
}

function zAjax_ShowMessage(strMessage) {
	alert(strMessage);
}

function zAjax_FormatContent(strContent,intStyle) {
	var strResult = strContent;
	
	if (strResult != "" && strResult != null) {
		if (intStyle == 1) {
			var strTemp = strContent.toLowerCase();
			var intStartPosition = strTemp.indexOf("<body");
			var intEndPosition = 0;
			if (intStartPosition != -1) {
				intStartPosition = strTemp.indexOf(">",intStartPosition) + 1;
				intEndPosition = strTemp.indexOf("</body>",intStartPosition);
				
				strResult = strResult.substring(intStartPosition,intEndPosition);
			}
		}
	}
	
	return(strResult);
}

function zAjax_NoPower() 
{
	location.href='login.htm'
}
