// JavaScript Document
var emoteData=[]
emoteData.push(["微笑","wx"])
emoteData.push(["撇嘴","pz"])
emoteData.push(["色","se"])
emoteData.push(["发呆","fd"])
emoteData.push(["得意","dy"])
emoteData.push(["流泪","ll"])
emoteData.push(["害羞","hx"])
emoteData.push(["闭嘴","bz"])
emoteData.push(["睡","shui"])
emoteData.push(["大哭","dk"])
emoteData.push(["尴尬","gg"])
emoteData.push(["发怒","fn"])
emoteData.push(["调皮","tp"])
emoteData.push(["呲牙","cy"])
emoteData.push(["惊讶","jy"])
emoteData.push(["难过","ng"])
emoteData.push(["酷","kuk"])
emoteData.push(["冷汗","lengh"])
emoteData.push(["抓狂","zk"])
emoteData.push(["吐","tuu"])
emoteData.push(["偷笑","tx"])
emoteData.push(["可爱","ka"])
emoteData.push(["白眼","baiy"])
emoteData.push(["傲慢","am"])
emoteData.push(["饥饿","jie"])
emoteData.push(["困","kun"])
emoteData.push(["惊恐","jk"])
emoteData.push(["流汗","lh"])
emoteData.push(["憨笑","hanx"])
emoteData.push(["大兵","db"])
emoteData.push(["奋斗","fendou"])
emoteData.push(["咒骂","zhm"])
emoteData.push(["疑问","yiw"])
emoteData.push(["嘘...","xu"])
emoteData.push(["晕","yun"])
emoteData.push(["折磨","zhem"])
emoteData.push(["衰","shuai"])
emoteData.push(["骷髅","kl"])
emoteData.push(["敲打","qiao"])
emoteData.push(["再见","zj"])
emoteData.push(["擦汗","ch"])
emoteData.push(["抠鼻","kb"])
emoteData.push(["鼓掌","gz"])
emoteData.push(["糗大了","qd"])
emoteData.push(["坏笑","huaix"])
emoteData.push(["左哼哼","zhh"])
emoteData.push(["右哼哼","yhh"])
emoteData.push(["哈欠","hq"])
emoteData.push(["鄙视","bs"])
emoteData.push(["委屈","wq"])
emoteData.push(["快哭了","kk"])
emoteData.push(["阴险","yx"])
emoteData.push(["亲亲","qq"])
emoteData.push(["吓","xia"])
emoteData.push(["可怜","kel"])
emoteData.push(["菜刀","cd"])
emoteData.push(["西瓜","xig"])
emoteData.push(["啤酒","pj"])
emoteData.push(["篮球","lq"])
emoteData.push(["乒乓","pp"])
emoteData.push(["咖啡","kf"])
emoteData.push(["饭","fan"])
emoteData.push(["猪头","zt"])
emoteData.push(["玫瑰","mg"])
emoteData.push(["凋谢","dx"])
emoteData.push(["示爱","sa"])
emoteData.push(["爱心","xin"])
emoteData.push(["心碎","xs"])
emoteData.push(["蛋糕","dg"])
emoteData.push(["闪电","shd"])
emoteData.push(["炸弹","zhd"])
emoteData.push(["刀","dao"])
emoteData.push(["足球","zq"])
emoteData.push(["瓢虫","pch"])
emoteData.push(["便便","bb"])
emoteData.push(["月亮","yl"])
emoteData.push(["太阳","ty"])
emoteData.push(["礼物","lw"])
emoteData.push(["拥抱","yb"])
emoteData.push(["强","qiang"])
emoteData.push(["弱","ruo"])
emoteData.push(["握手","ws"])
emoteData.push(["胜利","shl"])
emoteData.push(["抱拳","bq"])
emoteData.push(["勾引","gy"])
emoteData.push(["拳头","qt"])
emoteData.push(["差劲","cj"])
emoteData.push(["爱你","aini"])
emoteData.push(["NO","bu"])
emoteData.push(["OK","hd"])
emoteData.push(["爱情","aiq"])
emoteData.push(["飞吻","fw"])
emoteData.push(["跳跳","tiao"])
emoteData.push(["发抖","fad"])
emoteData.push(["怄火","oh"])
emoteData.push(["转圈","zhq"])
emoteData.push(["磕头","kt"])
emoteData.push(["回头","ht"])
emoteData.push(["跳绳","tsh"])
emoteData.push(["挥手","hsh"])
emoteData.push(["激动","jd"])
emoteData.push(["街舞","jw"])
emoteData.push(["献吻","xw"])
emoteData.push(["左太极","左太极"])
emoteData.push(["右太极","ytj"])

