 var usertype = "";
 var path = "";
 var Url = {};
 var markerUrl = {};
 var electronicFenceUrl = {}; 
 var mapType = 1;
 var baidMap = {};
 var map ={};

function startMarker(){
 				 
 				 initparms();
	 			  //添加标注菜单
		 	     addMarkerMenu();
		 	     
				 if(usertype=="-1000"||usertype=="-100"){ 			  
		 			 document.getElementById("biaozhu_close").style.display = "none";
		 			 document.getElementById("markerPermissionsPanelBtn").style.display = "none";
		 			 document.getElementById("markerNamePermissionsPanelBtn").style.display = "none";
				 }else{
				 	
				 	 //点击地图时关闭已经打开的弹出框	
		 			  mapclickEvent();
		   
		  			  //获取标注Josn集
					  getMarkerJson();
					  
					  //获取标注组Json集
					  getGroupJson();
					  
					  //获取所有标注组Json集
					  getAllMarkerGroupJson();
					  
					  //绘制标注树
					  showMarkerGroupTree();
					    
					  //添加所有标注  
					  addAllMarker();
		 			
		 			 //添加标注组选择框
		 			 //addMarkerGroupSelect("marker_group_option");
		 			
		             //添加标注窗口开始
						frame("markerContentWin","moveMarkerWin","closecmarkerWin");
					 //添加标注窗口结束
					 
					 //添加标注组窗口开始
						frame("addGroupContentWin","moveGroupWin","closeGroupWin");
					 //添加标注组窗口结束
					 
					 //标注头像选择窗口开始
						frame("selectMarkerPhotoWin","moveSelectMarkerPhotoWin","closeSelectMarkerPhotoWin");
					 //标注头像选择窗口结束
					 
					 //装载区域大小滑块
					 loadAreaSlider();
				 }
				 
				 addEvent();

}

var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;
var markerGroupJson=null;
var allMarkerGroupJson=null;
var markerObject={
	markerJson : "",
	markerArr : {},
	myLatlng : null,
	infowindow : null,
	markerids : new Array(),
	markertitlearr : new Array(),
	addMarker : function(_id,_lat,_lng,_icon){
	
					 this.markerids.push(_id);
					 
	},
	addMarkerListener : function(_marker){
					
					
					 
	},
	deleteMarker : function(_id){
					

	},
	closeInfowindow : function(){
				
	}, 
	clear : function(){
	
	}
}
function googleToBaidu(glng,glat) {
	
	var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	//alert(x_pi);
	
	var x = glng, y = glat;
	var z =Math.sqrt(x * x + y * y) + 0.00002 *Math.sin(y * x_pi);
	var theta =Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
	var lng = z *  Math.cos(theta) + 0.0065;
	var lat = z *  Math.sin(theta) + 0.006;
	var myLatlng = new BMap.Point(lng,lat);
	
	return myLatlng;
	
}
function getMarkerJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_getMarker.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 markerObject.markerJson=json;	
	         		 showMarkerBaidu(markerObject.markerJson);
	         		showMarkerGroupTree();
                 }else{
                 	alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}
function getAllMarkerGroupJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_getMarkerGroup.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 allMarkerGroupJson=json;		        	 					           				
                 }else{
                 	alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}
function deleteMarker(id){
		
		markerObject.closeInfowindow();
		
		if(window.confirm(language.sfscbz)){
			if(markerObject.markerArr[id].competence==1){
				$.ajax({
			        type: "POST",
			        dataType: "json",
			        async:false,
			        url: path+"json/markerAction_delMarker.action",
			        data: {"markerID":id},
			        success: function(json) {		         
				         if (json.flag==true) {
				              
				                  deleteMarkerGroupTreeNode(id);
				                  			
		                 }else{
		                 	alert(json.msg);
		                 }
			        },
			        error: function() {}
			   });	
			}else{
				alert(language.qxts);
			}
		}
}

function addMarker_Area(){
		$("#addMarkerButton").attr("disabled","disabled");
		var title,desc,icon,lat,lng,groupid,leftlat,leftlng,rigthlat,rigthlng,bzType,customerNum;
		title=$("#markertitle").val();
		desc=$("#markerdesc").val();
		if (isChrome) {
        	icon=$("#markerImagesrc").css("backgroundImage").split("(")[1].split(")")[0];
		}else{
			icon=$("#markerImagesrc").css("backgroundImage").split("\"")[1];
		}
		lat=$("#markerlat").val();
		lng=$("#markerlng").val();
		groupid=$("#markerGroupId").val();
		leftlat=$("#leftlat").val();
		leftlng=$("#leftlng").val();
		rigthlat=$("#rigthlat").val();
		rigthlng=$("#rigthlng").val();
		bzType=$('input[name="bzType"]:checked').val();
		customerNum=$("#customerNum").val();
		if(title.length==0){
			$("#addmarkermsg").text(language.btbnwk);
			$("#addmarkermsg").css("color","red");
			$("#addMarkerButton").removeAttr("disabled");
			return;
		}else{
			$("#addmarkermsg").css("color","rgb(153, 153, 153)");
		}
		if(desc.length>150){
			$("#addmarkermsg").text(language.msbndy150gz);
			$("#addmarkermsg").css("color","red");
			$("#addMarkerButton").removeAttr("disabled");
			return;
		}
		
		
		var getcustomerNums = getcustomerNum_vlaues();
		
		if( customerNum.length > 0 && ($.inArray(customerNum, getcustomerNums) < 0)){
		
			if(!window.confirm(language.yytwtjdkhh)){
			
				$("#addMarkerButton").removeAttr("disabled");
				
				return;
				
			}
			
		}
		
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_addOrUpdateUserMarker.action",
	        data:{"title":title,"text":desc,"icon":icon,"lat":lng,"lng":lat,"groupid":groupid,"leftLat":leftlat,"leftLon":leftlng,"rightLat":rigthlat,"rightLon":rigthlng,"radius":markersize,"bzType":bzType,"customerNum":getcustomerNums.join("/")},
	        success: function(json) {		         
		         if (json.flag==true) {
		         		 if(typeof json.data[0].id=="number" && typeof json.data[0].lat2=="number" && typeof json.data[0].lng2=="number" && json.data[0].icon.length!=0){
		 		
							 markerRefreshObject.addMarkerGroup(json.data[0].groupid);//若标注树上没有标注组自动添加标注组
							 
							 addMarkerGroupTreeNode(json.data[0].id,json.data[0].groupid,json.data[0].title);
 
						  	 var curnode=treeObj.getNodeByParam("id",json.data[0].id);
						  	
						  	 if(curnode != null){
						  	 	treeObj.checkNode(curnode, true, false, false);
						  	 }
							
							 if(selectImage!=null){
						   		 selectImage.attr("class","unselected");
						   		 selectImage=$("#selectImage");//用于保存当前选中的标记图标
				    			 selectImage.attr("class","selected");
			    			 }	 
					     }
					     
					     $("#closecmarkerWin").click();
					  	 $("#addMarkerButton").removeAttr("disabled");
                 }else{
                 	if(json.msg!="10001"){
	                 	$("#addmarkermsg").text(json.msg);
						$("#addmarkermsg").css("color","red");
					}else{
						$("#addmarkermsg").text(language.bzmbncf);
						$("#addmarkermsg").css("color","red");
					}$("#addMarkerButton").removeAttr("disabled");
                 }
	        },
	        error: function() {$("#addMarkerButton").removeAttr("disabled");}
	   });		   
}

function openUpdateMarkerWin(markerId){
	
	$("#updateMarkerButton").removeAttr("disabled");
	
	$("#updateMarkerButton").show();
	$("#addMarkerButton").hide();
	$("#timeform").show();
	var curMarkerObject=markerObject.markerArr[markerId];
	
	/*$("#addMarkerGroupSelect").hide();
	$("#markerGroupId").val(curMarkerObject.groupid);*/
	
	addMarkerGroupSelect();
	
	$("#addMarkerGroupSelect").show();
	
	$("#markerGroupId").val(curMarkerObject.groupid);
	
	$(".marker_group_option a").each(function(){
		
		if($(this).attr("name") == curMarkerObject.groupid ){
			$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text($(this).eq(0).text());
			$("#markerGroupId").val($(this).eq(0).attr("name"));
			return false;
		}
	});
	$("#markerName").text(language.xgbz); 		              
    
    if(curMarkerObject.marker && curMarkerObject.marker.getMap()){	              
	    $("#markerlat").val(curMarkerObject.marker.getPosition().lat());
	    $("#markerlng").val(curMarkerObject.marker.getPosition().lng());
    }else{
    	$("#markerlat").val(curMarkerObject.lat);
   		$("#markerlng").val(curMarkerObject.lng);
    }
    
    $("#markertitle").val(curMarkerObject.title);
	$("#markerdesc").val(curMarkerObject.text);
	$("#markerImagesrc").css("backgroundImage","url("+curMarkerObject.icon+")"); 
	$("#markerId").attr("value",markerId);
	$("#customerNum").val('');
	
	initCustomerNum_vlaue(curMarkerObject.customerNum.split("/"))
	
	$("#addmarkermsg").text(language.btbnwk);
    $("#addmarkermsg").css("color","rgb(153, 153, 153)");
    
    if(curMarkerObject.bzType==0){
   		$("#factoryselected").attr("checked","checked");
   	}else{
   		$("#siteselected").attr("checked","checked");
   	}
    
	markersize=curMarkerObject.areaRadius;
	
	if(curMarkerObject.area!=null){
		markerArea=curMarkerObject.area;
	}else{
		//markerArea=drawMarkerArea(new google.maps.LatLng(0,0),new google.maps.LatLng(0,0))
	}
	if( typeof curMarkerObject.areaRadius !="undefined"){
		$( "#markerArea" ).slider( "value", curMarkerObject.areaRadius);
	}else{
		$( "#markerArea" ).slider( "value", 0);
	}
	/*for(var i=0;i<markerGroupJson.totalcount;i++){
		if(markerGroupJson.data[i].id==curMarkerObject.groupid){
			$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text(markerGroupJson.data[i].groupName);
    		$("#markerGroupId").val(curMarkerObject.groupid);
			break;
		}
	}*/
	
	

    $("#markerContentWin").show();
    //$("#markerContentWin").center();
}

