//==============================
// ASBox_信息提示窗口
// Powered By FelixDong
// Last Update: 2007.09.26
//==============================
//所需参数:
//标题: Title, 类型: Type[1-图片,2-Html], 内容(图片的话就是图片地址,内容的话就是隐藏DIV的ID): ContentObj, 高度: Height, 宽度: Width, 链接地址: Url, 效果类型:Effect[1-无效果;2-立即变暗,3-渐变变暗], 是否保持屏幕中央: Center[true-保持中央,false-固定]
function ShowAlertBox(Type, Title, ContentObj, Height, Width, Url, Effect, Center) {
	//函数初始化开始
	var ASBox_Type		= 2;
	var ASBox_content	= "正在加载内容,请稍后...";
	var Effect_Type		= 1;
	var isCenter		= false;
	var gotoUrl			= 0;
	var loadCancelled	= false;
	//函数初始化结束
	//构建所需要的层元素开始
	var strHTML = "<div id=\"ASBox_w\" style=\"display:none;\"></div>\n";
	strHTML +=	"<div id=\"ASBox_progress\" style=\"display:none;\"><img src=\""+BlogPath+"Include/ASBox/ASBox_Loading.gif\" alt=\"正在加载内容,请稍后...\" border=\"0\" /></div>\n";
	strHTML +=	"<div id=\"ASBox_wrapper\" style=\"display:none\">\n";
	strHTML +=	"  <div class=\"ASBox_header\">\n";
	strHTML +=	"    <div id=\"ASBox_header_title\"></div>\n";
	strHTML +=	"    <div class=\"ASBox_header_close\"><span id=\"ASBox_close_span\">关闭窗口</span></div>\n";
	strHTML +=	"  </div>\n";
	strHTML +=	"  <div class=\"ASBox_main\">\n";
	strHTML +=	"    <div class=\"ASBox_border\">\n";
	strHTML +=	"      <div id=\"ASBox_content\"></div>\n";
	strHTML +=	"    </div>\n";
	strHTML +=	"  </div>\n";
	strHTML +=	"</div>\n";
	var ASBox			= document.createElement("div");
	ASBox.setAttribute("id","ASBox");
	ASBox.style.display	= "";
	ASBox.innerHTML		= strHTML;
	document.getElementsByTagName("body")[0].appendChild(ASBox);
	//构建所需要的层元素结束
	//输出底部内容
	var ASBox_wrapper		= getElem('ASBox_wrapper');
	var ASBox_header_title	= getElem('ASBox_header_title');
	var ASBox_openwin		= "<span id='ASBox_openwin'>浏览完整图片</span>";
	if (Title != "") {ASBox_header_title.innerHTML = ASBox_openwin + Title;} else {ASBox_header_title.innerHTML = ASBox_openwin;}
	//定制内容类型
	ASBox_Type		= Type;
	ASBox_content	= ContentObj;
	switch(ASBox_Type) {
		case 1:
			showIndicator();
			imgPreloader = new Image();
			imgPreloader.onload = function() {
				imgPreloader = resizeImageToScreen(imgPreloader);
				hideIndicator();
				var strHTML = "<img src=\""+ASBox_content+"\" alt=\"关闭窗口\" style=\"width:"+imgPreloader.width+"px;height:"+imgPreloader.height+"px;border:0;cursor:hand;margin:0;padding:0;position:absolute;\"/>";
				if (loadCancelled == false) {

					if (Height != 0) {ASBox_wrapper.style.height = Height + 'px';}
					else {ASBox_wrapper.style.height = imgPreloader.height + 'px';}
					if (Width != 0) {ASBox_wrapper.style.width = Width  + 'px';}
					else {ASBox_wrapper.style.width = imgPreloader.width + 'px';}

					ASBox_wrapper.style.display		= "";
					ASBox_wrapper.style.visibility	= "hidden";
					posToCenter(ASBox_wrapper);
					ASBox_wrapper.style.visibility	= "visible";

					setASBoxContent(strHTML);
				}
			}
			loadCancelled		= false;
			imgPreloader.src	= ASBox_content;
			break;

		case 2:
			showIndicator();
			var strHTML = "";

			if (Height != 0) {ASBox_wrapper.style.height = Height + 'px';}
			else {ASBox_wrapper.style.height = '350px';}
			if (Width != 0) {ASBox_wrapper.style.width = Width + 'px';}
			else {ASBox_wrapper.style.height = '180px';}

			hideIndicator();
			ASBox_wrapper.style.display		= "";
			ASBox_wrapper.style.visibility	= "hidden";
			posToCenter(ASBox_wrapper);
			ASBox_wrapper.style.visibility	= "visible";
			getElem('ASBox_content').style.overflow = "auto";

			setASBoxContent(ContentObj);
			break;

		case 3:
			showIndicator();
			var strHTML = "";

			if (Height != 0) {ASBox_wrapper.style.height = Height + 'px';}
			else {ASBox_wrapper.style.height = '350px';}
			if (Width != 0) {ASBox_wrapper.style.width = Width + 'px';}
			else {ASBox_wrapper.style.height = '180px';}

			hideIndicator();
			ASBox_wrapper.style.display		= "";
			ASBox_wrapper.style.visibility	= "hidden";
			posToCenter(ASBox_wrapper);
			ASBox_wrapper.style.visibility	= "visible";
			getElem('ASBox_content').style.overflow = "auto";

			var elemSrc = getElem(ContentObj);
			if(elemSrc) {strHTML = elemSrc.innerHTML;}
			setASBoxContent(strHTML);
			break;

		case 4:
			showIndicator();
			AjaxUrl = ContentObj;
			http.open("GET", AjaxUrl, true);
			http.onreadystatechange = function() {
				if(http.readyState == 4){

					if (Height != 0) {ASBox_wrapper.style.height = Height + 'px';}
					else {ASBox_wrapper.style.height = '350px';}
					if (Width != 0) {ASBox_wrapper.style.width = Width + 'px';}
					else {ASBox_wrapper.style.height = '180px';}

					hideIndicator();
					ASBox_wrapper.style.display		= "";
					ASBox_wrapper.style.visibility	= "hidden";
					posToCenter(ASBox_wrapper);
					ASBox_wrapper.style.visibility	= "visible";
					getElem('ASBox_content').style.overflow = "auto";

					var response = http.responseText;
					setASBoxContent(response);
				}
			}
			http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=GB2312");
			http.send(null);
			break;

		default:
	}
	ASBox_wrapper.style.opacity	= 100;
	ASBox_wrapper.style.filter	= 'alpha(opacity=100)';

	gotoUrl = Url;
	if (ASBox_Type == 2 || ASBox_Type == 3 || ASBox_Type == 4) {
		ASBox_wrapper.onclick = null;
		getElem("ASBox_openwin").style.display="none";
		if (gotoUrl != 0) {
			getElem("ASBox_close_span").onclick = function () {hideASBox();window.location.href = gotoUrl;};
		} else {
			getElem("ASBox_close_span").onclick = function() {hideASBox();}
		}
	} else {
		ASBox_wrapper.onclick = hideASBox;
		getElem("ASBox_openwin").onclick = function (){window.open(ContentObj, "", "fullscreen,scrollbars");};
		getElem("ASBox_close_span").onclick = null;
	}
	//定制背景效果.
	Effect_Type = Effect;
	isCenter	= Center;
	showEffect(Effect_Type);
	if (isCenter == true) {
		window.onscroll = maintPos;
		window.onresize = maintPos;
	}
	//屏蔽<select>
	hideSelects("hidden");
}
//显示背景效果
function showEffect(Effect_Type) {
	var box_w = getElem('ASBox_w');
	if (Effect_Type == 1) {
		box_w.style.opacity	= 0;
		box_w.style.filter	= 'alpha(opacity=0)';
	} else if (Effect_Type == 2) {
		box_w.style.opacity	= 0.8;
		box_w.style.filter	= 'alpha(opacity=80)';
	} else if (Effect_Type == 3) {
		box_w.style.opacity	= 0;
		box_w.style.filter	= 'alpha(opacity=0)';
		setBGOpacity		= setOpacity;
		//修改"8"可以改变渐变程度
		for (var i=0; i<=8; i++) {setTimeout("setBGOpacity('ASBox_w',"+i+")",70*i);}
	}

	box_w.style.display = "";
	var pagesize		= new getPageSize();
	var scrollPos		= new getScrollPos();
	var ua = navigator.userAgent;

	if (ua.indexOf("MSIE ") != -1) {box_w.style.width = pagesize.width+'px';}
	/*else {box_w.style.width = pagesize.width-20+'px';}*/ // scrollbars removed! Hurray!
	//box_w.style.height = pagesize.height+scrollPos.scrollY+'px';
	//box_w.style.height = document.body.clientHeight+scrollPos.scrollY+'px';
	//box_w.style.height = document.body.scrollHeight+scrollPos.scrollY+'px';
	box_w.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight)+'px';

}
//显示loading的画面
function showIndicator() {
	var ASBox_p				= getElem('ASBox_progress');
	ASBox_p.style.display	= "";
	posToCenter(ASBox_p);
	ASBox_p.onclick = function() {hideASBox();hideIndicator();loadCancelled = true;}
}
//结束loading的画面
function hideIndicator() {
	var ASBox_p				= getElem('ASBox_progress');
	ASBox_p.style.display	= "none";
	ASBox_p.onclick			= null;
}
//设置透明度
function setOpacity(elemid,value) {
	var e = getElem(elemid);
	e.style.opacity = value/10;
	e.style.filter = 'alpha(opacity=' + value*10 + ')';
}
//重新规范图片尺寸
function resizeImageToScreen(objImg) {
	var pagesize	= new getPageSize();
	var x			= pagesize.width  - 100;
	var y			= pagesize.height - 100;

	if (objImg.width > x) {
		objImg.height	= objImg.height * (x/objImg.width);
		objImg.width	= x;
		if (objImg.height > y) {
			objImg.width	= objImg.width * (y/objImg.height);
			objImg.height	= y;
		}
	} else if (objImg.height > y) {
		objImg.width	= objImg.width * (y/objImg.height);
		objImg.height	= y;
		if (objImg.width > x) {
			objImg.height	= objImg.height * (x/objImg.width);
			objImg.width	= x;
		}
	}
	if (objImg.width < 280 || objImg.height < 210) {
		objImg.width	= 350;
		objImg.height	= 180;
	}
	return objImg;
}
//隐藏ASBox
function hideASBox() {
	var box_w			= getElem('ASBox_w');
	box_w.style.display = "none";
	var ASBox_wrapper	= getElem('ASBox_wrapper');
	ASBox_wrapper.style.display	= "none";
	getElem('ASBox_content').innerHTML = "";
	window.onscroll		= null;
	//恢复<select>
	hideSelects("visible");
}
//隐藏<select>
function hideSelects(visibility) {
	selects = document.getElementsByTagName("select");
	for (var i=0; i<selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
}
//保证对象随屏幕移动,并居中
function maintPos() {
	var ASBox_wrapper	= getElem('ASBox_wrapper');
	var box_w			= getElem('ASBox_w');
	var pagesize		= new getPageSize();
	var scrollPos		= new getScrollPos();
	var ua				= navigator.userAgent;

	if (ua.indexOf("MSIE ") != -1) {box_w.style.width = pagesize.width+'px';}

	/*else {box_w.style.width = pagesize.width-20+'px';}*/

	if (ua.indexOf("Opera/9") != -1) {box_w.style.height = document.body.scrollHeight+'px';}
	else {box_w.style.height = pagesize.height+scrollPos.scrollY+'px';}

	//box_w.style.height = document.body.scrollHeight+50+'px';

	posToCenter(ASBox_wrapper);
}
//使对象居为屏幕中央
function posToCenter(elem) {
	var scrollPos	= new getScrollPos();
	var pageSize	= new getPageSize();
	var emSize		= new getElementSize(elem);
	var x			= Math.round(pageSize.width/2) - (emSize.width /2) + scrollPos.scrollX;
	var y			= Math.round(pageSize.height/2) - (emSize.height /2) + scrollPos.scrollY;
	elem.style.left	= x+'px';
	elem.style.top	= y+'px';
}
//计算滚动条像素
function getScrollPos() {
	var docElem		= document.documentElement;
	this.scrollX	= self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
	this.scrollY	= self.pageYOffset || (docElem&&docElem.scrollTop)  || document.body.scrollTop;
}
//取得页面尺寸
function getPageSize() {
	var docElem	= document.documentElement
	this.width	= self.innerWidth  || (docElem&&docElem.clientWidth)  || document.body.clientWidth;
	this.height	= self.innerHeight || (docElem&&docElem.clientHeight) || document.body.clientHeight;
}
//取得对象尺寸
function getElementSize(elem) {
	this.width	= elem.offsetWidth  || elem.style.pixelWidth;
	this.height = elem.offsetHeight || elem.style.pixelHeight;
}
//输出内容
function setASBoxContent(str) {
	getElem('ASBox_content').innerHTML		= "";
	getElem('ASBox_content').style.overflow	= "auto";
	getElem('ASBox_content').innerHTML		= str;
}
//documentgetElementById的简写函数
function getElem(elemId) {
	return document.getElementById(elemId);
}
//Ajax的简单应用
function createRequestObject() {
	var xmlhttp;
		/*@cc_on
	@if (@_jscript_version>= 5)
			try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
					try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
					catch (E) {xmlhttp = false;}
			}
	@else
		xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
		try {xmlhttp = new XMLHttpRequest();} catch (e) {xmlhttp = false;}
	}
	return xmlhttp;
}
var http = createRequestObject();