/* 
 * js文件：专家个人页
 * 时间：2014-11-19
 * 王志远
 * =============================================================================
 */
onload = function(){
    goodproblem();
    recommend();
    posts();
}
function recommend(){
    $('#experts').html('.....');
    $.ajax({
        url:'/user/Expert/recommend/',
        data:{'recommend':'is','page':4},
        type:'get',
        success:function(e){
            //alert(e);return;
            
            var recommend = eval('('+e+')');
            
            var str = '';
            if(e != 'error'){
                for(var i in recommend){
               
                    str+="<li><a href=\"http://user.nsyh001.com/user/show/Personal/expertid/"+recommend[i].user_id+"\" class=\"user_img\"><img src=\""+recommend[i].user_face.replace('30.jpg','60.jpg')+"\"></a><a href=\"http://user.nsyh001.com/user/show/Personal/expertid/"+recommend[i].user_id+"\" class=\"user_name\">"+recommend[i].user_real_name+"</a><p class=\"hui1 dis_inline\">";
                    if(recommend[i].expertTitle == '' || recommend[i].expertTitle == null){
                        str += "</p>"; 
                    }else{
                        str += recommend[i].expertTitle+"</p>";
                    }
                    str+="<p>"+recommend[i].life+"年工作经验</p><a href=\"#\" class=\"icon answer\">"+recommend[i].anwser+"解答</a>";
                    if(recommend[i].anwser != null){
                         str+="<span class=\"icon icon9 hui1\">感谢"+recommend[i]['anwsercount'].thank+"</span><div class=\"clear\"></div></li>";
                    }else{
                         str+="<span class=\"icon icon9 hui1\">感谢0</span><div class=\"clear\"></div></li>";
                    }
                   
                    
                }
                
                $('#experts').html(str);
               
            }
        }
    });
}

function goodproblem(){
     $('#goodproblem').html('.....');
     $.ajax({
        url:'/user/Expert/GoodProblem/',
        data:{'limit':3},
        type:'post',
        success:function(e){
            //alert(e);return;
            
            if(e != 'error'){
                var recommend = eval('('+e+')');
                var str = '';
                for(var i in recommend){
                    str += "<li><span class=\"poroblem-title-word\">提问：</span><a href=\"#\" class=\"poroblem-title-text\">"+recommend[i]['question_answer_content']+"</a>";

                    if(recommend[i]['evaluation_star'] == '' || recommend[i]['evaluation_star'] == null){

                            str += "<div class=\"clear\"></div><div class=\"border1\"></div><div class=\"border1-a\"><span class=\"lv\">解答：</span>"+recommend[i]['anwser']['question_answer_content']+"<span class=\"problem-time\">"+recommend[i]['anwser']['question_answer_time']+"</span></div><div class=\"border1-b\"></div></li>";
                    }else{
                            str += "<img src=\"/Public/Photo/star"+recommend[i]['evaluation_star']*2+".gif\" class=\"poroblem-title-star\"><div class=\"clear\"></div><div class=\"border1\"></div><div class=\"border1-a\"><span class=\"lv\">解答：</span>"+recommend[i]['anwser']['question_answer_content']+"。<span class=\"problem-time\">"+recommend[i]['anwser'].question_answer_time+"</span></div><div class=\"border1-b\"></div></li>";
                    }      
                }
                
                $('#goodproblem').html(str);
               
            }
        }
    });
}

function posts(){
    $('#posts').html('.....');
    $.ajax({
       url:'/user/Expert/postses/',
       data:{'limit':3},
       type:'post',
       success:function(e){
           //alert(e);return;
           var recommend = eval('('+e+')');
           var str = '';
           if(e != 'error'){
               for(var i in recommend){
                   str += "<li><h3 class=\"article-title\"><a href=\"/bbs/Talk/PostsInfomation/posts/"+recommend[i]['posts_id']+"\">"+recommend[i]['posts_title']+"</a></h3><span class=\"perfect\"></span><span class=\"stick\"></span><div class=\"clear\"></div><p>"+recommend[i]['posts_title']+"</p>";
                   if(recommend[i]['posts_photo'] == null || recommend[i]['posts_photo'] == ''){
                       str += "<div class=\"clear\"></div><div class=\"article_t\"><span class=\"fleft\">"+recommend[i]['username']+"</span><span class=\"article_time\">"+recommend[i]['posts_time']+"发表 | 最后回复：9月18日 16：57</span><a href=\"#\" class=\"p_review\">"+recommend[i]['commentcount']+"</a><span class=\"p_read\">"+recommend[i]['posts_hits']+"</span></div></li>";
                   }
                   
                   
               }
               
               $('#posts').html(str);

           }
       }
    });
}

/**
 * 关注专家
 * @param {this} ob
 * @param {int} $id
 */
function AddExpert(ob,$id){
    $.ajax({
        url:'/user/Expert/AddConcernedExpert',
        data:{'expert_id':$id},
        type:'post',
        success:function (e){
            if(e == 1){
              
                $(ob).toggleClass("icon_a icon_a1"); 
                $(ob).toggleClass('icon_a icon_a1h'); 
                $(ob).removeAttr('onclick')
            
            }
        }
    });
}