/*
main:mothod
	<SCRIPT LANGUAGE="JavaScript">
	<!--
		Editor(document.form1.content.value);
	//-->
	</SCRIPT>
*/
function CheckForm(obj){
	obj.content.value = getContent();
}
//-->

/*********************************************
编辑器工具栏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=\"字体颜色\"><\/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=\"加粗\"><\/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=\"倾斜\"><\/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=\"下划线\"><\/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=\"超级链接\"><\/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=\"取消链接\"><\/TD>");
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=\"插入图片\"><\/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=\"取消格式\"><\/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=\"使用说明\"><\/TD>");
document.writeln("<TD><\/TD>");
document.writeln("<\/TR>");
document.writeln("<\/TABLE>");
document.writeln("");
}

/*********************************************
  编辑器工具栏结束 EditorToolbar()
*********************************************/
function Editor(content){
	EditorToolbar()
	document.write('<iframe name="wrEditor" id="wrEditor" width="550" height="230" src="about:blank"></iframe>');
	oEditor = document.wrEditor;
	var strHtml = '<html><style>body{font-size:12px;line-height: 20px; margin:2px;}\ntd, a{color:#0000FF; font-size:12px;}</style><body>'+content+'</body></html>';
	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:200px; status:0; help:0");
	if (arr)
	{
		oEditor.document.body.innerHTML+=arr;
	}
	oEditor.focus();
}
//说明信息
function about(){
	var arr = showModalDialog("Editor/include/about.htm", window, "dialogWidth:310px; 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 unformat(){
	var sText = oEditor.document.selection.createRange();
	if(sText){
		oEditor.document.execCommand("RemoveFormat", false, "");
	}	
}
function getContent()
{
	return correctUrl(oEditor.document.body.innerHTML);
}
function correctUrl(cont)
{
	cont = cont.replace(/<.*?>/g, c);
	return cont;
}	
function c(tag){
	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(/(face=([^"\s>]+))/g, '');
	tag = tag.replace(/(face="([^"\s>]+)")/g, '');
	tag = tag.replace(/(family=([^"\s>]+))/g, '');
	tag = tag.replace(/(family="([^"\s>]+)")/g, '');
	tag = tag.replace(/(width=([^"\s>]+))/g, '');
	tag = tag.replace(/(width="([^"\s>]+)")/g, '');
	tag = tag.replace(/(height=([^"\s>]+))/g, '');
	tag = tag.replace(/(height="([^"\s>]+)")/g, '');
	tag = tag.replace(/(border=([^"\s>]+))/g, '');
	tag = tag.replace(/(border="([^"\s>]+)")/g, '');
	tag = tag.replace(/(alt=([^"\s>]+))/g, '');
	tag = tag.replace(/(alt="([^"\s>]+)")/g, '');
	tag = tag.replace(/(Title=([^"\s>]+))/g, '');
	tag = tag.replace(/(Title="([^"\s>]+)")/g, '');
	tag = tag.replace(/(style=".*?")/g, '');
	tag = tag.replace(/(onclick=".*?")/g, '');
	tag = tag.replace(/(href="javascript:(.*?)")/g, 'href="http://www.2ey.cn/"');
	tag = tag.replace(/(STRONG)/g, 'B');
	return tag;
}