function updateMarker(){
		$("#updateMarkerButton").attr("disabled","disabled");//设置所有的button不可用 
		var id,title,desc,icon,lat,lng,groupid,leftlat,leftlng,rigthlat,rigthlng,bzType,customerNum;
		title=$("#markertitle").val();
		desc=$("#markerdesc").val();
		if (isChrome) {
        	icon=$("#markerImagesrc").css("backgroundImage").split("(")[1].split(")")[0];
		}else{
			icon=$("#markerImagesrc").css("backgroundImage").split("\"")[1];
		}
		lat=$("#markerlat").val();
		lng=$("#markerlng").val();
		groupid=$("#markerGroupId").val();
		id=parseInt($("#markerId").attr("value"));
		leftlat=$("#leftlat").val();
		leftlng=$("#leftlng").val();
		rigthlat=$("#rigthlat").val();
		rigthlng=$("#rigthlng").val();
		bzType=$('input[name="bzType"]:checked').val();
		customerNum=$("#customerNum").val();
		
		if(title.length==0){
			$("#addmarkermsg").text(language.btbnwk);
			$("#addmarkermsg").css("color","red");
			$("#updateMarkerButton").removeAttr("disabled");
			return;
		}else{
			$("#addmarkermsg").css("color","rgb(153, 153, 153)");
		}
		
		if(desc.length>150){
			$("#addmarkermsg").text(language.msbndy150gz);
			$("#addmarkermsg").css("color","red");
			$("#updateMarkerButton").removeAttr("disabled");
			return;
		}
		
		var getcustomerNums = getcustomerNum_vlaues();
		
		if( customerNum.length > 0 && ($.inArray(customerNum, getcustomerNums) < 0)){
			if(!window.confirm(language.yytwtjdkhh)){
				$("#updateMarkerButton").removeAttr("disabled");
				return;
			}
		}
		
		
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_addOrUpdateUserMarker.action",
	        data:{"id":id,"title":title,"text":desc,"icon":icon,"lat":lng,"lng":lat,"groupid":groupid,"leftLat":leftlat,"leftLon":leftlng,"rightLat":rigthlat,"rightLon":rigthlng,"radius":markersize,"bzType":bzType,"customerNum":getcustomerNums.join("/")},
	        success: function(json) {		         
		         if (json.flag==true) {
		         		 
						  	 var curnode=treeObj.getNodeByParam("id",json.data[0].id);
			  	 
						  	 if (curnode!=null) {
						  	 
								curnode.name = json.data[0].title;
								
								treeObj.updateNode(curnode);
								
								
								if(curnode.getParentNode().id != 'g_'+json.data[0].groupid){
								
									var prevParentNode = curnode.getParentNode();
									
									prevParentNode.count = parseInt(prevParentNode.count)-1 ;
									
									if(prevParentNode.count == 0){
										prevParentNode.name = prevParentNode.title;
									}else{
										prevParentNode.name = prevParentNode.title+"("+prevParentNode.count+")";
									}
									
									var curGroupnode=treeObj.getNodeByParam("id",'g_'+json.data[0].groupid);					
									
									if(curGroupnode == null){
									
										//添加标注所属组(若改组已经存在则不操作)
									  	 markerRefreshObject.addMarkerGroup(json.data[0].groupid);
									  	 
										 curGroupnode=treeObj.getNodeByParam("id",'g_'+json.data[0].groupid);
										 
									}
									
									curGroupnode.count = parseInt(curGroupnode.count)+1 ;

									curGroupnode.name = curGroupnode.title+"("+curGroupnode.count+")";
									
									treeObj.moveNode(curGroupnode, curnode, "inner");
									
									treeObj.updateNode(prevParentNode);
									treeObj.updateNode(curGroupnode);
								}	
							 }
					  	 
					  	 
					  	 if(selectImage!=null){
			   		 		selectImage.attr("class","unselected");
			   		 		selectImage=$("#selectImage");//用于保存当前选中的标记图标
	    			 		selectImage.attr("class","selected");
    			 		 }
    			 			
    			 		$("#closecmarkerWin").click(); 
    			 		$("#updateMarkerButton").removeAttr("disabled"); 			  	 
                 }else{
                 	if(json.msg!="10001"){
	                 	$("#addmarkermsg").text(json.msg);
						$("#addmarkermsg").css("color","red");
					}else{
						$("#addmarkermsg").text(language.bzmbncf);
						$("#addmarkermsg").css("color","red");
					}$("#updateMarkerButton").removeAttr("disabled");
                 }
	        },
	        error: function() {$("#updateMarkerButton").removeAttr("disabled");}
	   });	
}

function getGroupJson(){
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:false,
	        url: path+"json/markerAction_getUserMarkerGroup.action",
	        success: function(json) {		         
		         if (json.flag==true) {
	         		 markerGroupJson=json;		        	 					           				
                 }else{
                 	alert(json.msg);
                 }
	        },
	        error: function() {}
	   });	
}
function addAllMarker(){

	if(typeof baidMap=="undefined"){
		setTimeout('addAllMarker()',500);
		return;
	}
	if(markerObject.markerJson==""){
		setTimeout('addAllMarker()',500);
		return;
	}
	
	var marker,json=markerObject.markerJson;
	
	if(null!=json&&""!=json&&json.totalcount>0){
		for(var i=0;i<json.totalcount;i++){
			
			if(typeof json.data[i].id=="number" && typeof json.data[i].lat2=="number" && typeof json.data[i].lng2=="number" && json.data[i].icon.length!=0 &&json.data[i].lat2!=0&&json.data[i].lng2!=0){			
				 
				
		 		 markerObject.markerArr[json.data[i].id]={};
			  	 
			  	 markerObject.markerArr[json.data[i].id].competence=json.data[i].competence;		
			  	 markerObject.markerArr[json.data[i].id].title=json.data[i].title;
			  	 markerObject.markerArr[json.data[i].id].text=json.data[i].text;
			  	 markerObject.markerArr[json.data[i].id].icon=json.data[i].icon;
			  	 markerObject.markerArr[json.data[i].id].lat=json.data[i].lng2;
			  	 markerObject.markerArr[json.data[i].id].lng=json.data[i].lat2;
			  	 markerObject.markerArr[json.data[i].id].groupid=json.data[i].groupid;
			  	 markerObject.markerArr[json.data[i].id].id=json.data[i].id;
			  	 markerObject.markerArr[json.data[i].id].bzType=json.data[i].bzType;
			  	 
			  	 markerObject.markerArr[json.data[i].id].customerNum=json.data[i].markcode;
			  	 
			  	 marker=markerObject.addMarker(json.data[i].id,json.data[i].lng2,json.data[i].lat2,json.data[i].icon);
			  	 markerObject.markerArr[json.data[i].id].marker=marker;
			  	 
			  	 markerObject.markerArr[json.data[i].id].isShow=false;

		  	 }
		}

	}
}
var menu=null;
function addMarkerMenu(){
	
}

function addMarkerGroupSelect(){

    //获取标注组Json集
	 getGroupJson();
	 $(".marker_group_select_box").unbind("click")
    if(markerGroupJson==null){
		setTimeout("addMarkerGroupSelect()",500);
		return;
	}
	var optionStr="<a name=\"0\">--"+language.xzfz+"--</a>"; 
	for(var i=0;i<markerGroupJson.totalcount;i++){
		if(typeof markerGroupJson.data[i] !="undefined"){
			optionStr+="<a name=\""+markerGroupJson.data[i].id+"\">"+markerGroupJson.data[i].groupName+"</a>";
		}
	}
	optionStr+="<a name=\"-1\" style=\"color:rgb(153,153,153);\">"+language.tjbjz+"</a>";
	//document.getElementById("marker_group_option").innerHTML=optionStr;

	$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text($(".marker_group_option a").eq(0).text());
	$("#markerGroupId").val($(".marker_group_option a").eq(0).attr("name"));
	//添加标注组开始
	$(".marker_group_select_box").click(function(event){   
		event.stopPropagation();
		$(this).find(".marker_group_option").toggle();
		$(this).parent().siblings().find(".marker_group_option").hide();
	});
	$(document).click(function(event){
		var eo=$(event.target);
		if($(".marker_group_select_box").is(":visible") && eo.attr("class")!="marker_group_option" && !eo.parent(".marker_group_option").length)
		$('.marker_group_option').hide();									  
	});
	$(".marker_group_option a").click(function(){
		var value=$(this).attr("name");
		$(".marker_group_select_txt").text("");
		$("#markerGroupId").val("");
		if(value=="-1"){
		    $("#groupPanel").text(language.tjz);
		    $("#addMarkerGroup").show();
			$("#updateMarkerGroup").hide();
			$("#addMarkerGroup").removeAttr("disabled");
			$("#addGroupContentWin").css("z-index",$("#markerContentWin").css("z-index")+1);
			$("#addMarkerGroupmsg").css("color","rgb(153, 153, 153)");
			$("#markerGroupName").val("");
			$("#addGroupContentWin").show();
            $("#addGroupContentWin").center();
		}else{
			$(this).parent().siblings(".marker_group_select_txt").text($(this).text());
		    $("#markerGroupId").val(value);
		}
		
	 });
	 //添加标注组结束
	
}

