var ajax = new AJAX();ajax.setcharset("GBK");

function openUpdateWin(width, height,str){
	openWindow2(101,width,height,50)
	var msgDiv=S("msg")
	var bgDiv=S("bg")
	var iWidth = document.documentElement.scrollWidth
	var str="<div style='width:400px;'><div class='divboxtitle'><span onclick=\"closeWin();set(S('update'),'<font color=red >版本暂未升级...</font>');\" ><img src='../pic/btn_close.gif'/></span>RenDie在线升级</div><div  class='divboxbody'>"+str+"<input type='button' value='进入升级页面' id='openwin' class='btn'/>&nbsp;&nbsp;&nbsp;&nbsp;<input id='closewin' type='button' value='取   消' name='button' class='btn'  /></div><div class='divboxbottom'>Power By RenDie</div></div>"
	msgDiv.style.cssText += "FONT-SIZE: 12px;top:100px;left:"+(iWidth-width)/2+"px;text-align:center;";
	set(msgDiv,str)
	S("closewin").onclick = function(){
		closeWin()
		set(S("update"),"<font color='red'>版本暂未升级...</font>");
	}
	S("openwin").onclick = function(){
		closeWin()
		location.href='admin_update.asp';
	}
}
 
function checkNewVersionCallBack(obj){
	 
	if (obj.responseText == "False"){
		set(S("update"),"<font color='red'>暂时没有可升级文件!</font>");
	}else{
		openUpdateWin(400, "auto",obj.responseText)	
	}
}

function checkNewVersion(){
	set(S("update"),"<font color='red'>请稍等，正在检测新版本...</font>");
	var getUrl = "admin_update.asp?action=isNew";
	ajax.get(
		getUrl,
		checkNewVersionCallBack
	);	
}

function checkRepeat(){
	ajax.get(
		"admin_ajax.asp?action=checkrepeat&m_name="+S('m_name').value,
		function(obj){
			if (obj.responseText == "ok"){set(S("m_name_ok"),"<img src='img/yes.gif' border=0></img>");}else{set(S("m_name_ok"),"<img src='img/no.gif' border=0></img>");}
		}
	);	
}

function setVideoTopic(videoId,topicId){
	openWindow2(101,230,20,0)
	var msgDiv=S("msg")
	var topicTDObj = S("topic"+videoId);
	var topicTDTop = topicTDObj.offsetTop;
    var topicTDLeft = topicTDObj.offsetLeft;
    while (topicTDObj = topicTDObj.offsetParent){topicTDTop+=topicTDObj.offsetTop; topicTDLeft+=topicTDObj.offsetLeft;}
    msgDiv.style.cssText+="border:1px solid #55BBFF;background: #C1E7FF;padding:3px 0px 3px 4px;"
	msgDiv.style.top = (topicTDTop-1)+"px";
    msgDiv.style.left = (topicTDLeft-1)+"px"; 
	msgDiv.innerHTML="正在加载内容....";	
	ajax.get(
		"admin_ajax.asp?id="+videoId+"&action=select&topicid="+topicId, 
		function(obj) {
			msgDiv.innerHTML=obj.responseText;
		}
	);
}

function setVideoState(videoId){
	openWindow2(101,250,20,0)
	var msgDiv=S("msg")
	var topicTDObj = S("state"+videoId);
	var topicTDTop = topicTDObj.offsetTop;
    var topicTDLeft = topicTDObj.offsetLeft; 
    while (topicTDObj = topicTDObj.offsetParent){topicTDTop+=topicTDObj.offsetTop; topicTDLeft+=topicTDObj.offsetLeft;}
    msgDiv.style.cssText+="border:1px solid #55BBFF;background: #C1E7FF;padding:3px 0px 3px 4px;"
	msgDiv.style.top = (topicTDTop-1)+"px";
    msgDiv.style.left = (topicTDLeft-1)+"px"; 
	msgDiv.innerHTML="状态：连载到第<input type='text' size='5' id='series' name='series'>集<input type='button' value='确定' onclick='submitVideoState("+videoId+")' class='btn' /><input type='button' value='取消' onclick='closeWin()' class='btn' />";	
}

