
function resizeImages(w){
	for(i=0;i<document.images.length;i++){
		if(parseInt(document.images[i].width)>w){
			document.images[i].width=w;
			document.images[i].style.cursor="pointer";
			document.images[i].title+="图片已缩小，请点击查看原始尺寸。";
			document.images[i].onclick=function(){
				window.open(this.src,"","");
			}
		}
	}
}

function postData(sUrl, sData, mode, obj){
	if(navigator.appVersion.indexOf("Win") != -1 && navigator.userAgent.indexOf("Opera") == -1){
		if(window.XMLHttpRequest){
			xmlhttp = new XMLHttpRequest();
		}else if(window.ActiveXObject){
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}else{
		xmlhttp = false;
	}
	if(mode>0){
		if(xmlhttp){
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState==4&&xmlhttp.status==200) {
					var msgArr = [""
					,["文章未删除","文章已删除，返回首页？"]
					,["评论未删除","评论已删除，刷新文章？"]
					,["文章未删除","文章已删除，刷新列表？"]
					,["评论未删除","评论已删除，刷新列表？"]
					,["文章未修改","文章已修改，刷新列表？"]
					,["文章未修改","文章已修改，刷新文章？"]
					,["用户未删除","用户已删除，刷新列表？"]]
					var msg = xmlhttp.responseText;
					if(msg=="0"){
						window.alert(msgArr[mode][0]);
					}
					else{
						if(window.confirm(msgArr[mode][1])){
							if(mode==1){location.href="/";}
							else{location.reload();}
						}
					}
				}
			}
			xmlhttp.open("POST", sUrl, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.send(sData);
		}
		else{
			location.href = sUrl;
		}
	}
	else{
		if(xmlhttp){
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState==4) {
					var msg = xmlhttp.responseText;
					if(msg=="4"){window.alert("用户名已被注册");}
					else if(msg=="5"){alert("用户名或者密码不正确");}
					else{if(window.confirm("评论已发出，是否刷新页面？")){location.href="read.asp?rnd="+Math.random()+"&"+unescape(msg);}}
					document.getElementById("submit").value = "发表评论";
					document.getElementById("submit").disabled = false;
				}
			}
			document.getElementById("submit").value = "信息提交中……";
			document.getElementById("submit").disabled = true;
			xmlhttp.open("POST", sUrl, true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			xmlhttp.send(sData);
			return false;
		}else{
			return true;
		}
	}
}

function trim(str){
	return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

function check(obj){
	if(trim(obj.nickname.value)==""){
		alert("请输入昵称");
		obj.nickname.focus();
		return false;
	}

	else if(trim(obj.content.value)==""){
		alert("请输入内容");
		obj.content.focus();
		return false;
	}
	else if(trim(obj.content.value).length>400){
		alert("请把评论的字数控制在400以内");
		obj.content.focus();
		return false;
	}
	else if(obj.content.value.indexOf("href=")>0){
		alert("未知错误");
		obj.content.focus();
		return false;
	}
	else if(obj.reg&&obj.reg.checked){
		if(obj.password.value==""){
			alert("要注册成为新用户，请输入密码");
			obj.password.focus();
			return false;
		}

		// Forbid registering the strings which started with Guest.
		else if(trim(obj.nickname.value).toLowerCase().indexOf("guest")==0){
			alert("注册用户名不能以\"Guest\"开始");
			obj.nickname.focus();
			return false;
		}
		else{
			return postData("reply.asp?id="+escape(obj.id.value)+"&nickname="+escape(obj.nickname.value)+"&password="+escape(obj.password.value)+"&reg=yes&content="+escape(obj.content.value),"")
		}
	}
	else{
		if(obj.password){var spassword = obj.password.value}
		else{var spassword = ""}
		return postData("reply.asp?id="+escape(obj.id.value)+"&nickname="+escape(obj.nickname.value)+"&password="+escape(spassword)+"&reg=no&content="+escape(obj.content.value),"")
	}
}

function chkPm(obj){
	if(trim(obj.topic.value)==""){
		alert("请输入标题");
		obj.topic.focus();
	}
	else if(trim(obj.content.value)==""){
		alert("请输入内容");
		obj.content.focus();
	}
	else{
		obj.submit();
	}
}

function showhide(obj){
	var tmp;
	tmp = obj.parentNode.nextSibling.nextSibling;
	if(tmp.nodeName=="DIV"&&tmp.className=="content"){
		if(tmp.style.display=="none"){
			tmp.style.display="block";
			obj.value="┃";
			obj.title="隐藏";
		}
		else{
			tmp.style.display="none";
			obj.value="━";
			obj.title="显示";
		}
	}else if(tmp.nextSibling.nextSibling.nodeName=="DIV"&&tmp.nextSibling.nextSibling.className=="content"){
		if(tmp.nextSibling.nextSibling.style.display=="none"){
			tmp.nextSibling.nextSibling.style.display="block";
			obj.value="┃";
			obj.title="隐藏";
		}
		else{
			tmp.nextSibling.nextSibling.style.display="none";
			obj.value="━";
			obj.title="显示";
		}
	}
}

function mpcontrol(obj, txt){
	var w = document.getElementById(obj).style;
	var t = document.getElementById(txt);
	if(w.display=="block"){
		w.display="none";
		t.innerHTML="显示媒体文件";
	}
	else{
		w.display="block";
		t.innerHTML="隐藏媒体文件";
	}
}

function openme(u,n,w,h){
	if(u){
		window.open(u,n,"width="+w+",height="+h);
	}
}

function externalLinks(){
	if(!document.getElementsByTagName){
		return;
	}
	var anchors=document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor=anchors[i];
		anchor.onfocus=function(){this.blur();}
		if (anchor.getAttribute("href")&&anchor.getAttribute("rel")=="external"){
			anchor.target="_blank";
		}
	}
}

