﻿
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');}
        }
    }
    );
};

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 reportPost(pid){
    var xhr= new $Ajax.Request('ajax/ReportPost.aspx?topicid='+showtopicid+'&postid='+pid+'&url='+location+'&seed='+Math.random(),
    {
        method: 'get',
        onComplete: function(transport){
            if(transport.responseText=='ok'){
                postHint(pid, '谢谢，您的举报已提交成功！','open_jubaocg');
            }
            else{
                postHint(pid, transport.responseText,'open_jubaobcg');
            }
        }
    }
    );
};

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();
        }
    }
});