function submitVideoTopic(videoId){
	var topic,imgsrc
	 topic=S("topicselect").value
	if (topic.length==0) {
		alert('请选择专题')
		return false
	}
	ajax.get(
		"admin_ajax.asp?id="+videoId+"&topic="+topic+"&action=submittopic", 
		function(obj) {
			if(obj.responseText == "submitok"){
				if(videoId==0){imgsrc="img/icon_l01.gif";}else{imgsrc="img/icon_l02.gif";}
				set(S("topic"+videoId),"<img src='"+imgsrc+"' title='修改专题' style=\"cursor:pointer;\" onclick=\"setVideoTopic("+videoId+","+topic+")\"/>"+S("topicselect").options[S("topicselect").selectedIndex].text);
				closeWin();
			}else{
				set(S("topic"+videoId),"<font color='red'>发生错误</font>");		
			}
		}
	);
}

function GenerateImages(path,pathID,W,H){
  if (W==""&&H==""){alert('生成的宽高不能同时为空！');return false;}
  if (path==""){alert('图片地址不能为空！');return false;}
  ajax.get("admin_ajax.asp?action=GenerateImages&W="+W+"&H="+H+"&PathPic="+path, 
	function(obj){
	  if(obj.responseText == "err"){
		S(pathID).value="图片地址不正确！"
		}else{
		S(pathID).value=obj.responseText;
	  }
	}
  );
}

function submitVideoState(videoId){
	var state = S("series").value
	if (isNaN(state)) {
		alert('集数为数字')
		return false
	}else if(state == 'undefined' || state == ''){
		alert('集数不能为空')
		return false
	}
	ajax.get(
		"admin_ajax.asp?id="+videoId+"&state="+state+"&action=submitstate", 
		function(obj) {
			if(obj.responseText == "submitok"){
				set(S("state"+videoId),"<font color='red'>(连载到"+state+"集)</font>");
				closeWin();
			}else{
				set(S("state"+videoId),"<font color='red'>发生错误</font>");		
			}
		}
	);
}

function selectPicLink(selectObj,str){
	var selectValue=selectObj.options[selectObj.selectedIndex].value
	if 	(selectValue==str)
		S("tr_pre_pic").style.display=""
	else 
		S("tr_pre_pic").style.display="none"
}

function openAdWin(divid,path,url){
	S(divid).style.display="block";
	selfLabelWindefault(divid);	
	S("adpath").value='<script type=\"text/javascript\" language=\"javascript" src=\"'+url+path.replace("../","")+'\"></script>';	
}

function openHtmlToJsWin(divid){
	S(divid).style.display="block";
	selfLabelWindefault(divid);	
}

function insertHtmlToJsWin(divid,divid2,divid3){
	hide(divid);
	S(divid2).value=S(divid3).value
}

function openSelfLabelWin(divid,id){
	S(divid).style.display="block";
	selfLabelWindefault(divid);	
	set(S("labelcontent"),"代码加载中...");	
	ajax.get(
		"admin_ajax.asp?id="+id+"&action=getselflabel", 
		function(obj) {
			if(obj.responseText == "err"){
				set(S("labelcontent"),"发生错误");	
			}else{
				set(S("labelcontent"),obj.responseText);
			}
		}
	);
}

function selfLabelWindefault(divid){	
	S(divid).style.left=(document.documentElement.clientWidth-568)/2+"px"
	S(divid).style.top=(getScroll()+60)+"px"
}

function viewCurrentAdTr(id){
	var adtrObj=getElementsByName("tr","adtr")
	var n=adtrObj.length
	for (var i=0;i<=n-1;i++){
		adtrObj[i].className="";
	}
	S("adtr"+id).className="editlast";
}

function isExistUsername(id){
	var username=S("m_username").value
	if (username.length == 0){
		set(S("checkmanagername"),"管理员名称不能为空");
		return false; 
	}
	ajax.get(
		"admin_ajax.asp?username="+username+"&action=checkuser&id="+id, 
		function(obj) {
			var value = obj.responseText
			if(value == "no"){
				set(S("checkmanagername"),"发生错误");	
			}else{
				if (value == "1")
					set(S("checkmanagername"),"已经存在此管理员，请更换名称");	
				else if (value == "0")
					set(S("checkmanagername"),"恭喜，该用户名可用");	
			}
		}
	);
}

