// JavaScript Document
function $(id)
{
	return document.getElementById(id);	
}
function echo(obj,html)
{
	$(obj).innerHTML=html;
}
function fopen(obj)
{
	$(obj).style.display="";
}
function fclose(obj)
{
	$(obj).style.display="none";
}
function lTrim(str)
{
  if (str.charAt(0) == " ")
  {
    //如果字串左边第一个字符为空格
    str = str.slice(1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(1, str.length);
    str = lTrim(str);    //递归调用
  }
  return str;
}
function cj(str)
{
	return str.replace(/[+]/g,"j_**_h");
}
//去掉字串右边的空格
function rTrim(str)
{
  var iLength;
  
  iLength = str.length;
  if (str.charAt(iLength - 1) == " ")
  {
    //如果字串右边第一个字符为空格
    str = str.slice(0, iLength - 1);//将空格从字串中去掉
    //这一句也可改成 str = str.substring(0, iLength - 1);
    str = rTrim(str);    //递归调用
  }
  return str;
}

//去掉字串两边的空格
function trim(str)
{
  return lTrim(rTrim(str));
}
function sck(s)
{
	return s.replace(/\n/g,"[br]");
	//s=s.replace(chr(13)&chr(23),"<br />");	
	//return s;
}
function f(obj)
{
	return trim(eval("document.forms[0]."+obj+".value"));
	//return trim($(obj).value);
}
function setf(obj)
{
	return eval("document.forms[0]."+obj+".focus();");
}
function show(obj)
{
	var s=$(obj).style;
	s.display=s.display=="none" ? "" : "none";
}
function echo(obj,html)
{
		$(obj).innerHTML=html;
}
function createxmlhttp()
{
	var xmlhttp=false;
	try	{
  		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} 
	catch (e) {
  		try {
   			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  		} 
		catch (e) {
   			xmlhttp = false;
 		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  		xmlhttp = new XMLHttpRequest();
				if (xmlhttp.overrideMimeType) {//设置MiME类别
			xmlhttp.overrideMimeType('text/xml');
		}
	}	

	return xmlhttp;	
}
function getnum(url,obj)
{		
		//var b="";
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.onreadystatechange=requestdata;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		function requestdata(){
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
				{
				$(obj).value=xmlhttp.responseText;	
				}
		}
		}
}
function getdata(url,obj1,obj2)
{
		
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.onreadystatechange=requestdata;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		function requestdata()
		{
			
				fopen(obj1);
				echo(obj1,"数据加载中....");
				if(xmlhttp.readyState==4)
				{
					if(xmlhttp.status==200)
					{
						if(obj1!=obj2){fclose(obj1);};
						echo(obj2,xmlhttp.responseText);
						
					}
				}
			
		}
}
function postdata(url,obj,data)
{
		var xmlhttp=createxmlhttp();
		if(!xmlhttp)
		{
			alert("你的浏览器不支持XMLHTTP！！");
			return;
		}
		xmlhttp.open("POST", url, true);
		xmlhttp.onreadystatechange=requestdata;
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlhttp.send(data);
		function requestdata()
		{
			fopen(obj);
			echo(obj,"正在提交数据，请稍等......");
			//alert(xmlhttp.readyState);
			if(xmlhttp.readyState==4)
			{
				//alert(xmlhttp.status);
				if(xmlhttp.status==200)
				{
					echo(obj,xmlhttp.responseText);
				}
			}
		}
}
function checkform(obj,id)
{
	if(obj=="add")
	{
		if(f("user")=="")
		{
			alert("请留下您的大名！！");
			setf("user");
			return false;
		}
		if(f("user").length>10 && f("user")<2 )
		{
			alert("姓名长度只能在2-10位之间！！");
		}
		if(f("qq").length>10 && f("qq")<5 )
		{
			alert("QQ长度只能在5-10位之间！！");
		}
		if(f("title")=="")
		{
			alert("请填写留言标题！！");
			setf("title");
			return false;
		}
		if(f("title").length>50)
		{
			alert("对不起标题太长了！！");
			setf("title");
			return false;
		}
		if(f("content")=="")
		{
			alert("留言内容不能为空！！");
			setf("content");
			return false;
		}
		var sex=document.all.sex;
		var value=null;
		for(var i=0;i<sex.length;i++){
			if (sex[i].checked){value=sex[i].value;}   
		}
		data="user="+escape(cj(f("user")))+"&sex="+escape(cj(value))+"&email="+escape(cj(f("email")))+"&qq="+escape(cj(f("qq")))+"&title="+escape(cj(f("title")))+"&content="+escape(cj(document.forms[0].content.value));
		
		postdata("feedback/file.asp?action=addsave","msglist",data);
	}else if(obj=="reply")
	{
		if(f("reply")=="")
		{
			alert("留言内容不能为空！！");
			setf("reply");
			return false;
		}		
		data="reply="+escape(f("reply"))+"&id="+escape(cj(f("id")));
		
		postdata("feedback/file.asp?action=replysave","feedback",data);
	}
	return true;
}
function addtext(NewCode) 
{
    document.forms[0].content.value+=NewCode;
}
function add_b()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[B]"+temp.text+"[/B]";
	}else
	{
		addtext("[B][/B]");
	}
}
function add_i()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[I]"+temp.text+"[/I]";
	}else
	{
		addtext("[I][/I]");
	}
}
function add_u()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[U]"+temp.text+"[/U]";
	}else
	{
		addtext("[U][/U]");
	}
}
function add_email()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[EMAIL]"+temp.text+"[/EMAIL]";
	}else
	{
		addtext("[EMAIL][/EMAIL]");
	}
}
function add_url()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[URL]"+temp.text+"[/URL]";
	}else
	{
		addtext("[URL][/URL]");
	}
}
function add_image()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="[IMAGE]"+temp.text+"[/IMAGE]";
	}else
	{
		addtext("[IMAGE][/IMAGE]");
	}
}
function add_code()
{
	if(f("content") && document.selection.type=="Text")
	{
		temp=document.selection.createRange();
		temp.text="\r[CODE]\r"+temp.text+"\r[/CODE]\r";
	}else
	{
		addtext("\r[CODE]\r\r[/CODE]\r");
	}
}
function add_pic(value)
{
	document.forms[0].content.value+=value;
}
function tck(str)
{
	return str.replace("?"," ");	
}
function test(obj)
{
	var d=$(obj).value;
	var b=open('');
	b.document.write(tck(d));
}