/*
 * ComEditor
 * Copyright(c) 2006, Jack Slocum.
 * 
 * This code is licensed under BSD license. Use it as you wish, 
 * but keep this copyright intact.
 */
var IE=/Microsoft/.test(navigator.appName);var ClassUtil={extend:function(subClass,baseClass){function inheritance(){};inheritance.prototype=baseClass.prototype;subClass.prototype=new inheritance();subClass.prototype.constructor=subClass;subClass.baseConstructor=baseClass;subClass.superClass=baseClass.prototype;},getFileDir:function(sFileName){var scripts=document.getElementsByTagName("script");var regFileName=new RegExp(sFileName+"$");for(var i=0;i<scripts.length;i++)
{if(regFileName.test(scripts[i].src))
{return scripts[i].src.replace(regFileName,"");}}}}
var EventUtil={addEventHandler:function(target,sType,listener,bUseCapture)
{if(target.addEventListener)
{target.addEventListener(sType,listener,bUseCapture);}
else if(target.attachEvent)
{target.attachEvent("on"+sType,listener);}},removeEventHandler:function(target,sType,listener,bUseCapture)
{if(target.removeEventListener)
{target.removeEventListener(sType,listener,bUseCapture);}
else if(target.detachEvent)
{target.detachEvent("on"+sType,listener);}},getEvent:function(oEvent)
{return oEvent?oEvent:window.event;},getEventButton:function(oEvent)
{if(oEvent.which)
{var buttonMap=[1,4,2];return buttonMap[oEvent.button];}
else
{return oEvent.button;}}}
var ffDOMUtil={canHaveChildren:function(node)
{switch(node.tagName)
{case"AREA":case"BASE":case"BASEFONT":case"COL":case"FRAME":case"HR":case"IMG":case"BR":case"INPUT":case"ISINDEX":case"LINK":case"META":case"PARAM":return false;}
return true;},setOuterHTML:function(node,sHTML)
{var r=node.ownerDocument.createRange();r.setStartBefore(node);var df=r.createContextualFragment(sHTML);var parentNode=node.parentNode;parentNode.replaceChild(df,node);},getOuterHTML:function(node)
{var attr,attrs=node.attributes;var str="<"+node.tagName;for(var i=0;i<attrs.length;i++)
{attr=attrs[i];if(attr.specified)
str+=" "+attr.name+'="'+attr.value+'"';}
if(!ffDOMUtil.canHaveChildren(node))
return str+">";return str+">"+node.innerHTML+"</"+node.tagName+">";}}
function contains(containerNode,node)
{while(node)
{if(containerNode==node)
{return true;}
node=node.parentNode;}
return false;}
function buildElement(tagName,attrs,style,text)
{var e=document.createElement(tagName);if(attrs)
{for(key in attrs)
{switch(key)
{case"className":e.className=attrs[key];break;case"id":e.id=attrs[key];break;default:e.setAttribute(key,attrs[key]);}}}
if(style)
{for(key in style)
{e.style[key]=style[key];}}
if(text)
{e.appendChild(document.createTextNode(text));}
return e;}
function getCurrentStyle(element,cssRule)
{var value="";if(window.getComputedStyle)
{cssRule=cssRule.replace(/[A-Z]/g,function(match){return"-"+match.toLowerCase();});value=window.getComputedStyle(element,"").getPropertyValue(cssRule);}
else if(element.currentStyle)
{value=element.currentStyle[cssRule];}
return value;}
function getIntMeasure(element,cssRule)
{return parseInt(getCurrentStyle(element,cssRule));}
function getOffsetHeight(element)
{var styles=["borderTopWidth","paddingTop","height","paddingBottom","borderBottomWidth"];var height=0,measure;for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);if(isNaN(measure)&&styles[i]=="height")
{measure=0;for(var j=0;j<element.childNodes.length;j++)
{measure+=getOccupyHeight(element.childNodes[j]);}}
else if(isNaN(measure))
{measure=0;}
height+=measure;}
return height;}
function getOffsetWidth(element)
{var styles=["borderLeftWidth","paddingLeft","width","paddingRight","borderRightWidth"];var width=0,measure;for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);if(isNaN(measure)&&styles[i]=="width")
{measure=0;for(var j=0;j<element.childNodes.length;j++)
{if(element.childNodes[j].nodeType!=3)
{measure+=getOccupyWidth(element.childNodes[j]);}}}
else if(isNaN(measure))
{measure=0;}
width+=measure;}
return width;}
function getOccupyHeight(element)
{var styles=["marginTop","marginBottom"];var occupy=0,measure;occupy=getOffsetHeight(element);for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);measure=isNaN(measure)?0:measure;occupy+=measure;}
return occupy;}
function getOccupyWidth(element)
{var styles=["marginLeft","marginRight"];var occupy=0,measure;occupy=getOffsetWidth(element);for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);measure=isNaN(measure)?0:measure;occupy+=measure;}
return occupy;}
function calcHeightStyle(element,height)
{var styles=["borderTopWidth","paddingTop","paddingBottom","borderBottomWidth"];var measure;for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);height-=isNaN(measure)?0:measure;}
return height+"px";}
function calcWidthStyle(element,width)
{var styles=["borderLeftWidth","paddingLeft","paddingRight","borderRightWidth"];var measure;for(var i=0;i<styles.length;i++)
{measure=getIntMeasure(element,styles[i]);width-=isNaN(measure)?0:measure;}
return width+"px";}

function UiComponent(tagName,attrs,style,text)
{tagName=tagName.toLowerCase();this._parent=null;this._enabled=true;this._node=buildElement(tagName,attrs,style,text);this.setStyle("display","none");document.body.appendChild(this._node);if(tagName=="div"||tagName=="span")
{this._node.unselectable="on";}}
UiComponent.prototype.browser=function()
{var browser=new Object();var reVersion=null;var browserUserAgent=navigator.userAgent.toLowerCase();if(browserUserAgent.indexOf("msie")!=-1)
{browser.name="ie";reVersion=/.*MSIE ([0-9]{1,}[\.0-9]{0,}).*/i;}
else if(browserUserAgent.indexOf("gecko")!=-1)
{browser.name="gecko";reVersion=/.*rv:([0-9]{1,}[\.0-9]{0,}).*/i;}
else if(browserUserAgent.indexOf("opera")!=-1)
{browser.name="opera";reVersion=/.*opera\/([0-9]{1,}[\.0-9]{0,}).*/i;}
browser.version=parseFloat(browserUserAgent.replace(reVersion,"$1"));return browser;}();UiComponent.prototype.getNode=function()
{return this._node;}
UiComponent.prototype.setTop=function(top)
{this.setStyle("top",top+"px");}
UiComponent.prototype.getTop=function()
{var intMeasure=getIntMeasure(this._node,"top");return isNaN(intMeasure)?0:intMeasure;}
UiComponent.prototype.setLeft=function(left)
{this.setStyle("left",left+"px");}
UiComponent.prototype.getLeft=function()
{var intMeasure=getIntMeasure(this._node,"left");return isNaN(intMeasure)?0:intMeasure;}
UiComponent.prototype.setHeight=function(height)
{this.setStyle("height",calcHeightStyle(this._node,height));var misValue=this.getHeight()-height;if(misValue&&this.browser.name=="ie")
{this.setStyle("height",getIntMeasure(this._node,"height")-misValue+"px");}}
UiComponent.prototype.getHeight=function()
{return this.getStyle("display")!="none"?this._node.offsetHeight:getOffsetHeight(this._node);}
UiComponent.prototype.setWidth=function(width)
{this.setStyle("width",calcWidthStyle(this._node,width));var misValue=this.getWidth()-width;if(misValue&&this.browser.name=="ie")
{this.setStyle("width",getIntMeasure(this._node,"width")-misValue+"px");}}
UiComponent.prototype.getWidth=function()
{return this.getStyle("display")!="none"?this._node.offsetWidth:getOffsetWidth(this._node);}
UiComponent.prototype.getClientHeight=function()
{return this._node.clientHeight;}
UiComponent.prototype.getClientWidth=function()
{return this._node.clientWidth;}
UiComponent.prototype.setToolTipText=function(sText)
{this._toolTipText=String(sText);this._node.title=this._toolTipText;}
UiComponent.prototype.getToolTipText=function()
{return this._toolTipText;}
UiComponent.prototype.setParentNode=function(oParent,oBeforeSibling)
{this.removeStyle("display");if(oBeforeSibling)
{oParent.insertBefore(this._node,oBeforeSibling);}
else
{oParent.appendChild(this._node);}}
UiComponent.prototype.appendNode=function(oNode)
{this._node.appendChild(oNode);}
UiComponent.prototype._addedCallBack=function(){}
UiComponent.prototype.add=function(oChild)
{oChild.removeStyle("display");oChild._parent=this;this.appendNode(oChild.getNode());oChild._addedCallBack();}
UiComponent.prototype.setStyle=function(sStyle,sValue)
{try{this._node.style[sStyle]=sValue;}
catch(e){}}
UiComponent.prototype.getStyle=function(sStyle)
{return getCurrentStyle(this._node,sStyle);}
UiComponent.prototype.removeStyle=function(sStyle)
{if(this._node.style.removeAttribute)
{this._node.style.removeAttribute(sStyle);}
else
{sStyle=sStyle.replace(/[A-Z]/g,function(match){return"-"+match.toLowerCase();});this._node.style.removeProperty(sStyle);}}
UiComponent.prototype.setClassStyle=function(sClass)
{this._node.className=sClass;}
UiComponent.prototype._addState=function(sState)
{var className=this._node.className;var normalClass=className.split(" ",1)[0];if(normalClass)
{var stateClass=normalClass+"-"+sState;if(!new RegExp(stateClass,"ig").test(className))
{this._node.className+=" "+stateClass;}}}
UiComponent.prototype._removeState=function(sState)
{var className=this._node.className;var normalClass=className.split(" ",1)[0];if(normalClass)
{var stateClass=normalClass+"-"+sState;this._node.className=className.replace(new RegExp("( "+stateClass+"$)|(^"+
stateClass+" )|(^"+stateClass+"$)","g"),"").replace(new RegExp(" "+stateClass+" ","g")," ");}}
UiComponent.prototype.setEnabled=function(bEnabled)
{this._enabled=bEnabled;}
UiComponent.prototype.getEnabled=function()
{return this._enabled;}
UiComponent.prototype._setMouseOver=function(fHandlder)
{this._node.onmouseover=function(oEvent){oEvent=EventUtil.getEvent(oEvent);var fromNode=oEvent.relatedTarget||oEvent.fromElement;if(!contains(this,fromNode))
{fHandlder(oEvent);}}}
UiComponent.prototype._setMouseOut=function(fHandlder)
{this._node.onmouseout=function(oEvent){oEvent=EventUtil.getEvent(oEvent);var toNode=oEvent.relatedTarget||oEvent.toElement;if(!contains(this,toNode))
{fHandlder(oEvent);}}}
UiComponent.prototype._setMouseDown=function(fHandlder)
{this._node.onmousedown=function(oEvent){oEvent=EventUtil.getEvent(oEvent);fHandlder(oEvent);}}
UiComponent.prototype._setMouseUp=function(fHandlder)
{EventUtil.addEventHandler(document,"mouseup",fHandlder);}
UiComponent.prototype._onMouseOver=function(oEvent)
{this.onMouseOver(oEvent);}
UiComponent.prototype._onMouseOut=function(oEvent)
{this.onMouseOut(oEvent);}
UiComponent.prototype._onMouseDown=function(oEvent)
{this.onMouseOut(oEvent);}
UiComponent.prototype._onMouseUp=function(oEvent)
{this.onMouseUp(oEvent);}
UiComponent.prototype._onClick=function(oEvent)
{this.onClick(oEvent);}
UiComponent.prototype.onMouseOver=function(oEvent){}
UiComponent.prototype.onMouseOut=function(oEvent){}
UiComponent.prototype.onMouseDown=function(oEvent){}
UiComponent.prototype.onMouseUp=function(oEvent){}
UiComponent.prototype.onClick=function(oEvent){}

