<?
	$page=trim($_GET["page"]);
	$page=$page==""?"default":strtolower($page);
	switch($page){
		case "table":
			table();
			break;
		case "color":
			color();
			break;
		case "index":
		default:
			index();
			break;
	}
?>



<?
	function index(){		
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>PLUM's Editor</title>

<style>
#menu		{
					padding:0px 0px 0px 3px;
					width:420px;
					border:solid 0px #FFFFFF;
				}
#menu img	{
					border:solid 0px #FFFFFF;					
				}
#menu a:link , #menu a:hover , #menu a:visited{
					padding-top:2px;
					text-align:center;
					width:22px;
					height:26px;
					text-decoration: none;
					border:solid 1px #FFFFFF;
					background:#FFFFFF;					
				}
#menu a:hover{
					border:solid 1px #999999;
					background:#EEEEEE;
				}
</style>

</head>

<body leftmargin="0" topmargin="0" style="word-break:break-all;overflow-y:auto;" bgcolor="#FFFFFF">
<table id="defaults" width="590" align="left" valign="top" border="0"  cellspacing="0" cellpadding="0" style="word-break:break-all;" ondrag="return(false)">
  <tr id="bar1" style="height:28px; display:block;"> 
		<td id="toolbar" valign="middle">
			<select id="FontName" title="字体名" onchange="format('fontname',this[this.selectedIndex].value);">
				<option value="宋体" selected>字体
				<option value="宋体">宋体
				<option value="黑体">黑体
				<option value="楷体_GB2312">楷体
				<option value="仿宋_GB2312">仿宋
				<option value="隶书">隶书
				<option value="幼圆">幼圆
				<option value="Arial">Arial
				<option value="Arial Black">Arial Black
				<option value="Comic Sans MS">Comic Sans
				<option value="System">System
				<option value="Wingdings">Wingdings</option>
			</select>
		</td>
		<td valign="middle">
			<select id="FontSize" title="字号大小" onchange="format('fontsize',this[this.selectedIndex].value);">
				<option value="4" selected>字号
				<option value="7">一号
				<option value="6">二号
				<option value="5">三号
				<option value="4">四号
				<option value="3">五号
				<option value="2">六号
				<option value="1">七号</option>
			</select>
		</td>
		<td valign="bottom">

			<div id="menu">

				<a href="#">      
					<img src="images/bold.gif"       onmouseup="format('bold');"  TITLE="加粗">
				</a>				
				<a href="#">      
					<img src="images/italic.gif"     onmouseup="format('italic');"  TITLE="斜体">
				</a>				
				<a href="#">      
					<img src="images/underline.gif"  onmouseup="format('underline');"  TITLE="下划线">
				</a>				
				<a href="#">      
					<img src="images/aleft.gif"      onmouseup="format('justifyleft');"  TITLE="左对齐">
				</a>				
				<a href="#">      
					<img src="images/center.gif"     onmouseup="format('justifycenter');"  TITLE="居中">
				</a>				
				<a href="#">      
					<img src="images/aright.gif"     onmouseup="format('justifyright');"  TITLE="右对齐">
				</a>				
				<a href="#">      
					<img src="images/numlist.gif"    onmouseup="format('insertorderedlist');"  TITLE="编号">
				</a>				
				<a href="#">      
					<img src="images/bullist.gif"    onmouseup="format('insertunorderedlist');"  TITLE="项目符号">
				</a>				
				<a href="#">      
					<img src="images/outdent.gif"    onmouseup="format('outdent');"  TITLE="减少缩进量">
				</a>				
				<a href="#">      
					<img src="images/indent.gif"     onmouseup="format('indent');"  TITLE="增加缩进量">
				</a>			
				<a href="#">      
					<img src="images/table.gif"      onmouseup="fortable();"  TITLE="插入表格">
				</a>     
				<a href="#">      
					<img src="images/wlink.gif"      onmouseup="UserDialog('CreateLink');"  TITLE="插入超级连接">
				</a>       
				<a href="#">      
					<img src="images/hr.gif"         onmouseup="format('InsertHorizontalRule');"  TITLE="插入水平线">
				</a>
				<a href="#">
					<img src="images/color.gif"      onmouseup="forcolor();"  TITLE="设置颜色">
				</a>
				<a href="#">      
					<img src="images/image.gif"        onmouseup="up('image');"  TITLE="插入图片">
				</a>
				<a href="#">      
					<img src="images/flash.gif"        onmouseup="up('flash');"  TITLE="插入动漫">
				</a> 
				<a href="#">      
					<img src="images/packet.gif"        onmouseup="up('packet');"  TITLE="上传文件">
				</a>

			</div>

		</td>
  </tr>
	<tr id="bar2" style="height:28px; display:none;">
		<td><font style='font-size:12px;color:#000000;'>提示：当前为“源代码”编辑方式，工具条不可见。</font></td>
	</tr>
  <tr>
    <td colspan="40">
			<div style="border:solid 1px #000000;width:590px;overflow-x:hidden;">
				<iframe id="Editor" width="605" height="236" frameborder="0" scrolling="none"></iframe>
			</div>
		</td>
  </tr>
	<tr>
		<td colspan="10" height="30">
			<img id="design"  src="images/design.gif"  style="cursor:hand;border:1px inset; background:#EEEEEE;" onclick="mode()">
			<img id="code"    src="images/code.gif"    style="cursor:hand;border:1px outset;background:#FFFFFF;" onclick="mode()">
			<img id="preview" src="images/preview.gif" style="cursor:hand;border:1px outset;background:#FFFFFF;" onclick="preview()">
		</td>
		<td colspan="30" align="right">
			<!-- 
			<img src="images/sizeplus.gif" style="cursor:hand;border:1px outset; " onclick="change('+')" title="增加编辑框高度">
			<img src="images/sizeminu.gif" style="cursor:hand;border:1px outset; " onclick="change('-')" title="减小编辑框高度">
			-->
		</td>
	<tr>