function addMarkerGroup(){
        $("#addMarkerGroup").attr("disabled","disabled");
        var groupName=$("#markerGroupName").val();

        if(groupName==""||groupName==null){
        	$("#addMarkerGroupmsg").text(language.zmbnwk);
        	$("#addMarkerGroupmsg").css("color","red");
        	$("#addMarkerGroup").removeAttr("disabled");
        	return;
        }
        
		$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:false,
	        url: path+"json/markerAction_addOrUpdateUserMarkerGroup.action",
	        data:{"groupName":groupName},
	        success: function(json) {		         
		         if (json.flag==true) {		         				         		
		         
	         		    $(".marker_group_option a").parent().siblings(".marker_group_select_txt").text(json.data[0].groupName);
		    			$("#markerGroupId").val(json.data[0].id); 
		    			var newoption=$("<a name=\""+json.data[0].id+"\">"+json.data[0].groupName+"</a>");
		    			$(".marker_group_option a").eq($(this).size()-2).before(newoption);
		    			
		    			addMarkerGroupTreeGroupNode(json.data[0].id,json.data[0].groupName);
		    			newoption.click(function(){
							    var value=$(this).attr("name");
								$(this).parent().siblings(".marker_group_select_txt").text($(this).text());
							    $("#markerGroupId").val(value);				    							    
						});
						
						markerGroupJson.data.push(json.data[0]);
						allMarkerGroupJson.data.push(json.data[0]);
						 
		    			$("#closeGroupWin").click(); 
		    			$("#addMarkerGroup").removeAttr("disabled");	 					           				
                 }else{
                 	if(json.msg != "10000"){
	                 	$("#addMarkerGroupmsg").text(json.msg);
	        			$("#addMarkerGroupmsg").css("color","red");
        			}else{
        				$("#addMarkerGroupmsg").text(language.zmbncf);
	        			$("#addMarkerGroupmsg").css("color","red");
        			}$("#addMarkerGroup").removeAttr("disabled");
                 }
	        },
	        error: function() {$("#addMarkerGroup").removeAttr("disabled");}
	   });	
}

var selectImage=null;
function getImgURL(el){
	
	$("#markerImagesrc").css("backgroundImage","url("+$(el).attr("src")+")"); 
	
	$("#label-icon-list").hide();
	
	$("#markerImagesrc").attr("class","markerImagesrc");
	
	isopenMarkerselectWin=true;
	
 }

var isopenMarkerselectWin=true;

function openMarkerselectWin(){
	
	if(isopenMarkerselectWin){		
				
		$("#label-icon-list").show();
		
		$("#markerImagesrc").attr("class","markerImagesrc on");
		
		isopenMarkerselectWin=false;
		
		if($("#label-icon-list").children().length == 1){
		
			$("#MarkerImgloading").show();
			
			$.ajax({
		        type: "POST",
		        dataType: "html",
		        url: path+"gpsonline/jsp/cmonitor/marker_type.jsp",
		        success: function(html) {
		        		         
			        $("#label-icon-list").append(html);
			        $("#MarkerImgloading").hide();
			        
		        },
		        error: function() {}
	  		 });			
		}
	}else{	
		$("#label-icon-list").hide();
		$("#markerImagesrc").attr("class","markerImagesrc");
		isopenMarkerselectWin=true;		
	}
}

function closeVehicleInfoWindow(){
	for(var i=0;i<vehicles.length;i++){
          vehicles[i].infowindow.close();
    }
}


//单击时关闭标注和设备弹出框
function mapclickEvent(){

	
}

function closeMarkerPanel(){

		$("#biaozhu_close").show();
		$("#biaozhu_open").hide();
}
	
function openMarkerPanel(){

	$("#biaozhu_open").show();
	$("#biaozhu_close").hide();
}

var treeObj = null;

function showMarkerGroupTree(){
	if( markerObject.markerJson==""||allMarkerGroupJson==null){
		setTimeout("showMarkerGroupTree()",500);
		return;
	}
	if(allMarkerGroupJson.totalcount!=0){
		var groupNodeTreeStr="[";
		for(var i=0;i<allMarkerGroupJson.data.length;i++){
			//optionStr+="<a name=\""+markerGroupJson.data[i].id+"\">"+markerGroupJson.data[i].groupName+"</a>";
			if(typeof allMarkerGroupJson.data[i]!="undefined"){
				groupNodeTreeStr+="{ \"id\":\"g_"+allMarkerGroupJson.data[i].id+"\",\"title\":\""+allMarkerGroupJson.data[i].groupName+"\",\"name\":\""+allMarkerGroupJson.data[i].groupName+"\",\"icon\":\""+markerUrl.groupNodeicon+"\",\"count\":\"0\",\"pId\": \"0\",\"checked\":\"true\"},";
			}
		}
		groupNodeTreeStr=groupNodeTreeStr.substring(0,groupNodeTreeStr.length-1);
	    
	    groupNodeTreeStr="[{\"id\":\"root_g_-1000\",\"open\":\"true\",\"title\":\""+
	    						language.yhbz+"\",\"name\":\""+language.yhbz+"\",\"icon\":\""+electronicFenceUrl.allDom+"\",\"pId\": \"-1000\","+
								"\"children\":"+groupNodeTreeStr+"]}]";
								
	    groupNodeTreeStr=$.parseJSON(groupNodeTreeStr);
	    var setting={
	    		callback: {
					onClick: zTreeOnClick,
					onCheck: zTreeOnCheck
				},check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id"
					}
				},
				view: {
					addHoverDom: addHoverDom,
					removeHoverDom: removeHoverDom
				}		
	    }
		$.fn.zTree.init($("#markerGroupTree"),setting,groupNodeTreeStr);
		treeObj = $.fn.zTree.getZTreeObj("markerGroupTree");
		var parentNode,newNode;
		for(var i=0;i< markerObject.markerJson.data.length;i++){   
			addMarkerGroupTreeNode( markerObject.markerJson.data[i].id, markerObject.markerJson.data[i].groupid, markerObject.markerJson.data[i].title);
		}
		
		treeObj.checkNode(treeObj.getNodeByParam("id","root_g_-1000"), true, true);
		
	}
}

function addMarkerGroupTreeNode(id,parentId,title){
	    var newNode = [{'id':id,'name':title,"icon":markerUrl.markericon}];
		parentNode=treeObj.getNodeByParam("id","g_"+parentId);
		if(parentNode!=null){
			newNode=treeObj.addNodes(parentNode,newNode,true);
			
			parentNode.count=parseInt(parentNode.count)+1;
			parentNode.name =parentNode.title+"("+parentNode.count+")";
	        treeObj.updateNode(parentNode);			
		}else{
			parentNode=treeObj.getNodeByParam("id","g_0");
			newNode=treeObj.addNodes(parentNode,newNode,true);
			parentNode.count=parseInt(parentNode.count)+1;
			parentNode.name =parentNode.title+"("+parentNode.count+")";
	        treeObj.updateNode(parentNode);	
		}
		
		return newNode;
}
function addMarkerGroupTreeGroupNode(id,title){

		var newNode =null;
		if(treeObj==null){
			var setting={
	    		callback: {
					onClick: zTreeOnClick,
					onCheck: zTreeOnCheck
				},check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true,
						idKey: "id"
					}
				},
				view: {
					addHoverDom: addHoverDom,
					removeHoverDom: removeHoverDom
				}		
    		}
    		
		   $.fn.zTree.init($("#markerGroupTree"),setting,[{id:"root_g_-1000",open:true,title:language.yhbz,name:language.yhbz,icon:electronicFenceUrl.allDom,pId: -1000,
								children:[{ id:"g_"+id, pId: 0,title: title,count:0,name:title,icon:markerUrl.groupNodeicon}]}]);
		    treeObj = $.fn.zTree.getZTreeObj("markerGroupTree");
		    
		}else{
		
			newNode= [{id:"g_"+id, pId: 0,title: title,count:0,name:title,"icon":markerUrl.groupNodeicon}];
			var parentNode=treeObj.getNodeByParam("id","root_g_-1000");
			
			treeObj.addNodes(parentNode,newNode,true);
		}

		//addHoverDom("markerGroupTree", newNode);
		//removeHoverDom("markerGroupTree", newNode);
		
		
	    //treeObj.destroy();
		//showMarkerGroupTree();
}
function deleteMarkerGroupTreeNode(nodeid){
	var curnode=treeObj.getNodeByParam("id",nodeid);
	var parentNode=curnode.getParentNode();
    treeObj.removeNode(curnode);  
    parentNode.count=parseInt(parentNode.count)-1;
    if(parentNode.count==0){
    	parentNode.name =parentNode.title;
    }else{
		parentNode.name =parentNode.title+"("+parentNode.count+")";
    }
    treeObj.updateNode(parentNode);	
}

var showmarkersArr = new Array();
var title = "";
var mkid = 0;
var mklat = 0;
var mklng = 0;
function zTreeOnClick(event, treeId, treeNode) {
	if(!treeNode.isParent){
		treeObj.checkNode(treeNode, true, false, false);
		if(mapType==1 && baidMap!=undefined){
			updateMarkerIsShow(treeNode.id,true,false);
			showMarkersBaidu(treeNode.id,false);
			openMarkerBaidu(treeNode.id);
			title = treeNode.name;
			mkid = treeNode.id;
			for(i=0;i<bzMarkers.length;i++){
				if(bzMarkers[i].id==treeNode.id){
					mklat = bzMarkers[i].marker.getPosition().lat;
					mklng = bzMarkers[i].marker.getPosition().lng;
				}
			}
		}else{
			var curmarker=markerObject.markerArr[treeNode.id];
			
			if(curmarker!=null){
				curmarker.isShow=true;
		    }
			
			openMarker(treeNode.id);
		}
		
	}
	
}


