/*
main:mothod
	<SCRIPT LANGUAGE="JavaScript">
	<!--
		Editor(document.form1.content.value);
	//-->
	</SCRIPT>
*/
function CheckForm(obj){
	obj.content.value = getContent();
}
//-->
var pic_cr = "yes";
//
/*********************************************
编辑器工具栏EditorToolbar()
*********************************************/
function EditorToolbar(){
document.writeln("<style>");
document.writeln(".Hand_Off {");
document.writeln("BACKGROUND-COLOR: #FFFFFFF;");
document.writeln("Text-align: center;");
document.writeln("}");
document.writeln(".Hand_On {");
document.writeln("border : 1px solid #3169C6;");
document.writeln("background-color : #C6D3EF;");
document.writeln("Text-align: center;");
document.writeln("cursor: pointer;");
document.writeln("HEIGHT: 20px;");
document.writeln("WIDTH: 20px;");
document.writeln("}");
document.writeln("<\/style>");
document.writeln("<TABLE  width=\"550\">");
document.writeln("<TR class=esing>");
document.writeln("<TD width=\"32\">");
document.writeln("<select name=\"font_size\" id=\"font_size\" onchange=\"FontSize(this.options[this.selectedIndex].value)\">");
document.writeln("<option value=\"1\">字号<\/option>");
document.writeln("<option value=\"1\">1<\/option>");
document.writeln("<option value=\"2\">2<\/option>");
document.writeln("<option value=\"3\">3<\/option>");
document.writeln("<option value=\"4\">4<\/option>");
document.writeln("<option value=\"5\">5<\/option>");
document.writeln("<option value=\"6\">6<\/option>");
document.writeln("<option value=\"7\">7<\/option>");
document.writeln("<\/select>");
document.writeln("<\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"FontColor()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/fgcolor.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>字体颜色</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"bold()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/bold.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>加粗</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"italic()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/italic.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>倾斜</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"underline()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/underline.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>下划线</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"url()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/wlink.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>超级链接</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"unurl()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/unlink.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>取消链接</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"ralign(\'left\')\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor/images/aleft.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>居左</li>\"></TD>");
document.writeln("<TD width=\"16\" OnClick=\"ralign(\'center\')\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor/images/center.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>居中</li>\"></TD>");
document.writeln("<TD width=\"16\" OnClick=\"ralign(\'right\')\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor/images/aright.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>居右</li>\"></TD>");
document.writeln("");
if (pic_cr != "no"){
document.writeln("<TD width=\"16\" OnClick=\"image()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/img.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>插入图片</li>\"><\/TD>");
}
document.writeln("<TD width=\"16\" OnClick=\"unformat()\" this.className=\'Hand_Off\';ondrag=\'return false;\'\" onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/cleancode.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>取消格式</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edcopy()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_copy.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>复制所选</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edpaste()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_paste.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>粘贴内容</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edword()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/pasteword.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>清除Word格式</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edcut()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_cut.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>剪切所选</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edDelete()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_delete.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>删除所选</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"edhtml()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_html.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>清除所有HTML格式</li>\"><\/TD>");
document.writeln("<TD width=\"16\" OnClick=\"about()\" this.className=\'Hand_Off\'; onmouseover=this.className=\'Hand_On\'; onmouseout=this.className=\'Hand_Off\';><IMG SRC=\"Editor\/images\/ed_about.gif\" WIDTH=\"16\" HEIGHT=\"16\" BORDER=\"0\" ALT=\"<li>使用说明</li>\"><\/TD>");
document.writeln("<TD><\/TD>");
document.writeln("<\/TR>");
document.writeln("<\/TABLE>");
document.writeln("");
}

/*********************************************
  编辑器工具栏结束 EditorToolbar()
*********************************************/

function Editor(content){
	EditorToolbar();
	content = content.replace(/(src="up\/([^\s>]+)")/gi, 'src="..\/up\/$2"');
	var strHtml = '<html>\n';
	 strHtml += '<head>\n';
	 strHtml += '<TITLE>EXW Flash CMS - Editor</TITLE>\n';
	 strHtml += '<META http-equiv=Content-Type content="text/html; charset=gb2312">\n';
	 strHtml += '<style>\nbody{font-size:12px;line-height: 20px; margin:2px;}\n';
	 strHtml += 'td, a{color:#0000FF; font-size:12px;}\nimg{cursor:default;}\n';
	 strHtml += '</style>\n';
	 strHtml += '</head>\n';
	 strHtml += '<!--Content Start-->\n';
	 strHtml += '<body>\n'+content+'\n</body>\n';
	 strHtml += '<!--Content End-->\n';
	 strHtml += '</html>';
	var wrEditorContent = ('<iframe name="wrEditor" id="wrEditor" width="550" height="230" src="about:blank"></iframe>');
	document.write(wrEditorContent);
	oEditor = document.wrEditor;
	oEditor.document.open();
	oEditor.document.write(strHtml);
	oEditor.document.close();
	oEditor.document.designMode="On";
	oEditor.focus();
}

//文字加粗 
function bold(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("bold");
	}
}
//倾斜
function italic(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("italic");
	}
}
//下划线
function underline(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("underline");
	}
}
//超链接
function url(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("createLink");
	}
}
//取消链接
function unurl(){
	var sText = oEditor.document.selection.createRange();
	if(sText!=""){
		oEditor.document.execCommand("unlink");
	}	
}
/*插入图片*/
function image(){
	var arr = showModalDialog("Editor/include/img.htm", window, "dialogWidth:600px; dialogHeight:300px; status:0; help:0");
	if (arr)
	{
	    oEditor.focus();
		oEditor.document.execCommand("InsertImage", false, arr);
		//oEditor.document.body.innerHTML += arr;
	}
	//oEditor.focus();
}

