<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script>
$().ready(function(){
	<!--{if $data.package_type == 1}-->
		$("#slc_brand_edit").html($("#slc_brand").html());
		$("#slc_brand_edit").val("<!--{$data.mobile_brand_id}-->");
		changeSerial("_edit");
		$("#slc_serial_edit").val("<!--{$data.mobile_serial_id}-->");
	<!--{else}-->
		$("#slc_screen_edit").html($("#slc_screen").html());
		$("#slc_screen_edit").val("<!--{$data.mobile_screen_id}-->");
	<!--{/if}-->
	$("#editForm").validate({
		rules: {
			<!--{if $data.package_type == 1}-->
			'data[GamePackage][mobile_brand_id]' : {
				'required' : true
			},
			'data[GamePackage][mobile_serial_id]' : {
				'required' : true
			},
			<!--{else}-->
			'data[GamePackage][mobile_screen_id]' : {
				'required' : true
			},
			<!--{/if}-->
			'data[GamePackage][download_url]' : {
				'required' : true
			},
			'data[GamePackage][file_size]' : {
				'digits' : true
			},
			'data[GamePackage][show_order]' : {
				'digits' : true
			}
		},
		messages: {
			<!--{if $data.package_type == 1}-->
			'data[GamePackage][mobile_brand_id]' : {
				'required' : '手机品牌不能为空'
			},
			'data[GamePackage][mobile_serial_id]' : {
				'required' : '机型系列不能为空'
			},
			<!--{else}-->
			'data[GamePackage][mobile_screen_id]' : {
				'required' : '手机屏幕不能为空'
			},
			<!--{/if}-->
			'data[GamePackage][download_url]' : {
				'required' : '下载地址不能为空'
			},
			'data[GamePackage][file_size]' : {
				'digits' : '排列顺序必须为整数'
			},
			'data[GamePackage][show_order]' : {
				'digits' : '文件大小必须为整数'
			}
		},
		errorPlacement: function(error, element){
			$("#span_" + element.attr("id")).html(error).attr("class", "error");
		},
		submitHandler: function(form){
			setDisabled(":button",window.document);
			form.submit();
		},
		errorClass: "invalid",
		success: function(label){
			label.parent().html("&nbsp;").attr("class", "valid");
		}
	});
});

//系列不能重复
function checkSerialEdit(id){
	var serial = $("#slc_serial_edit");
	if (serial.val()) {
		$(".input_serial").each(function(){
			if ($(this).val() == serial.val() && $(this).attr("id") != "input_serial"+id) {
				alert("系列不能重复");
				serial.val("");
			}
		});
		$(".slc_serial").each(function(){
			if ($(this).val() == serial.val()) {
				alert("系列不能重复");
				serial.val("");
			}
		});
	}
}

//屏幕不能重复
function checkScreenEdit(id){
	var screen = $("#slc_screen_edit");
	if (screen.val()) {
		$(".input_screen").each(function(){
			if ($(this).val() == screen.val() && $(this).attr("id") != "input_screen"+id) {
				alert("屏幕不能重复");
				screen.val("");
			}
		});
		$(".slc_screen").each(function(){
			if ($(this).val() == screen.val()) {
				alert("屏幕不能重复");
				screen.val("");
			}
		});
	}
}

//jar上传事件
var jarbutton = $("#upload_edit");
new AjaxUpload($("#upload_edit"), {
	action: "index.php?r=Game.gamepackageupload&gameid="+$("#gameid").val(),
	name: "package_file",
	onSubmit: function(file, ext){
		if ((ext && /^(jad)$/i.test(ext))){
        	alert(ext+'文件请用jad专用上传按钮上传！');
        	return false;
		}
		jarbutton.html('<img src="images/ajax.gif"/>');
		this.disable();
	},
	onComplete: function(file, response){
		jarbutton.html('上传');
		this.enable();
		var data = eval("("+response+")");
		if (data.flag == 1) {
			$("#GamePackage_download_url").val(data.name);
			$("#oldname_edit").html("("+data.filename+"."+data.fileext+")");
			$("#GamePackage_file_type").val(data.fileext);
			$("#GamePackage_file_size").val(data.size);
		} else if (data.flag == -2) {
			alert("不能上传" + data.fileext + "文件!");
		} else if (data.flag == -3) {
			alert("文件大小超出指定范围!");
		} else {
			alert("上传文件失败!");
		}
	}
});