</table>
<script language="javascript">

 Editor.document.open();
 Editor.document.write("<body style='margin:2px;font:12px Fixedsys;word-break:break-all;'>")
 Editor.document.designMode="On";
 Editor.document.close(); 

function format(what,opt)
{
  if(opt==null) 
    {Editor.document.execCommand(what);}
  else 
    {Editor.document.execCommand(what,"",opt);}
  check();  
}

function UserDialog(what)
{
  Editor.document.execCommand(what, true);
  check();
}

function forcolor()
{
 var arr = showModalDialog("?page=Color", "", "dialogWidth:18em; dialogHeight:16em;help=no;resizable=no;status=no;scroll=no;center=yes;");
 if(arr != null) 
   {format('forecolor', arr);}
 check();	
}

function fortable()
{
 var arr = showModalDialog("?page=Table", "", "dialogWidth:13.5em; dialogHeight:11em;help=no;resizable=no;status=no;scroll=no;center=yes;");
 if (arr != null)
 {
  var ss;
  ss=arr.split("*")
  row=ss[0];
  col=ss[1];
  mod=100%col
  wid=(100-mod)/col
  var str;
  str="<table align=center width=560 border=1  cellpadding=2 cellspacing=0 bordercolor=#111111 style='border-collapse: collapse;word-break:break-all;'>";
  for(i=1;i<=row;i++){
  str=str+"<tr>";
  for(j=1;j<=col;j++){
  str=str+"<td width="+wid+"%>&nbsp;</td>";
  }
  str=str+"</tr>";
  }
  str=str+"</table>";
	Editor.focus();
	Editor.document.selection.createRange().pasteHTML(str);
 }
 check();	
}

function up(what)
{
 if(what=="")
 {
	check();
  return false;
 }
	
 if(upfile()==1)
 { 
  if(what=="image")
  {
   str="<img class=UpFile src="+UpFile_Path+" alt="+UpFile_Describe+" align=left style='margin:5px;'>";
  }
  if(what=="flash")
  {
	 str="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  align='absmiddle'><PARAM NAME='Src' value='"+UpFile_Path+"'><param name='quality' value='high'><param name='BGCOLOR' value='#000000'><param name='SCALE' value='exactfit'><PARAM NAME='Play' VALUE='1'><PARAM NAME='Menu' VALUE='-1'></object>";
  }
  if(what=="packet")
  {
   str="<a class=UpFile href="+UpFile_Path+" title="+UpFile_Describe+">"+UpFile_Describe+"</a>";
  }
	// 设置父窗口表单属性
  objstr="window.parent.document.all."+what
  obj=eval(objstr);
	if(obj!=null){obj.value=UpFile_Path;}
	Editor.focus();
	Editor.document.selection.createRange().pasteHTML(str);
 }
 check(); 
}

function preview()
{
	if(bar1.style.display=="block")
	{
		str=Editor.document.body.innerHTML;
	}
	else
	{
		str=Editor.document.body.innerText;
	}
  win=window.open('about:blank','preveiw','');
  win.document.write(str);
  win.focus();
}