var canDo=[]
canDo.push(["首页","./",0])
canDo.push(["发布QQ资料","description.htm",0])
canDo.push(["发布QQ签名","sign.htm",0])
canDo.push(["发布QQ网名","name.htm",0])
canDo.push(["发布聊天图文","chat.htm",0])
canDo.push(["发布空间留言代码","zone.htm",0])
canDo.push(["发布QQ头像","head.htm",0])
canDo.push(["发布QQ表情","emote.htm",0])
canDo.push(["发布非主流图片","feizl.htm",0])
canDo.push(["宣传我的主页","home.asp",0])
canDo.push(["修改资料","modify.asp",0])
canDo.push(["修改密码","password.htm",0])
var writeCanDo=function(selectedItem){
	var point=Cookie.get("ddLogin.ddPoint")
	var classNameMy=selectedItem
	var canDoString=""
	for(var i=0; i<canDo.length; i++){
		if(selectedItem=="*"){
			if(canDo[i][0]=="首页")continue;
			if(canDo[i][2]>point){
				canDoString+=canDo[i][0]+"(还差"+(canDo[i][2]-point)+"积分)<br />"
			}else{
				canDoString+='<a href="'+canDo[i][1]+'">'+canDo[i][0]+"</a><br />"
			}
		}else{
			if(canDo[i][2]>point){
				canDoString+=canDo[i][0]+" "
			}else{
				canDoString+='<a href="'+canDo[i][1]+'"'+(classNameMy==canDo[i][0]?' class="selected"':'')+'>'+canDo[i][0]+'</a> '
			}
		}
	}
	document.write(canDoString)
}

