var mess = new messageoperation();

function loadhtml()
{
    var html ="";
    html+="<div style=\"width:100%\" id=\"messlist\"></div>";
    html+="<table style=\"width:100%;\">";  
    html+="<tr><td width=\"40px\">姓名：</td><td><input type=\"text\" id=\"txtName\" /></td><td width=\"50px\">标题：</td><td><input type=\"text\" id=\"txtTitle\" /></td></tr>";
    html+="<tr><td width=\"40px\">评论：</td><td colspan=\"3\"><textarea id=\"txt\" style=\"width:99%;height:70px\"></textarea></td></tr> "            
    html+="<tr><td colspan=\"4\"><input id=\"Button1\" type=\"button\" value=\" 提   交 \" onclick=\"mess.sendmessage();\" /></td></tr>"
    html+="</table>";    
    return html;
}

function GetHttpRequest(){var httpRequest;if(window.XMLHttpRequest){httpRequest=new XMLHttpRequest();if(httpRequest.overrideMimeType){httpRequest.verrideMimeType('text/xml');}}else if(window.ActiveXObject){try{httpRequest=new ActiveXObject("MSXML2.XMLHTTP");}catch(e){try{httpRequest=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}return httpRequest;}

function httpLoad()
{
	var httpRequest = GetHttpRequest();
	 var type=arguments[0];
	httpRequest.onreadystatechange = function()
	{
		if(httpRequest.readyState == 1)// 开始加载
		{
		    //document.write(数据载入中...);
			document.getElementById("messlist").innerHTML = "<div style='text-align:center; height:30px;line-height:30px;vertical-align:middle;'><img src=\"loading.gif\">数据载入中...</div>";			
		}		
		if(httpRequest.readyState == 4)	// 调用完毕
		{			
			if(httpRequest.status == 200) // 加载成功
			{
			    var result = httpRequest.responseText;			   
			    			    
			    if(type==1)
			    {
			        if(result=="true")
			        {
			            mess.removevalue();
			            alert("发表评论成功");			            
			            mess.getlist(0);			            
			        }
			        else if(result=="false")
			        {
			            alert("发表评论失败");
			        }
			        else if(result=="NoLogin")
			        {
			            alert("你还没有登录");
			            window.location.href="../Yx_VipLogin.aspx";	            
			        }
			        else{
			            alert(result);
			        }
			    }
			    else if(type==2)
			    {
                    document.getElementById("messlist").innerHTML=result;
			    }
			}
		} 
	}		
	var url=arguments[1]
	httpRequest.open("get", url, false);
  	httpRequest.send(null);
}


function insertitems()
{
    mess.sendmessage();
}

window.onload =function(){     
    mess.getlist(0);
    
}

function messageoperation()
{
}
messageoperation.prototype.getlist=function(page)
{
    var url = "SendMessage.ashx?type=2&url="+window.location.href+"&page="+page+"&clearCache="+new Date().getTime();
    httpLoad(2,url);
}
messageoperation.prototype.sendmessage=function()
{
    if(!mess.validate()) return;    
    var url = "SendMessage.ashx?type=1&url="+window.location.href
    +"&txt="+  encodeURI(document.getElementById("txt").value)
    +"&title="+encodeURIdocument.getElementById("txtTitle").value)
    +"&name="+encodeURI(document.getElementById("txtName").value);
//    +"&txt="+  document.getElementById("txt").value)
//    +"&title="+document.getElementById("txtTitle").value
//    +"&name="+document.getElementById("txtName").value;
    ;   
    httpLoad(1,url);
}

messageoperation.prototype.validate=function()
{
    if(document.getElementById("txtName").value=="")
    {
        alert("姓名不能为空");
        return false;
    }
    if(document.getElementById("txtTitle").value=="")
    {
        alert("标题不能为空");
        return false;
    }
     if(document.getElementById("txt").value=="")
    {
        alert("内容不能为空");
        return false;
    }
    return true;
}

messageoperation.prototype.removevalue=function()
{
    document.getElementById("txtName").value="";  
    document.getElementById("txtTitle").value="";  
    document.getElementById("txt").value="";
}


