//------------获取站点跟目录-----------------------
var web_url=parent.web_url;
var web_path=parent.web_path;
var cscms_path=web_path;
//-------------------------------------------------
function $(id) {
	if(document.getElementById) {
		return document.getElementById(id);
	}else if(document.all) {
		return document.all[id];
	}else if(document.layers) {
		return document.layers[id];
	}
}

String.prototype.trim=function(){
   	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function display(id) {
     if($(id).style.display=='none'){
         $(id).style.display='';
     }else{
         $(id).style.display='none';
     }
}

function chkinput(obj,t,n){
	var re;
	if(t==1){re=/\D/g;} //数字
	if(t==2){re=/[\W]/g;} //英文、数字、下划线
	if(t==3){re=/[^\a-zA-Z0-9_/]/g;} //英文、数字、下划线、/
	if(t==4){re=/[^\a-zA-Z0-9_\u4E00-\u9FA5]/g;} //中文、英文、数字、下划线
	if(t==5){re=/[^\a-zA-Z0-9_/\u4E00-\u9FA5]/g;} //中文、英文、数字、下划线、/
	obj.onbeforepaste=function(){clipboardData.setData('text',clipboardData.getData('text').replace(re,'').substr(0,n));}
	obj.onkeyup=function(){obj.value=obj.value.replace(re,'');if(obj.value.length>n){obj.value=obj.value.substr(0,n);}}
	obj.onblur=function(){if(obj.value.length>n){obj.value=obj.value.substr(0,n)}}
}

function chkselect(s,divid){
	var divname='Issubport';
	var chkreport;
	s=Number(s)
	divname=divname+s;
	$(divid).innerHTML=divname;
	chkreport=$(divname).innerHTML;
	$(divid).innerHTML=chkreport;
}
//=========================================
function CheckAll(form){
        for (var i=0;i<form.elements.length;i++){
        var e = form.elements[i];
        if (e.name != 'chkall')
        e.checked = form.chkall.checked;
        }
}
//========================================
function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj){
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:no;');
	if (ReturnStr!='') SetObj.value=ReturnStr;
	return ReturnStr;
}

function changeAct(obj){
	var actType=obj.options[obj.selectedIndex].value;
	if(actType=="remove"){
		$("removeContain").style.display="";
	}
	else{
		$("removeContain").style.display="none";
	}
}
function showvip(){
        var actType=document.myform.CS_Vip.value;
	if(actType=="0"){
		$("vipid").style.display="none";
	}
	else{
		$("vipid").style.display="";
	}
}

//=====================编辑器=======================
function AdminEditor(cid){ //完全模式
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="'+cid+'"]', {
		      allowFileManager : true,
		      afterBlur: function(){this.sync();}
		});
	});
}

function FormEditor(cid){ //简单模式
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="'+cid+'"]', {
			resizeType : 1,
			allowPreviewEmoticons : false,
			allowImageUpload : false,
			items : [
				'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
				'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
			afterBlur: function(){this.sync();}
		});
	});

}
//============================================

function basebackup(id){
    if(id=='restore'){
        document.getElementById('basemsg').style.display = "none";
        document.getElementById(id).style.display = "";
    }else{
        document.getElementById('restore').style.display = "none";
        document.getElementById(id).style.display = "";
    }
}

function baserestore(name){

       var returned = window.confirm("您确定要还原该数据么！");
       if(returned){
           document.getElementById('restore').style.display = "none";
           document.getElementById('basemsg').style.display = "";
           window.open(web_url+'/admin/tools/restore/?name='+name+'&random='+Math.random(),'base_msg','');
       }else{
     	   return true;
       }
}

//============================================
function GetErr(msg,act){
        if(act=="goto"){if(msg.length>0)alert(msg);window.parent.location.reload();}else if(act=="off"){if(msg.length>0)alert(msg);window.parent.Dialog.close();}else{if(msg.length>0)alert(msg);}
}

function baseth(){
	var sid=document.myform.SID.value;
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/tools/ziduan/?sid="+sid;
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		var msg=unescape(xmlobj.responseText);
		$("ziduan").innerHTML = msg;
	}
}

function basedel(){
	var sid=document.myform.SID.value;
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/tools/delcid/?sid="+sid;
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		var msg=unescape(xmlobj.responseText);
		$("type").innerHTML = msg;
	}
}

function basedx(){
	var sid=document.myform.SID.value;
	var type=document.myform.type.value;
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/tools/duixiang/?sid="+sid+"&type="+type;
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		var msg=unescape(xmlobj.responseText);
		$("duixiang").innerHTML = msg;
	}
}

function basehits(){
	var sid=document.myform.SID.value;
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/tools/hitscid/?sid="+sid;
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		var msg=unescape(xmlobj.responseText);
		$("type").innerHTML = msg;
	}
}

