function killErr() {
	return true;
}
window.onerror=killErr;
function Trim() {
	return this.replace(/\s+$|^\s+/g,"");
}
String.prototype.Trim=Trim;
function F(id) {
	if(G(id).value!=undefined)
	return G(id).value.Trim();
	else
	return "";
}
function G(id) {
	if(document.getElementById) {
		return document.getElementById(id);
	}else if(document.all) {
		return document.all[id];
	}else if(document.layers) {
		return document.layers[id];
	}
}
var pos=null;
function setPos(){ 
	if (document.all){
		document.myform.Content.focus();
		pos = document.selection.createRange();
	}else{
		pos = G("Content").selectionStart;
	}
}
function InsertValue(str){
  	if (pos==null) {alert('请先在下面循环区定位要插入的位置！');return false;}
	if (document.all){
		pos.text=str;
	}else{
		var obj   = G('Content');
		var lstr  = obj.value.substring(0,pos);
		var rstr  = obj.value.substring(pos);
		obj.value = lstr+str+rstr;
	}
}

function InsertCustomValue(id){
	var htm0='';
	var htm1='<a href="" title="" target="_blank"></a>';
	var htm2='<img src="" width="" height="" alt="" />';
	var htm3='<li class="{typeclass}"><a href="{typeurl}" title="{typetitle}" target="{typetarget}" class="Hx{typeid}">{typename}</a></li>';
	var htm4='<li><a href="javascript:void(0)" onclick="showDiary({=diaryid});">{=diaryname}({=diarytime})</a></li>';
	if(id==1){
		InsertValue(htm1);
	}else if(id==2){
		InsertValue(htm2);
	}else if(id==3){
		InsertValue(htm3);
	}else if(id==4){
		InsertValue(htm4);
	}else{
		InsertValue(htm0);
	}
}

function showclass(n,id){
	var Indexstr=F(n);
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/label/ajax/?cid="+Indexstr+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		G("select_"+id).innerHTML = unescape(xmlobj.responseText);
	}
        if(n=="LP_12"){
             if(Indexstr==1){
                      document.getElementById('dance').style.display='';
                      document.getElementById('news').style.display='none';
                      document.getElementById('singer').style.display='none';
                      document.getElementById('vod').style.display='none';
                      document.getElementById('topic').style.display='';
                      document.getElementById('xing').style.display='';
                      document.getElementById('xing2').style.display='none';
                      showtopic(Indexstr);
             } else if(Indexstr==2){
                      document.getElementById('dance').style.display='none';
                      document.getElementById('news').style.display='';
                      document.getElementById('singer').style.display='none';
                      document.getElementById('vod').style.display='none';
                      document.getElementById('topic').style.display='';
                      document.getElementById('xing').style.display='';
                      document.getElementById('xing2').style.display='none';
                      showtopic(Indexstr);
             } else if(Indexstr==3){
                      document.getElementById('dance').style.display='none';
                      document.getElementById('news').style.display='none';
                      document.getElementById('singer').style.display='none';
                      document.getElementById('vod').style.display='';
                      document.getElementById('topic').style.display='';
                      document.getElementById('xing').style.display='';
                      document.getElementById('xing2').style.display='none';
                      showtopic(Indexstr);
             } else if(Indexstr==4){
                      document.getElementById('dance').style.display='none';
                      document.getElementById('news').style.display='none';
                      document.getElementById('singer').style.display='';
                      document.getElementById('vod').style.display='none';
                      document.getElementById('topic').style.display='none';
                      document.getElementById('xing').style.display='none';
                      document.getElementById('xing2').style.display='';
             }
        }
}

function showtopic(sid){
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/label/topic/?sid="+sid+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		G("tlist").innerHTML = unescape(xmlobj.responseText);
	}
}

function showLabelSetForm(act){
	var Ajax=new AJAXRequest();
	Ajax.url=web_url+"/admin/label/form/?ac="+act+"&random="+Math.random();
	Ajax.oncomplete=mycallback; 
	Ajax.get(); 
	function mycallback(xmlobj){ 
		G("LabelSetContent").innerHTML = unescape(xmlobj.responseText);
	}
}