var initEmoteUpload=function(){
	var uploadId=0
	var uploadCount=0
	insertUpload=function(){
		var tr=$("trUploadSample").cloneNode(true);
		tr.id="trUpload"+uploadId
		var elements=tr.getElementsByTagName("*")
		for(var i=0; i<elements.length; i++){
			if(elements[i].id=="frmUpload")elements[i].action+=uploadId
			if(elements[i].id!="")
				elements[i].id+=uploadId
			elements[i].index=uploadId
		}
		$("trInsertPosition").parentNode.insertBefore(tr, $("trInsertPosition"))
		tr.style.display=""
		uploadId++
		uploadCount++
	}
	insertUpload()
	insertUpload()
	insertUpload()
	$("trUploadSample").style.display="none"
	detectUpload=function(object){
		$("tipUploadSubmit").innerHTML=""
		$("tipUpload"+object.index).innerHTML='<strong class="cGreen">检测中...</strong>'
		var hasEmpty=false
		var hasSame=false
		for(var i=0; i<uploadId; i++){
			if($("filPicture"+i) && object!=$("filPicture"+i)){
				if(object.value==$("filPicture"+i).value){
					$("tipUpload"+object.index).innerHTML='<strong class="cRed">选择了重复的文件</strong> <a href="###" class="deletePicture" onclick="removeUpload('+object.index+'); return false;">移除</a>'
					$("txtHeadPictureId"+object.index).value=""
					hasSame=true
				}
				if($("tipUpload"+i).innerHTML=="&nbsp;")hasEmpty=true
			}
		}
		if(!hasEmpty)insertUpload()
		if(hasSame){
			replaceUpload(object)
			return
		}
		if(!object.value.match(/^.+(.jpg|.bmp|.gif|.jpeg|.png)$/i)){
			$("tipUpload"+object.index).innerHTML='<strong class="cRed">选择的不是一个图片文件</strong> <a href="###" class="deletePicture" onclick="removeUpload('+object.index+'); return false;">移除</a>'
			$("txtHeadPictureId"+object.index).value=""
			replaceUpload(object)
			return
		}
		$("previewPicture"+object.index).detected=false
		$("previewPicture"+object.index).src=object.value
	}
	replaceUpload=function(object){
		var nObject=object.cloneNode(true)
		object.parentNode.insertBefore(nObject,object)
		object.parentNode.removeChild(object)
	}
	detectPicture=function(object){
		if(object.detected)return
		$("tipUpload"+object.index).innerHTML='<img width="40" height="40" class="previewPicture" src="'+object.src+'"/> <strong class="cGreen">准备就绪</strong> <a href="###" class="deletePicture" onclick="removeUpload('+object.index+'); return false;">移除</a>'
		$("txtHeadPictureId"+object.index).value="OK"
		object.detected=true
	}
	errorPicture=function(object){
		$("tipUpload"+object.index).innerHTML='<strong class="cRed">无效的图片文件</strong> <a href="###" class="deletePicture" onclick="removeUpload('+object.index+'); return false;">移除</a>'
		$("txtHeadPictureId"+object.index).value=""
		replaceUpload("filPicture"+object.index)
	}
	removeUpload=function(index){
		var tr=$("trUpload"+index)
		tr.parentNode.removeChild(tr)
		uploadCount--
		if(!uploadCount)insertUpload()
	}
	$("frmTry").onsubmit=function(){
		$("tipUploadSubmit").innerHTML=""
		if(!$("txtName").value.replace(/[^\x00-\xff]/g,"dd").match(/.{2,24}$/)){
			$("tipName").innerHTML="名称不符合规范"
			return false
		}
		if($("optMethod_single").checked){
			var allOK=true
			var hasOK=0
			for(var i=0; i<uploadId; i++){
				if($("txtHeadPictureId"+i)){
					if($("txtHeadPictureId"+i).value!="OK" && $("tipUpload"+i).innerHTML!="&nbsp;"){
						allOK=false
					}else if($("txtHeadPictureId"+i).value=="OK"){
						hasOK++
					}
				}
			}
			if(!hasOK){
				$("tipUploadSubmit").innerHTML="上传列队中没有文件"
				return false
			}
			if(hasOK<5){
				$("tipUploadSubmit").innerHTML="至少需要 5 张图片"
				return false
			}
			var uploadStart=false
			if(!allOK){
				if(confirm("上传列队中有无效的文件, 这些文件将被移除, 是否继续?")) uploadStart=true
			}else{
				uploadStart=true
			}
			if(uploadStart){
				$("selClass").disabled=$("txtName").disabled=$("btnSubmit").disabled=$("optMethod_package").disabled=$("optMethod_single").disabled=true
				return true
			}
			return false
		}else{
			if(!$("fileRar").value.match(/^.+(.rar|.zip)$/i)){
				$("tipUploadSubmit").innerHTML="选择的不是一个压缩包文件"
				return false
			}
			$("selClass").disabled=$("txtName").disabled=$("btnSubmit").disabled=$("optMethod_package").disabled=$("optMethod_single").disabled=true
			return true
		}
	}
	detectUploadRar=function(object){
		$("tipUploadSubmit").innerHTML=""
	}

	submitProcess=function(){
		if($("optMethod_single").checked){
			for(var i=0; i<uploadId; i++){
				if($("txtHeadPictureId"+i)){
					if($("txtHeadPictureId"+i).value=="OK"){
						$("tipUpload"+i).innerHTML='排队中'
						$("filPicture"+i).style.left=-999+"px"
						$("filPicture"+i).style.top=-999+"px"
						$("spanPickFile"+i).className=""
					}else{
						removeUpload(i)
					}
				}
			}
			submitNext(0)
		}else{
			$("frmUploadRar").submit()
		}
	}
	submitNext=function(currentSubmitId){
		for(var i=currentSubmitId; i<uploadId; i++){
			if($("txtHeadPictureId"+i)){
				if($("txtHeadPictureId"+i).value=="OK"){
					$("tipUpload"+i).innerHTML='<strong class="cGreen">正在上传中...</strong>'
					$("frmUpload"+i).submit()
					return
				}
			}
		}
		var ids=[]
		for(var i=0; i<uploadId; i++){
			if($("txtHeadPictureId"+i)){
				if($("txtHeadPictureId"+i).value.match(/^\d{32}\.(gif|jpg)$/)){
					ids.push($("txtHeadPictureId"+i).value)
				}
			}
		}
		$("selClass").disabled=$("txtName").disabled=$("btnSubmit").disabled=$("optMethod_package").disabled=$("optMethod_single").disabled=false
		$("txtTempFileId").value=ids.join("|")
		$("frmContent").submit()
	}
	submitOK=function(id, tempFileId){
		$("tipUpload"+id).innerHTML='<strong class="cGreen">上传完毕</strong>'
		$("txtHeadPictureId"+id).value=tempFileId
		submitNext(id+1)
	}
	submitRarOK=function(tempFiles){
		$("selClass").disabled=$("txtName").disabled=$("btnSubmit").disabled=$("optMethod_package").disabled=$("optMethod_single").disabled=false
		$("txtTempFileId").value=tempFiles
		$("frmContent").submit()
	}
	$("txtName").onfocus=function(){$("tipName").innerHTML=""}
	errorAlert=function(text){
		alert(text)
		$("selClass").disabled=$("txtName").disabled=$("btnSubmit").disabled=$("optMethod_package").disabled=$("optMethod_single").disabled=false
	}
	submitComplete=function(){
		alert("恭喜! 您的发布已成功的提交, 请耐心等待管理员审核.")
		$("txtName").value=""
		$("txtTempFileId").value=""
		var uploadIdT=uploadId
		for(var i=0; i<uploadIdT; i++){
			if($("txtHeadPictureId"+i))removeUpload(i)
		}
		insertUpload()
		insertUpload()
		replaceUpload($("fileRar"))
		$("btnSubmit").disabled=false
	}
	$("optMethod_single").onclick=function(){
		$("optMethod_single").checked=true
		$("tbUploadSingle").style.display=""
		$("trUploadRar").style.display="none"
		$("tipUploadSubmit").innerHTML=""
	}
	$("optMethod_package").onclick=function(){
		$("optMethod_package").checked=true
		$("tbUploadSingle").style.display="none"
		$("trUploadRar").style.display=""
		$("tipUploadSubmit").innerHTML=""
	}
	window.onload=$("optMethod_single").onclick
}