function hitsall(){
        document.getElementById('basemsg').style.display = "";
}
//==========================================
function showtype(txt){
        if (txt == 1) {
	        $("wordform").style.display = "";	
        }else{
	        $("wordform").style.display = "none";	       
        }
}

function showtable(txt){
        if (txt == 1) {
	        $("tableform1").style.display = "";
	        $("tableform2").style.display = "none";	
        }else{
	        $("tableform1").style.display = "none";
	        $("tableform2").style.display = "";	       
        }
}

function ConfirmDel(){
   	if(confirm("确认删除？并且不能恢复！确定要删除此栏目吗？"))
     	return true;
   	else
     	return false;	 
}
function showliststyle(id){
	var obj=$(id);
        if (obj.style.display == 'none') {
	        obj.style.display = "";	
        }else{
	        obj.style.display = "none";	       
        }
}

function showliststyle2(id,id2){
	var obj=$(id),obj2=$(id2);
        if (obj.style.display == 'none') {
	        obj.style.display = "";
	        obj2.style.display = "none";		
        }else{
	        obj.style.display = "none";
	        obj2.style.display = "";		       
        }
}
function gettemplate(skins,url){
       if (url=='') {Dialog.alert('请先选定一个模板后再导入！');return false;}
	var Ajax=new AJAXRequest();
	Ajax.url=skins+"?filename="+url;
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		var msg=unescape(xmlobj.responseText);
		$("Content").value = msg;
		$(id).value="";
	}
}
//================文件删除=========================
function delrow(nTable, nPoint){
   	var myTable=$(nTable);
	var tr=$("tr_" + nPoint);       
        myTable.deleteRow(tr.rowIndex);
	Tips('删除操作成功');      	
}

function delUserFiles(strid){
	var Ajax = new AJAXRequest();
	Ajax.url=web_url+"/admin/files/del/?path="+strid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(obj) { 
		var msg=unescape(obj.responseText);
		if(msg=="ok"){
                    alert('删除成功!');
                    location.reload();
                }else{
                    alert('删除失败!');return false;
                }
	}
}

function AutoSaveFileTips(){
	var Saveobj=$("AutoSaveFile")
	if(Saveobj.checked){
	var isIe=(document.all)?true:false;
        var bWidth=parseInt(document.documentElement.scrollWidth);
        var bHeight=parseInt(document.documentElement.scrollHeight);
        var back=document.createElement("div");
        back.id="back";
        var styleStr="top:0px;left:0px;position:absolute;background:#666666;width:"+bWidth+"px;height:"+bHeight+"px;";
       	styleStr+=(isIe)?"filter:alpha(opacity=50);":"opacity:0.5;";
        back.style.cssText=styleStr;
        document.body.appendChild(back);
	var iWidth = document.documentElement.clientWidth; 
	var iHeight = document.documentElement.clientHeight;
	var oShow = $('Tips');
	oShow.style.display = '';
	oShow.style.left = (iWidth-130)/2+"px";
	oShow.style.top = document.documentElement.scrollTop+(iHeight-40)/2+"px";
	$('Tips').innerHTML="正在保存远程图片请稍候……";
	}
}
//======提示窗口================
document.write("<div id='Tips' style='z-index:1;position:absolute;width:10em;background-color:#008800;text-align:center;color:#FFFFFF;font-weight:bold;font-size:12px;display:none;'></div>");
function Tips(txt){
        var iWidth = document.documentElement.clientWidth; 
        var iHeight = document.documentElement.clientHeight;
        var oShow = $('Tips');
       	oShow.style.display = '';
        oShow.style.left = (iWidth-130)/2+"px";
        oShow.style.top = (iHeight-20)/2+"px";
	$('Tips').innerHTML=txt;
	setTimeout("sTimeout('Tips')",3000); 
}

function sTimeout(id) {
	$(id).style.display="none";
	return false;
}
//==========================================
function repairUrl(i){
	var urlStr,urlArray,newStr,j,flagCount,fromText,t
	fromText=$("m_playfrom"+i).options[$("m_playfrom"+i).selectedIndex].value
	if (fromText.length==0){Dialog.alert('请选择播放器类型');return false;}
	urlStr=$('m_playurl'+i).value
	if (urlStr.length==0){Dialog.alert('请填写地址');return false;}
	if(navigator.userAgent.indexOf("Firefox")>0){urlArray=urlStr.split("\n");}else{urlArray=urlStr.split("\r\n");}
	newStr="";
	for(j=0;j<urlArray.length;j++){
		if(urlArray[j].length>0){
			t=urlArray[j].split('$'),flagCount=t.length-1
			switch(flagCount){
				case 0:
					urlArray[j]='第'+(j<9 ? '0' : '')+(j+1)+'集$'+urlArray[j]+'$'+fromText
					break;
				case 1:
					urlArray[j]=urlArray[j]+'$'+fromText
					break;
				case 2:
					if(t[2]==''){
						urlArray[j]=urlArray[j]+fromText
					}
					break;
			}
			if(urlArray[j].indexOf('qvod://')!=-1){
				var t=urlArray[j].split("$");
				t[1]=t[1].replace(/[\u3016\u3010\u005b]\w+(\.\w+)*[\u005d\u3011\u3017]/ig,'').replace(/(qvod:\/\/\d+\|\w+\|)(.+)$/i,'$1['+(window.siteurl || document.domain)+']$2').replace(/(^\s*)|(\s*$)/ig,'');
				urlArray[j]=t.join("$");
			}
			newStr+=urlArray[j]+"\r\n";
		}
	}
	$('m_playurl'+i).value=trimOuterStr(newStr,"\r\n");
}

