<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title><!--{$UUDEV_PAGE_TITLE}--></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--{include file=elements/header.css.html}-->
<!--{include file=elements/header.js.html type=common}-->
<!--{include file=elements/header.js.html type=ubb}-->
<script src="js/jquery/jquery.contextmenu.js"></script>

<script src="js/jquery/jquery.blockUI.js" charset="utf-8"></script>

<link href="css/layoutcpanel.css" rel="stylesheet"/>
<style type="text/css">
#cpaneldiv{
	position:absolute;
	left:6px;
	width:353px;
	border:1px #24598b solid;
	background:#FFFFFF;
}
#rightdiv{
	position:absolute;
	left:368px;
	border:1px #24598b solid;
	background:#FFFFFF;
}
#cpanel-scroll-mid {height:30px;line-height:30px;text-align:center;}
</style>
</head>
<body>
<div id="outside">
	<!--{include file=frame/top.html}-->
	<div id="mainareaContent">
		<!--{include file=frame/left.html}-->
		<div id="rightContent">
			<div id="topContent">
				<div class="sitmap">
					<span class="r"><!--{include file="elements/uuadvad.html"}--></span>模块管理&nbsp;&gt;&nbsp;<!--{if $id == 1 || $id == 2}-->文章模块<!--{elseif $id == 3 || $id == 4}-->软件模块<!--{elseif $id == 5 || $id == 6}-->游戏模块<!--{elseif $id == 9 || $id == 10}-->主题模块<!--{elseif $id == 11 || $id == 12}-->图片模块<!--{elseif $id == 13 || $id == 14}-->音乐模块<!--{elseif $id == 15 || $id == 16}-->友链模块<!--{/if}-->&nbsp;&gt;&nbsp;<!--{if $id%2 !==0 }-->列表页布局<!--{else}-->内容页布局<!--{/if}-->
				</div>
			</div>
			<div class="tabcontent">
					
					<a href="index.php?r=FriendSite.friendsitelist" class="link">内管管理</a>
					<a href="index.php?r=SiteSet.friendsiteset" class="link">属性设置</a>
					<a href="index.php?r=FriendSite.friendsiteListLayout" class="link">列表页布局</a>
					<a href="index.php?r=FriendSite.friendsitePageLayout" class="nolink">内容页布局</a>
					<a href="index.php?r=FriendSite.realtimereport" class="link">实时数据分析</a>
				
			</div>
			<div id="secrightContent-cpanel" style="width:100%;height:100%; background:#689dcf; border:1px #24598b solid; padding:5px; margin-top:8PX;">
				<div id="cpaneldiv">
					<div class="UBBbuju_title">
						<!--{if $id % 2 == 1}-->列表页<!--{else}-->内容页<!--{/if}-->
					</div>
					<div style="text-align:right;height:24px;line-height:24px;padding:5px 0;">
						<a class="ubb_button_ui" id="<!--{$template.id}-->" href="javascript:void(0)" type="foot_ubb_content">修改底部</a><a class="ubb_button_ui_on" id="<!--{$template.id}-->" href="javascript:void(0)" type="head_ubb_content">修改顶部</a>
					</div>
					<div id="cpanel-scroll-top" style="border:1px #bfd5e8 solid; background:#FFFFFF;overflow-y:auto; overflow-x:hidden;width:100%;">
						<div id="cpanelBox_head_ubb_content" style="boder:0;width:100%;height:100%;"><!--{$template.head_ubb_content}--></div>
					</div>
					<div id="cpanel-scroll-mid"><!--{$data}--></div>
					<div id="cpanel-scroll-bot" style="border:1px #bfd5e8 solid; background:#FFFFFF;overflow-y:auto; overflow-x:hidden;width:100%;">
						<div id="cpanelBox_foot_ubb_content" style="boder:0;width:100%;height:100%;"><!--{$template.foot_ubb_content}--></div>
					</div>
				</div>
				<div id="rightdiv">
					<div id="help-scroll" style="boder:0; overflow-y:auto; overflow-x:hidden;">
						<div id="helperBox" style="boder:0;width:100%;height:100%;">
							<div class="UBBbuju_title">编辑区</div>
							<div class="layoutEditor" style=" background:#FFFFFF; padding:0px 3px;">
								<div class="editorBody">
									<form id="moduleTemplateForm" action="index.php?r=FriendSite.edit_template" method="post">
										<input type="hidden" id="template_id" name=data[ChannelModuleTemplate][id] value="<!--{$template.id}-->"/>
										<input type="hidden" id="module_type" value="head_ubb_content"/>
										<div class="ubbEditor" style="padding-top:3px; width:99%">
											<textarea id="content" name="data[ChannelModuleTemplate][head_ubb_content]"><!--{$templateubb.head_ubb_content}--></textarea>
										</div>
										<div class="ubbAttr" style="padding:5px 0;">
											<button type="submit" class="butT">保存</button>
										</div>
									</form>
								</div>
								<div style="overflow-y:scroll;border:1px #bfd5e8 solid;height:;" id="UBB_edit_navBox">
									<div class="showtool" style=" padding:2px; background:url(images/bgx.gif) 0px -199px; height:20px; line-height:20px; border-right:none; cursor:pointer">
										<span><b id="ubbmenu-status">基本功能</b><img src="images/jt.gif" alt=""></span>&nbsp;&nbsp;<span style="color:#FF0000; margin-left:8px;">[点击显示更多功能 <img src="images/new.gif" alt="">]</span>
									</div>
									<div class="ubbTool" style="background:#ffffff; border-top:1px #aedcfe solid;">
										<ul>
											<li><a class="ubbmenu" value="basic-function" href="javascript:void();">基本功能</a></li>
											<li><a class="ubbmenu" value="resources-call" href="javascript:void();">资源调用</a></li>
											<li><a class="ubbmenu" value="new-resources" href="javascript:void();">资源新增</a></li>
											<li><a class="ubbmenu" value="advertising-system" href="javascript:void();">广告系统</a></li>
											<li><a class="ubbmenu" value="links" href="javascript:void();">友情链接</a></li>
											<li><a class="ubbmenu" value="custom-search" href="javascript:void();">自定义搜索</a></li>
											<li><a class="ubbmenu" value="music-module" href="javascript:void();">音乐模块</a></li>
											<li><a class="ubbmenu" value="access-statistics" href="javascript:void();">访问统计</a></li>
											<!--li><a class="ubbmenu" value="personal-center-page" href="javascript:void();">个人中心页面</a></li>
											<li><a class="ubbmenu" value="member-display-page" href="javascript:void();">会员展示页面</a></li-->
											<li><a class="ubbmenu" value="ubbtags" href="javascript:void();">自定义标签</a></li>
										</ul>
									</div>
									<div class="ubbBody" style="background:#f6f9fc; border-top:1px #bfd5e8 solid;">
										<div id="ubbArea" style="line-height:24px; color:#0c6500; padding-left:5px;">
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>	
</body>
<script>
_$.resize = function(){
	var tcHeight = $("#topOutside").height();
	var leftWidth = $("#leftContent").width();
	var sWidth = document.documentElement.clientWidth;
	var sHeight = document.documentElement.clientHeight;
	var tabcontentheight = $(".tabcontent").height() + 5;
	var sitmapHeight = $(".sitmap").height();
	var cpaneldiv = $("#cpaneldiv").width();
	
	$("#mainareaContent").css({
		height: sHeight - tcHeight - 4
	});
	$("#leftContent").css({
		height: sHeight - tcHeight - 4
	});
	$("#rightContent").css({
		height: sHeight - tcHeight - 4
	});
	$("#rightContent").css({
		width: sWidth - leftWidth - 10
	});
	$("#secrightContent").css({
		height: sHeight - sitmapHeight - tabcontentheight - tcHeight
	});
	
	$("#cpanel-scroll-top").css({
		height: (sHeight - 85 - 21 - 90 - 32 - 34)/2
	});
	$("#cpanel-scroll-bot").css({
		height: (sHeight - 85 - 21 - 90 - 32 - 34)/2
	});
	
	$("#help-scroll").css({
		height: sHeight - 85 - 21 - 62
	});
	
	$("#secrightContent-cpanel").css({
		height: sHeight - 25 - tabcontentheight - tcHeight - 26
	});
	$("#rightdiv").css({
		width: sWidth - 151 - 6 - cpaneldiv - 30
	});
	
	var soc = 0;
	if(document.all)
	{
		if($("#cpanel-scroll").height()<$("#cpanelLayout").height())
		{
			soc+=18;
		}
		
		if($("#help-scroll").height()<$("#helperLayout").height())
		{
			soc+=18;
		}
	}
}

