// 当前模式
var sCurrMode = null;
var bEditMode = null;
// 连接对象
var oLinkField = null;
var sBaseUrl = document.location.protocol + '//' + document.location.host ;

// 浏览器版本检测
var borderShown = "no";

var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;

var g_state
function _setSize() {
	document.all.idPopup.style.pixelLeft = (document.body.clientWidth - idPopup.document.all.puRegion.offsetWidth) / 2	
}

function _initEditor() {
	g_state = new _CState()
	_CPopup_Init()
	setTimeout("_pageReady()",0)
}

//  _CState 
function _CState()
{
	this.selection		= null
	this.bMode			= true
	this.customButtons 	= false
	this.css = this.bgColor	= ""
	this.defaultSkin	= document.styleSheets.skin.cssText
	this.popupSkin		= document.styleSheets.popupSkin.cssText
	this.aLinks			= new Array()
	this.szSearch		= location.search.substring(1)
	this.aBindings		= new Array()
	this.aListPopups	= new Object()
	this.aCache			= new Object()
	this.RestoreSelection	= _CState_RestoreSelection
	this.GetSelection	= _CState_GetSelection
	this.SaveSelection	= _CState_SaveSelection
}

//  EDITOR PUBLIC (API)
function transform(htmlstring)
{
    var htmlsplit,imgsplit,somelink;
    var i,resu="",flag = 0;    
    if( htmlstring.indexOf("_263flash.jpg")!=-1 )
    {
        htmlsplit = htmlstring.split("_263flash.jpg");       
        for(i = 0; i < htmlsplit.length; i++)
        { 
            if(htmlsplit[i].indexOf("<IMG src=")!=-1)
            {  
                imgsplit = htmlsplit[i].split("<IMG src=");                                      
                resu = imgsplit[0] + "<embed height=\"400\" type=\"application/x-shockwave-flash\" width=\"550\" src="
                        + imgsplit[1]+ ".swf";                      
            }
            else if(htmlsplit[i].indexOf("<IMG align=")!=-1)
            {  
                imgsplit = htmlsplit[i].split("<IMG align=");                                      
                resu = imgsplit[0] + "<embed height=\"400\" type=\"application/x-shockwave-flash\" width=\"550\" align="
                        + imgsplit[1]+ ".swf";   
                flag = 1;            
            }
            else
            {
                resu += htmlsplit[i];
            }
        }
        if(flag == 1)
        {
            somelink = imgsplit[imgsplit.length-1].indexOf("src=");
            resu += "<br><br><br><br>如果无法看见邮件中的图片，请点击<a href=" + imgsplit[imgsplit.length-1].substr(somelink+4) +".swf\" target=\"_blank\">这里</a>"
        }
        else
        {
            resu += "<br><br><br><br>如果无法看见邮件中的图片，请点击<a href=" + imgsplit[imgsplit.length-1] +".swf\" target=\"_blank\">这里</a>"
        }
    }
    else
    {
        resu = htmlstring;
    }
    return resu;    
}

function setHTML(szHTML) 
{
if (g_state.bMode)
Composition.document.body.innerHTML = szHTML
else
Composition.document.body.innerText = szHTML
_Editor_MoveSelection(true)
}
function getHTML() 
{
var szRet = (g_state.bMode ? Composition.document.body.innerHTML : Composition.document.body.innerText)
var resu = transform(szRet);
return resu
}
function getText() {
var szRet = ""
if (g_state.bMode)
szRet = Composition.document.body.innerText
else {
setMode(true)
szRet = Composition.document.body.innerText
setMode(false)
}
return szRet
}
function getBody() 
{
var oRet = Composition.document.body
return oRet
}
function getWidth() 
{
var nRet = document.body.offsetWidth
return nRet
}
function getHeight() 
{
var nRet = document.body.offsetHeight
return nRet
}
function insertHTML(szHTML) 
{
var sType
var sel = g_state.GetSelection()
sType = sel.type
if (g_state.bMode) {
if (sType=="Control")
sel.item(0).outerHTML = szHTML
else 
sel.pasteHTML(szHTML)
}
else
sel.text = szHTML
}
function setFocus() {
Composition.focus()
}
function appendHTML(szHTML) {
if (g_state.bMode) 
Composition.document.body.insertAdjacentHTML("beforeEnd",szHTML)
else
Composition.document.body.insertAdjacentText("beforeEnd",szHTML)
}
function setBGColor(szValue) 
{
g_state.bgColor = szValue
if (g_state.bMode)
Composition.document.body.bgColor = g_state.bgColor
}
function getBGColor() 
{
var szRet = g_state.bgColor
return szRet
}
function setDefaultStyle(szValue) 
{
g_state.css = szValue
if (g_state.bMode)
Composition.document.body.style.cssText = g_state.css
}
function getDefaultStyle() 
{
var oRet = g_state.css
return oRet
}
function setSkin(szSkin) 
{
if (szSkin == null)
document.styleSheets.skin.cssText = g_state.defaultSkin
else
document.styleSheets.skin.cssText = szSkin
document.styleSheets.skin.disabled = false	
}
function setPopupSkin(szSkin) 
{
if (szSkin == null)
document.styleSheets.popupSkin.cssText = g_state.popupSkin
else
document.styleSheets.popupSkin.cssText = szSkin
_CPopup_Init()
}
function setToolbar(id,g_state) 
{
var el = document.all[id]
if (el)
el.style.display = (g_state) ? "" : "none"	
if (id=="tbmode")
_setSize()
}
function setLinks(arLinks) 
{
g_state.aLinks = arLinks
}
function setBindings(aBindings) 
{
if ((aBindings) && (aBindings.length>0)) 
{
g_state.aBindings = aBindings
for (var iField = DBSelect.length-1; iField > 0; iField--)
DBSelect[iField] = null
for (var iField = 0; iField < g_state.aBindings.length; iField++)
DBSelect.add(new Option(g_state.aBindings[iField]))
tbDBSelect.style.display = "inline"
}
else
tbDBSelect.style.display = ""
}

function addButton(sID,sButton) 
{
if (!sID)
tbButtons.insertAdjacentHTML("beforeEnd","<BR>")
else	
tbButtons.insertAdjacentHTML("beforeEnd","<INPUT TYPE=\"button\" ONCLICK=\"_userButtonClick(this)\" CLASS=\"userButton\" ID=\"" + sID + "\" VALUE=\"" + sButton + "\">&nbsp;")
g_state.customButtons = true
}
//  EDITOR PRIVATE
function _Format(szHow, szValue) {
var oSel	= g_state.GetSelection()
var sType   = oSel.type 
var oTarget = (sType == "None" ? Composition.document : oSel)
var oBlock  = (oSel.parentElement != null ? _CUtil_GetBlock(oSel.parentElement()) : oSel.item(0))
setFocus()
switch(szHow)
{
case "BackColor":
var el = null
if (oSel.parentElement != null) {
el =  _CUtil_GetElement(oSel.parentElement(),"TD")
if (!el) el =  _CUtil_GetElement(oSel.parentElement(),"TH")
if (!el) el =  _CUtil_GetElement(oSel.parentElement(),"TR")
if (!el) el =  _CUtil_GetElement(oSel.parentElement(),"TABLE")
}
else 
el = _CUtil_GetElement(oSel.item(0),"TABLE")
if (el)
el.bgColor = szValue
else
setBGColor(szValue)
break;
case "Justify":
if (oBlock) 
{
oBlock.style.textAlign = ""
if (((oBlock.tagName=="TABLE") || (oBlock.tagName=="IMG")) && (("left"==oBlock.align) && ("Left"==szValue))) {
oBlock.align = ""
break;
}	
oBlock.align = szValue
if ((oBlock.tagName=="HR") || ((oBlock.tagName=="IMG") && szValue!="Center")) break;
}
szHow=szHow+szValue
szValue=""
// Fall through
default:
oTarget.execCommand(szHow, false, szValue)
break
}
g_state.RestoreSelection()
setFocus()
return true
}

