
SEP_PADDING = 5
HANDLE_PADDING = 7

var yToolbars =	new Array();

var YInitialized = false;
helpstat = false;
stprompt = true;
basic = false;
function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}
function document.onreadystatechange()
{
  if (YInitialized) return;
  YInitialized = true;

  var i, s, curr;

  for (i=0; i<document.body.all.length;	i++)
  {
    curr=document.body.all[i];
    if (curr.className == "yToolbar")
    {
      InitTB(curr);
      yToolbars[yToolbars.length] = curr;
    }
  }

  DoLayout();
  window.onresize = DoLayout;

  Composition.document.open()
  Composition.document.write("<head><style type=\"text/css\">body {font-size: 10.8pt}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE></body>");
  Composition.document.close()
  Composition.document.designMode="On"
}

function InitBtn(btn)
{
  btn.onmouseover = BtnMouseOver;
  btn.onmouseout = BtnMouseOut;
  btn.onmousedown = BtnMouseDown;
  btn.onmouseup	= BtnMouseUp;
  btn.ondragstart = YCancelEvent;
  btn.onselectstart = YCancelEvent;
  btn.onselect = YCancelEvent;
  btn.YUSERONCLICK = btn.onclick;
  btn.onclick =	YCancelEvent;
  btn.YINITIALIZED = true;
  return true;
}

function InitTB(y)
{
  y.TBWidth = 0;

  if (!	PopulateTB(y)) return false;

  y.style.posWidth = y.TBWidth;

  return true;
}


function YCancelEvent()
{
  event.returnValue=false;
  event.cancelBubble=true;
  return false;
}

function BtnMouseOver()
{
  if (event.srcElement.tagName != "IMG") return	false;
  var image = event.srcElement;
  var element =	image.parentElement;

  if (image.className == "Ico")	element.className = "BtnMouseOverUp";
  else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";

  event.cancelBubble = true;
}

function BtnMouseOut()
{
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element =	image.parentElement;
  yRaisedElement = null;

  element.className = "Btn";
  image.className = "Ico";

  event.cancelBubble = true;
}

function BtnMouseDown()
{
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    event.returnValue=false;
    return false;
  }

  var image = event.srcElement;
  var element =	image.parentElement;

  element.className = "BtnMouseOverDown";
  image.className = "IcoDown";

  event.cancelBubble = true;
  event.returnValue=false;
  return false;
}

function BtnMouseUp()
{
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element =	image.parentElement;

  if(navigator.appVersion.match(/8./i)=='8.')
　{
　　if (element.YUSERONCLICK) eval(element.YUSERONCLICK + 'onclick(event)');
　}
　else
　{
　　if (element.YUSERONCLICK) eval(element.YUSERONCLICK + 'anonymous()');
　}

  element.className = "BtnMouseOverUp";
  image.className = "Ico";

  event.cancelBubble = true;
  return false;
}

function PopulateTB(y)
{
  var i, elements, element;

  elements = y.children;
  for (i=0; i<elements.length; i++) {
    element = elements[i];
    if (element.tagName	== "SCRIPT" || element.tagName == "!") continue;

    switch (element.className) {
    case "Btn":
      if (element.YINITIALIZED == null)	{
		if (! InitBtn(element))
			return false;
      }

      element.style.posLeft = y.TBWidth;
      y.TBWidth	+= element.offsetWidth + 1;
      break;

    case "TBGen":
      element.style.posLeft = y.TBWidth;
      y.TBWidth	+= element.offsetWidth + 1;
      break;

    case "TBSep":
      element.style.posLeft = y.TBWidth	+ 2;
      y.TBWidth	+= SEP_PADDING;
      break;

    case "TBHandle":
      element.style.posLeft = 2;
      y.TBWidth	+= element.offsetWidth + HANDLE_PADDING;
      break;

    default:
      return false;
    }
  }

  y.TBWidth += 1;
  return true;
}

function DebugObject(obj)
{
  var msg = "";
  for (var i in	TB) {
    ans=prompt(i+"="+TB[i]+"\n");
    if (! ans) break;
  }
}