/*说明信息*/
function about(){
	var arr = showModalDialog("Editor/include/about.htm", window, "dialogWidth:545px; dialogHeight:300px; status:0; help:0");
}

/*参数：left/center/right*/
function ralign(aStr){
	switch(aStr){
	case "left":
		oEditor.document.execCommand("JustifyLeft");
		break;
	case "center":
		oEditor.document.execCommand("JustifyCenter");
		break;
	case "right":
		oEditor.document.execCommand("JustifyRight");
		break;
	default:
		return false;
	}
}
/*字体颜色*/
function FontColor(){
	var arr = showModalDialog("Editor/include/selcolor.htm", window, "dialogWidth:300px; dialogHeight:280px; status:0; help:0");
	if (arr)
	{
		var sText = oEditor.document.selection.createRange();
		if(sText){
			oEditor.document.execCommand("ForeColor", "false", arr);
		}
	}
	oEditor.focus();
}
/*字体大小*/
function FontSize(value){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("FontSize", "false",  value );
	}	
}
/*字体名称*/
function FontName(value){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("FontName", "false", value);
	}	
}
/*取消格式*/ 
function unformat(){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("unlink");
		oEditor.document.execCommand("RemoveFormat", false, "");
	}
}
/*去除HTML*/ 
function edhtml(){
    var HtmlStr = oEditor.document.body.innerHTML;
    HtmlStr = HtmlStr.replace(/<.*?>/g, '');
    oEditor.document.body.innerHTML = HtmlStr;
}
// 清除WORD冗余格式
function edword() {
	html = oEditor.document.body.innerHTML;
	// 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>" ) ;
	
    oEditor.document.body.innerHTML = html;
}
/*复制选中*/
function edcopy(){
    oEditor.document.execCommand('Copy');
}
/*粘贴内容*/
function edpaste(){
    oEditor.focus();
    oEditor.document.execCommand('paste');
}
/*剪切选中*/
function edcut(){
    oEditor.document.execCommand('Cut');
}
/*删除选中*/
function edDelete(){
    oEditor.document.execCommand('Delete');
}
function getContent()
{
	return correctUrl(oEditor.document.body.innerHTML);
}
function correctUrl(cont)
{
	cont = cont.replace(/<.*?>/g, rec);
	cont = cont.replace(/(<P align="([^\s>]+)"><IMG src="([^\s>]+)")/gi ,'<P><IMG align="$2" src="$3"');
	cont = cont.replace(/(<P align="([^\s>]+)"><IMG align="([^\s>]+)" src="([^\s>]+)")/gi ,'<P><IMG align="$2" src="$4"');
	return cont;
} 
function rec(tag){
	//tag = tag.replace(/(IMG) .*?(src=.*)\b.*?/gi, '$1 $2');
	tag = tag.replace(/(A) .*?(href=.*) .*?/gi, '$1 $2');
	tag = tag.replace(/(face=([^\s>]+))/gi, '');
	tag = tag.replace(/(family=([^\s>]+))/gi, '');
	tag = tag.replace(/(border=([^\s>]+))/gi, '');
	tag = tag.replace(/(alt=([^\s>]+))/gi, '');
	tag = tag.replace(/(Title=((\w|\W)+))/gi, '');
	tag = tag.replace(/(dypop=([^\s>]+))/gi, '');
	tag = tag.replace(/(hlink=([^\s>]+))/gi, '');
	tag = tag.replace(/(target=([^\s>]+))/gi, '');
	tag = tag.replace(/(dir=([^\s>]+))/gi, '');
	tag = tag.replace(/(onclick=([^\s>]+))/gi, '');
	tag = tag.replace(/(href="javascript:(.*?)")/gi, 'href="http://www.2ey.cn/"');
	tag = tag.replace(/(STRONG)/g, 'B');
	tag = tag.replace(/<\\?xml[^>]*>/gi, "") ;
	tag = tag.replace(/(<!--((\w|\W)+)-->)/gi, '');
	tag = tag.replace(/<\??xml[^>]*>/gi, "") ;
	tag = tag.replace(/(color=([^"\s>]+))/g, 'color="$2"');
	tag = tag.replace(/(size=([^"\s>]+))/g, 'size="$2"');
	tag = tag.replace(/(src=([^"\s>]+))/g, 'src="$2"');
	tag = tag.replace(/(width=([^"\s>]+))/gi, 'width="$2"');
	tag = tag.replace(/(height=([^"\s>]+))/gi, 'height="$2"');
	tag = tag.replace(/(align=([^"\s>]+))/gi, 'align="$2"');
	tag = tag.replace(/(src="..\/([^\s>]+)")/gi ,'src="$2"');
	
	tag = tag.replace(/(<[^>]+) class=[^ |^>]*([^>]*>)/gi, '$1$2');
	tag = tag.replace(/(<[^>]+) style=\"[^\"]*\"([^>]*>)/gi, '$1$2');

	return tag;
}
function insertHTML(html) {
	oEditor.document.selection.createRange().pasteHTML(html) ; 
}