﻿/*  ------------------------------------------------------------------------
 *  FileName : HotelComment.js
 *  Version  :
 *  Modify Date:
 *  Author   :
 *  Host Url : http://dianping.elong.com
 *  Remark   : 取点评数据.
 *--------------------------------------------------------------------------*/ 
 
 
 function getHotelComment()
 {
    var shotelid = document.getElementById("hotelid").value;
    var sQuery = "&hotelid=" + shotelid + "&RecordNum=3";
    var ajax = new Ajax();
    ajax.doRequest("AjaxRequestProxy.aspx?RequestType=hotelcomment" + sQuery,OnGetHotelComment);
 }
 
 function OnGetHotelComment(state)
 {
    if (state)
    {
        var hotelComment = eval("(" + state + ")");
        var hotelid = document.getElementById("hotelid").value;
        
        var obj=document.getElementById("div_hotelComment");
        obj.style.display = 'block';
        obj.innerHTML = buildHotelComment(hotelComment,hotelid);
    }
 }
 
 function buildHotelComment(hotelComment,hotelId)
 {
    var shtml = '';
    
    if (hotelComment && hotelComment.length > 0)
    {
        shtml = '<div class="h_gk_title">用户点评</div>';
        shtml += '<table border="0" cellpadding="6" cellspacing="1" width="100%" bgcolor="#D6D6D6">';
        
        for(var i = 0; i < hotelComment.length; i++)
        {
            var sContent = siftHtml(hotelComment[i].Content);
            if (sContent != null && sContent.length > 30)
            {
                sContent = sContent.substr(0,30) + "…";
            }
            
            shtml += '<tr bgcolor="white">';
            shtml += '<td>' + hotelComment[i].MemberName + '</td>';
            shtml += '<td>' + hotelComment[i].CreatedTime + '</td>';
            shtml += '<td>' + sContent + '</td>';
            shtml += '</tr>';
        }
        
        shtml += '</table>';
        var slink = "javascript:HotelDetails('" + hotelId + "','commentary');";
        shtml += '<div align="right" class="margin_tb5"><a href="' + slink + '">更多用户点评</a></div>';
    }
    
    return shtml;
 }
 
 //去掉HTML标签
 function siftHtml(shtml)
 {
    //去掉HTML标签
    var regEx = /<[^>]*>/g;
    shtml = shtml.replace(regEx, "");
    
    //去掉空格
    shtml = shtml.replace(/\s/g, "");
    
    return shtml;
 }
 
 //转换JSON日期
 function convertJsonDate(data)
 {
    var exp = data.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', 'g'), "$1new Date($2)");
    return eval('(' + exp + ')');
 }