function _Editor_MoveSelection(bDir) {
var tr = Composition.document.body.createTextRange()
tr.collapse(bDir)
tr.select()
}
function _Editor_ClickHandler() {
g_state.selection = null
}
function _Editor_KeyDownHandler() {
var ev = this.parentWindow.event
if (ev.keyCode==9)
g_state.SaveSelection() 
else 
g_state.selection=null
}
function _Editor_DblClickHandler() {
// Shortcuts
var el = this.parentWindow.event.srcElement
if (el.tagName=="IMG")  {
el.removeAttribute("width")
el.removeAttribute("height")
el.style.removeAttribute("width")
el.style.removeAttribute("height")
el.width = el.width
el.height = el.height
}
if (el.tagName=="TABLE") 
_CPopup_Show('Table')
}

function _pageReady() 
{
Composition.document.body.oncontextmenu = new Function("return false")	
if (g_state.szSearch!="")
idPopup.document.domain = Composition.document.domain = document.domain = g_state.szSearch
//_Editor_MoveSelection(false)
if (self.parent.RTELoaded)
self.parent.RTELoaded(self)
if (document.styleSheets.skin.disabled) 
setSkin(null)
_setSize()
}
function _userButtonClick(el) 
{
if (parent.RTEButton) parent.RTEButton(self, el.id)
}