function selectDataBase(value){
	if (value==0){view("acc");hide("mssql")}
	if (value==1){hide("acc");view("mssql")}
}

function selectAlertWin(value){
	if (value==1){view("alertwinset");}
	if (value==0){hide("alertwinset");}
}

function selectWaterMark(value){
	if (value==0){hide("watermarkfont");hide("watermarkpic");}
	if (value==1){view("watermarkfont");hide("watermarkpic");}
	if (value==2){hide("watermarkfont");view("watermarkpic");}
}

function selecMakeMode(value){
	if (value=='dir1' || value=='dir3' || value=='dir5' || value=='dir7'){
		hide("dir2");view("dir1");
	}
	if (value=='dir2' || value=='dir4' || value=='dir6' || value=='dir8'){
		view("dir2");hide("dir1");
	}
}

function selecNewsMakeMode(value){
	if (value=='dir1' || value=='dir3' || value=='dir5' || value=='dir7'){
		hide("newsdir2");view("newsdir1");
	}
	if (value=='dir2' || value=='dir4' || value=='dir6' || value=='dir8'){
		view("newsdir2");hide("newsdir1");
	}
}

function selecProductMakeMode(value){
	if (value=='dir1' || value=='dir3' || value=='dir5' || value=='dir7'){
		hide("productdir2");view("productdir1");
	}
	if (value=='dir2' || value=='dir4' || value=='dir6' || value=='dir8'){
		view("productdir2");hide("productdir1");
	}
}

function selecNewsRunMode(value){
	if (value=='dynamic'){
		hide("newsstatic");view("newsdynamic");hide("newsforgedStatic");hide("newsdir2");hide("newsdir1");
	}
	if (value=='static'){
		view("newsstatic");hide("newsdynamic");hide("newsforgedStatic");selecNewsMakeMode(S('newsmakemode')[S('newsmakemode').selectedIndex].value);
	}
	if (value=='forgedStatic'){
		hide("newsstatic");view("newsforgedStatic");hide("newsdynamic");hide("newsdir2");hide("newsdir1");
	}
}
function selecProductRunMode(value){
	if (value=='dynamic'){
		hide("productstatic");view("productdynamic");hide("productforgedStatic");hide("productdir2");hide("productdir1");
	}
	if (value=='static'){
		view("productstatic");hide("productdynamic");hide("productforgedStatic");selecProductMakeMode(S('productmakemode')[S('productmakemode').selectedIndex].value);
	}
	if (value=='forgedStatic'){
		hide("productstatic");view("productforgedStatic");hide("productdynamic");hide("productdir2");hide("productdir1");
	}
}

function selectCacheSearch(v){
	S('CacheSearch').style.display=v=='1' ? '' : 'none';
}

function selectMakeplay(){
return;
	var y=S('ismakeplay'),v=y[y.selectedIndex].value,b=S('paramset2'),r=S('runmode'),x=r[r.selectedIndex].value;
	if(v=='3' && x=='static'){
		var a=S('paramset1');
		selectMakeplay.i = a.checked ? 1 : 2;
		a.checked=true;a.onclick();
		b.disabled=true;
	}else if (b.disabled){
		if(selectMakeplay.i==2){
			b.checked=true;b.onclick();
		}
		b.disabled=false;
	}
}

function onTxtChange(input){
	input.value=input.value.replace(/[^\w_]/ig,'');
}

function  starView(level,vid){
	var i,j,htmlStr;
	var htmlStr=""
	if (level==0){level=0}
	if (level>0){htmlStr+="<img src='img/starno.gif' border='0' style='cursor:pointer;margin-left:2px;' title='取消推荐'  onclick='commendVideo("+vid+",0)'/>"}
	for (i=1;i<=level;i++){
		htmlStr+= "<img src='../pic/star0.gif' border='0' style='cursor:pointer;margin-left:2px;' onclick='commendVideo("+vid+","+i+")' title='推荐为"+i+"星级' id='star"+vid+"_"+i+"'  />"
	}
	for(j=level+1;j<=5;j++){
		htmlStr+= "<img src='../pic/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' onclick='commendVideo("+vid+","+j+")' title='推荐为"+j+"星级' id='star"+vid+"_"+j+"' />"
	}
	set(S('star'+vid),htmlStr)
}

