<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

	  	<style>
	  		.popuWin {
			  width: 560px;
			  position: absolute;
			  z-index: 99999;
			}
			.shangbaoshijian{
				width: 80px;
			}
	  	</style>
  		<link rel="stylesheet" href="<%=path%>/gpsonline/css/extends/easyui.css"></link>
  		<script type="text/javascript" src="<%=path%>/gpsonline/js/extends/jquery.easyui.min.js"></script> 	

			<div class="top"></div>
			<div class="center">
		  		<h3 id="movePopuWin">
		        	<a href="javascript:;" title="关闭" class="message_close" id="closePopuWin"></a>
		        	<span>上报模式设置</span>
		        </h3>
		        <div class="popuWinMessage_main">
		        		<ul>
		        			<li style="text-align:center;">
		        				<span id="shangbaoMsg" style="color:red;">&nbsp;</span>
		        			</li>
		        		</ul>		     
			        	<table width="100%" border="0" style="line-height:35px;">			        		
								<tr>
				        			<td style="text-align: center;">
				        			    <input id="dingshi_shangbao_model" name="shangbao_model" type="radio" value="0" checked="checked"/>
				        			    <label for="dingshi_shangbao_model">定时上报</label>
				        			</td>
				        			<td style="text-align: center;">
				        			    <input id="zhendong_shangbao_model" name="shangbao_model" type="radio" value="1"/>
				        			    <label for="zhendong_shangbao_model">震动模式</label>
				        			</td>
				        			<td style="text-align: center;">
				        			    <input id="chixu_shangbao_model" name="shangbao_model" type="radio" value="2"/>
				        			    <label for="chixu_shangbao_model">持续上报</label>
				        			</td>
				        		</tr>	
				        		<tr>
				        			<td style="text-align: center;">
				        			   起始时间: <input id="shangbao_cmd_start_time" value="00:00" type="text" style="width:80px;height: 18px;"/>
				        			</td>
				        			<td style="text-align: center;">
				        			   终止时间: <input id="shangbao_cmd_end_time" value="23:59" type="text" style="width:80px;height: 18px;"/>
				        			</td>
				        			<td style="text-align: center;">
				        			   上报间隔: <input id="shangbao_cmd_interval_time" type="text" class="shangbaoshijian" 
													onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" 
													onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" 
													/>
				        			</td>
				        		</tr>	
				        		<tr>
				        			<td style="text-align: center;line-height: 20px;">
				        			    GPS: <span>
					        			    	 <input id="gps_kaiguan_kai" name="gps_kaiguan" type="radio" value="1" checked="checked"/>
					        			   		 <label for="gps_kaiguan_kai">开</label>
					        			   		 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					        			   		 <input id="gps_kaiguan_guan" name="gps_kaiguan" type="radio" value="0"/>
					        			   		 <label for="gps_kaiguan_guan">关</label>
				        			   		 </span>
				        			</td>
				        			<td style="text-align: center;line-height: 20px;">				        		
				        			     开关机键: 
				        			     	 <span>
					        			    	 <input id="guanji_kaiguan_kai" name="guanji_kaiguan" type="radio" value="0"  checked="checked"/>
					        			   		 <label for="guanji_kaiguan_kai">允许关机</label>
					        			   		 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					        			   		 <input id="guanji_kaiguan_guan" name="guanji_kaiguan" type="radio" value="1"/>
					        			   		 <label for="guanji_kaiguan_guan">禁止关机</label>
				        			   		 </span>
				        			</td>
				        			<td style="text-align: center;">
				        				<input id="shangbao_submitBtn" type="button" value="提交" style="width:80px; height:30px;"/>	
				        			</td>
				        		</tr>	
				        		<tr style="line-height: 15px;">
				        			<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
				        		</tr>		        	
			        	</table>		     
		        </div>
			</div>
			<div class="bot"></div>	
			<script>
			
				$(function(){
					
					$('#shangbao_cmd_start_time').timespinner({
					    min: '00:00',
					    required: false,
					    showSeconds: false
					});
					
					$('#shangbao_cmd_end_time').timespinner({
					    min: '00:00',
					    required: false,
					    showSeconds: false
					});
					
					$("input[name='shangbao_model']").change(function(){
						
						var model = $(this).val();
						var intervalTimeInputId = "shangbao_cmd_interval_time",
							intervalTimeInput = $("#" + intervalTimeInputId);
						
						if(model == 1){
							intervalTimeInput.val("2000");
							inputUnWrite(intervalTimeInputId);
						}else if(model == 2){
							intervalTimeInput.val("3");
							inputUnWrite(intervalTimeInputId);
						}else{
							inputEnableWrite(intervalTimeInputId);
						}
						
					});
					
					function inputEnableWrite(id){
						$("#" + id).removeAttr("readonly");					
					}
					
					function inputUnWrite(id){
						$("#" + id).attr("readonly","readonly")
					}
					
					
					$("#shangbao_submitBtn").unbind().click(function(){					
						submitForm();
					});
					
					function submitForm(){
						
						if(!validateForm()) return;
						
						$("#shangbaoMsg").html("&nbsp;");
						$("#shangbao_submitBtn").attr("disable","disable");
						$("#shangbao_submitBtn").val("提交..");
								   
						$.ajax({
						        type: "POST",
						        dataType: "json",
						        url: "json/cmdAction_send.action",
						        data: getFormData(),
						        success: function(json) {
							         if (json.flag) {
								         
								         $("#closePopuWin").click();								         
								         $('#cmdsgpanel tr').eq(0).after("<tr class='alarmrow" + ( getCmdTableSize() % 2) + "'><td width='100px' style='text-align: left;padding-left:30px;'>"+curSendCmdEq.name+"</td><td width='200px' style='text-align: center;'>"+getNowFormatDate()+"</td><td tyle='text-align: left;'>发送了上报模式设置命令</td><td width='80px' style='text-align: center;'><a style='cursor:pointer;color:#069;' href='javascript:;' onclick='openCarOwnerInfo(" + curSendCmdEq.eqId + ");'>" + language.chezhuxiangqing + "</a></td></tr>");	          
							         
							         }else{
							         
								         $("#shangbaoMsg").html(json.msg);
		                        		 $("#shangbao_submitBtn").attr("disable","");
										 $("#shangbao_submitBtn").val("提交");   								               	
							         }
						        },
						        error: function() {	             
						            $("#shangbaoMsg").html("*提交失败请稍后重试");
									$("#shangbao_submitBtn").attr("disable","");
									$("#shangbao_submitBtn").val("提交");
						        }
						  });
					}
					
					function getFormData(){			
													
						var startTime = $("#shangbao_cmd_start_time").timespinner('getValue').replace(":","");
						var endTime = $("#shangbao_cmd_end_time").timespinner('getValue').replace(":","");
						
						var data = "vid=" + curSendCmdEq.gprsCode +
								   "&mtid=" + curSendCmdEq.mtid +
								   "&cmdid=" + curSendCmdEq.cmdid +
								   "&cp=" + startTime + " " + endTime + 
								   "&cp=" + $("#shangbao_cmd_interval_time").val() +
								   "&cp=" + $("input[name='gps_kaiguan']:checked").val() +
								   "&cp=" + $("input[name='guanji_kaiguan']:checked").val() +
								   "&cp=";//最后一个cp表示密码
								   
						return data;
					}
					
					function validateForm(){
						
						var model = $("input[name='shangbao_model']:checked").val();	
						
						var startTime = $("#shangbao_cmd_start_time").timespinner('getValue').replace(":",""),
							endTime = $("#shangbao_cmd_end_time").timespinner('getValue').replace(":",""),
							intervalTime = $("#shangbao_cmd_interval_time").val();							
						
						if(model == 0){//定时上报
							if(startTime.length == 0){ $("#shangbaoMsg").html("*起始时间不能为空");  return false;}
							if(endTime.length == 0){ $("#shangbaoMsg").html("*结束时间不能为空");  return false;}
							if(endTime <= startTime){ $("#shangbaoMsg").html("*结束时间不能小于起始时间");  return false;}
							if(intervalTime.length == 0 || intervalTime < 5){ $("#shangbaoMsg").html("*间隔时间不能小于5");  return false;}
						}else if(model == 1){//震动报警
						
						}else if(model == 2){//持续上报
							if((startTime.length == 0 || startTime == "0000") && (endTime.length == 0 || endTime == "0000") ){ $("#shangbaoMsg").html("*请输入起始时间或结束时间");  return false;}
						}
						
						return true;
					}
					
				});
				
			</script>	