function UiImage(sUri,nWidth,nHeight)
{if(!this.browser){var oUiComponent=new UiComponent('div');this.browser=oUiComponent.browser.name;}
this._uri=sUri;if(this.browser.name=="ie"&&this.browser.version<7&&/\.png$/i.test(sUri))
{var sPngFilter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+
this._uri+"',sizingMethod='scale')";UiImage.baseConstructor.call(this,"img",{src:UiImage.BLANK_IMAGE_URI},{filter:sPngFilter,width:nWidth+"px",height:nHeight+"px"});}
else
{UiImage.baseConstructor.call(this,"img",{src:this._uri},{width:nWidth+"px",height:nHeight+"px"});}
this._disableDrag();this.UiName="UiImage";}
ClassUtil.extend(UiImage,UiComponent);UiImage.BLANK_IMAGE_URI=ClassUtil.getFileDir("uiimage.js")+"blank.gif";UiImage.prototype._disableDrag=function()
{if(this.browser.name=="ie")
{this._node.ondragstart=function(){return false;}}
else if(this.browser.name=="gecko")
{this._node.onmousedown=function(event){event.preventDefault();}}}
UiImage.prototype.getUri=function()
{return this._uri;}

function SmileyPanel(gender)
{this.sSmileyUrlTemplate='http://img.zhanzuo.com/s/webim/skin/default/emotes/'+(gender==1?'male':'female')+'/small/_sn_.gif';this.sSmileyNameMask='_sn_';this.nHeight=30;SmileyPanel.baseConstructor.call(this,"div",{className:"smiley-panel"});this._childs=new Array();this.UiName="SmileyPanel";}
ClassUtil.extend(SmileyPanel,UiComponent);SmileyPanel.prototype.setParent=function(oUiComponent){this._parentComponent=oUiComponent;oUiComponent.add(this);this.writeSmileyPanel();}
SmileyPanel.prototype.writeSmileyPanel=function(){for(var i=16;i<=50;i++){var sSmileyName=i;var sSmileyUrl=this.sSmileyUrlTemplate.replace(this.sSmileyNameMask,sSmileyName);var oSmileySample=new SmileySample(this,sSmileyUrl);this.add(oSmileySample);}
this.getNode().appendChild(document.createElement('hr'));for(var i=1;i<=15;i++){var sSmileyName=i;var sSmileyUrl=this.sSmileyUrlTemplate.replace(this.sSmileyNameMask,sSmileyName);var oSmileySample=new SmileySample(this,sSmileyUrl);this.add(oSmileySample);}}
SmileyPanel.prototype.pickSmiley=function(sSmileyUrl){this._parentComponent.onPickSmiley(sSmileyUrl);}
function SmileySample(oSmileyPanel,sSmileyUrl)
{SmileySample.baseConstructor.call(this,sSmileyUrl,oSmileyPanel.nHeight,oSmileyPanel.nHeight);this.UiName="SmileySample";this._SmileyPanel=oSmileyPanel;var oSmileySample=this;this._node.className='smiley-sample';this._setMouseOver(function(){oSmileySample._node.className='smiley-sample-hover';});this._setMouseOut(function(){oSmileySample._node.className='smiley-sample';});this._node.onclick=function(){oSmileyPanel.pickSmiley(sSmileyUrl);}}
ClassUtil.extend(SmileySample,UiImage);

function Fadeable(){var oThis=this;this.CONFIG={nOpacity:100,nStep:3,nTimeInMs:10,bQuickMode:true,bSelectExcluded:false};this.nCurrentOpacity=1;this.divFadeable=document.createElement('div');this.init=function(nDefaultOpacity,nDefaultStep,nDefaultTimeInMs,bDefaultQuickMode){if(nDefaultOpacity){this.CONFIG.nOpacity=nDefaultOpacity;}
if(nDefaultStep){this.CONFIG.nStep=nDefaultStep;}
if(nDefaultTimeInMs){this.CONFIG.nTimeInMs=nDefaultTimeInMs;}
if(bDefaultQuickMode){this.CONFIG.bQuickMode=bDefaultQuickMode;}
hide();document.body.appendChild(this.divFadeable);this.style=this.divFadeable.style;};function show(){if(IE&&oThis.CONFIG.bSelectExcluded){try{svcSelectReplace.replace();}
catch(e){}}
oThis.divFadeable.style.display='';}
function hide(){if(IE&&oThis.CONFIG.bSelectExcluded){try{svcSelectReplace.restore();}
catch(e){}}
oThis.divFadeable.style.display='none';}
this.setOpacity=function(nOpacity){if(nOpacity==0){hide();return;}
nOpacity=nOpacity?nOpacity:this.CONFIG.nOpacity;if(IE){this.divFadeable.style.filter='grey() alpha(opacity='+nOpacity+')';}
else{this.divFadeable.style.opacity=''+nOpacity/100;}
show();this.nCurrentOpacity=nOpacity;}
this.fadeIn=function(nOpacityFrom,nOpacityTo,nStep,nTimeInMs){nOpacityFrom=nOpacityFrom?nOpacityFrom:1;nOpacityTo=nOpacityTo?nOpacityTo:this.CONFIG.nOpacity;nStep=nStep?nStep:this.CONFIG.nStep;nTimeInMs=(nTimeInMs?nTimeInMs:this.CONFIG.nTimeInMs)*(this.CONFIG.bQuickMode?1:10);var oThis=this;if(nOpacityFrom<nOpacityTo+nStep){oThis.setOpacity(nOpacityFrom);window.setTimeout(function(){oThis.fadeIn(nOpacityFrom+nStep);},nTimeInMs);}}
this.fadeOut=function(nOpacityFrom,nOpacityTo,nStep,nTimeInMs){nOpacityFrom=nOpacityFrom?nOpacityFrom:this.nCurrentOpacity;nOpacityTo=nOpacityTo?nOpacityTo:2;nStep=nStep?nStep:this.CONFIG.nStep;nTimeInMs=(nTimeInMs?nTimeInMs:this.CONFIG.nTimeInMs)*(this.CONFIG.bQuickMode?1:10);var oThis=this;if(nOpacityFrom>nOpacityTo+nStep){oThis.setOpacity(nOpacityFrom);window.setTimeout(function(){oThis.fadeOut(nOpacityFrom-nStep);},nTimeInMs);}
else{hide();return;}}}
function PageInterlayer(){var oThis=this;Fadeable.call(this);this.CONFIG={nOpacity:75,nStep:3,nTimeInMs:10,bQuickMode:true,bSelectExcluded:true};this.nCurrentOpacity=1;this.divFadeable.className='PageInterlayer';this.setOpacity0=this.setOpacity;this.setOpacity=function(nOpacity){this.resize();this.setOpacity0(nOpacity);}
this.resize=function(){if(IE){var nDocWidth=document.body.scrollWidth;if(document.documentElement.clientWidth>nDocWidth){nDocWidth=document.documentElement.clientWidth;}
this.divFadeable.style.width=nDocWidth+'px';var nDocHeight=document.body.scrollHeight;if(document.body.clientHeight>nDocHeight){nDocHeight=document.body.clientHeight;}
if(document.documentElement.scrollHeight-4>nDocHeight){nDocHeight=document.documentElement.scrollHeight-4;}
this.divFadeable.style.height=nDocHeight+'px';}
else{this.divFadeable.style.width=document.documentElement.scrollWidth+'px';this.divFadeable.style.height=document.documentElement.scrollHeight+'px';}}
this.onClick=function(){};this.divFadeable.onclick=function(){oThis.onClick();}}
var svcSelectReplace=new SvcSelectReplace();function SvcSelectReplace(){var IE=/Microsoft/.test(navigator.appName)&&/MSIE 6/.test(navigator.appVersion);if(!IE){return null;}
var aRealSelect=[];this.replace=function(nZIndexCeiling){try{nZIndexCeiling=nZIndexCeiling||500;aRealSelect=document.getElementsByTagName('select');for(var i=0;i<aRealSelect.length;i++){var oRealSelect=aRealSelect[i];if(oRealSelect.oFakeSelect||getMaxZIndex(oRealSelect)>nZIndexCeiling)
continue;var oFakeSelect=buildElement('input',{className:'fake-select',value:(oRealSelect.options[oRealSelect.selectedIndex]).text},{width:oRealSelect.offsetWidth+'px'});oRealSelect.style.display='none';oRealSelect.insertAdjacentElement('afterEnd',oFakeSelect);oRealSelect.oFakeSelect=oFakeSelect;}}
catch(e){$log('replace');}}
this.restore=function(){try{for(var i=0;i<aRealSelect.length;i++){var oRealSelect=aRealSelect[i];oRealSelect.style.display='';if(oRealSelect.oFakeSelect){oRealSelect.parentNode.removeChild(oRealSelect.oFakeSelect);}
oRealSelect.oFakeSelect=null;}}
catch(e){$log('restore');}}
function getMaxZIndex(o){var nZ=0;while(o!=document.body){var n=getIntMeasure(o,'zIndex');nZ=(nZ>=n)?nZ:n;o=o.parentNode;}
return nZ;}}

