﻿//取得 Event
Object.reEvent = function () {
return window.event ? window.event : (function (o) {
while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0])){
o = o.caller;
}
return o.arguments[0];
})(this.reEvent)
}
function ChangeLogListMode(Mode) {
var ListElement = document.getElementsByName("HiddenLogBrief");
for (var i=0; i<ListElement.length; i++) {
if(Mode == "List") {
ListElement[i].parentNode.style.display = "";
} else {
ListElement[i].parentNode.style.display = "none";
}
}
document.getElementById("LogListMode_List").style.fontWeight	= "";
document.getElementById("LogListMode_Normal").style.fontWeight	= "";
document.getElementById("LogListMode_"+Mode).style.fontWeight	= "Bold";
}
//==============================
//顯示驗證編碼
//==============================
function GetCheckCode(Part) {
document.getElementById("CheckCodeBox_"+Part).innerHTML = "<img src=\""+BlogPath+"Include/AS_CheckCode.Asp?Part="+Part+"&Random="+Math.random()+"\" width=\"72\" height=\"22\" border=\"0\" align=\"absmiddle\" id=\"CheckCodePic\" title=\"重新產生驗證編碼\" class=\"Pointer\" onclick=\"this.src='"+BlogPath+"Include/AS_CheckCode.Asp?Part="+Part+"&Random='+Math.random();\">";
}
function ShowSidePanel() {
var ActionFile = "Ajax.Asp?Action=SidePanel&Part=";
if (document.getElementById("LoginASideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"LoginA", "LoginASideDiv");
if (document.getElementById("LoginBSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"LoginB", "LoginBSideDiv");
if (document.getElementById("CalendarSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"Calendar", "CalendarSideDiv");
if (document.getElementById("CountSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Count", "CountSideDiv");
if (document.getElementById("CommentSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"Comment", "CommentSideDiv");
if (document.getElementById("GBSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"GB", "GBSideDiv");
//if (document.getElementById("TagSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Tag", "TagSideDiv");
//if (document.getElementById("LinkSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"Link", "LinkSideDiv");
}
//==============================
//判斷電子信箱格式是否正確
//==============================
function isEmail(Str) {
if (Str.length < 6) {
return false;
} else {
var regu = /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
if (regu.test(Str)) return true;
return false;
}
}
//==============================
//字數限制,一個中文字算二的字串
//==============================
function getLength(Str) {
var len = 0;
var i;
for (i=0; i<Str.length; i++) {
if (Str.charCodeAt(i) > 255) {
len+=2;
} else {
len++;
}
}
return len;
}
//==============================
//Ajax 登入
//==============================
function AjaxLogin(Mode) {
BlurForm("LoginForm");
ASAjax.postf(
"LoginForm",
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
if (ReturnValue[0] == "Finish") {
hideASBox();
AjaxUpdate(BlogPath+"Ajax.Asp?Action=SidePanel&Part=Login"+Mode, "Login"+Mode+"SideDiv");
} else if ( ReturnValue[0] == "Wrong_CheckCode") {
GetCheckCode("Login");
document.getElementById("ASBox_main").innerHTML = ReturnValue[1];
} else {
document.getElementById("ASBox_main").innerHTML = ReturnValue[1];
}
}
);
}
//==============================
//Ajax 顯示行事日曆
//==============================
function ShowCalendar(TheYear,TheMonth) {
AjaxUpdate(BlogPath+"Ajax.Asp?Action=SidePanel&Part=Calendar&TheYear="+TheYear+"&TheMonth="+TheMonth, "CalendarSideDiv");
}
//==============================
//Ajax 儲存評論
//==============================
function AjaxSaveComment(Part,FromID,IsHtml,Editor) {
BlurForm("SaveCommentForm");
document.getElementById("SaveCommentBtn").disabled = true;
ASAjax.postf(
"SaveCommentForm",
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
if (ReturnValue[0] == "Finish") {
hideASBox();
document.getElementById("SaveInfo").innerHTML		= ReturnValue[1];
document.getElementById("SaveInfo").style.display	= "";
AjaxUpdate(BlogPath+"Ajax.Asp?Action=ViewComment&Part="+Part+"&FromID="+FromID+"&IsHtml="+IsHtml+"&page=200", "ListForPaginate");
AjaxUpdate(BlogPath+"Ajax.Asp?Action=WriteComment&Part="+Part+"&FromID="+FromID+"&IsHtml="+IsHtml, "WriteComment");
GoToScroller("ListForPaginate",300);
} else if (ReturnValue[0] == "Wait") {
document.getElementById("ASBox_main").innerHTML	= ReturnValue[1];
} else if ( ReturnValue[0] == "Wrong_CheckCode") {
GetCheckCode("Comment");
document.getElementById("ASBox_main").innerHTML		= ReturnValue[1];
document.getElementById("SaveCommentBtn").disabled	= false;
} else {
document.getElementById("SaveCommentBtn").disabled	= false;
document.getElementById("ASBox_main").innerHTML		= ReturnValue[1];
}
}
);
}
//==============================
//Ajax 儲存留言
//==============================
function AjaxSaveGB() {
BlurForm("SaveGBForm");
document.getElementById("SaveGBBtn").disabled = true;
ASAjax.postf(
"SaveGBForm",
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
document.getElementById("ASBox_main").innerHTML	= ReturnValue[1];
if (ReturnValue[0] == "Finish") {
document.getElementById("ASBox_closeimg").onclick = function () { hideASBox();window.location.href = BlogPath + '?GB'; }
} else {
document.getElementById("SaveGBBtn").disabled = false;
}
}
);
}
function ReWriteLink() {
AjaxUpdate(BlogPath + "Ajax.Asp?Action=WriteLink","ASBox_main");
}
function AjaxSaveLink() {
BlurForm("SaveLinkForm");
ASAjax.postf(
"SaveLinkForm",
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
document.getElementById("ASBox_main").innerHTML	= ReturnValue[1];
}
);
}
//==============================
//Ajax 檢查日誌密碼
//==============================
function AjaxCheckLogPwd(LogID) {
ShowASBox(2,'系統提示','正在驗證您輸入的日誌查閱密碼，請稍後．．．',205,425,0,2,false);
BlurForm("LogPwdForm");
document.getElementById("LogPwdButton").disabled = true;
ASAjax.get(
BlogPath+"Ajax.Asp?Action=CheckLogPwd&LogID="+LogID+"&LogPassword="+document.getElementById("LogPassword").value,
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
if (ReturnValue[0] == "Finish") {
document.getElementById("ASBox_main").innerHTML	= "驗證通過！開始載入日誌內容，請稍後．．．";
document.getElementById("LogPwdDiv").innerHTML	= ReturnValue[1];
hideASBox();
} else {
document.getElementById("LogPwdButton").disabled	= false;
document.getElementById("ASBox_main").innerHTML		= ReturnValue[1];
}
}
);
}
//==============================
//更新會員的收藏
//==============================
function UpdateMemberFav(Mode,LogID) {
ASAjax.get(
BlogPath+"Member/Index.Asp?Action=MemberFav&Mode="+Mode+"&LogID="+LogID,
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
document.getElementById("ASBox_main").innerHTML = ReturnValue[1];
}
);
}
//==============================
//評論及留言的作者
//==============================
function WriteAuthorName(InputID,Word) {
var InputObj = document.getElementById(InputID);
if ( InputObj != true ) {
InputObj.value = Word;
}
}
function BlurForm(FormID) {
var formObj = document.getElementById(FormID);
for (var i=0; i<formObj.elements.length; i++) {
formObj.elements[i].blur();
}
}
//==============================
//顯示|隱藏 Div
//==============================
function mousePosition(evt){
if(evt.pageX || evt.pageY){
return {x:evt.pageX, y:evt.pageY};
}
return {
x:evt.clientX + document.body.scrollLeft - document.body.clientLeft,
y:evt.clientY + document.body.scrollTop  - document.body.clientTop
}
}
function ShowBlock(showObj,posObj,hideObj,toppx,leftpx) {
var divobj		= document.getElementById(showObj);
var divposition	= document.getElementById(posObj);
if (divobj.style.display == "none" || divobj.style.visibility == "hidden") {
var posY = divposition.offsetTop;
var posH = divposition.clientHeight;
var posX = divposition.offsetLeft;
while (divposition = divposition.offsetParent) {
posY += divposition.offsetTop;
posX += divposition.offsetLeft;
}
divobj.style.top		= posY + posH + toppx + "px";
divobj.style.left		= posX + leftpx + "px";
divobj.style.display	= "block";
divobj.style.visibility	= "visible";
if (hideObj == true) {
Object.reEvent().cancelBubble	= true;
document.onclick = function () {
var mousePos = mousePosition(Object.reEvent());
if (divobj.offsetLeft	> mousePos.x || divobj.offsetLeft	+ divobj.offsetWidth	< mousePos.x ||
divobj.offsetTop	> mousePos.y || divobj.offsetTop	+ divobj.offsetHeight	< mousePos.y) {
divobj.style.display	= "none";
divobj.style.visibility = "hidden";
document.onclick		= null;
}
}
}
} else {
divobj.style.display	= "none";
divobj.style.visibility = "hidden";
}
}
//==============================
//顯示 Tip
//==============================
function ClearEdge(obj,whichedge) {
var edgeoffset = (whichedge == "rightedge") ? parseInt("9px")*-1 : parseInt("0")*-1;
if (whichedge == "rightedge") {
var windowedge = document.body.scrollLeft + document.body.clientWidth - 30;
tipobj.contentmeasure = tipobj.offsetWidth;
if (windowedge - tipobj.x < tipobj.contentmeasure)
edgeoffset = tipobj.contentmeasure + obj.offsetWidth + parseInt("9px");
} else {
var windowedge = document.body.scrollTop + document.body.clientHeight - 15;
tipobj.contentmeasure = tipobj.offsetHeight;
if (windowedge - tipobj.y < tipobj.contentmeasure)
edgeoffset = tipobj.contentmeasure - obj.offsetHeight;
}
return edgeoffset;
}
function ShowTip(text,pos,tipwidth) {
var divblock = document.createElement("div");
divblock.setAttribute("id", "TipBox");
document.body.appendChild(divblock);
tipobj = document.getElementById("TipBox");
if (document.getElementById("TipBox")) {
tipobj = document.getElementById("TipBox")
if (tipwidth != "") {
tipobj.widthobj			= tipobj.style;
tipobj.widthobj.width	= tipwidth;
}
var FinalLeft	= pos.offsetLeft;
var FinalTop	= pos.offsetTop;
var parentEl	= pos.offsetParent;
while (parentEl != null) {
FinalLeft	= FinalLeft + parentEl.offsetLeft;
FinalTop	= FinalTop	+ parentEl.offsetTop;
parentEl	= parentEl.offsetParent;
}
tipobj.x				= FinalLeft;
tipobj.y				= FinalTop;
tipobj.style.left		= tipobj.x - ClearEdge(pos, "rightedge") + pos.offsetWidth + "px";
tipobj.style.top		= tipobj.y - ClearEdge(pos, "bottomedge") + "px";
//tipobj.style.left		= tipobj.x - ClearEdge(pos, "rightedge") + pos.offsetWidth + 18 + "px";
//tipobj.style.top		= tipobj.y - ClearEdge(pos, "bottomedge") + 8 + "px";
tipobj.style.visibility	= "Visible";
iframeStr = "<iframe id='iframebox' frameBorder='0' style='filter:alpha(opacity=0);'></iframe>";
tipobj.innerHTML = iframeStr + text;
iframeObj = document.getElementById("iframebox");
iframeObj.style.visibility	= "inherit";
iframeObj.style.position	= "absolute";
iframeObj.style.top			= "0px";
iframeObj.style.left		= "0px";
iframeObj.style.marginLeft	= "-1px";
iframeObj.style.width		= tipobj.clientWidth + 4 + "px";
iframeObj.style.height		= tipobj.clientHeight + 2 + "px";
iframeObj.style.zIndex		= "-1";
pos.onmouseout = function() {
if (document.getElementById("TipBox")) {
document.body.removeChild(document.getElementById("TipBox"));
//if (document.getElementById("TipBox")) {
//}
}
}
}
}
//轉換為數字
function FormatInt(v) {
v = parseInt(v);
return isNaN(v) ? 0 : v;
}
function GetPosition(e) {
var l	= 0;
var t	= 0;
var w	= FormatInt(e.style.width);
var h	= FormatInt(e.style.height);
var wb	= e.offsetWidth;
var hb	= e.offsetHeight;
while (e.offsetParent){
l += e.offsetLeft + (e.currentStyle?FormatInt(e.currentStyle.borderLeftWidth):0);
t += e.offsetTop  + (e.currentStyle?FormatInt(e.currentStyle.borderTopWidth):0);
e = e.offsetParent;
}
l += e.offsetLeft + (e.currentStyle?FormatInt(e.currentStyle.borderLeftWidth):0);
t += e.offsetTop  + (e.currentStyle?FormatInt(e.currentStyle.borderTopWidth):0);
return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
}
function GetWindowScroll() {
var t, l, w, h;
if (document.documentElement && document.documentElement.scrollTop) {
t = document.documentElement.scrollTop;
l = document.documentElement.scrollLeft;
w = document.documentElement.scrollWidth;
h = document.documentElement.scrollHeight;
} else if (document.body) {
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
}
return { t: t, l: l, w: w, h: h };
}
function GoToScroller(StopObj,Speed) {
if (typeof StopObj != "object") { StopObj = document.getElementById(StopObj); }
if (!StopObj) return;
var z = this;
z.StopObj = StopObj;
z.p = GetPosition(StopObj);
z.s = GetWindowScroll();
z.clear = function(){window.clearInterval(z.timer);z.timer=null};
z.t=(new Date).getTime();
z.step = function(){
var t = (new Date).getTime();
var p = (t - z.t) / Speed;
if (t >= Speed + z.t) {
z.clear();
window.setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
} else {
st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
z.scroll(st, sl);
}
};
z.scroll	= function (t, l){window.scrollTo(l, t)};
z.timer		= window.setInterval(function(){z.step();},13);
}
function ShowOrHide(ShowObj) {
document.getElementById(ShowObj).style.display = document.getElementById(ShowObj).style.display == "none" ? "block" : "none";
}
//==============================
//uBB 語法
//==============================
function RunCode(CodeNum) {
var bodyTag = document.getElementById(CodeNum).value;
preWin = window.open('ASUBB-RunCode','','left=0,top=0,width=550,height=400,resizable=1,scrollbars=1,status=1, toolbar=1,menubar=0');
preWin.document.open();
preWin.document.write(bodyTag);
preWin.document.close();
preWin.document.title="uBB-執行測試";
//preWin.document.charset="UTF-8";
}
function CopyContent(Content) {
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", Content);
} else if (navigator.userAgent.indexOf("Opera") != -1) {
window.location = Content;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("您使用的 FireFox 瀏覽器安全性設定過高，將會造成部分功能或佈景主題發生錯誤！");
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext = Content;
str.data = copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip) return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("內容已經複製到剪貼簿！");
}
//==============================
//Ajax 部分
//==============================
var ASAjax = new AJAXRequest;
ASAjax.setcharset("utf-8");
//ASAjax.onrequeststart	= function() {
//document.getElementById("loadingDiv").style.display="block";
//}
//ASAjax.onrequestend		= function() {
//document.getElementById("loadingDiv").style.display="none";
//}
//Ajax 儲存資料
function AjaxSave(formobj) {
ASAjax.postf(
formobj,
function(obj) {
var ReturnValue = eval('(' + obj.responseText + ')');
document.getElementById("ASBox_main").innerHTML = ReturnValue[1];
}
);
}
function AjaxUpdate(url, updateobj) {
ASAjax.get(url, updateobj);
}
function AjaxAction(url) {
ASAjax.get(
url,
function(obj) { eval(obj.responseText); }
);
}