function commendVideo(vid,commendid){
	ajax.get(
		"admin_ajax.asp?id="+vid+"&commendid="+commendid+"&action=commend", 
		function(obj){
			if(obj.responseText == "submitok"){
				starView(commendid,vid);
			}else{
				set(S("star"+vid),"<font color='red'>发生错误</font>");		
			}
		}
	);
}

function viewCurrentTopicTr(id){
	var topictrObj=getElementsByName("tr","topictr")
	var n=topictrObj.length
	for (var i=0;i<=n-1;i++){
		topictrObj[i].style.background="#ffffff";	
	}
	S("topictr"+id).style.background="#E7E7E7";
}

function openTopicDesWin(divid,id){
	selfLabelWindefault(divid);	
	view(divid)
	S("f_m_id").value=id
	set(S("f_m_des"),"加载中...");	
	ajax.get(
		"admin_ajax.asp?id="+id+"&action=gettopicdes", 
		function(obj) {
			if(obj.responseText == "err"){
				set(S("f_m_des"),"发生错误");	
			}else{
				set(S("f_m_des"),obj.responseText);
			}
		}
	);
}

function submitTopicDes(divid){
	ajax.postf(
		S("f_des"),
		function(obj){if(obj.responseText=="ok"){hide(divid);alert('修改成功');}else{alert('发生错误');}}
	);
}

function gather(){
	var url=S("gatherurl").value
	if(url.length == 0) 
		return false
	else{
		view("loading")
		ajax.get(
			"admin_webgather.asp?url="+url+"&action=gather", 
			function(obj) {
				if(obj.responseText == "err"){
					S("gathercontent").value = "发生错误";	
				}else{
					S("gathercontent").value = obj.responseText;
				}
				hide("loading")
			}
		);
	}
}

function insertResult(i){
	var id=S("areaid").value
	S("m_playurl"+id).value += (S("m_playurl"+id).value!='' ? "\n" : '')+S("gathercontent").value
	S("gatherurl").value=''
	S("gathercontent").value=''
	S("areaid").value=i;
	hide('gathervideo')
}

function getReferedId(str){
	if(str.indexOf('土豆高清')>-1) return "hd_tudou"
	if(str.indexOf('新浪高清')>-1) return "hd_iask"
	if(str.indexOf('搜狐高清')>-1) return "hd_sohu"
	if(str.indexOf('天线高清')>-1) return "hd_openv"
	if(str.indexOf('56高清')>-1) return "hd_56"
	if(str.indexOf('56')>-1) return "56"
	if(str.indexOf('优酷')>-1) return "youku"
	if(str.indexOf('土豆')>-1) return "tudou"
	if(str.indexOf('搜狐')>-1) return "sohu"
	if(str.indexOf('新浪')>-1) return "iask"
	if(str.indexOf('六间房')>-1) return "6rooms"
	if(str.indexOf('qq')>-1) return "qq"
	if(str.indexOf('youtube')>-1) return "youtube"
	if(str.indexOf('17173')>-1) return "17173"
	if(str.indexOf('ku6视频')>-1) return "ku6"
	if(str.indexOf('FLV')>-1) return "flv"
	if(str.indexOf('SWF')>-1) return "swf"
	if(str.indexOf('real')>-1) return "real"
	if(str.indexOf('media')>-1) return "media"
	if(str.indexOf('qvod')>-1) return "qvod"
	if(str.indexOf('ppstream')>-1) return "pps"
	if(str.indexOf('迅播高清')>-1) return "gvod"
	if(str.indexOf('远古高清')>-1) return "wp2008"
	if(str.indexOf('播客CC')>-1) return "cc"
	if(str.indexOf('ppvod高清')>-1) return "ppvod"
	if(str.indexOf('闪播Pvod')>-1) return "pvod"
	if(str.indexOf('皮皮影音')>-1) return "pipi"
	if(str.indexOf('激动')>-1) return "joy"
	if(str.indexOf('奇艺')>-1) return "qiyi"
	return ""
}

