var xmlHttp;

function cxhr()
{
			try{
				xmlHttp=new XMLHttpRequest();
				}
			catch(e){
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}	
}
function t()
{
var m_type=""	
if($('n_type_1').checked)	
	m_type=2
else
	m_type=3
if ($("n_name").value!=""){
	if(n_t()){
		$("b_b").disabled="true";	
		cxhr();
		
		var url="save.asp";
		var t_post="n_name="+escape(document.getElementById("n_name").value)+"&n_content="+escape(document.getElementById("n_content").value)+"&m_type="+m_type
		xmlHttp.onreadystatechange=hsc;
		xmlHttp.open("post",url,true);
		xmlHttp.setRequestHeader("Content-Length",t_post.length);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		xmlHttp.send(t_post);
	}
}else{
	$("n_name_1").innerHTML="<font color=red>请填写您的昵称！</font>";	
}
}
function x()
{
	$("book").innerHTML="正在加载......";
	cxhr();	
	var url="save.asp";
	var t_post=""
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=function(){hsc(0)};
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}
function f(n)
{
	$("book").innerHTML="正在加载......";
	cxhr();
	var url="save.asp";
	var t_post="page="+n
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=function(){hsc(n)};
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}
function hsc(n)
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			$("book").innerHTML=xmlHttp.responseText;
			$("b_b").disabled=false;
			//$("n_name").value=""
			if(n>0)
				$("n_content").value=""
			$("n_content_1").innerHTML=""
		}
	}
}
function $(id){
	return document.getElementById(id);
}
function n_t(){
var Flag=false;
var u=$("n_name");
var u1=$("n_name_1");
var c=$("n_content");
var c1=$("n_content_1");
	if (u=="")
		u1.innerHTML="<font color=red>请填写您的昵称！</font>";
	else if (bytes(u) > 14)
		u1.innerHTML="<font color=red>您的昵称最长不得超过7个汉字，或14个字节(数字，字母和下划线)！</font>";
	else if (!chkstr(u))
		u1.innerHTML="<font color=red>您的昵称仅可使用汉字、数字、字母和下划线！</font>";
	else if (parseInt(bytes(c)) > 200)
		c1.innerHTML="<font color=red>您提交的留言不能超过200个字节！</font>";	
	else if (parseInt(bytes(c)) <= 1)
		c1.innerHTML="<font color=red>您提交的留言太短！</font>";			
	else {
		u1.innerHTML="";
		Flag=true;
	}
	return Flag;

}
function bytes(str){
	if(typeof(str)!='string'){
		str = str.value;
	}
	var len = 0;
	for(var i = 0; i < str.length; i++){
		if(str.charCodeAt(i) > 127){
			len++;
		}
		len++;
	}
	return len;
}
function chkstr(str){
	if(typeof(str)!='string'){
		str = str.value;
	}
	for(var i = 0; i < str.length; i++){
		if (str.charCodeAt(i) < 127 && !str.substr(i,1).match(/^\w+$/ig)){
			return false;
		}
	}
	return true;
}
//modify
var bgObj=title=msgObj=null;
function modify(id){ 
var msgw,msgh,bordercolor; 
msgw=400;//提示窗口的宽度 
msgh=200;//提示窗口的高度 
titleheight=25 //提示窗口标题高度 
bordercolor="#eff2fa";//提示窗口的边框颜色 
titlecolor="#d9e1f7";//提示窗口的标题颜色 

var sWidth,sHeight; 
sWidth=document.body.offsetWidth; 
sHeight=document.body.offsetHeight; 
bgObj=document.createElement("div"); 
bgObj.setAttribute('id','bgDiv'); 
bgObj.style.position="absolute"; 
bgObj.style.top="0"; 
bgObj.style.background="#777"; 
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
bgObj.style.opacity="0.6"; 
bgObj.style.left="0"; 
bgObj.style.width=sWidth + "px"; 
bgObj.style.height=sHeight + "px"; 
bgObj.style.zIndex = "10000"; 
document.body.appendChild(bgObj); 

 msgObj=document.createElement("div") 
msgObj.setAttribute("id","msgDiv"); 
msgObj.setAttribute("align","center"); 
msgObj.style.background="white"; 
msgObj.style.border="1px solid " + "#d9e1f7"; 
  msgObj.style.position = "absolute"; 
		msgObj.style.left = "50%"; 
		msgObj.style.top = "50%"; 
		msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
		msgObj.style.marginLeft = "-180px" ; 
		msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
		msgObj.style.width = msgw + "px"; 
		msgObj.style.height =msgh + "px"; 
		msgObj.style.textAlign = "center"; 
		msgObj.style.lineHeight ="25px"; 
		msgObj.style.zIndex = "10001"; 

title=document.createElement("h4"); 
 title.setAttribute("id","msgTitle"); 
 title.setAttribute("align","right"); 
 title.style.margin="0"; 
 title.style.padding="3px"; 
 title.style.background=bordercolor; 
 title.style.opacity="0.75"; 
 title.style.border="1px solid " + bordercolor; 
 title.style.height="18px"; 
 title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
 title.style.color="white"; 
 title.style.cursor="pointer"; 
 title.innerHTML="<font color=#000000>晴天提供：http://qingtiandy.cn 修改留言模式_请文明用语!  关闭</a>"; 
 title.onclick=title_on;
 document.body.appendChild(msgObj); 
 document.getElementById("msgDiv").appendChild(title); 
 var txt=document.createElement("div"); 
 txt.style.margin="1em 0" 
 txt.setAttribute("id","msgTxt"); 
 txt.innerHTML="<textarea name=\"n_content_m\" cols=\"50\" rows=\"6\" style=\"width:88%;\"  id=\"n_content_m\"></textarea><br><input type='button' value='确认修改' onclick=\"m_x_ok("+id+");\" id=n_content_m_b>"
	   document.getElementById("msgDiv").appendChild(txt); 
m_x(id)
		} 
