// JavaScript Document
var xmlHttp; 
var commentstr = "";
var urlstr = document.location.toString();
var submiturl = "";
if(urlstr.indexOf("http://www.aqsc.cn") != -1)
{
	submiturl = "http://www.aqsc.cn/cms/jsp/comment/publish_allcomments_xml.jsp?param=queryAllResults&domain=www.aqsc.cn&content_id=";
}
else
{
	submiturl = "http://www.cworksafety.com/cms/jsp/comment/publish_allcomments_xml.jsp?param=queryAllResults&domain=www.cworksafety.com&content_id=";
}
function createXMLHttpRequest()
{
    if(window.ActiveXObject)
    { 
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    else if(window.XMLHttpRequest)
    { 
        xmlHttp = new XMLHttpRequest(); 
    } 
}

function showComments(id)
{
	createXMLHttpRequest();
    try
    {
        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.open("GET", submiturl + id + "&r=" + Math.random(), true);
        xmlHttp.send(null);
    }
    catch(exception)
    {
        var box = document.getElementById('showcmtarea');
		box.innerHTML='不允许跨域访问';
    }
}

function handleStateChange()
{
    if(xmlHttp.readyState == 4)
    {
       	if (xmlHttp.status == 200 || xmlHttp.status == 0)
        {
            var xmlDOM = xmlHttp.responseXML;
            var root = xmlDOM.documentElement;
			commentstr = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";	
            try
            {
            	var items = root.getElementsByTagName('Comment');
				var i = 0;
            	for(i=0; i< items.length; i++)
            	{
					var GuestName = items[i].getElementsByTagName("GuestName")[0].firstChild.data;
            		var CommentDate = items[i].getElementsByTagName("CommentDate")[0].firstChild.data;
            		var CommentIP = items[i].getElementsByTagName("CommentIP")[0].firstChild.data;
					var CommentContent = items[i].getElementsByTagName("CommentContent")[0].firstChild.data;
					CommentContent = CommentContent.replace(/\[/g,'<').replace(/\]/g,'>');
					
            		commentstr = commentstr + "<tr><td align='left'><span style=\"font-family:\'宋体\'; line-height:150%; color:#666666; background:url(http://www.aqsc.cn/images/pen_icon.gif); background-repeat:no-repeat; background-position:right; padding-right:18px;\">"+GuestName+" "+CommentDate+"<\/span><\/td><\/tr>";
					commentstr = commentstr + "<tr><td align='left' style=\"font-family:\'宋体\'; line-height:150%; border-bottom:1px #DEE1FE dashed;\">"+CommentContent+"<\/td><\/tr>";
					//commentstr = commentstr + "<tr><td onmouseover=\"javascript:this.style.backgroundColor='#FBFCFF', this.style.cursor='pointer'\" onmouseout=\"javascript:this.style.backgroundColor='#FFFFFF'\" style=\"border-bottom:1px #DEE1FE dashed;\"><div style=\"font-family:\'宋体\'; line-height:150%; color:#666666;\">"+GuestName+" ("+CommentIP+") "+CommentDate+"<\/div>";
					//commentstr = commentstr + "<div style=\"font-family:\'宋体\' padding-bottom:20px; line-height:150%;\">"+CommentContent+"<\/div><\/td><\/tr>";
            	}
				commentstr = commentstr + "</table>";
				var box = document.getElementById('showcmtarea');
           		box.innerHTML=commentstr;
				//显示所有评论数
				document.getElementById('showplc_top').innerHTML = root.getElementsByTagName('CommentsCount')[0].firstChild.data;
            }
            catch(exception)
            {
				var box = document.getElementById('showcmtarea');
				box.innerHTML='访问数据时出现了异常';
            }
        }
    }
}