function PopUpBase(){}
//过车查询
PopUpBase.createCheTravelPopUp =  function(data){
	var picSrc=data.tplj.split(";");
	if(picSrc.indexOf('') != -1){picSrc.pop();}
	var proName = top.window.location.pathname.split("/")[1];
	var sysUrl = "http://"+window.location.host+"/"+proName;
	var picProxyGetUrl = sysUrl+"/sourceProxy?fileType=picUrlProxy&picUrl=";
	var strMsg = new Array();
	strMsg.push("<table><tr><td width=290>");
	strMsg.push("<div>");
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''"+data.monitorLocationName+"' >"+data.monitorLocationName+"</div></div>");
	strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ data.plateNo +"</p><p class='popUpInfo' title='' >"+ data.snapTime +"</p><p class='popUpInfo' title='' >"+ data.cheSpeed +"km/h</p></div>");
	strMsg.push("<div style='margin-top:5px; padding-top: 10px; border-top: 1px dotted #ccc;'>");
	strMsg.push("<div class='popupImgDiv'>");
	if(picSrc.length>1){
		strMsg.push("<a onclick='PopUpBase.picSlide(this)' class='leftBtn'><</a><a onclick='PopUpBase.picSlide(this)' class='rightBtn'>></a>");
	}
	strMsg.push("<div class='imglist'>");
	for(var i = 0;i<picSrc.length;i++){
		strMsg.push("<p style='display: inline-block;width: 290px;height: 140px;text-align: center;'><img class='pic' src='"+  (picProxyGetUrl+picSrc[i]) +"'  osrc='"+  (picProxyGetUrl+picSrc[i]) +"'  onerror='$.loadErrorPic(this);'style='max-width: 100%;max-height: 100%;'></p>");
	}
	strMsg.push("</div></div>");
	strMsg.push("<div style='width:100%;margin:10px 0;border-top: 1px dotted #ccc;'>");
	strMsg.push("<div onclick='' style='float:left;cursor: pointer;'><a class='ahref'>上一条</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>过车查询</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>车辆布控</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>下一条</a></div>");
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</td></tr></table>");
	return strMsg.join("");
};

PopUpBase.createCheTravelHisStartPopUp =  function(data){
	return PopUpBase.createCheTravelHisPopUp(data, "asc");
};

PopUpBase.createCheTravelHisEndPopUp =  function(data){
	return PopUpBase.createCheTravelHisPopUp(data, "desc");
};

