﻿function ShowASBox(Type, Title, Content, 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 ASBox_Drag		= false;
var ASBox_Skin		= "ASBox_Skin_ASBLOG";
var strHTML = "<div id=\"ASBox_window\" 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_body\" class=\""+ASBox_Skin+"\" style=\"display:none;position:absolute;\">\n";
strHTML +=	"<div id=\"ASBox_handle\" class=\"ASBox_header\">\n";
strHTML +=	"<div id=\"ASBox_header_title\"></div>\n";
strHTML +=	"<div class=\"ASBox_header_close\"><img src=\""+BlogPath+"Include/ASBox/ASBox_CloseImg.gif\" id=\"ASBox_closeimg\" /></div>\n";
strHTML +=	"<div style=\"clear: both;\"></div>\n";
strHTML +=	"</div>\n";
strHTML +=	"<div class=\"ASBox_wrap\">\n";
strHTML +=	"<div class=\"ASBox_border\">\n";
strHTML +=	"<div id=\"ASBox_main\"></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_body			= getElem("ASBox_body");
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	= Content;
switch(ASBox_Type) {
case 1:
showIndicator();
imgPreloader = new Image();
imgPreloader.onload = function() {
imgPreloader = resizeImageToScreen(imgPreloader);
hideIndicator();
var strHTML = "<img src=\""+ASBox_Content+"\" title=\"關閉視窗\" style=\"width:"+imgPreloader.width+"px;height:"+imgPreloader.height+"px;border:0;cursor:hand;margin:0;padding:0;position:absolute;\"/>";
if (loadCancelled == false) {
if (imgPreloader.DefaultSize == true) {
ASBox_body.style.height = "205px";
ASBox_body.style.width = "425px";
} else {
if (Height != 0) {ASBox_body.style.height = Height + "px";}
else {ASBox_body.style.height = imgPreloader.height + 100 + "px";}
if (Width != 0) {ASBox_body.style.width = Width + "px";}
else {ASBox_body.style.width = imgPreloader.width + 100 + "px";}
}
ASBox_body.style.display	= "";
ASBox_body.style.visibility	= "hidden";
posToCenter(ASBox_body);
ASBox_body.style.visibility	= "visible";
setASBoxContent(strHTML);
if (ASBox_Drag == true) { if (ASBox_Drag == true) { DragBox(getElem("ASBox_handle"),getElem("ASBox_body")); } }
}
}
loadCancelled		= false;
imgPreloader.src	= ASBox_Content;
break;
case 2:
showIndicator();
var strHTML = "";
if (Height != 0) {ASBox_body.style.height = Height + "px";}
else {ASBox_body.style.height = "425px";}
if (Width != 0) {ASBox_body.style.width = Width + "px";}
else {ASBox_body.style.height = "205px";}
hideIndicator();
ASBox_body.style.display	= "";
ASBox_body.style.visibility	= "hidden";
posToCenter(ASBox_body);
ASBox_body.style.visibility	= "visible";
getElem("ASBox_main").style.overflow = "auto";
setASBoxContent(Content);
if (ASBox_Drag == true) { DragBox(getElem("ASBox_handle"),getElem("ASBox_body")); }
break;
case 3:
showIndicator();
var strHTML = "";
if (Height != 0) {ASBox_body.style.height = Height + "px";}
else {ASBox_body.style.height = "425px";}
if (Width != 0) {ASBox_body.style.width = Width + "px";}
else {ASBox_body.style.height = "205px";}
hideIndicator();
ASBox_body.style.display	= "";
ASBox_body.style.visibility	= "hidden";
posToCenter(ASBox_body);
ASBox_body.style.visibility	= "visible";
getElem("ASBox_main").style.overflow = "auto";
var elemSrc = getElem(Content);
if(elemSrc) {strHTML = elemSrc.innerHTML;}
setASBoxContent(strHTML);
if (ASBox_Drag == true) { DragBox(getElem("ASBox_handle"),getElem("ASBox_body")); }
break;
case 4:
showIndicator();
AjaxUrl = Content;
http.open("GET", AjaxUrl, true);
http.onreadystatechange = function() {
if(http.readyState == 4){
if (Height != 0) {ASBox_body.style.height = Height + "px";}
else {ASBox_body.style.height = "425px";}
if (Width != 0) {ASBox_body.style.width = Width + "px";}
else {ASBox_body.style.height = "205px";}
hideIndicator();
ASBox_body.style.display	= "";
ASBox_body.style.visibility	= "hidden";
posToCenter(ASBox_body);
ASBox_body.style.visibility	= "visible";
getElem("ASBox_main").style.overflow = "auto";
var response = http.responseText;
setASBoxContent(response);
if (ASBox_Drag == true) { DragBox(getElem("ASBox_handle"),getElem("ASBox_body")); }
}
}
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf8");
http.send(null);
break;
default:
}
ASBox_body.style.opacity= 100;
ASBox_body.style.filter	= "alpha(opacity=100)";
gotoUrl = Url;
if (ASBox_Type == 2 || ASBox_Type == 3 || ASBox_Type == 4) {
ASBox_body.onclick = null;
getElem("ASBox_openwin").style.display = "none";
if (gotoUrl != 0) {
getElem("ASBox_closeimg").onclick = function () {hideASBox();window.location.href = gotoUrl;};
} else {
getElem("ASBox_closeimg").onclick = function() {hideASBox();}
}
} else {
ASBox_body.onclick = hideASBox;
getElem("ASBox_openwin").onclick = function (){window.open(Content, "", "fullscreen,scrollbars");};
getElem("ASBox_closeimg").onclick = null;
}
Effect_Type = Effect;
isCenter	= Center;
showEffect(Effect_Type);
if (isCenter == true) {
window.onscroll = maintPos;
window.onresize = maintPos;
}
hideSelects("hidden");
}
function showEffect(Effect_Type) {
var box_w = getElem("ASBox_window");
switch (Effect_Type) {
case 0 :
box_w.style.opacity		= 0.8;
box_w.style.background	= "#FFFFFF";
box_w.style.filter		= "alpha(opacity=75)";
break;
case 1 :
box_w.style.opacity		= 0;
box_w.style.filter		= "alpha(opacity=0)";
break;
case 2 :
box_w.style.opacity		= 0.8;
box_w.style.filter		= "alpha(opacity=80)";
break;
case 3 :
box_w.style.opacity		= 0;
box_w.style.filter		= "alpha(opacity=0)";
setBGOpacity			= setOpacity;
for (var i=0; i<=8; i++) { setTimeout("setBGOpacity('ASBox_window',"+i+")",70*i); }
break;
}
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";
}
function showIndicator() {
var ASBox_p				= getElem("ASBox_progress");
ASBox_p.style.display	= "";
posToCenter(ASBox_p);
ASBox_p.onclick = function() {hideASBox();hideIndicator();loadCancelled = true;}
}
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;
//var x				= pagesize.width;
//var y				= pagesize.height;  //堂修改

