﻿
function GetTopic(tid)
{
    $(".hwordcontent").html("<div style=\"text-align:left;padding-left:35px; padding-top:20px;color:red\">等待中******</div>");
    var qurl = "/Ajax/Topic.aspx?ran="+Math.random();
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{topicid:tid,action:"list"},
			//timeout : 10000,
			error : function(resp) {
				$(".hwordcontent").html("<div style=\"text-align:left;padding-left:35px; padding-top:20px;color:red\">对不起，加载失败，请稍候重试</div>");
			},
			success : function(data) {
			    var html = '';
			    for(var key in data){ 
				    html += '<ul>';
				    if(data[key].TopicPart==1)
				        html += '    <li class="hwdinfo"><span>正方：<strong>我邻房产网友</strong></span>  留言时间：'+data[key].CreateTime+'</li>';
				    else if(data[key].TopicPart==2)
				        html += '    <li class="hwdinfo"><span>反方：<strong>我邻房产网友</strong></span>  留言时间：'+data[key].CreateTime+'</li>';
				    html += '    <li class="hwdinfoa">'+data[key].Content+'</li>';
				    html += '</ul>';
                }
                if(html=="")
                {
                    $(".hwordcontent").html("<div style=\"text-align:left; padding-top:20px;padding-left:35px;color:red\">暂无留言</div>");
                }
                else
                {
			        $(".hwordcontent").html(html);
			    }
			}
			});
}

function checkradio(){ 
    var item = $(":radio:checked"); 
    var len=item.length; 
    if(len==0){ 
      alert("请选择支持方");
      return false;
    }
    return true;
} 

function DoTopic(tid)
{
    var contentv = $("#Content").val();
    if(!checkradio())
    {
        return;
    }
    var vpart =$(":radio:checked").val();
    if(contentv=="")
    {
        alert("留言内容不能为空");
        return;
    }
    
    $("#BtnSubmit").attr("disabled", "ture");
    var qurl = "/Ajax/Topic.aspx?ran="+Math.random();
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{topicid:tid,action:"do",content:contentv,topicpart:vpart},
			//timeout : 10000,
			error : function(resp) {
				alert("对不起，提交失败，请稍候重试");
			},
			success : function(data) {
			    
			    if ("0" == data.status) {
                    alert("提交成功");
                    //location="/";
                    var html = '';
				    html += '<ul>';
				    if(data.TopicPart==1)
				        html += '    <li class="hwdinfo"><span>正方：<strong>我邻房产网友</strong></s>  留言时间：'+data.CreateTime+'</li>';
				    else if(data.TopicPart==2)
				        html += '    <li class="hwdinfo"><span>反方：<strong>我邻房产网友</strong></s>  留言时间：'+data.CreateTime+'</li>';
				    html += '    <li class="hwdinfoa">'+data.Content+'</li>';
				    html += '</ul>';
                    //$(".hwordcontent").append(html);
                    window.location.reload();
                }else if("1" == data.status){
                    alert("请登录后发表评论");
                    window.location.reload();
                }else{
                    alert("对不起，提交失败");
                }
                $('#BtnSubmit').removeAttr("disabled"); 
			}
			});
}

function DoVote(tid,vpart)
{
    var qurl = "/Ajax/Topic.aspx?ran="+Math.random();
    $.ajax({
			url : qurl,
			type : "POST",
			dataType:"json",
            data:{topicid:tid,action:"dovote",topicpart:vpart},
			//timeout : 10000,
			error : function(resp) {
				alert("对不起，提交失败，请稍候重试");
			},
			success : function(data) {
			    if ("0" == data.status) {
			        alert("投票成功");
			        window.location.reload();
			    }
			}
			});
}

function InitTopic(tid,iflogin)
{
    GetTopic(tid);
}
