﻿<!--
//author: Ray.lee
//email:  xiangqi.lee@tom.com
//date:   03/31/2008

//global varibleris
var __editor_global__	= {
    container:      null,
    editor:         null,
    source:         null,
    preview:        null,
    postor:         null,
    fontName:       null,
    foreColor:      null,
    fontSize:       null,
    faceIcon:       null,
    linkBox:        null,
    specialSymbol:  null,
    serverTag:      null,
    selection:      null,
    toolbar:        true
    };

var __editor_img_size__ = {width:128, height:128};

var __is_ie__           = (document.attachEvent ? true:false);
 
var __editor_args__     = {
    bold:               true,
    italic:             true,
    underline:          true,
    strikeThrough:      true,
    fontName:           true,
    fontSize:           true,
    foreColor:          true,
    createLink:         true,
    subscript:          true,
    superscript:        true,
    insertOrderedList:  true,
    insertUnorderedList:true,
    insertFace:         true,
    insertImage:        true,
    insertMarquee:      true,
    insertTable:        true,
    insertMovie:        true,
    insertMusic:        true,
    insertFlash:        true,
    clearStyle:         true,
    specialSymbol:      false,
    serverTag:          false,
    cssRoot:            '../res/css/',
    iconRoot:           '../res/icon/',
    faceRoot:           '../res/icon/ubb/'
    }