function InpagePrompt(nMode,divContent,aParam,oPageInterlayer){var oThis=this;Fadeable.call(this);this.init_Fadeable=this.init;this._node=this.divFadeable;this.divContent=divContent;this.divContent.oOwner=this;aParam=aParam||{};if(nMode){this.CONFIG.nMode=nMode;}
this.sTitle=aParam.sTitle;this.nRegion=aParam.nRegion;this.oPageInterlayer=oPageInterlayer;this._node.className='InpagePrompt';this.oFloatLayer=new FloatLayer(this._node);this.divTitleBar=buildElement('div',{className:'divTitleBar'});this.divButtonBar=buildElement('div',{className:'divButtonBar'});this.btnConfirm=buildElement('input',{className:'btn',type:'button',value:'确定'});this.btnCancel=buildElement('input',{className:'rebtn',type:'button',value:'取消'});this.init=function(aParam){aParam=aParam||{};this.sTitle=aParam.sTitle||this.sTitle;if(this.sTitle){this._node.appendChild(this.divTitleBar);this.divTitleBar.innerHTML=this.sTitle;}
this.nRegion=aParam.nRegion||this.nRegion||InpagePrompt.REGION_MIDDLE_CENTER;this._node.appendChild(this.divContent);switch(this.CONFIG.nMode){case InpagePrompt.MODE_ALERT:this.divButtonBar.appendChild(this.btnConfirm);this._node.appendChild(this.divButtonBar);break;case InpagePrompt.MODE_CONFIRM:this.divButtonBar.appendChild(this.btnConfirm);this.divButtonBar.appendChild(this.btnCancel);this._node.appendChild(this.divButtonBar);break;}
this.init_Fadeable();}
this.setRegion=function(nRegion){this.oFloatLayer.setRegion(nRegion);}
this.popup=function(aParam,aData){aParam=aParam||{};this.nRegion=aParam.nRegion||this.nRegion;switch(this.CONFIG.nMode){case InpagePrompt.MODE_NOTIFY:oThis.fadeIn();break;case InpagePrompt.MODE_SPECIAL:oThis.popup();if(this.oPageInterlayer){this.oPageInterlayer.fadeIn();}
break;default:oThis.setOpacity(100);if(this.oPageInterlayer){this.oPageInterlayer.setOpacity();}}
if(this._node.parseData){this._node.parseData(aData);}
this.setRegion(this.nRegion);}
this.popoff=function(){switch(this.CONFIG.nMode){case InpagePrompt.MODE_NOTIFY:case InpagePrompt.MODE_CAUTION:oThis.fadeOut();if(this.oPageInterlayer){this.oPageInterlayer.setOpacity(0);}
break;case InpagePrompt.MODE_SPECIAL:oThis.fadeOut();if(this.oPageInterlayer){this.oPageInterlayer.fadeOut();}
break;default:oThis.setOpacity(0);if(this.oPageInterlayer){this.oPageInterlayer.setOpacity(0);}}}
this.onClick=function(){};this._node.onclick=function(){oThis.onClick();}
switch(this.CONFIG.nMode){case InpagePrompt.MODE_NOTIFY:this.onClick=function(){this.popoff();}
break;case InpagePrompt.MODE_CAUTION:this.onClick=function(){this.popoff();}
break;}
this.onConfirm=function(){return true;};this.btnConfirm.onclick=function(){if(oThis.onConfirm()){oThis.popoff();}}
this.onCancel=function(){};this.btnCancel.onclick=function(){oThis.onCancel();oThis.popoff();}}
InpagePrompt.MODE_GENERIC=0;InpagePrompt.MODE_NOTIFY=1;InpagePrompt.MODE_CAUTION=2;InpagePrompt.MODE_ALERT=3;InpagePrompt.MODE_CONFIRM=4;InpagePrompt.MODE_PROMPT=5;InpagePrompt.REGION_TOP_LEFT=1;InpagePrompt.REGION_TOP_CENTER=2;InpagePrompt.REGION_TOP_RIGHT=3;InpagePrompt.REGION_MIDDLE_LEFT=4;InpagePrompt.REGION_MIDDLE_CENTER=5;InpagePrompt.REGION_MIDDLE_RIGHT=6;InpagePrompt.REGION_BOTTOM_LEFT=7;InpagePrompt.REGION_BOTTOM_CENTER=8;InpagePrompt.REGION_BOTTOM_RIGHT=9;function FloatLayer(divFloatLayer){this.divFloatLayer=divFloatLayer;if(IE){this.divFloatLayer.style.position='absolute';}
else{this.divFloatLayer.style.position='fixed';}
this.setLeft=function(nLeft,bFreeFromSight){if(!bFreeFromSight){nLeft=nLeft>0?nLeft:0;}
this.divFloatLayer.style.left=nLeft+'px';}
this.setTop=function(nTop,bFreeFromSight){if(IE){nTop=nTop+(document.body.scrollTop||document.documentElement.scrollTop);}
if(!bFreeFromSight){nTop=nTop>0?nTop:0;}
this.divFloatLayer.style.top=nTop+'px';}
this.setRight=function(nRight,bFreeFromSight){this.setLeft(nRight-this.divFloatLayer.offsetWidth);}
this.setBottom=function(nBottom,bFreeFromSight){this.setTop(nBottom-this.divFloatLayer.offsetHeight);}
this.setCenter=function(nCenter,bFreeFromSight){this.setLeft(nCenter-this.divFloatLayer.offsetWidth/2);}
this.setMiddle=function(nMiddle,bFreeFromSight){this.setTop(nMiddle-this.divFloatLayer.offsetHeight/2);}
this.setHorizontalRegion=function(nHorizontalRegion){var sWidthInSight=window.innerWidth||document.documentElement.clientWidth||document.documentElement.scrollWidth;if(document.documentElement.clientWidth==document.documentElement.scrollWidth&&document.documentElement.scrollWidth<window.innerWidth){sWidthInSight=document.documentElement.clientWidth;}
switch(nHorizontalRegion){case 1:this.setLeft(0);break;case 3:this.setRight(sWidthInSight);break;default:this.setCenter(sWidthInSight/2);}}
this.setVerticalRegion=function(nVerticalRegion){var sHeightInSight=window.innerHeight||document.documentElement.clientHeight||document.documentElement.scrollHeight;switch(nVerticalRegion){case 1:this.setTop(0);break;case 3:this.setBottom(sHeightInSight);break;default:this.setMiddle(sHeightInSight/2);}}
this.setRegion=function(nRegion){nRegion=nRegion?nRegion:5;var nVerticalRegion=Math.ceil(nRegion/3);var nHorizontalRegion=(nRegion+3)-nVerticalRegion*3;this.setHorizontalRegion(nHorizontalRegion);this.setVerticalRegion(nVerticalRegion);}}

var oPageInterlayer=new PageInterlayer();function ImgChooser(){var oThis=this;oPageInterlayer.init();var divContent_ImgChooser=document.getElementById('divContent_ImgChooser');var oInpagePrompt_ImgChooser=new InpagePrompt(InpagePrompt.MODE_CONFIRM,divContent_ImgChooser,{sTitle:'选择（或上传）你要插入的图片'},oPageInterlayer);oInpagePrompt_ImgChooser.init();var upload_img=document.getElementById('upload_img');var sSrc=upload_img.src;var f_url=document.getElementById("f_url");var upload_toggler=document.getElementById("upload_toggler");this.pop=function(){f_url.value='';upload_img.style.display='none';upload_toggler.style.display='';oInpagePrompt_ImgChooser.popup();}
divContent_ImgChooser.style.display='';oInpagePrompt_ImgChooser.onConfirm=function(){var sUrl=f_url.value;if(!sUrl||sUrl.length==0){alert('请输入图片网址！');return false;}
if(/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){}
else{sUrl='http://'+sUrl;}
oThis.setImgUrl(sUrl);upload_img.src=sSrc;document.getElementById('ipreview').src='about:blank';return true;}
oInpagePrompt_ImgChooser.onCancel=function(){upload_img.src=sSrc;document.getElementById('ipreview').src='about:blank';oThis.setImgUrl(null);}}
function checkEnter(event){event=event||window.event;var keyCode=event.keyCode;if(keyCode==13){onPreview();}}
function useImgUploaded(sUrl){var f_url=document.getElementById("f_url");f_url.value=sUrl;onPreview();return true;}
function onPreview(){var f_url=document.getElementById("f_url");
var upload_img=document.getElementById('upload_img');
var sSrc=upload_img.src;
var sUrl=f_url.value;if(!sUrl){f_url.focus();return false;}
if(/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){}
else{sUrl='http://'+sUrl;}
document.getElementById('ipreview').src=sUrl;var upload_img = document.getElementById('upload_img');upload_img.src = 'about:blank';upload_img.src = sSrc;return true;}
function onUpload(){var upload_img=document.getElementById('upload_img');var divUploadImg=document.getElementById('divUploadImg');var upload_toggler=document.getElementById('upload_toggler');if(upload_img.style.display=='none'){upload_img.style.display='';}
upload_toggler.style.display='none';}

function Pallette()
{Pallette.baseConstructor.call(this,"div",{className:"pallette"});this._childs=new Array();this.UiName="ToolBar";}
ClassUtil.extend(Pallette,UiComponent);Pallette.prototype.setParent=function(oUiComponent){this._parentComponent=oUiComponent;oUiComponent.add(this);this.writeSimplePallette(this);}
Pallette.prototype.writeSimplePallette=function(el){var aColorStepMap=['00','88','FF'];var nStep=aColorStepMap.length;for(var i=0;i<nStep;i++){var divLine=new UiComponent('div',null,{lineHeight:'1em'});for(var j=0;j<nStep;j++){for(var k=0;k<nStep;k++){var oColorBrick=new ColorBrick(this,'#'+aColorStepMap[i]+aColorStepMap[j]+aColorStepMap[k]);divLine.add(oColorBrick);}}
el.add(divLine);}}
Pallette.prototype.detectColor=function(oEvent){}
Pallette.prototype.leaveColor=function(oEvent){}
Pallette.prototype.pickColor=function(sColor){this._parentComponent.onPickColor(sColor);}
function ColorBrick(oPallette,sColor)
{ColorBrick.baseConstructor.call(this,'span',{className:'pallette-color-brick'},{color:sColor},'■');this.UiName="ColorBrick";this._pallette=oPallette;var oColorBrickNode=this._node;this._setMouseOver(function(){oColorBrickNode.style.backgroundColor='black';oPallette.detectColor(sColor);});this._setMouseOut(function(){oColorBrickNode.style.backgroundColor='white';oPallette.leaveColor(sColor);});this._node.onclick=function(){oPallette.pickColor(sColor);}}
ClassUtil.extend(ColorBrick,UiComponent);

function RichEditor(sUri)
{this.CONFIG={};this.CONFIG.RESIZE={};this.CONFIG.RESIZE.bEnabled=true;this.CONFIG.RESIZE.nRESERVED=16;this.CONFIG.RESIZE.nMin=480;this.CONFIG.RESIZE.nMax=-48;this.CONFIG.nMax=0;this._templateUri=sUri;RichEditor.baseConstructor.call(this,"iframe",{className:"rich-editor",src:this._templateUri});this._loaded=false;this._firstFocused=true;this.UiName="RichEditor";var me=this;this.oTimeTake_CmdStateCheck=new TimeTaker(function(){me.commandStateChecker();},100);this._initialize(sUri);var _this=this;}
ClassUtil.extend(RichEditor,UiComponent);

RichEditor.prototype._initialize=function(sUri){
	var _this=this;
EventUtil.addEventHandler(this._node,"load",function(){try{_this._onIframeLoad();}
catch(e){_alert?_alert('编辑器似乎出现了乱码？\n如果是，那么请:<br/>1. <a href="'+sUri+'" target="_blank">点击这里</a>;<br/>2. 在弹出的窗口(或标签页)中按 Ctrl + F5 把乱码刷掉，关闭该窗口;<br/>3. 回到本页（即编辑器所在的地方），刷新（最好从右键菜单中选“刷新”）。',0,20000):alert('编辑器似乎出现了乱码？\n如果是，那么请:<br/>1. <a href="'+sUri+'" target="_blank">点击这里</a>;<br/>2. 在弹出的窗口(或标签页)中按 Ctrl + F5 把乱码刷掉，关闭该窗口;<br/>3. 回到本页（即编辑器所在的地方），刷新（最好从右键菜单中选“刷新”）。',0,20000)}},false);}