PopUpBase.createCheTravelHisPopUp =  function(data, type){
	var picSrc=data.tplj.split(";");
	if(picSrc.indexOf('') != -1){picSrc.pop();}
	var proName = top.window.location.pathname.split("/")[1];
	var sysUrl = "http://"+window.location.host+"/"+proName;
	var picProxyGetUrl = sysUrl+"/sourceProxy?fileType=picUrlProxy&picUrl=";
	var strMsg = new Array();
	strMsg.push("<table><tr><td width=290>");
	strMsg.push("<div>");
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''"+data.monitorLocationName+"' >"+data.monitorLocationName+"</div></div>");
	strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ data.plateNo +"</p><p class='popUpInfo' title='' >"+ data.snapTime +"</p><p class='popUpInfo' title='' >"+ data.cheSpeed +"km/h</p></div>");
	strMsg.push("<div style='margin-top:5px; padding-top: 10px; border-top: 1px dotted #ccc;'>");
	strMsg.push("<div class='popupImgDiv'>");
	if(picSrc.length>1){
		strMsg.push("<a onclick='PopUpBase.picSlide(this)' class='leftBtn'><</a><a onclick='PopUpBase.picSlide(this)' class='rightBtn'>></a>");
	}
	strMsg.push("<div class='imglist'>");
	for(var i = 0;i<picSrc.length;i++){
		strMsg.push("<p style='display: inline-block;width: 290px;height: 140px;text-align: center;'><img class='pic' src='"+  (picProxyGetUrl+picSrc[i]) +"'  osrc='"+  (picProxyGetUrl+picSrc[i]) +"'  onerror='$.loadErrorPic(this);'style='max-width: 100%;max-height: 100%;'></p>");
	}
	strMsg.push("</div></div>");
	strMsg.push("<div style='width:100%;margin:10px 0;border-top: 1px dotted #ccc;'>");
	strMsg.push("<div onclick='' style='float:left;cursor: pointer;'><a class='ahref'>上一条</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>过车查询</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>车辆布控</a></div>");
	strMsg.push("<div onclick='' style='float:left;margin-left:35px;cursor: pointer;'><a class='ahref'>下一条</a></div>");
	
	strMsg.push("<div onclick=CheTravel.carTraceReplay('"+type+"');" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-mapStart'></p><a class='ahref'>轨迹回放</a></div>");
	
	strMsg.push("<div title='' onclick=CheTravel.stopCarTraceReplay();" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-mapStop'></p><a  class='ahref'>停止轨迹回放</a></div>");
	
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</td></tr></table>");
	return strMsg.join("");
};

//车辆卡口
PopUpBase.createMonitorPopUp =  function(data){
	var uuid = $.uniqueId(),url = top.sysUrl+"/szmap/business/base/item/iframe/jklk-tab_show.jsp",
	urlSearch = top.sysUrl+"/vp/kakoubase/FuzzyCheTravelSet.jsp";
	$(window).data(uuid,data);
	var xzmc = data.xzmc||'';
	var strMsg = new Array();
	strMsg.push("<table><tr><td width=260>");
	strMsg.push("<div id="+uuid+">");
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''"+data.lkmc+"' >"+data.lkmc+"</div></div>");
	if(xzmc != ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ xzmc +"</p></div>");
	}
	strMsg.push("<div style='margin-top:20px; padding-top: 10px; border-top: 1px dotted #ccc'>");
	strMsg.push("<div onclick=PopUpBase.createDetailWindow('"+ urlSearch +"',this,top.$(document.body).height()*0.9,top.$(document.body).width()*0.7,true);" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-cheSearch'></p><a class='ahref'>车辆查询</a></div>");
	strMsg.push("<div onclick=PopUpBase.createDetailWindow('"+ url +"',this,380);" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-info-look'></p><a class='ahref'>详细信息</a></div>");
	strMsg.push("<div  onclick=MapMain.setSelectedFrameGridData('','车辆卡口',this); " +
			"style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-shouc'></p><a class='ahref'>加入所选</a></div>");
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</td></tr></table>");
	return strMsg.join("");
};

//警车GPS
PopUpBase.createChePopUp =  function(data){
	var uuid = $.uniqueId(),url = top.sysUrl+"/szmap/business/base/item/iframe/chegps-tab_show.jsp";
	$(window).data(uuid,data);
	var gxbmmc = data.gxbmmc || '';
	var hbsj = data.hbsj || '';
	var sbbh = (String)(data.sbbh);
	var tdbh = (String)(data.tdbh);
	var strMsg = new Array();
	strMsg.push("<table><tr><td width=250>");
	strMsg.push("<div id="+uuid+">");
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''" + data.hphm + "'>"+data.hphm+"</div></div>");
	if(data.bmmc == ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ hbsj +"</p></div>");
	}else if(hbsj != ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title=''>"+ data.bmmc +"</p>"+
				"<p class='camera-info-name popUpInfo' title='' >"+ hbsj +"</p></div>");
	}else{
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ data.bmmc +"</p></div>");
	}
	strMsg.push("<div style='margin-top:20px; padding-top: 10px; border-top: 1px dotted #ccc'>");	
	strMsg.push("<div onclick=PopUpBase.startvideo('" + sbbh + "','" + tdbh + "');;" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-monitor'></p><a class='ahref'>实时视频</a></div>");
	strMsg.push("<div title='' onclick=javascript:CarTrace.startCarTrace('"+sbbh+"','"+tdbh+"');" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-mapStart'></p><a  class='ahref'>启用追踪</a></div>");
	strMsg.push("<div title='' onclick=javascript:CarTrace.clearCarRealTrace('"+sbbh+"','"+tdbh+"');" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-mapStop'></p><a  class='ahref'>停止追踪</a></div>");
	strMsg.push("<div onclick=PopUpBase.createDetailWindow('"+ url +"',this,360);" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-info-look'></p><a  class='ahref'>详细信息</a></div>");
	strMsg.push("<div title='' onclick=javascript:CarTrace.hisCarTrace('"+sbbh+"','"+tdbh+"');" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-map'></p><a  class='ahref'>历史轨迹</a></div>");
	strMsg.push("<div  onclick=MapMain.setSelectedFrameGridData('','警车GPS',this); " +
			"style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-shouc'></p><a class='ahref'>加入所选</a></div>");
 	strMsg.push("</div>");
 	strMsg.push("</div>");
	strMsg.push("</td></tr></table>");
	return strMsg.join("");
};
//摄像头
PopUpBase.createVideoPopUp = function(data){
	var uuid = $.uniqueId(),url = top.sysUrl+"/szmap/business/base/item/iframe/monitor-tab_show.jsp";
	data.tdlxmc = data.tdlx ? MapConst.pastChannelSmallTypeName(data.tdlx) : "";
	$(window).data(uuid,data);
	var xzmc = data.xzmc||'';
	var sbbh = (String)(data.sbbh);
	var tdbh = (String)(data.tdbh);
	var strMsg = new Array();
	strMsg.push("<div  id="+uuid+" style = 'height:130px;width:246px;'>");	
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''" + data.tdmc + "'>"+data.tdmc+"</div></div>");
	if(data.tdlxmc == ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ xzmc +"</p></div>");
	}else if(xzmc != ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title=''>"+ data.tdlxmc +"</p>"+
				"<p class='camera-info-name popUpInfo' title='' >"+ xzmc +"</p></div>");
	}else{
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ data.tdlxmc +"</p></div>");
	}
	strMsg.push("<div style='margin-top:20px; padding-top: 10px; border-top: 1px dotted #ccc'>");
	
	strMsg.push("<div onclick=PopUpBase.startvideo('" + sbbh + "','" + tdbh + "');" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-monitor'></p><a class='ahref'>实时视频</a></div>");
	strMsg.push("<div onclick=PopUpBase.startrecord('" + sbbh + "','" + tdbh + "');" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-video'></p><a class='ahref'>录像倒查</a></div>");
	strMsg.push("<div onclick=PopUpBase.createDetailWindow('"+ url +"',this,300);" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-info-look'></p><a class='ahref'>详细信息</a></div>");
	strMsg.push("<div onclick=MapMain.setSelectedFrameGridData('','摄像头',this); " +
			"style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-shouc'></p><a class='ahref'>加入所选</a></div>");
	strMsg.push("<div title='' onclick=PopUpBase.startMove(this);" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-map'></p><a class='ahref'>位置迁移</a></div>");

	strMsg.push("</div>");
	strMsg.push("</div>");
	return strMsg.join("");
}

//标注html
PopUpBase.createMonitorPopUpBybz =  function(data){
	var strMsg = new Array();
	strMsg.push('<div>');
	strMsg.push('<div class="bzPopUp"><span class="text-content">摄像头：</span><input id="tdmc" placeholder="请选择摄像头"  readonly><a href="javascript:Label.tdmcClick();" class="icon-add img-btn"></a></div>');
	strMsg.push('<div class="bzPopUp"><span class="text-content">设备编号：</span><input id="sbbh" readonly></div>');
	strMsg.push('<div class="bzPopUp"><span class="text-content">通道编号：</span><input id="tdbh" readonly></div>');
	strMsg.push('<div class="bzPopUp"><span class="text-content">标注经度：</span><input value="'+data[0]+'" id="updateLongitude" readonly></div>');
	strMsg.push('<div class="bzPopUp"><span class="text-content">标注纬度：</span><input value="'+data[1]+'" id="updateLatitude" readonly></div>');
	strMsg.push('<div class="hidden"><span class="text-content">序号：</span><input id="xh"  readonly></div>');
	strMsg.push('<div class="bzPopUpBtnGroup"><a class="bzPopUpBtn" onclick="Label.update();">确定</a><a class="bzPopUpBtn" onclick="Label.cancle()">取消</a></div>');
	strMsg.push('</div>')
	return strMsg.join("");
};

//详细信息
PopUpBase.createDetailWindow = function(url,div,h,w,f){
	var pid = $(div).parent().parent("div").attr("id");
	var data  = $(window).data(pid),height = 300,width = 600;
	if(h) height = h;
	if(w) width = w;
 	windowid = top.$.createWin({
		 title	: 	'详情查询',
		 width  :  width,
		 maximizable:!!f,
		 height :  height,
		 data	:  data,
		 url	:  url
	 });
}

//实时视频
PopUpBase.startvideo = function(vdId,channelId){
	if(!ocx) {
        $.log("ocx is undefined...");
        return ;
    } 
    var vdId      = vdId;
    var channelId = channelId;
    try {       
        ocx.iSeeOcxNewWindow(3);
        ocx.iSeeOcxSetPopupWndProperties('',300,200);
        ocx.iSeeOcxSetScreenModeEx(0,1);
       var ret =  ocx.iSeeOcxMonitorStartEx2(0,0,vdId,channelId,0);
       console.log('startvideo: ret:' + ret );
    } catch(e) {
        $.showMsg("视频播放异常！");
    }
}

//取得实时追踪起点html
PopUpBase.getGpsCarRealStartPointHtml = function (data) {
	return PopUpBase.createChePopUp(data);
}
//取得历史轨迹起点html
PopUpBase.getGpsCarHisStartPointHtml = function (data) {
	return PopUpBase.getcarTraceReplayPointHtml(data, 'asc');
}
//取得轨迹回放html
PopUpBase.getcarTraceReplayPointHtml = function (data, type) {
	var uuid = $.uniqueId(),url = top.sysUrl+"/szmap/business/base/item/iframe/chegps-tab_show.jsp";
	$(window).data(uuid,data);
	var managerDeptName = data.managerDeptName || '';
	var reportTime = data.reportTime || '';
	var vdId = (String)(data.vdId);
	var channelId = (String)(data.channelId);
	var vdChannelId = vdId + '-' + channelId;
	var timeObj = CarTrace.hisCarTraceQueryTime[vdChannelId];
	var strMsg = new Array();
	strMsg.push("<table><tr><td width=250>");
	strMsg.push("<div id="+uuid+">");
	strMsg.push("<div class='clear'><div class='popUpTitle' title=''" + data.plateNo + "'>"+data.plateNo+"</div></div>");
	if(managerDeptName == ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title='' >"+ reportTime +"</p></div>");
	}else if(reportTime != ''){
		strMsg.push("<div class='clear'><p class='popUpInfo' title=''>"+ managerDeptName +"</p>"+
				"<p class='camera-info-name popUpInfo' title='' >"+ reportTime +"</p></div>");
	}
	strMsg.push("<div class='clear'>"+
			"<p class='camera-info-name popUpInfo' title='' >"+ timeObj.startTime +" 至 " + timeObj.endTime+"</p></div>");
			
	strMsg.push("<div style='margin-top:20px; padding-top: 10px; border-top: 1px dotted #ccc'>");
	
	strMsg.push("<div onclick=CarTrace.carTraceReplay('"+type+"');" +
			" style='float:left;cursor: pointer;'>" +
			"<p class='iconP icon-mapStart'></p><a class='ahref'>轨迹回放</a></div>");
	
	strMsg.push("<div title='' onclick=CarTrace.stopCarTraceReplay();" +
			" style='float:left;margin-left:20px;cursor: pointer;'>" +
			"<p class='iconP icon-mapStop'></p><a  class='ahref'>停止轨迹回放</a></div>");
	
	strMsg.push("</div>");
	strMsg.push("</div>");
	strMsg.push("</td></tr></table>");
	return strMsg.join("");
}
//取得历史轨迹终点html
PopUpBase.getGpsCarHisEndPointHtml = function (data) {
	return PopUpBase.getcarTraceReplayPointHtml(data, 'desc');
}
//录像回查
PopUpBase.startrecord = function(vdId,channelId){
	var datenow = new Date();
    if(!ocx) {
        $.log("ocx is undefined...");
        return ;
    } 
    var snapTime = datenow.format("yyyy-MM-dd hh:mm:ss");
        snapTime = snapTime.replace(new RegExp("-","gm"),"/");
    var startTime = (new Date(snapTime)).getTime()-MapConst.videoRecordTime;
    var endTime = (new Date(snapTime)).getTime();
    startTime = ($.formatDate(new Date(startTime),"yyyy-MM-dd hh:mm:ss")); 
    endTime = ($.formatDate(new Date(endTime),"yyyy-MM-dd hh:mm:ss")); 
    try {       
        ocx.iSeeOcxNewWindow(3);
        ocx.iSeeOcxSetPopupWndProperties('',300,200);
        ocx.iSeeOcxSetScreenModeEx(0,1);
        var ret = ocx.iSeeOcxDoPlaybackByTime(0,vdId,channelId, startTime, endTime);
        console.log('startrecord: ret:' + ret );
    } catch(e) {
        $.showMsg("录像播放异常！");
    }
}
//修改经纬度
PopUpBase.startMove = function(div){
	var pid = $(div).parent().parent("div").attr("id");
	var data  = $(window).data(pid);
	var moveData = data;
	var layer = MapMain.getLayer(MapConst.LAYER_MONITOR);
	var moveIndex = layer.markerIndex[data.id];
	if(moveIndex>=0){
		var moveMarker = layer.markerArray[moveIndex];
		moveMarker.flash2(3); 
		moveMarker.closeInfoWindowHtml();
		moveMarker.startMove(layer.callBack);
		$.showMsg("请拖动要修改的点位！");
		moveMarker.addListener("mouseup", function () {
			moveMarker.stopMove();
			var m={};
			moveData.jd = moveMarker.point.x;
			moveData.wd = moveMarker.point.y;
			m.sbbh = moveData.sbbh;
			m.tdbh = moveData.tdbh;
			m.jd = moveMarker.point.x;
			m.wd = moveMarker.point.y;
			if(!m.sbbh || !m.tdbh) {
				$.showMsg("请重新尝试！");
				return;
			}
			 $.ajax({
				type:'post',
				dataType : 'json',
				url:'szMapHttpAction!update_sbtd_jwd.do',
				data:m,
				success:function(data){
					if(data=="success"){							
						$.showMsg("修改成功！");
					}else{
						$.showMsg("修改失败！");
					}
				}
			});	
		});
	}
	
}
//图片左右切换
PopUpBase.picSlide = function(obj){
	var btn = $(obj).attr('class');
	var leftNum = $('.imglist').position().left;
	var maxNum = -($(".imglist").find('p').length - 1)*290;
	if(btn == 'rightBtn'){
		if(leftNum > maxNum)
		$(".imglist").animate({left: leftNum-290 + "px"}, {duration: 111});
	}else{
		if(leftNum != 0){
			$(".imglist").animate({left: leftNum+290 + "px"}, {duration: 111});
		}
	}
}