/** XMLHTTP **/
if (!window.XMLHttpRequest) 
{
	window.XMLHttpRequest = function()
	{
		var xmlhttp = null;
		try 
		{ 
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		} 
		catch (e) 
		{
			try 
			{ 
				xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
			} 
			catch (e)
			{
				try 
				{ 
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e)
				{}
			}
		}
		return xmlhttp;
	}
}



function Request(callback) 
{
	this.xmlhttp = new XMLHttpRequest();
	this.post = function (url, args)
	{
		this.xmlhttp.open("post", url, true);
		this.xmlhttp.setRequestHeader("Method", "POST " + url + " HTTP/1.1");
		//this.xmlhttp.setRequestHeader("Charset","gb2312");
		this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		this.xmlhttp.onreadystatechange = callback;
		this.xmlhttp.send(args);
	}

	this.get = function (url)
	{
		this.xmlhttp.open("get", url, true);
		this.xmlhttp.onreadystatechange = callback;
		this.xmlhttp.send(null);
	}
}

function $(id)
{
	return document.getElementById(id);
}


function gopager(url)
{
	if(typeof(url) == "undefined")
	{
		var url = "/comment/comment.php?id="+id+"&num="+num;
	}
	var req = new Request(
						function()
						{ 
						     
							if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
							{			
								 //alert(req.xmlhttp.responseText);
								 $('comment_div').innerHTML = req.xmlhttp.responseText;
								 
								
							}
						}
					);
		req.get(url);
}

function send(obj)
{
	var comment = trim(obj.comment.value);
	if (comment.length == 0)
	{
		alert('请填写留言内容!');
		return false;
	}else if ( comment.length < 5 )
	{
		alert('您填写留言也太短了吧!');
		return false;
	}else if (comment.length > 2000)
	{
		alert('留言内容请不要超过1000字节!');
		return false;
	}


	var req = new Request(
						function()
						{ 
						     
							if (req.xmlhttp.readyState == 4 && req.xmlhttp.status == 200)
							{			
								 //alert(req.xmlhttp.responseText);
								 //$('comment_div').innerHTML = req.xmlhttp.responseText;
								 if ( trim(req.xmlhttp.responseText) != '' )
								 {
									 $('sys_error').innerHTML = req.xmlhttp.responseText;
								 }else{								 
									gopager();
								 }
								 
								
							}
						}
					);
		req.post("/comment/comment.php?action=add","id="+id+"&comment="+comment+"&noname="+obj.noname.checked+"&rand="+obj.rand.value);
}

function close()
{
	$('comment_div').style.display = "none";
}


function trim(s)
{
	return s.replace(/(^\s+)|(\s+$)/, "");
}