RichEditor.prototype._onIframeLoad=function(){
	var doc=this.getContentDocument();var win=this.getContentWindow();var me=this;if(IE){doc.body.contentEditable=true;EventUtil.addEventHandler(this._node,"beforedeactivate",function(){me._ieSaveSelection()});EventUtil.addEventHandler(this._node,"focus",function(){me._ieRestoreSelection();});}
else{doc.designMode="on";doc.execCommand("styleWithCSS",false,false);var pNode=doc.getElementsByTagName("p").item(0);pNode.appendChild(doc.createElement("br"));var range=doc.createRange();range.selectNodeContents(pNode);var selection=win.getSelection();selection.removeAllRanges();selection.addRange(range);range.collapse(true);EventUtil.addEventHandler(doc,"keypress",function(e){me._ffKeyPress(e);},true);}

this.eventChecker=function(oEvent){
	setTimeout(function(){if(me._firstFocused)
{me._firstFocused=false;me.onFirstFocus();}
me.oTimeTake_CmdStateCheck.exec();me.resize2FullHeight();},10);
}

if(IE){EventUtil.addEventHandler(doc.body,"mouseup",this.eventChecker);EventUtil.addEventHandler(doc.body,"keydown",this.eventChecker);}
else{EventUtil.addEventHandler(doc,"mouseup",this.eventChecker);EventUtil.addEventHandler(doc,"keydown",this.eventChecker);}

EventUtil.addEventHandler(doc,"keypress",function(event){if((event.keyCode==13||event.keyCode==10)&&event.ctrlKey==true){me.onSubmit(me.getContentHtml());}});this._loaded=true;if(this._focused)
{if(this._firstFocused)
{this._firstFocused=false;this.onFirstFocus();}
this.setFocused(true);}
this.loadContent();
this.resize2FullHeight();
}

RichEditor.prototype.loadContent=function(){};
RichEditor.prototype._ffKeyPress=function(oEvent)
{if(oEvent.which==13&&!oEvent.shiftKey){return;}
if(oEvent.ctrlKey&&!oEvent.shiftKey&&!oEvent.altKey)
{var bPrevent=false;switch(oEvent.charCode)
{case 98:this.execCommand("bold");bPrevent=true;break;case 105:this.execCommand("italic");bPrevent=true;break;case 117:this.execCommand("underline");bPrevent=true;break;case 101:this.execCommand("JustifyCenter");bPrevent=true;break;case 108:this.execCommand("JustifyLeft");bPrevent=true;break;case 114:this.execCommand("JustifyRight");bPrevent=true;break;}
if(bPrevent)
{oEvent.preventDefault();oEvent.stopPropagation();}}}
RichEditor.prototype._ieSaveSelection=function(){var doc=this.getContentDocument();if(doc.readyState=="complete")
{this._keepedRange=doc.selection.createRange();}}
RichEditor.prototype._ieRestoreSelection=function(){if(this._keepedRange)
{var keepedRange=this._keepedRange;keepedRange.select();if(this._delayExceCommand)
{var res=this._delayExceCommand();delete this._delayExceCommand;}}}
RichEditor.prototype._ieClearSelection=function(){if(this._keepedRange)
{if(this._keepedRange.compareEndPoints&&this._keepedRange.compareEndPoints("StartToEnd",this._keepedRange)!=0)
{var doc=this.getContentDocument();doc.execCommand("Undo",false,null);doc.execCommand("Undo",false,null);}
delete this._keepedRange;}}
RichEditor.prototype.getContentDocument=function()
{return this._node.contentWindow.document;}
RichEditor.prototype.getContentWindow=function()
{return this._node.contentWindow;}
RichEditor.prototype.insertHTML=function(sHtml){this.execCommand('inserthtml',false,sHtml);this.resize2FullHeight();}

RichEditor.prototype.execCommand=function(sCommand,bUi,oCommandValue)
{
sCommand=sCommand.toLowerCase();
if(this.browser.name=="ie")
{
	this._delayExceCommand=function(){var doc=this.getContentDocument();

if(sCommand=='createlink'){
	if(doc.selection.createRange().htmlText==''){
		this.insertHTML('<a href="'+oCommandValue+'" target="_blank" >'+oCommandValue+'</a>');return;
	}
}
if(sCommand=='inserthtml')
{var oRange=doc.selection.createRange();oRange.pasteHTML(oCommandValue);this.resize2FullHeight();}
else if(sCommand=='insertimage')
{var img=document.createElement('img');img.src=oCommandValue;
var oRange=doc.selection.createRange();
oRange.pasteHTML('<img src="'+oCommandValue+'"/>');

this.resize2FullHeight();}
else{
	doc.execCommand(sCommand,bUi,oCommandValue);
	try{
		doc.selection.createRange().parentElement().target="_blank";
	}catch(e){
		try{
			doc.selection.createRange()(0).parentNode.target="_blank";
		}catch(e){}
	}
}
if(sCommand=='indent')
{var oRange=doc.selection.createRange();var oNode=oRange.parentElement();while(oNode.tagName.toLowerCase()!='html'){if(oNode.tagName.toLowerCase()=='blockquote'){oNode.className='fix_blockquote';}
oNode=oNode.parentNode;}}
else if(sCommand=='outdent')
{var oRange=doc.selection.createRange();var oNode=oRange.parentElement();while(oNode.tagName.toLowerCase()!='html'){if(oNode.className=='fix_blockquote'&&oNode.tagName.toLowerCase()!='blockquote'){oNode.className='';}
oNode=oNode.parentNode;}}
else if(sCommand=='forecolor')
{
var oRange=doc.selection.createRange();
var oNode=oRange.parentElement();
while(oNode.tagName && oNode.tagName.toLowerCase()!='font'){oNode=oNode.parentNode;}
var s=oNode.innerHTML && oNode.innerHTML.replace(/<strong>/ig,'<b class="fix_b">').replace(/<\/strong>/ig,'</b>');
if(oNode.innerHTML!=s){oNode.innerHTML=s;try{oRange.select();}catch(e){}}}

var me=this;me.oTimeTake_CmdStateCheck.exec();}
this.setFocused(true);}

else if(this.browser.name=="gecko")
{
	var me=this;var doc=this.getContentDocument();var win=this.getContentWindow();this.setFocused(true);
if(sCommand=='createlink'){if(win.getSelection().getRangeAt(0).collapsed){this.insertHTML('<a href="'+oCommandValue+'" target="_blank">'+oCommandValue+'</a>');}
else{doc.execCommand('CreateLink',false,oCommandValue); win.focus();
var sText=win.getSelection().focusNode;
try{
	while(sText.parentNode.tagName && sText.parentNode.tagName.toLowerCase() != 'a'){
		sText = sText.parentNode;
	}
	sText.parentNode.setAttribute("target","_blank");
}catch(e){
	try{
		while(sText.childNodes.length && sText.childNodes[0].tagName.toLowerCase() != 'a'){
			sText = sText.childNodes[0];
		}
		sText.childNodes.length && sText.childNodes[0].setAttribute("target","_blank");
	}catch(e){}
}
}
return;}

if(sCommand=='backcolor')
{doc.execCommand('styleWithCSS',false,true);doc.execCommand('hilitecolor',false,oCommandValue);doc.execCommand('styleWithCSS',false,false);return;}
else if(sCommand=='print')
{win.print();return;}
else if(sCommand=='unlink')
{var range=win.getSelection().getRangeAt(0),currentNode;if(range.collapsed)
{currentNode=range.startContainer;while(currentNode.nodeName.toLowerCase()!="body")
{if(currentNode.nodeName.toLowerCase()=="a")
{ffDOMUtil.setOuterHTML(currentNode,currentNode.innerHTML);break;}
currentNode=currentNode.parentNode;}}
else
{currentNode=range.startContainer;while(currentNode.nodeName.toLowerCase()!="body")
{if(currentNode.nodeName.toLowerCase()=="a")
{ffDOMUtil.setOuterHTML(currentNode,currentNode.innerHTML);break;}
currentNode=currentNode.parentNode;}
currentNode=range.endContainer;while(currentNode.nodeName.toLowerCase()!="body")
{if(currentNode.nodeName.toLowerCase()=="a")
{ffDOMUtil.setOuterHTML(currentNode,currentNode.innerHTML);break;}
currentNode=currentNode.parentNode;}}}
doc.execCommand(sCommand,bUi,oCommandValue);
if(sCommand=='indent')
{var oRange=win.getSelection().getRangeAt(0);oNode=oRange.startContainer.parentNode;while(oNode.tagName.toLowerCase()!='html'){if(oNode.tagName.toLowerCase()=='blockquote'){oNode.className='fix_blockquote';}
oNode=oNode.parentNode;}}
this.oTimeTake_CmdStateCheck.exec();}}

RichEditor.prototype.queryCommandValue=function(sCommand)
{var doc=this.getContentDocument(),sValue;sCommand=sCommand.toLowerCase();if(this.browser.name=="ie"&&sCommand=="formatblock")
{try{var oNode=doc.selection.createRange().parentElement();}
catch(e){return"";}
var sNodeName=oNode.nodeName.toLowerCase();while(sNodeName!="body")
{if(sNodeName=="h1"||sNodeName=="h2"||sNodeName=="h3"||sNodeName=="h4"||sNodeName=="h5"||sNodeName=="h6"||sNodeName=="p"||sNodeName=="pre"||sNodeName=="address")
{return"<"+sNodeName+">";}
oNode=oNode.parentNode;sNodeName=oNode.nodeName.toLowerCase();}
return"";}
else if(this.browser.name=="gecko"&&sCommand=="formatblock")
{return"<"+doc.queryCommandValue(sCommand)+">";}
else if(this.browser.name=="ie")
{sValue=doc.queryCommandValue(sCommand);return sValue?sValue:"";}
else
{return doc.queryCommandValue(sCommand);}}
RichEditor.prototype.queryCommandState=function(sCommand)
{var doc=this.getContentDocument();return doc.queryCommandState(sCommand);}
RichEditor.prototype.queryCommandEnabled=function(sCommand)
{var doc=this.getContentDocument();var win=this.getContentWindow();sCommand=sCommand.toLowerCase();if(sCommand=="copy"&&this.browser.name=="ie")
{return doc.queryCommandEnabled("cut");}
else if(sCommand=="unlink"&&this.browser.name=="gecko")
{var oRange=win.getSelection().getRangeAt(0);var oCurrentNode;if(oRange.collapsed){oCurrentNode=oRange.startContainer;while(oCurrentNode.nodeName.toLowerCase()!='body'){if(oCurrentNode.nodeName.toLowerCase()=='a'){return true;}
oCurrentNode=oCurrentNode.parentNode;}
return false;}
else{oCurrentNode=oRange.startContainer;while(oCurrentNode.nodeName.toLowerCase()!='body'){if(oCurrentNode.nodeName.toLowerCase()=='a'){return true;}
oCurrentNode=oCurrentNode.parentNode;}
oCurrentNode=oRange.endContainer;while(oCurrentNode.nodeName.toLowerCase()!='body'){if(oCurrentNode.nodeName.toLowerCase()=='a'){return true;}
oCurrentNode=oCurrentNode.parentNode;}
var fragmentHTML='';var fragmentNodes=oRange.cloneContents().childNodes;for(var i=0;i<fragmentNodes.length;i++){if(fragmentNodes[i].nodeType==3){fragmentHTML+=fragmentNodes[i].nodeValue;}
else if(fragmentNodes[i].nodeType==1){fragmentHTML+=fragmentNodes[i].outerHTML;}}
return/<\/a>/i.test(fragmentHTML);}}
else
{return doc.queryCommandEnabled(sCommand);}}