$(document).ready(function(){

	var editorBody = $(".editorBody").height();
	var sHeight = document.documentElement.clientHeight;
	var tcHeight = $("#topOutside").height();
	var toph = $(".sitmap").height();
	$("#UBB_edit_navBox").css({
		height: sHeight - editorBody -tcHeight -toph - 158
	});

	$(".ubb_button_ui").click(function(){
		$(".ubb_button_ui_on").attr("class", "ubb_button_ui");
		$(this).attr("class", "ubb_button_ui_on");
		var id = $(this).attr("id");
		var type = $(this).attr("type");
		$.ajax({
			url: "index.php?r=FriendSite.edit_template&id="+id+"&type="+type,
			type: "get",
			cache: false,
			dataType: "json",
			success: function(data){
				$("#template_id").val(data.id);
				$("#module_type").val(data.type);
				$("#content").val(data.data);
				$("#content").attr("name", "data[ChannelModuleTemplate]["+data.type+"]");
			}
		});
	});
	$(".ubb_button_ui_on").click(function(){
		$(".ubb_button_ui_on").attr("class", "ubb_button_ui");
		$(this).attr("class", "ubb_button_ui_on");
		var id = $(this).attr("id");
		var type = $(this).attr("type");
		$.ajax({
			url: "index.php?r=FriendSite.edit_template&id="+id+"&type="+type,
			type: "get",
			cache: false,
			dataType: "json",
			success: function(data){
				$("#template_id").val(data.id);
				$("#module_type").val(data.type);
				$("#content").val(data.data);
				$("#content").attr("name", "data[ChannelModuleTemplate]["+data.type+"]");
			}
		});
	});

	$("#moduleTemplateForm").submit(function(){
		$(this).ajaxSubmit({
			success: function(str){
				var data = eval('(' + str + ')');
				if (data.status == 1) {
					
					$.successUI({
						message:"保存成功！",
						showOverlay:true,
						confirm:function(){setTimeout($.unblockUI, 300);$("#cpanelBox_"+$("#module_type").val()).html(data.content);}
					});
							
				} else if (data.status == 0) {
					$.errorUI({
						message:"保存失败！",
						showOverlay:true
					});
				}
			}
		});
		return false;
	});

	var $Editor = $("#content").addClass("cleditorTextarea").cleditor({
		width: "100%",
		height: 120,
		controls: "bold italic underline break | undo redo | image link file |",
		customBind: function(editor){
			$.ajax({
				url:"index.php?r=Layout.getUbbTemplate",
				type:"get",
				data:{template:'basic-function'},
				cache:false,
				success:function(html){
					$("#ubbArea").empty();
					$(html).appendTo("#ubbArea");
					$(".ubbcode").bind('click',function(){
						$.cleditor.cRange(editor);
						$.cleditor.exec(editor,$(this).text());
					});
				}
			});
			
			$(".ubbmenu").click(function(){
				var btn_name = $(this).text();
				if($(this).attr("value")!=''){
					$.ajax({
						url:"index.php?r=Layout.getUbbTemplate",
						type:"get",
						data:{template:$(this).attr("value")},
						cache:false,
						success:function(html){
							$(".ubbTool").slideUp(1000);
							$("#ubbArea").empty();
							$("#ubbmenu-status").html(btn_name);
							$(html).appendTo("#ubbArea");
							$(".ubbcode").bind('click',function(){
								$.cleditor.cRange(editor);
								$.cleditor.exec(editor,$(this).text());
							});
							
							//绑定资源调用向导
							$(".useubbwizard").bind('click',function(){
								var channel_id=0,channel_text=$(this).attr("value");
								if(channel_text == '' || channel_text== undefined) return false;
								
								var isAll = false;
								var channels = new Array();
								
								switch(channel_text){
									case "article": channel_id = 1;break;
									case "software": channel_id = 2;break;
									case "theme": channel_id = 8;break;
									case "game": channel_id = 3;break;
									case "picture": channel_id = 9;break;
									case "forum": channel_id = 5;break;
									case "link": channel_id = 7;break;
									case "music": channel_id = 10;break;
								}
								
								$.ajax({
									url:"index.php?r=Layout.getChannelByModule",
									type:"get",
									data:{channel_module_id:channel_id},
									cache:false,
									success:function(ChannelResponseText){
										var fc = $.fn.firesbox.start(ChannelResponseText, {hideOnContentClick: false});
										//绑定checkall事件
										fc.find("#checkall").unbind("click").bind("click", function(){
											if($(this).attr("checked")){
												$(".channelbox").each(function(){
													$(this).attr("checked",true);
												});
												isAll = true;
											}else{
												$(".channelbox").each(function(){
													$(this).attr("checked",false);
												});
												isAll = false;
											}
										});
										//绑定单个选框事件
										fc.find(".channelbox").unbind("click").bind("click", function(){
											var channel_id = $(this).val();
											if($(this).attr("checked")){
												if($.inArray(channel_id,channels) == -1){
													channels.push(channel_id);
												}
											}else{
												if($.inArray(channel_id,channels) != -1){
													channels = $.grep(channels,function(n,i){return n!=channel_id;});
												}
												
												if(isAll){
													isAll = false;
													$("#checkall").attr("checked",false);
													$(".channelbox").each(function(){
														if($(this).attr("checked")){
															if($.inArray($(this).val(),channels) == -1){
																channels.push($(this).val());
															}
														}
													});
												}
											}
										});
										
										fc.find(".nextBtn").unbind("click").bind("click", function(){
											if(!isAll && channels.length<1){
												alert("请选择频道！");
												return false;
											}
											var channel = "";
											if(isAll){
												channel = "0";
											}else{
												$(channels).each(function(k,v){
													if(channel == ""){
														channel = v;
													}else{
														channel+="|"+v;
													}
												});
											}
											switch(channel_text){
												case "article": bindArticle(editor,channel);break;
												case "software": bindSoftware(editor,channel);break;
												case "theme": bindTheme(editor,channel);break;
												case "game": bindGame(editor,channel);break;
												case "picture": bindPicture(editor,channel);break;
												case "forum": bindForum(editor,channel);break;
												case "link": bindLink(editor,channel);break;
												case "music": bindMusic(editor,channel);break;
											}
										});
									}
								});
							});
							
							//绑定资源新增向导
							$(".useubbwizard-new").bind('click',function(){
								var channel_id=0,channel_text=$(this).attr("value");
								if(channel_text == '' || channel_text== undefined) return false;
								
								var isAll = false;
								var channels = new Array();
								
								switch(channel_text){
									case "article": channel_id = 1;break;
									case "software": channel_id = 2;break;
									case "theme": channel_id = 8;break;
									case "game": channel_id = 3;break;
									case "picture": channel_id = 9;break;
									case "bbs": channel_id = 5;break;
									case "link": channel_id = 7;break;
								}
								
								$.ajax({
									url:"index.php?r=Layout.getChannelByModule",
									type:"get",
									data:{channel_module_id:channel_id},
									cache:false,
									success:function(ChannelResponseText){
										var fc = $.fn.firesbox.start(ChannelResponseText, {hideOnContentClick: false});
										//绑定checkall事件
										fc.find("#checkall").unbind("click").bind("click", function(){
											if($(this).attr("checked")){
												$(".channelbox").each(function(){
													$(this).attr("checked",true);
												});
												isAll = true;
											}else{
												$(".channelbox").each(function(){
													$(this).attr("checked",false);
												});
												isAll = false;
											}
										});
										//绑定单个选框事件
										fc.find(".channelbox").unbind("click").bind("click", function(){
											var channel_id = $(this).val();
											if($(this).attr("checked")){
												if($.inArray(channel_id,channels) == -1){
													channels.push(channel_id);
												}
											}else{
												if($.inArray(channel_id,channels) != -1){
													channels = $.grep(channels,function(n,i){return n!=channel_id;});
												}
												if(isAll){
													isAll = false;
													$("#checkall").attr("checked",false);
													$(".channelbox").each(function(){
														if($(this).attr("checked")){
															if($.inArray($(this).val(),channels) == -1){
																channels.push($(this).val());
															}
														}
													});
												}
											}
										});
										
										fc.find(".nextBtn").unbind("click").bind("click", function(){
											if(!isAll && channels.length<1){
												alert("请选择频道！");
												return false;
											}
											var channel = "";
											if(isAll){
												channel = "0";
											}else{
												$(channels).each(function(k,v){
													if(channel == ""){
														channel = v;
													}else{
														channel+="|"+v;
													}
												});
											}
											bindResourcesNew(editor,channel,channel_text);
										});
									}
								});
							});
							
							//绑定广告
							$(".useubbADwizard").bind('click',function(){
								bindADWizard(editor);
							});
							
							$(".useubbsearchwizard").bind('click',function(){
								$.ajax({
									url:"index.php?r=Layout.getSearchInputWizard",
									type:"get",
									data:{},
									cache:false,
									success:function(HtmlResponseText){
										var fc = $.fn.firesbox.start(HtmlResponseText, {hideOnContentClick: false});
										
										 fc.find(".cancelBtn").unbind("click").bind('click',function(){
											$.fn.firesbox.close();
										});
										fc.find(".insertBtn").unbind("click").bind('click',function(){
											var input_name = $("#firesbox_content").find("#input-name").val();
											var input_size = $("#firesbox_content").find("#input-size").val();
											var input_value = $("#firesbox_content").find("#input-value").val();
											if(input_name == ""){
												alert("搜索框名不能为空！");
												return false;
											}
											$.cleditor.cRange(editor);
											$.cleditor.exec(editor,"[input name="+input_name+" size="+input_size+" value="+input_value+"]");
											
											$.fn.firesbox.close();
										});
									}
								});
							});
							
							$(".useubbsearchbuttonwizard").bind('click',function(){
								var channel_id=0,channel_text=$(this).attr("value");
								if(channel_text == '' || channel_text== undefined) return false;
								var $channel_id = 0;
								switch(channel_text){
									case "article": channel_id = 1;break;
									case "software": channel_id = 2;break;
									case "theme": channel_id = 8;break;
									case "game": channel_id = 3;break;
									case "picture": channel_id = 9;break;
									case "forum": channel_id = 5;break;
								}
								$.ajax({
									url:"index.php?r=Layout.getSearchChannelByModule",
									type:"get",
									data:{channel_module_id:channel_id},
									cache:false,
									success:function(ChannelResponseText){
										var fc = $.fn.firesbox.start(ChannelResponseText, {hideOnContentClick: false});
										//绑定checkall事件
										fc.find(".channelbox").unbind("click").bind("click", function(){
											if ($(this).attr("checked")) {
												$channel_id = $(this).val();
											}
										});
										fc.find(".nextBtn").unbind("click").bind("click", function(){
											switch(channel_text){
												case "article": bindSearchArticle(editor,$channel_id);break;
												case "software": bindSearchSoftware(editor,$channel_id);break;
												case "theme": bindSearchTheme(editor,$channel_id);break;
												case "game": bindSearchGame(editor,$channel_id);break;
												case "picture": bindSearchPicture(editor,$channel_id);break;
												case "forum": bindSearchForum(editor,$channel_id);break;
											}
										});
									}
								});
							});
						}
					});
				}
			});
		  }
      });
		
	$(".showtool").click(function(){
		if($(".ubbTool").is(":visible") !== false){
			$(".ubbTool").slideUp(300);
		}else{
			$(".ubbTool").slideDown(300);
		}
	});
		
	function bindArticle(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getArticleWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[article="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSoftware(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getSoftwareWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find("#ordering").unbind("change").bind('change',function(){
					if($(this).val() == 5){
						$("#firesbox_content").find("#show-ordering-day").fadeIn("slow");
					}else{
						$("#firesbox_content").find("#show-ordering-day").fadeOut("slow");
					}
				});
				
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					var ordering_day = $("#firesbox_content").find("#ordering-day").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					if(ordering == "5" && ordering_day==""){
						alert("请填写天数！");
						return false;
					}else if(ordering == "5" && ordering_day >0){
						ordering+= "|"+ordering_day;
					}
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[software="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindTheme(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getThemeWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find("#ordering").unbind("change").bind('change',function(){
					if($(this).val() == 5){
						$("#firesbox_content").find("#show-ordering-day").fadeIn("slow");
					}else{
						$("#firesbox_content").find("#show-ordering-day").fadeOut("slow");
					}
				});
				
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					var ordering_day = $("#firesbox_content").find("#ordering-day").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					if(ordering == "5" && ordering_day==""){
						alert("请填写天数！");
						return false;
					}else if(ordering == "5" && ordering_day >0){
						ordering+= "|"+ordering_day;
					}
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[theme="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindGame(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getGameWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find("#ordering").unbind("change").bind('change',function(){
					if($(this).val() == 5){
						$("#firesbox_content").find("#show-ordering-day").fadeIn("slow");
					}else{
						$("#firesbox_content").find("#show-ordering-day").fadeOut("slow");
					}
				});
				
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					var ordering_day = $("#firesbox_content").find("#ordering-day").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					if(ordering == "5" && ordering_day==""){
						alert("请填写天数！");
						return false;
					}else if(ordering == "5" && ordering_day >0){
						ordering+= "|"+ordering_day;
					}
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[game="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindPicture(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getPictureWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find("#ordering").unbind("change").bind('change',function(){
					if($(this).val() == 5){
						$("#firesbox_content").find("#show-ordering-day").fadeIn("slow");
					}else{
						$("#firesbox_content").find("#show-ordering-day").fadeOut("slow");
					}
				});
				
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					var ordering_day = $("#firesbox_content").find("#ordering-day").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					if(ordering == "5" && ordering_day==""){
						alert("请填写天数！");
						return false;
					}else if(ordering == "5" && ordering_day >0){
						ordering+= "|"+ordering_day;
					}
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[picture="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}

	function bindForum(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getForumWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[bbs="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindLink(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getLinkWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var title_length = $("#firesbox_content").find("#title-length").val();
					var show_br = $("#firesbox_content").find("#show-br").val();
					var br_count = $("#firesbox_content").find("#br-count").val();
					var spacer = $("#firesbox_content").find("#spacer").val();
					if(record_count == "") record_count = 20;
					if(title_length == "") title_length = 0;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[link="+channel+"_"+record_count+"_"+ordering+"_"+title_length+"_"+show_br+"_"+br_count+"_"+spacer+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindResourcesNew(editor,channel,module){
		$.ajax({
			url:"index.php?r=Layout.getResourcesNewWizard",
			type:"get",
			data:{module:module},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					if(record_count == "") record_count = 20;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"["+module+"="+channel+"_"+record_count+"_"+ordering+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindADWizard(editor){
		$.ajax({
			url:"index.php?r=Layout.getADWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				var fc = $.fn.firesbox.start(HttpResponseText, {hideOnContentClick: false});
				fc.find(".cancelBtn").unbind("click").bind('click',function(){
					//清空cookie
					$.cookie("ADCOOKIES",null);
					$.fn.firesbox.close();
				});
				fc.find(".insertBtn").unbind("click").bind('click',function(){
					var ad_cookies = $.cookie("ADCOOKIES");
					if(ad_cookies == "" ||　ad_cookies == undefined){
						alert("请先选择要投放的广告！");
						return false;
					}
					var record_count = $("#firesbox_content").find("#record-count").val();
					if(record_count == "") record_count = 20;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ad]"+ad_cookies+"_"+record_count+"[/ad]");
					//清空cookie
					$.cookie("ADCOOKIES",null);
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindMusic(editor,channel){
		$.ajax({
			url:"index.php?r=Layout.getMusicWizard",
			type:"get",
			data:{},
			cache:false,
			success:function(HttpResponseText){
				$("#firesbox_content").empty();
				$(HttpResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var show_type = $("#firesbox_content").find("#show-type").val();
					var record_count = $("#firesbox_content").find("#record-count").val();
					var ordering = $("#firesbox_content").find("#ordering").val();
					var show_channel = $("#firesbox_content").find("#show-channel").val();
					if(record_count == "") record_count = 20;
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"["+show_type+"="+channel+"_"+record_count+"_"+ordering+"_"+show_channel+"]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchArticle(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchArticleWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=article_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchSoftware(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchSoftwareWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=software_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchTheme(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchThemeWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=theme_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchGame(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchGameWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=game_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchPicture(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchPictureWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=picture_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
		
	function bindSearchForum(editor,$channel_id){
		$.ajax({
			url:"index.php?r=Layout.getSearchForumWizard",
			type:"get",
			data:{channel_module_id:1},
			cache:false,
			success: function(HtmlResponseText){
				$("#firesbox_content").empty();
				$(HtmlResponseText).appendTo("#firesbox_content");
				$("#firesbox_content").find(".cancelBtn").unbind("click").bind('click',function(){
					$.fn.firesbox.close();
				});
				$("#firesbox_content").find(".insertBtn").unbind("click").bind('click',function(){
					var input_name = $("#firesbox_content").find("#input-name").val();
					var btn_name = $("#firesbox_content").find("#btn-name").val();
					$.cleditor.cRange(editor);
					$.cleditor.exec(editor,"[ancho=bbs_"+$channel_id+" name="+input_name+"]"+btn_name+"[/ancho]");
					
					$.fn.firesbox.close();
				});
			}
		});
	}
	
});
</script>
</html>