function repairUrl(i){
	var urlStr,urlArray,newStr,j,flagCount,fromText,t
	fromText=S("m_playfrom"+i).options[S("m_playfrom"+i).selectedIndex].value
	if (fromText.length==0){alert('请选择播放器类型');return false;}
	urlStr=S('m_playurl'+i).value
	if (urlStr.length==0){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]+'$'+getReferedId(fromText)
					break;
				case 1:
					urlArray[j]=urlArray[j]+'$'+getReferedId(fromText)
					break;
				case 2:
					if(t[2]==''){
						urlArray[j]=urlArray[j]+getReferedId(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";
		}
	}
	S('m_playurl'+i).value=trimOuterStr(newStr,"\r\n");
}

function repairUrl2(i){
	var urlStr,urlArray,newStr,j,flagCount,fromText
	fromText=S("m_downfrom"+i).options[S("m_downfrom"+i).selectedIndex].value
	if (fromText.length==0){alert('请选择下载类型');return false;}
	urlStr=S('m_downurl'+i).value
	if (urlStr.length==0){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){
			flagCount=urlArray[j].split('S').length-1
			switch(flagCount){
				case 0:
					urlArray[j]='第'+(j<9 ? '0' : '')+(j+1)+'集S'+urlArray[j]+'Sdown'
					break;
				case 1:
					urlArray[j]=urlArray[j]+'Sdown'
					break;
				case 2:
					break;
			}
			newStr+=urlArray[j]+"\r\n";
		}
	}
	S('m_downurl'+i).value=trimOuterStr(newStr,"\r\n");
}

function expendPlayArea(i,optionStr,type){
	if(expendPlayArea.i===false){
		expendPlayArea.i=i
	}else{
		i=++expendPlayArea.i;
	}
	optionStr=unescape(optionStr)
	var n=i-1,m=i+1
	var sparkStr=(type==1)?"&nbsp;&nbsp;<font color='red'>＊</font>":""
	var sparkStr2=(type==1)?"<font color='blue' style='position:absolute;left: 510px;line-height:28px;white-space:nowrap'>地址单集格式： <font color='red'>标题$ID$来源</font>(多集换行隔开)</font>":""
	var area="<table width='100%' id='playfb"+i+"'><tr class='noborder-tb'><td align='right' height='22' width='70'>播放来源"+i+"：</td><td>"+sparkStr2+"<select id='m_playfrom"+i+"' name='m_playfrom'><option value=''>暂无数据"+i+"</option>"+optionStr+"</select>&nbsp;&nbsp;<input type='button' class='btn' value='WEB采集' onclick='viewGatherWin("+i+");selectTogg();'/>&nbsp;&nbsp;<img onclick=\"var tb=S('playfb"+i+"');tb.parentNode.removeChild(tb);\"  src='img/btn_dec.gif' class='pointer' alt='删除播放来源"+i+"' align='absmiddle' />&nbsp;&nbsp;<a href=\"javascript:moveTableUp(S('playfb"+i+"'))\">上移</a>&nbsp;&nbsp;<a href=\"javascript:moveTableDown(S('playfb"+i+"'))\">下移</a>"+sparkStr+"</td></tr><tr><td align='right' height='22'>数据地址"+i+"：<br/><input type='button' value='校正' title='校正右侧文本框中的数据格式' class='btn'  onclick='repairUrl("+i+")'/></td><td><textarea id='m_playurl"+i+"' name='m_playurl' rows='8' cols='100'></textarea>"+sparkStr+"</td></tr></table>"
	var _nextdiv=document.createElement("div");
	_nextdiv.innerHTML=area
	S('m_playarea').appendChild(_nextdiv.getElementsByTagName('table')[0]);
	_nextdiv=null;
}
expendPlayArea.i=false;

