<form action="" id="form_module_product" name="form_module_product" method="post" class="zhezhao_style"  style="background-color:#FBFDFC" onsubmit="return product_submit_module();"><!-- 商品选择部分 -->
    <table width="600" border="0" cellpadding="0" cellspacing="0"class="from_table2" style="width:530px" >
		<tr>
		  <th width="25%" height="30" align="center" valign="middle" class="td1"><tpl> $langChannelModuleId </tpl>:</th>
			<td height="30" align="left" class="td1">product_module_
			  <input type="text" name="product_temp_name" id="product_temp_name"  class="txtinput" value="<tpl> $modi_array.temp_name </tpl>" />
			  
			  <p style="color:#FF0000"> <tpl> $langChannelNoteModuleIdIs100EnglistOrNum </tpl></p>		  </td>
		</tr>
		<tr>
		  <th width="25%" height="30" align="center" valign="middle" class="td1"><tpl> $langChannelMerchandiseNameWordNum </tpl>:</th>
			<td height="30" align="left" class="td1"><input type="text" name="name_num"  class="txtinput" id="name_num" value="<tpl> $modi_array.name_num </tpl>" />
			
			<p style="color:#FF0000"><tpl> $langChannelHomeDisSiz </tpl></p>		  </td>
		</tr>
		<tr>
		  <th width="25%" height="30" align="center" valign="middle" class="td1"><tpl> $langChannelMerchandiseDisType </tpl>:</th>
			<td height="30" align="left" class="td1">
				<input type="radio" name="show_type" value="0" 
				<tpl> if $modi_array.show_type eq '0' || $modi_array.show_type eq '' </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langChannelWord </tpl>
				<input type="radio" name="show_type" value="1" <tpl> if $modi_array.show_type eq '1' </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langChannelImage </tpl>
				<input type="radio" name="show_type" value="2" <tpl> if $modi_array.show_type eq '2' </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langChannelPopProduct </tpl> 
				<input type="radio" name="show_type" value="3" <tpl> if $modi_array.show_type eq '3' </tpl>checked="checked"<tpl> /if </tpl> /><tpl> $langChannelCommendProduct </tpl>		  </td>
		</tr>
		<tr>
			<td height="30" colspan="2" class="td1">
				<table width="100%" border="0" cellpadding="0" cellspacing="0" id="pro_list" class="noborder" style="border:1px dashed #0099CC;">
				<tr style=" background-color:#EFF8FC">
				  <td colspan="2" align="left" valign="middle">&nbsp;<tpl> $langChannelMerchandiseName </tpl></td>
				  <td width="15%" align="left" valign="middle"><tpl> $langCSort </tpl></td>
				  <td width="15%" align="left" valign="middle"><tpl> $langCOperation </tpl></td>
				</tr>
				<tpl> if $modi_array.p_id[0].p_id neq "" </tpl>
					<tpl> foreach from=$modi_array.p_id item=one key=key </tpl>
					<tr>
					
					  <td colspan="2" width="68%" align="left" valign="middle"><tpl> $one.p_name </tpl></td>
					  <td align="left" valign="middle"><input type="text" size="4" name="p_sort[<tpl> $one.p_id </tpl>]" id="p_sort_<tpl> $one.p_id </tpl>" value="<tpl> $modi_array.sort_value[$key] </tpl>" /><input type="hidden" name="p_id[<tpl> $one.p_id </tpl>]" id="p_id_<tpl> $one.p_id </tpl>" value="<tpl> $one.p_id </tpl>" /></td>
						<td width="15%" align="center" valign="middle"><a href="javascript:;" onclick="var row=$(this).parent().parent();row.fadeOut('normal', function(){row.remove();});" title="<tpl> $langCdele </tpl>" class="del_a_pic">
					  </a></td>
					</tr>
					<tpl> /foreach </tpl>
				<tpl> /if </tpl>
			  </table>		  </td>
		</tr>
		<tr>
		  <td height="50" colspan="2" align="center" valign="bottom" class="td1" style=" padding-left:210px; padding-top:10px"><span class="btn_left">
		    <input name="submit" type="submit" class="btn_submit" value="<tpl> $langChannelConfirm </tpl>"/>
		  </span></td>
        </tr>
			<tr>
			<td colspan="2" align="left" style=" height:40px; line-height:40px; padding-top:10px; font-size:14px; color:#007dc6">使用以下搜索功能，选取您所需要的本模块内容：</td>
		</tr>
		<tr>
			<td height="30" colspan="3"><!-- 商品列表搜索 -->
				<table width="100%" border="0" cellpadding="0" cellspacing="0" class="noborder">
				   <tr>
					<th width="26%" class="td1"><tpl> $langChannelType </tpl>：</th><td width="74%" align="left"> <select name="c1" id="c1" style="WIDTH: 110px">
						<option value=""></option>
						<tpl> foreach item = parent from = $ProductCateArray </tpl>
						<option value="<tpl>$parent.id</tpl>||<tpl>$parent[5]</tpl>"><tpl>$parent.name</tpl></option>
						<tpl> /foreach </tpl>
					  </select>
					  <select name="c2" id="c2" style="WIDTH: 110px">
					  </select>
					  <select name="c3" id="c3" style="WIDTH: 110px">
					  </select>
					  <select name="c4" id="c4" style="WIDTH: 110px">
					  </select><br />
					  <input type="hidden" name="search_cate" id="search_cate" /><!-- 商品类别检索的值 -->					</td>
				  </tr>
				   <tr>
					<th width="26%" class="td1">
				    <tpl> $langChannelKeyWord </tpl>：</th><td align="left"> <input type="text" id="keyword" class="txtinput" name="keyword" />
						&nbsp;&nbsp;
							<span class="btn_left">
						<input value="<tpl> $langChannelConditionSelect </tpl>" type="button" class="btn_submit" onclick="product_submit_search();"/>		
					  </span>									</td>
				   </tr>
			  </table>
				<!-- 商品列表搜索end -->		  </td>
		</tr>
		<tr>
			<td colspan="2">	<div id="pro_search_list"  style="padding-left:130px;*padding-left:110px;_padding-left:110px"><!-- pro_search_list条件筛选出来的商品列表 -->
			</div></td>
		</tr>
  </table>