function trimOuterStr(str,outerstr){
	var len1
	len1=outerstr.length;
	if(str.substr(0,len1)==outerstr){str=str.substr(len1)}
	if(str.substr(str.length-len1)==outerstr){str=str.substr(0,str.length-len1)}
	return str
}

function set(obj, value) {
	obj.innerHTML = value
}

function view(id) {
	$(id).style.display = 'inline'
}
function hide(id) {
	$(id).style.display = 'none'
}

function expendPlayArea(i,optionStr,type,tname){
	if(expendPlayArea.i==false){
		expendPlayArea.i=i
	}else{
		i=++expendPlayArea.i;
	}
	optionStr=unescape(optionStr)
	var today=new Date();
	var month = today.getMonth() + 1;
	var year  = today.getYear(); 
	month     = month<10?"0"+month:month;
	var date  = year + "" + month;
	var n=i-1,m=i+1
	var area="<table width='100%' id='playfb"+i+"'><tr><td height='22'>播放来源"+i+"：<select id='m_playfrom"+i+"' name='m_playfrom'>"+optionStr+"</select>&nbsp;地址格式：<font color='red'>集数$地址$来源</font>(多集分行)</font>&nbsp;<input type='button' value='格式校正' title='校正文本框中的数据格式' onclick='repairUrl("+i+")' class='italk-st'/>&nbsp;<input type='button' value='地址采集' title='直接从视频站地址里提取地址' onclick='getvideoUrl("+i+")' class='italk-st'>&nbsp;<input type='button' name='Submit' value='视频上传' class='italk-st' onClick=\"Uploadup2('video','m_playurl"+i+"');\">&nbsp;<img onclick=\"var tb=$('playfb"+i+"');tb.parentNode.removeChild(tb);\" src='"+web_path+"csdj/admin/images/btn_dec.gif' style='cursor:pointer' title='删除播放来源"+i+"' align='absmiddle' /></td></tr><tr><td><textarea style='width:796px;height:100px' rows='5' name='"+tname+"[]' id='m_playurl"+i+"'></textarea></td></tr></table>"
	var _nextdiv=document.createElement("div");
	_nextdiv.innerHTML=area
	$('m_playarea').appendChild(_nextdiv.getElementsByTagName('table')[0]);
	_nextdiv=null;
}
expendPlayArea.i=false;

//===========================================
function Pagehtml(url){  //批量生成自定义页面
        var Cs = document.getElementsByName("CS_ID[]");
        var CMS = ""; 
        for( var i = 0; i < Cs.length; i++ ) { if ( Cs[i].checked ){ CMS += Cs[i].value+','; } } 
        CMS = CMS.substr(0,CMS.length-1);
        if(CMS==""){Dialog.alert("请最少选定一个文档！");return false;}
	var Manag = new Dialog();
	Manag.Width = 600;
	Manag.Height= 400;
	Manag.Title = "批量生成自定义页面";
	Manag.URL   = url+"?id="+CMS;
	Manag.show();
}
//===========================================
function Plruku(url){  //批量入库
	var Manag = new Dialog();
	Manag.Width = 600;
	Manag.Height= 400;
	Manag.Title = "批量入库数据";
	Manag.URL   = url;
	Manag.show();
}