function title_on (){ 
	  document.body.removeChild(bgObj); 
			document.getElementById("msgDiv").removeChild(title); 
			document.body.removeChild(msgObj); 
			} 
//读取
function m_x(id)
{
	$("n_content_m").value="正在加载......";
	cxhr();	
	var url="m_save.asp";
	var t_post="id="+id;
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=m_hsc;
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}
function m_hsc()
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			$("n_content_m").value=xmlHttp.responseText;
		}
	}
}
//修改
function m_x_ok(id)
{
	$("n_content_m_b").value="正在提交......";
	$("n_content_m_b").disabled="true";
	cxhr();	
	var url="m_save_ok.asp";
	var t_post="id="+id+"&n_content_m="+escape(document.getElementById("n_content_m").value);
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=m_hsc_ok;
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}

function m_hsc_ok()
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			var temp_x=xmlHttp.responseText;
			if (temp_x=="OK"){
				title_on();
				ff($('p').value);
				
			}
			else{
				$("n_content_m_b").value="确认修改";
				$("n_content_m_b").disabled=false;					
			}
		}
	}
}
//删除
var nn6=document.getElementById&&!document.all; //判断IE还是FF
function del(id,o){
	if (confirm("你确认要删除吗？")){
		if (nn6)
			o.parentNode.parentNode.parentNode.childNodes[3].childNodes[1].innerHTML="正在删除...."
		else
			o.parentNode.parentNode.parentNode.childNodes[1].childNodes[0].childNodes[0].innerHTML="正在删除...."
			
	cxhr();	
	var url="del_save.asp";
	var t_post="id="+id;
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=del_hsc;
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);	}
		
}
function del_hsc()
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			var temp_x=xmlHttp.responseText;
			if (temp_x=="OK")
				ff($('p').value);
			
		}
	}
}
//回复
function hf(id){ 
var msgw,msgh,bordercolor; 
msgw=400;//提示窗口的宽度 
msgh=200;//提示窗口的高度 
titleheight=25 //提示窗口标题高度 
bordercolor="#eff2fa";//提示窗口的边框颜色 
titlecolor="#99CCFF";//提示窗口的标题颜色 

var sWidth,sHeight; 
sWidth=document.body.offsetWidth; 
sHeight=document.body.offsetHeight; 
bgObj=document.createElement("div"); 
bgObj.setAttribute('id','bgDiv'); 
bgObj.style.position="absolute"; 
bgObj.style.top="0"; 
bgObj.style.background="#777"; 
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75"; 
bgObj.style.opacity="0.6"; 
bgObj.style.left="0"; 
bgObj.style.width=sWidth + "px"; 
bgObj.style.height=sHeight + "px"; 
bgObj.style.zIndex = "10000"; 
document.body.appendChild(bgObj); 

 msgObj=document.createElement("div") 
msgObj.setAttribute("id","msgDiv"); 
msgObj.setAttribute("align","center"); 
msgObj.style.background="white"; 
msgObj.style.border="1px solid " + "#d9e1f7"; 
  msgObj.style.position = "absolute"; 
		msgObj.style.left = "50%"; 
		msgObj.style.top = "50%"; 
		msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif"; 
		msgObj.style.marginLeft = "-180px" ; 
		msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px"; 
		msgObj.style.width = msgw + "px"; 
		msgObj.style.height =msgh + "px"; 
		msgObj.style.textAlign = "center"; 
		msgObj.style.lineHeight ="25px"; 
		msgObj.style.zIndex = "10001"; 

title=document.createElement("h4"); 
 title.setAttribute("id","msgTitle"); 
 title.setAttribute("align","right"); 
 title.style.margin="0"; 
 title.style.padding="3px"; 
 title.style.background=bordercolor; 
 title.style.opacity="0.75"; 
 title.style.border="1px solid " + bordercolor; 
 title.style.height="18px"; 
 title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif"; 
 title.style.color="white"; 
 title.style.cursor="pointer"; 
 title.innerHTML="<font color=#000000>晴天提供：http://qingtiandy.cn 修改留言模式_请文明用语!  关闭</a>"; 
 title.onclick=title_on;
 document.body.appendChild(msgObj); 
 document.getElementById("msgDiv").appendChild(title); 
 var txt=document.createElement("div"); 
 txt.style.margin="1em 0" 
 txt.setAttribute("id","msgTxt"); 
 txt.innerHTML="<textarea name=\"hf_content_m\" cols=\"50\" rows=\"6\" style=\"width:88%;\"  id=\"hf_content_m\"></textarea><br><input type='button' value='确认回复' onclick=\"hf_x_ok("+id+");\" id=hf_content_m_b>"
	   document.getElementById("msgDiv").appendChild(txt); 
m_x_h(id)
		}
function hf_x_ok(id)
{
	$("hf_content_m_b").value="正在提交您的回复......";
	$("hf_content_m_b").disabled="true";
	cxhr();	
	var url="hf_save_ok.asp";
	var t_post="id="+id+"&hf_content_m="+escape(document.getElementById("hf_content_m").value);
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=hf_hsc_ok;
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}
function hf_hsc_ok()
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			var temp_x=xmlHttp.responseText;
			if (temp_x=="OK"){
				title_on();
				ff($('p').value);
			}
			else{
				$("hf_content_m_b").value="确认回复";
				$("hf_content_m_b").disabled=false;					
			}
		}
	}
}
//读取回复信息
function m_x_h(id)
{
	$("hf_content_m").value="正在加载......";
	cxhr();	
	var url="hf_save_rd.asp";
	var t_post="id="+id;
	xmlHttp.open("post",url,true);
	xmlHttp.onreadystatechange=m_hsc_h;
	xmlHttp.setRequestHeader("Content-Length",t_post.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlHttp.send(t_post);
}
function m_hsc_h()
{
	if(xmlHttp.readyState==4)
	{	
		if (xmlHttp.status==200)
		{
			$("hf_content_m").value=xmlHttp.responseText;
		}
	}
}