function mode()
{
	if(bar1.style.display=="block")
	{
		design.style.borderStyle="outset";
		design.style.background="#FFFFFF"
		code.style.borderStyle='inset'
		code.style.background="#EEEEEE"
		bar1.style.display="none";
		bar2.style.display="block";
		Editor.document.body.innerText=Editor.document.body.innerHTML;		
	}
	else
	{
		design.style.borderStyle="inset";
		design.style.background="#EEEEEE"
		code.style.borderStyle='outset'
		code.style.background="#FFFFFF"
		bar1.style.display="block";
		bar2.style.display="none";
		Editor.document.body.innerHTML=Editor.document.body.innerText;
	}
	check()
	return false
}

// 判断滚动条
function check()
{
	Editor.focus();
	Editor.document.body.scrollTop=Editor.document.body.scrollTop+1;
	if(Editor.document.body.scrollTop!=0)
	{
		document.all.Editor.height=document.all.Editor.height-(-50);

		//判断该页面是否被上一页面嵌套
		obj=window.parent.document.all.item("plum")
		if( obj != null )
		{
			window.parent.document.all.plum.height=window.parent.document.all.plum.height-(-50);
			window.parent.document.body.scrollTop=window.parent.document.all.plum.height;
		}
		check();
	}	
}

// 快捷键
function KeyDown(event)
{ 
	//alert(event.keyCode);
	var key = String.fromCharCode(event.keyCode).toUpperCase();
	if (event.keyCode==9) // Tab
	{
		var caretPos = Editor.document.selection.createRange();
		caretPos.text="    "
		event.cancelBubble = true;
		event.returnValue = false;
		return false;
	}

	if (event.keyCode==13 || (event.ctrlKey && event.keyCode==13) ) // Enter
	{
		var sel = Editor.document.selection.createRange();
		if (event.ctrlKey){
			sel.pasteHTML("<p>");
		}
		else{
			sel.pasteHTML("<br>");
		}
		event.cancelBubble = true;
		event.returnValue = false;
		sel.select();
		sel.moveEnd("character", 1);
		sel.moveStart("character", 1);
		sel.collapse(false);
		return false;
	}

	// 屏蔽事件 Ctrl+B,I,U
	if (event.ctrlKey)
	{	
		if ((key == "B")||(key == "I")||(key == "U"))
		{
			//return false;
		}
	}
	
}


document.oncontextmenu=new Function("return false;");
document.ondblclick=new Function("return false;");
Editor.document.onclick=check;
Editor.document.oncontextmenu=new Function("check();return false;");
Editor.document.onkeydown= new Function("return KeyDown(Editor.event);");
Editor.document.onkeyup=check;
</script>
<? require_once("upfile.php"); ?>
</body>
</html>

