/**
 * @file globals.js
 * @desription 本文件定义程序全局的简单变量，包括常量定义
 * @version 1.0 2005.01
 * @author longhongye
 */

/**
 * ITOWNWEBOBJ类，存放应用相关信息
 */
function ITOWNWEBOBJ(){
    this.WEB_APP_NAME  = "ItownAPP";
    this.FORM_NAME     = "form1";
    this.DEBUG         = false;
    //一个汉字所占位数
    this.bitsOfOneChinese = 2;
    //返回结果分割符
    this.resultSplit = "RESPONSE_SEPARATOR";
    //局部刷新不作处理的开头标识
    this.NOT_DEAL_INDENTIFIER = "<!-- itownappNotDeal -->";
    //数据窗口是否自动调整大小
    this.isAutoResize = true;
    // 含有异步下载对象信息，仅供 getPageContent、onGetPageContentDone 方法使用。
var downloadObjs = new Array();
/*
使用指定URL进行数据下载。
如果是同步方法，则直接返回下载内容（指定URL的整个页面或其它的传回数据）;
如果是异步方法，则在下载完成后，使用下载内容作为参数调用回调方法，而此方法直接返回空串；
如果此方法发生错误则返回 null。
传入url地址串、请求参数（可选）、异步下载时的回调方法（可选）、下载内容类型（可选，默认为字符串）；
如果不需要请求参数，则可传入null；如果是异步下载，则必须提供回调方法，否则认为是同步下载。
下载内容类型可为：0、字符串（默认）；1、XML DOMDocument 对象；2、二进制字节数组
*/
this.downloadData = function fnDownloadData(url, requestParameter, callBackMethod, resultType) {
	try {
		if (typeof(callBackMethod) != "function") callBackMethod = null;
		if (typeof(resultType) != "number" || resultType != 1 && resultType != 2) resultType = 0;
		var isAsync = (callBackMethod != null);
		var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); //Msxml2.XMLHTTP // Msxml2.ServerXMLHTTP.4.0
		if (isAsync) {
			var index = 0;
			var downArray = null;
			for (; index < downloadObjs.length; index++) {
				if (downloadObjs[index][0] != null) continue;
				downArray = downloadObjs[index];
				break;
			}
			if (downArray == null) {
				downArray = new Array();
				index = downloadObjs.length;
				downloadObjs[index] = downArray;
			}
			downArray[0] = xmlhttp;
			downArray[1] = callBackMethod;
			downArray[2] = resultType;
			xmlhttp.onreadystatechange = new Function ("ItownGlobals.onGetPageContentDone(" + index + ")");
		} else {
			window.status = "请稍候，正在查询数据。。。";
		}
		xmlhttp.open("GET", url, isAsync);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		if (requestParameter && requestParameter.length) {
			requestParameter = encodeURI(requestParameter);
			xmlhttp.setRequestHeader("Content-Length", requestParameter.length);
			xmlhttp.send(requestParameter);
		} else {
			xmlhttp.send();
		}
		if (isAsync) {
			return "";
		} else {
			window.status = "";
			//alert(xmlhttp.responseXML.xml);
			//alert(xmlhttp.getAllResponseHeaders());
			switch (resultType) {
				case 1:
					return xmlhttp.responseXML;
				case 2:
					return xmlhttp.responseBody;
				default:
					return xmlhttp.responseText;
			}
		}
	} catch (error) {
		if (this.DEBUG == true) {
			window.status = "(" + (error.number & 0xFFFF) + ")" + error.description;
		} else {
			window.status = "";
		}
		return null;
	}
}

/*异步下载完成后，将使用此方法以调用回调方法，进行回调处理。*/
this.onGetPageContentDone = function(index) {
	var xmlhttp = downloadObjs[index][0];
	if (xmlhttp.readyState == 4) {
		try { // 回调异步方法
			var value;
			switch (downloadObjs[index][2]) {
				case 1:
					value = xmlhttp.responseXML;
				case 2:
					value = xmlhttp.responseBody;
				default:
					value = xmlhttp.responseText;
			}
			downloadObjs[index][1].apply(null, new Array(value));
		} catch (error) {
			if (this.DEBUG == true) window.status = index + ":(" + (error.number & 0xFFFF) + ")" + error.description;
		}
		downloadObjs[index][0] = null;
	}
 }
}
//实例化对象
var ItownGlobals = new ITOWNWEBOBJ();
//设定应用名称
ItownGlobals.WEB_APP_NAME="WebDeclare 2.3 版 (C)2005 北京信城通数码科技有限公司";
//设置调试标志
ItownGlobals.DEBUG = true;