</form>
<!-- 商品选择部分end -->
<script>
$(document).ready(function() {
	<tpl> if $list_class_error != '' </tpl>
	//输出后台程序错误信息
	showMessage(<tpl> $list_class_error </tpl>);
	<tpl> /if </tpl>
});

//添加模块，以模块标识符号
function product_submit_module(){

	var temp_name = "";//模块标识符
	var patrn=/^[a-zA-Z0-9]{1,100}$/; //正则匹配.
	var patrn_num=/^[0-9]{1,1000}$/; //正则数字匹配.
	var sort_value = "";//排序的序号拼成的字符串，值之间的顺序为选中的商品的顺序
	var param_array = new Array();//参数数组，用来拼传到服务器端的字符串用的
	var name_num = "";//商品名称字数
	var p_str = "";//选中的商品 字符串
	var sort_sign = true; //排序的序号是否正确的标识
	
	
	//商品列表，取选中的项
	$('#pro_list input[@type=hidden]').each(function(){
		if(this.value != ""){
			p_str += "p_id:"+this.value+"|||";//选中字符串
			sort_value += "sort_value:"+$("#p_sort_"+this.value).val()+"|||";//排序字符串
			if (!patrn_num.exec($("#p_sort_"+this.value).val())){sort_sign=false;}
		}
	});
	
	//验证排序的序号是否正确
	if(sort_sign == false){alert("<tpl> $langChannelCompositorNumIsNumber </tpl>");return false;}
	
	//验证右侧是否有值
	if(p_str == ""){alert("<tpl> $langChannelAddInfoNotNull </tpl>");return false;}
	
	//验证模块标识符是否存在，不存在则返回错误
	temp_name = $("#product_temp_name").val();
	if (!patrn.exec(temp_name)){alert("<tpl> $langChannelModuleIdIs100EnglistOrNum </tpl>");	return false;}
	
	//验证商品名称长度
	name_num = $("#name_num").val();
	if (!patrn_num.exec(name_num)){alert("<tpl> $langChannelMerchandiseNameLengthIsNum </tpl>");return false;}
	
	//取表单的参数信息，以后如果继续添加参数，则以"|||"分割，参数标识：参数值 的形式衔接
	param_array[0] = "temp_name:"+temp_name+"|||";//模块标识符
	param_array[1] = "name_num:"+name_num+"|||";//商品名称字数
	param_array[2] = p_str;//选中商品标识
	param_array[3] = sort_value;//排序字段
	param_array[4] = "show_type:"+$("input[@name=show_type][@checked]").val();//展现形式
	
	
	//循环param_array拼成字符串存入隐藏域中
	var str = "";
	for(i=0;i<param_array.length;i++){
		str += param_array[i];
	}
	
	temp_name = "product_module_"+temp_name//给模块标识符添加前缀
	
	if(checkRepeatModuleName(temp_name) == false){return false;}//验证是否与已有名称或者表单名重复 

	//添加模块标签
	$("#add_module_sign").append("<tr><td><span class='btn_left'><input type='button' class='btn_submit' style='width:250px' value='"+temp_name+"' onclick='modi_module(\""+temp_name+"\");deleteRow(this);set_module_style(\"disabled\");'/></span><input type='hidden' name='"+temp_name+"' id='"+temp_name+"' value='"+str+"'/><a href=\"javascript:;\" onclick=\"javascript: copyToClipboard('"+temp_name+"')\" title='<tpl> $langChannelCopyModuleName </tpl>' class='copy_a_pic'></a><a href='javascript:;' onclick='if($(\"#add_module\")[0].disabled != true){deleteProhibitionElements(\""+temp_name+"\");deleteRow(this);}else{alert(\"<tpl> $langModuleDelWrong </tpl>\");}' title='<tpl> $langChannelDelThisModule </tpl>' class='del_a_pic'></a></td></tr>");
	
	$("#body_module").html("");//替换为模块标识符，隐藏域为拼的字符串
	
  	$("#add_module").attr("disabled","");//开放增加按钮
	
	set_module_style('no_disabled');//将模块区域中的按钮还原成no_disabled
	
	$.unblockUI();//去除遮罩
	
	$("#module_block").html('');//去除遮罩中的内容
	
	return false;
}