<?		
	}

	function table(){
?>

<HTML>
<HEAD>
<TITLE>表格</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE TYPE="text/css">
 td {font-size: 10.8pt}
 body {font-size: 10.8pt}
 BUTTON {width:5em}
</STYLE>
<SCRIPT LANGUAGE=JavaScript FOR=Ok EVENT=onclick>
  window.returnValue = selrow.value+"*"+selcol.value
  window.close();
</SCRIPT>

</HEAD>

<BODY bgcolor=menu>

<div align="center"><center><br>
<table border="0" cellspacing="10" cellpadding="0">
<tr><td colspan=2 align=center>输入表格</td></tr><tr><td align=center>
行数: </td><td align=center>列数：</td></tr><tr><td><INPUT TYPE=TEXT SIZE=7 ID=selrow></td><td><input type=text id=selcol size=7></tr>
<tr><td colspan=2 align=center><BUTTON ID=Ok TYPE=SUBMIT>确定</BUTTON>&nbsp;<BUTTON ONCLICK="window.close();">取消</BUTTON></td></tr></table></center></div>

</BODY>   
</HTML>			

<?
	}

	function color(){
?>

<HTML>
<HEAD>
<TITLE>颜色</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE TYPE="text/css">
 td {font-size: 10.8pt}
 body {font-size: 10.8pt}
 BUTTON {width:5em}
</STYLE>

<SCRIPT LANGUAGE=JavaScript>
var SelRGB = '';
var DrRGB = '';
var SelGRAY = '120';

var hexch = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');

function ToHex(n)
{	var h, l;

	n = Math.round(n);
	l = n % 16;
	h = Math.floor((n / 16)) % 16;
	return (hexch[h] + hexch[l]);
}

function DoColor(c, l)
{ var r, g, b;

  r = '0x' + c.substring(1, 3);
  g = '0x' + c.substring(3, 5);
  b = '0x' + c.substring(5, 7);
  
  if(l > 120)
  {
    l = l - 120;

    r = (r * (120 - l) + 255 * l) / 120;
    g = (g * (120 - l) + 255 * l) / 120;
    b = (b * (120 - l) + 255 * l) / 120;
  }else
  {
    r = (r * l) / 120;
    g = (g * l) / 120;
    b = (b * l) / 120;
  }

  return '#' + ToHex(r) + ToHex(g) + ToHex(b);
}

function EndColor()
{ var i;

  if(DrRGB != SelRGB)
  {
    DrRGB = SelRGB;
    for(i = 0; i <= 30; i ++)
      GrayTable.rows(i).bgColor = DoColor(SelRGB, 240 - i * 8);
  }

  SelColor.value = DoColor(RGB.innerText, GRAY.innerText);
  ShowColor.bgColor = SelColor.value;
}
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=ColorTable EVENT=onclick>
  SelRGB = event.srcElement.bgColor;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=ColorTable EVENT=onmouseover>
  RGB.innerText = event.srcElement.bgColor;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=ColorTable EVENT=onmouseout>
  RGB.innerText = SelRGB;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=GrayTable EVENT=onclick>
  SelGRAY = event.srcElement.title;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=GrayTable EVENT=onmouseover>
  GRAY.innerText = event.srcElement.title;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=GrayTable EVENT=onmouseout>
  GRAY.innerText = SelGRAY;
  EndColor();
</SCRIPT>

<SCRIPT LANGUAGE=JavaScript FOR=Ok EVENT=onclick>
  window.returnValue = SelColor.value;
  window.close();
</SCRIPT>

</HEAD>

<BODY bgcolor=menu>

<div align="center"><center><table border="0" cellspacing="10" cellpadding="0"><tr><td>
<TABLE ID=ColorTable BORDER=0 CELLSPACING=0 CELLPADDING=0 style='cursor:hand'>
<SCRIPT LANGUAGE=JavaScript>
function wc(r, g, b, n)
{
	r = ((r * 16 + r) * 3 * (15 - n) + 0x80 * n) / 15;
	g = ((g * 16 + g) * 3 * (15 - n) + 0x80 * n) / 15;
	b = ((b * 16 + b) * 3 * (15 - n) + 0x80 * n) / 15;

	document.write('<TD BGCOLOR=#' + ToHex(r) + ToHex(g) + ToHex(b) + ' height=8 width=8></TD>');
}

var cnum = new Array(1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0);

  for(i = 0; i < 16; i ++)
  {
     document.write('<TR>');
     for(j = 0; j < 30; j ++)
     {
     	n1 = j % 5;
     	n2 = Math.floor(j / 5) * 3;
     	n3 = n2 + 3;

     	wc((cnum[n3] * n1 + cnum[n2] * (5 - n1)),
     		(cnum[n3 + 1] * n1 + cnum[n2 + 1] * (5 - n1)),
     		(cnum[n3 + 2] * n1 + cnum[n2 + 2] * (5 - n1)), i);
     }

     document.writeln('</TR>');
  }
</SCRIPT>
</TABLE></td><td>
<TABLE ID=GrayTable BORDER=0 CELLSPACING=0 CELLPADDING=0 style='cursor:hand'>
<SCRIPT LANGUAGE=JavaScript>
  for(i = 255; i >= 0; i -= 8.5)
     document.write('<TR BGCOLOR=#' + ToHex(i) + ToHex(i) + ToHex(i) + '><TD TITLE=' + Math.floor(i * 16 / 17) + ' height=4 width=20></TD></TR>');
</SCRIPT>
</TABLE></td></tr></table></center></div>

<div align="center"><center><table border="0" cellspacing="10" cellpadding="0">
<tr><td rowspan="2" align="center">
选中色彩<table ID=ShowColor border="1" width="40" height="30" cellspacing="0" cellpadding="0">
<tr><td></td></tr></table></td>
<td rowspan="2">基色: <SPAN ID=RGB></SPAN><BR>
亮度: <SPAN ID=GRAY>120</SPAN><BR>
代码: <INPUT TYPE=TEXT SIZE=7 ID=SelColor></td>
<td><BUTTON ID=Ok TYPE=SUBMIT>确定</BUTTON></td></tr>
<tr><td><BUTTON ONCLICK="window.close();">取消</BUTTON></td></tr></table></center></div>

</BODY>   
</HTML>			

<?
	}	
?>