<%@ 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="shefangMsg" style="color:red;">&nbsp;</span></li></ul>		     
			        	<table width="100%" border="0" style="line-height:35px;">			        		
								<tr>
				        			<td style="width: 70px;text-align: center;">
				        			     <input type="text" value="1000" id="shefang_distance" class="popu_input" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'');console.info(this.value);}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>			        	
			        	</table>	
			        	<input id="shefangFormBtn" type="button" value="提交" style="width:80px; height:30px; margin-left:110px; margin-top:20px;" />		        	
			        	<input type="hidden" id="shefang_vid" value="${param.vid}"/>		     
		        </div>
			</div>
			<div class="bot"></div>	
			<script>
				
				$(function(){
					
					$("#shefangFormBtn").unbind().click(function(){
							
							$("#shefangMsg").html("&nbsp;");
							$("#shefangFormBtn").attr("disable","disable");
							$("#shefangFormBtn").val("提交..");
							
							var data = getFormData();
										
							$.ajax({
			                    type: "POST",
			                    dataType: "json",
			                    url: "json/vehiclecmdAction_shefang.action",
			                    data: data,
			                    success: function (json) {
			                    	if(json.flag){
			                    		var LatLng = getCurVhcLatLng(data.vid);			                    		
			                    		SheFang.add(data.vid, data.distance / 2, LatLng.lat, LatLng.lng);			                    			                   
				                        $("#closePopuWin").click();
			                        }else{
			                        	$("#shefangMsg").html(json.msg);
			                        	$("#shefangFormBtn").attr("disable","");
										$("#shefangFormBtn").val("提交");
			                        }
			                    },
			                    error: function(data) {
			                     		$("#shefangMsg").html("*提交失败请稍后重试");
										$("#shefangFormBtn").attr("disable","");
										$("#shefangFormBtn").val("提交");
			                     }
			
			                });       				
					});
					
					function getFormData(){
						var vid = $("#shefang_vid").val();
						var LatLng = getCurYuanShiVhcLatLng(vid);
						var distance = parseInt($("#shefang_distance").val());
						return {	
									vid : vid,
									lat : LatLng.lat,
								    lng : LatLng.lng,
								    distance : distance
								    								   	
							   };

					}
					
					function getCurYuanShiVhcLatLng(vid){
					
						var LatLng = {
									   lat : 0,
									   lng : 0
									 };
							if(carList){
	    						for(var i=0; i<carList.data.length;i++){
	    							if(vid == carList.data[i].id){
	    								LatLng.lat = carList.data[i].positionLast.ilat;
	    								LatLng.lng = carList.data[i].positionLast.ilng;
	    								break;
	    							}
	    						}
    						}
    					return LatLng;
					}
					
					function getCurVhcLatLng(vid){
					
						var LatLng = {
									   lat : 0,
									   lng : 0
									 };
							if(carList){
	    						for(var i=0; i<carList.data.length;i++){
	    							if(vid == carList.data[i].id){
	    								LatLng.lat = carList.data[i].positionLast.lat;
	    								LatLng.lng = carList.data[i].positionLast.lng;
	    								break;
	    							}
	    						}
    						}
    					return LatLng;
					}
					
				});
				
			</script>	
  </body>
</html>
