if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(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 _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,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");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  {
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    {
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire +";path=/;domain=.youban.com";
}
//writeCookie("pop_welcome_close",1,720)
//writeCookie("pop_is_close",1,720)
var LOG = {
	isDebug:false,
	alert:function(str)
	{
		if(this.isDebug)
		{  
			var div = $("__debug__");
			if(div == null)					 
			{
				div = document.createElement("div");
				div.style.border= "1px solid #FF0000";
				div.style.height = "250px";
				div.style.width = "400px";
				div.style.overflow = "auto";
				div.setAttribute("id" ,"__debug__");
				document.body.appendChild(div);
			}
			var cDiv = document.createElement("div");
			cDiv.style.borderTop = "1px solid #0099cc";
			cDiv.innerHTML = str;
			div.appendChild(cDiv);
		}
	}
};
var Edit = {
	editWindow : null,	//
	editDocument : null,//
	editId : null,//
	loadtime : 0,//是否在有限的时间内完成加载
	isInitOk : false,//是否初始化成功
	isCanEdit : false,//菜单是否可用的开关
	selectEdit : null,
	openDiv : null,	 //打开的弹出式div对象
	selectElement : null, //被选择的对象
	//daley:bak:maxLebgth : 15000, //文字的最大长度
	maxLebgth : 65535, //文字的最大长度
	forms : null, //填入的对应的表单
	yctFace : {bg:"http://www.youban.com/images/act/bq-list.gif",width : 40 , height : 40 , bgWidth : 360 ,bgHeight : 160},  //洋葱头的背景
	bg : "/edit/button.gif",
	options : {},//
	baseBar : [{cmd:"fontname",title:"字体",is_select:1,
						options:{"字体":"",
								"宋体":"宋体",
								"黑体":"黑体",
								"楷体":"楷体_GB2312",
								"仿宋":"仿宋_GB2312",
								"隶书":"隶书",
								"幼圆":"幼圆",
								"Arial":"Arial",
								"System":"System",
								"Courier":"Courier"},bg:"/images/other/select-bg1.gif",mouseover:"/images/other/select-bg2.gif",width:92},
				{cmd:"fontsize",title:"字号",is_select:1,options:{"字号":"",
								"一号" : "1",
								"二号" : "2",
								"三号" : "3",
								"四号" : "4",
								"五号" : "5",
								"六号" : "6",
								"七号" : "7"},bg:"/images/other/select-bg3.gif",mouseover:"/images/other/select-bg4.gif",width:57},
				{cmd:"font_color",title:"字体颜色",bg: {width:25,height:21,top:504 ,left:134}},
				{isSpance:true},
				{cmd:"Bold",title:"加粗",bg: {width:25,height:21,top:504 ,left:10}} ,
				{cmd:"Italic",title:"斜体",bg: {width:25,height:21,top:504 ,left:50}},
				{cmd:"Underline",title:"下划线",bg: {width:25,height:21,top:504 ,left:93}},
				{isSpance:true},
				{cmd:"JustifyLeft",title:"左对齐",bg: {width:22,height:20,top:0 ,left:0,url:"/images/other/icon15.gif"}},
				{cmd:"JustifyCenter",title:"居中",bg: {width:25,height:21,top:504 ,left:262}} ,
				{cmd:"JustifyRight",title:"右对齐",bg: {width:25,height:21,top:504 ,left:304}},	 				
				{isSpance:true},
				{adminbar:true}, //高级功能呢个站位
				{cmd:"Undo",title:"撤销",bg: {width:23,height:21,top:0 ,left:0,url:"/images/other/icon16.gif"}},
				{cmd:"Redo",title:"重做",bg: {width:23,height:21,top:0 ,left:0,url:"/images/other/icon17.gif"}}],
	adminBar : [{cmd:"face",title:"添加表情",bg: {width:25,height:21,top:504 ,left:175}} ,
				{cmd:"ycongtou",title:"添加洋葱头表情",bg: {width:22,height:20,top:0 ,left:0,url:"/images/other/icon14.gif"}},
				{cmd:"img",title:"添加图片",bg: {width:25,height:21,top:504 ,left:219}},
				{cmd:"flash",title:"添加视频",bg: {width:25,height:21,top:504 ,left:344}},					
				{cmd:"createlink",title:"添加链接",bg: {width:25,height:21,top:325 ,left:1,url:"/images/diary/icon.gif"}},
				{isSpance:true}],
	setAttribute : function(ele,k,v, isStyle)
	{
		if(typeof ele != "undefine" && ele.tagName != "")
		{ 			
			return false;
		}
		if(isStyle)
		{
			ele.style[k] = v;
		} else
		{
			if(Prototype.Browser.IE)
			{
				ele.prototype[k] = v;
			}else
			{	
				ele.setAttribute(k,v);
			}

		}
	},
	/**
	*	初始化工具栏
	**/
	initBar :function()
	{
		if(this.options.baseToolBar === true || this.options.adminToolBar === true)
		{
			var baseT = document.createElement("table");   					
			var baseTb= document.createElement("tbody");
			var baseTr= document.createElement("tr");
			if(this.options.baseToolBar || this.options.adminToolBar)
			{  	
				for(var i = 0 ; i < this.baseBar.length; i++)
				{
					var o = this.baseBar[i];
					if(o.adminbar)
					{	  
						if(this.options.adminToolBar)
						{
							//高级菜单
							for(var j = 0 ; j < this.adminBar.length; j++)
							{
								var oa = this.adminBar[j];
								if(this.options.adminBar[oa.cmd] === false)
								{
									continue;
								}
								var td = document.createElement("td");
								td.style.padding = "0px 2px";
								var a = document.createElement("a");   					
								this.setAttribute(a,"text-decoration","none",1);
								if(oa.bg)
								{
									a.style.width = oa.bg.width + "px";
									a.style.position = "relative";
									a.style.height = oa.bg.height + "px";
									a.style.display = "block";
									a.title = oa.title;
									a.href = "javascript:void(0);";
									if(oa.bg.url)
									{
										a.style.background = "url(" + oa.bg.url + ") -" + oa.bg.left + "px -" + oa.bg.top + "px"; 
									}else
									{
										a.style.background = "url(" + this.bg + ") -" + oa.bg.left + "px -" + oa.bg.top + "px"; 
									}
									a.setAttribute("cmd",oa.cmd);
									Event.observe(a,"click",function(e){Edit.cmd(e,Event.element(e).getAttribute("cmd"));},true);
								} else
								{	//这是一个分隔符
									if(this.options.baseToolBar === false)
									{
										continue;
									}
									a.innerHTML = "|";
								} 
								td.appendChild(a);
								baseTr.appendChild(td);
							}
							continue; 						}
					}
					if(this.options.baseToolBar === false)
					{
						continue;
					}
					var td = document.createElement("td");
					td.style.padding = "0px 2px";
					if(o.is_select)
					{
						var select = document.createElement("select");
						select.setAttribute("cmd",o.cmd) ;
						select.setAttribute("name",o.cmd) ;
						select.setAttribute("id",o.cmd) ;
						select.setAttribute("bg",o.bg) ;
						select.setAttribute("mouseover",o.mouseover) ;
						select.style.background = "url(" + o.bg +")";
						Event.observe(select,"mouseover",function(ev){Event.element(ev).style.background = "url(" + Event.element(ev).getAttribute("mouseover") + ")";});
						Event.observe(select,"mouseout",function(ev){Event.element(ev).style.background = "url(" + Event.element(ev).getAttribute("bg") + ")";});
						for(var key in o.options)
						{
							var op = new Option(key,o.options[key],false,false);
							op.innerHTML = key;
							select.appendChild(op);
						}
						Event.observe(select,"click",function(event){  							
							Event.observe(Event.element(event),"change",function(event)
							{
								var selected = Event.element(event);
								var value = selected.options[selected.selectedIndex].value;
								Edit.cmd(event,selected.getAttribute("cmd"),value);
								selected.options[0].selected = true;
								
							});
							Event.stop(event);
						});
						
						td.appendChild(select);
					}else
					{  //有图标的命令
						var a = document.createElement("a");   					
						this.setAttribute(a,"text-decoration","none",1);
						if(o.title)
						{
							a.href = "javascript:void(0);"	 ;
							a.title =  o.title;
							a.style.textDecoration = "none";
							a.style.position = "relative";
							if(o.bg)
							{
								a.style.width = o.bg.width + "px";
								a.style.height = o.bg.height + "px";
								a.style.display = "block";
								if(o.bg.url)
								{
									a.style.background = "url(" + o.bg.url + ") -" + o.bg.left + "px -" + o.bg.top + "px"; 
								}else
								{
									a.style.background = "url(" + this.bg + ") -" + o.bg.left + "px -" + o.bg.top + "px"; 
								}
							//	a.style.background = "url(" + this.bg + ") -" + o.bg.left + "px -" + o.bg.top + "px"; 
							} else
							{	//这是一个分隔符
								a.innerHTML = o.title;
							}  							
							a.setAttribute("cmd",o.cmd);
							Event.observe(a,"click",function(e){Edit.cmd(e,Event.element(e).getAttribute("cmd"));});
						}else
						{
							a.innerHTML = "|";
						}
						td.appendChild(a);
					}
					baseTr.appendChild(td);
				}
				baseTb.appendChild(baseTr);
				baseT.appendChild(baseTb); 				
			} 
			
			return baseT;
		}else
		{
			return false;
		}
	},
	/**
	*  初始化状态栏
	**/
	initStatus:function()
	{
		var button = document.createElement("div");
		button.innerHTML = "查看一旦代码";
		Event.observe(button,"click",function(e)
			{	 				
				var text = $(Edit.editId);
				if(text)
				{
					if(text.style.display == "none")
					{
						text.style.display = "block";
						text.value = UBB.html_ubb(Edit.editDocument.body.innerHTML);
						$(Edit.editId + "_doc_").style.display = "none";
					}else
					{
						text.style.display = "none";
						Edit.editDocument.body.innerHTML = UBB.ubb_html(text.value);
						$(Edit.editId + "_doc_").style.display = "block";
					}
				}
			});
			return button;
	},
	isCanEdit : false,//是否处于可以编辑的状态
	/**
	*	初始化编辑器的鼠标与键盘是件
	**/
	setOptions : function (op2)
	{	
		this.options.keyup = (op2.keyup && typeof op2.keyup == "function")? (op2.keyup) :(function(e){});
		this.options.keypress = (op2.keypress && typeof op2.keypress == "function")? (op2.keypress) :(function(e){});
		this.options.keydown = (op2.keydown && typeof op2.keydown == "function")? (op2.keydown) :(function(e){});
		this.options.mouseover = (op2.mouseover && typeof op2.mouseover == "function")? (op2.mouseover) :(function(e){});
		this.options.mouseout = (op2.mouseout && typeof op2.mouseout == "function")? (op2.mouseout) :(function(e){});
		this.options.mousemove = (op2.mousemove && typeof op2.mousemove == "function")? (op2.mousemove) :(function(e){});
		this.options.width = (parseInt(op2.width) > 0) ? (parseInt(op2.width)) : (500);
		this.options.height = (parseInt(op2.height) > 0) ? (parseInt(op2.height)) : (500);
		this.options.baseToolBar = (op2.baseToolBar === false) ? (false) : (true);
		this.options.adminToolBar = (op2.adminBar === false) ? (false) : (true);
		this.options.viewUBB = (op2.viewUBB === true) ? (true) : (false);
		this.options.submit = (op2.submit && typeof op2.submit == "function")? (op2.submit) :(function(e){return true});
		this.forms = (op2.form) ? op2.form : null;
		this.options.adminBar = {};
		this.options.adminBar["createlink"] = (op2.Link === false) ? (false) : (true);
		this.options.adminBar["face"] = (op2.QQface === false) ? (false) : (true);
		this.options.adminBar["img"] = (op2.Img === false) ? (false) : (true);
		this.options.adminBar["flash"] = (op2.Flash === false) ? (false) : (true);
		this.options.adminBar["ycongtou"] = (op2.yct === false) ? (false) : (true);	  		
	},
	/**
	*  页面初始化的时候调用
	**/
	init : function(id,options)
	{
		this.editId = id;
		this.loadtime = 0;
		this.isInitOk = false;
		this.setOptions(options);
		if(typeof(editorCls)=='undefined'){//daley:原编辑器
			var table = this.createTable();
			$(this.editId).style.display = "none";
			$(this.editId).parentNode.appendChild(table);
			var iframe = this.createEdit(table);		 
			var header = this.initBar();
			if(header !== false)
			{
				table.setHeader(header);
			}
			if(this.options.viewUBB)
			{
			 table.setFoot(this.initStatus());
			}
			 $(this.editId).style.width = "100%";
			  $(this.editId).style.height = "100%";
			 table.setBody($(this.editId));
		}
		else{//Ctrl+Enter快速发布
			//alert(DE_EC);
			document.onkeydown=ctrlEnterSubmit;
		}
	},
	/**
	*	初始化编辑器
	**/
	createEdit : function(table)
	{
		var div = document.createElement("div");
		var iframe = document.createElement("iframe");
		iframe.id = this.id + "__edit";
		iframe.style.zIndex = -1;
		var config = {
                border: '0',
                frameBorder: '0',
                marginWidth: '0',
                marginHeight: '0',
                leftMargin: '0',
                topMargin: '0',
                allowTransparency: 'true',
                width: '100%'
            };
		for(var i in config) 
		{
            iframe.setAttribute(i, config[i]);
        }
		var isrc = 'javascript:;';
		if (Prototype.Browser.IE) 
		{
			isrc = 'about:blank';
			iframe.id = this.editId + "_doc_";
		}
		//iframe.style.border = "#cccccc 1px solid";
		iframe.setAttribute("id",this.editId + "_doc_");
		iframe.setAttribute('src', isrc);
		iframe.setAttribute("width","100%");
		iframe.setAttribute("height","100%");	
		table.setBody(iframe);
		this.editWindow = iframe.contentWindow;
		this.editDocument = iframe.contentWindow.document;
		
		var self = this;
		window.setTimeout(function(){self.initContent.call(self);},20);
	},
	/**
	*	编辑器获得焦点
	**/
	editFocus : function()
	{		
		if(document.hasFocus())
		{
			Edit.editWindow.focus();
			return true;
		}else
		{				
			return true;
		}
	},
	getRange:function()
	{
		var range = null;
		if(this.editWindow || this.editDocument)
		{
			if(this.editDocument.selection)
			{
				range = Edit.editDocument.selection;
			}else
			{
				range = Edit.editWindow.getSelection();
			}
		}
		return range;
	},
	getTextRange : function()
	{
		var select = null;
		if(this.getRange())
		{
			if(Prototype.Browser.IE)
			{
				select = this.getRange().createRange();
				/*select.execCommand = function(cmd,obj,value)
					{
						if(Edit.editWindow.selectElement)
						{
							Edit.editWindow.selectElement.execCommand(cmd,obj,value);
						}
					} ;
				select.pasteHTML = function(tem)
					{
						if(Edit.editWindow.selectElement)
						{
							Edit.editWindow.selectElement.pasteHTML(tem);
						}
					};	*/
			}else
			{
				select = this.getRange().getRangeAt(0);
				select.execCommand = function(cmd,obj,value)
					{
						if(select)
						{
							Edit.editDocument.execCommand(cmd,obj,value);
						}
					}  
			}
			return select ;
		}else
		{
			return null;
		}
	} ,
	checkedComplite : function()
	{
		var self = this;
		if(this.loadtime > 10)
		{
			return false;
		}else
		{
			if(this.isInitOk)
			{
			}else
			{
				if(Prototype.Browser.IE)
				{
					if(this.editDocument.body && this.editDocument.body.readyState == 'complete')
					{
						this.isInitOk = true;
					}
				}else
				{
					this.isInitOk = true;
				}
				if(this.isInitOk)
				{
					if(this.editDocument.designMode.toLowerCase() != 'on')
					{
					}else
					{

						Event.observe(self.editDocument,"keyup",function(e){Edit.options.keyup(e)});
						Event.observe(self.editDocument,"keypress",function(e,self)
							{
								Edit.options.keypress(e);
								if(Prototype.Browser.Gecko)
								{
									if(e.keyCode == 13 && !(e.ctrlKey || e.shiftKey || e.altKey))
									{
										var rs = Edit.getTextRange();
										if(rs != null)
										{
											 Edit.editDocument.execCommand("inserthtml",false,"<p></P>");
											 e.stopPropagation();
											 e.preventDefault();
											//rs.pasteHTML("<BR/>");
											//rs.select();
										}
										return false;
									}
								}
							});
						Event.observe(self.editDocument,"keydown",function(e,self){Edit.options.keydown(e);});
						Event.observe(self.editDocument,"mouseover",function(e){Edit.options.mouseover(e)});
						Event.observe(self.editDocument,"mouseout",function(e){Edit.options.mouseout(e)});
						Event.observe(self.editDocument,"mousemove",function(e){Edit.options.mousemove(e)});
						Event.observe(self.editDocument,"mousedown",function(e)
								{
										Edit.closeDIV();
								});						
						Event.observe(self.editWindow,"focus" , function(){this.isCanEdit = true;});
						Event.observe(self.editWindow,"blur" , function(){this.isCanEdit = false;});
						Event.observe(window,"beforeunload",function(e)
						{
							if(Prototype.Browser.IE && Edit.editDocument.body.innerText != "" && false)
							{
								var   n   =   window.event.screenX   -   window.screenLeft;   
								var   b   =   n   >   document.documentElement.scrollWidth-20;   
								if(b   &&   window.event.clientY   <   0   ||   window.event.altKey)   
								{
									window.event.returnValue   =   "您编辑的内容未保存，点“确定”你将丢失你所编辑的内容。";     //这里可以放置你想做的操作代码   
								}else{
									window.event.returnValue   =   "您编辑的内容未保存，点“确定”你将丢失你所编辑的内容。";
								}
							}
						});
						this.editDocument.body.innerHTML = UBB.ubb_html($(this.editId).value);
						this.disMenu = false;
						//this.editWindow.focus();
					}
				}else
				{
					setTimeout(function() {
                    self.checkedComplite.call(self);
					}, 200);
				}
			}
		}
	},
	
	initContent : function()
	{
		var html = {};
		var css = '<link href="/styles/edit-n.css" rel="stylesheet" type="text/css" />';
		if(Prototype.Browser.WebKit)
		{
			var doc = this.editDocument.implementation.createHTMLDocument();
			var origDoc = this.editDocument;
			origDoc.open();
			origDoc.close();
			doc.open();
			doc.write(html);
			doc.write(css);
			doc.close();
			var node = origDoc.importNode(doc.getElementsByTagName("html")[0], true);
			origDoc.replaceChild(node, origDoc.getElementsByTagName("html")[0]);
			origDoc.body._rteLoaded = true;
		}else
		{
			this.editDocument.open();
			if(Prototype.Browser.Gecko)
			{
				this.editDocument.write(html);
			}						
			this.editDocument.write(css);
			this.editDocument.close();
		}
		this.editDocument.designMode = 'on';
		this.checkedComplite();
	}, 	
	/**
	*	创建编辑器的架构部分
	**/
	createTable : function()
	{
		var table = document.createElement("table");
		table.style.border = "1px solid #CCCCCC";
		if(Prototype.Browser.IE)
		{
			table.style.width = this.options.width + "px";
			table.style.height = this.options.height + "px";
		}else
		{
			table.setAttribute("width",this.options.width + "px");
			table.setAttribute("height",this.options.height + "px");
		}
		var tbody = document.createElement("tbody");
		var header = document.createElement("tr");
		var body = document.createElement("tr");
		var foot = document.createElement("tr");
		var tdH = document.createElement("td");
		var tdB = document.createElement("td");
		var tdF = document.createElement("td");
		tdB.style.border = "#cccccc 1px solid";
		tdH.style.backgroundColor = "#F7F5F4";	
		tdH.style.border = "#cccccc 1px solid";
		tdH.style.height = "28px";
		tdH.align = "left";
		header.appendChild(tdH);
		body.appendChild(tdB);
		foot.appendChild(tdF);
		tbody.appendChild(header);
		tbody.appendChild(body);
		tbody.appendChild(foot);
		table.appendChild(tbody);
		table.setBody = function(obj)
			{
				tdB.height = Edit.options.height +"px";
				tdB.appendChild(obj);
			};
		table.setHeader = function(obj)
			{
				tdH.appendChild(obj);
			};
		table.setFoot = function(obj)
			{
				tdF.appendChild(obj);
			};
		return table;
	},
	/**
	*  提交表单
	**/
	submit : function(id)
	{
		if(this.data() && typeof(this.forms)!= "undefined" && this.forms !== null && typeof(this.forms.tagName)!= "undefined" && this.forms.tagName.toLowerCase() == "form")
		{
			if(id)
			{
				if($(id).value.length < 1)
				{
					alert("请输入标题");
					return false;
				}
			}
                        var currtime = parseInt( new Date().getTime()/1000 );
			writeCookie("denycmts",currtime , 1);
/*
                        var cookietime = readCookie('denycmts');
                        //alert(cookietime+"|"+currtime)
                        var timeslong = currtime - cookietime ;
                        if(timeslong < 5 ) { 	
					alert('你发帖太快了，去边上喝杯茶吧'); return false; 
				} else {
					writeCookie("denycmts",currtime , 1);
				}
*/
//alert(this.options);alert(this.forms.id);
			/*if(this.options.submit())
			{return false;*/
				this.forms.submit();
			//}
		}
	},
	cmd : function(ev,cmd,value)
	{	
		Edit.closeDIV();
		Edit.editFocus();
		var selection = this.getTextRange();
		if(selection != null && (Prototype.Browser.IE ? Edit.editDocument.hasFocus() : true))
		{
			Edit.editWindow.selectElement =  selection;
			switch (cmd)
			{
				case "fontsize":
					if(value)
					{
						if(value == "")
						{
							break;
						}
						if(Prototype.Browser.IE)
						{
							Edit.editWindow.selectElement.execCommand(cmd,null,value);
						}else
						{	
							 this.editDocument.execCommand(cmd,false,value);
						}
					}
					break;
				case "fontname":
					if(value)
					{
						if(value == "")
						{
							break;
						}
						if(Prototype.Browser.IE)
						{
							Edit.editWindow.selectElement.execCommand(cmd,null,value);
						}else
						{	
							 this.editDocument.execCommand(cmd,false,value);
						}
					}
					break;
				case "font_color":
					this.show_font_color(ev);
					break;
				case "createlink":
					if(Prototype.Browser.IE)
					{
						Edit.editWindow.selectElement.execCommand(cmd);	
					}else
					{
						 var szURL = prompt("请输入链接的地址:", "http://");
						 if ((szURL != null) && (szURL != "")) 
						{
							 this.editDocument.execCommand(cmd,false,szURL);
						}
					}
					break;
				case "img":
					this.insertIMG(ev);
					break;
				case "ycongtou":
					this.show_yangcongtou(ev);
					break;
				case "flash":
					this.insertFlash(ev);
					break;
				case "face":
					this.insert_QQ_face(ev);
					break;
				case "view":
					this.per_view();
					break;
				default :
					this.editDocument.execCommand(cmd,false,null);
					this.editFocus();
					break;
			} 			
		}
		this.editFocus();
		//Edit.editWindow.selectElement = null;
	},
	/**
	*  字体颜色设置的弹出
	**/
	show_font_color :function(e)
	{
		var op = {};
		if(Prototype.Browser.IE)
		{
			op.width = 193;
			op.height = 120;
		}else
		{
			op.width = 193;
			op.height = 120;
		}
		var div = this.createDiv(e,op);
		
		var corlor = ["000000","990000","ff6600","003300","006666","000099","9900ff","990066","666666","cc0000","ff9900","006600","00cccc","0000FF","cc00ff","cc0066","999999","ff0000","ffcc00","009900","00ccff","0066ff","9966ff","ff0099","cccccc","ff6666","ffff00","00cc00","33cccc","0099ff","cc66ff","ff00ff","ffffff","ff9999","ffff99","00ff00","00ffff","00ccff","ccccff","ff99ff"];
		for(var i = 0 ; i < corlor.length ; i++)
		{
			var a = document.createElement("a");				
			a.href = "javascript:;"	 ;
			a.style.textDecoration = "none";
			a.style.backgroundColor = "#" + corlor[i];
			a.setAttribute("cmd_color",corlor[i]);
			a.style.display = "block";
			a.style.width = "20px";
			a.style.height = "20px";
			a.style.styleFloat = "left";
			a.style.cssFloat = "left";
			a.style.border = "1px solid #cccccc";
			a.style.padding = "1px";
			Event.observe(a,"click",function(e)
				{
					Event.element(e).parentNode.parentNode.removeChild(Event.element(e).parentNode);
					Edit.editWindow.selectElement.execCommand("ForeColor",false,Event.element(e).getAttribute("cmd_color"));
					Edit.editFocus();
			});
			div.appendChild(a);
		}
		div.show();
	},
	/**
	*  打开表情窗口
	**/
	show_face : function(event)
	{
	},
	/**
	*  加载洋葱头的表情
	**/
	show_yangcongtou : function(event)
	{
		var div = null;			
		div = this.createDiv(event,{width : 380,height : 170});
		
		var face = [{fileName:"bgl",title:"不干了"},
					{fileName:"dk",title:"大哭"},
					{fileName:"dm",title:"倒霉"},
					{fileName:"dx",title:"大侠"},
					{fileName:"dzh",title:"打招呼"},
					{fileName:"gd",title:"孤单"},
					{fileName:"h",title:"寒"},
					{fileName:"han",title:"汗"},
					{fileName:"hc",title:"花痴"},
					{fileName:"huaix",title:"坏笑"},
					{fileName:"hx",title:"害羞"},
					{fileName:"ka",title:"可爱"},
					{fileName:"kbz",title:"抠鼻子"},
					{fileName:"kf",title:"咖啡"},
					{fileName:"ku",title:"哭"},
					{fileName:"kun",title:"困"},
					{fileName:"kx",title:"狂笑"},
					{fileName:"lg",title:"路过"},
					{fileName:"ng",title:"难过"},
					{fileName:"nu",title:"怒"},
					{fileName:"pg",title:"飘落"},
					{fileName:"qdl",title:"糗大了"},
					{fileName:"rc",title:"认错"},
					{fileName:"ti",title:"踢"},
					{fileName:"tu",title:"吐"},
					{fileName:"tx",title:"挑衅"},
					{fileName:"wa",title:"晚安"},
					{fileName:"wg",title:"无辜"},
					{fileName:"wx",title:"微笑"},
					{fileName:"wy",title:"无语"},
					{fileName:"yun",title:"晕"},
					{fileName:"yw",title:"疑问"},
					{fileName:"yy",title:"愉悦"},
					{fileName:"yydy",title:"洋洋得意"},
					{fileName:"zj",title:"再见"},
					{fileName:"zy",title:"质疑"}];
		for(var i = 0 ; i < face.length ; i++)
		{
			var o = face[i];
			var a = document.createElement("a");
			a.style.textDecoration = "none";
			this.setAttribute(a,"text-decoration","none",1);
			a.href = "javascript:void(0);";
			a.setAttribute("href","javascript:void(0);");
			a.title = o.title;
			a.setAttribute("file",o.fileName);
			a.style.display = "block";
			a.style.width = this.yctFace.width + "px";
			a.style.height = this.yctFace.width + "px";
			a.style.border = "1px solid #FFFFFF";  			
			if(Prototype.Browser.IE)
			{
				a.style.styleFloat = "left";
			}else
			{
				if(Prototype.Browser.Gecko)
				{
					a.style.cssFloat = "left";
				} else
				{
					a.style.float = "left";
				}
			}
			a.style.background = "url(" + this.yctFace.bg + ") -" + (this.yctFace.width * (i % 9)) + "px -" + (this.yctFace.height * Math.floor(i/9)) + "px";			
			Event.observe(a,"mouseout",function(ev)
				{
					var a = Event.element(ev);
					a.style.border = "1px solid #FFFFFF";
					var imgs = a.parentNode.getElementsByTagName("img"); 					
					for(var i= 0  ; i < imgs.length ; i++)
					{
						a.parentNode.removeChild(imgs[i]);
					}
				});
			Event.observe(a,"mouseover",function(ev)
				{
					var bg = Event.element(ev);
					bg.style.border = "1px solid #0099cc";
					var img = document.createElement("img");
					img.setAttribute("src","http://www.youban.com/images/bq/" + bg.getAttribute("file") + ".gif");
					img.style.border = "2px solid #A7C8FF";
					img.style.position = "absolute";
					img.style.top = "0px";
					
					if(Prototype.Browser.Gecko)
					{		  						
						if((ev.layerY - Edit.yctFace.width*2) < 1)
						{
							 // alert(ev.layerY) ;
							if((ev.layerX - Edit.yctFace.width * 2) <  1)
							{
								// alert(ev.layerX - Edit.yctFace.width * 2) ;
								img.style.right = "0px";
							}else
							{
								img.style.left = "0px";
							}
						}else
						{
							img.style.left = "0px";
						}
					}else
					{
						if(Prototype.Browser.IE)
						{
							var x = Event.pointerX(ev);
							var y = Event.pointerY(ev);
							var pLeft = parseInt(bg.parentNode.offsetLeft);
							var pTop = parseInt(bg.parentNode.offsetTop);
							if((y - pTop - Edit.yctFace.width * 2) < 0)
							{
								if((x - pLeft - Edit.yctFace.width * 2) < 0)
								{
									img.style.right = "0px";
								}else
								{
									img.style.left = "0px";
								}
							}else
							{
								img.style.left = "0px";
							}
						}
					}
					bg.parentNode.appendChild(img);									
				});
			Event.observe(a,"click",function(ev)
				{
					var a = Event.element(ev);					
					var file = a.getAttribute("file");
					if((Prototype.Browser.IE ? Edit.editDocument.hasFocus() : true))
					{
					}else
					{
						Edit.editFocus();
					}
					Edit.editWindow.selectElement.execCommand("InsertImage",false,"http://www.youban.com/images/bq/" + file + ".gif");
					Edit.closeDIV();
				});
			div.appendChild(a);
		}
		var t = document.createElement("a");
		t.style.clear  = "both";
		div.appendChild(t);
		div.show();
	},
	/**
	*	插入flash
	**/
	insertFlash : function(event)
	{
		var div = Edit.createDiv(event,{width : 400 ,height :395});
		var divB =  document.createElement("div");
		var table = document.createElement("table");
		var tbody = document.createElement("tbody");
		var trhea = document.createElement("tr");
		var trInf = document.createElement("tr");
		var trUrl = document.createElement("tr");
		var trPre = document.createElement("tr");
		var trBut = document.createElement("tr");

		var tdhea   = document.createElement("td");
		var tdhinf  = document.createElement("td");
		var tdUrl   = document.createElement("td");
		var tdPre   = document.createElement("td");
		var tdBut   = document.createElement("td");

		var OK =  document.createElement("button");
		var CAL =  document.createElement("button");
		var perView = document.createElement("button");

		divB.setAttribute("id","__pre_flash__div");
		divB.style.width = "98%";
		divB.style.height = "100%";
		divB.style.border = "1px solid #396ac9"	;
		perView.innerHTML = "预览";
		tdPre.style.padding = "8px";
		//tdUrl.style.border = "1px solid #396ac9";
		//tdUrl.style.padding = "3px";

		//perView.style.border = "1px sloid #396ac9";
		perView.style.backgroundColor = "#396ac9";
		perView.style.width = "50px";
		perView.style.marginLeft = "10px";
		perView.style.color = "#FFFFFF";

		OK.innerHTML = "确定";
		CAL.innerHTML = "取消";		
		OK.className = "button2";		
		CAL.className = "button2";
		 table.style.width = "100%";
		 table.style.padding = "2px";
		 tdhea.style.height = "30px"; 		
		 tdhinf.style.height = "25px";
		 tdUrl.style.height = "30px";
		 tdPre.style.height = "260px";
		 tdBut.style.height = "30";
		 tdhea.style.backgroundColor = "#EFF6FF";
		 tdhea.innerHTML = "<b>&nbsp;请输入你要插入的FLASH地址： </b>";
		 tdhinf.innerHTML = '&nbsp;输入flash的地址，如http://youban.com/abc.swf';
		 tdUrl.innerHTML = '&nbsp;FALSH地址：<input type="text" size="38" id="__flash_url__" value="http://">';
		
		 
		 tdUrl.appendChild(perView);
		 Event.observe(perView,"click",function(ev){
				var url = $("__flash_url__");					
				if(/http:\/\/(.*)(\..*)+\/.*/ig.test(url.value))
				{	
					var so = new SWFObject(url.value, "__flash_id", "100%", "100%", "9", "#FFFFFF");
					so.addParam('wmode','transparent');
					so.addParam('menu','false');							
					so.write("__pre_flash__div"); 		
				}else
				{
					alert("请输入正确的flash地址");
				}
			});
		
		 
		Event.observe(OK,"click",function(ev)
			{
				var img = document.createElement("img");
				img.src = "/images/other/flash.gif";  				
				img.title="src:" + $("__flash_url__").value; 				
				img.style.border = "1px solid #FF0000";
				img.style.backgroundColor = "#FFFFcc";
				img.style.width = "550px";
				img.style.height = "400px";
				img.style.backgroundImage = "url(flash.gif)";
				img.style.backgroundPositionX = "center";
				img.style.backgroundPositionY = "50%";
				img.style.backgroundRepeat = "no-repeat";
				Edit.editFocus();
				if(Edit.editWindow.selectElement == null)
				{
					Edit.editWindow.selectElement = Edit.editDocument.body;
				}
				if(Prototype.Browser.Gecko)
				{						
					Edit.editWindow.selectElement.insertNode(img);
				}else
				{
					if(Prototype.Browser.IE)
					{	
						Edit.editWindow.selectElement.pasteHTML(img.outerHTML);
					}
				}
				var o = Event.element(ev);
				while(o.parentNode.tagName.toLowerCase() != "div")
				{
					o = o.parentNode;
				}
				Edit.closeDIV();
			});
		Event.observe(CAL,"click",function(ev){Edit.closeDIV();});
		tdBut.appendChild(OK);
		tdBut.appendChild(CAL);

		trhea.appendChild(tdhea);
		trInf.appendChild(tdhinf);
		trUrl.appendChild(tdUrl);
		trBut.appendChild(tdBut);
		tdPre.appendChild(divB); 		
		trPre.appendChild(tdPre);
		tbody.appendChild(trhea);
		tbody.appendChild(trInf);
		tbody.appendChild(trUrl); 	
		tbody.appendChild(trPre);
		tbody.appendChild(trBut);
		table.appendChild(tbody);  		
		div.setBody(table);
		div.show();
	},
	/**
	*  插入qq表情
	**/
	insert_QQ_face : function(event)
	{
		var QQ_face = this.createDiv(event,{width : 312,height:286});
		var title=["","撇嘴","色","发呆","得意","流泪","害羞","闭嘴","睡","大哭","尴尬","发怒","调皮","呲牙","惊讶","难过","酷","冷汗","抓狂","吐","偷笑","可爱","白眼","傲慢","饥饿","困","惊恐","流汗","憨笑","大兵","奋斗","咒骂","质疑","嘘","晕","折磨","哀","骷髅","敲打","再见","擦汗","抠鼻","鼓掌","糗大了","坏笑","左哼哼","右哼哼","哈欠","鄙视","委屈","快哭了","阴险","亲亲","吓","可怜","菜刀","西瓜","啤酒","篮球","乒乓","咖啡","饭","猪头","玫瑰","凋谢","示爱","爱心","心碎","蛋糕","闪电","炸弹","刀","足球","瓢虫","便便","月亮","太阳","礼物","拥抱","强","弱","握手","胜利","保全","勾引","拳头","差劲","爱你","NO","OK","爱情","飞吻","跳跳","发抖","怄火","转圈","磕头","回头","跳绳","回收","激动","街舞","献吻","左太极","右太极","","","","","","","","","","","","","","","","","","","","","","","",""];
		for(var i = 1 ; i <= 132 ; i++)
		{
			var img = document.createElement("img");
			img.style.border = "1px solid #FFFFFF";
			img.style.width = "24px";
			img.style.margin = "0px";
			img.style.height = "24px";
			//img.style.margin = "1px";
			img.style.cursor = "pointer";
			img.title= title[i];
			img.setAttribute("src" ,"/images/Face2/" + i + ".gif");
			QQ_face.appendChild(img);
			Event.observe(img,"mouseover",function(ev)
				{
					var img = Event.element(ev);
					img.style.border = "1px solid #71C3F2";
				});
			Event.observe(img,"mouseout",function(ev)
				{
					var img = Event.element(ev);
					img.style.border = "1px solid #FFFFFF";
				});
			Event.observe(img,"click",function(ev)
				{
					var img = Event.element(ev); 
					if((Prototype.Browser.IE ? Edit.editDocument.hasFocus() : true))
					{
					}else
					{
						Edit.editFocus();
					}
					Edit.editWindow.selectElement.execCommand("InsertImage",false,img.getAttribute("src"));
					Edit.closeDIV();
					Edit.editFocus(); 	
				});
		}
		QQ_face.style.backgroundColor = "#EEF7FF" ;
		QQ_face.show();
	},
	/**
	*  插入图片和获取图片
	**/
	insertIMG : function(event)
	{  		
		var div = this.createDiv(event,{width:400,height:404});
		new Ajax.Request("/edit/getIMG.php?cmd=pb",{
			onSuccess: function(rs)
				{
					
					var pbSel = document.createElement("select");	
					pbSel.style.width = "150px";
					eval("var obj = " + rs.responseText);  					
					if(obj)
					{
						if(obj.err)
						{
							//alert(obj.msg);
						}else
						{
							for(var i = 0 ; i < obj.length ; i++)
							{									
								var op = new Option(obj[i].pbname,obj[i].pbid,false,false);
								op.innerHTML = obj[i].pbname;
								pbSel.appendChild(op);
							}
							Event.observe(pbSel,"change",function(ev)
								{
									var sel = Event.element(ev);
									var pbid = sel.options[sel.selectedIndex].value;
									Edit.getIMGs(pbid,1);
								});
							
							var subdiv = document.createElement("div");
							subdiv.style.overflowY = "auto";
							subdiv.style.height = "280px";	
							subdiv.style.border = "1px solid #A7C8FF";
							subdiv.style.padding = "1px";
							subdiv.style.marginTop = "8px";
							subdiv.setAttribute("id","__inser__img__div");
							var bottom =  document.createElement("div");
							var queren = document.createElement("div");
							var page = document.createElement("div");
							queren.style.styleFloat = "left";
							queren.style.widht = "150px";
							bottom.style.padding = "8px";
							page.style.styleFloat = "right";
							page.style.width = "150px";
							page.setAttribute("id","__inser__img__div_page");							
							var flash = document.createElement("div");
							flash.style.clear = "both";
							flash.setAttribute("id","__insert_img_by_flash__");  
							flash.style.borderBottom = "1px solid #A7C8FF";
							flash.style.marginBottom = "10px";
							var OK =  document.createElement("button");
							var CAL = document.createElement("button");
							OK.style.height = "23px";
							OK.style.width = "60px";
							OK.style.marginLeft = "10px";
							OK.style.color ="#ffffff";
							OK.style.backgroundColor = "#396ac9";
							CAL.style.height = "23px";
							CAL.style.width = "60px";
							CAL.style.marginLeft = "10px";
							CAL.style.color ="#ffffff";
							CAL.style.backgroundColor = "#396ac9";
							OK.innerHTML = "确定";
							CAL.innerHTML = "取消";
							Event.observe(OK,"click",function(ev){
									if(window.selectedImg && window.selectedImg.length > 0)
									{	
										Edit.editFocus();
										var str = "";
										if((Prototype.Browser.IE ? Edit.editDocument.hasFocus() : true))
										{
										}else
										{
											Edit.editFocus();
										}
										for(var i = 0 ; i < window.selectedImg.length ; i++)
										{	
											if(Prototype.Browser.IE)
											{
												str += '<img src="' + window.selectedImg[i] + '" />';
												//Edit.getTextRange().execCommand("InsertImage",false,window.selectedImg[i]);  
											}else
											{
												Edit.editDocument.execCommand("InsertImage",false,window.selectedImg[i]);  
											}
										}
										if(Prototype.Browser.IE)
										{
											Edit.getTextRange().pasteHTML(str);
										}
										window.selectedImg = null;
										Edit.closeDIV();
										Edit.editFocus();
									}else
									{
										if($("__ghf_insert_img_url_input"))
										{
											if($("__ghf_insert_img_url_input").value.length > 1 && /^(http|ftp|https):\/\/(\S+)\.(\S+)(.+)/i.test($("__ghf_insert_img_url_input").value))
											{
												if(Prototype.Browser.IE)
												{
													Edit.editWindow.selectElement.pasteHTML('<img src="' + $("__ghf_insert_img_url_input").value + '" />');
												}else{
													Edit.editDocument.execCommand("InsertImage",false,$("__ghf_insert_img_url_input").value);
												}
												Edit.closeDIV();
												Edit.editFocus();
											}else
											{
												alert("图片地址不合法");
											}
										}else
										{
											alert("你没有选择照片");
										}
									}

								});
							Event.observe(CAL,"click",function(ev){
									Edit.closeDIV();
								});	 							
								
							
							div.appendChild(flash)	;
							div.appendChild(document.createTextNode("从相册中选择图片： "));
							div.appendChild(pbSel) ;
							queren.appendChild(OK);
							queren.appendChild(CAL);
							bottom.appendChild(queren);
							bottom.appendChild(page);
							div.appendChild(subdiv)	;
							div.appendChild(bottom)	; 							
							div.show();
							if($("__insert_img_by_flash__").innerHTML == "")
							{
								/*daley:debug:if(/qun0\.youban\.com/i.test(document.domain))
								{
									$("__insert_img_by_flash__").update('外部图片地址<input type="text" id="__ghf_insert_img_url_input" value="http://" size="40">');
								}else
								{*/
									div.style.zIndex = 999;
									$("__insert_img_by_flash__").style.backgroundColor = "#FFFFFF";
									var so = new SWFObject("/js/edit/newupload.swf", "__inser__img_by_flash", "388px", "40px", "9", "#FFFFFF");
									//so.addParam('wmode','transparent');
									so.addParam('menu','false');
									so.write("__insert_img_by_flash__"); 
								//}
							} 
							if(Prototype.Browser.IE)
							{
								pbSel.fireEvent("onchange");
							}else
							{
								 var   evt   =   document.createEvent('HTMLEvents');  
								  evt.initEvent('change',true,true);  
								  pbSel.dispatchEvent(evt); 
							}	  												
						}
					}else
					{
						//alert(obj);
					}
				}});
	},
	/**
	*  取得相册中的照片列表
	**/
	getIMGs : function(pbid,pageNum)
	{
		new Ajax.Request("/edit/getIMG.php?cmd=img&pbid=" + pbid + "&page=" + pageNum,{
						onSuccess: function(rs)
						{
							var div = $("__inser__img__div");
							div.innerHTML = "";
							var page = $("__inser__img__div_page");
							page.innerHTML = "";  							
							eval("var obj = " + rs.responseText) ;
							if(obj)
							{
								try{
								if(obj.err)
								{
									alert(obj.msg);
								}else
								{	
									if(pageNum > 1)
									{
										var per = document.createElement("a");
										per.innerHTML = "上一页"
										per.style.styleFloat = "left";
										per.style.display = "block";
										per.style.width = "50px";
										per.style.border = "1px solid #396ac9";
										//per.style.backgroundColor = "#396ac9";
										per.setAttribute("href","javascript:;") ;
										page.appendChild(per);
										Event.observe(per,"click",function(e){Edit.getIMGs(pbid,(pageNum-1));});
									}
									
									if(Math.ceil(obj.sum / 20) > pageNum)
									{  
										var next = document.createElement("a");
										next.innerHTML = "下一页" ;
										next.style.styleFloat = "right";
										next.style.display = "block";
										next.style.width = "50px";
										next.style.marginRight = "20px";
										next.style.border = "1px solid #396ac9";
										//next.style.backgroundColor = "#396ac9";
										next.setAttribute("href","javascript:;") ;
										page.appendChild(next);
										Event.observe(next,"click",function(e){Edit.getIMGs(pbid,(pageNum+1));});
									}
									
									for(var i = 0 ; i < obj.list.length ; i++)
									{
										var o =  obj.list[i];
										var img = document.createElement("img");
										var turl = o.purl;
										turl = turl.replace(/([\/]?img\/)(.*)w_800_600_h(.*)/ig,"$1small/$2w_160_120_h$3");
										turl = turl.replace(/([\/]?img\/)(.*)w_600_800_h(.*)/ig,"$1small/$2w_120_160_h$3");
										turl = turl.replace(/([\/]?img\/)(.*)w_600_600_h(.*)/ig,"$1small/$2w_120_120_h$3");
										var spiltB = "/";
										if(/^\/*/ig.test(turl))
										{
											spiltB = "";
										}
										img.src = spiltB +  turl;
										img.setAttribute("bigsrc", spiltB + o.purl);
										img.style.width = "90px";
										img.style.height = "90px";
																
										img.style.border = "2px solid #FFFFFF";
										img.style.styleFloat = "left";
										img.style.cssFloat = "left";
										img.alt = "鼠标点击选中或取消选中";
										/*if(typeof window.selectedImg == "object" &&  window.selectedImg.length)
										{
											for(var i = window.selectedImg.length - 1 ; i>= 0; i--)
											{
												if(window.selectedImg[i] == img.getAttribute("bigsrc"))
												{
													img.style.borderColor = "#FF0000";
												}
											}
										}*/	 
										Event.observe(img,'click',function(ev)
											{
												var img = Event.element(ev);
												LOG.alert("img click :::" + typeof window.selectedImg);
												if(typeof window.selectedImg == "undefined" || window.selectedImg == null)
												{
													window.selectedImg = [];
												}
												LOG.alert("selected img border = " + img.style.borderColor);
												if(Prototype.Browser.IE)
												{
													if(img.style.borderColor == "#ffffff")
													{
														 img.style.borderColor = "#FF0000";
														 window.selectedImg.push(img.getAttribute("bigsrc"));
													}else
													{
														img.style.borderColor = "#ffffff";
														for(var i = 0 ; i < window.selectedImg.length ; i++)
														{
															if(window.selectedImg[i] == img.getAttribute("bigsrc"))
															{
																window.selectedImg[i] = null;  															
															}
														}
														window.selectedImg = window.selectedImg.compact();
													}
												}else
												{
													if(img.getAttribute("isSelect") != 1)
													{
														 img.style.borderColor = "#FF0000";
														 img.setAttribute("isSelect",1);
														 window.selectedImg.push(img.getAttribute("bigsrc"));
													}else
													{
														img.style.borderColor = "#FFFFFF";
														img.setAttribute("isSelect",0);
														for(var i = 0 ; i < window.selectedImg.length ; i++)
														{
															if(window.selectedImg[i] == img.getAttribute("bigsrc"))
															{
																window.selectedImg[i] = null;  															
															}
														}
														window.selectedImg = window.selectedImg.compact();
													}
												}
											});
										div.appendChild(img);
									}
								}
								}catch(e){}
							}else
							{									
							}
						}});
	},
	/**
	*  关闭弹出窗口
	**/
	closeDIV : function()
	{
		try{
		if(typeof Edit.openDiv != "undefined" && Edit.openDiv != null)
		{
			try{document.body.removeChild(Edit.openDiv);}catch(e){}
			Edit.openDiv = null;
		}
		Edit.editFocus();
		}catch(ex)
		{
		}
	},
	/**
	*  提交数据的时候用到的
	**/
	data:function()
	{
		Edit.closeDIV();
		//daley:add:2010.04.30:
		if(typeof(editorCls)=='undefined')//原编辑器
			var str=Edit.editDocument.body.innerHTML;
		else if(editorCls=='deeditor')//新编辑器
			var str=$('__ghf_edit_content').value;
		var flah_text 	= document.getElementById("flag_text");
		var flage 	= document.getElementById("flag_f");
		var furl 	= document.getElementById("flag_furl");
		if(flage)
		{
		}else
		{
			flage = document.createElement("input");
			furl = document.createElement("input");
			flah_text = document.createElement("input");
			flage.type = "hidden";
			furl.type = "hidden";
			flah_text.type = "hidden";
			flage.name = "mediatype";
			furl.name = "mediaurl";
			flah_text.name = "text";
			flage.id	= "flage_f";
			furl.id 	= "flag_furl";
			furl.value  ="";
			flage.value = 0;
			flah_text.id 	= "flah_text";
		}
		var reg = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x09|\x0B|\x0C|\x0A|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F/ig;
		str = str.replace(reg,"");
		//bak:var teml = UBB.html_ubb(Edit.editDocument.body.innerHTML);
		//daley:bak:去掉UBB：var teml=UBB.html_ubb(str);
		var teml=str;
		var text = $(Edit.editId);
		if(text)
		{
			//daley:bak:text.value = teml.replace(/(\r|\n)*/ig,"");
			//daley:bak:var p = text.parentNode;
			//add:
			var p = $('__ghf_write_blog_form');
			if(p==null)
				p=$(editFormId);
			if(p==null)
				p=text.parentNode;			
			var len = 30;
			while(p.tagName.toLowerCase() != "form" && len > 0)
			{
				p = p.parentNode;
				len--;
			}
			if(p.tagName.toLowerCase() != "form")
			{
				alert("没有表单");
			}else
			{
				this.forms = p;
				p.appendChild(flage);
				p.appendChild(furl);
				p.appendChild(flah_text);
			}
			flah_text.value = UBB.ubb_text(text.value);
			/*daley:bak:判断是图片贴、视频贴：if(/\[img\](.*?)\[\/img\]/ig.test(text.value) && (/\[flash(.*?)\](.*?)\[\/flash\]/ig.test(text.value)||/(\[(embed)(.*?)\](.*?)\[\/(embed)\])/ig.test(text.value)))
			{
				flage.value = 2;
			}else
			{
				if(/\[flash(.*?)\](.*?)\[\/flash\]/ig.test(text.value)||/(\[(embed)(.*?)\](.*?)\[\/(embed)\])/ig.test(text.value)  )
				{
					flage.value = 2;
				}
				if(/\[img\](.*?)\[\/img\]/ig.test(text.value) || /\[img( (\d+),(\d+))\]http:\/\/www\.youban\.com\/img\/(.*?)\[\/img\]/ig.test(text.value))
				{
					flage.value = 1;
				}
			}*/
			//add:
			if((/<img[^>]+(DE_ismp3|DE_ismv|DE_isswf|DE_isflv)[^>]+>/ig.test(text.value)) || (/<embed[^>]+src[^>]+>/ig.test(text.value)))
				flage.value=2;//视频贴
			else if(/<img[^>]+src[^>]+>/ig.test(text.value)){
				flage.value=1;//图片贴
			}
			if((text.value + "").length  > Edit.maxLebgth)
			{
				alert('您输入的帖子正文长度超出'+((text.value+'').length-Edit.maxLebgth)+'个字符');
				return false;
			}
			if((text.value + "").length < 1)
			{
				alert("内容不能为空");
				return false;
			}else
			{
				return true;
			}
		}
	},
	/**
	*  创建一个div；
	*	option{left:0左对齐,bottom:0下对齐,top:0上对齐,righ:0右对齐,width:100.height:100}
	**/
	createDiv : function(ev,option)
	{
		Edit.closeDIV();		
		var op = {};
		if(option.left)
		{
			op.left = true;
		}else
		{
			if(option.right)
			{
				op.right = true;
			}else
			{
				op.left = true;
			}
		}
		if(option.bottom)
		{
			op.bottom = true;
		}else
		{
			if(option.top)
			{
				op.top = true;
			}else
			{
				op.bottom = true;
			}
		}
		op.width = (option.width ? option.width : 300) + "px";
		op.height = (option.height ? option.height : 300) + "px"; 
		var div = document.createElement("div");
		div.setBody = function (obj)
			{
				this.appendChild(obj);
			};
		div.show = function()
			{
				this.style.display = "block";
			};
		var x = Event.pointerX(ev);
		var y = Event.pointerY(ev);
		if(Prototype.Browser.IE)
		{
			x -= ev.offsetX;
			y -= ev.offsetY;
		}else
		{
			if(Prototype.Browser.Gecko)
			{
				x -= ev.layerX;
				y -= ev.layerY;					
				LOG.alert("鼠标在目标对象中的位置：" + ev.layerX + "  :::  " + ev.layerY ) ;
				LOG.alert("---" + Event.element(ev).tagName) ;
			}
		}  		
		if(op.left)
		{	
			if(this.options.baseToolBar === false)
			{
				div.style.left = x + "px";
			}else
			{
				div.style.left = (x - parseInt(parseInt(op.width) / 2)) + "px";
			}
			LOG.alert("div left：" + x + "px");
		}else
		{
			if(this.options.baseToolBar === false)
			{
				div.style.left = x + "px";
			}else
			{
				div.style.left = (x + Event.element(ev).getWidth()) + "px";
			}
			LOG.alert("div left：" + (x + Event.element(ev).getWidth()) + "px");
		}
		if(op.top)
		{
			div.style.top = y + "px";
			LOG.alert("div top:" + y + "px");
		}else
		{
			div.style.top = (y + Event.element(ev).getHeight()) + "px";
			LOG.alert("div top:" + (y + Event.element(ev).getHeight()) + "px");
		} 		
		div.style.width = op.width;
		div.style.height = op.height;
		div.style.position = "absolute";
		div.style.border = "1px solid #A7C8FF";
		div.style.display = "none";
		div.style.backgroundColor = "#FFFFFF";
		document.body.appendChild(div);
		Edit.openDiv = div;
		return div;
		
	},
	per_view : function()
	{
		var w = 740;
		var h = 450;
		var div = document.createElement("iframe");
		var isrc = 'javascript:;';
		if (Prototype.Browser.IE) 
		{
			isrc = 'about:blank';
		}
		div.setAttribute('src', isrc);
		div.id="__edit_preview";
		document.body.appendChild(div);

		div = Element.extend(div);		
		var ifrm = div;
		ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
		
		div.style.position = "absolute";
		div.style.zIndex = 1000;
		div.style.width = w + "px";
		div.style.height = h + "px";
		div.style.backgroundColor = "#FFFFFF";
		div.style.border = "5px solid #A7C8FF";
		
		this.data();
		var str = $(Edit.editId).value;
		str = UBB.html_ubb(str);
		str = UBB.ubb_html(str);
		var styles = {mydiary:{styles:["diary.css"],tag:"div",className:"main"},
					  myheart:{styles:[""],tag:"",className:""},
					  myphoto:{styles:[""],tag:"",className:""},
					  groupbbs:{styles:[""],tag:"",className:""},
					  groupphoto:{styles:[""],tag:"",className:""},
					  groupboard:{styles:[""],tag:"",className:""},
					  groupboard:{styles:[""],tag:"",className:""}
					  };

		var stys = styles.mydiary;
		var st = '<link href="/styles/global-n.css" rel="stylesheet" type="text/css" />';
		for(var i = stys.styles.length - 1 ; i>= 0 ; i--)
		{
			st += '<link href="/styles/' + stys.styles[i] + '" rel="stylesheet" type="text/css" />';
		}
		ifrm.document.open();
		ifrm.document.write(st + '<h1 style="padding:6px 0;border-bottom:1px solid #CCCCCC;text-align:center;background-color:#F6F6F6;width:100%;">样式预览如下</h1><div style="overflow-y:auto;padding:10px;height:'+ (h - 90) + 'px;border-bottom:1px solid #CCCCCC;" id="_edit_pre_view"><'+stys.tag+' class="'+stys.tag+'">' +str + '</'+stys.tag+'></div><div style="text-align:center;padding:5px 0;"><button class="button1" onclick="window.parent.document.body.removeChild(window.parent.document.getElementById(\'__edit_preview\'));">关闭</button></div></div>');
		ifrm.document.close();
		p = getPageSize();
		var de = document.documentElement;		
		var scrollX = self.pageXOffset || ( de && de.scrollLeft ) || document.body.scrollLeft;
		var scollY = self.pageYOffset || ( de && de.scrollTop ) || document.body.scrollTop; 
		div.style.top = (p.windowHeight-h)/2 + scollY + "px";
		div.style.left = (p.windowWidth-w)/2 + scollY + "px";
		
	}	
};	 
function check_times() {
                        var currtime = parseInt( new Date().getTime()/1000 );
                        var cookietime = parseInt(readCookie('denycmts'));
                        var timeslong = currtime - cookietime ;
                        if(timeslong < 15) { alert("你发帖太快了，去边上喝杯茶吧"); return false;} else { return true; }
}
function SetImgUrl(str)
{//daley:本地用flash上传图片有问题alert(str);alert(editorCls);//alert(typeof(editorCls));
	if(typeof(editorCls)=='undefined'){//原上传
		try{
			var list = str.split("|");
			if((Prototype.Browser.IE ? Edit.editDocument.hasFocus() : true))
			{
			}else
			{
				Edit.editFocus();
			}
			if(Prototype.Browser.IE)
			{	
				var tem = ""; 
				for(var i = 0 ; i < list.length ; i++)
				{
					tem += '<img src="http://www.youban.com/' + list[i] + '" />';
				}
				Edit.editWindow.selectElement.pasteHTML(tem);
			}else
			{
				for(var i = 0 ; i < list.length ; i++)
				{
					Edit.editDocument.execCommand("InsertImage",false,"http://www.youban.com/" + list[i]);  
				}
			}
			
			Edit.closeDIV();
		}catch(e)
		{
			alert(e);
		}
	}
	else if(editorCls=='deeditor'){//新编辑器上传
		var list=str.split("|"),s='';
		for(var i=0;i<list.length;i++)
		{//daley:env:
			s+='<img src="http://www.youban.com/'+list[i]+'" />';
		}
		DE_EC.insStr(s,'img');
	}
}
//daley
function ctrlEnterSubmit(ev){
	//alert(DE_EC);alert(DE_EC.EC.event);
	var keyCode=0,ev=ev||event||DE_EC.EC.ev||DE_EC.EC.event;//alert(ev);
	keyCode=ev.keyCode||ev.which||ev.charCode;
	//var keyName=String.fromCharCode(keyCode);
	//alert("按键码: " + keyCode + " 字符: " + keyName);
	//alert(ev.ctrlKey);
	//if(ev.ctrlKey && keyCode==13 && Edit.data()){
	if(ev.ctrlKey && keyCode==13){
		//daley:add:if:
		if($('__ghf_write_blog_form')!=null){
			try{
				if(preSubmit(document.getElementById('__ghf_subgid_s').value)){
					DE_EC.GetCon();
					ghf.newBlog.blog.submit();
				}
			}catch(e){//编辑时无类别
				DE_EC.GetCon();
				ghf.newBlog.blog.submit();			
			}
		}else if($('__ghf_blog_comment')!=null){
			if(check_times()){DE_EC.GetCon();ghf.cmt.submit()}
		}
	}
}