function Pledit(url){  //批量修改 2013.6.15
        var Cs = document.getElementsByName("CS_ID[]");
        var CMS = ""; 
        for( var i = 0; i < Cs.length; i++ ) { if ( Cs[i].checked ){ CMS += Cs[i].value+','; } } 
        CMS = CMS.substr(0,CMS.length-1);
        if(CMS==""){Dialog.alert("请最少选定一个文档！");return false;}
	var Manag = new Dialog();
	Manag.Width = 600;
	Manag.Height= 400;
	Manag.Title = "批量修改数据";
	Manag.URL   = url+"?id="+CMS;
	Manag.show();
}
//===========================================
function SaveSpecial(url,sid,id){  //批量专题 2013.6.14
        var Cs = document.getElementsByName("CS_ID[]");
        var CMS = ""; 
        for( var i = 0; i < Cs.length; i++ ) { if ( Cs[i].checked ){ CMS += Cs[i].value+','; } } 
        CMS = CMS.substr(0,CMS.length-1);
        if(id){
             CMS=id;
        }else{
             if(CMS==""){Dialog.alert("请最少选定一个文档！");return false;}
        }
	var Manag = new Dialog();
	Manag.Width = 500;
	Manag.Height= 300;
	Manag.Title = "批量加入专题操作";
	Manag.URL   = url+"?sid="+sid+"&id="+CMS;
	Manag.show();
}
//===========================================
function baseedit(url){  //优化、修复数据表
        var Cs = document.getElementsByName("CS_ID[]");
        var CMS = ""; 
        for( var i = 0; i < Cs.length; i++ ) { if ( Cs[i].checked ){ CMS += Cs[i].value+','; } } 
        CMS = CMS.substr(0,CMS.length-1);
        if(CMS==""){alert("请最少选定一个文档！");return false;}
	var Ajax = new AJAXRequest();
	Ajax.url=url+"?table="+CMS+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.post(); 
	function mycallback(obj) { 
		var msg=unescape(obj.responseText);
		if(msg=="ok"){
                    alert("恭喜您，操作成功！");
                }else{
                    alert("抱歉，操作失败！");
                }
	}
}
//===========================================
function SelectBrother(id,obj,t){
	var title;
	var Manag = new Dialog();
	if(t==1){
		if(!$("IsGL").checked){Dialog.alert("请勾选上启用内嵌关联后操作！");return false;}
		title="编辑器内嵌信息关联";
		Manag.Modal = false;
	}else{
		title="自定义信息关联";
	}
	Manag.Width = 500;
	Manag.Height= 400;
	Manag.Title = title;
	Manag.URL   = "Cs.SelectBrother.asp?id="+id;
	Manag.OKEvent = function(){
		var Indexstr="",outid2="";
        	var Cs = Manag.innerFrame.contentWindow.document.getElementsByName("Aid");  
        	for( var i = 0; i < Cs.length; i++ ) { if ( Cs[i].checked ){ Indexstr += Cs[i].value+'-'; } } 
        	Indexstr = Indexstr.substr(0,Indexstr.length-1);
		var outid = Manag.innerFrame.contentWindow.document.getElementsByName("outid");  
        	for( var i = 0; i < outid.length; i++ ) { if ( outid[i].checked ){ outid2 += outid[i].value+','; } } 
        	outid2 = outid2.substr(0,outid2.length-1);
		if (Indexstr==''||Indexstr=='undefined'){Dialog.alert('请最少选择一条文档！');return false;}
		if (t==0){
			$(obj).value+="{$GL("+id+","+Indexstr+","+outid2+")}";
		}else{
			KE.insertHtml(obj,"{$GL("+id+","+Indexstr+","+outid2+")}");
		}
		Manag.close();
	};
	Manag.show();
}

function SelectChoice(id,obj){
	var Manag = new Dialog();
	Manag.Width = 360;
	Manag.Height= 240;
	Manag.Title = "项目参数选择";
	Manag.URL   = web_url+"/admin/rigin/xuan/?ac="+id;
	Manag.OKEvent = function(){
		var Indexstr=""
		var select=Manag.innerFrame.contentWindow.document.getElementById("oID");
		for(var i=0;i<select.length;i++){
			if(select[i].selected==true){Indexstr+=select[i].value+",";}
		}
		Indexstr=Indexstr.substr(0,Indexstr.length-1);
		if (Indexstr==''||Indexstr=='undefined'){Dialog.alert('请选择一个资源！');return false;}
		$(obj).value=Indexstr;
		Manag.close();
	};
	Manag.AbsoluteID=obj;
	Manag.show();
}

function SelectTags(obj){
	var Manag = new Dialog();
	Manag.Width = 530;
	Manag.Height= 380;
	Manag.Title = "快速选择标签";
	Manag.URL   =web_url+"/admin/tags/res?f="+obj;
	Manag.show();
}
function SelectFile(obj){
	var Manag = new Dialog();
	Manag.Width = 580;
	Manag.Height= 500;
	Manag.Title = "模板文件选择";
	Manag.URL   =web_url+"/admin/skins/res/";
	Manag.OKEvent = function(){
		var FileNamepath=Manag.innerFrame.contentWindow.FileName
		if(FileNamepath!=""){$id(obj).value = FileNamepath;}
		Manag.close();
	};
	Manag.show();
}
//导入模版
function DaoruFile(skins){
	var Manag = new Dialog();
	Manag.Width = 580;
	Manag.Height= 500;
	Manag.Title = "模板文件选择";
	Manag.URL   =web_url+"/admin/skins/res/";
	Manag.OKEvent = function(){
		var FileNamepath=Manag.innerFrame.contentWindow.FileName
		if(FileNamepath!=""){
                      gettemplate(skins,FileNamepath);
                }
		Manag.close();
	};
	Manag.show();
}

