<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  	
  </head>
  <body>
			<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="terRepMsg" style="color:red;">&nbsp;</span>
		        			</li>
		        		</ul>		     
			        	<table width="100%" border="0" style="line-height:35px;">			        		
								<tr>
				        			<td style="width: 70px;text-align: center;">
				        			    设备名称:
				        			</td>
				        			<td>
				        			    <label id="cmd_win_terRep_eqName">&nbsp;</label>
				        			</td>
				        		</tr>	
				        		<tr>
				        			<td style="width: 70px;text-align: center;">
				        			    SIM卡号:
				        			</td>
				        			<td>
				        			    <label id="cmd_win_terRep_sim">&nbsp;</label>
				        			</td>
				        		</tr>	
				        		<tr>
				        			<td style="width: 70px;text-align: center;">
				        			    工作模式:
				        			</td>
				        			<td>				        		
				        			     <input name="pc_workmodel" value="0" type="radio" checked="checked">正常模式</input>
				        			     &nbsp; &nbsp; &nbsp; &nbsp;
				        			     <input name="pc_workmodel" value="1" type="radio">精确定位模式</input>
				        			</td>
				        		</tr>
				        		<tr>
				        			<td style="width: 70px;text-align: center; vertical-align: top;">
				        			    唤醒周期: 				        			    
				        			</td>
				        			<td>
				        				
				        				<input name="pc_cycle" value="0" type="radio" checked="checked">间隔模式</input>
				        				
				        				<br/>	
				        				&nbsp;&nbsp;&nbsp;&nbsp;
				        				每隔				        				
				        				<select id="interval_hour_select">
				        					
				        				</select>
				        				时
				        				<select id="interval_minute_select">
				        					
				        				</select>
				        				分 
				        				
				        				<br/>			   				        						        			    
				        			    
				        			    <input name="pc_cycle" value="1" type="radio">闹钟模式</input>
				        				
				        				<br/>
				        				&nbsp;&nbsp;&nbsp;&nbsp;
				        				每
				        				<select id="clock_day_select">
				        				</select>
				        				天的
				        				<select id="clock_hour_select">
				        				</select>
				        				时
				        				<select id="clock_minute_select">
				        				</select>
				        				分
				        				
				        			</td>				        			
				        		</tr>					        		
				        		<tr>
				        			<td style="width: 70px;text-align: center;" colspan="2">
				        			    <input id="terRep_submitBtn" type="button" value="提交" style="width:80px; height:30px;"/>					    		
				        			</td>
				        		</tr>				        	
			        	</table>		     
		        </div>
			</div>
			<div class="bot"></div>	
			<script>
			
				$(function(){
					
					
					$("#terRep_submitBtn").unbind().click(function(){					
						submitForm();
					});
					
					function submitForm(){
						
						var pc_cycle = $("input[name='pc_cycle']:checked").val();
						
						if((pc_cycle == 0 && getIntervalTime() == "0000") || (pc_cycle == 1 && getLockTime() == "000000") ){		
							$("#terRepMsg").html("*请选择周期时间");
							return;
						}	
						
						$("#terRepMsg").html("&nbsp;");
						$("#terRep_submitBtn").attr("disable","disable");
						$("#terRep_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{
							         
								         $("#terRepMsg").html(json.msg);
		                        		 $("#terRep_submitBtn").attr("disable","");
										 $("#terRep_submitBtn").val("提交");   								               	
							         }
						        },
						        error: function() {	             
						            $("#terRepMsg").html("*提交失败请稍后重试");
									$("#terRep_submitBtn").attr("disable","");
									$("#terRep_submitBtn").val("提交");
						        }
						  });
					}
					
					function getFormData(){
						
						var pc_cycle = $("input[name='pc_cycle']:checked").val();
						
						var time = "";
						if(pc_cycle == 0){		
							time = getIntervalTime();
						}else{
							time = getLockTime();
						}
						
						
						var data = "vid=" + curSendCmdEq.gprsCode +
								   "&mtid=" + curSendCmdEq.mtid +
								   "&cmdid=" + curSendCmdEq.cmdid +
								   "&cp=" + $("input[name='pc_workmodel']:checked").val() + 
								   //"&cp=" + pc_cycle +
								   "&cp=" + time + 
								   "&cp=";//最后一个cp表示密码
								   
						return data;
					}
					
					function getIntervalTime(){
					
						var time = "";
						var time_hour = $("#interval_hour_select").val();
						if(time_hour.length == 1) time_hour = "0" + time_hour;
						
						var time_minute = $("#interval_minute_select").val();
						if(time_minute.length == 1) time_minute = "0" + time_minute;
						
						time = time_hour + time_minute;
						
						return time;
					}
					
					function getLockTime(){
						var time = "";
						
						var time_day = $("#clock_day_select").val();
						if(time_day.length == 1) time_day = "0" + time_day;
						
						var time_hour = $("#clock_hour_select").val();
						if(time_hour.length == 1) time_hour = "0" + time_hour;
						
						var time_minute = $("#clock_minute_select").val();
						if(time_minute.length == 1) time_minute = "0" + time_minute;
						
						time = time_day + time_hour + time_minute;
						
						return time;
					}
					
					
					//初始化周期选择框
					putOpt("interval_hour_select", 12, 12);
					putOpt("interval_minute_select", 59, 0);
					
					putOpt("clock_day_select", 7, 1);
					putOpt("clock_hour_select", 12, 0);
					putOpt("clock_minute_select", 59, 0);
					
					if(curSendCmdEq){
						$("#cmd_win_terRep_eqName").html(curSendCmdEq.name);
						$("#cmd_win_terRep_sim").html(curSendCmdEq.simCode);
					}

					function putOpt(selectId, num, checkValue){//selectId 容器id、num  option 最大值 、 checkValue 默认选择项
						var options = [];
						for(var i=0; i<=num; i++){
							options.push("<option value=\"" + i + "\" " + (i == checkValue ? "selected=\"selected\"" : "") + ">" + i + "</option>");
						}
						$("#" +　selectId).html(options.join(""));
					}
					
				});
				
			</script>	
  </body>
</html>