function _CState_RestoreSelection() 
{
if (this.selection) this.selection.select()
}
function _CState_GetSelection() 
{
var oSel = this.selection
if (!oSel) {
oSel = Composition.document.selection.createRange()
oSel.type = Composition.document.selection.type
}
return oSel
}
function _CState_SaveSelection() 
{
g_state.selection = Composition.document.selection.createRange()
g_state.selection.type = Composition.document.selection.type
}
//  POPUP (Link, table and image popup need to be worked on)
function _CPopup_Init() 
{
var sz  =   ""
+   "<HTML ID=popup>"
+	   "<STYLE>" 
+		   document.styleSheets.defPopupSkin.cssText 
+		   "\n" 
+		   document.styleSheets.popupSkin.cssText 
+	   "</STYLE>"
+	   "<SCRIPT>function IMAGELoaded(w) {parent._IMAGELoaded(w,self)}</SCRIPT>"
+	   "<BODY "
+		   "ONSCROLL=\"return false\" SCROLL=no TABINDEX=-1 "
+		   "ONSELECTSTART=\"return event.srcElement.tagName=='INPUT'\" "
+	   "><DIV ID=puRegion>"
+		   "<TABLE ID=header>"
+			   "<TR>"
+				   "<TH NOWRAP ID=caption></TH>"
+				   "<TH VALIGN=middle ALIGN=RIGHT><DIV ID=close ONCLICK=\"parent._CPopup_Hide()\">"
+					   L_CLOSEBUTTON_TEXT
+				   "</DIV></TH>"
+			   "</TR>"
+		   "</TABLE>"
+		   "<DIV ALIGN=CENTER ID=content></DIV>"
+	   "</DIV></BODY>"
+   "</HTML>"
idPopup.document.open("text/html","replace")
idPopup.document.write(sz)
idPopup.document.close()
}
function _CPopup_InsertDatabound(eSelect)
{
if (eSelect.selectedIndex != 0)
{
var sElemName = eSelect.options[eSelect.selectedIndex].text;
var iLen = sElemName.length
sElemName = sElemName.replace(/"/g, '&#034;')
insertHTML('<INPUT CLASS=DataBound SIZE=' + (iLen + 2) + ' NAME="' + sElemName +'" VALUE=" ' + sElemName + ' ">')
eSelect.selectedIndex = 0;
Composition.focus()	
}
}
function _CPopup_Hide() 
{
//Composition.focus()
document.all.idPopup.style.zIndex=-1
document.all.idPopup.style.visibility = "hidden"	
idPopup.document._type = ""
idPopup.document.onkeydown=idPopup.document.onmouseover=idPopup.document.onclick = null
Composition.focus()
}
function _CPopup_Show(szType) 
{
var oRenderer, szCacheKey = "PopupRenderer." + szType
//Composition.focus()
if (idPopup.document._type == szType)
{
_CPopup_Hide()
}
else
{
document.all.idPopup.style.zIndex = -1
oRenderer = g_state.aCache[szCacheKey]
if ((!oRenderer) || ("Link"==szType))
g_state.aCache[szCacheKey] = oRenderer = new _CPopupRenderer(szType)
// Force Sizing
document.all.idPopup.style.visibility = ""
idPopup.document.all.puRegion.style.pixelHeight = 80;
idPopup.document.all.puRegion.style.pixelWidth = 340
idPopup.document._type					= szType
idPopup.document._renderer				= oRenderer
idPopup.document.all.caption.innerText	= oRenderer.GetCaption()
idPopup.document.all.content.innerHTML	= oRenderer.GetHTML()
idPopup.document.onkeydown				= new Function("this._renderer.OnKeyDown()")
idPopup.document.onmouseover			= new Function("this._renderer.OnMouseOver()")
idPopup.document.onclick				= new Function("this._renderer.OnClick()")
oRenderer.ResetContext(idPopup.document)
setTimeout("_CPopupRenderer_Display('" + szType + "')",0)
}
}
function _CPopupRenderer_Display(szType) {
var oRenderer, szCacheKey = "PopupRenderer." + szType
oRenderer = g_state.aCache[szCacheKey]
if (oRenderer.autoSize) {	
idPopup.document.all.puRegion.style.pixelHeight = document.all.idPopup.style.pixelHeight = idPopup.document.all.puRegion.offsetHeight
idPopup.document.all.puRegion.style.pixelWidth = document.all.idPopup.style.pixelWidth = idPopup.document.all.puRegion.offsetWidth + 50
document.all.idPopup.style.pixelLeft = (document.body.clientWidth - idPopup.document.all.puRegion.offsetWidth) / 2
}
else { 
idPopup.document.all.puRegion.style.pixelHeight  = document.all.idPopup.style.pixelHeight = document.body.clientHeight - idToolbar.offsetHeight- document.all.idMode.offsetHeight-20
idPopup.document.all.puRegion.style.pixelWidth  = document.all.idPopup.style.pixelWidth = document.body.clientWidth - 50
document.all.idPopup.style.pixelLeft = 25
}
document.all.idPopup.style.zIndex=2
idPopup.focus()
}
function _CPopupRenderer(szType)
{
this.szType		=  szType
this.elCurrent	=  this.oDocument  = null
this.ResetContext   =  _CPopupRenderer_ResetContext
this.GetCaption	= _CPopupRenderer_GetCaption	
this.GetHTML	= _CPopupRenderer_GetHTML
this.autoSize	= true
this.OnMouseOver = new Function()
this.OnKeyDown	= _CListPopupRenderer_GenericOnKeyDown
switch(szType)
{
case "formatblock":
case "font":
case "fontsize":
this.OnMouseOver= _CListPopupRenderer_OnMouseOver
this.OnKeyDown  = _CListPopupRenderer_OnKeyDown
case "BackColor": 
case "ForeColor":
this.OnClick	= _CListPopupRenderer_OnClick
this.Highlight  = _CListPopupRenderer_Highlight
this.Select		= _CListPopupRenderer_Select
break
default:
this.OnClick	= new Function()
break	
}
switch(szType)
{
case "formatblock":
this.szCaption		= L_PUTITLEPARAGRAPHSTYLE_TEXT
this.PrepareHTML	= _CFormatBlockPopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
break
case "font":
this.szCaption		= L_PUTITLEFONTFACE_TEXT
this.PrepareHTML	= _CFontFacesPopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
break
case "fontsize":
this.szCaption		= L_PUTITLEFONTSIZE_TEXT
this.PrepareHTML	=_CFontSizesPopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
break
case "Link":
this.szCaption		= L_PUTITLELINK_TEXT
this.PrepareHTML	= _CLinkPopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
break
case "Table": 
this.szCaption		= L_PUTITLENEWTABLE_TEXT
this.PrepareHTML	= _CTablePopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
break
case "Image":
this.szCaption		= L_PUTITLEIMAGE_TEXT
this.PrepareHTML	= _CImagePopupRenderer_PrepareHTML
this.szHTML			= this.PrepareHTML()
this.autoSize		= false
break
case "BackColor": 
this.szCaption		= L_PUTITLEBGCOLOR_TEXT
this.szHTML			= "<DIV ID=ColorPopup ALIGN=CENTER>" + _CUtil_BuildColorTable("") + "</DIV>"
break
case "ForeColor":
this.szCaption		= L_PUTITLETEXTCOLOR_TEXT
this.szHTML			= "<DIV ID=ColorPopup ALIGN=CENTER>" + _CUtil_BuildColorTable("") + "</DIV>"
break
case "Emoticon":
this.szCaption		= L_PUTITLEEMOTICON_TEXT
this.PrepareHTML	= _CEmoticonRenderer_PrepareHTML1
this.szHTML			= this.PrepareHTML()
break
case "Emoticon2":
this.szCaption		= L_PUTITLEEMOTICON_TEXT
this.PrepareHTML	= _CEmoticonRenderer_PrepareHTML2
this.szHTML			= this.PrepareHTML()
break

case "Emoticon3":
this.szCaption		= L_PUTITLEEMOTICON_TEXT
this.PrepareHTML	= _CEmoticonRenderer_PrepareHTML3
this.szHTML			= this.PrepareHTML()
break

default:
this.szCaption		= ""
break
}
}
function _CPopupRenderer_ResetContext(oDoc)
{
this.oDocument  = oDoc
this.elCurrent  = null
if (this.szType=="Table") {
var oSel	= Composition.document.selection.createRange() 
var oBlock  = (oSel.parentElement != null ? _CUtil_GetElement(oSel.parentElement(),"TABLE") : _CUtil_GetElement(oSel.item(0),"TABLE"))
if (oBlock!=null) {
oDoc.all.tabEdit.className=""
oDoc.all.tabEditBodytxtPadding.value = oBlock.cellPadding
oDoc.all.tabEditBodytxtSpacing.value = oBlock.cellSpacing
oDoc.all.tabEditBodytxtBorder.value = oBlock.border
oDoc.all.tabEditBodytxtBorderColor.value = oBlock.borderColor
oDoc.all.tabEditBodytxtBackgroundImage.value = oBlock.background
oDoc.all.tabEditBodytxtBackgroundColor.value = oBlock.bgColor
}
oDoc.elCurrent = oBlock
}
}
function _CPopupRenderer_GetCaption()
{
return this.szCaption
}
function _CPopupRenderer_GetHTML()
{
return this.szHTML
}
function _CEmoticonRenderer_PrepareHTML1() {
var sz = "<DIV ALIGN=center>"
for (var i=0; i < arEmoticons1.length-50; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=2 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons1.length-50; i < arEmoticons1.length-40; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=1 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons1.length-40; i < arEmoticons1.length-30; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=2 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons1.length-30; i < arEmoticons1.length-20; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=1 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons1.length-20; i < arEmoticons1.length-10; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=2 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons1.length-10; i < arEmoticons1.length; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT1 + arEmoticons1[i] + "\" HSPACE=1 VSPACE=1>"
if ((i+1)%10==0) sz+="<BR>"
}
		
//if (i%5!=0) sz+="<BR>"
//for (var i=0; i < arBigEmoticons.length; i++) 
//{
//sz  +=  "<IMG TABINDEX=" + (i+arEmoticons.length) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT + arBigEmoticons[i] + "\" WIDTH=20 HEIGHT=20 HSPACE=3 VSPACE=3>"
//if ((i+1)%6==0) sz+="<BR>"
//}			
sz+="</DIV>"
return sz
}

function _CEmoticonRenderer_PrepareHTML2() {
var sz = "<DIV ALIGN=center>"
for (var i=0; i < arEmoticons2.length-2; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT2 + arEmoticons2[i] + "\" HSPACE=2 VSPACE=5>"
if ((i+1)%10==0) sz+="<BR>"
}
for (var i=arEmoticons2.length-2; i < arEmoticons2.length; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT2 + arEmoticons2[i] + "\" HSPACE=10 VSPACE=5>"
}		
		
sz+="</DIV>"
return sz
}

function _CEmoticonRenderer_PrepareHTML3() {
var sz = "<DIV ALIGN=center>"
for (var i=0; i < arEmoticons3.length-3; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT3 + arEmoticons3[i] + "\" HSPACE=2 VSPACE=5>"
if ((i+1)%10==0) sz+="<BR>"
}	
for (var i=arEmoticons3.length-3; i < arEmoticons3.length; i++) 
{
sz  +=  "<IMG TABINDEX=" + (i+1) + " ONCLICK=\"parent._CEmoticonRenderer_Select(this)\" CLASS=emoticon SRC=\"" + L_EMOTICONPATH_TEXT3 + arEmoticons3[i] + "\" HSPACE=10 VSPACE=5>"
}		
			
sz+="</DIV>"
return sz
}


function _CEmoticonRenderer_Select(elImg) {
insertHTML("<IMG SRC=\"" + elImg.src + "\" WIDTH=" + elImg.width + " HEIGHT=" + elImg.height + ">")
g_state.RestoreSelection()
_CPopup_Hide()
}
function _CFontSizesPopupRenderer_PrepareHTML()
{   
var sz  =  "<TABLE ALIGN=center ID=idList CELLSPACING=0 CELLPADDING=0>"
for (var i=1; i <= 7; i++) 
{
sz  +=  ""
+   "<TR>"
+	   "<TD NOWRAP "
+		   "_item=" + i + " "
+		   "ALIGN=center "
+		   "STYLE=\"margin:0pt;padding:0pt\""
+	   ">"
+		   "<FONT SIZE=" + i + ">" 
+			   L_STYLESAMPLE_TEXT + "(" + i + ")"
+		   "</FONT>"
+	   "</TD>"
+   "</TR>"
}			
sz  +=  "</TABLE>"
return sz
}
function _CFontFacesPopupRenderer_PrepareHTML()
{   
var sz  =  "<TABLE ALIGN=center ID=idList CELLSPACING=0 CELLPADDING=0>"
for (var i=0; i < defaultFonts.length; i++) 
{
sz  +=  ""
+   "<TR>"
+	   "<TD NOWRAP "
+		   "_item=" + i + " "
+		   "ALIGN=center "
+		   "STYLE=\"margin:0pt;padding:0pt\""
+	   ">"
+		   "<FONT FACE=\"" + defaultFonts[i][0] + "\">" 
+			   defaultFonts[i][1] 
+		   "</FONT>"
+			(defaultFonts[i][2] ? ("(" + defaultFonts[i][1] + ")") : "")
+	   "</TD>"
+   "</TR>"
}
//	sz += "<TR><TD ONCLICK=\"parent._CFontFacesPopupRenderer_InsertOther(this)\" ALIGN=center _item=\"custom\" STYLE=\"margin:0pt;padding:0pt\" NOWRAP><FONT ID=customFont>" + L_CUSTOMFONT_TEXT + "</FONT></TR>"
sz  +=  "</TABLE>"
return sz
}
function _CFontFacesPopupRenderer_InsertOther(el) {
if (el._item=="custom") {
el._item = "input"
var sz = "<INPUT ONSELECTSTART=\"event.cancelBubble=true\" ONKEYDOWN=\"event.cancelBubble=true\" ONKEYPRESS=\"if (event.keyCode==13) {this.face=this.value;document._renderer.Select(this.parentElement)};event.cancelBubble=true\" VALUE=\"" + L_CUSTOMFONTENTRY_TEXT + "\" ONFOCUS=\"if (this.value==this.defaultValue) this.select()\" TYPE=text>"
el.innerHTML = sz
el.children[0].focus()
}
el.document.parentWindow.event.cancelBubble = true	
}
function _CFormatBlockPopupRenderer_PrepareHTML()
{   
var sz, defaultParagraphs   = new Array()
defaultParagraphs[0] = new Array("<P>", L_STYLENORMAL_TEXT + " (P)")	
for (var i=1; i <= 6; i++) 
defaultParagraphs[i] = new Array("<H"+i+">", L_STYLEHEADING_TEXT + i + " (H" + i + ")")	
defaultParagraphs[7] = new Array("<PRE>", L_STYLEFORMATTED_TEXT + "(PRE)")
sz  =  "<TABLE CLASS=block ALIGN=center ID=idList CELLSPACING=0 CELLPADDING=0>"
for (var i=0; i < defaultParagraphs.length; i++) 
{
sz  +=  ""
+   "<TR>"
+	   "<TD NOWRAP "
+		   "_item=" + i + " "
+		   "ALIGN=center "
+		   "STYLE=\"margin:0pt;padding:0pt\""
+	   ">"
+		   defaultParagraphs[i][0] 
+		   defaultParagraphs[i][1] 
+		   "</" + defaultParagraphs[i][0].substring(1) 
+	   "</TD>"
+   "</TR>"
}
sz  +=  "</TABLE>"
return sz
}
function _CImagePopupRenderer_PrepareHTML()
{   
return "<IFRAME ID=idPhotos WIDTH=98% HEIGHT=90% STYLE=\"visibility: hidden;border: none\" SRC=\"photos/photos.htm" + ((g_state.szSearch!="") ? ("?" + g_state.szSearch) : "") +  "\"></IFRAME>"
}
function _IMAGELoaded(wPhotos,wPopup) {
wPhotos.setBGColor("#F1F1F1")
wPopup.document.all.idPhotos.style.visibility = ""
}
function _CTablePopupRenderer_PrepareHTMLPage(szID,bDisplay) {
var sz=""
+   "<TABLE height=100% " + ((!bDisplay) ? " style=\"display: none\"" : "") + " width=100% CELLSPACING=0 CELLPADDING=0 ID=" + szID + ">"
+	   "<TR ID=tableContents>"
+		   "<TD ID=tableOptions VALIGN=TOP NOWRAP WIDTH=150 ROWSPAN=2>"
+			   "<A HREF=\"javascript:parent._CTablePopupRenderer_Select(this,'" + szID + "','prop1')\">"
+				   L_TABLEROWSANDCOLS_TEXT
+			   "</A>"
+			   "<BR>"
+			   "<A HREF=\"javascript:parent._CTablePopupRenderer_Select(this,'" + szID + "','prop2')\">"
+				   L_TABLEPADDINGANDSPACING_TEXT
+			   "</A>"
+			   "<BR>"
+			   "<A HREF=\"javascript:parent._CTablePopupRenderer_Select(this,'" + szID + "','prop3')\">"
+				   L_TABLEBORDERS_TEXT
+			   "</A>"
+			   "<BR>"
+			   "<A HREF=\"javascript:parent._CTablePopupRenderer_Select(this,'" + szID + "','prop4')\">"
+				   L_TABLEBG_TEXT
+			   "</A>"
+			   "<BR>"
+		   "</TD>"
+		   "<TD BGCOLOR=black ID=puDivider ROWSPAN=2>"
+		   "</TD>"
+		   "<TD ID=tableProps VALIGN=TOP>"
if (szID=="tabNewBody") {
sz+= "<DIV ID='" + szID + "prop1'>"
+	"<P CLASS=tablePropsTitle>" + L_TABLEROWSANDCOLS_TEXT + "</P>"
+  "<TABLE><TR><TD>"
+				   L_TABLEINPUTROWS_TEXT
+				   "</TD><TD><INPUT SIZE=2 TYPE=text ID=" + szID + "txtRows VALUE=2 >"
+				   "</TD></TR><TR><TD>"
+				   L_TABLEINPUTCOLUMNS_TEXT
+				   "</TD><TD><INPUT SIZE=2 TYPE=text ID=" + szID + "txtColumns VALUE=2 >"
+			   "</TD></TR></TABLE></DIV>" 
} 
else  {
sz+= "<DIV ID='" + szID + "prop1'>"
+	"<P CLASS=tablePropsTitle>" + L_TABLEROWSANDCOLS_TEXT + "</P>"	
+   "<INPUT type=button ID=" + szID + "txtRows VALUE=\"" + L_TABLEINSERTROW_TEXT + "\" ONCLICK=\"parent._CTablePopupRenderer_AddRow(this)\"><P>"
+   "<INPUT type=button ID=" + szID + "txtCells VALUE=\"" + L_TABLEINSERTCELL_TEXT + "\" ONCLICK=\"parent._CTablePopupRenderer_AddCell(this)\"><BR>"
+	"</DIV>" 
}
sz +=			   "<DIV ID='" + szID + "prop2' STYLE=\"display: none\">"
+					"<P CLASS=tablePropsTitle>" + L_TABLEPADDINGANDSPACING_TEXT + "</P>"
+				   L_TABLEINPUTCELLPADDING_TEXT
+				   "<INPUT SIZE=2 TYPE=text ID=" + szID + "txtPadding VALUE=0>"
+				   "<BR>"
+				   L_TABLEINPUTCELLSPACING_TEXT
+				   "<INPUT SIZE=2 TYPE=text ID=" + szID + "txtSpacing VALUE=0>"
+			   "</DIV>"
+			   "<DIV ID=" + szID + "prop3 STYLE=\"display: none\">"
+					"<P CLASS=tablePropsTitle>" + L_TABLEBORDERS_TEXT + "</P>"
+				   L_TABLEINPUTBORDER_TEXT
+				   "<INPUT SIZE=2 TYPE=text ID=" + szID + "txtBorder VALUE=1>"
+				   "<BR>"
+				   L_TABLEINPUTBORDERCOLOR_TEXT
+				   "<INPUT SIZE=4 TYPE=text ID=" + szID + "txtBorderColor value=#000000><BR>" 
+				   _CUtil_BuildColorTable("idBorder"+szID, "", "parent._CTablePopupRenderer_ColorSelect(this,'" + szID + "txtBorderColor')") 
+			   "</DIV>"
+			   "<DIV ID=" + szID + "prop4 SIZE=12 STYLE=\"display: none\">"
+					"<P CLASS=tablePropsTitle>" + L_TABLEBG_TEXT + "</P>"
+				   L_TABLEINPUTBGIMGURL_TEXT
+				   "<INPUT TYPE=text ID=" + szID + "txtBackgroundImage SIZE=15>"
+				   "<BR>"
+				   L_TABLEINPUTBGCOLOR_TEXT	
+				   "<INPUT TYPE=text SIZE=4 ID=" + szID + "txtBackgroundColor><BR>" 
+				   _CUtil_BuildColorTable("idBackground"+szID, "", "parent._CTablePopupRenderer_ColorSelect(this,'" + szID + "txtBackgroundColor')") 
+			   "</DIV>"
+		   "</TD>"
+	   "</TR><TR><TD align=center ID=tableButtons valign=bottom>"
if (szID=="tabNewBody") {
sz +=	"<INPUT TYPE=submit ONCLICK=\"parent._CTablePopupRenderer_BuildTable('" + szID + "',this.document)\" VALUE=\"" + L_TABLEINSERT_TEXT + "\">"
+   " <INPUT TYPE=reset VALUE=\"" + L_CANCEL_TEXT + "\" ONCLICK=\"parent._CPopup_Hide()\">"
} else {
sz +=	"<INPUT TYPE=submit ONCLICK=\"parent._CTablePopupRenderer_BuildTable('" + szID + "',this.document)\" VALUE=\"" + L_TABLEUPDATE_TEXT + "\">"
+   " <INPUT TYPE=reset VALUE=\"" + L_CANCEL_TEXT + "\" ONCLICK=\"parent._CPopup_Hide()\">"
}
sz+=   "</TD></TR></TABLE>"
return sz
}
function _CTablePopupRenderer_PrepareHTML()
{   
var sz  = "<TABLE CLASS=tabBox ID=\"tabSelect\" CELLSPACING=0 CELLPADDING=0 WIDTH=95%><TR HEIGHT=15><TD CLASS=tabItem STYLE=\"border-bottom: none\" NOWRAP><DIV ONCLICK=\"if (tabEdit.className!='disabled') {this.className='selected';this.parentElement.style.borderBottom = tabEdit.className=tabNewBody.style.display='';tabEditBody.style.display='none';tabEdit.parentElement.style.borderBottom='1px black solid'}\" CLASS=selected ID=tabNew>New Table</DIV></TD>"
+   "<TD CLASS=tabItem NOWRAP><DIV ONCLICK=\"if (this.className!='disabled') {this.className='selected';this.parentElement.style.borderBottom = tabNew.className=tabEditBody.style.display='';tabNew.parentElement.style.borderBottom='1px black solid';tabNewBody.style.display='none'}\" CLASS=disabled ID=tabEdit>Edit Table</DIV></TD><TD CLASS=tabSpace WIDTH=100%>&nbsp;</TD></TR><TR><TD VALIGN=TOP CLASS=tabBody COLSPAN=3>"
+   _CTablePopupRenderer_PrepareHTMLPage("tabNewBody",true)
+   _CTablePopupRenderer_PrepareHTMLPage("tabEditBody",false)
+	"</TD></TR></TABLE>"
return sz
}
function _CTablePopupRenderer_Select(el,szID, id) 
{
var d = el.document
for (var i = 1; i < 5; i++)
d.all[szID + "prop" + i].style.display = "none"
d.all[szID + id].style.display = ""
}
function _CTablePopupRenderer_ColorSelect(el,id) 
{
el.document.all[id].value = el.bgColor
}	
function _CTablePopupRenderer_AddRow(el) {
var elRow = el.document.elCurrent.insertRow()
for (var i=0;i<el.document.elCurrent.rows[0].cells.length;i++) {
var elCell = elRow.insertCell()
elCell.innerHTML = "&nbsp;"
}
}
function _CTablePopupRenderer_AddCell(el) {
for (var i=0;i<el.document.elCurrent.rows.length;i++) {
var elCell = el.document.elCurrent.rows[i].insertCell()
elCell.innerHTML = "&nbsp;"
}
}
function _CTablePopupRenderer_BuildTable(szID, d) 
{
if (szID=="tabNewBody") {
var sz =   ""
+   "<TABLE "
+  (((d.all[szID + "txtBorder"].value=="") || (d.all[szID + "txtBorder"].value=="0")) ? "class=\"NOBORDER\"" : "")
+	   (d.all[szID + "txtPadding"].value != "" ? "cellPadding=\"" + d.all[szID + "txtPadding"].value + "\" " : "")
+	   (d.all[szID + "txtSpacing"].value != "" ? "cellSpacing=\"" + d.all[szID + "txtSpacing"].value + "\" " : "")
+	   (d.all[szID + "txtBorder"].value != "" ? "border=\"" + d.all[szID + "txtBorder"].value + "\" " : "")
+	   (d.all[szID + "txtBorderColor"].value != "" ? "bordercolor=\"" + d.all[szID + "txtBorderColor"].value + "\" " : "")
+	   (d.all[szID + "txtBackgroundImage"].value != "" ? "background=\"" + d.all[szID + "txtBackgroundImage"].value + "\" " : "")
+	   (d.all[szID + "txtBackgroundColor"].value != "" ? "bgColor=\"" + d.all[szID + "txtBackgroundColor"].value + "\" " : "")
+   ">"
for (var r=0; r < d.all[szID + "txtRows"].value; r++) 
{
sz +=  "<TR>"
for (var c=0; c < d.all[szID + "txtColumns"].value; c++)
sz +=  "<TD>&nbsp;</TD>"
sz +=  "</TR>"
}
sz +=  "</TABLE>"
insertHTML(sz)
} else
if (d.elCurrent) {
d.elCurrent.cellPadding = d.all.tabEditBodytxtPadding.value
d.elCurrent.cellSpacing = d.all.tabEditBodytxtSpacing.value
d.elCurrent.border = d.all.tabEditBodytxtBorder.value
d.elCurrent.className = (d.elCurrent.border=="" || d.elCurrent.border==0) ? "NOBORDER" : ""
d.elCurrent.borderColor = d.all.tabEditBodytxtBorderColor.value
d.elCurrent.bgColor = d.all.tabEditBodytxtBackgroundColor.value
d.elCurrent.background = d.all.tabEditBodytxtBackgroundImage.value
}
_CPopup_Hide()	
}
function _CListPopupRenderer_OnClick() 
{
var elTD = _CUtil_GetElement(this.oDocument.parentWindow.event.srcElement, "TD") 
if (elTD && elTD._item) this.Select(elTD)
}
function _CListPopupRenderer_GenericOnKeyDown() {
var ev		= this.oDocument.parentWindow.event
if (ev.keyCode==27) _CPopup_Hide()
}
function _CListPopupRenderer_OnKeyDown() 
{
var el
var iRow = iCell	= 0
var ev		= this.oDocument.parentWindow.event
var idList  = this.oDocument.all.idList
var elTR	= _CUtil_GetElement(this.elCurrent,"TR")
var elTD	= _CUtil_GetElement(this.elCurrent,"TD")
if (elTR != null) 
{
iRow	= elTR.rowIndex
iCell   = elTD.cellIndex
}
switch (ev.keyCode) 
{
case 37:
iCell--
if (iCell < 0) 
iCell = idList.rows[iRow].cells.length-1
break
case 38:
iRow--
if (iRow < 0) 
iRow = idList.rows.length-1
break
case 39:
iCell++
if (iCell > idList.rows[iRow].cells.length-1) 
iCell = 0
break
case 40:
iRow++
if (iRow > idList.rows.length-1) 
iRow = 0
break
case 13:
break;
case 27:
_CPopup_Hide()
break;
default:
return;
}
el = idList.rows[iRow].cells[iCell]
if (el && el._item)
if (13 == ev.keyCode) {
ev.keyCode=0		
this.Select(el)
}
else
this.Highlight(el)
}
function _CListPopupRenderer_OnMouseOver() 
{
var el = _CUtil_GetElement(this.oDocument.parentWindow.event.srcElement, "TD") 
if (el && el._item && el != this.elCurrent)
this.Highlight(el)
}
function _CListPopupRenderer_Highlight(el) 
{
var elC = this.elCurrent
if (elC) elC.style.borderWidth =  elC.style.borderColor = elC.style.borderStyle  =   ""
el.style.borderWidth	=   "1px"
el.style.borderColor	=   "green"
el.style.borderStyle	=   "solid"
this.elCurrent			=   el
}
function _CListPopupRenderer_Select(elTD) 
{
g_state.RestoreSelection()
var el = elTD.children[0]
switch (this.szType) 
{
case "font":
_Format("FontName",el.face)
break
case "fontsize":
_Format("FontSize",el.size)			
break
case "formatblock":
_Format("FormatBlock","<" + el.tagName + ">")
break
case "ForeColor":
_Format("ForeColor", elTD.bgColor)
break
case "BackColor":
_Format("BackColor",elTD.bgColor)
break
}
_CPopup_Hide()
}
function _CLinkPopupRenderer_AddLink(d) 
{
var szURL = d.all.urlValue.value
var szType = d.all.urlType[d.all.urlType.selectedIndex].text
var oSel = g_state.GetSelection()
var sType = oSel.type
szURL = ((0 == szURL.indexOf("mailto:") || 0 == szURL.indexOf("http://") || 0 == szURL.indexOf("ftp://")) ? "" : szType) + szURL
if (szURL!="") 
{
if ((oSel.parentElement) && (oSel.text=="")) 
{
oSel.expand("word")
if (oSel.text=="") 
{
var oStore = oSel.duplicate()
if (d.all.pageList) {
var idx = d.all.pageList.selectedIndex
if (d.all.pageList[idx].value==szURL)
oSel.text = d.all.pageList[idx].text
else
oSel.text = szURL
}
else
oSel.text = szURL				
oSel.setEndPoint("StartToStart",oStore)
} 
oSel.select()
sType="Text"
}
if ((oSel.item) && (oSel.item(0).tagName=="IMG")) 
{
oSel.item(0).width = oSel.item(0).offsetWidth
oSel.item(0).height = oSel.item(0).offsetHeight
oSel.item(0).border = (d.all.displayBorder.checked) ? 1 : ""
}
if (d.all.urlValue.value!="")
oSel.execCommand("CreateLink",false,szURL)	
else
oSel.execCommand("UnLink",false,szURL)			
}
Composition.focus()	
}
function _CLinkPopupRenderer__UpdateURL(oDoc,szURL) {
var szType = szURL.substring(0,szURL.indexOf(":"))
for (var i=0;i<oDoc.all.urlType.length;i++) 
if (oDoc.all.urlType[i].value==szType)
oDoc.all.urlType.selectedIndex = i
if (("http"==szType) || ("ftp"==szType)) 
szURL = szURL.substring(szURL.indexOf("//")+2)
else
szURL = szURL.substring(szURL.indexOf(":")+1)
oDoc.all.urlValue.value = szURL
}
function _CLinkPopupRenderer_PrepareHTML() 
{
var d = this.oDocument
var oSel = g_state.GetSelection()
var oEl, sType = oSel.type, bImg = false, szURL = sz = ""
if (oSel.parentElement)  
{
oEl = _CUtil_GetElement(oSel.parentElement(),"A")
}
else 
{
oEl = _CUtil_GetElement(oSel.item(0),"A")
bImg = oSel.item(0).tagName=="IMG"
}
if (oEl)
szURL = oEl.href
sz  ="<TABLE ALIGN=center>" 
if (g_state.aLinks.length>0) 
{
sz  +=  ""
+   "<TR>"
+	   "<TD>" 
+		   L_LINKSELECT_TEXT 
+		   "<SELECT ID=pageList ONCHANGE=\"parent._CLinkPopupRenderer__UpdateURL(this.document,this[this.selectedIndex].value)\">"
+			   "<OPTION VALUE=''>" 
+				   "=="
+				   L_LINKSELECTPAGE_TEXT
+				   "=="
+			   "</OPTION>"
for (var i = 0; i < g_state.aLinks.length; i++) 
{
sz  +=  ""
+   "<OPTION VALUE=\"" + g_state.aLinks[i][0] + "\" "
+	   (oEl && (g_state.aLinks[i][0]==oEl.href) ? "SELECTED" : "")
+   ">"
+	   g_state.aLinks[i][1]
+   "</OPTION>"
}
sz  +=  "</SELECT>"
}
var arTypes = new Array("http","ftp","mailto")
var arText = new Array("http://","ftp://","mailto:")
var szType = szURL.substring(0,szURL.indexOf(":"))
if (("http"==szType) || ("ftp"==szType)) 
szURL = szURL.substring(szURL.indexOf("//")+2)
else
szURL = szURL.substring(szURL.indexOf(":")+1)
sz  += ""
+   "<BR>" 
+   L_LINKWEB_TEXT 
+   "<NOBR><SELECT ID=urlType>"
for (var i=0;i<arTypes.length;i++) {
sz+= "<OPTION VALUE='" + arTypes[i] + "' "
+	(arTypes[i]==szType ? " SELECTED " : "")
+ ">" + arText[i]
}
sz += "</SELECT><INPUT ID=urlValue SIZE=45 VALUE=\"" + szURL + "\" TYPE=text></NOBR>"
if (bImg)
{
sz  +=  ""
+   "<BR>"
+   "<INPUT TYPE=checkbox ID=displayBorder " + ((oSel.item(0).border!=0) ? " checked " : "") + ">" 
+   L_LINKIMGBORDER_TEXT
}
sz  +=  ""
+		   "</TD>"
+	   "</TR>"
+	   "<TR>"
+		   "<TD ALIGN=center>"
+			   "<INPUT ONCLICK=\"parent._CLinkPopupRenderer_AddLink(this.document)\" TYPE=submit ID=idSave VALUE=\"" + L_INSERT_TEXT + "\"> <INPUT ONCLICK=\"parent._CPopup_Hide()\" TYPE=reset ID=idCancel VALUE=\"" + L_CANCEL_TEXT + "\">"
+		   "</TD>"
+	   "</TR>"
+   "</TABLE>"
return sz
}
//  UTIL
function _CUtil_GetElement(oEl,sTag) 
{
while (oEl!=null && oEl.tagName!=sTag)
oEl = oEl.parentElement
return oEl
}
function _CUtil_BuildColorTable(sID,fmt,szClick) 
{
var sz, cPick = new Array("00","33","66","99","CC","FF"), iCnt=2
var iColors = cPick.length, szColor = ""
sz = "<TABLE CELLSPACING=0 CELLPADDING=0><TR><TD VALIGN=middle><DIV CLASS=currentColor ID=\"" + sID + "Current\">&nbsp;</DIV></TD><TD>"
+   "<TABLE ONMOUSEOUT=\"document.all." + sID + "Current.style.backgroundColor = ''\" ONMOUSEOVER=\"document.all." + sID + "Current.style.backgroundColor = event.srcElement.bgColor\" CLASS=colorTable CELLSPACING=0 CELLPADDING=0 ID=\"" + sID + "\">"
for (var r=0;r<iColors;r++) {
sz+="<TR>"
for (var g=iColors-1;g>=0;g--)
for (var b=iColors-1;b>=0;b--) {
szColor = cPick[r]+cPick[g]+cPick[b] 
sz+="<TD"
+ " BGCOLOR=\"#" + szColor + "\""
+ "_item=\"" + szColor + "\" "
+ "TITLE=\"#" + szColor + "\" "
+ (szClick ? "ONCLICK=\"" + szClick + "\" " : "")
+ ">&nbsp;</TD>"
}
sz+="</TR>"
}
sz+="</TABLE></TD></TR></TABLE>"
return sz
}
function _CUtil_GetBlock(oEl) 
{
var sBlocks = "|H1|H2|H3|H4|H5|H6|P|PRE|LI|TD|DIV|BLOCKQUOTE|DT|DD|TABLE|HR|IMG|"
while ((oEl!=null) && (sBlocks.indexOf("|"+oEl.tagName+"|")==-1))
oEl = oEl.parentElement
return oEl
}

function PasteText(){
	//if (!validateMode()) return;
	Composition.focus();
	var sText = HTMLEncode( clipboardData.getData("Text") ) ;
	insertHTML(sText);
	Composition.focus();
}

// 替换特殊字符
function HTMLEncode(text){
	text = text.replace(/&/g, "&amp;") ;
	text = text.replace(/"/g, "&quot;") ;
	text = text.replace(/</g, "&lt;") ;
	text = text.replace(/>/g, "&gt;") ;
	text = text.replace(/'/g, "&#146;") ;
	text = text.replace(/\ /g,"&nbsp;");
	text = text.replace(/\n/g,"<br>");
	text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
	return text;
}

// 在当前文档位置插入.
function insertHTML(html) {
	//if (!validateMode()) return;
	if (Composition.document.selection.type.toLowerCase() != "none")
		Composition.document.selection.clear() ;
	Composition.document.selection.createRange().pasteHTML(html) ; 
}

// 从Word中粘贴，去除格式
function PasteWord(){
	//if (!validateMode()) return;
	Composition.focus();
	if (BrowserInfo.IsIE55OrMore)
		cleanAndPaste( GetClipboardHTML() ) ;
	else if ( confirm( "此功能要求IE5.5版本以上，你当前的浏览器不支持，是否按常规粘贴进行？" ) )
		format("paste") ;
	Composition.focus();
}

function GetClipboardHTML() {
	var oDiv = document.getElementById("divTemp")
	oDiv.innerHTML = "" ;
	
	var oTextRange = document.body.createTextRange() ;
	oTextRange.moveToElementText(oDiv) ;
	oTextRange.execCommand("Paste") ;
	
	var sData = oDiv.innerHTML ;
	oDiv.innerHTML = "" ;
	
	return sData ;
}

function cleanAndPaste( html ) {
	// Remove all SPAN tags
	html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	// Remove Style attributes
	html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
	// Remove Tags with XML namespace declarations: <o:p></o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
	// Replace the &nbsp;
	html = html.replace(/&nbsp;/, " " );
	// Transform <P> to <DIV>
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<div$2</div>" ) ;
	
	insertHTML( html ) ;
}

// 查找替换
function findReplace(){
	ShowDialog('./dialog/findreplace.htm', 320, 165, true)
}

// 显示无模式对话框
function ShowDialog(url, width, height, optValidate) {
	//if (optValidate) {
		//if (!validateMode()) return;
	//}
	Composition.focus();
	var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
	Composition.focus();
}

// 设置编辑器的内容
function setHTML(html) {
	//if (!validateMode()) return;
	//ContentEdit.value = html;
	//if(bEditMode){
		Composition.document.body.innerHTML = html;
	//}else{
	//	Composition.document.body.innerText = html;
	//}
}

// 相对(absolute)或绝对位置(static)
function absolutePosition(){
	var objReference	= null;
	var RangeType		= Composition.document.selection.type;
	if (RangeType != "Control") return;
	var selectedRange	= Composition.document.selection.createRange();
	for (var i=0; i<selectedRange.length; i++){
		objReference = selectedRange.item(i);
		if (objReference.style.position != 'absolute') {
			objReference.style.position='absolute';
		}else{
			objReference.style.position='static';
		}
	}
	Composition.content = false;
	Composition.setActive();
}

// 上移(forward)或下移(backward)一层
function zIndex(action){
	var objReference	= null;
	var RangeType		= Composition.document.selection.type;
	if (RangeType != "Control") return;
	var selectedRange	= Composition.document.selection.createRange();
	for (var i=0; i<selectedRange.length; i++){
		objReference = selectedRange.item(i);
		if (action=='forward'){
			objReference.style.zIndex  +=1;
		}else{
			objReference.style.zIndex  -=1;
		}
		objReference.style.position='absolute';
	}
	Composition.content = false;
	Composition.setActive();
}

function showBorders() {
	//if (!validateMode()) return;
	
	var allForms = Composition.document.body.getElementsByTagName("FORM");
	var allInputs = Composition.document.body.getElementsByTagName("INPUT");
	var allTables = Composition.document.body.getElementsByTagName("TABLE");
	var allLinks = Composition.document.body.getElementsByTagName("A");

	// 表单
	for (a=0; a < allForms.length; a++) {
		if (borderShown == "no") {
			allForms[a].runtimeStyle.border = "1px dotted #FF0000"
		} else {
			allForms[a].runtimeStyle.cssText = ""
		}
	}

	// Input Hidden类
	for (b=0; b < allInputs.length; b++) {
		if (borderShown == "no") {
			if (allInputs[b].type.toUpperCase() == "HIDDEN") {
				allInputs[b].runtimeStyle.border = "1px dashed #000000"
				allInputs[b].runtimeStyle.width = "15px"
				allInputs[b].runtimeStyle.height = "15px"
				allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
				allInputs[b].runtimeStyle.color = "#FDADAD"
			}
		} else {
			if (allInputs[b].type.toUpperCase() == "HIDDEN")
				allInputs[b].runtimeStyle.cssText = ""
		}
	}

	// 表格
	for (i=0; i < allTables.length; i++) {
			if (borderShown == "no") {
				allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
			} else {
				allTables[i].runtimeStyle.cssText = ""
			}

			allRows = allTables[i].rows
			for (y=0; y < allRows.length; y++) {
			 	allCellsInRow = allRows[y].cells
					for (x=0; x < allCellsInRow.length; x++) {
						if (borderShown == "no") {
							allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
						} else {
							allCellsInRow[x].runtimeStyle.cssText = ""
						}
					}
			}
	}

	// 链接 A
	for (a=0; a < allLinks.length; a++) {
		if (borderShown == "no") {
			if (allLinks[a].href.toUpperCase() == "") {
				allLinks[a].runtimeStyle.border = "1px dashed #000000"
				allLinks[a].runtimeStyle.width = "20px"
				allLinks[a].runtimeStyle.height = "16px"
				allLinks[a].runtimeStyle.backgroundColor = "#FFFFCC"
				allLinks[a].runtimeStyle.color = "#FFFFCC"					
			}
		} else {
			allLinks[a].runtimeStyle.cssText = ""		
		}
	}

	if (borderShown == "no") {
		borderShown = "yes"
	} else {
		borderShown = "no"
	}

	scrollUp()
}

// 返回页面最上部
function scrollUp() {
	Composition.scrollBy(0,0);
}

// 插入特殊对象
function insert(what) {
	//if (!validateMode()) return;
	Composition.focus();
	var sel = Composition.document.selection.createRange();

	switch(what){
	case "excel":		// 插入EXCEL表格
		insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='../cab/msowc.cab' width='100%' height='250'><param name='HTMLURL' value><param name='HTMLData' value='&lt;html xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--&gt;&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:OWCVersion&gt;9.0.0.2710&lt;/x:OWCVersion&gt;&lt;x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver'&gt;&lt;x:Caption&gt;Microsoft Office Spreadsheet&lt;/x:Caption&gt; &lt;/x:Label&gt;&lt;x:Name&gt;Sheet1&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:Selected/&gt;&lt;x:Height&gt;7620&lt;/x:Height&gt;&lt;x:Width&gt;15240&lt;/x:Width&gt;&lt;x:TopRowVisible&gt;0&lt;/x:TopRowVisible&gt;&lt;x:LeftColumnVisible&gt;0&lt;/x:LeftColumnVisible&gt; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt; &lt;x:DefaultRowHeight&gt;210&lt;/x:DefaultRowHeight&gt; &lt;x:StandardWidth&gt;2389&lt;/x:StandardWidth&gt; &lt;/x:WorksheetOptions&gt; &lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt; &lt;x:MaxHeight&gt;80%&lt;/x:MaxHeight&gt;&lt;x:MaxWidth&gt;80%&lt;/x:MaxWidth&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;table class=wc4590F88 x:str&gt;&lt;col width=&quot;56&quot;&gt;&lt;tr height=&quot;14&quot;&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'> <param name='DataType' value='HTMLDATA'> <param name='AutoFit' value='0'><param name='DisplayColHeaders' value='-1'><param name='DisplayGridlines' value='-1'><param name='DisplayHorizontalScrollBar' value='-1'><param name='DisplayRowHeaders' value='-1'><param name='DisplayTitleBar' value='-1'><param name='DisplayToolbar' value='-1'><param name='DisplayVerticalScrollBar' value='-1'> <param name='EnableAutoCalculate' value='-1'> <param name='EnableEvents' value='-1'><param name='MoveAfterReturn' value='-1'><param name='MoveAfterReturnDirection' value='0'><param name='RightToLeft' value='0'><param name='ViewableRange' value='1:65536'></object>");
		break;
	case "nowdate":		// 插入当前系统日期
		var d = new Date();
		insertHTML(d.toLocaleDateString());
		break;
	case "nowtime":		// 插入当前系统时间
		var d = new Date();
		insertHTML(d.toLocaleTimeString());
		break;
	case "br":			// 插入换行符
		insertHTML("<br>")
		break;
	case "code":		// 代码片段样式
		insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#FDFDDF style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是代码片段：</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
		break;
	case "quote":		// 引用片段样式
		insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#F3F3F3 style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是引用片段：</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
		break;
	case "big":			// 字体变大
		insertHTML("<big>" + sel.text + "</big>");
		break;
	case "small":		// 字体变小
		insertHTML("<small>" + sel.text + "</small>");
		break;
	default:
		alert("错误参数调用！");
		break;
	}
	sel=null;
}

// 确保焦点在 Composition 内
function VerifyFocus() {
	if ( Composition )
		Composition.focus();
}

// 改变模式：代码、编辑、预览
function setMode(NewMode){
	if (NewMode!=sCurrMode){
		var sBody = "";
		switch(sCurrMode){
		case "CODE":
			sBody = Composition.document.body.innerText;
			break;
		case "EDIT":
		case "VIEW":
			sBody = Composition.document.body.innerHTML;
			break;
		default:
			sBody = ContentEdit.value;
			break;
		}
		// 换图片
		try{
			document.all["Composition_CODE"].className = "StatusBarBtnOff";
			document.all["Composition_EDIT"].className = "StatusBarBtnOff";
			document.all["Composition_VIEW"].className = "StatusBarBtnOff";
			document.all["Composition_"+NewMode].className = "StatusBarBtnOn";
			}
		catch(e){
			}
		// 换内容
		switch (NewMode){
		case "CODE":
			Composition.document.designMode="On";
			Composition.document.open();
			Composition.document.write(config.StyleEditorHeader);
			Composition.document.body.innerText=sBody;
			Composition.document.body.contentEditable="true";
			Composition.document.oncontextmenu=new Function("return showContextMenu(Composition.event);");
			Composition.document.close();
			bEditMode=false;
			break;
		case "EDIT":
			Composition.document.designMode="On";
			Composition.document.open();
			Composition.document.write(config.StyleEditorHeader);
			Composition.document.body.innerHTML=sBody;
			Composition.document.body.contentEditable="true";
			Composition.document.oncontextmenu=new Function("return showContextMenu(Composition.event);");
			Composition.document.execCommand("2D-Position",true,true);
			Composition.document.execCommand("MultipleSelection", true, true);
			Composition.document.execCommand("LiveResize", true, true);
			Composition.document.close();
			doZoom(nCurrZoomSize);
			bEditMode=true;
			break;
		case "VIEW":
			Composition.document.designMode="off";
			Composition.document.open();
			Composition.document.write(config.StyleEditorHeader+sBody);
			Composition.document.body.contentEditable="false";
			Composition.document.close();
			bEditMode=false;
			break;
		}
		sCurrMode=NewMode;
		disableChildren(Composition_Toolbar);

		if ((borderShown != "no")&&bEditMode) {
			borderShown = "no";
			showBorders()
		}

	}
	Composition.focus();
}

// 使工具栏无效
function disableChildren(obj){
	if (obj){
		obj.disabled=(!bEditMode);
		for (var i=0; i<obj.children.length; i++){
			disableChildren(obj.children[i]);
		}
	}
}