﻿
function Getxmlhttp()
{
	var xmlhttp = null;  
	try  {  
		xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");  
	}  
	catch(e)  {  
		try  {  
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
		}  
		catch(e2){}  
	}
	
	if (xmlhttp==null){
		try	{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e3){}
	}
	return xmlhttp;
}

function GetRemoteData(url) 
{
	//
	var xmlhttp = Getxmlhttp();
	if (xmlhttp==null) return "";

	try {
		xmlhttp.open("GET", url, false); 
		xmlhttp.send("");
		if ( xmlhttp.status == 200 ) 
		{ 
			return xmlhttp.responseText; 
		} 
		throw '';  
	} 
	catch(e) 
	{ 
		return ''; 
	}
}

//=======================================================================

function UserAddComment(SystemPath, sArticleID)
{
	var sContent = document.getElementById("txtCommentContent").value;
	sContent = sContent.replace(/(^\s*)|(\s*$)/g, "");
	sContent = escape(sContent);

	if (sContent.length<3)
	{
		alert("评论内容不能少于3个字符！");
		return false;
	}

	if (sContent.length>250)
	{
		alert("评论内容不能多于250个字符！");
		return false;
	}

	var sInputNum = document.getElementById("txtCheckComment").value;
	var sBuildNum = GetRemoteData(SystemPath + "Admin/Content/Comment_Action.aspx?Action=checknum&ID=" + sArticleID + "&tmp=" + Math.random());

	if (sInputNum != sBuildNum && sBuildNum != "")
	{
		alert("验证码不正确！");
		return false;
	}

	var sGarde = "3";
	if (document.getElementById("optGarde1").checked==true) sGarde = "1";
	if (document.getElementById("optGarde2").checked==true) sGarde = "2";
	if (document.getElementById("optGarde4").checked==true) sGarde = "4";
	if (document.getElementById("optGarde5").checked==true) sGarde = "5";

	var sBuildNum = GetRemoteData(SystemPath + "Admin/Content/Comment_Action.aspx?Action=save&ID=" + sArticleID + "&C=" + sContent + "&G=" + sGarde + "&N=" + sInputNum + "&t=" + Math.random());
	GetCommentList(SystemPath, sArticleID);
	document.getElementById("txtCommentContent").value = "";
	document.getElementById("txtCheckComment").value = "";
	document.getElementById("imgCheckCommentInput").src = document.getElementById("imgCheckCommentInput").src + "&"+ Math.random();
}

function GetCommentList(SystemPath, sArticleID)
{
	GetCommentList_asyn(SystemPath + "Admin/Content/Comment_Action.aspx?Action=getlist&ID=" + sArticleID + "&tmp=" + Math.random());
}

function GetCommentList_asyn(url)
{
	var xmlhttp_CommentList_asyn = Getxmlhttp();
	if (xmlhttp_CommentList_asyn==null) return "";
	
	xmlhttp_CommentList_asyn.open("GET", url, true); 
	xmlhttp_CommentList_asyn.onreadystatechange = function() 
	{
		if(xmlhttp_CommentList_asyn.readyState==4)
		{
			if(xmlhttp_CommentList_asyn.status==200)
			{
				document.getElementById("CommentList").innerHTML = xmlhttp_CommentList_asyn.responseText;
			}
		}
	} 
	xmlhttp_CommentList_asyn.send("");
}