function zTreeOnCheck(event, treeId, treeNode){

    if(mapType==2 && baidMap!=undefined){
		if(markerObject.infowindow!=null){
			markerObject.infowindow.close();
		}
	}
	
	var isParent = false;
	
	var nodesNoChecked = treeObj.getCheckedNodes(false);
	
	for(var i=0;i<nodesNoChecked.length;i++){
		isParent=nodesNoChecked[i].isParent;
		if(!isParent){
				if(mapType==1 && baidMap!=undefined){
					updateMarkerIsShow(nodesNoChecked[i].id,false,false);
					hideMarkersBaidu(nodesNoChecked[i].id,false);	
						
				}else{
					var curmarker=markerObject.markerArr[nodesNoChecked[i].id];
		   			if(curmarker!=null){
		   				curmarker.isShow=false;
		   				if(curmarker.marker != null){
		   					if(curmarker.marker.getMap() != null){
		   						curmarker.marker.setMap(null);
		   					}
		   				}
		   				
		   				if(curmarker.area != null){
		   					if(curmarker.area.getMap() != null){
		   						curmarker.area.setMap(null);
		   					}
		   				}
		   			}
	   			}
		}
	}
	
	
	var nodes = treeObj.getCheckedNodes(true);
	
	var curmarker=null;
	
	for(var i=0;i<nodes.length;i++){
		isParent=nodes[i].isParent;
		if(!isParent){
			if(mapType==1 && baidMap!=undefined){
					updateMarkerIsShow(nodes[i].id,true,false);
					showMarkersBaidu(nodes[i].id,false);	
						
				}else{
						curmarker=markerObject.markerArr[nodes[i].id];
			   			if(curmarker!=null){
			   				curmarker.isShow=true;
			   				if(curmarker.marker != null){
			   					if(curmarker.marker.getMap() == null){
			   						curmarker.marker.setMap(map);
			   					}
			   				}
			   				
			   				if(curmarker.area != null){
			   					if(curmarker.area.getMap() == null){
			   						curmarker.area.setMap(map);
			   					}
			   				}
			   			}
	   			}
		}
	}
	
	if($("#bzShowNamekbox").attr("checked")){
		hideMarkerName();
	}
	
	
}

function addHoverDom(treeId, treeNode) {
	if(treeNode!=null){
			if (treeNode.parentNode && treeNode.parentNode.id!=1) return;
			var aObj = $("#" + treeNode.tId + "_a");
			if ((treeNode.id+"").indexOf("_")>=0&&treeNode.id.split("_")[0]=="g"&&treeNode.id.split("_")[1]!="0") {
				for(var i=0;i<markerGroupJson.data.length;i++){
					if(typeof markerGroupJson.data[i]!="undefined"){
						if("g_"+markerGroupJson.data[i].id==treeNode.id){
							if ($("#diyBtn_space_"+treeNode.id).length>0) return;
							var editStr = "<span id='diyBtn_space_" +treeNode.id+ "' >&nbsp;</span><span class='button update' id='update_diyBtn_" +treeNode.id+ "' title='"+treeNode.name+"' onfocus='this.blur();'></span>";
							aObj.append(editStr);
							//var delbtn = $("#del_diyBtn_"+treeNode.id);
							var updatebtn = $("#update_diyBtn_"+treeNode.id);
							/*if (delbtn) delbtn.bind("click", function(){
								if(treeNode!=null){
									if(confirm(language.qryscz)){
										deleteMarkerGroup(treeNode.id);
									}
								}
							});*/
							if (typeof updatebtn !="undefined") 
								updatebtn.bind("click", function(){if(treeNode!=null){openupdateGroupWin(treeNode.id);}});
							break;
						}
					}
				}
			}
	}
}

function removeHoverDom(treeId, treeNode) {
		if(treeNode!=null){
			$("#del_diyBtn_"+treeNode.id).unbind().remove();
			$("#update_diyBtn_"+treeNode.id).unbind().remove();
			$("#diyBtn_space_" +treeNode.id).unbind().remove();
		}
}

function deleteMarkerGroup(id){
	
	if(treeObj!=null){
    	var curnode=treeObj.getNodeByParam("id",id);
    	//判断是否不存在
    	if(curnode!=null){
    		//判断是否有子节点
    		if(curnode.children==null || curnode.children.length==0){
    		
	 		       var groupid=parseInt(id.split("_")[1]);
	 		       
		 		   $.ajax({
				        type: "POST",
				        dataType: "json",
				        async:false,
				        url: path+"json/markerAction_delUserMarkerGroup.action",
				        data:{"groupid":groupid+""},
				        success: function(json) {		         
					         if (json.flag==true) {
				         		 //--删除组
				    			 treeObj.removeNode(curnode);
					 		     
					 		     //--删除json中的组allMarkerGroupJson，markerGroupJson					 		     
					 		     for(var i=0;i<allMarkerGroupJson.data.length;i++){
					 		     	
					 		     	 if(typeof allMarkerGroupJson.data[i]!="undefined" && allMarkerGroupJson.data[i].id==groupid){
					 		     	 	delete allMarkerGroupJson.data[i];
					 		     	 	break;
					 		     	 }
					 		     }
					 		     
					 		     for(var i=0;i<markerGroupJson.data.length;i++){
					 		     	 if( typeof markerGroupJson.data[i]!="undefined" && markerGroupJson.data[i].id==groupid){
					 		     	 	delete markerGroupJson.data[i];
					 		     	 	break;
					 		     	 }
					 		     }
					 		     
					 		     if($("#markerGroupId").attr("value")==groupid+""){
					 		     	$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text($(".marker_group_option a").eq(0).text());
									$("#markerGroupId").val($(".marker_group_option a").eq(0).attr("name"));
					 		     }				 		     
					 		     $("#addMarkerGroupSelect a[name='"+groupid+"']").remove(); 			           				
			                 }else{ 
			                      if( json.msg = "10002" ){
			                      	  alert(language.dqzxybzbnsc);
			                      }else{
			                      	  alert(json.msg);
			                      }
			                 }
				        },
				        error: function() {}
				   });	
	 		    
    		}else{
    			alert(language.dqzxybzbnsc);
    		}
    	}
	}
}

function openupdateGroupWin(id){
	$("#closeGroupWin").click();
	$("#updateMarkerGroup").removeAttr("disabled");
	for(var i=0;i<markerGroupJson.totalcount;i++){
     	 if( typeof markerGroupJson.data[i]!="undefined" && "g_"+markerGroupJson.data[i].id==id){
     	 	 $("#markerGroupName").val(markerGroupJson.data[i].groupName);
     	 	 $("#markerGroupId").val(markerGroupJson.data[i].id);
			break;
     	 }
    }
    $("#groupPanel").text(language.xgz);
    
    $("#updateMarkerGroup").show();
	$("#addMarkerGroup").hide();
	
    $("#addGroupContentWin").css("z-index",$("#markerContentWin").css("z-index")+1);
	$("#addMarkerGroupmsg").css("color","rgb(153, 153, 153)");
	$("#addGroupContentWin").show();
	$("#addGroupContentWin").center();
	
     
}

function updateMarkerGroup(){
$("#updateMarkerGroup").attr("disabled","disabled");
	var groupName=$("#markerGroupName").val();

    if(groupName==""||groupName==null){
    	$("#addMarkerGroupmsg").text(language.zmbnwk);
    	$("#addMarkerGroupmsg").css("color","red");
    	$("#updateMarkerGroup").removeAttr("disabled");
    	return;
    }
	
	var id=$("#markerGroupId").val();
	      
	$.ajax({
	       type: "POST",
	       dataType: "json",
	       async:false,
	       url: path+"json/markerAction_addOrUpdateUserMarkerGroup.action",
	       data:{"groupid":id,"groupName":groupName},
	       success: function(json) {		         
	         	if(json.flag==true){
	         		 if(json.data!=null&&json.data.length>0){
	         		 	
	         		 	var curnode=treeObj.getNodeByParam("id","g_"+id);
	         		 	
	         		 	if(curnode!=null){
	         		 		curnode.title=json.data[0].groupName;	         		 		
	         		 		if(curnode.count!=0){
	         		 			curnode.name =curnode.title+"("+curnode.count+")";
	         		 		}else{
	         		 			curnode.name =curnode.title;
	         		 		}
	         		 		treeObj.updateNode(curnode);
	         		 	}
	         		 	
		         		for(var i=0;i<allMarkerGroupJson.data.length;i++){
		 		     	
			 		     	 if(typeof allMarkerGroupJson.data[i]!="undefined" && allMarkerGroupJson.data[i].id==parseInt(id)){
			 		     	 	 allMarkerGroupJson.data[i].groupName=json.data[0].groupName;
			 		     	 	 break;
			 		     	 }
			 		     }
			 		     
			 		     for(var i=0;i<markerGroupJson.data.length;i++){
			 		     	 if( typeof markerGroupJson.data[i]!="undefined" && markerGroupJson.data[i].id==parseInt(id)){
			 		     	 	markerGroupJson.data[i].groupName=json.data[0].groupName;
			 		     	 	break;
			 		     	 }
			 		     }
			 		     
			 		     if($("#markerGroupId").attr("value")==id){
			 		     	$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text(json.data[0].groupName);
							$("#markerGroupId").val(json.data[0].id);
			 		     }
			 		     
			 		     $("#addMarkerGroupSelect a[name='"+id+"']").text(json.data[0].groupName);
	         		}
	         		$("#closeGroupWin").click(); 
	         		$("#updateMarkerGroup").removeAttr("disabled");
	         	}else{
	         		if(json.msg != "10000"){
	                 	$("#addMarkerGroupmsg").text(json.msg);
	        			$("#addMarkerGroupmsg").css("color","red");
        			}else{
        				$("#addMarkerGroupmsg").text(language.zmbncf);
	        			$("#addMarkerGroupmsg").css("color","red");
        			}$("#updateMarkerGroup").removeAttr("disabled");
	         	}
	       },
	       error: function() {$("#updateMarkerGroup").removeAttr("disabled");}
	  });	
}


