﻿
function showTopicError(detail) {
    $alert('错误', detail, '');
};

function confirmDelete(pid) {
    $confirm('确认删除', '<h3>您确认删除吗？</h3>', 'open_shanchu', function() { deletePost(showtopicid, pid); });
};
function deletePost(tid, pid) {
    onAction('ajax/DeleteMyPost.aspx?action=1&topicid=' + tid + '&postid=' + pid + '&seed=' + Math.random(), '删除', '帖子');
};

function showRatePanel(pid) {
    var xhr = new $Ajax.Request('ajax/RatePost.aspx?topicid=' + showtopicid + '&postid=' + pid + '&seed=' + Math.random(),
    {
        method: 'get',
        onComplete: function(transport) {
            if (transport.responseText.indexOf('<!--ERROR:-->') > 0) {
                $alert('评分失败', transport.responseText, 'open_tijiaobcg');
            } else {
                $modal('评分', transport.responseText, 'open_pingfen');
                Reposition();
            }
        }
    }
    );
};

function postRate(pid) {
    var xhr = new $Ajax.Request('ajax/RatePost.aspx?topicid=' + showtopicid + '&postid=' + pid + '&seed=' + Math.random(),
    {
        
        method: 'post',
        postBody: $('ratepostform').serialize(),
        onComplete: function(transport) {
            if (transport.responseText == 'ok') {
                getPostRateLog(pid);
                $modal.close();
                postHint(pid, '谢谢，您的评分已提交成功！', 'open_jubaocg');
            }
            else {

                $alert('评分失败', '<h3>' + transport.responseText + '</h3>', 'open_tijiaobcg', null, $T.UI.ModalPopup.DOM);
                //postHint(pid, transport.responseText,'open_jubaobcg');
            }
        }
    }
    );
};

function showPeportPost(pid, floorNum, topicTitle) {
    new $Ajax.Request('ajax/ReportPost.aspx?seed=' + Math.random(),
    {
        method: 'get',
        parameters: { 'topicid': showtopicid, 'postid': pid, 'url': encodeURI(location.href), 'floorNum': floorNum, 'topicTitle': encodeURI(topicTitle) },
        onComplete: function(transport) {
            if (transport.responseText == "noLogin") {
                postHint(pid, "未登录不能举报!", 'open_jubaobcg');
            }
            else if (transport.responseText == "reReport") {
                postHint(pid, "不要重复举报!", 'open_jubaobcg');
            }
            else {
                $modal('举报', transport.responseText, 'open_pingfen');
                Reposition();
                BindWaterMark("ta_moreReason", "输入更多举报理由，字数不超过50个汉字")
            }
        }
    });
};
function PeportPost(request, pid) {
    var reason = '';
    var moreReason = '';
    $$("input[name='cb_reason']").each(function(item) {
        if (item.checked) {
            reason += (item.value + ",");
        }
    });
    reason = reason.substring(0, reason.length - 1);
    moreReason = $F("ta_moreReason") == "输入更多举报理由，字数不超过50个汉字" ? "" : $F("ta_moreReason");
    new $Ajax.Request(request,
    {
        method: 'post',
        parameters: { 'reason': reason, 'moreReason': moreReason },
        onComplete: function(transport) {
            if (transport.responseText == 'ok') {
                $modal.close();
                postHint(pid, '谢谢，您的举报已提交成功！', 'open_jubaocg');
            }
            else {
                $("spanMsg").show();
                $("spanMsg").style.color = 'red';
                $("spanMsg").innerHTML = transport.responseText;
                setInterval(function() { $("spanMsg").hide(); }, 1500);
            }

        }
    });
}

function addFriend(uid) {
    var xhr = new $Ajax.Request('ajax/AddFriend.ashx?f=' + uid + '&seed=' + Math.random(),
    {
        method: 'get',
        onComplete: function(transport) {
            if (transport.responseText == 'ok') {
                $alert('请求发送成功', '<h3>您的好友请求已发送成功，请耐心等待！</h3>', 'open_tijiaocg');
            } else {
                $alert('请求发送失败', '<h3>' + transport.responseText + '</h3>', 'open_tijiaobcg');
            }
        }
    }
    );
}

function postHint(pid, contents, cssClass, onHide) {
    var hint = $('posthint_' + pid);
    if (hint) {
        hint.className = cssClass;
        hint.style.display = '';
        hint.innerHTML = contents;
        hint.timer = setTimeout(function() {
            hidePostHint(pid);
            if (onHide) {
                onHide();
            }
        }, 3000);
        hint.parentNode.style.position = 'relative';
    }
};
function hidePostHint(pid) {
    var hint = $('posthint_' + pid);
    if (hint) {
        hint.style.display = 'none';
        if (hint.timer) {
            clearTimeout(hint.timer);
        }
        hint.parentNode.style.position = 'static';
    }
};
$T.Util.ExecuteOnLoaded(function() {
    if (location.hash != '' && location.hash != null && location.hash != '#') {
        var anchors = $$('a[name=' + location.hash + ']');
        if (anchors && anchors.length > 0) {
            anchors[0].scrollTo();
        }
    }
});
function BindWaterMark(dom, watermark, initFocus) {
    dom = $(dom);
    if (dom) {
        dom.stopObserving('focus');
        dom.stopObserving('blur');
        dom.watermark = watermark;
        if (dom.value == '') {
            dom.value = dom.watermark;
            dom.style.color = '#999';
        }
        else {
            dom.style.color = '#333';
        }
        dom.observe('focus', function(event) {
            if (dom.value == dom.watermark) {
                dom.style.color = '#333';
                dom.value = '';
            }
        });

        dom.observe('blur', function(event) {
            if (dom.value == '') {
                dom.style.color = '#999';
                dom.value = dom.watermark;
            }
        });
        if (typeof initFocus != 'undefined' && initFocus) {
            dom.focus();
        }
    }
}
function Reposition() {
    var dom = $T.UI.ModalPopup.DOM != null ? $T.UI.ModalPopup.DOM : $T.UI.Confirm.DOM;
    if (dom) {
        if ($B.IE6 == true) {
            dom.style.position = 'absolute';
            dom.style.top = Math.floor(document.documentElement.scrollTop + document.documentElement.clientHeight / 2) + 'px';
            dom.style.left = Math.floor(document.documentElement.scrollLeft + document.documentElement.clientWidth / 2) + 'px';
        } else {
            dom.style.top = '50%';
            dom.style.left = '50%';
        }
        dom.style.marginLeft = (dom.offsetWidth / -2) + 'px';
        dom.style.marginTop = (dom.offsetHeight / -2) + 'px';
    }
}