//initail editor
function editor_oninit(poster, args, type){
    if (args == null)
        args = __editor_args__;
    var enc         = 'eR2yJ3i1vKM';
    var container   = enc + 'container';
    var name1       = enc + 'editor';
    var name2       = enc + 'fontName';
    var name3       = enc + 'foreColor';
    var name4       = enc + 'fontSize';
    var name5       = enc + 'faceIcon';
    var name6       = enc + 'linkBox';
    var name7       = enc + 'source';
    var name8       = enc + 'preview';
    var name9       = enc + 'specialSymbol';
    var name10      = enc + 'serverTag';
    
    var icon_root = args.iconRoot;
    var face_root = args.faceRoot;
    var css_root  = args.cssRoot;
    var html = '<table class="Editor" id="'+container+'">'+
               ' <tr>'+ 
               '   <td class="ToolBar" oncontextmenu="return false" '+
               '                       onselectstart="return false" '+
               '                       onmouseover="editor_ontoolbarmouseover(event)"'+
               '                       onmouseout="editor_ontoolbarmouseout(event)">'+
               '     <iframe id="'+name2+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="140px" height="150px" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
               '     <iframe id="'+name3+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="155px" height="105px" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
               '     <iframe id="'+name4+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="140px" height="150px" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
               '     <iframe id="'+name5+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="182px" height="105px" frameborder="no" marginheight="0" marginwidth="0" scrolling="no"></iframe>'+
               '     <iframe id="'+name6+'" class="Menu" style="display: none;"'+
               '             width="300px" height="105px" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
               '     <iframe id="'+name9+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="140px" height="150px" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
               '     <iframe id="'+name10+'" class="Menu" style="display: none;" onblur="this.style.display=\'none\'"'+
               '             width="140px" height="150px" frameborder="no" marginheight="0" marginwidth="0"></iframe>';
    if (args.bold)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'Bold\')"><IMG title="加粗" src="'+icon_root+'ubb/bold.gif"></DIV>';
    if (args.italic)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'Italic\')"><IMG title="斜体" src="'+icon_root+'ubb/italic.gif"></DIV>';
    if (args.underline)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'Underline\')"><IMG title="下划线" src="'+icon_root+'ubb/underline.gif"></DIV>';
    if (args.strikeThrough)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'StrikeThrough\')"><IMG title="删除线" src="'+icon_root+'ubb/strike.gif"></DIV>';
    if (args.bold || args.italic || args.underline || args.strikeThrough)
        html += '     <DIV><IMG src="'+icon_root+'ubb/separator.gif"></DIV>';
        
    if (args.fontName)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'FontName\')"><IMG title="文本字体" src="'+icon_root+'ubb/style.gif"></DIV>';
    if (args.fontSize)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'FontSize\')"><IMG title="文本大小" src="'+icon_root+'ubb/size.gif"></DIV>';
    if (args.foreColor)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'ForeColor\')"><IMG title="文本颜色" src="'+icon_root+'ubb/color.gif"></DIV>';
    if (args.fontName || args.fontSize || args.foreColor)
        html += '     <DIV><IMG src="'+icon_root+'ubb/separator.gif"></DIV>';
        
    if (args.createLink)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'CreateLink\')"><IMG title="超链接" src="'+icon_root+'ubb/url.gif"></DIV>';
    if (args.subscript)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'Subscript\')"><IMG title="上标" src="'+icon_root+'ubb/sub.gif"></DIV>';
    if (args.superscript)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'Superscript\')"><IMG title="下标" src="'+icon_root+'ubb/sup.gif"></DIV>';
    if (args.insertOrderedList)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertOrderedList\')"><IMG title="有序号列表" src="'+icon_root+'ubb/orderlist.gif"></DIV>';
    if (args.insertUnorderedList)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertUnorderedList\')"><IMG title="无序号列表" src="'+icon_root+'ubb/unorderlist.gif"></DIV>';
    if (args.createLink || args.subscript || args.superscript || args.insertOrderedList || args.insertUnorderedList)
        html += '     <DIV><IMG src="'+icon_root+'ubb/separator.gif"></DIV>';

    if (args.insertFace)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertImage\',10)"><IMG title="心情图标" src="'+icon_root+'ubb/face.gif"></DIV>';
    if (args.insertImage)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertImage\',20)"><IMG title="链接的图片" src="'+icon_root+'ubb/image.gif"></DIV>';
    if (args.insertMarquee)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertMarquee\')"><IMG title="滚动文本" src="'+icon_root+'ubb/meguee.gif"></DIV>';
    if (args.insertTable)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertTable\')"><IMG title="链接的表格" src="'+icon_root+'ubb/table.gif"></DIV>';
    if (args.insertMovie)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertMovie\')"><IMG title="链接的视频" src="'+icon_root+'ubb/movie.gif"></DIV>';
    if (args.insertMusic)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertMusic\')"><IMG title="链接的音乐" src="'+icon_root+'ubb/music.gif"></DIV>';
    if (args.insertFlash)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'InsertFlash\')"><IMG title="链接的Flash" src="'+icon_root+'ubb/flash.gif"></DIV>';
    if (args.insertFace || args.insertImage || args.insertMarquee || args.insertTable || args.insertMovie || args.insertMusic || args.insertFlash)
        html += '     <DIV><IMG src="'+icon_root+'ubb/separator.gif"></DIV>';

    if (args.specialSymbol)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'SpecialSymbol\')"><IMG title="特殊符号" src="'+icon_root+'ubb/specialchar.gif"></DIV>';
    if (args.serverTag)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'ServerTag\')"><IMG title="服务器标签" src="'+icon_root+'ubb/tag.gif"></DIV>';
    if (args.specialSymbol || args.serverTag)
        html += '     <DIV><IMG src="'+icon_root+'ubb/separator.gif"></DIV>';

    if (args.clearStyle)
        html += '     <DIV class="Out" onclick="editor_execcommand(event,\'ClearStyle\')"><IMG title="清除样式" src="'+icon_root+'ubb/easer.gif"></DIV>';
        
    html += '   </td>'+
            '  </tr>'+
            ' <tr>'+
            '   <td class="Content">'+
            '     <iframe id="'+name1+'" width="100%" height="100%" frameborder="no" marginheight="0" marginwidth="0"></iframe>'+
            '   </td>'+
            ' </tr>'+
            ' <tr style="display:none;">'+
            '   <td class="Source">'+
            '     <textarea id="'+name7+'" style="width: 100%; height: 100%; word-wrap: break-word; word-break:break-all;">' + poster.value + '</textarea>'+
            '   </td>'+
            ' </tr>'+
            ' <tr style="display:none;">'+
            '   <td class="Preview">'+
            '     <div id="'+name8+'" class="Editor-Body" style="width: 100%; height: 100%; overflow: auto;"></div>'+
            '   </td>'+
            ' </tr>'+
            ' <tr>'+
            '   <td class="Command" oncontextmenu="return false" '+
            '                       onselectstart="return false" '+
            '                       onclick="editor_ontoolbarmouseclick(event)">'+
            '     <div class="Over" type="design">设计模式</div>'+
            '     <div><img src="'+icon_root+'ubb/separator.gif"></div>'+
            '     <div class="Out" type="source">源码模式</div>'+
            '     <div><img src="'+icon_root+'ubb/separator.gif"></div>'+
            '     <div class="Out" type="preview">预览模式</div>'+
            '   </td>'+
            ' </tr>'+
            '</table>';
    document.writeln(html);
    __editor_global__.container     = document.getElementById(container);    
    __editor_global__.editor        = document.getElementById(name1);
    __editor_global__.fontName      = document.getElementById(name2);
    __editor_global__.foreColor     = document.getElementById(name3);
    __editor_global__.fontSize      = document.getElementById(name4);
    __editor_global__.faceIcon      = document.getElementById(name5);
    __editor_global__.linkBox       = document.getElementById(name6);
    __editor_global__.source        = document.getElementById(name7);
    __editor_global__.preview       = document.getElementById(name8);
    __editor_global__.specialSymbol = document.getElementById(name9);
    __editor_global__.serverTag     = document.getElementById(name10);
    __editor_global__.postor        = poster;
    
    //fontname init
    var obj = __editor_global__.fontName.contentWindow;
    obj.document.open();
    obj.document.writeln(  '<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-FontName"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.fontName)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.fontName)"'+
                        '        onclick="parent.editor_execcommand(event,\'FontName\',true)">'+
				        '   <div class="Out" style="font-family:宋体">宋体</div>'+
				        '   <div class="Out" style="font-family:黑体">黑体</div>'+	
				        '   <div class="Out" style="font-family:Arial">Arial</div>'+
				        '   <div class="Out" style="font-family:Arial Black">Arial Black</div>'+	
				        '   <div class="Out" style="font-family:Courier New">Courier New</div>'+
				        '   <div class="Out" style="font-family:Impact">Impact</div>'+
				        '   <div class="Out" style="font-family:Lucida Console">Lucida Console</div>'+
				        '   <div class="Out" style="font-family:MingLiU">MingLiU</div>'+
				        '   <div class="Out" style="font-family:Sans-Serif">Sans-Serif</div>'+				        
				        '   <div class="Out" style="font-family:Times New Roman">Times New Roman</div>'+
				        '   <div class="Out" style="font-family:Tahoma">Tahoma</div>'+
				        '   <div class="Out" style="font-family:Verdana">Verdana</div>'+
				        '   <div class="Out" style="font-family:Verdana">Webdings</div>'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //forecolor init
    var obj = __editor_global__.foreColor.contentWindow;
    obj.document.open();
    obj.document.writeln(  '<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-ForeColor"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.foreColor)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.foreColor)"'+
                        '        onclick="parent.editor_execcommand(event,\'ForeColor\',true)">'+
                        '       <div class="Out" style="background-color:darkred"></div>'+
                        '       <div class="Out" style="background-color:firebrick"></div>'+
                        '       <div class="Out" style="background-color:red"></div>'+
                        '       <div class="Out" style="background-color:deeppink"></div>'+
                        '       <div class="Out" style="background-color:tomato"></div>'+
                        '       <div class="Out" style="background-color:orange"></div>'+
                        '       <div class="Out" style="background-color:goldenrod"></div>'+
                        '       <div class="Out" style="background-color:gold"></div>'+
                        '       <div class="Out" style="background-color:darkkhaki"></div>'+
                        '       <div class="Out" style="background-color:olive"></div>'+
                        '       <div class="Out" style="background-color:yellowgreen"></div>'+
                        '       <div class="Out" style="background-color:green"></div>'+
                        '       <div class="Out" style="background-color:olivedrab"></div>'+
                        '       <div class="Out" style="background-color:darkolivegreen"></div>'+
                        '       <div class="Out" style="background-color:darkcyan"></div>'+
                        '       <div class="Out" style="background-color:steelblue"></div>'+
                        '       <div class="Out" style="background-color:slateblue"></div>'+
                        '       <div class="Out" style="background-color:royalblue"></div>'+
                        '       <div class="Out" style="background-color:blue"></div>'+
                        '       <div class="Out" style="background-color:mediumblue"></div>'+
                        '       <div class="Out" style="background-color:navy"></div>'+
                        '       <div class="Out" style="background-color:silver"></div>'+
                        '       <div class="Out" style="background-color:gray"></div>'+
                        '       <div class="Out" style="background-color:black"></div>'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //fontsize init
    var obj = __editor_global__.fontSize.contentWindow;
    obj.document.open();
    obj.document.writeln(  '<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-FontSize"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.fontSize)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.fontSize)"'+
                        '        onclick="parent.editor_execcommand(event,\'FontSize\',true)">'+
				        '   <div class="Out" style="font-size:7pt" size="1">XX-Small</div>'+
				        '   <div class="Out" style="font-size:10pt" size="2">X-Small</div>'+
				        '   <div class="Out" style="font-size:11pt" size="3">Small</div>'+
				        '   <div class="Out" style="font-size:12pt" size="4">Middle</div>'+
				        '   <div class="Out" style="font-size:14pt" size="5">Large</div>'+
				        '   <div class="Out" style="font-size:16pt" size="6">X-Large</div>'+
				        '   <div class="Out" style="font-size:18pt" size="7">XX-Large</div>'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //faceicon init
    var obj = __editor_global__.faceIcon.contentWindow;
    obj.document.open();
    obj.document.writeln(  '<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-FaceIcon"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.faceIcon)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.faceIcon)"'+
                        '        onclick="parent.editor_execcommand(event,\'InsertImage\',false)">'+
                        '    <div class="Out"><img src="'+face_root+'face/00.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/01.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/02.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/03.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/04.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/05.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/06.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/07.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/08.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/09.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/10.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/11.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/12.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/13.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/14.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/15.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/16.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/17.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/18.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/19.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/20.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/21.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/22.gif"></div>'+
                        '    <div class="Out"><img src="'+face_root+'face/23.gif"></div>'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //linkbox init
    var obj = __editor_global__.linkBox.contentWindow;
    obj.document.open();
    obj.document.writeln('<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet"/>'+
                        '  </head>'+
                        '  <body oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-DefaultBox">'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //special symbols init
    var special_symbols = Array('§','№','☆','★','○','●','◎','◇','◆','□','℃','‰','■','△','▲','※',
                                '→','←','↑','↓','〓','¤','°','＃','＆','＠','＼','︿','＿','￣','―','α',
                                'β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ',
                                'σ','τ','υ','φ','χ','ψ','ω','≈','≡','≠','＝','≤','≥','＜','＞','≮',
                                '≯','∷','±','＋','－','×','÷','／','∫','∮','∝','∞','∧','∨','∑','∏',
                                '∪','∩','∈','∵','∴','⊥','∥','∠','⌒','⊙','≌','∽','〖','〗','【','】',
                                '（','）','［','］'); 
    var obj = __editor_global__.specialSymbol.contentWindow;
    obj.document.open(); 
    var symbols = '';
    for (i = 0; i < special_symbols.length; i++)
		symbols += '<div class="Out">'+special_symbols[i]+'</div>';
    obj.document.writeln('<html>'+
                        '  <head>'+
                        '      <link href="css/HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-SpecialSymbol"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.specialSymbol)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.specialSymbol)"'+
                        '        onclick="parent.editor_execcommand(event,\'SpecialSymbol\',\'false\')">'+
                        '    '+symbols+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    //server tags init
    var obj = __editor_global__.serverTag.contentWindow;
    obj.document.open();
    obj.document.writeln(  '<html>'+
                        '  <head>'+
                        '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                        '  </head>'+
                        '  <body onselectstart="return false"'+
                        '        oncontextmenu="return false"'+
                        '        class="Editor-Box Editor-ServerTag"'+
                        '        onmouseover="parent.editor_ontoolbarmouseover(event,parent.__editor_global__.serverTag)"'+
                        '        onmouseout="parent.editor_ontoolbarmouseout(event,parent.__editor_global__.serverTag)"'+
                        '        onclick="parent.editor_execcommand(event,\'ServerTag\',true)">'+
			            '   <div class="Out" tag="[:Receiver]">Receiver name</div>'+
			            '   <div class="Out" tag="[:Sender]">Sender name</div>'+
			            '   <div class="Out" tag="[:DateTime]">Date/Time</div>'+
			            '   <div class="Out" tag="[:Username]">Username</div>'+
			            '   <div class="Out" tag="[:Password]">Password</div>'+
			            '   <div class="Out" tag="[:PrimaryEmail]">Primary email</div>'+
			            '   <div class="Out" tag="[:ContactEmail]">Contact email</div>'+
                        '  </body>'+
                        '</html>');
    obj.document.close();
    
    //editor init
    var obj = __editor_global__.editor.contentWindow;
    obj.document.designMode = 'on';
    obj.document.open();
    obj.document.writeln('<html>'+
                         '  <head>'+
                         '      <link href="'+css_root+'HtmlEditor.css" type="text/css" rel="stylesheet">'+
                         '  </head>'+
                         '  <body class="Editor-Box Editor-Body">'+
                         __editor_global__.postor.value+
                         '  </body>'+
                         '</html>');
    obj.document.close();
    obj.focus();
    if (__is_ie__){
	    obj.document.attachEvent("ondblclick",    editor_ondblclick);
	    obj.document.attachEvent("oncontextmenu", editor_oncontextmenu);
    }else{
	    obj.document.addEventListener('ondblclick',    editor_ondblclick,  false);
	    obj.document.addEventListener('oncontextmenu', editor_oncontextmenu,  false);
	}
	if (type){
	    var rows = __editor_global__.container.rows;
	    for (var i = 0; i < rows.length; i++){
	        if (rows[i].cells[0].className == 'Command'){
	            var divs = rows[i].cells[0].getElementsByTagName('DIV');
	            for (var j = 0; j < divs.length; j++){
	                if (divs[j].getAttribute('type') == type){
	                    editor_ontoolbarmouseclick(divs[j]);
	                    break;
	                }
	            }
	            break;
	        }
	    }
	}
}
function editor_createlinkbox(command, nameKey, nameValue, urlKey, urlValue){
    //link box init
    var obj = __editor_global__.linkBox.contentWindow;
    obj.document.body.innerHTML =
    '       '+nameKey+'<br>'+
    '       <input id="txtLinkName" type="textbox" value="'+nameValue+'" class="Textbox" height="18px" width="280px"><br>'+
    '       '+urlKey+'<br>'+
    '       <input id="txtLinkUrl" type="textbox" value="'+urlValue+'" class="Textbox" height="18px" width="280px"><br>'+
    '       <a href="javascript:void(0);" onclick="parent.editor_execcommand(event,\''+command+'\',true)">'+
    '           <img src="'+__editor_args__.iconRoot+'ubb/014.gif">确定</a>'+
    '       <a href="javascript:void(0);" onclick="parent.editor_hidesubwindow(parent.__editor_global__.linkBox, true)">'+
    '           <img src="'+__editor_args__.iconRoot+'ubb/008.gif">取消</a>';
    //obj.document.close();
    editor_displaysubwindow(__editor_global__.linkBox, __editor_global__.editor, true);
}
//hide/display sub window
function editor_hidesubwindow(e, noEvent){
	var obj   = e.contentWindow.document;
	var nodes = obj.getElementsByTagName('DIV');
	for (var i = 0; i < nodes.length; i++){
	    if (nodes[i].className == 'Over'){
	        nodes[i].className =  'Out';
	        break;
	    }
	}
	if (noEvent)
	    e.style.display = 'none';
	else
	    editor_attachevent(e);
	__editor_global__.editor.contentWindow.focus();
}
function editor_displaysubwindow(e, p, isCenter){
    var pos = getElementPos(p);
    if (isCenter){
        var width    = parseInt(p.offsetWidth, 10);
        var height   = parseInt(p.offsetHeight,10);
        e.style.left = (pos.x + (width - parseInt(e.width))/2) + 'px';
        e.style.top  = (pos.y + (height - parseInt(e.height))/2) + 'px';
    }else{
        e.style.left = (pos.x - 2) + 'px';
        e.style.top  = (pos.y + parseInt(p.offsetHeight)) + 'px';
    }
    e.style.display  = '';
    e.focus();
}
//preview editor
function editor_ontabclick(e, isPreview){
	e.classSave = 'Selected';
	editor_ontabmouseover(e);
	var tr = e.parentElement;
	for (var i = 0; i < tr.cells.length; i++){
		var td = tr.cells[i];
		if (td.className == 'Selected'){
			td.classSave =  'UnSelected';
			editor_ontabmouseout(td);
		}
	}
    __editor_global__.editor.contentWindow.document.designMode = (isPreview ? 'on' : 'off');
}
function editor_ontabmouseover(e){
	if (e.tagName == 'TD' && e.className != '')
		e.className = e.classSave + ' Over';
}
function editor_ontabmouseout(e){
	if (e.tagName == 'TD' && e.className != '')
		e.className = e.classSave;
}
//attach/remove event
function editor_removeevent(p){
    if (!__is_ie__ && p && p.onblur){
        p._onblur = p.onblur;
        p.onblur  = null;
    }
}
function editor_attachevent(p){
    if (!__is_ie__ && p){
        p.onblur = p._onblur;
        p.focus();
    }
}
//onclick element
function editor_ontoolbarmouseclick(e){
    if (typeof(e.tagName) != 'string')
        e = (__is_ie__ ? e.srcElement:e.target);
    var tag = e.tagName;
	if (tag == 'DIV' || tag == 'IMG'){
		while (e.tagName != 'DIV') e = e.parentNode;
		if (e.className == 'Out'){
		    var el = e.parentNode;
		    while (el.className != 'Command')
		           el = el.parentNode;
		    var objs = document.getElementsByTagName('DIV');
		    for (var i = 0; i< objs.length; i++){
		        var obj = objs[i];
		        if (obj.className == 'Over'){
		            obj.className = 'Out';
		            break;
		        }
		    }
		    var source_box  = __editor_global__.source.parentNode.parentNode;
		    var preview_box = __editor_global__.preview.parentNode.parentNode;
		    var editor_box  = __editor_global__.editor.parentNode.parentNode;
		    switch (e.getAttribute('type')){
		        case 'design':
                if (preview_box.style.display != 'none')
	                __editor_global__.editor.contentWindow.document.body.innerHTML = __editor_global__.preview.innerHTML;
	            else if (source_box.style.display != 'none')
	                __editor_global__.editor.contentWindow.document.body.innerHTML = __editor_global__.source.value.trim().merge();
	            source_box.style.display    = 'none';
	            editor_box.style.display    = '';
	            preview_box.style.display   = 'none';
                __editor_global__.toolbar   = true;
	            __editor_global__.editor.contentWindow.focus();
		        break;
		        case 'source':
                if (source_box.style.display == 'none')
	                __editor_global__.source.value = editor_getcontent();
	            source_box.style.display    = '';
	            editor_box.style.display    = 'none';
	            preview_box.style.display   = 'none';
                __editor_global__.toolbar   = false;
	            __editor_global__.source.focus();
		        break;
		        case 'preview':
                if (editor_box.style.display != 'none')
	                __editor_global__.preview.innerHTML = __editor_global__.editor.contentWindow.document.body.innerHTML;
	            else if (source_box.style.display != 'none')
	                __editor_global__.preview.innerHTML = __editor_global__.source.value.trim().merge();
	            source_box.style.display    = 'none';
	            editor_box.style.display    = 'none';
	            preview_box.style.display   = '';
                __editor_global__.toolbar   = false;
		        break;
		    }
		    __editor_global__.fontName.parentNode.className = (__editor_global__.toolbar ? 'ToolBar':'Disable');
		    e.className = 'Over';		    
	    }
	}
}
//onover/onout element
function editor_ontoolbarmouseover(e,p){
    if (!__editor_global__.toolbar)
        return;
    e = (__is_ie__ ? e.srcElement:e.target);
    var tag = e.tagName;
	if (tag == 'DIV' || tag == 'IMG'){
		while (e.tagName != 'DIV') e = e.parentNode;
		if (e.className != '')
		    e.className = 'Over';
        editor_removeevent(p);		    
	}
}
function editor_ontoolbarmouseout(e,p){
    if (!__editor_global__.toolbar)
        return;
    e = (__is_ie__ ? e.srcElement:e.target);
    var tag = e.tagName;
	if (tag == 'DIV' || tag == 'IMG'){
		while (e.tagName != 'DIV') e = e.parentNode;
		if (e.className != '')
		    e.className = 'Out';
        editor_attachevent(p);		    
	}
}
//action command
function editor_execcommand(e,command,args){
    if (!__editor_global__.toolbar)
        return;
    var editor = __editor_global__.editor.contentWindow;
	if (__editor_global__.editor == null ||
	    editor.document.designMode.toString().toLowerCase() != 'on')
	    return;
	editor.focus();
	var range = (__is_ie__ ? editor.document.selection.createRange() : editor.getSelection());
	switch(command){
		case 'CreateLink':
		    if (args == null){
                var text = (__is_ie__ ? range.text : range.toString());
                if (typeof(text) == 'undefined') return;
                if (text == '')
                    text = '默认链接';
                var url  = 'http://';
		        if (__is_ie__){
		            var type = editor.document.selection.type;
		            switch (type){
		                case 'Text':
		                    e = range.parentElement();
		                    if (e.tagName == 'A')
		                        url = e.href;
		                    break;
		            }
		        }else{
    		        //firefox
    		        e = range.getRangeAt(0);
                    if(e.startContainer.nodeName != "#text"){
                       var node_offset = e.startOffset;
                       var e = e.startContainer.childNodes[node_offset];
                    }
                    if (e.tagName == 'A')
                        url = e.href;
		        }
	            if (__is_ie__) __editor_global__.selection = range;		        
		        editor_createlinkbox(command,'链接名称',text,'链接地址(例:http://www.comicfox.com)',url);
		    }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
	            var obj = __editor_global__.linkBox.contentWindow.document;
	            var text= obj.getElementById('txtLinkName').value.trim();
	            var url = obj.getElementById('txtLinkUrl').value.trim().replace(/\\/gim,'\\\\').replace(/\"/gim,'\\"');
	            if (text != '' && url != '' && url != 'http://'){
	                var html = '<a href="'+url+'">'+text.toHtml()+'</a>';
	                if (__is_ie__){
		                if (editor.document.selection.type == 'Control'){
		                    e = range(0);
		                    e.outerHTML = html;
		                }else{
	                        range.pasteHTML(html);
	                    }
	                }else{
		                editor.document.execCommand('InsertHTML', false, html);
		            }
		        }
		        editor_hidesubwindow(__editor_global__.linkBox, true);
            }
			break;
		case 'InsertImage':
			if (typeof(args) == 'number' && args == 20){
                var text = '链接的图片';
                var url  = 'http://';
	            if (__is_ie__){
	                var type = editor.document.selection.type;
	                switch (type){
	                    case 'Control':
	                        e = range(0);
	                        if (e.tagName == 'IMG'){
	                            url = e.src;
	                            if (e.alt && e.alt != '')
	                                text = e.alt;
	                        }
	                        break;
	                }
	            }else{
		            //firefox
		            e = range.getRangeAt(0);
                    if(e.startContainer.nodeName != "#text"){
                       var node_offset = e.startOffset;
                       var e = e.startContainer.childNodes[node_offset];
                    }
                    if (e.tagName == 'IMG'){
                        url = e.src;
                        if (e.alt && e.alt != '')
                            text = e.alt;
                    }
	            }
                if (__is_ie__) __editor_global__.selection = range;		        
	            editor_createlinkbox(command,'图片名称',text,'图片地址(例:http://localhost/default.gif)',url);
            }else if (typeof(args) == 'boolean' && args){
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
	            var obj = __editor_global__.linkBox.contentWindow.document;
	            var text= obj.getElementById('txtLinkName').value.trim();
	            var url = obj.getElementById('txtLinkUrl').value.trim().replace(/\\/gim,'\\\\').replace(/\"/gim,'\\"');
	            if (url != '' && url != 'http://'){
	                var html = '<IMG src="'+url+'" alt="'+text+'">';
	                if (__is_ie__){
		                if (editor.document.selection.type == 'Control'){
		                    e = range(0);
		                    e.outerHTML = html;
		                }else{
	                        range.pasteHTML(html);
	                    }
	                }else{
		                editor.document.execCommand('InsertHTML', false, html);
		            }
		        }
		        editor_hidesubwindow(__editor_global__.linkBox, true);
			}else if (typeof(args) == 'number' && args == 10){
			    var evt = e;
                e = (__is_ie__ ? e.srcElement:e.target);
                var tag = e.tagName;
                if (tag != 'DIV' && tag != 'IMG') return;
	            while (e.tagName != 'DIV') e = e.parentNode;
                if (__is_ie__) __editor_global__.selection = range;			    
                editor_displaysubwindow(__editor_global__.faceIcon, e, false);
            }else if (typeof(args) == 'boolean' && !args){
			    var evt = e;
                e = (__is_ie__ ? e.srcElement:e.target);
                var tag = e.tagName;
                if (tag != 'DIV' && tag != 'IMG') return;
	            while (e.tagName != 'DIV') e = e.parentNode;
                if (__is_ie__){
	                range = __editor_global__.selection;
	                range.select();
	                range.pasteHTML(e.innerHTML);
	            }else{
		            editor.document.execCommand('InsertHTML', false, e.innerHTML);
		        }
			}
			break;
		case 'ForeColor':
            var evt = e;
            e = (__is_ie__ ? e.srcElement:e.target);
            var tag = e.tagName;
            if (tag != 'DIV' && tag != 'IMG') return;
            while (e.tagName != 'DIV') e = e.parentNode;
		    if (args == null){
	            if (__is_ie__) __editor_global__.selection = range;		    
                editor_displaysubwindow(__editor_global__.foreColor, e, false);
		    }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
		        window.status = e.outerHTML;
		        var text = (__is_ie__ ? range.text : range.toString());
	            if (text != '') editor.document.execCommand(command, false, e.style.backgroundColor);
	            editor_hidesubwindow(__editor_global__.foreColor);
			}
			break;
		case 'FontSize':
            var evt = e;
            e = (__is_ie__ ? e.srcElement:e.target);
            var tag = e.tagName;
            if (tag != 'DIV' && tag != 'IMG') return;
            while (e.tagName != 'DIV') e = e.parentNode;
		    if (args == null){
	            if (__is_ie__) __editor_global__.selection = range;		    
                editor_displaysubwindow(__editor_global__.fontSize, e, false);
		    }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
		        var text = (__is_ie__ ? range.text : range.toString());
	            if (text != '') editor.document.execCommand(command, false, e.getAttribute('size'));
	            editor_hidesubwindow(__editor_global__.fontSize);
			}
			break;
		case 'FontName':
            var evt = e;
            e = (__is_ie__ ? e.srcElement:e.target);
            var tag = e.tagName;
            if (tag != 'DIV' && tag != 'IMG') return;
            while (e.tagName != 'DIV') e = e.parentNode;
		    if (args == null){
	            if (__is_ie__) __editor_global__.selection = range;		    
                editor_displaysubwindow(__editor_global__.fontName, e, false);
		    }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
		        var text = (__is_ie__ ? range.text : range.toString());
	            if (text != '') editor.document.execCommand(command, false, (__is_ie__ ? e.innerText : e.textContent));
	            editor_hidesubwindow(__editor_global__.fontName);
			}
			break;
		case 'InsertMarquee':
		    var html =  '<MARQUEE scrollamount="4" scrolldelay="100">请在此处输入滚动文本的内容...</MARQUEE>';
            if (__is_ie__){
                if (editor.document.selection.type == 'Control'){
                    e = range(0);
                    e.outerHTML = html;
                }else{
                    range.pasteHTML(html);
                }
            }else{
                editor.document.execCommand('InsertHTML', false, html);
            }
			break;
		case 'InsertTable':
			var html =  '<TABLE style="width:300px;">'+
				        '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>'+
				        '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>'+
				        '<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>'+
					    '</TABLE>';
            if (__is_ie__){
                if (editor.document.selection.type == 'Control'){
                    e = range(0);
                    e.outerHTML = html;
                }else{
                    range.pasteHTML(html);
                }
            }else{
                editor.document.execCommand('InsertHTML', false, html);
            }
			break;
		case 'SpecialSymbol':
            var evt = e;
            e = (__is_ie__ ? e.srcElement:e.target);
            var tag = e.tagName;
            if (tag != 'DIV' && tag != 'IMG') return;
            while (e.tagName != 'DIV') e = e.parentNode;
		    if (args == null){
	            if (__is_ie__) __editor_global__.selection = range;		    
                editor_displaysubwindow(__editor_global__.specialSymbol, e, false);
		    }else{
		        var html = e.innerHTML;
                if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
                    if (editor.document.selection.type == 'Control'){
                        e = range(0);
                        e.outerHTML = html;
                    }else{
                        range.pasteHTML(html);
                    }
                }else{
                    editor.document.execCommand('InsertHTML', false, html);
                }
	            editor_hidesubwindow(__editor_global__.specialSymbol);
			}
			break;
		case 'ServerTag':
            var evt = e;
            e = (__is_ie__ ? e.srcElement:e.target);
            var tag = e.tagName;
            if (tag != 'DIV' && tag != 'IMG') return;
            while (e.tagName != 'DIV') e = e.parentNode;
		    if (args == null){
	            if (__is_ie__) __editor_global__.selection = range;		    
                editor_displaysubwindow(__editor_global__.serverTag, e, false);
		    }else{
		        var html = e.getAttribute('tag');
		        if (html == '[:DateTime]'){
		            var now = new Date();
		            html = now.getMonth()+'/'+now.getDate()+'/'+now.getFullYear()+' '+now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
		        }
                if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
                    if (editor.document.selection.type == 'Control'){
                        e = range(0);
                        e.outerHTML = html;
                    }else{
                        range.pasteHTML(html);
                    }
                }else{
                    editor.document.execCommand('InsertHTML', false, html);
                }
	            editor_hidesubwindow(__editor_global__.serverTag);
			}
			break;
		case 'ClearStyle':
		    var text = (__is_ie__ ? range.text : range.toString());
			if (text != ''){
                text = text.toHtml();
			    if (__is_ie__){
			        range.pasteHTML(text);
			        editor.document.selection.empty();
			    }else{
			        editor.document.execCommand('InsertHTML', false, text);
			        range.removeAllRanges();
			    }
			}
			break;
		case 'InsertMovie':
		    if (args == null){
                var text = '视频名称';
                var url  = 'http://';
                if (__is_ie__){
                    var type = editor.document.selection.type;
                    switch (type){
                        case 'Control':
                            e = range(0);
                            if (e.tagName == 'EMBED'){
                                url = e.src;
                                if (e.title && e.title != '')
                                    text = e.title;
                            }
                            break;
                    }
                }else{
	                //firefox
	                e = range.getRangeAt(0);
                    if(e.startContainer.nodeName != "#text"){
                       var node_offset = e.startOffset;
                       var e = e.startContainer.childNodes[node_offset];
                    }
                    if (e.tagName == 'EMBED'){
                        url = e.src;
                        if (e.title && e.title != '')
                            text = e.title;
                    }
                }
                if (__is_ie__) __editor_global__.selection = range;		        
                editor_createlinkbox(command,'视频名称',text,'视频地址(例:http://www.comicfox.com/default.wma)',url);
            }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
	            var obj = __editor_global__.linkBox.contentWindow.document;
	            var text= obj.getElementById('txtLinkName').value.trim();
	            var url = obj.getElementById('txtLinkUrl').value.trim().replace(/\\/gim,'\\\\').replace(/\"/gim,'\\"');
	            if (url != '' && url != 'http://'){
	                var html = '<EMBED src="'+url+'" autostart="true" width="512" height="444" showstatusbar="true" title="'+text+'"></EMBED>';
	                if (__is_ie__){
		                if (editor.document.selection.type == 'Control'){
		                    e = range(0);
		                    e.outerHTML = html;
		                }else{
	                        range.pasteHTML(html);
	                    }
	                }else{
		                editor.document.execCommand('InsertHTML', false, html);
		            }
		        }
		        editor_hidesubwindow(__editor_global__.linkBox, true);
		    }
		    break;
		case 'InsertMusic':
		    if (args == null){
                var text = '音乐名称';
                var url  = 'http://';
                if (__is_ie__){
                    var type = editor.document.selection.type;
                    switch (type){
                        case 'Control':
                            e = range(0);
                            if (e.tagName == 'EMBED'){
                                url = e.src;
                                if (e.title && e.title != '')
                                    text = e.title;
                            }
                            break;
                    }
                }else{
	                //firefox
	                e = range.getRangeAt(0);
                    if(e.startContainer.nodeName != "#text"){
                       var node_offset = e.startOffset;
                       var e = e.startContainer.childNodes[node_offset];
                    }
                    if (e.tagName == 'EMBED'){
                        url = e.src;
                        if (e.title && e.title != '')
                            text = e.title;
                    }
                }
                if (__is_ie__) __editor_global__.selection = range;		        
                editor_createlinkbox(command,'音乐名称',text,'音乐地址(例:http://www.comicfox.com/default.mp3)',url);
            }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
	            var obj = __editor_global__.linkBox.contentWindow.document;
	            var text= obj.getElementById('txtLinkName').value.trim();
	            var url = obj.getElementById('txtLinkUrl').value.trim().replace(/\\/gim,'\\\\').replace(/\"/gim,'\\"');
	            if (url != '' && url != 'http://'){
	                var html = '<EMBED src="'+url+'" autostart="true" controls="controlpanel" showstatusbar="true" title="'+text+'"></EMBED>';
	                if (__is_ie__){
		                if (editor.document.selection.type == 'Control'){
		                    e = range(0);
		                    e.outerHTML = html;
		                }else{
	                        range.pasteHTML(html);
	                    }
	                }else{
		                editor.document.execCommand('InsertHTML', false, html);
		            }
		        }
		        editor_hidesubwindow(__editor_global__.linkBox, true);
		    }
		    break;
		case 'InsertFlash':
		    if (args == null){
                var text = 'Flash名称';
                var url  = 'http://';
                if (__is_ie__){
                    var type = editor.document.selection.type;
                    switch (type){
                        case 'Control':
                            e = range(0);
                            if (e.tagName == 'EMBED'){
                                url = e.src;
                                if (e.title && e.title != '')
                                    text = e.title;
                            }
                            break;
                    }
                }else{
	                //firefox
	                e = range.getRangeAt(0);
                    if(e.startContainer.nodeName != "#text"){
                       var node_offset = e.startOffset;
                       var e = e.startContainer.childNodes[node_offset];
                    }
                    if (e.tagName == 'EMBED'){
                        url = e.src;
                        if (e.title && e.title != '')
                            text = e.title;
                    }
                }
                if (__is_ie__) __editor_global__.selection = range;		        
                editor_createlinkbox(command,'Flash名称',text,'Flash地址(Example:http://localhost/default.swf)',url);
            }else{
		        if (__is_ie__){
		            range = __editor_global__.selection;
		            range.select();
		        }
	            var obj = __editor_global__.linkBox.contentWindow.document;
	            var text= obj.getElementById('txtLinkName').value.trim();
	            var url = obj.getElementById('txtLinkUrl').value.trim().replace(/\\/gim,'\\\\').replace(/\"/gim,'\\"');
	            if (url != '' && url != 'http://'){
	                var html = '<EMBED src="'+url+'" autostart="true" width="512" height="384" title="'+text+'"></EMBED>';
	                if (__is_ie__){
		                if (editor.document.selection.type == 'Control'){
		                    e = range(0);
		                    e.outerHTML = html;
		                }else{
	                        range.pasteHTML(html);
	                    }
	                }else{
		                editor.document.execCommand('InsertHTML', false, html);
		            }
		        }
		        editor_hidesubwindow(__editor_global__.linkBox, true);
		    }
		    break;
		default:
		    var text = (__is_ie__ ? range.text : range.toString());
			if (text != '') editor.document.execCommand(command, false, null);
			break;
	}
}

//set/get content
function editor_getcontent(){
    var editor = __editor_global__.editor.contentWindow;
    var source_box  = __editor_global__.source.parentNode.parentNode;
    var preview_box = __editor_global__.preview.parentNode.parentNode;
    
    if (source_box.style.display != 'none')
        editor.document.body.innerHTML = __editor_global__.source.value.trim().merge();
    else if (preview_box.style.display != 'none')
        editor.document.body.innerHTML = __editor_global__.preview.innerHTML;
        
	var objs = editor.document.getElementsByTagName('INPUT');
	if (objs != null){
		var count = objs.length-1;
		for (var i = count; i >= 0; i--){		
			var obj = objs[i];
			var p = obj.parentNode;			
			switch(obj.type){
				case 'hidden':
					p.removeChild(obj);
					break;
				case 'image':
				    var o = document.createElement('INPUT');
				    o.setAttribute('type', 'image');
				    o.setAttribute('style',obj.getAttribute('style'));
					o.setAttribute('src',  obj.getAttribute('src'));
					p.replaceChild(img, obj);
					break;
				case 'submit':
				case 'reset':
				    var o = document.createElement('INPUT');
				    o.setAttribute('type', 'button');
				    o.setAttribute('value',obj.value);
				    o.setAttribute('style',obj.getAttribute('style'));
					p.replaceChild(img, obj);
					break;
			}
		}
	}
	var objs = editor.document.getElementsByTagName('A');
	if (objs != null){
		var count = objs.length;
		for (var i = 0; i < count; i++){
			if (objs[i].target != '_blank')
				objs[i].target = '_blank';
		}
	}
	var result = editor.document.body.innerHTML;
	result = result.trim().merge();
	result = result.replace(/^.*<BODY[^>]*>/gim,'');
	result = result.replace(/<\/BODY>.*$/gim,'');
	result = result.replace(/(?:<FORM[^>]*>)|(?:<\/FORM>)/gim,'');
	result = result.replace(/<SCRIPT[^>]*>.*<\/SCRIPT>/gim,'');
    result = result.replace(/<\?XML[^>]*>/gim,'');
    result = result.replace(/<LINK[^>]+css\/HtmlEditor\.css[^>]*>/gim,'');
	result = result.replace(/<P>(?:\&nbsp;)*\s*<\/P>/gim,'<br/>');
	result = result.replace(/^(?:\s*<br\s*\/?>\s*)+/gim,'');
	result = result.replace(/(?:\s*<br\s*\/?>\s*)+$/gim,'');
	result = result.replace(/^(?:&nbsp;)+/gim,'');
	result = result.replace(/(?:&nbsp;)+$/gim,'');
    var matchs = result.match(/<\w+\s[^>]+>/gim);
	if (matchs != null){
	    for (var i = 0; i < matchs.length; i++){
	        var tag = matchs[i];
	        tag = tag.replace(/[\n\r\f]+/gim,' ');
	        //tag = tag.replace(/(\s\w+=)'?([#\w-_]+)'?/gim, '$1"$2"');
	        tag = tag.replace(/(\s\w+=)["']*([^"\s>]+)["']*/gim, '$1"$2"');
	        tag = tag.replace(/\s(?:(?:id)|(?:name)|(?:on[a-zA-Z]+))=\"[^\"]+\"/gim,'');
	        result = result.replace(matchs[i], tag);
	    }
	}
	//result = result.replace(/(<(?:(?:HR)|(?:BR)|(?:INPUT))[^>]*)\/?>/gim, '$1/>');
	result = result.replace(/(<IMG[^>]*)>(?!<XSL:ATTRIBUTE)/gim, '$1/>');
	return result;
}
function editor_setcontent(){
	__editor_global__.editor.contentWindow.document.body.innerHTML = __editor_global.postor.value;
}
function editor_noresize(e){
	e.removeAttribute('width');
	e.removeAttribute('height');
	e.style.removeAttribute('width');
	e.style.removeAttribute('height');
}
function editor_showhelp(){
	var help =	'在线帮助\n\n'+
				'链接:输入文字并且选定->点击"链接"按钮'+
				'图片:点击"图片"按钮,输入图片的地址'+
				'滚动:点击"滚动"按钮,双击滚动条修改滚动内容'+
				'表格:点击"表格"按钮'+
				'     CTRL+鼠标右键双击,增加行'+
				'     ATL +鼠标右键双击,增加列'+
				'     CTRL+SHIFT+鼠标右键双击,删除行'+
				'     ATL +SHIFT+鼠标右键双击,删除列'+
				'清除:选中一段文字点击"清除样式"按钮';
	alert(help);
}

function editor_oncontextmenu(){
    return false;
}
function editor_ondblclick(evt){
    var editor = __editor_global__.editor.contentWindow;
	if (__editor_global__.editor == null ||
	    editor.document.designMode.toString().toLowerCase() != 'on')
	    return;
    var e = (__is_ie__ ? evt.srcElement:evt.target);
	switch (e.tagName){
		case 'TD':
		    if (__is_ie__){
			    var tr = e;
			    while (tr.tagName != 'TR') tr = tr.parentNode;
			    var tb = tr;
			    while (tb.tagName != 'TABLE') tb = tb.parentNode;
			    var cellIndex = e.cellIndex;
			    var rowIndex  = tr.rowIndex;
			    if (evt.altKey && !evt.ctrlKey){
				    if (!evt.shiftKey){
					    cellIndex++;
					    for (var i = 0; i < tb.rows.length; i++) tb.rows(i).insertCell(cellIndex);				
				    }else{
					    if (tr.cells.length > 1) for (var i = 0; i < tb.rows.length; i++) tb.rows(i).deleteCell(cellIndex);
				    }
			    }
			    if (!evt.altKey && evt.ctrlKey){
				    if (!evt.shiftKey){
					    rowIndex++;
					    var row = tb.insertRow(rowIndex);
					    for (var i = 0; i < tr.cells.length; i++) row.insertCell();
				    }else{
					    if (tb.rows.length > 1) tb.deleteRow(rowIndex);
				    }
			    }
			}
			break;
		case 'MARQUEE':
		case 'TABLE':
		case 'IMG':
			editor_noresize(e);
			break;
	}
}
function editor_setimageautofixedwidth(img, fit, isClick, padding){
    var is_obj  = (typeof(fit) == 'object' ? true:false);
    if (is_obj){
	    img.style.position	 = 'absolute';
	    img.style.visibility = 'hidden';
	    fit = parseInt(fit.offsetWidth, 10);
    }
	if (padding != null)
	    fit -= padding * 2;
	var width	= img.getAttribute('_width');
	var height	= img.getAttribute('_height');
	if (width == null){
	    var width	= img.offsetWidth;
	    var height	= img.offsetHeight;
	    img.setAttribute('_width', width);
	    img.setAttribute('_height',height);
	}
	if (fit < __editor_img_size__.width)
	    fit = __editor_img_size__.width;
	    
	if (width > fit){
		height = parseInt(height * (fit/width),10);
		width  = fit;
		img.style.width  = width;
		img.style.height = height;
		if (isClick != null && isClick){
			img.style.cursor = 'pointer';
		    img.alt          = '点击查看原图';
			img.onclick	     = function(){window.open(img.src,'_blank');}
            if (is_obj){
	            img.style.position	 = '';
	            img.style.visibility = '';
	        }
			return;
		}
	}
    if (is_obj){
        img.style.position	 = '';
        img.style.visibility = '';
    }
	img.style.cursor = '';
	img.alt          = '';
	img.onclick	     = null;
}

function editor_setimageautosize(img,box,isClick,padding){
	img.style.position	 = 'absolute';
	img.style.visibility = 'hidden';
	var width	= img.getAttribute('_width');
	var height	= img.getAttribute('_height');
	if (width == null){
	    var width	= img.offsetWidth;
	    var height	= img.offsetHeight;
	    img.setAttribute('_width', width);
	    img.setAttribute('_height',height);
	}
	if (padding == null) padding = 0;
	var _width	= box.offsetWidth -(padding * 2);
	var _height	= box.offsetHeight-(padding * 2);
	var is_change = false;
	if (width > _width){
		height = parseInt(height * (_width/width),10);
		width  = _width;
		is_change = true;
	}
	if (height > _height){
		width  = parseInt(width * (_height/height),10);
		height = _height;
		is_change = true;
	}
	if (is_change){
		img.style.width  = width;
		img.style.height = height;
		if (isClick != null){
			img.style.cursor = 'hand';
		    img.alt          = '点击查看原图';
			img.onclick	     = function(){window.open(img.src,'_blank');}
	        img.style.position	 = '';
	        img.style.visibility = '';
	        return;
		}			
	}
	img.style.position	 = '';
	img.style.visibility = '';
	img.style.cursor     = '';
	img.alt              = '';
	img.onclick	         = null;
}
//-->