function openMarker(_id){
	if(markerObject.infowindow!=null){
		markerObject.infowindow.close();
	}
	var curmarker=markerObject.markerArr[_id];
    if(curmarker!=null){
	    map.setCenter(new google.maps.LatLng(curmarker.lat,curmarker.lng));
		map.setZoom(13);
		
		for(var i=0;i<markerObject.markerids.length;i++){
			if(markerObject.markerArr[markerObject.markerids[i]].marker != null && markerObject.markerArr[markerObject.markerids[i]].isShow){
				if(markerObject.markerArr[markerObject.markerids[i]].marker.getMap() == null){
					markerObject.markerArr[markerObject.markerids[i]].marker.setMap(map);
				}
			}
			if(markerObject.markerArr[markerObject.markerids[i]].area != null && markerObject.markerArr[markerObject.markerids[i]].isShow){
				if(markerObject.markerArr[markerObject.markerids[i]].area.getMap() == null){
					markerObject.markerArr[markerObject.markerids[i]].area.setMap(map);
				}
			}
			
			if(!markerObject.markerArr[markerObject.markerids[i]].isShow && markerObject.markerArr[markerObject.markerids[i]].marker != null){
				if(markerObject.markerArr[markerObject.markerids[i]].marker.getMap() != null){
					markerObject.markerArr[markerObject.markerids[i]].marker.setMap(null);
				}
			}
			
			if(!markerObject.markerArr[markerObject.markerids[i]].isShow && markerObject.markerArr[markerObject.markerids[i]].area != null){
				if(!markerObject.markerArr[markerObject.markerids[i]].area.getMap() != null){
					markerObject.markerArr[markerObject.markerids[i]].area.setMap(null);
				}
			}
		}
		
		if($("#bzShowNamekbox").attr("checked")){
			hideMarkerName();
		}
		
		if(curmarker.marker!=null){
			curmarker.marker.setMap(map);
			google.maps.event.trigger(curmarker.marker, 'click');
		}
		
		if(curmarker.area!=null){
			curmarker.area.setMap(map);
		}
    }
}


function showMarkerName(element){
		
		if($(element).attr("checked")){
			
			for(var j=0;j<bzMarkers.length;j++){
	      		if(bzMarkers[j].label != null){
	      			if(bzMarkers[j].isShow){
	      				baidMap.addOverlay(bzMarkers[j].label);
	      			}
	      		}
		  	}
		}else{
			for(var j=0;j<bzMarkers.length;j++){
	      		if(bzMarkers[j].label != null){
	      			baidMap.removeOverlay(bzMarkers[j].label);
	      		}
		  	}
		}
	
	
}

function hideMarkerName(){
	for(var i=0;i<markerObject.markerids.length;i++){
		if(markerObject.markertitlearr[i]!=null){
			markerObject.markertitlearr[i].setMap(null);
			markerObject.markertitlearr[i]=null;
		}
	}
	markerObject.markertitlearr=new Array();
	
	if($("#bzShowNamekbox").attr("checked")){
		for(var i=0;i<markerObject.markerids.length;i++){
			if(markerObject.markerArr[markerObject.markerids[i]] != null && markerObject.markerArr[markerObject.markerids[i]].isShow && markerObject.markerArr[markerObject.markerids[i]].marker != null){
				markerObject.markertitlearr.push(new myLableMarker(map,"<div class=\"iconTheStyle\" style=\"background:#f5fcb8;  font-size:12px; color:#000000; font-weight:bold; white-space:nowrap; border:1px solid #666666;\" >"+markerObject.markerArr[markerObject.markerids[i]].title+"</div>",markerObject.markerArr[markerObject.markerids[i]].marker.getPosition(),markerObject.markerids[i]));
			}
		
		}
				
	}

}


function frame(framecontentId,framemovetitleId,closebuttonId){
		$("#"+closebuttonId).click(function(event){
			stopBubble(event);
		   $("#"+framecontentId).fadeOut("fast");
		   if(closebuttonId=="closeGroupWin"){
		   		 var groupName=$(".marker_group_option a").parent().siblings(".marker_group_select_txt");
		   		 var groupId=$("#markerGroupId");
		   		 if(groupName.text()==""&&groupId.val()==""){
		   		 	 groupName.text($(".marker_group_option a").eq(0).text());
		    	     groupId.val($(".marker_group_option a").eq(0).attr("name"));
		   		 }
		   		 
		   		  $("#addMarkerGroupmsg").css("color","rgb(153, 153, 153)");
		   		  $("#addMarkerGroupmsg").text(language.zmbnwk);
		   		   		
		   }                 
		   if(closebuttonId=="closecmarkerWin"){
		   		 if(selectImage!=null){
			   		 selectImage.attr("class","unselected");
			   		 selectImage=$("#selectImage");//用于保存当前选中的标记图标
	    			 selectImage.attr("class","selected");   			 
    			 }	

    			 $("#factoryselected").attr("checked","checked");
    			  
    			  isopenMarkerselectWin=false;
    			  openMarkerselectWin();
    			  isopenMarkerselectWin=true;
    			  
    			  var curMarkerObject=markerObject.markerArr[$("#markerId").val()];
    			  if(typeof curMarkerObject !="undefined" && curMarkerObject!=null &&markerArea!=null){
						if( typeof curMarkerObject.areaRadius !="undefined" && curMarkerObject.areaRadius!=null){
							$( "#markerArea" ).slider( "value", curMarkerObject.areaRadius);
							curMarkerObject.area=markerArea;
							curMarkerObject.area.setMap(map);
						}
				  }
	
				  
				 if($("#markerId").val().length!=0&&markerArea!=null){
	    			 	//markerArea.setMap(null); //删除未添加标注绘制的默认区域
	    			 	markerArea=null;
	    			    clearAreaLagLng();    			   
    			 }else{
    			 		if(markerArea!=null){
	    			 		markerArea.setMap(null); //删除未添加标注绘制的默认区域
		    			 	markerArea=null;
	    			 	}
	    			    clearAreaLagLng(); 
    			 }$("#markerId").val("");
    			$("#customerNum").val("");
    			 
    			 $("#customerNumListOutCanvas").html("");
    			 $("#addcustomerNum_Msg").html("&nbsp;");
		   }
		   if(closebuttonId=="closePasswordWin"){
		   		$("#updatePasswordMsg").css("color","rgb(153, 153, 153)");
		        $("#updatePasswordMsg").text(language.mmbnwk);
		        $("#curPassword").val("");
				$("#newPassword").val("");
				$("#renewPassword").val("");
		   }	   
		});
		$("#"+framemovetitleId).mousedown(function(dom){
					     var top1=$("#"+framecontentId).css("top");
						 var left1=$("#"+framecontentId).css("left");
						 var x=dom.clientX;
						 var y=dom.clientY;
						 var x1=Math.abs(x-parseInt(left1));
						 var y1=Math.abs(y-parseInt(top1));
						 $("body").mousemove(function(dom){
						 	  var x=dom.clientX;
						      var y=dom.clientY;  
						      $("#"+framecontentId).css({"top":y-y1,"left":x-x1});
						 	});
					}).mouseup(function(){
					    $("body").unbind("mousemove"); 	
					});
	}
/*
 *区域
 */
 var markerArea=null;
 var markersize=500;
 function loadAreaSlider(){
  $( "#markerArea" ).slider({
				range : "min",
				max : 5000,
				min : 50,
				value : 500,
				orientation : 'horizontal'
		  });
  $("#markerArea").bind('slidechange', function(event, ui) {
			/*var r=ui.value;
			var t=4;
			var w=100;
			var p=[500,800,1200,1500,2000,3000,5000];//[5000,3000,2000,1000,1500,800,500]
			var u=[0,20,40,60,80,100,120,140];
			for(var s=0,o=u.length-1;s<o;s++){
				if(r>=u[s]&&r<u[s+1]){
					t=s;
					break
				}
				if(r>=140){
					t=6;
					break
				}
			}*/
			markersize=ui.value;
			updateMarkerArea(ui.value,markerArea);
		});
 }

function drawMarkerArea(lefttoplatlng_,rigthbelowlatlng_){
			return rectangle = new google.maps.Rectangle({
				strokeColor: '#0000FF',
				strokeOpacity: 0.8,
				strokeWeight: 2,
				fillColor: '#0000cc',
				fillOpacity: 0.35,
				zIndex:0,
				map: map,
				bounds: new google.maps.LatLngBounds(
				  lefttoplatlng_,
				  rigthbelowlatlng_)
				});  
}

function updateMarkerArea(len_,markerArea_){
	$("#markersize").text(len_+"m");
	markerArea_.setBounds(new google.maps.LatLngBounds(getAreaSWLatlng(parseFloat($("#markerlat").val()),parseFloat($("#markerlng").val()),len_),getAreaNELatLng(parseFloat($("#markerlat").val()),parseFloat($("#markerlng").val()),len_)));
}

function getAreaNELatLng(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#rigthlat").val(lat_-dlat);
	$("#rigthlng").val(lng_+dlng);
	return new google.maps.LatLng(lat_-dlat,lng_+dlng);
}
function getAreaSWLatlng(lat_,lng_,len_){
	var dlat = len_/111.0/1000.0;
	var dlng = len_/85.567/1000.0;
	$("#leftlat").val(lat_+dlat);
	$("#leftlng").val(lng_-dlng);
	return new google.maps.LatLng(lat_+dlat,lng_-dlng);
}
function clearAreaLagLng(){
	$("#leftlat").val("");
	$("#leftlng").val("");
	$("#rigthlat").val("");
	$("#rigthlng").val("");
	markersize=500;
}
/*
 *tool
 */
	function showtoolPanel(){
	 	$("#tools_box").show();
	}
	function hidetoolPanel(){
		$("#tools_box").hide();
	}
	
Array.prototype.remove=function(dx){
　　if(isNaN(dx)||dx>this.length){return false;}
　　for(var i=0,n=0;i<this.length;i++){
　　　　if(this[i]!=this[dx]){
　　　　　　this[n++]=this[i]
　　　　}
　　}
　　this.length-=1
}
function initMarkerisShow(){
	if(mapType=="1" && baidMap!=undefined){
		var isParent = false;
		
		var nodesNoChecked = treeObj.getCheckedNodes(false);
		
		for(var i=0;i<nodesNoChecked.length;i++){
			isParent=nodesNoChecked[i].isParent;
			if(!isParent){			
					updateMarkerIsShow(nodesNoChecked[i].id,false,false);
					hideMarkersBaidu(nodesNoChecked[i].id,false);
			}
		}
		
		
		var nodes = treeObj.getCheckedNodes(true);
		
		var curmarker=null;
		
		for(var i=0;i<nodes.length;i++){
			isParent=nodes[i].isParent;
			if(!isParent){
					updateMarkerIsShow(nodes[i].id,true,false);
					showMarkersBaidu(nodes[i].id,false);
			}
		}
	}else{
		zTreeOnCheck(null,null,null);
	}
}

