<!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}-->
<!--{include file=elements/header.js.html type=upload}-->
<!--{include file=elements/header.js.html type=valid}-->
<style type="text/css">
div.button {
	font-size:12px;
	color:#00f;
	line-height:25px;
	text-align:center;
	float:left;
	margin-left:5px;
}
div.button.hover{
	color:#f00;
}
.anchorbutton{
	font-size:12px;
	color:#00f;
	text-align:center;
	float:left;
	margin-left:5px;
	cursor:pointer;
}

.anchorbuttonon{
	color:#f00;
}
</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;游戏模块&nbsp;&gt;&nbsp;内容管理&nbsp;&gt;&nbsp;新增游戏
				</div>
			</div>
			<div class="tabcontent">
				<a href="index.php?r=Game.resource" class="nolink">内管管理</a>
				<a href="index.php?r=SiteSet.gameset" class="link">属性设置</a>
				<a href="index.php?r=Game.gameListLayout" class="link">列表页布局</a>
					<a href="index.php?r=Game.gamePageLayout" class="link">内容页布局</a>
			</div>
			<div id="secrightContent">
				<div class="tableContent">
					<form action="index.php?r=Game.addgameinfo" method="post" id="addGameForm">
						<input type="hidden" name="returnParams" value="<!--{$returnParams}-->"/>
						<table class="tbl_edit" width="100%">
							<tr>
								<td class="td_name">游戏名称<span class="red">*</span></td>
								<td class="td_content"><input type="text" class="text" id="title" name="data[Game][title]" maxlength='256'/><span id="span_title"></span></td>
							</tr>
							<tr>
								<td class="td_name">主图片</td>
								<td class="td_content">
									<div style="float:left;"><input type="text" class="text" name="data[Game][image_url]" id="Game_image_url"/></div>
									<div style="float:left;" id="button1" class="button">上传图片</div>
									<div style="float:left;line-height:25px;">&nbsp;<span id="main_img"></span></div>
									<input type="hidden" name="data[Game][thumb_image_url]" id="Game_thumb_image_url" value=""/>
								</td>
							</tr>
							<tr>
								<td class="td_name">游戏截图</td>
								<td class="td_content">
									<div>
										<div style="float:left;"><input type="text" class="text anchorinput" name="data[GamePicture][image_url][]"/></div>
										<div style="float:left;" id="button2" class="button">上传图片</div>
										<div style="float:left;line-height:25px;" class="anchorbutton" onMouseOver="overanchor(this)" onMouseOut="outanchor(this)" onClick="deletepic(this)">删除截图</div>
										<div style="float:left;line-height:25px;">&nbsp;<span class="img_src_name"></span></div>
									</div>
									<div id="scpicurlcontainer"></div>
									<div class="anchorbutton" id="addgamepicbutton" style="clear:both;margin-left:0px;">添加截图</div>
								</td>
							</tr>
							<tr>
								<td class="td_name">发布频道</td>
								<td class="td_content">
								<!--{if !empty($channels)}-->
									<!--{foreach from=$channels item=channel name=foo}-->
										<input type="checkbox" name="channel_id[]" id="channel_id[]" value="<!--{$channel.id}-->" <!--{if $channel_id == $channel.id}-->checked="checked"<!--{/if}-->/>[<!--{$channel.id}-->]<!--{$channel.channel_text}-->&nbsp;
										<!--{if ($smarty.foreach.foo.index+1) % 4 == 0}--><br/><!--{/if}-->
									<!--{/foreach}-->
								<!--{else}-->
									无
								<!--{/if}-->
								</td>
							</tr>
							<tr>
								<td class="td_name">推荐等级</td>
								<td class="td_content"><select name="data[Game][recommend_level]">
									<option value="">推荐等级</option>
									<option value="1">1</option>
									<option value="2">2</option>
									<option value="3">3</option>
									<option value="4">4</option>
									<option value="5">5</option>
								</select></td>
							</tr>
							<tr>
								<td class="td_name">好评数</td>
								<td class="td_content"><input type="text" class="number" id="good_count" name="data[Game][good_count]" value="0"/><span id="span_good_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">中评数</td>
								<td class="td_content"><input type="text" class="number" id="normal_count" name="data[Game][normal_count]" value="0"/><span id="span_normal_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">差评数</td>
								<td class="td_content"><input type="text" class="number" id="bad_count" name="data[Game][bad_count]" value="0"/><span id="span_bad_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">人气</td>
								<td class="td_content"><input type="text" class="number" id="click_count" name="data[Game][click_count]" value="0"/><span id="span_click_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">下载次数</td>
								<td class="td_content"><input type="text" class="number" id="down_count" name="data[Game][down_count]" value="0"/><span id="span_down_count"></span></td>
							</tr>
							<tr>
								<td class="td_name">收费类型</td>
								<td class="td_content"><select name="data[Game][fee_type]">
									<option value="">收费类型</option>
									<option value="1">免费</option>
									<option value="2">收费</option>
									<option value="3">其他</option>
								</select></td>
							</tr>
							<tr>
								<td class="td_name">收费说明</td>
								<td class="td_content"><input type="text" class="text" name="data[Game][fee_detail]" maxlength='64'/></td>
							</tr>
							<tr>
								<td class="td_name">厂商</td>
								<td class="td_content"><input type="text" class="text" name="data[Game][manufacturer]" maxlength='32'/></td>
							</tr>
							<tr>
								<td class="td_name">是否重命名上传包</td>
								<td class="td_content"><input type="radio" name="data[Game][rename_flag]" value="1" checked/>是&nbsp;&nbsp;<input type="radio" value="0" name="data[Game][rename_flag]"/>否</td>
							</tr>
							<tr>
								<td class="td_name">是否开启评论</td>
								<td class="td_content"><input type="radio" name="data[Game][comment_flag]" value="1" checked/>是&nbsp;&nbsp;<input type="radio" value="0" name="data[Game][comment_flag]"/>否</td>
							</tr>
							<tr>
								<td class="td_name">游戏介绍</td>
								<td class="td_content"><textarea id="introduction" name="data[Game][introduction]"></textarea></td>
							</tr>
							<tr>
								<td class="td_name">安装教程</td>
								<td class="td_content"><textarea id="install_tutorial" name="data[Game][install_tutorial]"></textarea></td>
							</tr>
							<tr>
								<td class="noborder"></td>
								<td class="noborder"><button type="submit" class="butsubmit">提交</button>&nbsp;&nbsp;<button type="button" class="but2font" onClick="window.location.href='index.php?<!--{$returnParams}-->'">返回</button></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
