﻿function GetClubNewestPosts()
{
    ClubPostShow.GetClubNewestPosts(document.getElementById("SiteHeaderUC_ClubDomainHidden").value,
                    onSuccessForClubNewestPostsGet, onFailedForCommon, ""); 
}
function onSuccessForClubNewestPostsGet(result)
{
    if(result != null)
    {
        document.getElementById("clubNewestPosts").innerHTML=result; return false;
    }
    document.getElementById("clubNewestPosts").innerHTML="";
    return false;
}
function GetClubPlacardsInfo()
{
    ClubCommon.GetClubPlacardsInfo(document.getElementById("SiteHeaderUC_ClubDomainHidden").value,
                    onSuccessForClubPlacardsInfoGet, onFailedForCommon, ""); 
}
function onSuccessForClubPlacardsInfoGet(result)
{
    if(result != null)
    {
        document.getElementById("clubPubishBody").innerHTML=result; return false;
    }
    document.getElementById("clubPubishBody").innerHTML="";
    return false;
}
function essentialPost(ev)
{
     ClubPostShow.EssentialClubPost(document.getElementById("ForumPostIDHidden").value, true,
           onSuccessForEssentialPost, onFailedForCommon, true);        
}
function unEssentialPost(ev)
{
    ClubPostShow.EssentialClubPost(document.getElementById("ForumPostIDHidden").value, false,
           onSuccessForEssentialPost, onFailedForCommon, false); 
}
function onSuccessForEssentialPost(result, id)
{
    if(result)
    {
        if(id)
        {
            document.getElementById("AddEssential0").style.display="none";
            document.getElementById("CancelEssential0").style.display="";
            document.getElementById("CancelEssential0").className="floatRight";
            //openAlert("谢谢，您已经成功把本贴加为精华！");
        }
        else
        {
            document.getElementById("AddEssential0").style.display="";
            document.getElementById("AddEssential0").className="floatRight";
            document.getElementById("CancelEssential0").style.display="none";
            //openAlert("谢谢，您已经成功取消加精！");
        }
    }
    else
    {
    		alert("对不起，操作失败，请您稍后再试！")
        //openAlert("对不起，操作失败，请您稍后再试！");
    }
}
function topPost(ev)
{
    ClubPostShow.TopClubPost(document.getElementById("ForumPostIDHidden").value, 1,
           onSuccessForTopPost, onFailedForCommon, true); }
function unTopPost(ev)
{
    ClubPostShow.TopClubPost(document.getElementById("ForumPostIDHidden").value, 0,
           onSuccessForTopPost, onFailedForCommon, false); }

