﻿document.writeln("<table width=99% height=100% cellpadding=2 cellspacing=0 border=0><tr><td align=left>");
var FormatTextlist="粗体 bold|倾斜 italic|下划线 underline|上标 superscript|下标 subscript|删除线 strikethrough|删除文字格式 RemoveFormat|左对齐 Justifyleft|居中 JustifyCenter|右对齐 JustifyRight|两端对齐 justifyfull|剪切 cut|复制 copy|粘贴 paste|撤消 undo|恢复 redo";
var list= FormatTextlist.split ('|'); 
for(i=0;i<list.length;i++) {
if (list[i]=="<br>"){document.write("<br>");
}else{
var TextName= list[i].split (' '); 
document.write(" <img align=absmiddle src=/Images/Messages/ybb/"+TextName[1]+".gif alt="+TextName[0]+" style=cursor:hand onClick=FormatText('"+TextName[1]+"')> ");
}
}
document.writeln("<img src=/Images/Messages/ybb/foreColor.gif alt=\"字体颜色\" align=absmiddle style=cursor:hand onClick=foreColor()>");
document.writeln("<img src=/Images/Messages/ybb/img.gif alt=\"插入图片\" align=absmiddle style=cursor:hand onClick=img()>");
document.writeln("<img alt=\"插入表情\" src=/Images/Messages/ybb/em.gif align=absmiddle style=cursor:hand onclick=em()>");
document.writeln("<img alt=\"清理代码\" src=/Images/Messages/ybb/CleanCode.gif align=absmiddle style=cursor:hand onclick=CleanCode()>");
document.writeln("</td></tr><tr><td height=120><iframe ID=HtmlEditor MARGINHEIGHT=5 MARGINWIDTH=5 width=99% height=100%  border=0 frameborder=0 class=bk></iframe></td></tr></table>");

if (document.all){var IframeID=frames["HtmlEditor"];}else{var IframeID=document.getElementById("HtmlEditor").contentWindow;}
if (navigator.appVersion.indexOf("MSIE 6.0",0)==-1){IframeID.document.designMode="On";}
IframeID.document.open();
IframeID.document.write ('<script>i=0;function ctlent(eventobject){if(event.ctrlKey && window.event.keyCode==13 && i==0){i=1;parent.document.aspnetForm.ctl00$cph$nl.value=document.body.innerHTML;parent.document.aspnetForm.submit();parent.document.aspnetForm.submit1.disabled=true;}}<\/script><body onkeydown=ctlent()>');
IframeID.document.close();
IframeID.document.body.contentEditable = "True";
if (document.getElementById("ctl00$cph$nl") != null){
IframeID.document.body.innerHTML=document.getElementById("ctl00$cph$nl").value;
}
else{
IframeID.document.body.innerHTML=document.getElementById("nl").value;
}
IframeID.document.body.style.fontSize="10pt";


function em(){
var arr = showModalDialog("Repost/Emotion.htm", "", "dialogWidth:20em; dialogHeight:9.5em; status:0;help:0");
if (arr != null){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML(arr);
}
}

function CleanCode(){
var body = IframeID.document.body;
var html = IframeID.document.body.innerHTML;
html = html.replace(/\<p>/gi,"[$p]");
html = html.replace(/\<\/p>/gi,"[$\/p]");
html = html.replace(/\<br>/gi,"[$br]");
html = html.replace(/\<[^>]*>/g,"");
html = html.replace(/\[\$p\]/gi,"<p>");
html = html.replace(/\[\$\/p\]/gi,"<\/p>");
html = html.replace(/\[\$br\]/gi,"<br>");
IframeID.document.body.innerHTML = html;
}


function FormatText(command,option){IframeID.focus();IframeID.document.execCommand(command,true,option);}

function CheckLength(){alert("最大字符为 "+500+ " 字节\n您的内容已有 "+IframeID.document.body.innerHTML.length+" 字节");}

function emoticon(theSmilie){
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<img src=/Images/Emotions/"+theSmilie+".gif>");
}

function DoTitle(addTitle) {
var revisedTitle;var currentTitle = document.aspnetForm.topic.value;revisedTitle = addTitle+currentTitle;document.aspnetForm.topic.value=revisedTitle;document.aspnetForm.topic.focus();
}

function CheckForm(form){
var name = document.getElementById("ctl00$cph$name").value;
var code = document.getElementById("ctl00$cph$code").value;
if(name.length < 1) {alert("留言人不能为空！");return false;}
if(code.length < 1) {alert("验证码不能为空！");return false;}
aspnetForm.ctl00$cph$nl.value=IframeID.document.body.innerHTML;
MessageLength=IframeID.document.body.innerHTML.length;
if(MessageLength<10){alert("文章内容不能小于10个字符！");return false;}
if(MessageLength>500){alert("文章内容不能超过500个字符！");return false;}
document.aspnetForm.submit1.disabled = true;
}

function Gopreview()
{
document.preview.ctl00$cph$nl.value=IframeID.document.body.innerHTML; 
window.open('', 'preview_page', 'resizable,scrollbars,width=750,height=450');
document.preview.submit()
}

function BackColor()
{
  var arr = showModalDialog("Repost/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('BackColor', arr);
  else IframeID.focus();
}

function foreColor()
{
  var arr = showModalDialog("Repost/selcolor.htm", "", "dialogWidth:18em; dialogHeight:17.5em; status:0;help:0");
  if (arr != null) FormatText('forecolor', arr);
  else IframeID.focus();
}

function img(){
url=prompt("请输入图片文件地址:","http://");
if(!url || url=="http://") return;
IframeID.focus();
sel=IframeID.document.selection.createRange();
sel.pasteHTML("<br><img src="+url+" onload='if(this.width>480){var s=(585/this.width);this.width=480;this.height=this.height*s}'>");
}

// 清空编辑框内容
function Pure_empty()
{
	IframeID.document.body.innerHTML = "<P>&nbsp;</P>";
}