//筛选条件中类别选择
function tonext(whos) {
		$(whos).change(
			function(){
				var valarray=$(this).val().split('||');	
				$('#search_cate').val(valarray[0]);
				if (valarray[1]=='1') {
					$(this).next().attr('disabled','true').html('<option value="" selected="selected"><tpl> $langChannelDataToLoading </tpl></option>');
					$.get('../member/own_productcate.php',{action:'list',id:valarray[0],random_number:Math.random()},function(data){
					DataArray = data.split("|||");var a='';for (var i = 0; i<DataArray.length-1; i++) {att=DataArray[i].split("||");id=att[0];cla=att[2];a+='<option value="'+id+'||'+cla+'">'+att[1]+((cla=='1')?' ->':'')+'</option>';};
					$(whos).next().removeAttr('disabled').html('<option value="" selected="selected"></option>'+a).nextAll().html('');
					tonext($(whos).next());
				})} else {$(whos).nextAll().html('').attr('disabled','true');
				};
		})
};
$().ready(function() {
	tonext('#c1');
});	

/* 通过检索条件，列出商品列表 */function product_submit_search(){
	ShowDiv = 'pro_search_list';
	var search_keyword = escape($("#keyword").val());
	/* 取表单参数 */$.ajax({
		url: "channel.manage.php",
		data: "action=product_search&search_cate="+$("#search_cate").val()+"&keyword="+search_keyword,
		type:'get',
		dataType:"html",
		beforeSubmit:  showLoading(showText),// 提交之前执行的方法
		success: function(msg){
			hideLoading();
			if(msg != ""){
				$("#pro_search_list").html(msg);
			}else{
				alert("<tpl> $langChannelThisTypeNotMerchandise </tpl>");
			}
		}
	});
	return false;
}
</script>