function markerRefresh(id,groupId,eventName,isMarker){//alert("id="+id+",groupId="+groupId+",eventName="+eventName+",isMarker="+isMarker);
					switch(eventName){
						case "add" :    
										if(isMarker){
											markerRefreshObject.addMarker(id);
										}else{
											markerRefreshObject.addMarkerGroup(id);
										}
										
										break;
										
						case "delete" : 
										if(isMarker){
											markerRefreshObject.delMarker(id);
										}else{
											markerRefreshObject.delMarkerGroup(id);
										}
										
										break;
										
						case "update" : 
										if(isMarker){
											markerRefreshObject.updateMarker(id);
										}else{
											markerRefreshObject.updateMarkerGroup(id);
										}
										
										break;
					}
}

var markerRefreshObject = {
	refresh : function (id,groupId,eventName,isMarker){//alert("id="+id+",groupId="+groupId+",eventName="+eventName+",isMarker="+isMarker);
					switch(eventName){
						case "add" :    
										if(isMarker){
											markerRefreshObject.addMarker(id);
										}else{
											markerRefreshObject.addMarkerGroup(id);
										}
										
										break;
										
						case "delete" : 
										if(isMarker){
											markerRefreshObject.delMarker(id);
										}else{
											markerRefreshObject.delMarkerGroup(id);
										}
										
										break;
										
						case "update" : 
										if(isMarker){
											markerRefreshObject.updateMarker(id);
										}else{
											markerRefreshObject.updateMarkerGroup(id);
										}
										
										break;
					}
	},
	addMarker : function(id){
	    if(treeObj!=null && treeObj.getNodeByParam("id",id) == null){
				$.ajax({
			        type: "POST",
			        dataType: "json",
			        async:false,
			        url: path+"json/markerAction_getMarker.action",
			        data:{"id":id},
			        success: function(json) {		         
				         if (json.flag==true) {
				    			 if(typeof json.data[0].id=="number" && typeof json.data[0].lat2=="number" && typeof json.data[0].lng2=="number" && json.data[0].icon.length!=0){
			         		 
						         		
							 			
									  	 //添加标注所属组(若改组已经存在则不操作)
									  	 markerRefreshObject.addMarkerGroup(json.data[0].groupid);
									  	 
										 addMarkerGroupTreeNode(json.data[0].id,json.data[0].groupid,json.data[0].title);
										 
										 
									 
				    	        }
						    		  	 
		                 }
			        }
			   });	
		   }
	},
	delMarker : function(id){
							      if(treeObj!=null && treeObj.getNodeByParam("id",id) != null){
							      
					        	 	  markerObject.deleteMarker(id);
					        	 	  
					                  deleteMarkerGroupTreeNode(id);
					                  
					                  for(var i=0;i<markerObject.markerids.length;i++){
											if(id==markerObject.markerids[i]){
												markerObject.markerids.remove(i);
											}
											break;
									  }
									  
					                  for(var i=0;i<markerObject.markerJson.data.length;i++){
					                	  if(id==markerObject.markerJson.data[i].id){
												markerObject.markerJson.data.remove(i);
												break;
										  }
					                	  
					                  }
					                  
					                  markerObject.markerJson.totalcount = markerObject.markerJson.data.length;
				                  }
				                  
	},
	updateMarker : function(id){
		if(treeObj!=null && treeObj.getNodeByParam("id",id) != null){
			$.ajax({
		        type: "POST",
		        dataType: "json",
		        async:false,
		        url:path+ "json/markerAction_getMarker.action",
		        data:{"id":id},
		        success: function(json) {		         

		        }
		   });
	   }
	},
	addMarkerGroup : function(id){
						//查看标注所属组存不存在
	         		 	//不存在查找添加组
	         		 	//存在添加标注
	         		 	if(id != 0 && treeObj != null){
					    	var curnode=treeObj.getNodeByParam("id","g_"+id);
					    	//判断是否不存在
					    	if(curnode==null){
					    	   //查找组
					    	   $.ajax({
								        type: "POST",
								        dataType: "json",
								        async:false,
								        url: path+"json/markerAction_getUserMarkerGroup.action",
								        data:{"groupid":id},
								        success: function(json) {		         
									         if (json.flag==true) {
									    			
									    			//**************
									    			if(parseInt($("#userId").val()) ==json.data[0].creater ){//判断是否是该用户的组
									    				
									    				if($("#addMarkerGroupSelect a[name='"+id+"']").length<=0){
										    				var newoption=$("<a name=\""+json.data[0].id+"\">"+json.data[0].groupName+"</a>");
										    			
										    				$(".marker_group_option a").eq($(this).size()-2).before(newoption);
										    				
										    				newoption.click(function(){
										    				
															    var value=$(this).attr("name");
																$(this).parent().siblings(".marker_group_select_txt").text($(this).text());
															    $("#markerGroupId").val(value);	
															    			    							    
															});
															markerGroupJson.data.push(json.data[0]);
														}			
									    			}else{									    			    				
									    				allMarkerGroupJson.data.push(json.data[0]);									    				
									    			}
									    			addMarkerGroupTreeGroupNode(json.data[0].id,json.data[0].groupName);			    						 
									         }
									    }
									  });		    	  	
					    	}
					    }
	},
	delMarkerGroup : function(id){
							if(treeObj!=null){
						    	var curnode=treeObj.getNodeByParam("id","g_"+id);
						    	//判断是否不存在
						    	if(curnode!=null){
						    		//判断是否有子节点
						    		if(curnode.children==null || curnode.children.length==0){
						    		
							 		         var groupid=parseInt(id.split("_")[1]);
							 		      
							         		 //--删除组
							    			 treeObj.removeNode(curnode);
								 		     
								 		     //--删除json中的组allMarkerGroupJson，markerGroupJson					 		     
								 		     for(var i=0;i<allMarkerGroupJson.data.length;i++){
								 		     	
								 		     	 if(typeof allMarkerGroupJson.data[i]!="undefined" && allMarkerGroupJson.data[i].id==groupid){
								 		     	 	delete allMarkerGroupJson.data[i];
								 		     	 	break;
								 		     	 }
								 		     }
								 		     
								 		     for(var i=0;i<markerGroupJson.data.length;i++){
								 		     	 if( typeof markerGroupJson.data[i]!="undefined" && markerGroupJson.data[i].id==groupid){
								 		     	 	delete markerGroupJson.data[i];
								 		     	 	break;
								 		     	 }
								 		     }
								 		     
								 		     if($("#markerGroupId").attr("value")==groupid+""){
								 		     	$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text($(".marker_group_option a").eq(0).text());
												$("#markerGroupId").val($(".marker_group_option a").eq(0).attr("name"));
								 		     }
								 		     			 		     
								 		     $("#addMarkerGroupSelect a[name='"+groupid+"']").remove();
								 		      			           										           					 		    
						    		}else{
						    			alert(language.dqzxybzbnsc);
						    		}
						    	}
							}			    
	},
	updateMarkerGroup : function(id){
		$.ajax({
	       type: "POST",
	       dataType: "json",
	       async:false,
	       url: path+"json/markerAction_getUserMarkerGroup.action",
	       data:{"groupid":id},
	       success: function(json) {		         
	         	if(json.flag==true){
	         		 if(json.data!=null&&json.data.length>0){
	         		 	
	         		 	var curnode=treeObj.getNodeByParam("id","g_"+id);
	         		 	
	         		 	if(curnode!=null){
	         		 		curnode.title=json.data[0].groupName;	         		 		
	         		 		if(curnode.count!=0){
	         		 			curnode.name =curnode.title+"("+curnode.count+")";
	         		 		}else{
	         		 			curnode.name =curnode.title;
	         		 		}
	         		 		treeObj.updateNode(curnode);
	         		 	}
	         		 	
		         		for(var i=0;i<allMarkerGroupJson.data.length;i++){
		 		     	
			 		     	 if(typeof allMarkerGroupJson.data[i]!="undefined" && allMarkerGroupJson.data[i].id==parseInt(id)){
			 		     	 	 allMarkerGroupJson.data[i]=json.data[0];
			 		     	 	 break;
			 		     	 }
			 		     }
			 		     
			 		     for(var i=0;i<markerGroupJson.data.length;i++){
			 		     	 if( typeof markerGroupJson.data[i]!="undefined" && markerGroupJson.data[i].id==parseInt(id)){
			 		     	 	markerGroupJson.data[i]=json.data[0];
			 		     	 	break;
			 		     	 }
			 		     }
			 		     
			 		     if($("#markerGroupId").attr("value")==id){
			 		     	$("#marker_group_option a").parent().siblings(".marker_group_select_txt").text(json.data[0].groupName);
			 		     }
			 		     
			 		     $("#addMarkerGroupSelect a[name='"+id+"']").text(json.data[0].groupName);
			 		     
	         		}
	         		
	         	}
	       },
	       error: function() {}
	  });
	}
}

function updateMarkerPosition(_id){
	
	var _marker = markerObject.markerArr[_id];
	
	
	$.ajax({
	        type: "POST",
	        dataType: "json",
	        async:true,
	        url: path+"json/markerAction_addOrUpdateUserMarker.action",
	        data:{"id":_id,"lng":ceneterLatlng.lat(),"lat":ceneterLatlng.lng(),"leftLat":LatLngBounds.getSouthWest().lat(),"leftLon":LatLngBounds.getSouthWest().lng(),"rightLat":LatLngBounds.getNorthEast().lat(),"rightLon":LatLngBounds.getNorthEast().lng(),"title":_marker.title,"text":_marker.desc,"icon":_marker.icon,"groupid":_marker.groupid,"radius":_marker.markersize,"bzType":_marker.bzType},	        
	        success: function(json) {		         
		         if (json.flag==true) {
		         
		         	 //markerObject.infowindow.close();
		         	
			  		_marker.lat=json.data[0].lng2;
			  		_marker.lng=json.data[0].lat2;

				  	_marker.areaRadius=json.data[0].userMarkerArea.markerRadius;
         	
		      		$("#moveMarkerBtn").hide();
		      		
                 }else{
                 	$("#updatePositionMsg").val("*"+json.msg);
                 }
	        },
	        error: function() {}
	   });	
	
	
}

