var oldContent="";
function turnit(newContent) {

  if(document.all[newContent].style.display=="none") {
    if(oldContent!="") {
      document.all[oldContent].style.display="none";
    }
    oldContent=newContent;
    document.all[newContent].style.display="";
  } else {
    if(oldContent!="")
    oldContent=newContent;
    document.all[newContent].style.display="none";
  }
}

function turnit2() {
  if(oldContent!="") {
    document.all[oldContent].style.display="none";
    oldContent="";
  }
}


	function hdel(id,newclass,page,title,table_name)
	{
		if (confirm("你确定要删除 “"+id+". "+title+"” 吗？"))
		{
			document.location.href="admin.php?goto=dele&id="+id+"&newclass="+newclass+"&table_name="+table_name+"&page="+page;
		}
	}
	function unhdel(id,newclass,page,title,table_name)
	{
		if (confirm("你确定要恢复 “"+id+". "+title+"” 吗？"))
		{
			document.location.href="admin.php?goto=undele&id="+id+"&newclass="+newclass+"&table_name="+table_name+"&page="+page;
		}
	}
	function del(newclass,page,table_name)
	{
		if (confirm("您确定要批量删除选中的记录？"))
		{
			form1.action= "admin.php?goto=piliangdele&newclass="+newclass+"&table_name="+table_name+"&page="+page;
			form1.submit(); 
		}
	}
	function undel(newclass,page,table_name)
	{
		if (confirm("您确定要批量恢复删除选中的记录？"))
		{
			form1.action= "admin.php?goto=unpiliangdele&newclass="+newclass+"&table_name="+table_name+"&page="+page;
			form1.submit(); 
		}
	}
	function released(newclass,page,table_name)
	{
		if (confirm("您确定要批量关闭选中的记录？"))
		{
			form1.action= "admin.php?goto=piliangreleased&newclass="+newclass+"&table_name="+table_name+"&page="+page;
			form1.submit(); 
		}
	}
	function unreleased(newclass,page,table_name)
	{
		if (confirm("您确定要批量关闭选中的记录？"))
		{
			form1.action= "admin.php?goto=unpiliangreleased&newclass="+newclass+"&table_name="+table_name+"&page="+page;
			form1.submit(); 
		}
	}
	
	
	
	function cdel(newclass,title,table_name)
	{
		if (confirm("你确定要删除分类 “"+title+"” 吗？"))
		{
			document.location.href="admin.php?goto=newclass_dele&newclass="+newclass+"&table_name="+table_name;
		}
	}
	function mdel(newmenu,title,table_name)
	{
		if (confirm("你确定要删除菜单 “"+title+"” 吗？"))
		{
			document.location.href="admin.php?goto=newmenu_dele&newmenu="+newmenu+"&table_name="+table_name;
		}
	}
	function tdel(newtree,title,table_name)
	{
		if (confirm("你确定要删除结构 “"+title+"” 吗？"))
		{
			document.location.href="admin.php?goto=newtree_dele&newtree="+newtree+"&table_name="+table_name;
		}
	}

// 说明：Javascript 控制 CheckBox 的全选与取消全选 
function checkAll(name)
{
	var el = document.getElementsByTagName('input');
	var len = el.length;
	for(var i=0; i<len; i++) {
		if((el[i].type=="checkbox") && (el[i].name==name)) 
		{
			el[i].checked = true;
		}
	}
}

function clearAll(name)
{
	var el = document.getElementsByTagName('input');
	var len = el.length;
	for(var i=0; i<len; i++)
	{
		if((el[i].type=="checkbox") && (el[i].name==name))
		{
			el[i].checked = false;
		}
	}
}

function zz(smilieface){
   document.frmAnnounce.zznews.value=smilieface;
}

function tg(smilieface){
   document.frmAnnounce.reporter.value=smilieface;
}

function nr2(xxx,smilieface){
   xxx.value+=smilieface;
}

function o(){
	document.frmAnnounce.author.value=document.frmAnnounce.author2.value;
}

function ly(smilieface){
   document.frmAnnounce.Nfrom.value=smilieface;
}

function oCopy(obj){
   obj.select();
   js=obj.createTextRange();
   js.execCommand("Copy")
   }

function oCopy2(xxx,obj){
   obj.select();
   js=obj.createTextRange();
   xxx.value+=obj.value;
   }