function expendDownArea(i,optionStr,type){
	if(expendDownArea.i===false){
		expendDownArea.i=i
	}else{
		i=++expendDownArea.i;
	}
	optionStr=unescape(optionStr)
	var n=i-1,m=i+1
	var sparkStr=(type==1)?"&nbsp;&nbsp;<font color='blue' style='position:absolute;left: 400px;line-height:18px;white-space:nowrap'>地址单集格式：<font color='red'>下载名称$下载地址$down</font>(多集换行隔开)</font>":""
	var area="<table width='100%' id='downfb"+i+"'><tr><td align='right' height='22' width='70'>下载来源"+i+"：</td><td>"+sparkStr+"<select id='m_downfrom"+i+"' name='m_downfrom'><option value=''>暂无数据"+i+"</option>"+optionStr+"</select>&nbsp;&nbsp;<img onclick=\"var tb=S('downfb"+i+"');tb.parentNode.removeChild(tb);\"  src='img/btn_dec.gif' class='pointer' alt='删除下载来源"+i+"' align='absmiddle' />&nbsp;&nbsp;<a href=\"javascript:moveTableUp(S('downfb"+i+"'))\">上移</a>&nbsp;&nbsp;<a href=\"javascript:moveTableDown(S('downfb"+i+"'))\">下移</a></td></tr><tr><td align='right' height='22'>下载地址"+i+"：<br/><input type='button' value='校正' title='校正右侧文本框中的下载格式' class='btn'  onclick='repairUrl2("+i+")'/></td><td><textarea id='m_downurl"+i+"' name='m_downurl' rows='8' cols='100'></textarea></td></tr></table>";
	var _nextdiv=document.createElement("div");
	_nextdiv.innerHTML=area
	S('m_downarea').appendChild(_nextdiv.getElementsByTagName('table')[0]);
	_nextdiv=null;
}
expendDownArea.i=false;

function expendPlayerSkin(i){
	var str="皮肤"+(i+1)+" :背景颜色 #<input type='text' name='playerbgcolor'  alt='clrDlg0"+i+"' /> 文字颜色 #<input type='text' name='playerfontcolor'  alt='clrDlg1"+i+"' /><br><div id='addplayerskin"+i+"'><img  src='img/btn_add.gif' onclick='expendPlayerSkin("+(i+1)+")'  style='cursor:pointer'/></div>";
	var _nextdiv=document.createElement("div")
	set(_nextdiv,str)
	S('playerskindiv').appendChild(_nextdiv)
	if(i>0){hide("addplayerskin"+(i-1))}
}

function expendContentSkin(i){
	var str='<li id="li_'+i+'" style="cursor:pointer">内容'+i+'\
			<img onclick="var tb=S(\'li_'+i+'\');tb.parentNode.removeChild(tb);" src="img/btn_dec.gif" class="pointer" alt="删除内容'+i+'" align="absmiddle"/></li>\
			<li id="hide_li_'+i+'"><img onclick="expendContentSkin('+(i+1)+')" src="img/btn_add.gif" class="pointer" align="absmiddle"/>&nbsp;&nbsp;<font color="red" style="font-weight:100;">单击前面的按钮添加一组内容</font></li>'
	//var str2='<input type="hidden" id="m_content'+i+'" name="m_content'+i+'" value="" style="display:none" /><input type="hidden" id="m_content'+i+'___Config" value="" style="display:none" /><iframe id="m_content'+i+'___Frame" src="fckeditor/editor/fckeditor.html?InstanceName=m_content'+i+'&amp;Toolbar=rendie" width="640" height="250" frameborder="0" scrolling="no"></iframe>';
	var _nextdiv=document.createElement("ul")
	set(_nextdiv,str)
	S('makeHtmlTab').appendChild(_nextdiv)
	if(i>0){hide("hide_li_"+(i-1))}
}

function addcontentdiv(i)
{
	$("#addcontentdiv").hide();
	$("#addcontentdiv").before('<div id="des_content'+i+'" style="padding:5px;">内&nbsp;&nbsp;容&nbsp;&nbsp;'+i+'&nbsp;&nbsp;<img onclick="var tb=S(\'des_content'+i+'\');tb.parentNode.removeChild(tb);" src="img/btn_dec.gif" class="pointer" alt="删除内容'+i+'" align="absmiddle"/><br/><input type="hidden" name="m_content" value="m_content'+i+'" style="display:none"/><input type="hidden" id="m_content'+i+'" name="m_content'+i+'" value="" style="display:none" /><input type="hidden" id="m_content'+i+'___Config" value="" style="display:none" /><iframe id="m_content'+i+'___Frame" src="fckeditor/editor/fckeditor.html?InstanceName=m_content'+i+'&amp;Toolbar=rendie" width="640" height="250" frameborder="0" scrolling="no"></iframe></div><div id="addcontentdiv" style="padding:5px;"><img id="addcontent" src="img/btn_add.gif" class="pointer" align="absmiddle" onclick="addcontentdiv('+(i+1)+')"/><font color="red" style="font-weight:100;">单击前面的按钮添加一组内容</font></div>');
}