function chkReg(obj){
	if(trim(obj.nickname.value)==""){
		alert("请输入昵称");
		obj.nickname.focus();
	}
	else if(trim(obj.password.value)==""){
		alert("请输入密码");
		obj.password.focus();
	}
	else if(trim(obj.password2.value)==""){
		alert("请输入确认密码");
		obj.password2.focus();
	}
	else if(obj.password.value != obj.password2.value){
		alert("两次输入的密码不符");
		obj.password2.focus();
	}
	else if(obj.email.value!=""&&!obj.email.value.match(/^.+@.+\..{2,3}(\..{2,3})?$/)){
		alert("电子邮件地址格式不正确");
		obj.email.focus();
	}
	else if(obj.homepage.value!=""&&!obj.homepage.value.match(/^http:\/\/.+\..+(\..+)?(\..+)?$/)){
		alert("网址格式不正确");
		obj.homepage.focus();
	}
	else if(obj.msn.value!=""&&!obj.msn.value.match(/^.+@.+\..{2,3}(\..{2,3})?$/)){
		alert("MSN格式不正确");
		obj.msn.focus();
	}
	else if(obj.qq.value!=""&&!obj.qq.value.match(/^\d{5,10}$/)){
		alert("QQ格式不正确");
		obj.qq.focus();
	}
	else if(obj.icq.value!=""&&!obj.icq.value.match(/^\d{5,10}$/)){
		alert("ICQ格式不正确");
		obj.icq.focus();
	}
	else if(obj.popo.value!=""&&!(obj.popo.value.match(/^.+@.+\..{2,3}(\..{2,3})?$/)||obj.popo.value.length<17)){
		alert("POPO格式不正确");
		obj.popo.focus();
	}
	else if(obj.tel.value!=""&&obj.tel.value.length>20){
		alert("电话不正确");
		obj.tel.focus();
	}
	else if(obj.mobile.value!=""&&obj.mobile.value.length>20){
		alert("移动电话不正确");
		obj.mobile.focus();
	}
	else if(obj.from.value!=""&&obj.from.value.length>16){
		alert("“来自”不正确");
		obj.from.focus();
	}
	else{
		obj.submit();
	}
}
function mp3(s,a){
	document.write("<div class=\"c\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"468\" height=\"80\"><param name=\"movie\" value=\"player.swf?a="+a+"&s="+s+"\" /><param name=\"quality\" value=\"high\" /><embed src=\"player.swf?a="+a+"&s="+s+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"468\" height=\"80\"></embed></object></div>")
}
function flv(s,a){
	if(MM_FlashCanPlay){
		document.write("<div class=\"c\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"468\" height=\"351\"><param name=\"movie\" value=\"flv8.swf?a="+a+"&s="+s+"\" /><param name=\"quality\" value=\"high\" /><embed src=\"flv8.swf?a="+a+"&s="+s+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"468\" height=\"351\"></embed></object></div>")
	}
	else{
		document.write("<div class=\"c\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"468\" height=\"310\"><param name=\"movie\" value=\"flv.swf?a="+a+"&s="+s+"\" /><param name=\"quality\" value=\"high\" /><embed src=\"flv.swf?a="+a+"&s="+s+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"468\" height=\"310\"></embed></object><div>你还没装<a rel=\"external\" href=\"http://www.macromedia.com/shockwave/download/triggerpages_mmcom/flash.html\" title=\"下载Flash Player 8.0\">Flash Player 8.0</a>吗？</div></div>")
	}
}
function swf(u,w,h){
	document.write("<div class=\"swf\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+w+"\" height=\""+h+"\"><param name=\"movie\" value=\""+u+"\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\""+u+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\""+w+"\" height=\""+h+"\"></embed></object></div>")
}


var MM_contentVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
		}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<scr' + 'ipt language="VBScript"> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</scr' + 'ipt> \n');
}

window.onload = function(e) {
	externalLinks();
	location.href.indexOf("read") != -1 ? resizeImages(640) : resizeImages(640)
		// for read.asp and common pages respectively.
}