var LatLngBounds = null;
var ceneterLatlng = null;

var curmarkerNameLabe = null;



function addEvent(){
	
	var isOpencustomerNumListOutCanvas = false;
	var customerNumBlurEvent = null;
	var customerNumTimeoutEvent = null;
	var isOnAddCustomerNum = false;
	
	$("#customerNum").focus(function(){
	
		/*if(!isOpencustomerNumListOutCanvas){
		
			$("#customerNumListOutCanvas").show();
			
			isOpencustomerNumListOutCanvas = true;
			
		}else{*/
		
			$("#customerNumListOutCanvas").show();
			
			isOpencustomerNumListOutCanvas = true;
		
	});
	
	$("#customerNum").blur(function(){
	
		clearTimeout(customerNumBlurEvent);
	
		customerNumBlurEvent = setTimeout(function(){
		
							if(!isOnAddCustomerNum){
							
								isOpencustomerNumListOutCanvas = false;
								
							}
							
							clearTimeout(customerNumTimeoutEvent);
							
							customerNumTimeoutEvent = setTimeout(function(){
									
									if(!isOpencustomerNumListOutCanvas){
									
										$("#customerNumListOutCanvas").hide();
										
										isOpencustomerNumListOutCanvas = false;
										
										
										if($("#customerNum").val().lenght == 0){
											$("#addcustomerNum_Msg").html("&nbsp;");
										}
										
									}
									
								},100);
							
						},100);
	});	
	
	$("#customerNum").mouseover(function(){
	
		if($("#customerNumListOutCanvas").is(":visible")){
		
			isOpencustomerNumListOutCanvas = true;
			
		}
		
		
		
	});
	
	$("#customerNum").mouseleave(function(){
		
		isOpencustomerNumListOutCanvas = false;
		
		clearTimeout(customerNumTimeoutEvent);
		
		customerNumTimeoutEvent = setTimeout(function(){
				
				if(!isOpencustomerNumListOutCanvas){
				
					$("#customerNumListOutCanvas").hide();
					
					isOpencustomerNumListOutCanvas = false;
					
					$("#customerNum").blur();
					
					
					if($("#customerNum").val().lenght == 0){
						$("#addcustomerNum_Msg").html("&nbsp;");
					}

				}
				
			},100);
	});	
	
	
	$("#customerNumListOutCanvas").mouseover(function(){
	
		isOpencustomerNumListOutCanvas = true;
		
	});
	
	$("#customerNumListOutCanvas").click(function(){
	
		isOpencustomerNumListOutCanvas = true;
		
	});
	
	
	$("#addcustomerNum").mouseover(function(){
	
		isOnAddCustomerNum = true;
		
		if($("#customerNumListOutCanvas").is(":visible")){
		
			isOpencustomerNumListOutCanvas = true;
			
		}
		
	});
	
	$("#addcustomerNum").mouseleave(function(){
	
		isOnAddCustomerNum = false;

		isOpencustomerNumListOutCanvas = false;
		
		clearTimeout(customerNumTimeoutEvent);
		
		customerNumTimeoutEvent = setTimeout(function(){
				
				if(!isOpencustomerNumListOutCanvas){
				
					$("#customerNumListOutCanvas").hide();
					
					isOpencustomerNumListOutCanvas = false;
					
					$("#customerNum").blur();
					
					
					if($("#customerNum").val().lenght == 0){
						$("#addcustomerNum_Msg").html("&nbsp;");
					}

				}
				
			},100);

		
	});
	
	$("#addcustomerNum").click(function(){
		 
		 isOnAddCustomerNum = true;
		
		if($("#customerNumListOutCanvas").is(":visible")){
		
			isOpencustomerNumListOutCanvas = true;
			
		}
		
		var value = $("#customerNum").val();
		
		var customerNum_vlaueList = getcustomerNum_vlaues();
		
		$("#addcustomerNum_Msg").html("&nbsp;");
		
		if(value.length !=0 && ($.inArray(value, customerNum_vlaueList) < 0)){
						
				$("#customerNumListOutCanvas").prepend("<div class='search_item' onmouseover='over(this)' onmouseout='out(this)'><span name='customerNum_vlaue' style='white-space:nowrap;display:inline-block;width:100px; overflow:hidden;text-overflow: ellipsis;' >"+value+"</span><span style='float:right;margin-right:5px;margin-top:2px;*margin-right:0px;*margin-top:-12px;display:inline-block;'><a href='javascript:;' onclick='deleteCustomerNumItem(this);'><img style='display:inline-block;' src='gpsonline/image/marker/ico_dele.png'></img></a></span></div>");
				
				$("#customerNum").val("");
				
		}else if(($.inArray(value, customerNum_vlaueList) >= 0)){
		
				$("#addcustomerNum_Msg").text(electronicFenceLanguage.ycz);
				
		}
		
		
				
	});
	
	
	
	
	$("#customerNumListOutCanvas").mouseleave(function(){
		
		isOpencustomerNumListOutCanvas = false;
		
		clearTimeout(customerNumTimeoutEvent);
		
		customerNumTimeoutEvent = setTimeout(function(){
				
				if(!isOpencustomerNumListOutCanvas){
				
					$("#customerNumListOutCanvas").hide();
					
					isOpencustomerNumListOutCanvas = false;
					
					$("#customerNum").blur();
					
					if($("#customerNum").val().lenght == 0){
						$("#addcustomerNum_Msg").html("&nbsp;");
					}
					
				}
				
			},100);
	});	
	
	
}

function getcustomerNum_vlaues(){
	var customerNum_vlaueList = [];
		
		$("span[name='customerNum_vlaue']").each(function(){
		
			customerNum_vlaueList.push($(this).text());
			
		});
		
	return 	customerNum_vlaueList;
}

function initCustomerNum_vlaue(valuesArr){

	$("#customerNumListOutCanvas").html("");
	
	for(var i=0;i<valuesArr.length;i++){
		
		if(valuesArr[i].length != 0){
			
			$("#customerNumListOutCanvas").append("<div class='search_item' onmouseover='over(this)' onmouseout='out(this)'><span name='customerNum_vlaue' style='white-space:nowrap;display:inline-block;width:100px; overflow:hidden;text-overflow: ellipsis;' >"+valuesArr[i]+"</span><span style='float:right;margin-right:5px;margin-top:2px;*margin-right:0px;*margin-top:-12px;display:inline-block;'><a href='javascript:;' onclick='deleteCustomerNumItem(this);'><img style='display:inline-block;' src='gpsonline/image/marker/ico_dele.png'></img></a></span></div>");
		
		}
	}
}

function over(el) {
	
						$(el).attr("class","customerNum_item_over");
						
				  }
					
function out(el) {
	
						$(el).attr("class","search_item");
						
				 }				 
			 
function deleteCustomerNumItem(el){
	
	$(el).parent().parent().remove();

}

function initparms(){

	usertype = $("#usertypeId").val();
 	path =$("#serverPath").text(); 

	Url={
		distanceclose : path+"gpsonline/image/tool/close.gif",
		distancestart : path+"gpsonline/image/tool/dd-start.png",
		distanceend : path+"gpsonline/image/tool/mm_20_red.png",
		queryLoading : path+"gpsonline/image/monitor/guanli/recoderdeleting.gif"
	}
	
	markerUrl={
		groupNodeicon : path+"gpsonline/image/marker/organisation.png",
		markericon : path+"gpsonline/image/marker/pin.png"
	}
	
	electronicFenceUrl ={
		allDom : path+"gpsonline/image/electronicFence/data_n.png",
		polygon : path+"gpsonline/image/electronicFence/juxing_n.png",
		line : path+"gpsonline/image/electronicFence/luxian_n.png",
		linefirstMarker : path+"gpsonline/image/electronicFence/icon_greenA.png",
		eventPhoto : path+"gpsonline/image/electronicFence/ico_photo_n.png"
	}
}
function stopBubble(e){  
    // 如果传入了事件对象，那么就是非ie浏览器  
    if(e&&e.stopPropagation){  
        //因此它支持W3C的stopPropagation()方法  
        e.stopPropagation();  
    }else{  
        //否则我们使用ie的方法来取消事件冒泡  
        window.event.cancelBubble = true;  
    }  
}
var bzMarkers =[];
var latlngs =[];
var markerIds =[];
var markerObjs =[];
var markerIdAndNames =[];
var nums=1;
function showMarkersBaidu(id,bool){
	var bzcheckbox = document.getElementsByName("bzcheckbox");
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.addOverlay(bzMarkers[i].marker);
//				baidMap.addOverlay(bzMarkers[i].polygon);
				if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			     }
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				
				baidMap.addOverlay(bzMarkers[i].marker);