function chatEncode(text){
	text=text.toHTML()
	for(var i=0; i<emoteData.length; i++){
		eval("text=text.replace(/\\/"+emoteData[i][1]+"/g,'<img src=\"/style/images/emote/"+i+".gif\"/>')")
	}
	return text+"&nbsp;"
}
function zoneEncode(text){
	text=text.toHTML()
	for(var i=0; i<=90; i++){
		eval("text=text.replace(/\\[em\\]e"+i+"\\[\\/em\\]/g,'<img src=\"/style/images/emoteOld/e"+i+".gif\"/>')")
	}
	for(var i=0; i<emoteData.length; i++){
		eval("text=text.replace(/\\[em\\]e"+(100+i)+"\\[\\/em\\]/g,'<img src=\"/style/images/emote/"+i+".gif\"/>')")
	}
	text=text.replace(/\[ftf=([^]]+)\]/g,'<font_qqbiji face="$1">')
	text=text.replace(/\[fts=([^]]+)\]/g,'<font_qqbiji size="$1" style="line-height: 1.3me">')
	text=text.replace(/\[ftc=([^]]+)\]/g,'<font_qqbiji color="$1">')
	text=text.replace(/\[ffg,([^,]+),([^]]+)\]/g,'<font_qqbiji style="display: inline-block; filter: glow(color=$1,strength=3); color: $2; padding: 1px; height: 10px;">')
	text=text.replace(/\[B\]/g,'<b_qqbiji>')
	text=text.replace(/\[I\]/g,'<i_qqbiji>')
	text=text.replace(/\[U\]/g,'<u_qqbiji>')
	text=text.replace(/\[M\]/g,'<center_qqbiji>')
	text=text.replace(/\[R\]/g,'<center_qqbiji style="text-align: right">')
	
	text=text.replace(/\[\/ft\]/g,'</font_qqbiji>')
	text=text.replace(/\[\/B\]/g,'</b_qqbiji>')
	text=text.replace(/\[\/I\]/g,'</i_qqbiji>')
	text=text.replace(/\[\/U\]/g,'</u_qqbiji>')
	text=text.replace(/\[\/M\]/g,'</center_qqbiji>')
	text=text.replace(/\[\/R\]/g,'</center_qqbiji>')
	var testData=new Array("font","b","i","u","center")
	for(var i=0; i<testData.length; i++){
		var nStart=text.split("<"+testData[i]+"_qqbiji").length-1
		var nEnd=text.split("</"+testData[i]+"_qqbiji").length-1
		for(var o=nStart; o>nEnd; o--){
			text+='</'+testData[i]+'_qqbiji>'
		}
	}
	return text.replace(/\_qqbiji/g,"")+"&nbsp;"
}