//获取歌曲属性
function Dance(url){
        var durl=document.getElementById("CS_DownUrl1").value;
        if(durl==""){
                alert('下载地址为空！');return false;
        }
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?url="+durl+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
            if(xmlobj.responseText=="no"){
                alert('获取失败！');
            } else if(xmlobj.responseText=="linux"){
                alert('Linux系统暂时不支持！');
            }else{
                var msg = unescape(xmlobj.responseText).split("|");
		document.getElementById("CS_Dx").value = msg[0];
		document.getElementById("CS_Yz").value = msg[1];
		document.getElementById("CS_Sc").value = msg[2];
            }
	}
}

function Uploadup(ids,type){
	var Manag = new Dialog();
	Manag.Width = 400;
	Manag.Height= 150;
	Manag.Title = "文件上传选择";
	Manag.URL   =web_url+"/admin/upload/duo/?ac="+ids+"&fh="+type;
	Manag.show();
}

function Uploadup2(ids,type){
	var Manag = new Dialog();
	Manag.Width = 400;
	Manag.Height= 390;
	Manag.Title = "文件上传选择";
	Manag.URL   =web_url+"/admin/upload/duo/?ac="+ids+"&fh="+type;
	Manag.show();
}

function Uploadpic(ids){
	var Manag = new Dialog();
	Manag.Width = 430;
	Manag.Height= 160;
	Manag.Title = "上传图片";
	Manag.URL   =web_url+"/admin/upload/index/?ac="+ids;
	Manag.show();
}

function SelectData(idobj,titobj,urlobj,picobj){
	var Manag = new Dialog();
	Manag.Width = 580;
	Manag.Height= 500;
	Manag.Title = "数据文档选择";
	Manag.URL   = "admin/Cs.SelectData.asp";
	Manag.OKEvent = function(){
		var FileNamepath=Manag.innerFrame.contentWindow.FileName
		if(FileNamepath!=""){
			FileNamepath=FileNamepath.split("|^|");
			if(idobj!=""){$id(idobj).value = FileNamepath[0];}
			if(titobj!=""){$id(titobj).value = FileNamepath[1];}
			if(urlobj!=""){$id(urlobj).value = FileNamepath[2];}
			if(picobj!=""&&FileNamepath[3]!=""){$id(picobj).value = FileNamepath[3];}
		}
		Manag.close();
	};
	Manag.show();
}

function opchoices(){
	var Loop=$("choices");
	var Indexstr=document.myForm.Inputbox.value;
	if(Indexstr==11){
		Loop.style.display="";
	}else{
		Loop.style.display="none";
	}
}
function showvotetype(t){
        if (t == 1) {
	        $("vt_2").style.display = "";
	        $("strOption").style.display = "";
	        $("vt_1").style.display = "none";
        }else{
	        $("vt_1").style.display = "";
	        $("vt_2").style.display = "none";
	        $("strOption").style.display = "none";
        }
}
//==================myField 文本框对象/myValue在光标处插入字符串=======
function insertAtCursor(myField, myValue) {  
	myField=$(myField);
	if (document.selection){ 
		myField.focus(); 
		sel = document.selection.createRange(); 
		sel.text = myValue; 
		sel.select(); 
	}else if (myField.selectionStart || myField.selectionStart == '0'){ 
		var startPos = myField.selectionStart; 
		var endPos = myField.selectionEnd; 
		var restoreTop = myField.scrollTop; 
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length); 
		if (restoreTop > 0){
			myField.scrollTop = restoreTop; 
		} 
		myField.focus(); 
		myField.selectionStart = startPos + myValue.length; 
		myField.selectionEnd = startPos + myValue.length; 
	} else { 
		myField.value += myValue; 
		myField.focus(); 
	} 
} 

//=======鼠标选取加入关键字词========
function getTextFieldSelection(e){
        if(e.selectionStart != undefined && e.selectionEnd != undefined) 
            return e.value.substring(e.selectionStart,e.selectionEnd); 
        else return ""; 
} 
function getKeywords(evt,Keyid){
	var inputid=$(Keyid);
	if(!inputid){return false;}
	var Keyvalue=inputid.value;
	var e=window.event?window.event:evt;
  	var textField=e.srcElement?e.srcElement:e.target;
        var selectedText; 
        if(window.getSelection) selectedText=getTextFieldSelection(textField); 
        else selectedText=document.selection.createRange().text;
	if(selectedText!=null&&selectedText.trim()!=""){
		if(Keyvalue!=null&&Keyvalue.trim()!=""){
			inputid.value+=","+selectedText;
		}else{
			inputid.value=selectedText;
		}
	} 
}

