var App = new function(){
    this.loading="...";    
	/**
	 * 初始化数据
	 * @param {Object} datastr
	 */
	this.load = function(_datastr){
		var msg = null;
		eval("var obj = "+_datastr+";");
		if(obj.msg){
			msg=$(obj.msg);
			if(obj.hide==false){
				msg.style.display="block";
				msg.style.position="absolute";
				msg.style.top = 250;
				msg.style.left = 300;
				msg.style.zIndex =1001;
			}else if(obj.hide=='msg'){
				msg.style.display="none";
			}
		}else if(obj.msg1){
			msg=$(obj.msg1);
			if(obj.hide==false){
				msg.style.display="block";
				msg.style.position="absolute";
				msg.style.top = 0;
				msg.style.left = 0;
				msg.style.zIndex =1001;
			}else if(obj.hide=='msg'){
				msg.style.display="none";
			}
		}else if(obj.loadid){
			$(obj.loadid).innerHTML = this.loading;
		}else{
			if(obj.hide==false){
				$(obj.id).innerHTML=this.loading;
			}
		}
		this.callback = function(_response){
			if(obj.msg) {msg.style.display="none";}
			if(obj.msg1){msg.style.display="none";}
			if(obj.loadid){$(obj.loadid).innerHTML = "";};
			$(obj.id).innerHTML=_response.responseText;
			loadScripts($(obj.id).innerHTML);
		}
		Request.send(obj.url,this.callback,null,obj.chunnel);
	};
	/**
	 * 提交数据
	 * @param {String} id  		元素的名称
	 * @param {String} callback		callBack函数
	 * @param {String} chunnel      通道名称,默认"default"
	 * @param {String} isHtmlEncode 是否转换HTML转化.
	 */
	this.submit = function(id,callback,isHtmlEncode) {
		var data="";
		if(isHtmlEncode == undefined){isHtmlEncode = true;}
		var elements=$(id).elements;
		for (var i=0;i<elements.length;i++){
			var e = $(id).elements[i];
			if(e.type == 'radio' || e.type == 'checkbox')
				if(!e.checked)continue;
			if(i>0) data+="&";
			if(isHtmlEncode) data+=e.name+"="+encodeURIComponent(htmlEncode(e.value));
			else data+=e.name+"="+encodeURIComponent(e.value);
		}
		Request.send($(id).action,callback,data);
	};
	this.hide = function(id) {$(id).style.display = 'none';};
	this.display = function(id) {$(id).style.display = '';};
	this.close = function(id){$(id).innerHTML='';};

	this.check = function(_datastr){
		eval("var obj = "+_datastr+";");
		this.callback = function(_response){
			var mt=_response.responseText.trim(),mt0=mt.substring(0,1),mt1=mt.substring(1);
			if(mt0==1)mt1="<span style='color:blue'>"+mt1+"</span>";
			$(obj.id).innerHTML=mt1;
			loadScripts($(obj.id).innerHTML);
		}		
		Request.send(obj.url,this.callback,null,obj.chunnel);
	};
	
	this.checks = function(_datastr){
		eval("var obj = "+_datastr+";");
		this.callback = function(_response){
			var mt=_response.responseText.trim(),mt0=mt.substring(0,1),mt1=mt.substring(1);
			if(mt0==1){mt1="<span style='color:blue'>"+mt1+"</span>";}
			else{}
			$(obj.id).innerHTML=mt1;
			loadScripts($(obj.id).innerHTML);
		}		
		Request.send(obj.url,this.callback,null,obj.chunnel);
	};
}