function copyToClipboard(txt) {
	var errUnsupport="代码复制操作暂不支持您的浏览器. 您可以使用 Ctrl+C 来手动复制."
	var errNotAllow="您的浏览器不允许脚本执行剪切板操作, 代码复制无法完成!"
	if(window.clipboardData) {   
		window.clipboardData.clearData()
		window.clipboardData.setData("Text", txt)
		return ""
	}else if(navigator.userAgent.indexOf("Opera") != -1) {   
		return errUnsupport
	}else if (window.netscape){
		try {   
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
		}catch(e){   
			return errNotAllow+'\n\n如果您正在使用 FireFox 浏览器浏览, 请在地址栏输入 about:config 并按回车键,\n然后将 signed.applets.codebase_principal_support 选项设置为 true.'
			return false
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard)
		if (!clip) return errNotAllow
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable)
		if (!trans) return errNotAllow
		trans.addDataFlavor('text/unicode')
		var str = new Object()
		var len = new Object()
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt
		str.data = copytext
		trans.setTransferData("text/unicode",str,copytext.length*2)
		var clipid = Components.interfaces.nsIClipboard
		if (!clip) return errNotAllow
		clip.setData(trans,null,clipid.kGlobalClipboard)
		return ""
	}
	return errUnsupport
} 
var zoneEditor={}
zoneEditor.writeTools=function(){
	document.write('<tr id="fontPanel" class="toolPanel"><td width="80" valign="top" class="tableHeader">字体<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td id="tdFonts">&nbsp;</td></tr><tr id="sizePanel" class="toolPanel"><td valign="top" class="tableHeader">字号<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td id="tdSizes" style="line-height: 36px;">&nbsp;</td></tr><tr id="emotePanel" class="toolPanel"><td valign="top" class="tableHeader">表情<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td id="tdEmote">&nbsp;</td></tr><tr id="linkPanel" class="toolPanel"><td valign="top" class="tableHeader">超级链接<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td>链接地址<input type="text" class="input" id="txtLinkURL" value="www.QQbiji.com" size="47" /><input type="button" class="buttonInsert" id="btnLink" value="插入" /></td></tr><tr id="emailPanel" class="toolPanel"><td valign="top" class="tableHeader">邮箱地址<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td>邮箱地址<input type="text" class="input" id="txtMailURL" value="hi@QQbiji.com" size="47" /><input type="button" class="buttonInsert" id="btnMail" value="插入" /></td></tr><tr id="picturePanel" class="toolPanel"><td valign="top" class="tableHeader">插入图片<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td>图片地址<input type="text" class="input" id="txtPictureURL" size="47" /><input type="button" class="buttonInsert" id="btnPicture" value="插入" /></td></tr><tr id="colorPanel" class="toolPanel"><td valign="top" class="tableHeader">字体颜色<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td id="toolColor"></td></tr><tr id="glowPanel" class="toolPanel"><td valign="top" class="tableHeader">发光字<br /><a href="#" class="closeTool" onclick="hideShowPanel(); return false">[收起来]</a></td><td id="toolColorGlow">&nbsp;</td></tr>')
}
zoneEditor.writeToolIcons=function(){
	document.write('<a href="#" style="background-position:0px -176px;" onmouseup="hideShowPanel(\'fontPanel\')">字体</a><a href="#" style="background-position:0px -192px;" onmouseup="hideShowPanel(\'sizePanel\')">字号</a><a href="#" style="background-position:0px -32px;" onmouseup="inputUBB(\'[B]#selected#[/B]\')"></a><a href="#" style="background-position:0px -48px;" onmouseup="inputUBB(\'[I]#selected#[/I]\')"></a><a href="#" style="background-position:0px -64px;" onmouseup="inputUBB(\'[U]#selected#[/U]\')"></a><a href="#" style="background-position:0px 0px;" onmouseup="hideShowPanel(\'colorPanel\')"></a><a href="#" style="background-position:0px -16px;" onmouseup="hideShowPanel(\'glowPanel\')"></a><a href="#" style="background-position:0px -96px;" onmouseup="inputUBB(\'[M]#selected#[/M]\')"></a><a href="#" style="background-position:0px -80px;" onmouseup="inputUBB(\'[R]#selected#[/R]\')"></a><a href="#" style="background-position:0px -112px;" onmouseup="hideShowPanel(\'emotePanel\')"></a><a href="#" style="background-position:0px -128px; display:none;" onmouseup="hideShowPanel(\'picturePanel\')"></a><a href="#" style="background-position:0px -144px; display:none;" onmouseup="hideShowPanel(\'linkPanel\')">链接</a>')
}
zoneEditor.init=function(){
	var tr=$("zoneEdit").getElementsByTagName("tr")
	hideShowPanel=function(panelName){
		for(var i=0; i<tr.length; i++){
			tr[i].style.display="none"
		}
		if(!$(panelName)) return false
		if($(panelName).style.display=="") $(panelName).style.display="none"
		else $(panelName).style.display=""
	}
	hideShowPanel()
	var fonts="微软雅黑,仿宋_GB2312,黑体,楷体_GB2312,宋体,新宋体,Tahoma,Arial,Impact,Verdana".split(",")
	var fontString=""
	for(var i=0; i<fonts.length; i++){
		fontString+='<a href="###" onclick="inputUBB(\'[ftf='+fonts[i]+']#selected#[/ft]\');return false;" style="font-family:\''+fonts[i]+'\'">'+fonts[i]+'</a> '
	}
	$("tdFonts").innerHTML=fontString
	var fSizes="六号,五号,四号,三号,二号,一号".split(",")
	var sizeString=""
	for(var i=0; i<fSizes.length; i++){
		sizeString+='<a href="###" onclick="inputUBB(\'[fts='+(i+1)+']#selected#[/ft]\');return false;"><font size="'+(i+1)+'">'+fSizes[i]+'</font></a> '
	}
	$("tdSizes").innerHTML=sizeString
	
	var links=$("toolBar").getElementsByTagName("A")
	for(var i=0; i<links.length; i++){
		links[i].onfocus=function(){this.blur()}
		links[i].onclick=function(){return false}
	}
	$("btnMail").onclick=function(){
		if($("txtMailURL").value==""){
			alert("您输入的邮箱地址无效, 请核对后重新输入!")
			return false
		}
		inputUBB("[email=#selected#]"+$("txtMailURL").value+"[/email]")
	}
	$("btnPicture").onclick=function(){
		if($("txtPictureURL").value==""){
			alert("您输入的图片地址无效, 请核对后重新输入!")
			return false
		}
		inputUBB("[img]"+($("txtPictureURL").value.toLowerCase().substr(0,7)=="http://"?$("txtPictureURL").value:("http://"+$("txtPictureURL").value))+"[/img]")
	}
	$("btnLink").onclick=function(){
		if($("txtLinkURL").value==""){
			alert("您输入的超级链接地址无效, 请核对后重新输入!")
			return false
		}
		inputUBB("[url="+($("txtLinkURL").value.toLowerCase().substr(0,7)=="http://"?$("txtLinkURL").value:("http://"+$("txtLinkURL").value))+"]#selected#[/url]")
	}
	makeColorToolHtml=function(clickScript){
		var cString='<div class="toolColor">'
		for(var i=0; i<2; i++){
			for(var b=0; b<6; b++){
				for(var r=i*3; r<i*3+3; r++){
					for(var g=0; g<6; g++){
						var c=(r*51).toString(16).replace(/^([\da-f])$/g,"0$1")+(g*51).toString(16).replace(/^([\da-f])$/g,"0$1")+(b*51).toString(16).replace(/^([\da-f])$/g,"0$1")
						cString+='<div style="background-color:#'+c+';"><a href="###" onclick="'+clickScript.replace("#color#",c)+'; return false" onfocus="this.blur()"></a></div>'
					}
				}
			}
		}
		return cString.replace(/\<tr\>$/,"")+"</div>"
	}
	$("toolColor").innerHTML=makeColorToolHtml("inputUBB('[ftc=##color#]#selected#[/ft]')")
	$("toolColorGlow").innerHTML=makeColorToolHtml("inputUBB('[ffg,##color#,#ffffff]#selected#[/ft]')")
	
	var emoteString='<div style="width: 400px;">'
	for(var i=0; i<emoteData.length; i++){
		if(i % 15==0 && i)emoteString+="<br />"
		emoteString+='<a href="###" title="'+emoteData[i][0]+'" onclick="return inputUBB(\'[em]e'+(i+100)+'[/em]\');" onfocus="this.blur()"></a>'
	}
	$("tdEmote").innerHTML=emoteString+"</div>"
	
	inputUBB=function(ubbCode){
		$("txtZone").focus();
		var text=""
		if (document.selection) {
			text=document.selection.createRange().text
			document.selection.createRange().text = ubbCode.replace("#selected#",text);
			document.selection.createRange().select()
		}else {
			var startPos = $("txtZone").selectionStart;
			var endPos = $("txtZone").selectionEnd;
			text=$("txtZone").value.substr(startPos, endPos-startPos)
			$("txtZone").value = $("txtZone").value.substring(0, startPos) + ubbCode.replace("#selected#",text) + $("txtZone").value.substring(endPos, $("txtZone").value.length);
			$("txtZone").setSelectionRange(startPos, startPos+ubbCode.replace("#selected#",text).length);
		}
		hideShowPanel()
		return false
	}
}

var chatEditor={}
chatEditor.init=function(){
	var emoteString=""
	for(var i=0; i<emoteData.length; i++){
		if(i % 15==0 && i)emoteString+="<br />"
		emoteString+='<a href="###" title="'+emoteData[i][0]+'" onclick="return inputEmote(\'/'+emoteData[i][1]+'\');" onfocus="this.blur()"></a>'
	}
	$("tdEmote").innerHTML=emoteString
	inputEmote=function(emote){
		$("txtChat").focus();
		if (document.selection) {
			document.selection.createRange().text = emote;
		}else {
			var startPos = $("txtChat").selectionStart;
			var endPos = $("txtChat").selectionEnd;
			$("txtChat").value = $("txtChat").value.substring(0, startPos) + emote + $("txtChat").value.substring(endPos, $("txtChat").value.length);
			startPos += emote.length;
			$("txtChat").setSelectionRange(startPos, startPos);
		}
		return false
	}
}