﻿function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function getRadom(intMax){
    var intR = Math.floor(Math.random() * (intMax + 1));
    if (intR == 0)
        intR = 1;
    return intR;
}
function hideUserInfo(idx, uid){
    document.getElementById("dvInfo2_"+idx).style.display = "none";
    document.getElementById("window_avatar_"+idx).setAttribute("src", "/UploadFiles/Users/HeadImage/"+uid.toString().substring(0,1)+"/"+uid+"/" + uid + "_98173_HeadPhoto_Default_Cut_S.jpg?" + getRadom(999999).toString());
}
function showUserInfo(idx, uid){
    document.getElementById("dvInfo2_"+idx).style.display = "";
    document.getElementById("window_avatar_"+idx).setAttribute("src", "/UploadFiles/Users/HeadImage/"+uid.toString().substring(0,1)+"/"+uid+"/" + uid + "_98173_HeadPhoto_Default_Cut_B.jpg?" + getRadom(999999).toString());
}
var bStatus = 0;
var nRowNo = 0;
function UserInfoAll(){
    if(bStatus == 0){
        for(idx = 1; idx<=nRowNo; idx++){
            if(!document.getElementById("dvInfo2_"+idx)) continue;
            document.getElementById("dvInfo2_"+idx).style.display = "none";
            var oImage = document.getElementById("window_avatar_"+idx);
            if(oImage.src != null){oImage.src = oImage.src.replace("_B.jpg", "_S.jpg")};
        }
        bStatus = 1;
    }else{
        for(idx = 1; idx<=nRowNo; idx++){
            if(!document.getElementById("dvInfo2_"+idx)) continue;
            document.getElementById("dvInfo2_"+idx).style.display = "";
            var oImage = document.getElementById("window_avatar_"+idx);
            if(oImage.src != null){oImage.src = oImage.src.replace("_S.jpg", "_B.jpg")};
        }
        bStatus = 0;
    }
}
function MM_openBrWindow(theURL,winName,w,h,bar){
    var leftpix,toppix,features;
    leftpix=eval(screen.availWidth/2)-eval(w)/2;
    toppix=eval(screen.availHeight/2)-eval(h)/2;
    features = "width=" + w + ",height=" + h + ",left=" + leftpix + ",top=" + toppix + ",scrollbars=" + bar;
    window.open(theURL,winName,features);
}
function onGetSignContent(signObj){
    signObj = document.getElementById(signObj);
    if(signObj != null){
        val = "/Setup/Sign_Edit.aspx?fscon=" + escape(signObj.innerHTML);
        MM_openBrWindow(val, "Signature", 800, 400, "no");
    }
}
function onPageClick(pgid){
    var bUrl = (location.href.toLowerCase().indexOf("news_page_new") != -1)? "News_Page_New.aspx" : "News_Page.aspx";
    location.href = bUrl + "?nid=" + nid + "&p=" + pgid;
}
function onUndoClosePost(rid){
    val = "cbk=ucp&rid=" + rid;
    retxml = DoCallbackPost("News_Page.aspx", val, false);
    ret = retxml.responseText.split(',');
    alert(ret[1]);
    if(ret[0] == "1"){
        location.reload(true);
    }
}
function detectbrowser(){
    if (window.ActiveXObject) {
        try {
            return 1;
        } catch (e) {
            try {
                return 2;
            } catch (e2) {
                return 0;
            }
        }
    } else if (window.XMLHttpRequest) {
        return 100;
    } else {
        return 0;
    }
}
function onDeleteNewsArticle(nForumID, nThisTitleID, nThisReplyID, nThisReplyAuthorPID, nShowHandBonusRate){
    val = "cbk=onDeleteNewsArticle&nForumID=" + nForumID + "&nThisTitleID=" + nThisTitleID + "&nThisReplyID=" + nThisReplyID + "&nThisReplyAuthorPID=" + nThisReplyAuthorPID + "&nShowHandBonusRate=" + nShowHandBonusRate;
    retxml = DoCallbackPost("News_Page.aspx", val, false);
    ret = retxml.responseText.split(',');
    alert(ret[1]);
    if(ret[0] == "1"){
        location.href = top.location.href;
    }
}
function onGoodPointArticle(bIsTitle, nArticleID, nArticleAuthorPID, nGiverPID, sGiverNickName, sGoodPointReason){
    if(confirm("確定要「推文」這篇文章 ?")){ 
        val = "cbk=onGoodPointArticle&bIsTitle=" + bIsTitle + "&nArticleID=" + nArticleID + "&nArticleAuthorPID=" + nArticleAuthorPID + "&nGiverPID=" + nGiverPID + "&sGiverNickName=" + escape(sGiverNickName) + "&sGoodPointReason=" + escape(sGoodPointReason);
        retxml = DoCallbackPost("News_Page.aspx", val, false);
        ret = retxml.responseText.split(',');
        alert(ret[1]);
        if(ret[0] == 1){
            document.getElementById("infoGPS").style.display = "none";                     
            var sObjID = "";
            var nNewValue = 0;
            sObjID = "Reply_" + ret[3]  + "_GoodPoints_Span";
            nNewValue = parseInt(GetText(sObjID)) + 1;
            SetText(sObjID, nNewValue.toString());
        }
    }
}
function onProsecutionArticle(bIsTitle, nArticleID, nArticleAuthorPID, nGiverPID, sGiverNickName, sGoodPointReason){
    if(confirm("確定要「檢舉」這篇文章 ?")){
        val = "cbk=onProsecutionArticle&bIsTitle=" + bIsTitle + "&nArticleID=" + nArticleID + "&nArticleAuthorPID=" + nArticleAuthorPID + "&nGiverPID=" + nGiverPID + "&sGiverNickName=" + sGiverNickName + "&sGoodPointReason=" + sGoodPointReason;
        retxml = DoCallbackPost("News_Page.aspx", val, false);
        ret = retxml.responseText.split(',');
        alert(ret[1]);        
        if(ret[0] == 1){
            document.getElementById("infoProsecution").style.display = "none";
            
            var sObjID = "";
            var nNewValue = 0;
            sObjID = "Reply_" + ret[3]  + "_ProsecutionCounts_Span";
            nNewValue = parseInt(GetText(sObjID)) + 1;                        
            SetText(sObjID, nNewValue.toString());
        }
    }
}
function SetText(oObjID,sValue){        
    if(window.navigator.userAgent.toLowerCase().indexOf("msie") >=1){
        document.getElementById(oObjID).innerText = sValue;
    }else{
        document.getElementById(oObjID).textContent = sValue;
    }    
}
function GetText(oObjID){
    var sValue = "";
    if(window.navigator.userAgent.toLowerCase().indexOf("msie") >=1){
        sValue = document.getElementById(oObjID).innerText;
    }else{
        sValue = document.getElementById(oObjID).textContent;
    }
    return sValue;
}
function DoLogin(){
    if (confirm("尚未登入 ! 是否先登入 ?"))
        location.href='https://member.98173.com.tw/Login/Login.aspx?FromUrl='+escape(location.href);
}
var dragapproved=false;
function initializedragie(e, obj) {
    iex=e.clientX;
    iey=e.clientY;
    tempx=parseInt(document.getElementById(obj).style.left, 10);
    tempy=parseInt(document.getElementById(obj).style.top, 10);
    
    dragapproved=true;
    objName = obj;
    document.onmousemove= function(e) {
        if (dragapproved==true) {
            var evt = e||window.event;
            document.getElementById(objName).style.left=tempx + evt.clientX-iex + "px";
            document.getElementById(objName).style.top=tempy + evt.clientY-iey + "px";
            document.getElementById("HelpFrame").style.left=tempx + evt.clientX-iex+20 + "px";
            document.getElementById("HelpFrame").style.top=tempy + evt.clientY-iey+20 + "px";
            
            return false; } }
}