function showsome(){
	var Loop=G("Loopcontent");
	var Indexstr=document.myform.LaNames.value;
	showLabelSetForm(Indexstr);
	if(Indexstr=="Cs_0"){
		Loop.style.display="none";
	}else{
		Loop.style.display="";G("Content").innerHTML="";
	}
	var LabelParam=parent.G("LabelParam");
	if(LabelParam){LabelParam.value="";parent.FunParam();}
}

function replaceLoopcontent(str,A,B,C,D){  //标签，名称，内容，时间
	var contstr=str;
	if(A!=''&&A!=0){
		contstr=contstr.replace(":name]",":name len="+A+"]");
	}
	if(B!=''&&B!=0){
		contstr=contstr.replace(":content]",":content len="+B+"]");
		contstr=contstr.replace(":neir]",":neir len="+B+"]");
	}
	if(C!=''&&C!=0){
              if(D==1){
		for(var i=1;i<=4;i++){
		   C=C.replace("[moxing:","[dance:");
                }
		contstr=contstr.replace("[dance:time]",""+C+"");
              } else if(D==2){
		for(var i=1;i<=4;i++){
		   C=C.replace("[moxing:","[news:");
                }
		contstr=contstr.replace("[news:time]",""+C+"");
              } else if(D==3){
		for(var i=1;i<=4;i++){
		   C=C.replace("[moxing:","[vod:");
                }
		contstr=contstr.replace("[vod:time]",""+C+"");
              } else if(D==4){
		for(var i=1;i<=4;i++){
		   C=C.replace("[moxing:","[singer:");
                }
		contstr=contstr.replace("[singer:time]",""+C+"");
              }
		contstr=contstr.replace("[topic:time]",""+C+"");
	}
	return contstr;
}

function aa(){
    var xingji="";
    var rs=document.getElementsByName("LP_2"); 
    for(var i=0;i<rs.length;i++){
         if(rs[i].checked){
             xingji+=rs[i].value+",";
         }
    }      
    if(xingji!=''){xingji=xingji.substr(0,xingji.length-1);}
    return xingji;
}


