﻿
/*textutil.js start*/
var TextUtil = new Object;

TextUtil.isNotMax = function(oTextArea) {
    return oTextArea.value.length != oTextArea.getAttribute("maxlength");
};
/*textutil.js end*/

/*util start*/
function StringBuffer() {
    this.__strings__ = new Array;
}

StringBuffer.prototype.append = function (str) {
    this.__strings__.push(str);
};

StringBuffer.prototype.toString = function () {
    return this.__strings__.join("");
};
/*util end*/

function Forum_Engine()
{
	var ua;
	this.majorVersion="3";
	this.minorVersion="0.0";
	this.releaseDate="2009-01-20";
}

Forum_Engine.prototype = {
    init: function(settings) {
        this.settings = settings;

        this._def("Id_Post", "comment");
        this._def("Id_AuthorName", "ForumAuthorName");
        this._def("Id_AuthorEmail", "ForumAuthorEmail");
        this._def("Id_AuthorURL", "ForumAuthorURL");
        this._def("Id_Title", "ForumTitle");
        this._def("Id_Comments", "ForumComments");
        this._def("Id_ValidateCode", "ForumValidateCode");
        this._def("Id_ErrorMsg", "ForumErrorMsg");

        this._def("forumBasePath", "http://www.ctitv.com.tw:8081/Forum.aspx");   // 留言板系統的真正url
        this._def("replyUrl", (location.href.indexOf("#" + forum.settings.Id_Post) == -1 ? location.href : location.href.substring(0, location.href.indexOf("#" + forum.settings.Id_Post))));
        this._def("Encoding", "UTF-8");
        this._def("retryTimes", 20);
        this._def("retryIntevals", 500);
        this._def("forumCounts", 0);
        this._def("Debug", false);
        this._def("Page_Size", 5);
        this._def("Ascending", false);
        this._def("ActiveReport", false);
        this._def("contentTitle", (typeof (contentTitle) == "undefined" ? "" : contentTitle));
        this._def("contentAssortment", (typeof (contentAssortment) == "undefined" ? "" : contentAssortment));
        this._def("contentAssortmentId", (typeof (contentAssortmentId) == "undefined" ? "" : contentAssortmentId));
        this._def("channel", (typeof (channel) == "undefined" ? "" : channel));
        this._def("ArticleNo", 0);

        this._def("LABEL_AuthorName", "姓名 / 暱稱：");
        this._def("LABEL_AuthorEmail", "e-mail：");
        this._def("LABEL_AuthorURL", "您的網站：");
        this._def("LABEL_Title", "回應標題：");
        this._def("LABEL_Comments", "回應內容：");
        this._def("LABEL_ValidateCode", "驗證：");
        this._def("LABEL_PageHeader", "頁次：");
        this._def("LABEL_CommentListHeader", "留言和迴響");
        this._def("LABEL_CommentHeader", "我要留言");

        this._def("Text_addCommentButton", "確認發表");
        this._def("Text_cancelCommentButton", "取消發表");

        this._def("ERROR_AuthorName", "姓名 / 暱稱, 請輸入! \r\n");
        this._def("ERROR_AuthorEmail", "e-mail, 請輸入! \r\n");
        this._def("ERROR_AuthorURL", "您的網站, 請輸入! \r\n");
        this._def("ERROR_Title", "回應標題, 請輸入! \r\n");
        this._def("ERROR_Comments", "回應內容, 請輸入! \r\n");
        this._def("ERROR_ValidateCode", "驗證碼, 請輸入! \r\n");
        this._def("ERROR_ContentLinksTooMush", "回應內容只能有3個超連結，請修改! \r\n");
        this._def("ERROR_SaveError", "存檔失敗，可能原因：\n  1.此 url 的 domain  未加入留言系統運作\n  2.帳號(會員ID)已被封鎖\n  3.相同IP在30秒內連續發言");
        this._def("ERROR_CommentLength", "回應內容字數超過，可輸入字數為：");
        this._def("Rows_Comments", 10);
        this._def("Cols_Comments", 40);
        this._def("MaxLength_Comments", 150);

        this._def("SIZE_AuthorName", 40);
        this._def("SIZE_AuthorEmail", 40);
        this._def("SIZE_AuthorURL", 40);
        this._def("SIZE_Title", 40);

        this._def("MaxLength_AuthorName", 10);
        this._def("MaxLength_AuthorEmail", 50);
        this._def("MaxLength_AuthorURL", 100);
        this._def("MaxLength_Title", 30);
        this._def("MaxLength_ValidateCode", 6);
        //擷取留言系統的 domain url，最後會自帶 "/"
        this.settings.forumBase = this.settings.forumBasePath.substring(0, this.settings.forumBasePath.lastIndexOf("/") + 1);
        //使用者可以自訂外部程序內嵌到 forum 繪製完畢後繼續執行，可接受 Forum資料物件
        this.onRenderCompleted = this._getParam("onRenderCompleted", function(data) { });
    },

    _def: function(key, def_val) {
        var v = this._getParam(key, def_val);
        this.settings[key] = v;
    },

    _getParam: function(name, default_value) {
        var value = (typeof (this.settings[name]) == "undefined") ? default_value : this.settings[name];
        return value
    },

    inputValidation: function() {
        var validName = 0;
        var validEmail = 0;
        var validTitle = 0;
        var validComments = 0;
        var validCommentLength = 0;
        var validValidateCode = 0;
        var links = 0;

        // var email = document.getElementById(this.settings.Id_AuthorEmail).value;
        var validate = document.getElementById(this.settings.Id_ValidateCode).value;
        var txt = document.getElementById(this.settings.Id_Comments).value;

        // var name = document.getElementById(this.settings.Id_AuthorName).value
        // akuei
        //var email = 'akuei_wu@mail.infortimes.com.tw';
        //var name = '吳阿貴';
        var email = getcookie('CtvEmail');
        var name = getcookie('CtvUserName');
        var title = document.getElementById(this.settings.Id_Title).value;
        var filter = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (name != '') {
            validName = 1;
        }

        if (filter.test(email)) {
            validEmail = 1;
        }

        if (txt != '') {
            validComments = 1;
        }

        if (txt.length <= this.settings.MaxLength_Comments) {
            validCommentLength = 1;
        }

        if (validate != '') {
            validValidateCode = 1;
        }

        if (title != '') {
            validTitle = 1;
        }

        for (var ind = 0; ind < txt.length; ind++) {
            if (txt.substring(ind, ind + 7) == "http://") {
                links = links + 1;
            } else if (txt.substring(ind, ind + 6) == "ftp://") {
                links = links + 1;
            } else if (txt.substring(ind, ind + 8) == "https://") {
                links = links + 1;
            }
        }

        if (validName == 1 && validEmail == 1 && validComments == 1 && links < 4 && validValidateCode == 1 && validCommentLength == 1 && validTitle == 1) {
            this._submitForm();
        } else {
            var buffer = new StringBuffer();
            buffer.append("Errors: \r\n");
            if (validName == 0) { buffer.append(this.settings.ERROR_AuthorName); }
            if (validEmail == 0) { buffer.append(this.settings.ERROR_AuthorEmail); }
            if (validComments == 0) { buffer.append(this.settings.ERROR_Comments); }
            if (validTitle == 0) { buffer.append(this.settings.ERROR_Title); }
            if (validCommentLength == 0) { buffer.append(this.settings.ERROR_CommentLength + this.settings.MaxLength_Comments); }
            if (validValidateCode == 0) { buffer.append(this.settings.ERROR_ValidateCode); }
            if (links > 3) { buffer.append(this.settings.ERROR_ContentLinksTooMush); }
            window.alert(buffer.toString());
        }
    },

    _resetForm: function() {
        document.getElementById(this.settings.Id_AuthorName).value = "";
        document.getElementById(this.settings.Id_AuthorEmail).value = "";
        document.getElementById(this.settings.Id_AuthorURL).value = "";
        document.getElementById(this.settings.Id_Title).value = "";
        document.getElementById(this.settings.Id_Comments).value = "";
        document.getElementById(this.settings.Id_ValidateCode).value = "";
        document.getElementById(this.settings.Id_ErrorMsg).innerHTML = "";
    },
    //取得留言資料以後，開始建立留言列表
    _callBack: function() {
        var oDiv = document.getElementById(this.settings.Id_Post);
        if (oDiv == undefined || oDiv == null) return;

        var buffer = new StringBuffer();
        buffer.append('<div class="entry">');
        buffer.append('<h2>' + this.settings.LABEL_CommentListHeader + '</h2>');
        buffer.append('<p class="allEntry">' + ((Forum == null || typeof (Forum.Count) == "undefined") ? '0' : Forum.Count) + '篇迴響</p>');

        if (Forum != null && Forum.Count > 0) {
            //this._buildForumBlock(oDiv, Forum.List);
            for (var i = 0; i < Forum.List.length; i++) {
                var forum = Forum.List[i];
                if (typeof (forum) == "undefined") continue;
                Forum.List.idx = i;
                buffer.append('<h3>' + Forum.List[i].Title + '</h3>');
                buffer.append('<p>' + Forum.List[i].Content + '</p>');
                //this._buildSingleForum(oDiv, Forum.List[i]);  繪製我要留言的表單

                if (Forum.List[i].ResponseText && Forum.List[i].ResponseText.length > 0) {
                    //Clear string buffer
                    //有回應則必須繪製
                    buffer.append('<p class="admin">版主回應：</p>');
                    buffer.append('<p class="reply">' + Forum.List[i].ResponseText + '</p>');
                }

                buffer.append('<ul class="info">');
                //buffer.append('<li>' + Forum.List[i].Seq + '樓</li>');
                buffer.append('<li>' + Forum.List[i].Name + '</li>');
                buffer.append('<li class="last">' + Forum.List[i].Published + '</li></ul>');
            }

            //this._buildPageBar(oDiv, Forum);  //分頁bar

            buffer.append('<ul class="page">' + Forum.Pagerbar);
            buffer.append('</ul>');
            buffer.append('</div>');

        }

        //檢查該文章是否有編輯台公告
        //        if (Forum.OnTopResponse && Forum.OnTopResponse.length > 0) {
        //            //有公告則必須繪製
        //            buffer.append('<p class="admin">版主回應：</p>');
        //            buffer.append('<p class="reply">');
        //            buffer.append(Forum.OnTopResponse + '</p>');
        //            buffer.append('<ul class="info">');
        //            buffer.append('<li>999樓</li>');
        //            buffer.append('<li>會員ID</li>');
        //            buffer.append('<li class="last">' + Forum.OnTopResponseTime + '</li></ul>');
        //            
        //        }
        //         var WebUrl = "http://localhost:8397/CtiTVWeb/";
        var WebUrl = "http://www.ctitv.com.tw/";
        //// akuei
        //var CtiMemberID = '87032DA9-C00C-43D0-85B1-3A6376825A86';
        //var CtiNickName = '吳阿貴';
        var CtiMemberID = getcookie('CtvMemberID');
        var CtiNickName = getcookie('CtvNickName');
        if (CtiMemberID != null && CtiMemberID != "") {
            buffer.append('<h2>' + this.settings.LABEL_CommentHeader + '</h2>');
            buffer.append('<fieldset>');
            buffer.append(' <table class="formTbl">');
            buffer.append('     <tr><td colspan="2">標示＊為必填欄位 </td></tr>');
            buffer.append('     <tr><th nowrap>＊會員ID：</th>');
            buffer.append('         <td><input id="ForumAuthorName" value="' + CtiNickName + '" disabled="disabled">');
            buffer.append('             <span class="opt">我不是 <em>' + CtiNickName + '</em>，讓我<a id="Forum_Logout" class="close iframe" href="' + WebUrl + 'Modal/logout_modal.aspx">登出</a>！ </span>');
            buffer.append('              </td></tr>');
            buffer.append('     <tr><th nowrap>&nbsp;&nbsp;&nbsp;&nbsp;＊' + this.settings.LABEL_Title + '</th>');
            buffer.append('         <td><input type="text" class="singleLine" id="' + this.settings.Id_Title + '" maxlength="' + this.settings.MaxLength_Title + '" value="re:' + this.settings.contentTitle + '" /></td></tr>');
            buffer.append('     <tr><th nowrap>＊' + this.settings.LABEL_Comments + '</th>');
            buffer.append('         <td><textarea id="' + this.settings.Id_Comments + '" rows="' + this.settings.Rows_Comments + '" cols="' + this.settings.Cols_Comments + '" maxlength="' + this.settings.MaxLength_Comments + '" onkeypress="return TextUtil.isNotMax(this)"></textarea>');
            buffer.append('             <span class="opt">留言限定150字以內</span></td></tr>');
            buffer.append('     <tr id="anonymouspostcomment1_tbcaptchaimage">');
            buffer.append('         <th nowrap>＊' + this.settings.LABEL_ValidateCode + '</th>');
            buffer.append('         <td><img id="captcha" src="' + this.settings.forumBase + 'captcha.ashx" onload="forum._captchaLoadCheck()" /> <a class="regenerate" href="#" onclick="forum._captchaReLoad();return false;">重新產生驗證碼</a>');
            buffer.append('             <span class="opt">請輸入上圖六位數字驗證碼：');
            buffer.append('             <input id="' + this.settings.Id_ValidateCode + '" maxlength="' + this.settings.MaxLength_ValidateCode + '" value="" />');
            buffer.append('             </span></td></tr>');
            buffer.append('     <tr>');
            buffer.append('         <td colspan="2" class="formBtn"><input id="addCommentButton" onClick="forum.inputValidation();" value=' + this.settings.Text_addCommentButton + ' type="button">');
            buffer.append('             <input id="cancelCommentButton" onClick="forum._resetForm();" value="' + this.settings.Text_cancelCommentButton + '"  type="reset"></td>');
            buffer.append('</tr>');
            buffer.append('<tr>');
            buffer.append('<th>注意事項：</th>');
            buffer.append('<td><p>網友發言請遵守規範，禁止發表、複製和傳播下列文字：</p>');
            buffer.append('<ol>');
            buffer.append('<li>人身攻擊、詆譭謾罵、粗鄙不雅、探人隱私、口水爭執</li>');
            buffer.append('<li>宣揚迷信、色情、賭博、暴力、教唆犯罪</li>');
            buffer.append('<li>違反著作權法的文章、影音、連結等。</li>');
            buffer.append('</ol>');
            buffer.append('<p>上述貼文一經發現，管理者可不通知作者、不作公告而逕行刪除。</p></td>');
            buffer.append('</tr></table></fieldset>');
            //buffer.append('</div>');
            buffer.append('<div id="' + this.settings.Id_ErrorMsg + '"></div><BR />');

        }
        else {

            buffer.append('<table id="noCommentForm" class="formTbl" runat="server">');
            buffer.append('<tr>');
            buffer.append('<td>');
            buffer.append('<h2>我要留言</h2>');
            buffer.append('留言前，請先<a id="Forum_Login" class="close iframe" href="' + WebUrl + 'Modal/login_modal.aspx">登入會員</a>');
            buffer.append('</td>');
            buffer.append('</tr>');
            buffer.append('</table>');
        }
        jQuery(oDiv).append(buffer.toString());
        $('#Forum_Logout').fancybox({
            'hideOnOverlayClick': false,
            'hideOnContentClick': false,
            'centerOnScroll': true,
            'zoomSpeedIn': 500,
            'frameWidth': 500,
            'frameHeight': 400,
            'zoomSpeedOut': 500,
            'callbackOnClose': function() { document.location.reload(true); }
        });
        $('#Forum_Login').fancybox({
            'hideOnOverlayClick': false,
            'hideOnContentClick': false,
            'centerOnScroll': true,
            'zoomSpeedIn': 500,
            'frameWidth': 500,
            'frameHeight': 400,
            'zoomSpeedOut': 500,
            'callbackOnClose': function() { document.location.reload(true); }
        });

    },
    //處理 留言送出
    _submitForm: function() {
        if (location.href.indexOf("http:" + "//gb.ctitv.com.tw/gate/gb/") > -1) {
            var schHttp = new RegExp("^http:".concat("//", "gb.ctitv.com.tw/", "gate/gb/"));
            forum.settings.replyUrl = forum.settings.replyUrl.replace(schHttp, "http:".concat("//"));
        }

        var dataVars =
            "url=" + encodeURIComponent(String(forum.settings.replyUrl)) +
        //"&n=" + encodeURIComponent(document.getElementById(this.settings.Id_AuthorName).value) +
        // akuei
        //"&n=" + encodeURIComponent('吳阿貴') +
			"&n=" + encodeURIComponent(getcookie('CtvNickName')) +
        //"&e=" + document.getElementById(this.settings.Id_AuthorEmail).value.toLowerCase() +
        //"&e=" + encodeURIComponent('akuei_wu@mail.infortimes.com.tw') +
			"&e=" + encodeURIComponent(getcookie('CtvEmail')) +
        //"&l=" + encodeURIComponent(document.getElementById(this.settings.Id_AuthorURL).value.toLowerCase()) +
			"&l=" + encodeURIComponent("http://www.chinatimes.com") +
			"&t=" + encodeURIComponent(document.getElementById(this.settings.Id_Title).value) +
			"&c=" + encodeURIComponent(document.getElementById(this.settings.Id_Comments).value) +
			"&v=" + document.getElementById(this.settings.Id_ValidateCode).value +
        //UserId  
        // akuei
        //            "&member_id=" + encodeURIComponent('87032DA9-C00C-43D0-85B1-3A6376825A86') +
			"&member_id=" + encodeURIComponent(getcookie('CtvMemberID')) +
            "&i=yes";

        jQuery("#addCommentButton").attr("disabled", "true");
        jQuery("#cancelCommentButton").attr("disabled", "true");
        //prompt("",forum.settings.forumBasePath + "?" + dataVars);
        //解決 cross site 的問題，只能使用 load script 的方式

        jQuery.ajax({
            url: forum.settings.forumBasePath + "?" + dataVars,
            dataType: 'script',
            scriptCharset: 'utf-8',
            success: function() {
                if (typeof (result.ErrMsg) != "undefined") {
                    if (result.ErrMsg != "") alert(result.ErrMsg);
                    jQuery("#addCommentButton").attr("disabled", "");
                    jQuery("#cancelCommentButton").attr("disabled", "");
                }
                else if (typeof (result.Success) != "undefined") {
                    if (result.Success) {
                        //處理文章標題以及分類記錄, 因為資訊太長，所以區分 2 次處理
                        dataVars =
                            "url=" + encodeURIComponent(String(forum.settings.replyUrl)) +
			                "&t=" + encodeURIComponent(forum.settings.contentTitle) +
			                "&a=" + encodeURIComponent(forum.settings.contentAssortment) +
			                "&aid=" + encodeURIComponent(forum.settings.contentAssortmentId) +
			                "&cha=" + encodeURIComponent(forum.settings.channel) +
			                "&ano=" + encodeURIComponent(forum.settings.ArticleNo) +
			                "&v=" + document.getElementById(forum.settings.Id_ValidateCode).value +
                            "&ext=yes";
                        jQuery.ajax({
                            url: forum.settings.forumBasePath + "?" + dataVars,
                            dataType: 'script',
                            scriptCharset: 'utf-8',
                            success: function() {
                                jQuery.cookie("pageNo", -1, { expires: (10000 / (24 * 60 * 60 * 1000)) });

                                var url = forum.settings.replyUrl;
                                if (url.indexOf("#" + forum.settings.Id_Post) > -1)
                                    url.substring(0, forum.settings.replyUrl.indexOf("#" + forum.settings.Id_Post));

                                //window.location.href = url;
                                window.location.reload();

                            }
                        });
                    }
                    else {
                        jQuery("#addCommentButton").attr("disabled", "");
                        jQuery("#cancelCommentButton").attr("disabled", "");
                    }
                }
            }
        });
    },
    //繪製 單頁留言列表
    _buildForumBlock: function(oDiv, forums) {
        for (var i = 0; i < forums.length; i++) {
            var forum = forums[i];
            if (typeof (forum) == "undefined") continue;
            forum.idx = i;
            this._buildSingleForum(oDiv, forums[i]);
        }
    },
    //繪製 分頁導覽列
    _buildPageBar: function(oDiv, f) {
        var buffer = new StringBuffer();
        buffer.append('<div class="bar-align-right" style="padding-bottom: 15px">');
        buffer.append('    <dl class="inline-list">');
        buffer.append('        <dt class="ui">'.concat(this.settings.LABEL_PageHeader, '</dt>'));
        buffer.append(f.Pagerbar);
        buffer.append('    </dl>');
        buffer.append('</div>');
        jQuery(oDiv).append(buffer.toString());
    },
    //繪製 留言輸入表單
    _buildPostBlock: function(oDiv) {
        var buffer = new StringBuffer();
        //debugger;
        buffer.append('<h2 class="h2-1">');
        //buffer.append('    <span class="rightitem ui" style="font-weight: normal; font-size: 13px; margin-right: 8px"><a class="more" href="http://tb.chinatimes.com/index.asp">中時聊聊吧</a></span>');
        buffer.append('    <span class="rightitem ui" style="font-weight: normal; font-size: 13px; margin-right: 8px"></span>');
        buffer.append('    '.concat(this.settings.LABEL_CommentHeader));
        buffer.append('</h2>');
        buffer.append('<p style="margin-top: 1em; text-align: center">打「<span class="must-have"><b>*</b></span>」欄位為必填</p>');
        //buffer.append('<p style="margin-top: 1em; text-align: center">為維護您的發言權益，留言須為中網會員。打「<span class="must-have"><b>*</b></span>」欄位為必填</p>');
        buffer.append('<fieldset>');
        buffer.append('    <table class="comment-form" cellspacing="0" cellpadding="0">');
        buffer.append('        <tbody>');
        buffer.append('            <tr>');
        buffer.append('                <th><span class="must-have">*</span>'.concat(this.settings.LABEL_AuthorName, '</th>'));
        buffer.append('                <td><input id="'.concat(this.settings.Id_AuthorName, '" size="', this.settings.SIZE_AuthorName, '" maxlength="', this.settings.MaxLength_AuthorName, '" value="" /> </td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th><span class="must-have">*</span>'.concat(this.settings.LABEL_AuthorEmail, '</th>'));
        buffer.append('                <td><input id="'.concat(this.settings.Id_AuthorEmail, '" size="', this.settings.SIZE_AuthorEmail, '" maxlength="', this.settings.MaxLength_AuthorEmail, '" value="" /> </td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th>'.concat(this.settings.LABEL_AuthorURL, '</th>'));
        buffer.append('                <td><input id="'.concat(this.settings.Id_AuthorURL, '" size="', this.settings.SIZE_AuthorURL, '" maxlength="', this.settings.MaxLength_AuthorURL, '" value="" /> </td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th>'.concat(this.settings.LABEL_Title, '</th>'));
        buffer.append('                <td><input id="'.concat(this.settings.Id_Title, '" size="', this.settings.SIZE_Title, '" maxlength="', this.settings.MaxLength_Title, '" value="" /> </td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th><span class="must-have">*</span>'.concat(this.settings.LABEL_Comments, '</th>'));
        buffer.append('                <td><textarea id="'.concat(this.settings.Id_Comments, '" rows="', this.settings.Rows_Comments, '" cols="', this.settings.Cols_Comments, '" maxlength="', this.settings.MaxLength_Comments, '" onkeypress="return TextUtil.isNotMax(this)"></textarea><p>留言限定150字以內</p></td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr id="anonymouspostcomment1_tbcaptchaimage">');
        buffer.append('                <th><span class="must-have">*</span>'.concat(this.settings.LABEL_ValidateCode, '</th>'));
        buffer.append('                <td><img id="captcha" src="'.concat(this.settings.forumBase, 'captcha.ashx" onload="forum._captchaLoadCheck()" /> <a class="regenerate" href="#" onclick="forum._captchaReLoad();return false;">重新產生驗證碼</a><br />'));
        buffer.append('                    <p>請輸入上圖六位數字驗證碼： </p><input id="'.concat(this.settings.Id_ValidateCode, '" maxlength="', this.settings.MaxLength_ValidateCode, '" value="" /></td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th></th><td></td>');
        buffer.append('            </tr>');
        buffer.append('            <tr>');
        buffer.append('                <th></th>');
        buffer.append('                <td><input disabled="true" class="form-btn" id="addCommentButton" onclick="forum.inputValidation();" type="submit" value="'.concat(this.settings.Text_addCommentButton, '" />&nbsp;'));
        buffer.append('                    <input disabled="true" class="form-btn" id="cancelCommentButton" type="reset" onclick="forum._resetForm();" value="'.concat(this.settings.Text_cancelCommentButton, '" /></td>'));
        buffer.append('            </tr>');
        buffer.append('            <tr class="memo">');
        buffer.append('                <th>注意事項：</th>');
        buffer.append('                <td><p>網友發言請遵守規範，禁止發表、複製和傳播下列文字：</p>');
        buffer.append('                    <ol>');
        buffer.append('                      <li>人身攻擊、詆譭謾罵、粗鄙不雅、探人隱私、口水爭執</li>');
        buffer.append('                      <li>宣揚迷信、色情、賭博、暴力、教唆犯罪</li>');
        buffer.append('                      <li>違反著作權法的文章、影音、連結等。</li>');
        buffer.append('                    </ol>');
        buffer.append('                    <p>上述貼文一經發現，管理者可不通知作者、不作公告而逕行刪除。</p>');
        buffer.append('                </td>');
        buffer.append('            </tr>');
        buffer.append('        </tbody>');
        buffer.append('    </table>');
        buffer.append('</fieldset>');

        buffer.append("<div id='".concat(this.settings.Id_ErrorMsg, "'></div><BR />"));

        jQuery(oDiv).append(buffer.toString());
    },
    //繪製 留言列表項目
    _buildSingleForum: function(oDiv, f) {
        var buffer = new StringBuffer();
        var divComment = document.createElement("div");

        jQuery(divComment).attr("class", "container");

        //繪製 檢舉按鈕(暫時關閉)
        buffer.append('<div class="ui report" style="display:'.concat((this.settings.ActiveReport ? "" : "none"), '">'));
        buffer.append('    <a title="檢舉此回應內容" href="javascript:;">檢舉</a>');
        buffer.append('</div>');
        var articlebox = document.createElement("div");
        jQuery(articlebox).attr("class", "articlebox clear-fix").append(buffer.toString());
        //Clear string buffer
        buffer = new StringBuffer();

        //裝載 標題+內容
        jQuery(articlebox).append(jQuery(document.createElement("h3")).text(f.Title));
        jQuery(articlebox).append(jQuery(document.createElement("p")).html(f.Content));
        //檢查該留言是否有主編回應
        if (f.ResponseText && f.ResponseText.length > 0) {
            //Clear string buffer
            buffer = new StringBuffer();
            //有回應則必須繪製
            buffer.append('<div class="container editor"><div class="articlebox clear-fix">');
            buffer.append('<h3>編輯台回應</h3>');
            buffer.append('<p>' + f.ResponseText + '</p></div>');
            buffer.append('<ul class="dialogue-head inline-list">');
            buffer.append('<li class="ui floor">留言：</li>');
            buffer.append('<li class=ui>中時電子報主編</li>');
            //buffer.append('<li class=ui><a class=web href="http://news.chinatimes.com/">網站</a></li>');
            buffer.append('<li class="ui last">' + f.ResponseTime + '</li></ul></div>');
            jQuery(articlebox).append(buffer.toString());
        }

        jQuery(divComment).append(articlebox);

        //裝載 留言者資訊
        //Clear string buffer
        buffer = new StringBuffer();
        buffer.append('<ul class="dialogue-head inline-list">');
        buffer.append('    <li class="ui floor">留言：</li>');
        //        buffer.append('    <li class="ui floor">留言：</li>');
        //        buffer.append('    <li class="ui floor">'.concat(f.Seq, '樓</li>'));//
        if (f.Email == "")  //沒有email直接顯示名稱即可
            buffer.append('    <li class="ui">'.concat(f.Name, '</li>'));
        else                //有email必須顯示成超連結狀態
            buffer.append('    <li class="ui"><a href="'.concat('mailto:', f.Email, '">', f.Name, '</a></li>'));
        if (f.Link != "")   //有網站url的才顯示
            buffer.append('    <li class="ui"><a class="web" href="'.concat(f.Link, '" target="_blank">網站</a></li>'));
        buffer.append('    <li class="ui last">'.concat(f.Published, '</li>'));
        buffer.append('</ul>');

        jQuery(divComment).append(buffer.toString());
        jQuery(oDiv).append(divComment);
    },
    //繪製 整個留言列表 & 留言輸入 區塊主程序
    renderCommentBlock: function(oforum) {
        (function() {
            function importJS(src, look_for, onload) {
                var s = document.createElement('script');
                s.setAttribute('type', 'text/javascript');
                s.setAttribute('charset', 'utf-8');
                s.setAttribute('src', src);
                if (onload) wait_for_script_load(look_for, onload);
                if (eval("typeof " + look_for) == 'undefined') {
                    var head = document.getElementsByTagName('head')[0];
                    if (head) head.appendChild(s);
                    else document.body.appendChild(s);
                }
            }

            function importCSS(href) {
                var s = document.createElement('link');
                s.setAttribute('href', href);
                s.setAttribute('type', 'text/css');
                s.setAttribute('charset', 'utf-8');
                s.setAttribute('rel', 'Stylesheet');
                var head = document.getElementsByTagName('head')[0];
                if (head) head.appendChild(s);
                else document.body.appendChild(s);
            }

            function wait_for_script_load(look_for, callback) {
                var interval = setInterval(function() {
                    if (eval("typeof " + look_for) != 'undefined') {
                        clearInterval(interval);
                        callback();
                    }
                }, 50);
            }
            importJS("http://www.chinatimes.com/2009Cti/cthead/jquery-1.3.2.min.js", "jQuery", function() {
                importJS(forum.settings.forumBase + "jquery.cookie.js", "jQuery.cookie", function() {

                    //render block
                    //確定頁面上有 <div class="comment">...</div> & <div class="comment" id="comment"></div>，因為要把 forum 放在裡面
                    if (jQuery(".comment").length == 0 || jQuery(".comment").attr("tagName").toLowerCase() != "div") {
                        jQuery("body").append('<div class="comment"></div>');
                    }
                    //                    else if (jQuery("#" + forum.settings.Id_Post + " > a[name=" + forum.settings.Id_Post + "]").length == 0) {
                    //                        jQuery("#" + forum.settings.Id_Post).append('<a name="' + forum.settings.Id_Post + '" />');
                    //                    }
                    //送出前，檢查頁面是否為 GB2312 編碼，如果是，必須變更參數
                    if (location.href.indexOf("http:" + "//gb.ctitv.com.tw/gate/gb/") > -1) {
                        var schHttp = new RegExp("^http:".concat("//", "gb.ctitv.com.tw/", "gate/gb/"));
                        forum.settings.replyUrl = forum.settings.replyUrl.replace(schHttp, "http:".concat("//"));
                    }
                    var dataVars =
			            "url=" + encodeURIComponent(String(forum.settings.replyUrl)) +
			            "&p=" + (jQuery.cookie("pageNo") == null ? 0 : jQuery.cookie("pageNo")) +
			            "&ps=" + forum.settings.Page_Size +
			            "&asc=" + forum.settings.Ascending;
                    //prompt("", oforum.settings.forumBasePath + "?" + dataVars);
                    //解決 cross site 的問題，只能使用 load script 的方式
                    jQuery.ajax({
                        url: oforum.settings.forumBasePath + "?" + dataVars,
                        dataType: 'script',
                        scriptCharset: 'utf-8',
                        success: function() {
                            if (result) {
                                if (result.isHided) return;
                            }
                            oforum._callBack();
                            //oforum._buildPostBlock(document.getElementById(oforum.settings.Id_Post));
                            //呼叫其他處理程序
                            if (Forum == null)
                                Forum = { count: 0, List: [], PageSize: 0 };

                            if (typeof (oforum.onRenderCompleted) == "function") oforum.onRenderCompleted(Forum);

                            //將頁面移動到留言版的開頭
                            if (Forum.GoToPage) {
                                if (window.location.href.indexOf("#" + forum.settings.Id_Post) == -1)
                                    window.location.href = window.location.href + "#" + forum.settings.Id_Post;
                                else
                                    window.location.href = window.location.href.substring(0, window.location.href.indexOf("#" + forum.settings.Id_Post)) + "#" + forum.settings.Id_Post;

                            }
                            //debugger;

                            jQuery.cookie("pageNo", '', { expires: -1 });
                        }
                    });
                });
            });
        })();

    },
    //等待驗證碼下載
    _captchaLoadCheck: function() {
        var interval = setInterval(function() {
            try {
                if (jQuery("#captcha").attr("complete") == true) {
                    jQuery("#addCommentButton").attr("disabled", "");
                    jQuery("#cancelCommentButton").attr("disabled", "");
                    clearInterval(interval);
                }
            }
            catch (ex) {
                if (jQuery("#captcha").attr("readyState") == "complete") {
                    jQuery("#addCommentButton").attr("disabled", "");
                    jQuery("#cancelCommentButton").attr("disabled", "");
                    clearInterval(interval);
                }
            }
        }, 50);
    },
    //重新下載驗證碼
    _captchaReLoad: function() {
        var src = jQuery("#captcha").attr("src");
        src = (src.indexOf("?") == -1) ? src : src.substring(0, src.indexOf("?"));
        src += "?r=" + Math.random();
        jQuery("#captcha").attr("src", src);
    },
    //換頁處理
    _changePage: function(pageNo) {
        jQuery.cookie("pageNo", pageNo);
        window.location.reload();
    }
};
//留言板操作物件
var forum = new Forum_Engine();

//留言板資料物件
var Forum = null;
//留言儲存狀況
var result = null;
