var format="HTML";
//var jsPath="/article/js/";
var jsPath="";
var activeCSS="border: 1 solid buttonface; color: windowtext; cursor: text;";
var inactiveCSS="border: 1 solid window; cursor: hand; color: red;";
var validTextColor="windowtext";
var invalidTextColor="buttonshadow";

window.onload=initRichTextEditorPrime;

//初始化系统
function initRichTextEditorPrime()
{
	textEdit.document.designMode="On";
  	if (document.all.oldwebdata && document.all.oldwebdata.value && document.all.oldwebdata.value.length>1)
   	{
   		textEdit.document.open();
   		textEdit.document.write(document.all.oldwebdata.value);
   		textEdit.document.close();
   	}
   	else
   	{
		textEdit.document.open();
		textEdit.document.write("<BODY style=\"FONT-FAMILY:宋体;font-size:12pt\"></BODY>");
		textEdit.document.close();
	}
}

//判断版本
function ieVersion()
{
	var ua=window.navigator.userAgent;
	var msieIndex=ua.indexOf("MSIE")
	if(msieIndex== -1)return 0;
	return ua.substring(msieIndex+5,msieIndex+6);
}

function include(fileName)
{
	document.write('<script type="text/javascript" src="'+jsPath+fileName+'"></script>');
}

function replaceSpecial(str)
{
	return str.replace(/\&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
}

function getReal(el,type,value)
{
	temp=el;
	while((temp!=null)&&(temp.tagName!="BODY"))
	{
		if(eval("temp."+type)==value)
		{
			el=temp;return el;
		}
		temp=temp.parentElement;
	}
	return el;
}

//设置窗口布局
function fixEditorSize()
{
	document.all.textEdit.style.height=Math.max(document.body.clientHeight-document.all.textEdit.offsetTop-switchDiv.offsetHeight,0);
}

function initEditor()
{
	include("coolbuttons.js");
	fixEditorSize();
	Window.onresize=fixEditorSize;
}

//设置焦点
function setFocus()
{
	textEdit.focus();
}

//修改内容
function execCommand(command)
{	
	if(format=="HTML")
	{
		setFocus();
		var edit=textEdit.document.selection.createRange();
		if(arguments[1]==null)
			edit.execCommand(command);
		else
			edit.execCommand(command,false,arguments[1]);
		edit.select();
	}
}

//设置格式
function doFormat(what)
{
	execCommand(what,arguments[1],arguments[2]);
}

//选择
function doSelectClick(str,el)
{
	if(el.selectedIndex!= -1)
	{
		doFormat(str,el.options[el.selectedIndex].value);
		el.options[el.selectedIndex].focus();
	}
}

function paletteToggle()
{
	palette.style.display=(palette.style.display=="block")?"none":"block";
}

//提交表单
function SubmitIt( ctl, action )
{
	document.all.oldwebdata.value=textEdit.document.documentElement.innerHTML;
	document.all.MyContent.value=textEdit.document.documentElement.innerHTML;
	document.all.MyBody.value=textEdit.document.documentElement.innerText;

	document.all.postForm.submit();
}

//输入字符串并处理文档
function f_ProcInput(iProc,iInfo,iTitle)
{
	var tPath;
	tPath=f_GetText(iInfo,iTitle);
	if (tPath && tPath.length>1)
	{
		doFormat(iProc,tPath);
	}
}