//==================选择专题====================
function optzt(obj){
	var con=Ajax_Page('zt',1);
	var str="<div id='strOption' style='margin:10px auto;'>"+con+"</div>";
	var Manag = new Dialog();
	Manag.Width = 380;
	Manag.Height= 180;
	Manag.Title = "选择专题";
	Manag.InnerHtml=str;
	Manag.OKEvent = function(){
		var Indexstr="",titles="",values="";
		var select=document.getElementById("ZTID");
		for(var i=0;i<select.length;i++){
			if(select[i].selected==true){
				values=select[i].value;
				Indexstr+="|"+values+"|";
				titles+="<a href='javascript:;' style='padding-right: 20px;' onclick='go_delzt(this,\""+obj+"\",\"|"+values+"|\");' title='点击删除'>·"+select[i].title+" ×</a>";
			}
		}
		if (Indexstr==''||Indexstr=='undefined'){Dialog.alert('请选择一个专题！');return false;}
		$(obj).value+=Indexstr;
		$(obj+"_title").innerHTML+=titles;
		Manag.close();
	};
	//Manag.AbsoluteID=obj; //隐藏文本框FF下不能定位，所以取消。
	Manag.show();
}


//=================视频采集处理=================
function copyCode(obj) { 
	obj.select(); 
	js=obj.createTextRange(); 
	js.execCommand("Copy") 
	Dialog.alert("已经复制到剪贴板中，可以通过按 Ctrl + V 键粘贴！");
} 

function getvideoUrl(id){
	var s="";
	if(id==1){s='checked';} 
	var str="<p style='height:50px;text-align:left;'>&nbsp;&nbsp;粘贴播放页面(支持优酷、酷6、土豆、搜狐、新浪、6房间、QQ、奇艺、PPS、<br>&nbsp;&nbsp;乐视、56、音悦台)地址</p>";
	str+="<p style='height:35px;'><input type='text' class='text' style='width:350px;height:17px;' id='videoUrl' value='' />";
	str+="<input type='button' class='italk-bt' value='确定' onclick='m_video("+id+");'></p>";
	str+="<p style='height:30px;text-align:left;'>&nbsp;&nbsp;同时更新：<input type='checkbox' name='m-title' id='m-title' value='1' "+s+" />视频标题&nbsp;&nbsp;";
	str+=" <input type='checkbox' name='m-PicUrl' id='m-PicUrl' value='1' "+s+" />缩略题图&nbsp;&nbsp;";
	str+=" <input type='checkbox' name='m-Origin' id='m-Origin' value='1' checked />视频来源</p>";
	var Manag = new Dialog();
	Manag.Width = 450;
	Manag.Height= 120;
	Manag.Title = "直接从视频站播放页面地址里提取地址 - 来源("+id+")";
	Manag.InnerHtml=str;
	Manag.AbsoluteID="m_playurl"+id;
	Manag.show();
}

function m_video(id) {
	var str=$("videoUrl").value;
	if (str.trim()!=''){
		var tit=0,pic=0,lys=0;
		if($("m-title").checked==true){tit=1;}
		if($("m-PicUrl").checked==true){pic=1;}
		if($("m-Origin").checked==true){lys=1;}
		$("videoUrl").value ="采集中，请稍候……";
		var Ajax=new AJAXRequest();
		Ajax.get(web_url+"/admin/ajax/caiji/?url="+str+"&random="+Math.random(),
		function(obj){
                    var neir=unescape(obj.responseText);
                    if(neir){
			var msg=neir.split("|^|");
			insertAtCursor("m_playurl"+id, msg[0]+"\n");
			if(tit==1&&msg[1]!=""){$("CS_Name").value =msg[1];}
			if(pic==1&&msg[2]!=""){$("CS_Pic").value =msg[2];}
			if(lys==1&&msg[3]!=""){
				var CS_Laiy=$("CS_Laiy").value;
				if(CS_Laiy!=null&&CS_Laiy.trim()!=""){
					if(CS_Laiy.indexOf(msg[3])==-1){$("CS_Laiy").value +=","+msg[3];}
				}else{
					$("CS_Laiy").value =msg[3];
				}
			}
                    }else{
			insertAtCursor("m_playurl"+id, neir+"\n");
                    }
			Dialog.close();
		});
	}else{
		Dialog.close();
	}
}
//================图片处理==================
function ResizeImages(myimg,maxwidth,maxheight){
   	var oldwidth,oldheight;
	if(myimg.width > myimg.height){
         	if(myimg.width > maxwidth){
            		oldwidth = myimg.width;
            		myimg.height = myimg.height * (maxwidth/oldwidth);
            		myimg.width = maxwidth;
         	}
     	}else{
         	if(myimg.height > maxheight){
            		oldheight = myimg.height;
            		myimg.width = myimg.width * (maxheight/oldheight);
            		myimg.height = maxheight;
         	}
     	}
}

function $$() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (element) {} else {
			element = null
		}
		if (arguments.length == 1) {
			return element
		} else {
			elements.push(element)
		}
	}
	return elements
}
function ABS(a) {
	a = $$(a);
	var b = {x: a.offsetLeft,y: a.offsetTop};
	a = a.offsetParent;
	while (a) {b.x += a.offsetLeft;b.y += a.offsetTop;a = a.offsetParent}
	return b
}

