function $(id) {
	return document.getElementById(id);
}

function ctlent(event) {
	if((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
		$("submit").click();
	}
}

function addquote(obj,strAuthor){
	var text = $(obj).innerHTML;
	text = text.replace(/alt\=(\"|)([^\"\s]*)(\"|)/g,"> $2 <");
	text = text.replace(/\<[^\<\>]+\>/g,"\n");
	text = text.replace(/ +/g," ");
	text = text.replace(/\n+/g,"\n");
	text = text.replace(/^\n*/gm,"");
	text = text.replace(/^\s*/gm,"");
	text = text.replace(/\n*$/gm,"");
	text = text.replace(/\s*$/gm,"");
	text = text.replace(/&lt;/g,"<");
	text = text.replace(/&gt;/g,">");
	text = text.replace(/&nbsp;&nbsp;/g,"  ");
	text = text.replace(/&amp;/g,"&");
	$("content").value += "[quote="+strAuthor+"]"+text+"[/quote]";
	$("content").focus();
}

function checkform() {
	if ($('username') && $('username').value == "") {
		alert("请输入您的名字.");
		return false;
	}
	if ($('content') && $('content').value == "")	{
		alert("请输入内容.");
		return false;
	}
	if ($('clientcode') && $('clientcode').value == "")	{
		alert("请输入验证码.");
		return false;
	}
	if (((postminchars != 0 && $('content').value.length < postminchars) || (postmaxchars != 0 && $('content').value.length > postmaxchars))) {
		alert("您的评论内容长度不符合要求。\n\n当前长度: "+$('content').value.length+" 字节\n系统限制: "+postminchars+" 到 "+postmaxchars+" 字节");
		return false;
	}			
	$('submit').disabled = true;
	return true;
}

function checkloginform() {
	if ($('username').value == "") {
		alert("请输入您的名字.");
		return false;
	}
	if ($('password').value == "" || ($('confirmpassword') && $('confirmpassword').value == "")) {
		alert("请输入密码和确认密码.");
		return false;
	}
	if ($('confirmpassword') && $('password').value !== $('confirmpassword').value) {
		alert("两次输入密码不一样,请重新输入.");
		return false;
	}
	if ($('clientcode') && $('clientcode').value == "")	{
		alert("请输入验证码.");
		return false;
	}
	return true;
}

function showhide(obj) {
	$(obj).style.display = $(obj).style.display == "none" ? "block" : "none";
}

function showajaxdiv(action, url, width) {
	var x = new Ajax('statusid', 'XML');
	x.get(url, function(s) {
		if($("ajax-div-"+action)) {
			var divElement = $("ajax-div-"+action);
		} else {
			var divElement = document.createElement("DIV");
			divElement.id = "ajax-div-"+action;
			divElement.className = "ajaxdiv";
			document.body.appendChild(divElement);
		}
		divElement.style.cssText = "width:"+width+"px;";
		var userAgent = navigator.userAgent.toLowerCase();
		var is_opera = (userAgent.indexOf('opera') != -1);
		var clientHeight = scrollTop = 0; 
		if(is_opera) {
			clientHeight = document.body.clientHeight /2;
			scrollTop = document.body.scrollTop;
		} else {
			clientHeight = document.documentElement.clientHeight /2;
			scrollTop = document.documentElement.scrollTop;
		}
		divElement.innerHTML = s.lastChild.firstChild.nodeValue;
		divElement.style.left = (document.documentElement.clientWidth /2 +document.documentElement.scrollLeft - width/2)+"px";
		divElement.style.top = (clientHeight +　scrollTop - divElement.clientHeight/2)+"px";
	});	
}

function setCopy(content){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',content);
		alert ("该地址已经复制到剪切板");
	} else {
		prompt("请复制网站地址:",content); 
	}
}

function fiximage(thumbs_size) {
	var max = thumbs_size.split('x');
	var fixwidth = max[0];
	var fixheight = max[1];
	imgs = document.getElementsByTagName('img');
	for(i=0;i<imgs.length;i++) {
		w=imgs[i].width;h=imgs[i].height;
		if(w>fixwidth) { imgs[i].width=fixwidth;imgs[i].height=h/(w/fixwidth);}
		if(h>fixheight) { imgs[i].height=fixheight;imgs[i].width=w/(h/fixheight);}
	}
}

function showflash(swf,sid,w,h,trans,fs,menu,checkver,fv){
	if(checkver!=null){
		var downloadurl="http://www.macromedia.com/go/getflashplayer";
		var version=getFlashPlayerVersion();
		if(version[0]<checkver){
			document.write('<p></p>');
			document.write('<font color=red>此处应该显示为FLASH</font>');
			document.write('<br><font color=red>系统检测到你的电脑中FLASH播放器未安装或版本低于需要</font>');
			document.write('<br><a href="'+downloadurl+'" target="_blank"><font color=red>请点击此处至官方网站安装</font></a>');
			document.write('<br><font color=red>安装完成后请刷新本页面</font>');
			document.write('<p></p>');
			return false;
		}
	}
	menu=menu==null||menu=="false"?"false":menu;
	trans=trans==null||trans=="false"?"window":"transparent";
	fs=fs==null||fs=="false"?"false":fs;
	fv=fv==null?"":fv;
	document.write('<object id="'+sid+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="'+swf+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="allowFullScreen" value="'+fs+'">');
	document.write('<param name="wmode" value="'+trans+'">');
  document.write('<param name="flashVars" value="'+fv+'">');
	document.write('<param name="menu" value="'+menu+'">');
	document.write('<embed name="'+sid+'" menu="'+menu+'" allowFullScreen="'+fs+'" flashVars="'+fv+'" allowScriptAccess="always" src="'+swf+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"  wmode="'+trans+'"></embed>');
	document.write('</object>');
}

function getFlashPlayerVersion(){
	var version=[0,0,0];
	if(navigator.plugins&&navigator.mimeTypes.length){
		var x=navigator.plugins["Shockwave Flash"];
		if(x&&x.description){
			version=x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split(".");
		}
	}else{
		if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){
			var axo=1;
			var t=3;
			while(axo){
				try{
					t++;
					axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+t);
					version=[t,0,0];
					}catch(e){
						axo=null;
					}
				}
		}else{
				try{
					var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
				}catch(e){
					try{
						var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
						version=[6,0,21];
						axo.AllowScriptAccess="always";
				  }catch(e){
				  	if(version[0]=="6"){
				  		for(var i in version){
				  			version[i]==parseInt(version[i]);
				  		}
				  		return version;
				  	}
				  }
				  try{
				  	axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				  }catch(e){
				  }
				  }
				 if(axo!=null){
				 	 version=axo.GetVariable("$version").split(" ")[1].split(",");
				 }
				}
		}
		for(var i in version){
			version[i]==parseInt(version[i]);
		}
		return version;
};