function LayoutTBs()
{
  NumTBs = yToolbars.length;

  if (NumTBs ==	0) return;

  var i;
  var ScrWid = (document.body.offsetWidth) - 6;
  var TotalLen = ScrWid;
  for (i = 0 ; i < NumTBs ; i++) {
    TB = yToolbars[i];
    if (TB.TBWidth > TotalLen) TotalLen	= TB.TBWidth;
  }

  var PrevTB;
  var LastStart	= 0;
  var RelTop = 0;
  var LastWid, CurrWid;

  var TB = yToolbars[0];
  TB.style.posTop = 0;
  TB.style.posLeft = 0;

  var Start = TB.TBWidth;
  for (i = 1 ; i < yToolbars.length ; i++) {
    PrevTB = TB;
    TB = yToolbars[i];
    CurrWid = TB.TBWidth;

    if ((Start + CurrWid) > ScrWid) {
      Start = 0;
      LastWid =	TotalLen - LastStart;
    }
    else {
      LastWid =	PrevTB.TBWidth;
      RelTop -=	TB.offsetHeight;
    }

    TB.style.posTop = RelTop;
    TB.style.posLeft = Start;
    PrevTB.style.width = LastWid;

    LastStart =	Start;
    Start += CurrWid;
  }

  TB.style.width = TotalLen - LastStart;

  i--;
  TB = yToolbars[i];
  var TBInd = TB.sourceIndex;
  var A	= TB.document.all;
  var item;
  for (i in A) {
    item = A.item(i);
    if (! item)	continue;
    if (! item.style) continue;
    if (item.sourceIndex <= TBInd) continue;
    if (item.style.position == "absolute") continue;
    item.style.posTop =	RelTop;
  }
}

function DoLayout()
{
  LayoutTBs();
}

function validateMode()
{
  if (!	bTextMode) return true;
  alert("请取消“使用 HTML 语法书写”选项再使用系统编辑功能!");
  Composition.focus();
  return false;
}

function format1(what,opt)
{
  if (opt=="removeFormat")
  {
    what=opt;
    opt=null;
  }

  if (opt==null) Composition.document.execCommand(what);
  else Composition.document.execCommand(what,"",opt);

  pureText = false;
  Composition.focus();
}

function format(what,opt)
{
  if (!validateMode()) return;

  format1(what,opt);
}

function setMode(newMode)
{
  bTextMode = newMode;
  var cont;
  if (bTextMode) {
    cleanHtml();
    cleanHtml();

    cont=Composition.document.body.innerHTML;
    Composition.document.body.innerText=cont;
  } else {
    cont=Composition.document.body.innerText;
    Composition.document.body.innerHTML=cont;
  }

  Composition.focus();
}