//jad上传事件
var jadbutton = $("#uploadjad_edit");
new AjaxUpload($("#uploadjad_edit"), {
	action: "index.php?r=Game.gamepackageupload&gameid="+$("#gameid").val(),
	name: "package_file",
	onSubmit: function(file, ext){
		if (! (ext && /^(jad)$/i.test(ext))){
        	alert('jad专用上传按钮不能上传'+ext+'文件！');
        	return false;
		}
		jadbutton.html('<img src="images/ajax.gif"/>');
		this.disable();
	},
	onComplete: function(file, response){
		jadbutton.html('上传');
		this.enable();
		var data = eval("("+response+")");
		if (data.flag == 1) {
			$("#download_additional_url").val(data.name);
		} else if (data.flag == -2) {
			alert("不能上传" + data.fileext + "文件!");
		} else if (data.flag == -3) {
			alert("文件大小超出指定范围!");
		} else {
			alert("上传文件失败!");
		}
	}
});
</script>
<form action="index.php?r=Game.packedit" method="post" id="editForm">
	<input type="hidden" name="data[GamePackage][id]" value="<!--{$data.id}-->" />
	<input type="hidden" name="game_id" value="<!--{$data.game_id}-->" />
	<input type="hidden" name="pakListReturnParams" value="<!--{$pakListReturnParams}-->" />
	<table class="tbl_edit" width="100%">
		<!--{if $data.package_type == 1}-->
		<tr>
			<td class="td_name">手机品牌</td>
			<td class="td_content"><select id="slc_brand_edit" name="data[GamePackage][mobile_brand_id]" onchange="changeSerial('_edit')"></select><span id="span_slc_brand_edit"></span></td>
		</tr>
		<tr>
			<td class="td_name">机型系列</td>
			<td class="td_content"><select id="slc_serial_edit" name="data[GamePackage][mobile_serial_id]" onchange="checkSerialEdit('<!--{$data.id}-->')"></select><span id="span_slc_serial_edit"></span></td>
		</tr>
		<!--{else}-->
		<tr>
			<td class="td_name">手机屏幕</td>
			<td class="td_content"><select id="slc_screen_edit" name="data[GamePackage][mobile_screen_id]" onchange="checkScreenEdit('<!--{$data.id}-->')"></select><span id="span_slc_screen_edit"></span></td>
		</tr>
		<!--{/if}-->
		<!--{if $data.download_type == 1}-->
		<tr>
			<td class="td_name">包下载地址</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][download_url]" id="GamePackage_download_url" value="<!--{$data.download_url}-->" readonly/><div class="button" id="upload_edit">上传</div><div id="oldname_edit" style="display:inline;"></div><span id="span_GamePackage_download_url"></span></td>
		</tr>
		<tr>
			<td class="td_name">jad下载地址</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][download_additional_url]" id="GamePackage_download_additional_url" value="<!--{$data.download_additional_url}-->" readonly/><div class="button" id="uploadjad_edit">上传</div></td>
		</tr>
		<tr>
			<td class="td_name">文件类型</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][file_type]" id="GamePackage_file_type" value="<!--{$data.file_type}-->" readonly/><input type="hidden" name="data[GamePackage][download_type]" value="1"/></td>
		</tr>
		<tr>
			<td class="td_name">文件大小</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][file_size]" id="GamePackage_file_size" value="<!--{$data.file_size}-->" readonly/><span id="span_GamePackage_file_size"></span></td>
		</tr>
		<!--{else}-->
		<tr>
			<td class="td_name">包下载地址</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][download_url]" id="GamePackage_download_url" value="<!--{$data.download_url}-->"/><span id="span_GamePackage_download_url"></span></td>
		</tr>
		<tr>
			<td class="td_name">jad下载地址</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][download_additional_url]" id="GamePackage_download_additional_url" value="<!--{$data.download_additional_url}-->"/></td>
		</tr>
		<tr>
			<td class="td_name">文件类型</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][file_type]" id="GamePackage_file_type" value="<!--{$data.file_type}-->"/></td>
		</tr>
		<tr>
			<td class="td_name">文件大小</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][file_size]" id="GamePackage_file_size" value="<!--{$data.file_size}-->"/><span id="span_GamePackage_file_size"></span></td>
		</tr>
		<!--{/if}-->
		<tr>
			<td class="td_name">排序</td>
			<td class="td_content"><input type="text" class="text" name="data[GamePackage][show_order]" id="GamePackage_show_order" value="<!--{$data.show_order}-->"/><span id="span_GamePackage_show_order"></span></td>
		</tr>
		<tr>
			<td class="td_name">显示机型</td>
			<td class="td_content"><textarea class="textarea" name="data[GamePackage][agent_description]" id="GamePackage_agent_description"><!--{$data.agent_description}--></textarea></td>
		</tr>
		<tr>
			<td class="noborder"></td>
			<td class="noborder"><button type="submit" class="butsubmit">提交</button></td>
		</tr>
	</table>
</form>