RichEditor.prototype.setFocused=function setFocused(bFocused)
{this._focused=bFocused;if(!this._loaded)return;var win=this.getContentWindow();if(bFocused){win.focus();var me=this;setTimeout(function(){if(me._delayExceCommand){me._delayExceCommand();}
else{}},100);this.commandStateChecker();}
else{win.blur();}}

RichEditor.prototype.image2object4flash=function(s)
{var h=s.match(/height="?(\d+)/)[1];var w=s.match(/width="?(\d+)/)[1];var url=s.match(/title="?([^"\s]+)/)[1];return['<object width="',w,'" height="',h,'" classid="CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000">','<param name="movie" value="',url,'" />','<param name="quality" value="high" />','<param name="bgcolor" value="#000000" />','<param name="wmode" value="transparent" />','<param name="allowFullScreen" value="true" />','<embed width="',w,'" height="',h,'" align="middle" allowfullscreen="true" type="application/x-shockwave-flash" bgcolor="#000000" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="',url,'"/>','</object>'].join('');}
RichEditor.prototype.getContentHtml=function()
{var doc=this.getContentDocument();if(this.browser.name=="ie")
{}
var s=doc.body.innerHTML;
s=s.replace(/<strong/ig,'<b');
s=s.replace(/<\/strong>/ig,'</b>');
s=s.replace(/<b>/ig,'<b class="fix_b">');
s=s.replace(/<ol>/ig,'<ol class="fix_ol">');
s=s.replace(/<ul>/ig,'<ul class="fix_ul">');
s=s.replace(/<em/ig,'<i');
s=s.replace(/<\/em/ig,'</i');

var rFlashPH=/<img[^>]* class="?flash_placeholder"?[^>]*>/ig;var a=s.match(rFlashPH);if(a){for(var i=0;i<a.length;i++){var sImg=a[i];s=s.replace(sImg,this.image2object4flash(sImg));}}
var rMplayerPH=/<img[^>]* class="?(video|audio)_placeholder"?[^>]*>/ig;var a=s.match(rMplayerPH);if(a){for(var i=0;i<a.length;i++){var sImg=a[i];var h,w;if(/height:/i.test(sImg)){h=sImg.match(/height: (\d+)/i)[1];w=sImg.match(/width: (\d+)/i)[1];}
else{h=sImg.match(/height="?(\d+)/i)[1];w=sImg.match(/width="?(\d+)/i)[1];}
var url=sImg.match(/title="?([^"\s]+)/)[1];

var sMplayerCode=['<object width="',w,'" height="',h,'" type="application/x-oleobject" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">','<param name="url" value="',url,'" />','<param name="autostart" value="false">',
'<embed width="',w,'" height="',h,'" type="application/x-mplayer2" src="',url,'"/></object>'].join('');
s=s.replace(sImg,sMplayerCode);}}
return trim(s);}

RichEditor.prototype.object2image4flash=function(s){var h=s.match(/height="?(\d+)/)[1];var w=s.match(/width="?(\d+)/)[1];var url=s.match(/src="?([^"\s]+)/)[1]; return ['<img class="flash_placeholder" src="',this.sImgDir,'flash_placeholder.jpg" width="',w,'" height="',h,'" title="',url,'" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join('');}

RichEditor.modifySrc=function(img){img.title=window.prompt('修改媒体的URL:',img.title)||img.title;}
RichEditor.prototype.setContentHtml=function(s){
	s = s.replace(/\r|\n/g,'');
	if(s&&s!=''){
		var doc=this.getContentDocument();
		var rFlashPH=/<object.*?D27CDB6E-AE6D-11cf-96B8-444553540000.*?<\/object>/ig;
		var a=s.match(rFlashPH);
		
		if(a){
			for(var i=0;i<a.length;i++){
				var sObj=a[i];
				s=s.replace(sObj,this.object2image4flash(sObj) );
			}
		}
		var rMplayerPH=/<object .*?autostart.*?<\/object>/ig;
		var b=s.match(rMplayerPH);
		
		if(b){
			for(var i=0;i<b.length;i++){
				var sObjectCode=b[i];
				var h=sObjectCode.match(/height="?(\d+)/)[1];var w=sObjectCode.match(/width="?(\d+)/)[1];
				var url=(sObjectCode.match(/name="?URL"? value="?([^"\s]+)/i)||sObjectCode.match(/data="?([^"\s]+)/i))[1];
				var sMediaCode=/\.(mid|midi|rmi|aif|aiff|au|snd|wav|wma|wax|mp3|m3u|ogg)$/.test(url)?['<img class="audio_placeholder" src="',this.sImgDir,'audio_placeholder.jpg" title="',url,'" width="',w,'" height="45" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join(''):['<img class="video_placeholder" src="',this.sImgDir,'video_placeholder.jpg" title="',url,'" width="',w,'" height="',h,'" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join('');
				s=s.replace(sObjectCode,sMediaCode);
			}
		}
		doc.body.innerHTML=s;
	}
}

RichEditor.prototype.getText=function(){var doc=this.getContentDocument();var s=this.browser.name=="ie"?doc.body.innerText:doc.body.textContent;return trim(s);};RichEditor.prototype.isEmpty=function(){

try{
var sText=this.getText();
if(sText.replace(/(^\s*)|(\s*$)/g,"")==''){
	if(this.getContentDocument().body.innerHTML.match(/<img/ig)){
		return false;
	}else{
		return true;
	}
}
}catch(e){return true;}

return false;}
RichEditor.prototype.setAutoResize=function(b){this.CONFIG.RESIZE.bEnabled=b;}
RichEditor.prototype.setHeight=function(height){this.CONFIG.RESIZE.nMin=height;this.setStyle("height",calcHeightStyle(this._node,height));var misValue=this.getHeight()-height;if(misValue&&this.browser.name=="ie"){this.setStyle("height",getIntMeasure(this._node,"height")-misValue+"px");}}
RichEditor.prototype.resize2FullHeight=function(s)
{if(!this.CONFIG.RESIZE.bEnabled){return;}
var doc=this.getContentDocument();var nHeight=doc[IE?'body':'documentElement'].scrollHeight+this.CONFIG.RESIZE.nRESERVED;if(!nHeight||nHeight<this.CONFIG.RESIZE.nMin){nHeight=this.CONFIG.RESIZE.nMin;}
var nMaxHeight;if(this.CONFIG.RESIZE.nMax<0){var sHeightInSight=window.innerHeight||document.documentElement.clientHeight||document.documentElement.offsetHeight;nMaxHeight=sHeightInSight+this.CONFIG.RESIZE.nMax;}
else{nMaxHeight=this.CONFIG.RESIZE.nMax;}
if(nHeight>nMaxHeight){nHeight=nMaxHeight;}
this._node.style.height=nHeight+'px';}
RichEditor.prototype.commandStateChecker=function(){}
RichEditor.prototype.onFirstFocus=function(){}
function TimeTaker(f,nDelay){var nTimer=0;this.exec=function(){clearTimeout(nTimer);nTimer=setTimeout(f,nDelay);}}

function ToolBar()
{ToolBar.baseConstructor.call(this,"div",{className:"tool-bar"});this._childs=new Array();this.UiName="ToolBar";}
ClassUtil.extend(ToolBar,UiComponent);

ToolBar.prototype.add=function(oChild)
{ToolBar.superClass.add.call(this,oChild);oChild.setEnabled(this._enabled);this._childs.push(oChild);}

ToolBar.prototype.setEnabled=function(bEnabled)
{ToolBar.superClass.setEnabled.call(this,bEnabled);for(var i=0;i<this._childs.length;i++)
{this._childs[i].setEnabled(bEnabled);}}
function ToolBarButton(sText,oIcon)
{ToolBarButton.baseConstructor.call(this,"span",{className:"tool-bar-button"});if(oIcon)
{oIcon.setStyle("verticalAlign","middle");oIcon.setStyle("marginRight",sText?"3px":"0");this._iconOuter=new UiComponent("span");this._iconOuter.add(oIcon);this.add(this._iconOuter);this._icon=oIcon;}
if(sText)
{this._textNode=document.createTextNode(sText);this.appendNode(this._textNode);}
this._setBehavior();this._iconPosition="left";this.UiName="ToolBarButton";}

