function noteSave(content_id, score) {
    var postContent = '?content_id=' + content_id;
    if (score != "") postContent += '&score=' + score;
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open('POST', "/content_comments/send_score.html"+postContent, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function() {
        reponse_sendNoteSave(xmlHttp, content_id)
    }
    xmlHttp.send(encodeURI(postContent));
}
function reponse_sendNoteSave(xmlHttp, content_id) {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var xmlDoc = xmlHttp.responseXML;
        if (xmlDoc.documentElement) {
            var getData = xmlDoc.documentElement.childNodes;
            if(getData[0].nodeValue != "no"){
			document.getElementById('score_average').innerHTML = getData[0].nodeValue;
			window.location.reload();
			}else{
				alert("请不要再次参加!");
			}
        }
    }
}
function noteShow(obj, score) {
	if(score != 'none'){
		document.getElementById('score').innerHTML = score;
		if(score ==1){document.getElementById('stars0').className ="stars1";}
		if(score ==2){document.getElementById('stars0').className ="stars2";}
		if(score ==3){document.getElementById('stars0').className ="stars3";}
		if(score ==4){document.getElementById('stars0').className ="stars4";}
		if(score ==5){document.getElementById('stars0').className ="stars5";}
	}else{
		document.getElementById('score').innerHTML = "";
		if(score =='none'){document.getElementById('stars0').className ="stars0";}
	}
}
function sendContentComment(content_id, volume) {
    var postContent = 'content_id=' + content_id;
    if (volume != "") postContent += '&volume=' + volume;
    var text = document.getElementById('textarea_comment_text').value;
    postContent += "&text=" + text;
    
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open('POST', "/content_comments/send_comment.html", true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function() {
        reponse_sendContentComment(xmlHttp, content_id, text)
    }
    xmlHttp.send(encodeURI(postContent));
}

function reponse_sendContentComment(xmlHttp,content_id,text) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                if (getData[0].nodeValue == 'login_error') {
                    // not_login
                    window.location.href = "/login/index.html?forward=" + window.location.href;
                } else if (getData[0].nodeValue == 'id_error'){
                    // content_id is null
                    return false;
                } else if (getData[0].nodeValue == 'text_error') {
                    // text is null
                    alert('请输入评论的内容！');
                    return false;
                } else if (getData[0].nodeValue == 'ok') {
                    // response ok, start refresh comments.
                    //getContentComment(content_id, 1);
                    window.location.reload();
                }
            } else {
                // no response
            }
        }
    } else {
        // in process
    }
}

function getContentComment(content_id, page, size, order, volume) {
    var param = '?content_id=' + content_id;
    if (page != "") param += '&page=' + page;
    if (size != "") param += '&size=' + size;
    if (order != "") param += '&order=' + order;
    if (volume != "") param += '&volume=' + volume;
    
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open('GET', '/content_comments/get_comment.html' + param, true);
    xmlHttp.onreadystatechange = function() {
        reponse_getContentComment(xmlHttp)
    }
    xmlHttp.send(null);
}

function reponse_getContentComment(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var textDoc = xmlHttp.responseText;
            document.getElementById('content_comment').innerHTML = textDoc;
        }
    } else {
        document.getElementById('comments_loading').innerHTML = '<img src="/common/image/highslide/graphics/loader.white.gif">';
    }
}

function handleHttpResponse_getTemplate(xmlHttp) {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
	  //var textDoc = xmlHttp.responseText;
      //alert(textDoc);
      //document.getElementById('refresh').innerHTML = textDoc;
        
    }
}
function getAll() {
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open('GET', '/content_comments/get_all.html', true);
    xmlHttp.onreadystatechange = function() {
        getAll_text(xmlHttp)
    }
    xmlHttp.send(null);
}


/////////////////////////////////////////////////
// 举报
function goReport(id) {
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open('GET', '/login/check.html', true);
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                var xmlDoc = xmlHttp.responseXML;
                if (xmlDoc.documentElement) {
                    var getData = xmlDoc.documentElement.childNodes;
                    if (getData[0].nodeValue == 'logined') {
                        document.getElementById('validateImage').src = "/product/validate_picture.html?" + Math.random();
                        document.getElementById('comment_id').value = id;
                        document.getElementById('report_text').value = '请输入举报说明'
                        var reportDiv = document.getElementById('report_div');
        				reportDiv.style.top = (document.body.scrollTop + (document.body.clientHeight - 240) / 2) + "px";
        				reportDiv.style.left = (document.body.scrollLeft + (document.body.clientWidth - 100) / 2) + "px";
                        reportDiv.style.display = "block";
                    } else {
                        alert('请先登录！');
                        document.location.href = '/login/index.html?forward=' + document.location.href;
                    }
                }
            }
        }
    }
    xmlHttp.send(null);
}

function closeReport() {
    var reportDiv = document.getElementById('report_div');
    var commentIdObj = document.getElementById('comment_id');
    var reportTextObj = document.getElementById('report_text');
    
    if (reportDiv) reportDiv.style.display = "none";
    if (commentIdObj) commentIdObj.value = "";
    if (reportTextObj) reportTextObj.value = "";
}

