﻿
	
function SEditor_B(editor){
	edtFormat(editor,"bold");
}
function SEditor_I(editor){
	edtFormat(editor,"italic");
}
function SEditor_U(editor){
	edtFormat(editor,"underline");
}
function SEditor_FColor(editor){
	var colorPage = "/SimpleEditor/colorpicker.aspx";
	if(navigator.appName.indexOf("etscape")>-1)
	{
		window.open(colorPage,'newWin','modal=yes,width=210,height=170,resizable=no,scrollbars=no'); 
	}
	else
	{
		var color = showModalDialog(colorPage,window,'dialogWidth:210px;dialogHeight:170px;status:0;scroll:0;help:0;');	
		editor.document.execCommand('forecolor','',color);
	}
}
function SEditor_FColorFireFox(color)
{
	Editor1.document.execCommand('forecolor','',color);
}
function SEditor_InsertPic(editor){
	var url = prompt("请输入图片的地址(图片宽度不过超过500像素).", "http://");
	if (url == "http://" || url == null || url == "" || url == "undefined") return;		
	var img = "<img src='" + url + "' />";
	if(navigator.appName.indexOf("icrosoft")>-1)
	{
		editor.focus();
		var range = editor.document.selection.createRange();
		range.pasteHTML(img);
		editor.focus();	
	}
	else
	{
		var html = editor.document.body.innerHTML + img;
		SEditor_Initialize(editor,html);
		editor.focus();
	}
}
function SEditor_InsertFlash(editor){
	var url = prompt("请输入Flash的地址.", "http://");
	if (url == "http://" || url == null || url == "" || url == "undefined") return;		
	var flash = "<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=200 height=200><PARAM NAME=movie VALUE="+url+"><PARAM NAME=quality VALUE=high><PARAM NAME=menu VALUE=false><embed src="+url+" quality=high pluginspage="+"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" +" width=200 height=200>"+url+"</embed></OBJECT>";;
	
	if(navigator.appName.indexOf("icrosoft")>-1)
	{
		editor.focus();
		var range = editor.document.selection.createRange();
		range.pasteHTML(flash);
		editor.focus();	
	}
	else
	{
		var html = editor.document.body.innerHTML + flash;
		SEditor_Initialize(editor,html);
		alert(editor.document.body.innerHTML);
		editor.focus();
	}
}
function SEditor_InsertFace(editor){
	var facePage = "/SimpleEditor/facepicker.htm";
	if(navigator.appName.indexOf("etscape")>-1)
	{
		window.open(facePage,'newWin','modal=yes,width=500,height=360,resizable=no,scrollbars=no'); 
	}
	else
	{
		var url = showModalDialog(facePage,window,'dialogWidth:500px;dialogHeight:360px;status:0;scroll:0;help:0;');
		if (url == "http://" || url == null || url == "" || url == "undefined") return;		
		var face = "<img src='" + url + "' />";
		editor.focus();
		var range = editor.document.selection.createRange();
		range.pasteHTML(face);
		editor.focus();	
	}
}
function SEditor_InsertFaceFireFox(url)
{
	var editor = window.frames["Editor1"];
	if (url == "http://" || url == null || url == "" || url == "undefined") return;		
	var face = "<img src='" + url + "' />";
	var html = editor.document.body.innerHTML + face;
	SEditor_Initialize(editor,html);
}
function SEditor_InsertLink(editor){
	editor.focus();
    editor.document.execCommand('createlink','1',null);
}
function edtFormat(editor, format){
	editor.focus();
	editor.document.execCommand(format,'',null);
}
function SEditor_Initialize(editor,initHtml) {
	editor.document.designMode = 'On';	
	editor.document.open();
	editor.document.write(initHtml);
	editor.document.close();
	editor.document.contentEditable = 'True';	
}

function Editor1_CancelEvent(){
    var editor = Editor1;
    editor.event.cancelBubble = true; 
	editor.event.returnValue = false; 
	return false;
}

var seditor;
if(navigator.appName.indexOf("etscape")>-1)
    seditor = window.frames["Editor1"];
else
    seditor = Editor1;
SEditor_Initialize(seditor,document.all.Editor1Data.value);

var objEditor;
if(navigator.appName.indexOf("icrosoft")>-1)
{
    document.getElementById("Editor1_button").style.display = "block";
    objEditor = document.getElementById("Editor1");
    objEditor.attachEvent("onblur", Editor_Blur);
	Editor1.document.attachEvent("onkeydown",Editor_KeyDown);
}
else
{
    document.getElementById("Editor1_button").style.display = "none;"
    objEditor = document.getElementById("Editor1").contentDocument;
	objEditor.addEventListener("blur",Editor_Blur,false);
	objEditor.addEventListener("keypress",Editor_KeyDown,false);
}
function Editor_Blur()
{
	if(navigator.appName.indexOf("icrosoft")>-1)
		document.getElementById("Editor1Data").value = document.frames["Editor1"].document.body.innerHTML;
	else
	    document.getElementById("Editor1Data").value = objEditor.body.innerHTML;
}


function Editor_KeyDown(e)
{
	if(navigator.appName.indexOf("icrosoft")>-1)
	{
		var editor = Editor1;
		if(editor.event.keyCode==13 && editor.event.ctrlKey)
		{
			if( editorSubmit != null){
				document.getElementById("Editor1Data").value=editor.document.body.innerHTML;
				editorSubmit();
				return false;
			}
		}
		if(editor.event.keyCode==86 && editor.event.ctrlKey)
		{
			var editor = Editor1;
			editor.document.selection.createRange().pasteHTML(window.clipboardData.getData("Text"));
			return false;
		}
	}
	else
	{
		if(arguments[0].keyCode==13 && arguments[0].ctrlKey && editorSubmit != null)
		{
			document.getElementById("Editor1Data").value = objEditor.body.innerHTML;
			editorSubmit();
			return false;
		}
		/*if(arguments[0].keyCode==0 && arguments[0].ctrlKey)
		{
			alert("B");
			alert(window.clipboardData.getData("Text"));
			objEditor.document.selection.createRange().pasteHTML(window.clipboardData.getData("Text"));
			return false;
		}*/
	}

}