function PreviewImage(obj){
	var Cs=document.getElementById("Cs_img");
	if(Cs){document.body.removeChild(Cs);}
	var url,element = arguments[1];
	if (element!=undefined){
		url = element;
	}else{
		url = obj.src.replace("/s_","/");
	}	
	var imgstr='<img src="'+url+'" style="border:1px solid #CCC;cursor:url(../img/zoomout.cur),auto" />';
	var ps = ABS(obj);
        var box = document.createElement("div");
	box.id  = "Cs_img";
        box.style.display  = "block";
        box.style.position = "absolute";
        box.style.zindex   = "999";
	box.style.top = ps.y + "px";
	box.style.left= ps.x + "px"
        box.innerHTML = imgstr;
        document.body.appendChild(box);
	box.onclick=function(){document.body.removeChild(box);}
}
//===============一键生成===================
function TokeymakeAll(mid,type){
        for(var i=1;i<7;i++){document.getElementById("one_"+i).style.display  = "none";}
	makeindex(0,web_url+"/admin/html/index/?");
	makeindex(mid,web_url+"/admin/html/"+type+"/?op=index");
        if(type=='dance'){
	     TokeyHtmlopt('生成所有歌曲播放页',web_url+"/admin/html/"+type+"/?op=play&t=all");
	     TokeyHtmlopt('生成所有歌曲列表页',web_url+"/admin/html/"+type+"/?op=list&t=all");
             sid=1;
        } else if(type=='vod'){
	     TokeyHtmlopt('生成所有视频内容页',web_url+"/admin/html/"+type+"/?op=show&t=all");
	     TokeyHtmlopt('生成所有视频列表页',web_url+"/admin/html/"+type+"/?op=list&t=all");
             sid=3;
        }else{
	     TokeyHtmlopt('生成所有文章内容页',web_url+"/admin/html/"+type+"/?op=show&t=all");
	     TokeyHtmlopt('生成所有文章列表页',web_url+"/admin/html/"+type+"/?op=list&t=all");
             sid=2;
        }
	TokeyHtmlopt('生成所有专集内容页',web_url+"/admin/html/topic/?op=showall&sid="+sid);
	TokeyHtmlopt('生成所有专集列表',web_url+"/admin/html/topic/?op=list&sid="+sid);
};

function makeindex(id,Url){
	$("msg_"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=Url+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("msg_"+id).innerHTML =msg;
	} 
	return false;
}

function TokeyHtmlopt(type,URL){
	var Manag = new Dialog();
	Manag.Width = 420;
	Manag.Height= 200;
	Manag.Title = type;
	Manag.URL   = URL;
	Manag.show();
};
function Tokeymakeplay(URL){
	var Manag = new Dialog();
	Manag.Width = 420;
	Manag.Height= 200;
	Manag.Title = "生成所有播放页";
	Manag.URL   = URL;
	Manag.show();
};
function TokeymakeMsg(obj,str){
	var obj=document.getElementById(obj)
	if(obj){obj.innerHTML = str;}
}
//=============================================
function SelectListshowItem(typeid,Items){
	var II,str='<input type="checkbox" disabled checked>批量选中 ';
	str+='<input type="checkbox" disabled checked>信息标题 ';
	str+='<input type="checkbox" disabled checked>状态标识 ';
	str+='<input type="checkbox" disabled checked>管理操作 ';
	var arr=["缩略题图 ","点击人气 ","信息作者 ","添加时间 ","投票操作 ","评论操作<br>","信息来源 ","信息录入 ","评分等级 "];
	for(var t=0;t<9;t++){
		if(Items.indexOf("t"+t)>-1){II="checked";}else{II="";}
		str+='<input type="checkbox" name="ListshowItem" value="t'+t+'" '+II+'>'+arr[t];
	}
	if(typeid==3){
		var arr3=["视频导演 ","发行年份 ","视频语言 ","视频地区"];
		for(var s=0;s<4;s++){
			if(Items.indexOf("s"+s)>-1){II="checked";}else{II="";}
			str+='<input type="checkbox" name="ListshowItem" value="s'+s+'" '+II+'>'+arr3[s];
		}
	}else if(typeid==4){
		var arr4=["下载类别 ","下载语言 ","授权方式 ","运行平台 ","资源大小"];
		for(var x=0;x<5;x++){
			if(Items.indexOf("x"+x)>-1){II="checked";}else{II="";}
			str+='<input type="checkbox" name="ListshowItem" value="x'+x+'" '+II+'>'+arr4[x];
		}
	}
	$("showItem").innerHTML =str;
}

//推荐星际
function Xing(url,level,id,sid){
	$("reco"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&level="+level+"&sid="+sid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("reco"+id).innerHTML = msg; 
	} 
	return false;
}