function doReport() {
    var comment_id = document.getElementById('comment_id').value;
    var text = document.getElementById('report_text').value;
    var validate = document.getElementById('validateText').value;
    
    if (comment_id != "" || !NaN(comment_id)) {
        var xmlHttp = getXmlHttpObject();
        
        var postContent = 'id=' + comment_id;
        if (text != "") postContent += '&text=' + text;
        if (validate != "") postContent += '&validate=' + validate;
        
        xmlHttp.open('POST', '/content_comments/report_complete.html', true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    var xmlDoc = xmlHttp.responseXML;
                    if (xmlDoc.documentElement) {
                        var getData = xmlDoc.documentElement.childNodes;
                        if (getData[0].nodeValue == 'complete') {
                            closeReport();
                            alert('感谢您提供信息！');
                        } else if (getData[0].nodeValue == 'already') {
                            closeReport();
                            alert('您已经举报过本条评论！');
                        } else if (getData[0].nodeValue == 'not_exists') {
                            closeReport();
                            alert('您举报的评论已经删除！');
                        } else if (getData[0].nodeValue == 'validate_error') {
                            //closeReport();
                            alert('您输入的验证码错误！');
                        } else {
                            closeReport();
                            alert('发生错误，请联系管理员！');
                        }
                        document.getElementById('report_button').innerHTML = '<input type="button" value="确定" onclick="doReport()">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="取消" onclick="closeReport()">';
                    }
                }
            } else {
                document.getElementById('report_button').innerHTML = ' 请稍候 <img src="/common/image/highslide/graphics/loader.white.gif">';
            }
        }
        xmlHttp.send(encodeURI(postContent));
    }
}

function display_report(id, action) {
    //document.getElementById(id).style.display = action;
}

function report_clear() {
    if (document.getElementById('report_text').value == '请输入举报说明') {
        document.getElementById('report_text').value = '';
    }
}



function add(add_pic)
{
	var content = document.getElementById("textarea_comment_text");
	content.value += add_pic; 
}


var list="<img src='/common/image/kxw-1.gif' >";
var list="<img src='/common/image/rrw-1.gif' >";
var list="<img src='/common/image/sina-1.gif' >";
function crertdiv(_parent,_element,_id,_css){//创建层
                var newObj = document.createElement(_element);
                if(_id && _id!="")newObj.id=_id;
                if(_css && _css!=""){
                        newObj.setAttribute("style",_css);
                        newObj.style.cssText = _css;
                }
                if(_parent && _parent!=""){
                        var theObj=getobj(_parent);
                        
                        var parent = theObj.parentNode;
                        if(parent.lastChild == theObj){
                                theObj.appendChild(newObj);
                        }
                        else{
                                theObj.insertBefore(newObj, theObj.nextSibling);
                        }
                }
                else        document.getElementById('div').appendChild(newObj);
}
function getobj(o){//获取对象
                return document.getElementById(o)
}
var swtemp=0,objtemp;
function showdiv(inputid,inputlist){//显示层
        if (swtemp==1){getobj(objtemp+"mydiv").style.display="none";}
        var text_list=inputlist;
	        if(inputid =="kxw"){
				text_list="<img src='/common/image/kxw-1.gif' >";
	        }
	        if(inputid =="rrw"){
				text_list="<img src='/common/image/rrw-1.gif' >";
	        }
	        if(inputid =="sina"){
				text_list="<img src='/common/image/sina-1.gif' >";
	        }
	        if(inputid =="baidu"){
				text_list="<img src='/common/image/baidu-1.gif' >";
	        }
	        if(inputid =="qq"){
				text_list="<img src='/common/image/qq-1.gif' >";
	        }
	        if(inputid =="douban"){
				text_list="<img src='/common/image/douban-1.gif' >";
	        }
	        if(inputid =="buzz"){
				text_list="<img src='/common/image/buzz-1.gif' >";
	        }
	        if(inputid =="msn"){
				text_list="<img src='/common/image/msn-1.gif' >";
	        }
        //alert(inputlist);
	        if(inputid =="kxw"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+0)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="rrw"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+33)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="sina"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+65)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="baidu"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+95)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="qq"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+120)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="douban"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+155)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="buzz"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+185)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
	        if(inputid =="msn"){
	                if (!getobj(inputid+"mydiv")){//若尚未创建就建之
	                        var divcss="font-size:12px;color:#00f;position:absolute;left:"+(getobj(inputid).offsetWidth+215)+"px;top:"+(getobj(inputid).offsetTop+15)+"px;"
	                        crertdiv("","div",inputid+"mydiv",divcss);//创建层"mydiv"
	                        getobj(inputid+"mydiv").innerHTML=text_list;
	                }
	        }
                var newdiv=getobj(inputid+"mydiv")
                newdiv.onclick=function(){hiddiv(event,inputid);}
                newdiv.onmouseout=function(){Mout(this)}
                newdiv.onmouseover=function(){clearTimeout(timer)}
                getobj(inputid).onmouseout=function(){Mout(newdiv)}
                newdiv.style.display="block";
                swtemp=1;
                objtemp=inputid;
}
var timer
function Mout(o){
	o.style.display="none";
	swtemp=0;
	 //o.parentNode.removeChild(o);//删除层
}
function hiddiv(e,inputid){
    e=e||window.event;
    ev=e.target||e.srcElement;
    v=ev.innerText||ev.textContent;
    if (v!="clear")getobj(inputid).value=v;else getobj(inputid).value=""
                getobj(inputid+"mydiv").style.display="none";
}