function submitdate(){
	var LengthArr="",Lpname="",p=0,Labelstr="";
	var v0,v1,v2,v3,v4,v5,v6,v7,v8,Xing,Name,Neir,Time;
	var Indexstr=document.myform.LaNames.value;
	var Loopcontent=document.myform.Content.value.replace("'","\'");

	if (Indexstr=='Cs_0') {alert('请选择一个系统函数标签名称！');return false;}
	if(Indexstr=="Cs_cms" || Indexstr=="Cs_self" || Indexstr=="Cs_js" || Indexstr=="Cs_page"){
		Labelstr='\n'+Loopcontent+'\n';
	}
	if(Indexstr=="Cs_class"){
		v11=F("LP_11");
	        if (v11==0) {alert('请选择要操作的版块！');return false;}
		v0=F("LP_0");
		v1=F("LP_1");
		v4=F("LP_4");
	        if (v0<1) {alert('数量最少为1！');return false;}

                if(v11==1 || v11==2){
                    if(v1=="all"){
		      Labelstr='\n{cscms:class loop='+v0+' sid='+v11+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:class}';
                    }else{
		      Labelstr='\n{cscms:class cid='+v1+' sid=1 order='+v4+'}\n'+Loopcontent+'\n{/cscms:class}';
                    }
                } else if(v11==3){
                    if(v1=="all"){
		      Labelstr='\n{cscms:vlist loop='+v0+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:vlist}';
                    }else{
		      Labelstr='\n{cscms:vlist cid='+v1+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:vlist}';
                    }
                } else if(v11==4){
                    if(v1=="all"){
		      Labelstr='\n{cscms:gslist loop='+v0+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:gslist}';
                    }else{
		      Labelstr='\n{cscms:gslist cid='+v1+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:gslist}';
                    }
                }
	}
	if(Indexstr=="Cs_link"){
		v0=F("LP_0");
		v1=F("LP_1");
		Labelstr='\n{cscms:link loop='+v0+' cid='+v1+'}\n'+Loopcontent+'\n{/cscms:link}';
	}
	if(Indexstr=="Cs_vod"){
		Labelstr='\n{cscms:play loop=all start=1}\n'+Loopcontent+'\n {cscms:url start=1} \n <a href="[url:link]" title="[url:name]" target="_blank">[url:name]</a> \n {/cscms:url} \n {/cscms:play}';
	}
	if(Indexstr=="Cs_topic"){
		v0=F("LP_0");
		v1=F("LP_1");
		v3=F("LP_3");
		v4=F("LP_4");
		Xing=aa(); //星际
		Name=F("LP_5"); //名称
		Neir=F("LP_6"); //内容
		Times=F("LP_7"); //时间
	        if (v0<1) {alert('数量最少为1！');return false;}
		Loopcontent=replaceLoopcontent(Loopcontent,Name,Neir,Times); //替换长度和时间类型标签
                if(Xing!=""){
		      Labelstr='\n{cscms:topic loop='+v0+' stars='+Xing+' sid='+v1+' sort='+v3+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:topic}';
                } else {
		      Labelstr='\n{cscms:topic loop='+v0+' sid='+v1+' sort='+v3+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:topic}';
                }
	}
	if(Indexstr=="Cs_data"){
                var topic="";var tids="";
		v12=F("LP_12");
	        if (v12==0) {alert('请选择要操作的版块！');return false;}
		v0=F("LP_0");
		v1=F("LP_1");
		v3=F("LP_3");
		v4=F("LP_4");
		v13=F("LP_13");
		Name=F("LP_5"); //名称
		Neir=F("LP_6"); //内容
		Times=F("LP_7"); //时间
		v8=F("LP_8");
                if (v12==4){
		   v10=F("LP_10");
		   v11=F("LP_11");
                   if(v10==1){ tids=" tid=1";}
                }else{
		   Xing=aa(); //星际
		   v9=F("LP_9");
                   if(v9!=0){ topic=" tid="+v9+"";}
                   if(Xing!=""){ Xing=" stars="+Xing+"";}
                }
	        if (v0<1) {alert('数量最少为1！');return false;}
		Loopcontent=replaceLoopcontent(Loopcontent,Name,Neir,Times,v12); //替换长度和时间类型标签
	        if (v12==1) { //歌曲
                     if(v13==2){
		           Labelstr='\n{cscms:dance pagesize='+v0+''+Xing+' cid=auto sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:dance}';
                     } else {
		           Labelstr='\n{cscms:dance loop='+v0+''+Xing+' cid='+v1+' sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:dance}';
                     }
	        } else if (v12==2) { //文章
                     if(v13==2){
		           Labelstr='\n{cscms:news pagesize='+v0+''+Xing+' cid=auto sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:news}';
                     } else {
		           Labelstr='\n{cscms:news loop='+v0+''+Xing+' cid='+v1+' sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:news}';
                     }
	        } else if (v12==3) { //视频
                     if(v13==2){
		           Labelstr='\n{cscms:vod pagesize='+v0+''+Xing+' cid=auto sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:vod}';
                     } else {
		           Labelstr='\n{cscms:vod loop='+v0+''+Xing+' cid='+v1+' sort='+v3+''+topic+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:vod}';
                     }
	        } else if (v12==4) { //歌手
                     if(v13==2){
		           Labelstr='\n{cscms:singer pagesize='+v0+' singer='+v11+' cid=auto sort='+v3+''+tids+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:singer}';
                     } else {
		           Labelstr='\n{cscms:singer loop='+v0+' cid='+v1+' singer='+v11+''+tids+' sort='+v3+' order='+v4+'}\n'+Loopcontent+'\n{/cscms:singer}';
                     }
                }
	}
    	parent.InsertValue(Labelstr);
	var LabelParam=parent.G("LabelParam");
	if(Lpname!=''){Lpname=Lpname.substr(0,Lpname.length-1);}   //去掉参数最后一个逗号
	if(LabelParam){LabelParam.value=Lpname;parent.FunParam();} //将参数传到父页面
	parent.Dialog.close();       //调用父页面JS关闭本页面

}