//审核歌曲
function dancesh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//审核文章
function newssh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}


//审核视频
function vodsh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//审核专集
function topicsh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//审核歌手
function singersh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//推荐歌手
function singertj(url,tid,id){
	$("tj"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&tid="+tid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("tj"+id).innerHTML = msg; 
	} 
	return false;
}

//审核歌手
function linksh(url,yid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&yid="+yid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//推荐会员
function usertj(url,tid,id){
	$("tj"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&tid="+tid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("tj"+id).innerHTML = msg; 
	} 
	return false;
}

//解锁会员
function usersh(url,sid,id){
	$("sh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&sid="+sid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("sh"+id).innerHTML = msg; 
	} 
	return false;
}

//激活会员
function userjh(url,id){
	$("jh"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("jh"+id).innerHTML = msg; 
	} 
	return false;
}

//会员认证
function userrz(url,rzid,id){
	$("rz"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?id="+id+"&rzid="+rzid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("rz"+id).innerHTML = msg; 
	} 
	return false;
}

//生成HTML
function html(url,ac,id,cid){
	$("html"+id).innerHTML="<img src='"+web_path+"csdj/images/load.gif'>";
	var Ajax=new AJAXRequest();
	Ajax.url=url+"?ac="+ac+"&id="+id+"&cid="+cid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj) { 
		var msg= unescape(xmlobj.responseText);
		$("html"+id).innerHTML = msg;
	} 
	return false;
}
//==================================MENU==========================================
function csMenu(_menu){
	_menu=document.getElementById(_menu);
    	this.IEventHander = null;
    	this.IFrameHander = null;
    	this.IContextMenuHander = null;
    	this.Show = function(evt,_menu){
		var e=window.event?window.event:evt;
        	if (e.button == 2){
            		if (window.document.all)
            		{
                		this.IContextMenuHander = function(){return false;};
                		document.attachEvent("oncontextmenu", this.IContextMenuHander);
            		}
            		else
            		{
                		this.IContextMenuHander = document.oncontextmenu;
                		document.oncontextmenu = function(){return false;};
            		}

            		window.csMenu$Object = this;
            		this.IEventHander = function(event){window.csMenu$Object.Hide(event,_menu);};

            		if (window.document.all)
                	document.attachEvent("onmousedown", this.IEventHander);
            		else
                	document.addEventListener("mousedown", this.IEventHander, false);

			var Position = getPosition();
			var oleft=Position.left+e.clientX,otop=Position.top+e.clientY;
			if(oleft+150-Position.left > Position.width){oleft=oleft- 150;}
			if(otop+100-Position.top  > Position.height){otop=otop - 100;}

            		_menu.style.left = oleft+"px";
            		_menu.style.top  = otop+"px";
            		_menu.style.display = "";
        	}
	};

    	this.Hide = function(evt,_menu){
		var e=window.event?window.event:evt;
		var _element=e.srcElement?e.srcElement:e.target;
        	do
        	{
            		if (_element == _menu)
            		{
                	return false;
            		}
		}
        	while ((_element = _element.offsetParent));
        	if (window.document.all)
         	document.detachEvent("on"+e.type, this.IEventHander);
        	else
         	document.removeEventListener(e.type, this.IEventHander, false);

        	_menu.style.display = "none";
        
        	if (window.document.all)
         	document.detachEvent("oncontextmenu", this.IContextMenuHander);
        	else
         	document.oncontextmenu = this.IContextMenuHander;
	};

    	this.initialize = function(_menu)
    	{  
        	window._csMenu$Object = this;
        	var _eventHander = function(event){window._csMenu$Object.Show(event,_menu);};
        	_menu.style.position= "absolute";
     		_menu.style.display = "none";
     		_menu.style.zIndex  = "1000000";
        	if (window.document.all)
        	{
            		document.attachEvent("onmouseup", _eventHander);
        	}
        	else
        	{
            		document.addEventListener("mouseup", _eventHander, false);
        	}
	};
    	this.initialize(_menu);
}
function getPosition() {
        var top    = document.documentElement.scrollTop;
        var left   = document.documentElement.scrollLeft;
        var height = document.documentElement.clientHeight;
        var width  = document.documentElement.clientWidth;
        return {top:top,left:left,height:height,width:width};
}
//=======================需要显示的菜单,一般用DIV======================
document.write('<div id="Cscms_csMenu" class="DreamMenu" style="display:none">')
document.write('<a href="'+web_path+'" target="_blank">网站首页</a>') 
document.write('<a href="#" onclick="window.parent.Removecache()">更新缓存</a>') 
document.write('<a href="'+web_url+'/admin/login/logout" target="_top">退出系统</a>') 
document.write('<ul></ul>') 
document.write('<a href="http://www.chshcms.com" target="_blank">CsCMS 版权所有</a>') 
document.write('</div>')
//============================调用方法===============================
//var MM = new csMenu("Cscms_csMenu");