var IsDefaultSize	= false;
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 < 375 && objImg.height < 155) {
//objImg.width	= 375;
//objImg.height	= 155;
IsDefaultSize	= true;
}
objImg.DefaultSize = IsDefaultSize;
return objImg;
}
function hideASBox() {
var box_w			= getElem("ASBox_window");
box_w.style.display = "none";
var ASBox_body		= getElem("ASBox_body");
ASBox_body.style.display = "none";
getElem("ASBox_main").innerHTML = "";
window.onscroll = null;
hideSelects("visible");
}
function hideSelects(visibility) {
selects = document.getElementsByTagName("select");
for (var i=0; i<selects.length; i++) {
selects[i].style.visibility = visibility;
}
}
function maintPos() {
var ASBox_body	= getElem("ASBox_body");
var box_w		= getElem("ASBox_window");
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_body);
}
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_main").innerHTML			= "";
getElem("ASBox_main").style.overflow	= "auto";
getElem("ASBox_main").innerHTML			= str;
}
function getElem(elemId) {
return document.getElementById(elemId);
}
function DragBox(o1,o2){
o1.onselectstart = function() { return(false); };
o1.onmousedown = function(e) {
e = e || window.event;
e.cancelBubble = true;
var x = e.layerX || e.offsetX;
var y = e.layerY || e.offsetY;
document.onmousemove = function(e) {
e = e || window.event;
o2.style.top	= (e.clientY - y) + "px";
o2.style.left	= (e.clientX - x) + "px";
};
document.onmouseup = function() { document.onmousemove = null; };
};
}
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();