//				baidMap.addOverlay(bzMarkers[i].polygon);
				if(bzcheckbox[0].checked){
					 baidMap.addOverlay(bzMarkers[i].label);
			    }
			}
		}
	}
	
}
function hideMarkersBaidu(id,bool){
	if(bool){
		for(i=0;i<bzMarkers.length;i++){
				baidMap.removeOverlay(bzMarkers[i].marker);
//				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				baidMap.removeOverlay(bzMarkers[i].marker);
//				baidMap.removeOverlay(bzMarkers[i].polygon);
				baidMap.removeOverlay(bzMarkers[i].label); 
			}
		}
	}
	
}
var markerObj;
var _operation;
var _bool=false;
function showMarkerBaidu(markersJson){
	if(markersJson == ""){
		return;
	}
	for(var i=0;i<markersJson.data.length;i++){
		(function(x){
			var myLatlng =googleToBaidu(markersJson.data[i].lng2,markersJson.data[i].lat2); //new BMap.Point(,);
			var myIcon = new BMap.Icon("http://mapday.exlive.cn/mi/p/b/3/red.gif", new BMap.Size(35,35));
			var marker = new BMap.Marker(
					myLatlng
					,{icon:myIcon}
					
			);  // 创建标注
			baidMap.addOverlay(marker);
			marker.setTitle(markersJson.data[i].id);
			markerIdAndNames[markersJson.data[i].id]=markersJson.data[i].title;
			var opts = {
			  position : myLatlng,    // 指定文本标注所在的地理位置
			  offset   : new BMap.Size(5,-5)    //设置文本偏移量
			 
			}
			var label = new BMap.Label(markersJson.data[i].title, opts);  // 创建文本标注对象
			label.setStyle({
				 color : "#000000",
				 backgroundColor : "#f5fcb8",
				 borderColor : "#000000",
				 fontSize : "12px",
				 height : "16px",
				 lineHeight : "16px",
				 fontWeight:"",
				 fontFamily:""
			});
			//baidMap.addOverlay(label); 
			//创建信息窗口
			var html="<div style='font-weight:normal;'><b>名称：</b>"+markersJson.data[i].title+"</br>"
			+"<b>描述：</b>"+markersJson.data[i].text+"</br>"
			+"<b>经度：</b>"+markersJson.data[i].lat2+"</br>"
			+"<b>纬度：</b>"+markersJson.data[i].lng2+"</br>";
			
			var htm="</div>";
			if(markersJson.data[i].competence==1){
				html=html+htm;
			}else{
				html=html+"</div>";
			}
			var infoWindow = new BMap.InfoWindow(html);
			marker.addEventListener("click", function(){
				var bool =true;
				for(var i=0;i<markerIds.length;i++){
					if(this.getTitle()==markerIds[i]){
						bool = false;
					}
				}
				if(bool==true){
					_bool=false;
					var newIcon = new BMap.Icon("http://mapday.exlive.cn/mi/p/b/3/green.gif", new BMap.Size(35,35));
					this.setIcon(newIcon);
					document.getElementById("time1").value="";
					document.getElementById("time2").value="";
					document.getElementById("msg").innerHTML="";
					var timeform2 = document.getElementById("timeform2");
					var clientWidth= document.documentElement.clientWidth;
					timeform2.style.left = clientWidth/2-200+"px";
					
					$("#timeform").show();
					
					markerObj=this;
					
					markerIds.push(this.getTitle());
					latlngs.push(new BMap.Point(this.getPosition().lng,this.getPosition().lat));
					if(latlngs.length >= 2){
						_bool=false;
						setLatLng(latlngs[latlngs.length-2],latlngs[latlngs.length-1],this);
					}else{
						
						//alert(this.getTitle()+","+markerIdAndNames[this.getTitle()]+","+this.getPosition().lat+","+this.getPosition().lng+","+0);
						//obj = new ActiveXObject("ScriptAgent.ScriptBridage.1");
						//alert(obj);
						//obj.operation = "marker,"+this.getTitle()+","+markerIdAndNames[this.getTitle()]+","+this.getPosition().lat+","+this.getPosition().lng+","+0;
						_operation = "marker,"+this.getTitle()+","+markerIdAndNames[this.getTitle()]+","+this.getPosition().lat+","+this.getPosition().lng+","+0;
						_bool=true;
					}
					

					//nums++;
				}
				
			});
			var pStart;
			var pEnd;
			if(markersJson.data[i].userMarkerArea == null || markersJson.data[i].userMarkerArea ==""){
				var pStart = new BMap.Point(0,0);
				var pEnd = new BMap.Point(0,0);
			}else{
				var pStart = new BMap.Point(markersJson.data[i].userMarkerArea.leftLon,markersJson.data[i].userMarkerArea.leftLat);
				var pEnd = new BMap.Point(markersJson.data[i].userMarkerArea.rightLon,markersJson.data[i].userMarkerArea.rightLat);
				
			}
//			var polygon = new BMap.Polygon([
//	              new BMap.Point(pStart.lng,pStart.lat),
//				  new BMap.Point(pEnd.lng,pStart.lat),
//				  new BMap.Point(pEnd.lng,pEnd.lat),
//				  new BMap.Point(pStart.lng,pEnd.lat)
//	          ], {strokeColor:"blue",fillColor:"blue", strokeWeight:2, strokeOpacity:0.5});
			//baidMap.addOverlay(polygon);
			
			markerManage = new Object();
			markerManage.id = markersJson.data[i].id;
			markerManage.title = markersJson.data[i].title;
			markerManage.label = label;
			markerManage.marker = marker;
//			markerManage.polygon = polygon;
			markerManage.icon = markersJson.data[i].icon;
			markerManage.infowindow = infoWindow;
			markerManage.latlng = myLatlng;
			markerManage.isShow = true;
			bzMarkers.push(markerManage);
			
		})(i);
    }	
}
function updateMarkerIsShow(id,isShow,isAll){
	if(isAll){
		for(i=0;i<bzMarkers.length;i++){
				bzMarkers[i].isShow = isShow;
		}
	}else{
		for(i=0;i<bzMarkers.length;i++){
			if(bzMarkers[i].id==id){
				bzMarkers[i].isShow = isShow;
				break;
			}
		}
	}
	
}//olatlng,nlatlng

var route=[];

function setLatLng(olatlng,nlatlng,marker){
	
	var searchComplete = function(results){
	    if (driving.getStatus() != BMAP_STATUS_SUCCESS){
	        return ;
	    }
	    var plan = results.getPlan(0);
     
        /*alert(marker.getTitle()
        		+","+markerIdAndNames[marker.getTitle()]+
        		","+marker.getPosition().lat
        		+","+marker.getPosition().lng+","+plan.getDistance(true).substring(0,plan.getDistance(true).length-2));
		*/
	   // obj = new ActiveXObject("ScriptAgent.ScriptBridage.1");
	   // obj.operation = "marker,"+marker.getTitle()+","+markerIdAndNames[marker.getTitle()]+","+marker.getPosition().lat+","+marker.getPosition().lng+","+plan.getDistance(true);
	    _operation =  "marker,"+marker.getTitle()+","+markerIdAndNames[marker.getTitle()]+","+marker.getPosition().lat+","+marker.getPosition().lng+","+plan.getDistance(true).substring(0,plan.getDistance(true).length-2);
	    _bool=true;
	}
	var driving = new BMap.DrivingRoute(
			baidMap,
			{
				renderOptions:{map:baidMap},
				onSearchComplete:searchComplete
			}
			
	);
	driving.disableAutoViewport();
	
    driving.setMarkersSetCallback(function(marks){
		baidMap.removeOverlay(marks[0].marker);
		baidMap.removeOverlay(marks[1].marker);
	});
	driving.setPolylinesSetCallback(function(routes){
		//baidMap.removeOverlay(ss[0].marker);
		routes[0].getPolyline().setStrokeColor("#191970");
		routes[0].getPolyline().setStrokeOpacity(0.8);
		routes[0].getPolyline().setStrokeWeight(2);
		route.push(routes[0].getPolyline());
	});
	driving.search(olatlng, nlatlng);
}
function clears(){
	var myIcon = new BMap.Icon("http://mapday.exlive.cn/mi/p/b/3/red.gif", new BMap.Size(35,35));
	for(i=0;i<bzMarkers.length;i++){
		bzMarkers[i].marker.setIcon(myIcon);
	}
	for(i=0;i<route.length;i++){
		baidMap.removeOverlay(route[i]);
	}
	latlngs.length=0;
	markerIds.length=0;
	markerObjs.length=0;
	nums=1;
	clickMarkArr =[];
	clickMarkArr.length=0;
}
function cancel(){
	//var newIcon = new BMap.Icon("http://mapday.exlive.cn/mi/p/b/3/red.gif", new BMap.Size(35,35));
	//markerObj.setIcon(newIcon);
	$("#timeform").hide();
	if(route.length>=2){
		baidMap.removeOverlay(route[route.length-1]);
		route.pop();
	}
	markerIds.pop();
	latlngs.pop();
	
}

var clickMarkArr =[];
function finish(){
	//if(_bool==false) return;
	
	var time1 =  document.getElementById("time1").value;
	var time2 =  document.getElementById("time2").value;
	if( time1 != "" && time2 != ""){
		var bool1 = validate(time1);
		var bool2 = validate(time2);
		if(bool1==true && bool2 == true){
				if(time1>-1 && time1<61 && time2>-1 && time2<61){
//					_operation=_operation+","+time1+","+time2;
					var distance = 0;
					var newpoint = new BMap.Point(mklng,mklat);
					if(clickMarkArr.length!=0){
						distance = (baidMap.getDistance(clickMarkArr[clickMarkArr.length-1],newpoint)/1000).toFixed(2);
					}
					var parstr = "marker,"+mkid+","+title+","+mklat+","+mklng+","+distance+","+time1+","+time2;
					try{
						obj = new ActiveXObject("ScriptAgent.ScriptBridage.1");
						obj.operation = parstr;
					}catch (e) {
					}
					clickMarkArr.push(newpoint);
					$("#timeform").hide();
				}else{
					document.getElementById("msg").innerHTML="<font color='red'>必须为0-60的数字</font>";
				}
		}else{
			document.getElementById("msg").innerHTML="<font color='red'>必须为0-60的数字</font>";
		}	
	}else{
		document.getElementById("msg").innerHTML="<font color='red'>数据不能为空！</font>";
		//alert("有误");
	}
	//alert(check_validate(time1) && check_validate(time2) && time1>-1 && time1<61 && time2>-1 && time2<61);
}

function validate(value){
     var reg = new RegExp("^[0-9]*$");
    
	 if(!reg.test(value)){
	    // alert("请输入数字!");
		 return false;
	 }
	 if(!/^[0-9]*$/.test(value)){
	   //  alert("请输入数字!");
		 return false;
	 }
 return true;
}