// JavaScript Document
function fetchData(queryUrl,id){
	xmlHttp = createXMLHttpRequest();
	xmlHttp.open("GET",queryUrl,true);
	this.id = id;
	xmlHttp.onreadystatechange=callback;
	xmlHttp.send(null);
}

function callback(){ 	

	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			var responseText = xmlHttp.responseText;
			$(id).innerHTML = responseText;
		}
	}
}


//定义层类
function Layer(coverId,appId){
	this.coverId = coverId;
	this.appId   = appId
}

//返回浏览器窗口高度
Layer.prototype.getBodyHeight = function (){
	if(window.document.body.scrollHeight >= screen.height){
		return window.document.body.scrollHeight;
	}else{
		return screen.height;
	}
}

//返回浏览器窗口宽度
Layer.prototype.getBodyWidth = function (){
	return window.document.body.scrollWidth;
}

//背景层
Layer.prototype.createCoverLayer = function(bgcolor,opacity){
	var w,h;
	var coverLayer=document.createElement("div");
	
	w = this.getBodyWidth();
	h = this.getBodyHeight();

	coverLayer.setAttribute('id',this.coverId);
	coverLayer.style.position       = "absolute";
	coverLayer.style.top            = "0";
	coverLayer.style.background     = bgcolor;
	coverLayer.style.filter         = "Alpha(Opacity="+ opacity +")";
	coverLayer.style.opacity        = "0.6";
	coverLayer.style.left           = "0";
	coverLayer.style.width          = w + "px";
	coverLayer.style.height         = h + "px";
	coverLayer.style.zIndex         = "10000";
	document.body.appendChild(coverLayer);

}


Layer.prototype.createAppLayer = function(w,h,l,t){
	
	var appLayer=document.createElement("div");
	appLayer.setAttribute("id",this.appId);
	appLayer.setAttribute("align","center");
	
	appLayer.style.background       = "#000033";
	//appLayer.style.border           = "1px solid #aaaaaa";
	appLayer.style.position         = "absolute";
	
	//appLayer.style.padding          = "1px";
	appLayer.style.width            = w;
	appLayer.style.height           = h;
	appLayer.style.left             = ( l == -1 ) ? this.getBodyWidth()/2-w/2 : l;
	//appLayer.style.top              = screen.height/2+document.documentElement.scrollTop-h/2-200;
	//alert(this.getBodyHeight()/2);
	appLayer.style.top              = ( t == -1 ) ? this.getBodyHeight()/2-h/2 : t;
	appLayer.style.overflow         = "auto";
	appLayer.style.textAlign        = "center";
	appLayer.style.zIndex           = "10001";
	
	document.body.appendChild(appLayer);
	$(this.appId).innerHTML="<div style=\"padding:10px;color:white;text-align:center;font-size:12px\">正在加载数据...<br/>如果长时间没有加载成功,请更换成IE浏览器进行预览!</div>";

} 

Layer.prototype._init = function(bgclor,opacity,appWidth,appHeight,appLeft,appTop){
	
	this.createAppLayer(appWidth,appHeight,appLeft,appTop);

	this.createCoverLayer(bgclor,opacity);
}

Layer.prototype._destroy = function(){

		document.body.removeChild($(this.appId))	;
		document.body.removeChild($(this.coverId))	;

}