<?php include $this->admin_tpl('meta', 'admin');?>
<title>添加广告 - YzmCMS内容管理系统</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
		<ul>
			 <li><label><span class="c-red">*</span>广告名称</label><input type="text" placeholder="广告名称" class="input" name="title" value=""></li>
			 <li><label><span class="c-red">*</span>链接地址</label><input type="url" placeholder="要加http://" class="input" name="url" value="" style="width:400px"></li>
			 <li><label><span class="c-red">*</span>广告类型</label>
			 <span class="span_input">
			 	<label class="label_radio"><input name="type" type="radio" value="1" checked> 文字形式</label>
			 	<label class="label_radio"><input name="type" type="radio" value="2"> HTML代码</label>
			 	<label class="label_radio"><input name="type" type="radio" value="3"> 图片形式</label>
			 </span>
			 </li>
			 <li id="adver_text"><label><span class="c-red">*</span>广告值</label><textarea name="text" class="textarea" style="width:400px"></textarea></li>
			 <li id="adver_img" style="display:none"><label><span class="c-red">*</span>选择图像</label><?php echo form::image('img');?></li>
			 <li><label>开始时间</label><input type="text" class="input-text laydate-icon" id="start" style="width:230px;height:30px;" name="start_time" value=""> <span style="color:#898989">[留空为不限制]</span></li>
			 <li><label>结束时间</label><input type="text" class="input-text laydate-icon" id="end" style="width:230px;height:30px;" name="end_time" value=""> <span style="color:#898989">[留空为不限制]</span></li>
			 <li><label>简洁描述</label><span class="span_input"><input type="text" class="input" name="describe" value="" style="width:500px"></span></li>			 
			 <li><input type="hidden" name="dosubmit" value="1">
			 <input class="dosubmit w_120 btn-primary radius" type="submit" value="提交">
			 <input class="btn w_120 btn-default radius" type="button" value="取消" onclick="yzmcms_close()">
			</li>
		</ul>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/laydate/1.1/laydate.js"></script>
<script type="text/javascript">

	$(function(){
		$('input:radio[name="type"]').change(function(){  
			if($(this).val()=='3') {
				$('#adver_img').css('display','');
				$('#adver_text').css('display','none');
			}else{
				$('#adver_img').css('display','none');
				$('#adver_text').css('display','');
			}
		}); 
	});

	function dosub(obj){
		 if(obj.title.value==''){
			 layer.msg('广告名称不能为空！');
			 return false;
		 }
		 if(obj.url.value==''){
			 layer.msg('链接地址不能为空！');
			 return false;
		 }
		 if($("input[name='type']:checked").val()=='3'){
			 if(obj.img.value==''){
				 layer.msg('图像地址不能为空！');
				 return false;
			 }
		 }else{
			 if(obj.text.value==''){
				 layer.msg('广告值不能为空！');
				 return false;
			 }
		 }
		 
        $.ajax({
            type: 'POST',
            url: '<?php echo U('add');?>', 
            data: $(obj).serialize(),
		    dataType: "json", 
            success: function (msg) {
				if(msg.status == 1){
					parent.location.reload();       
			    }else{
					layer.msg(msg.message);
				}
            }
        })		 
		return false;			 
	}
	
	
	var start = {
		elem: '#start',
		format: 'YYYY-MM-DD', 
		istime: false,
		istoday: false,
		choose: function(datas){
			 end.min = datas; 
			 end.start = datas 
		}
	};

	var end = {
		elem: '#end',
		format: 'YYYY-MM-DD',
		istime: false,
		istoday: false,
		choose: function(datas){
			start.max = datas; 
		}
	};
	laydate(start);
	laydate(end);
</script> 

</body>
</html>