<% Option Explicit %>
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<%
Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<%
Dim Path,FileName,EditFile,FileContent
Path = Request.QueryString("Path")
FileName = Request.QueryString("FileName")
EditFile = Server.MapPath(Path) & "\" & FileName
Dim FsoObj,FileObj,FileStreamObj
Set FsoObj = Server.CreateObject("Scripting.FileSystemObject")
Set FileObj = FsoObj.GetFile(EditFile)
Set FileStreamObj = FileObj.OpenAsTextStream(1)
if Not FileStreamObj.AtEndOfStream then
	FileContent = FileStreamObj.ReadAll
else
	FileContent = ""
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文本编辑器---<% = FileName %></title>
</head>
<link rel="stylesheet" href="Editer.css">
<script language="JavaScript" src="../JS/PublicJS.js"></script>
<body topmargin="0" leftmargin="0" oncontextmenu="return false;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr id="ToolBar" height="32">
    <td height="30"> 
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="30" height="30"> <div align="center"><img src="../Images/Editer/save.gif" alt="保存" width="23" height="22" class="ToolBtn" onClick="SaveFile();"></div></td>
          <td width="30" height="30"> <div align="center"><img alt="插入表格" onClick="InsertTable();" src="../Images/Editer/table.gif" width="23" height="22" class="ToolBtn"></div></td>
          <td width="30" height="30"> <div align="center"><img alt="插入图片" onClick="InsertImg();" src="../Images/Editer/image.gif" width="23" height="22" class="ToolBtn"></div></td>
          <td width="30" height="30"> <div align="center"><img alt="插入JS" src="../Images/Editer/InsertJs.gif" width="23" height="22" class="ToolBtn" onclick="InserJS();"></div></td>
          <td width="30" height="30"> <div align="center"><img alt="插入表单" onClick="InsertForm();" src="../Images/Editer/form.gif" width="23" height="22" class="ToolBtn"></div></td>
		  <td width="160"> 
            <select onChange="InsertFormCode(this)" title="插入表单代码" style="width:100%;" name="select">
				<option value="" selected>插入表单对象</option>
				<option value="input" InsertType="text">文本字段</option>
				<option value="input" InsertType="hidden">隐藏域</option>
				<option value="textarea"InsertType="">文本区域</option>
				<option value="input"InsertType="checkbox">复选框</option> 
				<option value="input"InsertType="radio">单选按钮</option> 
				<option value="select"InsertType="">列表/菜单</option> 
				<option value="input"InsertType="submit">提交按钮</option> 
				<option value="input"InsertType="reset">重置按钮</option> 
				<option value="input"InsertType="button">按钮</option> 
            </select></td>
		  <td width="30" height="30"> <div align="center"><img alt="退出" src="../Images/Editer/Exit.gif" width="23" height="22" class="ToolBtn" onclick="window.close();"></div></td>
          <td height="30">&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td id="EditAreaTR"><textarea onChange="SetEditFlag();" id="EditArea" style="width:100%;" name="textarea"><% =FileContent %></textarea></td>
  </tr>
</table>
</body>
</html>
<iframe id="SaveFrame" src="SaveFileFrame.asp" width="0" height="0"></iframe>
<form id="TempForm" name="TempForm"></form>
<%
Set FsoObj = Nothing
Set FileObj = Nothing
Set FileStreamObj = Nothing
%>
<script language="JavaScript">
var AlreadyEdit=false;
var bInitialized = false;
var Path='<% = Path %>';
var FileName='<% = FileName %>';
function SetEditAreaHeight()
{
	var BodyHeight=document.body.clientHeight;
	var EditAreaHeight=BodyHeight-document.all.ToolBar.height;
	document.all.EditArea.style.height=EditAreaHeight;
}
SetEditAreaHeight();
window.onresize=SetEditAreaHeight;
window.onunload=PromptSave;
function document.onreadystatechange()
{
	if (document.readyState!="complete") return;
	if (bInitialized) return;
	bInitialized = true;
	var i,j,s,curr;
	for (i=0; i<document.body.all.length;i++)
	{
		curr=document.body.all[i];
		if (curr.className == "ToolBtn") InitBtn(curr);
	}
}
function SetEditFlag()
{
	AlreadyEdit=true;
}
function PromptSave()
{
	if (AlreadyEdit==true)
	{
		if (confirm('文件已经修改，要保存吗？')==true) SaveFile();
	}
}
function InserJS()
{
	var Str='<'+'script language="JavaScript" type="text/JavaScript">'+'\n\n</script'+'>';
	InsertStr(Str);
}
function InsertTable()
{
	EditArea.focus();
	var Str='<table>\n <tr>\n <td>   </td>\n </tr>\n</table>';
	InsertStr(Str);
}
function InsertImg()
{
	var ReturnValue=OpenWindow('../inc/SelectPic.asp',550,290,window)
	if (ReturnValue!='')
	{
		var Str='<img src="'+ReturnValue+'">';
		InsertStr(Str);
	}
}
function InsertFormCode(Obj)
{
	var CreateObj;
	if (Obj.value!='')
	{
		CreateObj=document.createElement(Obj.value);
		switch (Obj.value)
		{
			case 'input':
				CreateObj.type=Obj.options(Obj.selectedIndex).InsertType;
				break;
			case 'select':
				break;
			case 'textarea':
				CreateObj.cols='1';
				CreateObj.rows='1';
				break;
			default:
				return;
		}
		CreateObj.name='FormArea';
		document.all.TempForm.appendChild(CreateObj);
		InsertStr(document.all.TempForm.innerHTML);
		document.all.TempForm.innerHTML='';
		Obj.options(0).selected=true;
	}
}
function InsertStr(Str)
{
	EditArea.focus();
	var RangeObj=document.selection.createRange();
	RangeObj.text=Str;
}
function InsertForm()
{
	var Str='<form name="" action="" method="post">\n\n</form>';
	InsertStr(Str);
}
function SaveFile()
{
	var SaveForm=frames["SaveFrame"].document.SaveFileForm;
	SaveForm.Path.value=Path;
	SaveForm.FileName.value=FileName;
	SaveForm.FileContent.value=EditArea.value;
	SaveForm.Result.value='Submit';
	SaveForm.submit();
	SaveForm.Result.value='';
	AlreadyEdit=false;
}
function InitBtn(btn) 
{
	btn.onmouseover = BtnMouseOver;
	btn.onmouseout = BtnMouseOut;
	btn.onmousedown = BtnMouseDown;
	btn.onmouseup = BtnMouseOut;
	btn.ondragstart = YCancelEvent;
	btn.onselectstart = YCancelEvent;
	btn.onselect = YCancelEvent;
	btn.disabled=false;
	return true;
}

function BtnMouseOver() 
{
	var image = event.srcElement;
	image.className = "ToolBtnMouseOver";
	event.cancelBubble = true;
}

function BtnMouseOut() 
{
	var image = event.srcElement;
	image.className = "ToolBtn";
	event.cancelBubble = true;
}

function BtnMouseDown() 
{
	var image = event.srcElement;
	image.className = "ToolBtnMouseDown";
	event.cancelBubble = true;
	event.returnValue=false;
	return false;
}
function YCancelEvent() 
{
	event.returnValue=false;
	event.cancelBubble=true;
	return false;
}
</script>