function width_height_add(i){
	var str='<span id="width_height_'+i+'"><input type="text" size="2" name="width"/>x<input type="text" size="2" name="height"/><img onclick="var tb=S(\'width_height_'+i+'\');tb.parentNode.removeChild(tb);" src="img/btn_dec.gif" class="pointer" alt="删除宽高'+i+'" align="absmiddle"/> &nbsp;&nbsp;</span>\
	<span id="width_height_add_'+i+'"><img src="img/btn_add.gif" onclick="width_height_add('+(i+1)+')" align="absmiddle" style="cursor:pointer"/></span>';
	var _nextdiv=document.createElement("span")
	set(_nextdiv,str)
	S('pictd').appendChild(_nextdiv)
	if(i>0){hide("width_height_add_"+(i-1))}
}

function viewGatherWin(i){
	S('gathervideo').style.display='block';S("areaid").value=i;selfLabelWindefault('gathervideo');
}

function alertUpdatePic(){
	ajax.get(
		"admin_ajax.asp?action=updatepic", 
		function(obj) {
			if(obj.responseText > 0){
				view('updatepic');set(S("updatepicnum"),obj.responseText)
			}
		}
	);
	floatBtttom("updatepic",500);
	}

function floatBtttom(id,retime) {
	S(id).style.top = (document.documentElement.scrollTop-0+document.documentElement.clientHeight-S(id).clientHeight)+"px";
	timer = setTimeout("floatBtttom('"+id+"',"+retime+");",retime);
}

function isViewState(){
	if (S("m_statebox").checked){S("m_statespan").style.display="inline";}	else{hide("m_statespan");S("m_state").value='';}
}

function clearCache(){
	set(S("upcacheresult"),'加载中...')
	ajax.get(
		"admin_ajax.asp?action=restartcache", 
		function(obj) {
			if(obj.responseText == 'ok'){
				set(S("upcacheresult"),'缓存更新成功')
			}else{
				set(S("upcacheresult"),'缓存更新失败')
			}
		}
	);	
}

function htmlToJs(htmlinput,jsinput){
	S(jsinput).value="document.writeln(\""+S(htmlinput).value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
} 