function format(xxx,what,opt)//命令
{

  if (opt=="removeFormat")
  {
    what=opt;
    opt=null;
  }
  xxx.focus();
  if (opt==null) xxx.document.execCommand(what);
  else xxx.document.execCommand(what,"",opt);
}

function link1(xxx) //内部链接
{
	str=xxx.document.selection.createRange().text;
	xxx.focus();
	var my_link = prompt("Enter URL:","/info/open.php?id=");
	if (my_link != null)
	{
		var sel = xxx.document.selection.createRange();
		sel.text = "[URL=" + my_link + "]" + str + "[/URL]";
	}
	xxx.focus();
	sel.collapse(true); 
	sel.select();       	
	return;
}

function link2(xxx) //外部链接
{
	str=xxx.document.selection.createRange().text;
	xxx.focus();
	var my_link = prompt("Enter URL:","http://");
	if (my_link != null)
	{
		var sel = xxx.document.selection.createRange();
		sel.text = "<a href=\"" + my_link + "\" target=\"_blank\">" + str + "</a>";
	}
	xxx.focus();
	sel.collapse(true); 
	sel.select();       	
	return;
}

function editin(xxx,aa1,aa2) //插入通用编辑
{
	str=xxx.document.selection.createRange().text;
	xxx.focus();
	var sel = xxx.document.selection.createRange();
	sel.text = aa1 + str + aa2;
	xxx.focus();
	sel.collapse(true); 
	sel.select();       	
	return;
}

function baike(xxx) //百科重定向
{
	str=xxx.document.selection.createRange().text;
	xxx.focus();
	var my_link = prompt("输入百科链接条目:","");
	if (my_link != null)
	{
		var sel = xxx.document.selection.createRange();
		sel.text = "[[" + my_link + "|" + str + "]]";
	}
	xxx.focus();
	sel.collapse(true); 
	sel.select();       	
	return;
}

function Media(xxx,Mediatype) //插入多媒体、flash文件
{
	str=xxx.document.selection.createRange().text;
	xxx.focus();
	var my_link = prompt("输入文件地址:","");
	var my_width = prompt("视频宽度:","352");
	var my_height = prompt("视频高度:","288");
	if (my_link != null)
	{
		var sel = xxx.document.selection.createRange();
		sel.text ="[" + Mediatype+ "=" + my_width + "," + my_height + "]" + my_link + "[/" + Mediatype + "]\n" + str;
	}
	xxx.focus();
	document.frmAnnounce.Mediaselect.value="";
	sel.collapse(true); 
	sel.select();       	
	return;
}

function fontcolor(xxx,value)//字体颜色
{
	if (value != "")
	{
		str=xxx.document.selection.createRange().text;
		xxx.focus();
		var sel = xxx.document.selection.createRange();
		sel.text = "<font color=" + value + ">" + str + "</font>";
		xxx.focus();
		document.frmAnnounce.TitleFontColor.value="";
		sel.collapse(true); 
		sel.select();
	}
	return;
}

function typeset(xxx)//自动排版
{
	str=xxx.document.selection.createRange().text;
	var r, re

	str="\r\n"+str;//文首添加换行符合
	
	re = /(　| )+(\r|\n)/g;//去除行尾空格
   	r = str.replace(re, "\r\n");

	re = /((\r|\n)+(　| |)+)+/g;//替换
   	r = r.replace(re, "\r\n\r\n　　");

	re = /((\r|\n)+(　| |)+)+$/g;//去除最尾巴的换行
   	r = r.replace(re, "");

	re = /(　| )+$/g;//去除文章末尾空格
   	r = r.replace(re, "");

	re = /^(\r|\n)+/g;//去除行首换行
   	r = r.replace(re, "");
	
	xxx.focus();
	var sel = xxx.document.selection.createRange();
	sel.text = "" + r + "";
	xxx.focus();
	document.frmAnnounce.TitleFontColor.value="";
	sel.collapse(true); 
	sel.select();	
}

function nowtime_2(xxx)
{
	str=xxx.document.selection.createRange().text;
	var range=xxx.document.selection.createRange();
	xxx.focus();
	var my_link = prompt("Enter URL:","http://");
	if (my_link != null)
	{
		var sel = xxx.document.selection.createRange();
		sel.text = "[URL=" + my_link + "]" + str +range.text + "[/URL]";
		range.pasteHTML("<span style='background-color:#550000'>"+range.text+"</span> ")
		range.select();		
	}
	xxx.focus();
	return;
}