$(document).ready(function(){
	$("#introduction").addClass("cleditorTextarea").cleditor({
		width : "80%",
		height: 120,
		controls: "bold italic underline break | undo redo | " +
			" image link file | basic-function advertising-system access-statistics"
	});
	$("#install_tutorial").addClass("cleditorTextarea").cleditor({
		width : "80%",
		height: 120,
		controls: "bold italic underline break | undo redo | " +
			" image link file | basic-function advertising-system access-statistics"
	});
	
	var button1 = $("#button1");
	new AjaxUpload(button1, {
		action: 'index.php?r=Game.gameimageupload',
		name: 'image_file',
		onSubmit : function(file, ext){
			this.disable();
			button1.html('<img src="images/ajax.gif"/>');
		},
		onComplete: function(file, response){
			var data = eval("("+response+")");
			if(data.flag == 1){
				$("#Game_image_url").val(data.name);
				$("#Game_thumb_image_url").val(data.thumb_name);
				button1.html('上传图片');
				$("#main_img").html(file);
				this.enable();
			} else if(data.flag == -1){
				alert("不能上传格式为" + data.fileext + "的文件!");
				button1.html('上传图片');
				this.enable();
			} else if(data.flag == -2){
				alert("上传文件的大小超出指定范围!");
				button1.html('上传图片');
				this.enable();
			} else if(data.flag == -10){
				//if(data.compress_error_code == 7){
					alert("水印文字过长,压缩文件失败!请调整游戏属性设置中图片压缩和水印设置后，重新上传!");
				//}
				button1.html('上传图片');
				this.enable();
			} else {
				alert("上传文件失败!");
				button1.html('上传图片');
				this.enable();
			}
		}
	});

	var button2 = $("#button2");
	new AjaxUpload(button2, {
		action: 'index.php?r=Game.screenimgupload',
		name: 'image_file',
		onSubmit : function(file, ext){
			this.disable();
			button2.html('<img src="images/ajax.gif"/>');
		},
		onComplete: function(file, response){
			var data = eval("("+response+")");
			if(data.flag == 1){
				$(button2).parent().find(".anchorinput").val(data.name);
				button2.html('上传图片');
				$(button2).parent().find(".img_src_name").html(file);
				this.enable();
			} else if(data.flag == -1){
				alert("不能上传格式为" + data.fileext + "的文件!");
				button2.html('上传图片');
				this.enable();
			} else if(data.flag == -2){
				alert("上传文件的大小超出指定范围!");
				button2.html('上传图片');
				this.enable();
			} else {
				alert("上传文件失败!");
				button2.html('上传图片');
				this.enable();
			}
		}
	});

	var uploadimgbuttoncount = 0;
	$("#addgamepicbutton").click(function(){
		uploadimgbuttoncount = uploadimgbuttoncount + 1;
		var str = "<div style=\"clear:both;\">";
		str = str + "<div style=\"float:left;\"><input type=\"text\" class=\"text anchorinput\" name=\"data[GamePicture][image_url][]\" id=\"GamePicture_image_url[]\" value=\"\" /></div>";
		str = str + "<div id=\"uploadimgbutton"+uploadimgbuttoncount+"\" class=\"button\">上传图片</div>";
		str = str + "<div style=\"float:left;line-height:25px;\" class=\"anchorbutton\" onMouseOver=\"overanchor(this)\" onMouseOut=\"outanchor(this)\" onclick=\"deletepic(this)\">删除截图</div>";
		str = str + "<div style=\"float:left;line-height:25px;\">&nbsp;<span class=\"img_src_name\"></span></div></div>";
		$(str).appendTo("#scpicurlcontainer");

		var uploadimgbutton = $("#uploadimgbutton"+uploadimgbuttoncount);
		new AjaxUpload(uploadimgbutton, {
			action: 'index.php?r=Game.screenimgupload',
			name: 'image_file',
			onSubmit : function(file, ext){
				this.disable();
				uploadimgbutton.html('<img src="images/ajax.gif"/>');
			},
			onComplete: function(file, response){
				var data = eval("("+response+")");
				if(data.flag == 1){
					$(uploadimgbutton).parent().find(".anchorinput").val(data.name);
					uploadimgbutton.html('上传图片');
					$(uploadimgbutton).parent().find(".img_src_name").html(file);
					this.enable();
				} else if(data.flag == -1){
					alert("不能上传格式为" + data.fileext + "的文件!");
					uploadimgbutton.html('上传图片');
					this.enable();
				} else if(data.flag == -2){
					alert("上传文件的大小超出指定范围!");
					uploadimgbutton.html('上传图片');
					this.enable();
				} else {
					alert("上传文件失败!");
					uploadimgbutton.html('上传图片');
					this.enable();
				}
			}
		});
	});

	$(".anchorbutton").hover(
			function(){$(this).addClass("anchorbuttonon")},
			function(){$(this).removeClass("anchorbuttonon")}
	);

	var validate = $("#addGameForm").validate({
		rules: {
			'data[Game][title]' : {
				'required' : true
			},
			'data[Game][good_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][normal_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][bad_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][click_count]':{
				'number': true,
				'digits' : true
			},
			'data[Game][down_count]':{
				'number': true,
				'digits' : true
			}
		},
		messages: {
			'data[Game][title]' : {
				'required' : '请填写游戏名称'
			},
			'data[Game][good_count]':{
				'number': '好评数必须为正整数',
				'digits':'好评数必须为正整数'
			},
			'data[Game][normal_count]':{
				'number': '好评数必须为正整数',
				'digits':'中评数必须为正整数'
			},
			'data[Game][bad_count]':{
				'number': '好评数必须为正整数',
				'digits':'差评数必须为正整数'
			},
			'data[Game][click_count]':{
				'number': '人气值必须为正整数',
				'digits':'人气值必须为正整数'
			},
			'data[Game][down_count]':{
				'number': '下载次数必须为正整数',
				'digits':'下载次数必须为正整数'
			}
		},
		errorPlacement: function(error, element){
			$("#span_" + element.attr("id")).html(error).attr("class", "error");
		},
		errorClass: "invalid",
		success: function(label){
			label.parent().html("&nbsp;").attr("class", "valid");
		}
	});

	$("#addGameForm").submit(function(){
		if (validate.numberOfInvalids() <= 0) {
			setDisabled(":button",window.document);
			return true;
		} else {
			return false;
		}
	});
	
});

function deletepic(deletebutton){
	$(deletebutton).html("<img src=\"images/ajax.gif\"/>");
	if($(deletebutton).parent().find(".anchorinput").val()){
		$.post("index.php?r=Game.deletepic", {picdir : $(deletebutton).parent().find(".anchorinput").val()}, function(data){
			$(deletebutton).parent().remove();
		});
	} else {
		$(deletebutton).parent().remove();
	}
}

function overanchor(button){
	$(button).addClass("anchorbuttonon");
}

function outanchor(button){
	$(button).removeClass("anchorbuttonon");
}
</script>
</html>