document.onmouseup=new Function("dragapproved=false");
function onChangeTab(tab){
    for(var i=0; i<document.getElementById('UlTabMoreLink').childNodes.length; i++){
        if(document.getElementById('UlTabMoreLink').childNodes[i].nodeName == "LI"){
            document.getElementById('UlTabMoreLink').childNodes[i].className = "";
        }
    }
    document.getElementById("newsLink" + (tab + 1).toString()).className = "Tab_On";
    for(var i=0; i<3; i++){
        document.getElementById('newsContant' + i.toString()).style.display = "none";
    }
    document.getElementById('newsContant' + tab.toString()).style.display = "";
}
function PostClose_area(obj){
    if (obj != null){
        switch_PostClose_area(obj);
    }else{
        var objs = document.getElementsByName("imgClose");
        for(var i=0; i<objs.length; i++){
            switch_PostClose_area(objs[i]);
        }
    } 
}
function switch_PostClose_area(obj){
    var par_chd_objs = obj.parentNode.parentNode.parentNode.childNodes;
    for (var j=0; j<par_chd_objs.length; j++)
    {
        if(par_chd_objs[j].className == "textarea" && par_chd_objs[j].tagName == "DIV")
        {
            if(par_chd_objs[j].style.display == "")
                par_chd_objs[j].style.display = "none";
            else
                par_chd_objs[j].style.display = "";
        }
    }
    var prev_par_chd_objs = obj.parentNode.parentNode.parentNode.previousSibling.childNodes;
    if (prev_par_chd_objs.length == 0)
    {
        prev_par_chd_objs = get_prevsibling(obj.parentNode.parentNode.parentNode.previousSibling).childNodes;
    }
    for (var j=0; j<prev_par_chd_objs.length; j++)
    {
        if(prev_par_chd_objs[j].className == "avatar" && prev_par_chd_objs[j].tagName == "DIV")
        {
            if(prev_par_chd_objs[j].style.display == "")
                prev_par_chd_objs[j].style.display = "none";
            else
                prev_par_chd_objs[j].style.display = "";
        }
        
        if(prev_par_chd_objs[j].className == "other" && prev_par_chd_objs[j].tagName == "DIV")
        {
            if(prev_par_chd_objs[j].style.display == "")
                prev_par_chd_objs[j].style.display = "none";
            else
                prev_par_chd_objs[j].style.display = "";
        }
    }
}
function ImgResize(obj){
    var imgw = obj.offsetWidth;
    var imgh = obj.offsetHeight;
    ResizePageIMG(obj, imgw, imgh);
}
function ResizePageIMG(imgObj,iImgSrcWidth,iImgSrcHeight){
    var iMaxWidth = 600 ;
    var iMaxHeight = 450 ;
    ImageReSizeMax(imgObj,iMaxWidth,iMaxHeight,iImgSrcWidth,iImgSrcHeight)
}
function ImageReSizeMax( sImgurl, iMaxWidth , iMaxHeight , iImgSrcWidth, iImgSrcHeight){
    var oImageOriginal ;
    
    srcWidth = iImgSrcWidth;
    srcHeight = iImgSrcHeight;
    
    if ((srcWidth > iMaxWidth) || (srcHeight > iMaxHeight)){
        if(srcWidth > iMaxWidth){
            srcHeight = iMaxWidth * srcHeight / srcWidth;
            srcWidth = iMaxWidth;
        }

        if(srcHeight > iMaxHeight){
            srcWidth = iMaxHeight * srcWidth / srcHeight;
            srcHeight = iMaxHeight;
        }
    }
    srcHeight = Math.round(srcHeight);
    srcWidth = Math.round(srcWidth);
    vSpac = Math.round((iMaxHeight - srcHeight) / 2)
    hSpac = Math.round((iMaxWidth - srcWidth) / 2)
    sImgurl.width = srcWidth;
    sImgurl.height = srcHeight;
    return 0;
}