ClassUtil.extend(ToolBarButton,UiComponent);ToolBarButton.prototype._addedCallBack=function()
{if(this._parent.getClientHeight()>0){}}
ToolBarButton.prototype._setBehavior=function()
{var me=this;var mouseOver=function(oEvent){if(!me.getEnabled())return;me._hover=true;me._addState("hover");if(me._mouseDown)
{me._addState("active");}
me._onMouseOver(oEvent);}
var mouseOut=function(oEvent){if(!me.getEnabled())return;me._hover=false;me._removeState("hover");if(me._mouseDown)
{me._removeState("active");}
me._onMouseOut(oEvent);}
var mouseDown=function(oEvent){if(!me.getEnabled()||EventUtil.getEventButton(oEvent)!=1)return;me._mouseDown=true;me._addState("active");me._onMouseDown(oEvent);}
var mouseUp=function(oEvent){if(!me.getEnabled()||!me._mouseDown||EventUtil.getEventButton(oEvent)!=1)return;var click=me._mouseDown&&me._hover;me._mouseDown=false;me._removeState("active");me._onMouseUp(oEvent);if(click)
{me._onClick(oEvent);}}
this._setMouseOver(mouseOver);this._setMouseOut(mouseOut);this._setMouseDown(mouseDown);this._setMouseUp(mouseUp);}
ToolBarButton.prototype.setIconPosition=function(sPosition)
{var oldIconPostion=this._iconPosition;this._iconPosition=sPosition;if(sPosition=="top"&&oldIconPostion!=sPosition)
{this._node.insertBefore(buildElement("br"),this._textNode);this._icon.removeStyle("marginRight");}}
ToolBarButton.prototype.setEnabled=function(bEnabled)
{ToolBarButton.superClass.setEnabled.call(this,bEnabled);this._node.disabled=this._enabled?false:true;if(!this._iconOuter)return;if(this._enabled)
{if(this.browser.name=="ie")
{this._iconOuter.removeStyle("filter");}
else if(this.browser.name=="gecko")
{this._icon.removeStyle("opacity");}}
else
{if(this.browser.name=="ie")
{this._iconOuter.setStyle("filter","gray() alpha(opacity=50)");}
else if(this.browser.name=="gecko")
{this._icon.setStyle("opacity","0.5");}
this._removeState("hover");this._removeState("active");}}
function ToolBarMenuButton(sText,oIcon,oMenu)
{ToolBarMenuButton.baseConstructor.call(this,sText,oIcon);this._node.className="tool-bar-menu-button";this._icon.setStyle("marginRight","2px");this._dropDownArrow=new UiComponent("span",{className:"ui-component tool-bar-menu-button-drop-down-arrow"});this.add(this._dropDownArrow);this.menu=oMenu;oMenu.button=this;this.UiName="ToolBarMenuButton";}
ClassUtil.extend(ToolBarMenuButton,ToolBarButton);ToolBarMenuButton.prototype._addedCallBack=function()
{ToolBarMenuButton.superClass._addedCallBack.call(this);this._dropDownArrow.setHeight(this._iconOuter.getHeight());}
ToolBarMenuButton.prototype._onClick=function(oEvent)
{this.setMenuToggled(true);this.menu.show(this);}
ToolBarMenuButton.prototype.setMenuToggled=function(bToggled)
{this._menuToggled=bToggled;if(this._menuToggled)
{this._addState("checked");}
else
{this._removeState("checked");}}
ToolBarMenuButton.prototype.getMenuToggled=function()
{return this._menuToggled;}
ToolBarMenuButton.prototype.setEnabled=function(bEnabled)
{ToolBarMenuButton.superClass.setEnabled.call(this,bEnabled);if(this._enabled)
{if(this.browser.name=="ie")
{this._dropDownArrow.removeStyle("filter");}
else if(this.browser.name=="gecko")
{this._dropDownArrow.removeStyle("opacity");}}
else
{if(this.browser.name=="ie")
{this._dropDownArrow.setStyle("filter","gray() alpha(opacity=50)");}
else if(this.browser.name=="gecko")
{this._dropDownArrow.setStyle("opacity","0.5");}}}
function MenuGroup(){var aMenu=new Array();this.add=function(oMenu){oMenu.group=this;aMenu.push(oMenu);}
this.setFocus=function(oMenu){for(var i=0;i<aMenu.length;i++){if(oMenu!=aMenu[i]){aMenu[i].hide();}}}}
function ToolBarMenu()
{ToolBarMenu.baseConstructor.call(this,"div",{className:"tool-bar-menu"},null,'');document.body.appendChild(this._node);this.setStyle('display','none');this.UiName='ToolBarMenu';this.hide=function(){this.button.setMenuToggled(false);this.setStyle('display','none');};var o=this;setMouseLeaveListener(this._node,function(){o.hide();});}
ClassUtil.extend(ToolBarMenu,UiComponent);ToolBarMenu.prototype.show=function(oToolBarMenuButton){this.group.setFocus(this);var o=getAbsoluteOffset(oToolBarMenuButton.getNode());this.setTop(o.top+o.height);this.setLeft(o.left);this.setStyle('display','block');}
function getAbsoluteOffset(e){var t=e.offsetTop;var l=e.offsetLeft;var w=e.offsetWidth;var h=e.offsetHeight-1;if(IE){t+=2;l+=2;}
while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}
return{top:t,left:l,width:w,height:h}}
function setMouseLeaveListener(el,l){if(IE){EventUtil.addEventHandler(el,'mouseleave',l);}
else{var nMouseLeaveTimer;EventUtil.addEventHandler(el,'mouseout',function(oEvent){nMouseLeaveTimer=setTimeout(l,1);});EventUtil.addEventHandler(el,'mouseover',function(oEvent){clearTimeout(nMouseLeaveTimer);});}}
function ToolBarToggleButton(sText,oIcon,bChecked)
{ToolBarToggleButton.baseConstructor.call(this,sText,oIcon);this.setChecked(bChecked);}
ClassUtil.extend(ToolBarToggleButton,ToolBarButton);ToolBarToggleButton.prototype._onClick=function(oEvent)
{this.setChecked(!this.getChecked());this.onClick(oEvent);}
ToolBarToggleButton.prototype.setChecked=function(bChecked)
{this._checked=bChecked;if(this._checked)
{this._addState("checked");}
else
{this._removeState("checked");}}
ToolBarToggleButton.prototype.getChecked=function()
{return this._checked;}
function ToolBarRadioButton(sText,oIcon,oGroup,bChecked)
{this.setGroup(oGroup);ToolBarRadioButton.baseConstructor.call(this,sText,oIcon,bChecked);}
ClassUtil.extend(ToolBarRadioButton,ToolBarToggleButton);ToolBarRadioButton.prototype._onClick=function(oEvent)
{this.setChecked(true);this.onClick(oEvent);}
ToolBarRadioButton.prototype.getGroup=function()
{return this._group;}
ToolBarRadioButton.prototype.setGroup=function(oRadioGroup)
{this._group=oRadioGroup;oRadioGroup.add(this);}
ToolBarRadioButton.prototype.setChecked=function(bChecked)
{if(bChecked)
{var items=this._group.getItems();for(var i=0;i<items.length;i++)
{if(this!=items[i])
{ToolBarRadioButton.superClass.setChecked.call(items[i],false);}}}
ToolBarRadioButton.superClass.setChecked.call(this,bChecked);}
function ToolBarSeparator()
{ToolBarSeparator.baseConstructor.call(this,"span",{className:"tool-bar-separator"});this._separatorLine=new UiComponent("div",{className:"tool-bar-separator-line"});this.add(this._separatorLine);this.UiName="ToolBarSeparator";}
ClassUtil.extend(ToolBarSeparator,UiComponent);function RadioGroup()
{this._items=new Array();}
RadioGroup.prototype.getItems=function()
{return this._items;}
RadioGroup.prototype.add=function(oRadioButton)
{this._items.push(oRadioButton);}
function ToolbarSelect(aOption,sTitle){ToolBarSeparator.baseConstructor.call(this,"select",{title:sTitle,className:"tool-bar-select"});for(var i=0;i<aOption.length;i++)
{this._node.appendChild(buildElement("option",{value:aOption[i].value},null,aOption[i].text));}
var oToolbarSelect=this;this._node.onchange=function(){oToolbarSelect.onChange();}
this.UiName="ToolbarSelect";}
ClassUtil.extend(ToolbarSelect,UiComponent);ToolbarSelect.prototype.setEnabled=function(bEnabled){this._node.disabled=!bEnabled;}
ToolbarSelect.prototype.setValue=function(sValue){this._node.value=sValue;}
ToolbarSelect.prototype.getValue=function(){return this._node.value;}
ToolbarSelect.prototype.onChange=function(){}
function ToolBarMenuSelect(aOption,oMenuGroup,sTitle,oIcon,oOptionPrototype,bSelectMode)
{var oThis=this;var oToolBarMenu=new ToolBarMenu();oMenuGroup.add(oToolBarMenu);ToolBarMenuSelect.baseConstructor.call(this,sTitle,oIcon,oToolBarMenu);this.setToolTipText(sTitle);if(bSelectMode){this._node.className='tool-bar-menu-button';}
this.UiName='ToolBarMenuSelect';this.writeOption=function(){for(var i=0;i<aOption.length;i++){var oOption=aOption[i];if(oOptionPrototype){if(IE){for(var k in oOptionPrototype){oOption[k]=oOptionPrototype[k];}}
else{oOption.__proto__=oOptionPrototype;}}
var oToolBarMenuOption=new ToolBarMenuOption(this,oToolBarMenu,oOption);oToolBarMenu.add(oToolBarMenuOption);if(bSelectMode){oToolBarMenuOption.setStyle('display','block');}}}
this.writeOption();this.aOption=aOption;this.bSelectMode=bSelectMode;this.oToolBarMenu=oToolBarMenu;}
ClassUtil.extend(ToolBarMenuSelect,ToolBarMenuButton);ToolBarMenuSelect.prototype.setValue=function(sValue){if(!sValue||this.value==sValue){return;}
for(var i=0;i<this.aOption.length;i++){if(this.aOption[i].value==sValue){if(this.bSelectMode){}
this.value=sValue;}}}
ToolBarMenuSelect.prototype.getValue=function(){return this.value;}
ToolBarMenuSelect.prototype.onChoose=function(sValue){}
function ToolBarMenuOption(oToolBarMenuSelect,oToolBarMenu,oOption){var oThis=this;oOption.getText=oOption.getText||function(){return this.text};oOption.getIcon=oOption.getIcon||function(){return null};oOption.getStyle=oOption.getStyle||function(){return null};ToolBarMenuOption.baseConstructor.call(this,oOption.getText(),oOption.getIcon());oToolBarMenu.add(this);this.value=oOption.value;this.getNode().className='tool-bar-menu-option';if(oOption.getHtml){this.getNode().innerHTML=oOption.getHtml();}
var aStyle=oOption.getStyle();if(aStyle){for(i in aStyle){this._node.style[i]=aStyle[i];}}
this.onClick=function(){oToolBarMenu.hide();oToolBarMenuSelect.setValue(this.value);oToolBarMenuSelect.onChoose();}}
ClassUtil.extend(ToolBarMenuOption,ToolBarButton);

function Comeditor(sTextareaId){var oImgChooser;this.sImgDir=zz_path_img+'editor/';this.richEditor=null;
this.txtArea=document.getElementById(sTextareaId);this.CONFIG={};this.CONFIG.autoresize=false;
this.focus=function(){window.scrollTo(0,$('#editorToolBar').offset().top);this.richEditor.getContentWindow().focus();}
var oThis=this;var txtArea = this.txtArea;var fm=txtArea.form;

this.init=function(){//var txtArea=document.getElementById(sTextareaId);this.txtArea=txtArea;
var height=txtArea.getAttribute('height')||120;var width=txtArea.getAttribute('width')||850;window.user_gender=txtArea.getAttribute('gender');var theme=txtArea.getAttribute('theme');var max=txtArea.getAttribute('max');var size_hint=txtArea.getAttribute('size_hint');if(size_hint){size_hint=document.getElementById(size_hint);}
height=Number(height);width=Number(width);if(theme=='full'){this.CONFIG.autoresize=true;blockBackspace();}
theme=Comeditor.theme[theme||'team'];if(!theme){document.title='编辑器theme不存在！';}
var oContainer=this.txtArea.parentNode;var editorToolBar=new ToolBar();editorToolBar.setParentNode(oContainer);editorToolBar.setEnabled(false);if(IE){editorToolBar.setHeight(20);}
else{editorToolBar.setHeight(20);}
editorToolBar.setWidth(width);editorToolBar.getNode().id='editorToolBar';this.editorToolBar=editorToolBar;var richEditor=new RichEditor('/editor/blank.html?12030931');richEditor.setParentNode(oContainer);richEditor.setLeft(0);richEditor.setWidth(width);richEditor.setHeight(height);richEditor.setAutoResize(this.CONFIG.autoresize);richEditor.sImgDir=this.sImgDir;this.richEditor=richEditor;var nLastCharCount = 0;function AutoCheckSize(){setTimeout(AutoCheckSize,500);try{richEditor.leftSize=max-richEditor.getText().length;if(!size_hint || richEditor.leftSize == nLastCharCount){return;}nLastCharCount = richEditor.leftSize;
if(richEditor.leftSize<0){size_hint.className='error';size_hint.innerHTML='<em>请删除'+(0-richEditor.leftSize)+'个字</em>';}
else{size_hint.className='ok';size_hint.innerHTML='还可以写<em>'+richEditor.leftSize+'</em>个字';}}
catch(e){}}
max&&AutoCheckSize();this.loadToolbar(theme);try{oImgChooser=new ImgChooser();this.buttons.image.onClick=function(){oImgChooser.pop();}
oImgChooser.setImgUrl=function(sUrl){if(sUrl&&sUrl!=''){richEditor.execCommand('InsertImage',false,sUrl);}}}
catch(e){}
richEditor.onFirstFocus=function(){editorToolBar.setEnabled(true);}
editorToolBar.setHeight(30);if(fm){fm.showError=fm.showError||function(){};var error_wrap=fm.getAttribute('error_wrap');var error_to=fm.getAttribute('error_to');if(error_to&&error_wrap){error_wrap=document.getElementById(error_wrap);error_to=document.getElementById(error_to);fm.showError=function(s){if(s){error_wrap.style.display='block';error_to.innerHTML=s;}
else{error_wrap.style.display='none';}}}

fm.checkEditor=fm.checkEditor||function(){
if(richEditor.isEmpty()){fm.showError(fm.getAttribute('empty_msg')||'编辑内容不能为空');return false;}
if(richEditor.leftSize<0){fm.showError(fm.getAttribute('over_max')||'编辑内容的文字不能超过'+max+'个');return false;}
oThis.syncTextarea();return true;
}

fm.onsubmit = function(){
	return this.checkEditor();
	//return false;
}
richEditor.onSubmit=function(s){if(fm.onsubmit&&fm.onsubmit()!==false){fm.submit();}}}
oThis.fm=fm;
if(this.comeditorIMG){this.comeditorIMG.style.display='none';window.setTimeout(function(){oThis.focus();},100);}
if(fm.comeditor_okay){fm.comeditor_okay.onclick = function(){};}
this.isInit=true;
window.setTimeout(function(){try{richEditor.eventChecker('event');}catch(e){richEditor.onFirstFocus();}}, 200);
}

this.isInit=txtArea.getAttribute('is_init');
this.comeditorIMG=null;
if(this.isInit=='true'){oThis.init();this.isInit=true;}else{
this.isInit=false;
this.comeditorIMG=document.createElement('img');
if(txtArea.getAttribute('width') == '520'){
	this.comeditorIMG.src=this.sImgDir+"comeditor_520.gif";
}else if(txtArea.getAttribute('width') == '640'){
	this.comeditorIMG.src=this.sImgDir+"comeditor_640.gif";
}else{
	this.comeditorIMG.src=this.sImgDir+"comeditor.gif";
	this.comeditorIMG.width = txtArea.getAttribute('width');
}


this.comeditorIMG.onclick=function(){
oThis.init();
}
txtArea.parentNode.appendChild(this.comeditorIMG);

if(fm.comeditor_okay){
	if(!oThis.isInit){
		fm.onsubmit = function(){return false};
		fm.comeditor_okay.onclick=function(){
			oThis.init();
			this.onclick = function(){};
		}
	}
}
}
this.syncTextarea=function(){
	this.txtArea.value=this.richEditor.getContentHtml();
}}