function getEl(sTag,start)
{
  while	((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

function UserDialog(what)
{
  if (!validateMode()) return;

  Composition.document.execCommand(what, true);

  pureText = false;
  Composition.focus();
}

function foreColor()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("selcolor.htm", "", "dialogWidth:18.5em; dialogHeight:17.5em; status:0");
  if (arr != null) format('forecolor', arr);
  else Composition.focus();
}

function fortable()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("table.htm", "", "dialogWidth:18.5em; dialogHeight:11.5em; status:0");

  if (arr != null){
  var ss;
  ss=arr.split("*")
  row=ss[0];
  col=ss[1];
  var string;
  string="<table border=0 cellspacing=1 cellpadding=1 bgcolor=#000000 width=100%>";
  for(i=1;i<=row;i++){
  string=string+"<tr>";
  for(j=1;j<=col;j++){
  string=string+"<td bgcolor=#ffffff></td>";
  }
  string=string+"</tr>";
  }
  string=string+"</table>";
  content=Composition.document.body.innerHTML;
  content=content+string;
   Composition.document.body.innerHTML=content;
  }
  else Composition.focus();
}
/*当前新闻*/
function forCurrentNews()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("CurrentNews.htm", "", "dialogWidth:410px; dialogHeight:460px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1张图片*/
function forCurrent1Image()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Current1Image.htm", "", "dialogWidth:410px; dialogHeight:260px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1条记录标题*/
function forCurrent1Title()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Current1Title.htm", "", "dialogWidth:410px; dialogHeight:240px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1条记录内容*/
function forCurrent1Content()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Current1Content.htm", "", "dialogWidth:410px; dialogHeight:240px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*某类下的所有子类*/
function forGetChildList()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("getchildlist.asp", "", "dialogWidth:410px; dialogHeight:200px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*某类下的N条新闻*/
function forGetNews()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetNews.asp", "", "dialogWidth:410px; dialogHeight:500px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/**/
function forGetNewsLi(){
	if (!	validateMode())	return;
  var arr = showModalDialog("GetNewsLi.asp", "", "dialogWidth:410px; dialogHeight:350px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1张图片*/
function forGet1Image()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Get1Image.asp", "", "dialogWidth:410px; dialogHeight:260px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1条记录标题*/
function forGet1Title()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Get1Title.asp", "", "dialogWidth:410px; dialogHeight:240px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*当前栏目第1条记录内容*/
function forGet1Content()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("Get1Content.asp", "", "dialogWidth:410px; dialogHeight:240px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*获得文字图片标签*/
function forGetImgNews()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetImgNews.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*获得文字图片标签2*/
function forGetImgNews2()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetImgNews2.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*获得文字图片标签3*/
function forGetImgNews3()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetImgNews3.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*多维文字新闻标签*/
function forGetMultiTxtNews()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetMultiTxtNews.asp", "", "dialogWidth:410px; dialogHeight:450px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*多维图片新闻标签*/
function forGetMultiImgNews()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetMultiImgNews.asp", "", "dialogWidth:410px; dialogHeight:510px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*友情链接*/
function forGetFriendLink()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("FriendLink.htm", "", "dialogWidth:410px; dialogHeight:240px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*所有新闻*/
function forGetNewsAll()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetNewsAll.asp", "", "dialogWidth:460px; dialogHeight:530px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
function forGetSpecialNews(){
  if (!	validateMode())	return;
  var arr = showModalDialog("GetSpecialNews.asp", "", "dialogWidth:410px; dialogHeight:520px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*获得图片标签(Div排版)*/
function forGetImgsLi()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("GetImgLi.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*读取远程文件*/
function GetRemoteFiles(){
	if (!	validateMode())	return;
  var arr = showModalDialog("GetRemoteFiles.asp", "", "dialogWidth:410px; dialogHeight:220px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}

/*读取本地文件*/
function GetLocalFiles(){
	if (!	validateMode())	return;
  var arr = showModalDialog("GetLocalFile.asp", "", "dialogWidth:410px; dialogHeight:220px; status:0");

  if (arr != null){  
   Composition.document.body.innerHTML=arr;
  }
  else Composition.focus();
}
/*插入标签*/
function insertLabels()
{
  if (!	validateMode())	return;
  var arr = showModalDialog("labellist.asp", "", "dialogWidth:440px; dialogHeight:440px; help:no;status:0");

  if (arr != null){  
  	 //Composition.document.body.innerHTML=Composition.document.body.innerHTML+arr;
   	Composition.focus();   	
        Composition.document.selection.createRange().pasteHTML(arr);        
        Composition.focus();
  }
  else Composition.focus();
}
//
function cleanHtml()
{
  var fonts = Composition.document.body.all.tags("FONT");
  var curr;
  for (var i = fonts.length - 1; i >= 0; i--) {
    curr = fonts[i];
    if (curr.style.backgroundColor == "#ffffff") curr.outerHTML	= curr.innerHTML;
  }
}

function getPureHtml()
{
  var str = "";
  var paras = Composition.document.body.all.tags("P");
  if (paras.length > 0)	{
    for	(var i=paras.length-1; i >= 0; i--) str	= paras[i].innerHTML + "\n" + str;
  } else {
    str	= Composition.document.body.innerHTML;
  }
  return str;
}

var bLoad=false
var pureText=true
var bodyTag="<head><style type=\"text/css\">body {font-size: 9pt;line-height: 20px;}</style><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\"></head><BODY bgcolor=\"#FFFFFF\" MONOSPACE>"
var bTextMode=false

public_description=new Editor

function Editor()
{
  this.put_HtmlMode=setMode;
  this.put_value=putText;
  this.get_value=getText;
}

function getText()
{
	if (bTextMode)
		return Composition.document.body.innerText;
	else
	{
		cleanHtml();
		cleanHtml();
		return Composition.document.body.innerHTML;
	}
}

function putText(v)
{
	if (bTextMode)
		Composition.document.body.innerText = v;
	else
		Composition.document.body.innerHTML = v;
}

function InitDocument()
{
	Composition.document.open();
	Composition.document.write(bodyTag+parent.document.form1.tempcontent.value);
	Composition.document.close();
	bLoad=true;
}

function doSelectClick(str, el) {
	var Index = el.selectedIndex;
	if (Index != 0){
		el.selectedIndex = 0;
		if (el.id == "specialtype")
			specialtype(el.options[Index].value);
		else
			format(str,el.options[Index].value);
	}
}
var bIsIE5 = navigator.userAgent.indexOf("IE 5")  > -1;
var edit;
var RangeType;

function specialtype(Mark){
	var strHTML;
	if (bIsIE5) selectRange();
	if (RangeType == "Text"){
		strHTML = "<" + Mark + ">" + edit.text + "</" + Mark + ">";
		edit.pasteHTML(strHTML);
		Composition.focus();
		edit.select();
	}
}

function selectRange(){
	edit = Composition.document.selection.createRange();
	RangeType =  Composition.document.selection.type;
}
 function img() {
	   if (!	validateMode())	return;
	   //var photo_path = showModalDialog("imgup.htm", "", "dialogWidth:30.5em; dialogHeight:15.5em; status:0");
	   txt=prompt("图片文件的地址","请输入地址");
			if (txt!=null) {
				
					AddTxt="<a href="+txt+" target=_blank><IMG SRC="+txt+" border=0 alt=按此在新窗口浏览图片></a>";
					AddText(AddTxt);
	
	}
}

function rm() {
	 if (!	validateMode())	return;
			txt=prompt("Real Player视频文件的地址","请输入");
			if (txt!=null) {
				
					AddTxt="<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=250 height=200><PARAM NAME=SRC VALUE="+txt+"><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=250><PARAM NAME=SRC VALUE="+txt+"><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>";
					AddText(AddTxt);
		
	}
}

function mp() {
	 if (!	validateMode())	return;
			txt=prompt("Media Player视频文件的地址","请输入");
			if (txt!=null) {
				   
					AddTxt="<object classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6 id=WindowsMediaPlayer1 width=245 height=240><param name=URL value="+txt+"><param name=rate value=1><param name=balance value=0><param name=currentPosition value=0><param name=defaultFrame value><param name=playCount value=1><param name=autoStart value=-1><param name=currentMarker value=0><param name=invokeURLs value=-1><param name=baseURL value><param name=volume value=50><param name=mute value=0><param name=uiMode value=full><param name=stretchToFit value=0><param name=windowlessVideo value=0><param name=enabled value=-1><param name=enableContextMenu value=-1><param name=fullScreen value=0><param name=SAMIStyle value><param name=SAMILang value><param name=SAMIFilename value><param name=captioningID value><param name=enableErrorDialogs value=0><param name=_cx value=6482><param name=_cy value=6350></object>";
					AddText(AddTxt);
	}
}

function qt() {
	 if (!	validateMode())	return;
			txt=prompt("Quicktime视频文件的地址","请输入");
			if (txt!=null) {
				
					AddTxt="<embed src="+txt+" width=250 height=200 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>";
					AddText(AddTxt);
	}
}

function sk() {
	 if (!	validateMode())	return;
		txt=prompt("Shockwave文件的地址","请输入地址");
			if (txt!=null) {
				
					AddTxt="<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=250 height=200><param name=src value="+txt+"><embed src="+txt+" pluginspage=http://www.macromedia.com/shockwave/download/ width=250 height=200></embed></object>";
					AddText(AddTxt);
					
	}
}
function fl() {
	 if (!	validateMode())	return;
		 var photo_path = showModalDialog("flsup.htm", "", "dialogWidth:30.5em; dialogHeight:15.5em; status:0");
	//txt=prompt("图片文件的地址","请输入地址");
			if (photo_path!=null) {
				
					AddTxt="<a href="+photo_path+" target=_blank><IMG SRC="+photo_path+" border=0 alt=按此在新窗口浏览图片></a>";
					AddText(AddTxt);
					
	}
}
function fj() {
	 if (!	validateMode())	return;
		txt=prompt("附件文件的地址","请输入地址");
			if (txt!=null) {
				
					AddTxt="<A href="+txt+" target=_blank>点击此处查看相关附件</A>";
					AddText(AddTxt);
					
	}
}
function AddText(NewCode) {
content=Composition.document.body.innerHTML;
content=content+NewCode;
Composition.document.body.innerHTML=content;
}
function help()
{
    var helpmess;
    helpmess="---------------标签编辑器---------------\r\n\r\n"+    	 
         "1.添加标签请注意标签的作用范围(所属类别)\r\n\r\n";
    alert(helpmess);

}