function jstohtml(jsinput,htmlinput){
	S(htmlinput).value=S(jsinput).value.replace(/document.writeln\("/g,"").replace(/document.write\("/g,"").replace(/"\);/g,"").replace(/\\\"/g,"\"").replace(/\\\'/g,"\'").replace(/\\\//g,"\/").replace(/\\\\/g,"\\").replace(/document.writeln\('/g,"").replace(/"\)/g,"").replace(/'\);/g,"").replace(/'\)/g,"")
}

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 reverseOrder(){
	if(S('gathercontent').value==""){alert("没有地址内容");return;}
	if(navigator.userAgent.indexOf("Firefox")>0){var listArray=S('gathercontent').value.split("\n");}else{var listArray=S('gathercontent').value.split("\r\n");}
	var newStr="";
	for(var i=listArray.length-1;i>=0;i--){
			newStr+=listArray[i]+"\r\n";
	}
	S('gathercontent').value=trimOuterStr(newStr,"\r\n");
}

function replaceStr(){
	var contentObj=S('gathercontent'),str="gi";
	if(contentObj.value==""){alert("没有地址内容");return;}
	var replace1=S("replace1").value,replace2=S("replace2").value;
	var content=contentObj.value;
	var reg=new RegExp(replace1,str);
	contentObj.value=content.replace(reg,replace2);	
}

function changeRowColor(tableId,trClass,n)
{
	var rows_changeColor = document.getElementById(tableId).getElementsByTagName('TR');
	for(var i=n;i<rows_changeColor.length;i++){
	rows_changeColor[i].onmouseover = function(){this.className=trClass;}
	rows_changeColor[i].onmouseout = function(){this.className="";}
	}

}

function viewComMakeOps(){view('tr_make_all');view('tr_make_type');view('tr_make_content');hide('tr_make_zt');hide('tr_make_self');S("makeHtmlTab").getElementsByTagName("li")[0].className="hover";S("makeHtmlTab").getElementsByTagName("li")[1].className="";}

function viewSpeMakeOps(){hide('tr_make_all');hide('tr_make_type');hide('tr_make_content');view('tr_make_zt');view('tr_make_self');S("makeHtmlTab").getElementsByTagName("li")[1].className="hover";S("makeHtmlTab").getElementsByTagName("li")[0].className="";}

function moveTableUp(o){
	if(!!o.previousSibling){
		o.parentNode.insertBefore(o,o.previousSibling);
	}
}
function moveTableDown(o){
	if(!!o.nextSibling){
		o.parentNode.insertBefore(o.nextSibling,o);
	}
}

function view(id){
	S(id).style.display='';
}
function hide(id){
	S(id).style.display='none';
}

var ColorHex=new Array('00','33','66','99','CC','FF')
var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF')
var current=null
var targetElement = null;
function intocolor(){
	var colorTable=''
	for (i=0;i<2;i++){
	for (j=0;j<6;j++){
		colorTable=colorTable+'<tr height=12>'
		colorTable=colorTable+'<td width=11 style="background-color:#000000">'
		if (i==0){
			colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">'
		}else{
			colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">'
		}
		colorTable=colorTable+'<td width=11 style="background-color:#000000">'
		for (k=0;k<3;k++)
		{
			for (l=0;l<6;l++){colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">'}
		}
	}
}
colorTable='<table width=253 border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">'
		   +'<tr height=30><td colspan=21 bgcolor=#cccccc>'
		   +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
		   +'<tr><td width="3"><td><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#ffff00"></td>'
		   +'<td width="3"><td><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000"></td></tr></table></td></table>'
		   +'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" onmouseover="doOver()" onmouseout="doOut()" onclick="doclick()" style="cursor:hand;">'
		   +colorTable+'</table>';
colorpanel.innerHTML=colorTable
}

function doOver() {
	  if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) {
		if (current!=null){current.style.backgroundColor = current._background}
		event.srcElement._background = event.srcElement.style.backgroundColor
		DisColor.style.backgroundColor = event.srcElement.style.backgroundColor
		HexColor.value = event.srcElement.style.backgroundColor.toUpperCase();
		event.srcElement.style.backgroundColor = "white"
		current = event.srcElement
	  }
}

function doOut() {
	if (current!=null) current.style.backgroundColor = current._background.toUpperCase();
}

function doclick()
{
	if (event.srcElement.tagName == "TD")
	{
		var clr = event.srcElement._background;
		clr = clr.toUpperCase();
		if (targetElement)
		{
			targetElement.style.borderLeft	="20px "+clr+" solid"
     		targetElement.style.borderTop	="1px "+clr+" solid"
     		targetElement.style.borderRight ="1px "+clr+" solid"
      		targetElement.style.borderBottom="1px "+clr+" solid"
			targetElement.value = clr.replace(/#/g,'');
		}
		DisplayClrDlg(false);
		return clr;
	}
}

function OnDocumentClick()
{
	var srcElement = event.srcElement;
	if (typeof(srcElement.title) != "undefined"&&srcElement.title.indexOf('clrDlg')==0){
		targetElement = event.srcElement;
		DisplayClrDlg(true);
	}
	else
	{
		while (srcElement && srcElement.id!="colorpanel")
		{
			srcElement = srcElement.parentElement;
		}
		if (!srcElement)
		{
			DisplayClrDlg(false);
		}
	}
}

function DisplayClrDlg(display)
{
	var clrPanel = document.getElementById("colorpanel");
	if (display)
	{
		var left = document.body.scrollLeft + event.clientX;
		var top = document.body.scrollTop + event.clientY;
		if (event.clientX+clrPanel.style.pixelWidth > document.body.clientWidth)
		{
			left -= clrPanel.style.pixelWidth;
		}
		if (event.clientY+clrPanel.style.pixelHeight > document.body.clientHeight)
		{
			top -= clrPanel.style.pixelHeight;
		}

		clrPanel.style.pixelLeft = left;
		clrPanel.style.pixelTop = top;
		clrPanel.style.display = "block";
	}
	else
	{
		clrPanel.style.display = "none";
	}
}