function blockBackspace(){var divContent_Warning=buildElement('div',{className:'divContent'});divContent_Warning.innerHTML='你刚刚按了[退格]键。<br/>为了避免因为浏览器“后退”而令你正在编辑的内容的丢失，我们把它屏蔽掉了。<br/>如果你真的想后退，请用其它方式（如点击“后退”按钮、鼠标手势等）。';var oInpagePrompt_Warning=new InpagePrompt(InpagePrompt.MODE_NOTIFY,divContent_Warning,{sTitle:'通知'});function checkEnter(event){var txtEditor=document.getElementById('content');event=event||window.event;var keyCode=event.keyCode;if(keyCode==8){var elTarget=event.target||event.srcElement;var sTagName=elTarget.tagName.toLowerCase();if(sTagName!='input'&&sTagName!='textarea'&&sTagName!='iframe'&&sTagName!='img'){if(oInpagePrompt_Warning){oInpagePrompt_Warning.popup();oInpagePrompt_Warning=null;}
return false;}}}
if(IE){document.onkeydown=checkEnter;}
else{window.onkeypress=checkEnter;}
oInpagePrompt_Warning.init();}
Comeditor.theme={full:['undo','redo','-','fontsize','fontname','bold','italic','underline','-','forecolor','backcolor','-','justifyleft','justifycenter','justifyright','-','unorderedlist','orderedlist','outdent','indent','-','smiley','-','link','image','flash','mplayer'],article:['fontsize2','fontname2','bold','italic','underline','-','forecolor','-','justifyleft','justifycenter','justifyright','-','smiley','-','link','image','flash'],team:['fontsize2','fontname2','bold','italic','underline','-','forecolor','-','justifyleft','justifycenter','justifyright','-','smiley','-','link','image','flash','mplayer'],poster:['fontsize2','fontname2','bold','italic','underline','-','forecolor','-','justifyleft','justifycenter','justifyright','-','link'],alumni:[]};Comeditor.prototype.fAddBtn={undo:function(){var undoButton=new ToolBarButton("",new UiImage(this.sImgDir+"undo.gif",20,20));this.editorToolBar.add(undoButton);undoButton.setToolTipText("撤销 (Ctrl+Z)");undoButton.richEditor=this.richEditor;undoButton.onClick=function(){this.richEditor.execCommand("Undo",false,null);}
undoButton.checkState=function(){undoButton.setEnabled(this.queryCommandEnabled("Undo"));}
return undoButton;},redo:function(){var redoButton=new ToolBarButton("",new UiImage(this.sImgDir+"redo.gif",20,20));this.editorToolBar.add(redoButton);redoButton.setToolTipText("恢复 (Ctrl+Y)");redoButton.richEditor=this.richEditor;redoButton.onClick=function(){this.richEditor.execCommand("Redo",false,null);}
redoButton.checkState=function(){redoButton.setEnabled(this.queryCommandEnabled("Redo"));}
return redoButton;},fontsize:function(){var arrFontSize=[{value:"",text:"默认大小"},{value:"1",text:"一号"},{value:"2",text:"二号"},{value:"3",text:"三号"},{value:"4",text:"四号"},{value:"5",text:"五号"},{value:"6",text:"六号"},{value:"7",text:"七号"}];var oToolbarSelect_FontSize=new ToolbarSelect(arrFontSize,'字体大小');this.editorToolBar.add(oToolbarSelect_FontSize);oToolbarSelect_FontSize.richEditor=this.richEditor;oToolbarSelect_FontSize.onChange=function(){this.richEditor.execCommand("FontSize",false,this.getValue());}
oToolbarSelect_FontSize.checkState=function(){oToolbarSelect_FontSize.setValue(this.queryCommandValue("FontSize"));}
return oToolbarSelect_FontSize;},fontname:function(){var arrFontName=[{value:"",text:"默认字体"},{value:"Arial",text:"Arial"},{value:"Arial Black",text:"Arial Black"},{value:"Comic Sans MS",text:"Comic Sans MS"},{value:"Courier New",text:"Courier New"},{value:"Times New Roman",text:"Times New Roman"},{value:"Verdana",text:"Verdana"},{value:"Tahoma",text:"Tahoma"},{value:"宋体",text:"宋体"},{value:"隶书",text:"隶书"},{value:"黑体",text:"黑体"},{value:"幼圆",text:"幼圆"},{value:"楷体_GB2312",text:"楷体_GB2312"}];var oToolbarSelect_FontName=new ToolbarSelect(arrFontName,'字体名称');this.editorToolBar.add(oToolbarSelect_FontName);oToolbarSelect_FontName.richEditor=this.richEditor;oToolbarSelect_FontName.onChange=function(){this.richEditor.execCommand("FontName",false,this.getValue());}
oToolbarSelect_FontName.checkState=function(){oToolbarSelect_FontName.setValue(this.queryCommandValue("FontName"));}
return oToolbarSelect_FontName;},fontname2:function(){var aFontName=[{value:"Arial",text:"Arial"},{value:"Arial Black",text:"Arial Black"},{value:"Comic Sans MS",text:"Comic Sans MS"},{value:"Courier New",text:"Courier New"},{value:"Times New Roman",text:"Times New Roman"},{value:"Verdana",text:"Verdana"},{value:"Tahoma",text:"Tahoma"},{value:"宋体",text:"宋体"},{value:"隶书",text:"隶书"},{value:"黑体",text:"黑体"},{value:"幼圆",text:"幼圆"},{value:"楷体_GB2312",text:"楷体_GB2312"}];var imgFontName=new UiImage(this.sImgDir+"font_family.gif",20,20);var oToolBarMenuSelect_FontName=new ToolBarMenuSelect(aFontName,this.oMenuGroup,'',imgFontName,{getHtml:function(){return'<font face="'+this.value+'" style="width: 118px;">'+this.text+'</font>';}},true);oToolBarMenuSelect_FontName.setToolTipText('字体名称');this.editorToolBar.add(oToolBarMenuSelect_FontName);var _this=this;oToolBarMenuSelect_FontName.onChoose=function(){_this.richEditor.execCommand("FontName",false,oToolBarMenuSelect_FontName.getValue());}
return imgFontName;},fontsize2:function(){var aFontSize=[{value:"1",text:"一号"},{value:"2",text:"二号"},{value:"3",text:"三号"},{value:"4",text:"四号"},{value:"5",text:"五号"},{value:"6",text:"六号"},{value:"7",text:"七号"}];var imgFontSize=new UiImage(this.sImgDir+"font_size.gif",20,20);var oToolBarMenuSelect_FontSize=new ToolBarMenuSelect(aFontSize,this.oMenuGroup,'',imgFontSize,{getHtml:function(){return'<font size="'+this.value+'" style="width: 96px;">'+this.text+'</font>';}},true);oToolBarMenuSelect_FontSize.setToolTipText('字体大小');this.editorToolBar.add(oToolBarMenuSelect_FontSize);var _this=this;oToolBarMenuSelect_FontSize.onChoose=function(){_this.richEditor.execCommand("FontSize",false,oToolBarMenuSelect_FontSize.getValue());}
return imgFontSize;},bold:function(){var boldButton=new ToolBarToggleButton("",new UiImage(this.sImgDir+"bold.gif",20,20));this.editorToolBar.add(boldButton);boldButton.setToolTipText("粗体 (Ctrl+B)");boldButton.richEditor=this.richEditor;boldButton.onClick=function(){this.richEditor.execCommand("Bold",false,null);}
boldButton.checkState=function(){boldButton.setChecked(this.queryCommandState("Bold"));}
return boldButton;},italic:function(){var italicButton=new ToolBarToggleButton("",new UiImage(this.sImgDir+"italic.gif",20,20));this.editorToolBar.add(italicButton);italicButton.setToolTipText("倾斜 (Ctrl+I)");italicButton.richEditor=this.richEditor;italicButton.onClick=function(){this.richEditor.execCommand("Italic",false,null);}
italicButton.checkState=function(){italicButton.setChecked(this.queryCommandState("Italic"));}
return italicButton;},underline:function(){var underlineButton=new ToolBarToggleButton("",new UiImage(this.sImgDir+"underline.gif",20,20));this.editorToolBar.add(underlineButton);underlineButton.setToolTipText("下划线 (Ctrl+U)");underlineButton.richEditor=this.richEditor;underlineButton.onClick=function(){this.richEditor.execCommand("Underline",false,null);}
underlineButton.checkState=function(){underlineButton.setChecked(this.queryCommandState("Underline"));}
return underlineButton;},forecolor:function(){var tbmForeColor=new ToolBarMenu();this.oMenuGroup.add(tbmForeColor);var pallette=new Pallette();pallette.setParent(tbmForeColor);tbmForeColor.richEditor=this.richEditor;tbmForeColor.onPickColor=function(sColor){this.richEditor.execCommand('ForeColor',false,sColor);this.hide();};var imgForeColor=new UiImage(this.sImgDir+"forecolor.gif",20,20);var mbForeColor=new ToolBarMenuButton("",imgForeColor,tbmForeColor);mbForeColor.setToolTipText("字体颜色");this.editorToolBar.add(mbForeColor);return tbmForeColor;},backcolor:function(){var tbmBackColor=new ToolBarMenu();this.oMenuGroup.add(tbmBackColor);var pallette2=new Pallette();pallette2.setParent(tbmBackColor);tbmBackColor.richEditor=this.richEditor;tbmBackColor.onPickColor=function(sColor){this.richEditor.execCommand('BackColor',false,sColor);this.hide();};var imgBackColor=new UiImage(this.sImgDir+"backcolor.gif",20,20);var mbBackColor=new ToolBarMenuButton("",imgBackColor,tbmBackColor);mbBackColor.setToolTipText("背景颜色");this.editorToolBar.add(mbBackColor);return mbBackColor;},smiley:function(){var tbmSmiley=new ToolBarMenu();this.oMenuGroup.add(tbmSmiley);var oSmileyPanel=new SmileyPanel(user_gender);oSmileyPanel.setParent(tbmSmiley);tbmSmiley.richEditor=this.richEditor;tbmSmiley.onPickSmiley=function(sUrl){this.richEditor.execCommand("InsertImage",false,sUrl);this.hide();};var imgSmiley=new UiImage(this.sImgDir+"smiley.gif",20,20);var mbSmiley=new ToolBarMenuButton("",imgSmiley,tbmSmiley);mbSmiley.setToolTipText("表情");this.editorToolBar.add(mbSmiley);return tbmSmiley;},justifyleft:function(){var justifyLeftButton=new ToolBarRadioButton("",new UiImage(this.sImgDir+"justifyleft.gif",20,20),this.justifyGroup);this.editorToolBar.add(justifyLeftButton);justifyLeftButton.setToolTipText("左对齐"+(!IE?"(Ctrl + L)":""));justifyLeftButton.richEditor=this.richEditor;justifyLeftButton.onClick=function(){this.richEditor.execCommand("JustifyLeft",false,null);}
justifyLeftButton.checkState=function(){justifyLeftButton.setChecked(this.queryCommandState("JustifyLeft"));}
return justifyLeftButton;},justifycenter:function(){var justifyCenterButton=new ToolBarRadioButton("",new UiImage(this.sImgDir+"justifycenter.gif",20,20),this.justifyGroup);this.editorToolBar.add(justifyCenterButton);justifyCenterButton.setToolTipText("居中"+(!IE?"(Ctrl + E)":""));justifyCenterButton.richEditor=this.richEditor;justifyCenterButton.onClick=function(){this.richEditor.execCommand("JustifyCenter",false,null);}
justifyCenterButton.checkState=function(){justifyCenterButton.setChecked(this.queryCommandState("JustifyCenter"));}
return justifyCenterButton;},justifyright:function(){var justifyRightButton=new ToolBarRadioButton("",new UiImage(this.sImgDir+"justifyright.gif",20,20),this.justifyGroup);this.editorToolBar.add(justifyRightButton);justifyRightButton.setToolTipText("右对齐"+(!IE?"(Ctrl + R)":""));justifyRightButton.richEditor=this.richEditor;justifyRightButton.onClick=function(){this.richEditor.execCommand("JustifyRight",false,null);}
justifyRightButton.checkState=function(){justifyRightButton.setChecked(this.queryCommandState("JustifyRight"));}
return justifyRightButton;},orderedlist:function(){var orderedButton=new ToolBarToggleButton("",new UiImage(this.sImgDir+"orderedlist.gif",20,20));this.editorToolBar.add(orderedButton);orderedButton.setToolTipText("编号列表");orderedButton.richEditor=this.richEditor;var buttons=this.buttons;orderedButton.onClick=function(){if(buttons.unorderedlist.getChecked())
{buttons.unorderedlist.setChecked(false);}
this.richEditor.execCommand("InsertOrderedList",false,null);}
orderedButton.checkState=function(){orderedButton.setChecked(this.queryCommandState("InsertOrderedList"));}
return orderedButton;},unorderedlist:function(){var unorderedListButton=new ToolBarToggleButton("",new UiImage(this.sImgDir+"unorderedlist.gif",20,20));this.editorToolBar.add(unorderedListButton);unorderedListButton.setToolTipText("项目符号列表");unorderedListButton.richEditor=this.richEditor;var buttons=this.buttons;unorderedListButton.onClick=function(){if(buttons.orderedlist.getChecked())
{buttons.orderedlist.setChecked(false);}
this.richEditor.execCommand("InsertUnorderedList",false,null);}
unorderedListButton.checkState=function(){unorderedListButton.setChecked(this.queryCommandState("InsertUnorderedList"));}
return unorderedListButton;},outdent:function(){var outdentButton=new ToolBarButton("",new UiImage(this.sImgDir+"outdent.gif",20,20));this.editorToolBar.add(outdentButton);outdentButton.setToolTipText("减少缩进量");outdentButton.richEditor=this.richEditor;outdentButton.onClick=function(){this.richEditor.execCommand("Outdent",false,null);}
outdentButton.checkState=function(){}
return outdentButton;},indent:function(){var indentButton=new ToolBarButton("",new UiImage(this.sImgDir+"indent.gif",20,20));this.editorToolBar.add(indentButton);indentButton.setToolTipText("增加缩进量");indentButton.richEditor=this.richEditor;indentButton.onClick=function(){this.richEditor.execCommand("Indent",false,null);}
indentButton.checkState=function(){}
return indentButton;},

link:function(){
var linkButton=new ToolBarButton("",new UiImage(this.sImgDir+"link.gif",20,20));linkButton.setToolTipText("插入超链接");linkButton.richEditor=this.richEditor;linkButton.onClick=function(){var sUrl=window.prompt("输入链接的 URL 地址: (默认为http)","");if(sUrl){if(/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){}
else{sUrl='http://'+sUrl;}
if(this._textSelected){ this.richEditor.execCommand('CreateLink',false,sUrl);}
else{this.richEditor.insertHTML('<a href="'+sUrl+'" target="_blank">'+sUrl+'</a>&nbsp;');}}}

linkButton.setCreateMode=function(bEnabled){this._textSelected=bEnabled;}
this.editorToolBar.add(linkButton);

var unlinkButton=new ToolBarButton("",new UiImage(this.sImgDir+"unlink.gif",20,20));unlinkButton.setToolTipText("删除超链接");unlinkButton.richEditor=this.richEditor;unlinkButton.onClick=function(){this.richEditor.execCommand("Unlink",false,null);}
unlinkButton.setEnabled=function(bEnabled){if(bEnabled){unlinkButton.getNode().style.display='';linkButton.getNode().style.display='none';}
else{unlinkButton.getNode().style.display='none';linkButton.getNode().style.display='';}}
this.editorToolBar.add(unlinkButton);
window.setTimeout(function(){unlinkButton.setEnabled(false);},1000);

return{checkState:function(){linkButton.setCreateMode(this.queryCommandEnabled("CreateLink"));unlinkButton.setEnabled(this.queryCommandEnabled("Unlink"));}};},

image:function(){var imageButton=new ToolBarButton('',new UiImage(this.sImgDir+'image.gif',20,20));this.editorToolBar.add(imageButton);imageButton.setToolTipText('插入图片');imageButton.richEditor=this.richEditor;imageButton.onClick=function(){var sUrl=window.prompt('输入图片的 URL 地址:','');if(sUrl){if(/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){}
else{sUrl='http://'+sUrl;}
this.richEditor.execCommand('InsertImage',false,sUrl);}}
this.imageButton=imageButton;return imageButton;},
	
flash:function(){var flashButton=new ToolBarButton('',new UiImage(this.sImgDir+'flash.gif',20,20));this.editorToolBar.add(flashButton);flashButton.setToolTipText('插入Flash');flashButton.richEditor=this.richEditor;var oThis=this;flashButton.onClick=function(){var sUrl=window.prompt('输入 Flash 的 URL 地址 或<object>代码。\n注意：这并不会上传本地文件。只能引用网络上的资源。','');if(sUrl){sUrl=trim(sUrl);if(/<object/.test(sUrl)){this.richEditor.insertHTML(this.richEditor.object2image4flash(sUrl));return;}
if(!/\.swf/.test(sUrl)){alert('警告：看上去不是flash格式的文件，可能无法正常播放。');return;}
if(!/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){sUrl='http://'+sUrl;}
this.richEditor.insertHTML(['<img class="flash_placeholder" src="',oThis.sImgDir,'flash_placeholder.jpg" title="',sUrl,'" width="',oThis.CONFIG.nFlashWidth,'" height="',oThis.CONFIG.nFlashHeight,'" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join(''));}}
this.flashButton=flashButton;return flashButton;},

mplayer:function(){
var mplayerButton=new ToolBarButton('',new UiImage(this.sImgDir+'mplayer.gif',20,20));this.editorToolBar.add(mplayerButton);mplayerButton.setToolTipText('插入mplayer');mplayerButton.richEditor=this.richEditor;var oThis=this;mplayerButton.onClick=function(){var sUrl=window.prompt('输入Windows Media Player 所支持的媒体（wmv、avi、mpg、mp3、wav等等，但不包括 RealPlayer 才支持的 rm 、rmvb等）的 URL 地址。','');if(sUrl){if(!/^([a-z]*):\/\/[\x21-\x7E]+/i.test(sUrl)){sUrl='http://'+sUrl;}
sUrl=trim(sUrl);if(/ /.test(sUrl)){sUrl=encodeURI(sUrl);}
if(/\.(mid|midi|rmi|aif|aiff|au|snd|wav|wma|wax|mp3|m3u|ogg)$/.test(sUrl)){this.richEditor.insertHTML(['<img class="audio_placeholder" src="',oThis.sImgDir,'audio_placeholder.jpg" title="',sUrl,'" width="',oThis.CONFIG.nMplayerWidth,'" height="45" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join(''));}
else{this.richEditor.insertHTML(['<img class="video_placeholder" src="',oThis.sImgDir,'video_placeholder.jpg" title="',sUrl,'" width="',oThis.CONFIG.nMplayerWidth,'" height="',oThis.CONFIG.nMplayerHeight,'" ondblclick="parent.RichEditor.modifySrc(this)"/>'].join(''));}}}
this.mplayerButton=mplayerButton;return mplayerButton;}

,'-':function(){var separator=new ToolBarSeparator;this.editorToolBar.add(separator);return}}
Comeditor.prototype.loadToolbar=function(aBtn){this.CONFIG.nFlashWidth=500;this.CONFIG.nFlashHeight=400;this.CONFIG.nMplayerWidth=400;this.CONFIG.nMplayerHeight=345;var oThis=this;this.buttons={};this.oMenuGroup=new MenuGroup();this.justifyGroup=new RadioGroup();for(var i=0;i<aBtn.length;i++){this.buttons[aBtn[i]]=this.fAddBtn[aBtn[i]].call(this);}
this.richEditor.setTop(this.editorToolBar.getHeight()+this.editorToolBar.getHeight());this.richEditor.commandStateChecker=function(){for(var i=0;i<aBtn.length;i++){try{oThis.buttons[aBtn[i]].checkState.call(this);}
catch(e){}}}
this.richEditor.loadContent=function(){this.setContentHtml(trim(oThis.txtArea.value));}}
function trim(s){return s.replace(/(^\s+)|(\s+$)/g,'');}

$(function(){
	if(!window.oComeditor){
		oComeditor=new Comeditor('comeditor');
		//oComeditor.init();
	}
});
//window.setTimeout(function(){if(!window.oComeditor){oComeditor=new Comeditor();}oComeditor.init('comeditor');},3000);