function onSuccessForTopPost(result, id)
{
    if(result)
    {
        if(id)
        {
            document.getElementById("AddSticky0").style.display="none";            document.getElementById("CancelSticky0").style.display="";
            document.getElementById("CancelSticky0").className="floatRight";      
        }
        else
        {
            document.getElementById("AddSticky0").style.display="";            document.getElementById("AddSticky0").className="floatRight";
            document.getElementById("CancelSticky0").style.display="none"; 
        }
    }
    else
    {
        openAlert("对不起，操作失败，请您稍后再试！");
    }
}
var updateclubpostwindow;
function updatePost(id, ev)
{
    if(id == 0)
    {
        updateclubpostwindow=dhtmlwindow.open("ForUpdateClubPostBox", "iframe", "http://www.nowpei.com/Club/UpdateClubPost.aspx", "更新帖子", "width=700px,height=450px,resize=0,scrolling=0,center=1", "recal")
        updateclubpostwindow.focus();
        return false    
    }
    else
    {
        var objPos = mousePosition(ev);
        if(updateForumPostReplyOpened)
        {
            openAlert("对不起，您一次只能打开一个更新窗口", objPos);
            return false;        }
        updateForumPostReplyOpened=true;        updateReplyOpendedID=id;
        updateReplyWindow =dhtmlwindow.open('ForUpdateForumPostReplybox', 'div', 'updatePostReply', '更新回复', 'width=310px,height=210px,left=' + objPos.x + 'px,top=' + objPos.y + 'px,resize=0,scrolling=0'); 
        updateReplyWindow.focus();       document.getElementById("replyTitle").value = document.getElementById("subject_" + id).innerHTML.trim();
        document.getElementById("replyBody").value = document.getElementById("postText_" + id).innerHTML.trim();
    }
}
var updateReplyWindow;var updateForumPostReplyOpened=false;var updateReplyOpendedID;
function deletePost(id, ev){   
    var objPos = mousePosition(ev);   
    document.getElementById("deletePost_" + id).disabled="disabled";
    if(id == 0)
    {        
        ClubPostShow.DeleteClubPost(document.getElementById("postID_" + id).innerHTML, 
            onSuccessForDeletePost, onFailedForCommon, objPos);        
        return false        }
    else
    {
        ClubPostShow.DeleteClubPostReply(document.getElementById("postID_" + id).innerHTML, 
            onSuccessForDeleteReplyPost, onFailedForCommon, id);        
        return false        }
}
function onSuccessForDeleteReplyPost(result, id){
    if(result)
    {
        alert("谢谢，回复删除成功！");   document.getElementById("postAllContent_" + id).style.display = "none";
        
        var numtp = parseInt(document.getElementById("lblRecordCount").innerHTML.trim()) - 1;
        document.getElementById("lblRecordCount").innerHTML = numtp.toString();
    }
    else
    {
        document.getElementById("deletePost_" + id).disabled="";
        alert("对不起，回复更新失败，请你稍后再试！");
    }
}
function onSuccessForDeletePost(result, objPos){
    if(result)
    {
        alert("帖子删除成功，乐配将帮您转到版块首页！");
        window.location.href = nowpeiprefix + "/q/" + document.getElementById("SiteHeaderUC_ClubDomainHidden").value
            + "/f/" + document.getElementById("ForumTypeHidden").value;
    }
    else
    {
        document.getElementById("deletePost_0").disabled="";        openAlert("对不起，帖子删除失败，请你稍后再试！", objPos);
    }
}
function repleyPost(title){
    document.getElementById("commentSubject").value="RE: " + title;
}  
function onUploadClubPostReplyPress(event){
    event = event? event:(window.event?window.event:null);  
    var kcode = event.keyCode?event.keyCode:event.which;  
	
    if(kcode==13)
    {
        submitPostComment(event);	
    }
} 
function submitPostComment(ev){		
    var objPos = mousePosition(ev);  
    if(!checkCanReply(ev))
    {
        return false;
    } 
    if(document.getElementById("commentSubject").value.trim().length == 0)
    {
        openAlert("对不起，请您输入回复主题！", objPos);
        document.getElementById("commentSubject").focus();
        return false;    }
    if(document.getElementById("CommentBody").value.trim().length == 0)
    {
        openAlert("对不起，请您输入回复内容！", objPos);
        document.getElementById("CommentBody").focus();
        return false;    }
    if(document.getElementById("postCommentVcode").value.trim().length != 4)
    {
        openAlert("对不起，请您正确输入验证码！", objPos);
        document.getElementById("postCommentVcode").focus();
        return false;    }
    document.getElementById("submitComment").disabled = "disabled";
    var newBody = replaceConImg(document.getElementById("CommentBody").value); 
    ClubPostShow.UploadClubPostComment(document.getElementById("ForumPostIDHidden").value, 
         document.getElementById("commentSubject").value.trim(), 
         document.all ? newBody.trim().replace(/\r\n/g, "<br />") : newBody.trim().replace(/\n/g, "<br />"),
         document.getElementById("postCommentVcode").value.trim(),
         onSuccessForReplyPost, onFailedForCommon, objPos);        
}
function onSuccessForReplyPost(result, objPos){
    if(result)
    {
        document.getElementById("CommentBody").value = "";document.getElementById("postCommentVcode").value = "";
        document.getElementById("submitComment").disabled = "";        
        document.getElementById("postCommentVcodeImage").innerHTML = "点击对话框显示验证码";
        is_show_vcode=false;  
        if(document.all)
        {      
		    document.getElementById("PostFirstLink").click(); }
        else
        {
	        location.reload(); }
    }
    else
    {
        document.getElementById("submitComment").disabled = "";
        document.getElementById("postCommentVcodeImage").innerHTML = "点击对话框显示验证码";
        is_show_vcode=false;
        openAlert("对不起，回复失败，请您检查您是否按照要求输入了相关内容或者请您稍后再试！", objPos);
    }
}
function updateReply(ev){
    var objPos = mousePosition(ev);
    if(document.getElementById("replyTitle").value.trim().length == 0)
    {
        openAlert("对不起，请您输入回复主题！", objPos);
        document.getElementById("replyTitle").focus();
        return false;    }

    if(document.getElementById("replyBody").value.trim().length == 0)
    {
        openAlert("对不起，请您输入回复内容！", objPos);
        document.getElementById("replyBody").focus();
        return false;    }
    
    if((document.getElementById("replyTitle").value == document.getElementById("subject_" + updateReplyOpendedID).innerHTML.trim())
        && (document.getElementById("replyBody").value == document.getElementById("postText_" + updateReplyOpendedID).innerHTML.trim()))
    {
        openAlert("谢谢，回复更新成功！", objPos);
        updateForumPostReplyOpened=false;
        return false;    }
    document.getElementById("updateReply").disabled="disabled";
    ClubPostShow.UpdateClubPostReply(document.getElementById("postID_" + updateReplyOpendedID).innerHTML, 
         document.getElementById("replyTitle").value.trim(), 
         document.all ? document.getElementById("replyBody").value.trim().replace(/\r\n/g, "<br />") : document.getElementById("replyBody").value.trim().replace(/\n/g, "<br />"),
         onSuccessForUpdateReplyPost, onFailedForCommon, objPos.x.toString() + " " + objPos.y.toString());        
}
function onSuccessForUpdateReplyPost(result, pos){
    var objPos = getPositionArray(pos);
    if(result)
    {
        openAlert("谢谢，回复更新成功！", objPos);
        document.getElementById("subject_" + updateReplyOpendedID).innerHTML = document.getElementById("replyTitle").value;
        document.getElementById("postText_" + updateReplyOpendedID).innerHTML = document.getElementById("replyBody").value;
        updateReplyWindow.close();        updateForumPostReplyOpened=false;
    }
    else
    {
        document.getElementById("updateReply").disabled=""; openAlert("对不起，回复更新失败，请你稍后再试！", objPos);
    }
}
var is_show_vcode=false;
function showVCodeForPostComment(id){
    var imgspan=id + "Image";
    if(!is_show_vcode)
    {
        var img_for_comment_vcode =
            '\
                <img src="http://www.nowpei.com/GHandler/VCodeImage.ashx?t=' + new Date().getTime() + '" width="60" height="20" alt="看不清，点击更换！" title="看不清，点击更换！" \
                ' + ' onclick="' + 'this.src=this.src+\'?\'; return false;"/>';             
        is_show_vcode=true;    
        document.getElementById(imgspan).innerHTML = img_for_comment_vcode;            
    }    
    return false;
}
function checkCanReply(ev, type){
    var objPos = mousePosition(ev);
    if(document.getElementById("ForumTypeHidden").value == "0" &&  document.getElementById("PostPrivacyHidden").value == "1")
    {
        if(!CheckLogin()){if(type==null){openAlert("对不起，本论坛只有登录用户才能回复！", objPos)}return false;}
    }
    if(document.getElementById("ForumTypeHidden").value == "0" &&  document.getElementById("PostPrivacyHidden").value == "2")
    {
        if(parseInt(document.getElementById("MemberTypeHidden").value) == -1)
        {if(type==null){openAlert("对不起，本圈论坛只有本圈圈友才能回复！", objPos)}return false;}
    }
    return true;
}
function isShowCommBox(ev){if(!checkCanReply(ev, 0)){document.getElementById("div_main_comment_clubpost").style.display = "none";}}
var shareClubPostBoxWin;
function shareClubPost(ev)
{
    var objPos = mousePosition(ev);
    if(!CheckLogin())
    {
        openAlert("对不起，您没有登录或者登录已经过期！", objPos);
        return false;
    }
    if(document.getElementById("ForumTypeHidden").value == "1")
    {
        openAlert("对不起，不能分享这篇圈子主题，因为它是私密区的主题！", objPos);
        return false;
    }
    shareClubPostBoxWin =dhtmlwindow.open('ForShareClubPostBoxWin', 'div', 'shareMessageBox', "说点什么吧！", 'width=280px,height=190px, left=' + objPos.x + 'px,top=' + objPos.y + 'px, resize=0,scrolling=0');
}
function shareMessageForClubPost(ev)
{
    var objPos = mousePosition(ev);
    if(!CheckLogin())
    {
        openAlert("对不起，您没有登录或者登录已经过期！", objPos);
        return false;
    }
    var clubPostID = document.getElementById("ForumPostIDHidden").value;
    var clubPostTitle = document.getElementById("subject_0").innerHTML;
    var clubPostDesc = document.getElementById("postBody_0").innerHTML;
    var clubPostUser = document.getElementById("postAuthor_0").innerHTML;
    var clubDomain = window.location.href;
    var clubName = document.getElementById("clubName").innerHTML;
    var comment = document.getElementById("shareMessageText").value;
    Home.ShareClubPost(clubPostID, clubPostTitle, clubPostDesc, clubPostUser, clubDomain, clubName, comment, onSuccessForShareClubPost, onFailedForCommon, objPos)
}
function onSuccessForShareClubPost(result, objPos)
{
    shareClubPostBoxWin.close();
    openAlert("已经成功分享了圈子主题，<a class='linkColor textUnderlineNo' href='http://www.nowpei.com/" + GetUserName() + "/usl'>去看看吧！</a>！", objPos);
}
