var hospitalsOnCall={};var hospitalsOnCallMarkerTxt={};var clinics_visible=[];var HOSPITAL_YELLOW_THRESHOLD=30;var HOSPITAL_CHANGES_MINUTES_THRESHOLD=10;var HOSPITAL_OPENS_HOURS_THRESHOLD=60;var HOSPITAL_HOURS_ROUNDING_THRESHOLD=15;var HOSPITAL_UPDATE_INTERVAL=5*60;var hospitalRequestBounds;var hospitalRequestDuration;
var hospitalServerDate;var hospitalRequestDate;var hospitalUpdateTimer;function getHospitalTip(I){var D,A;var C=new Date();var J=hospitalServerDate.getTime()+(C.getTime()-hospitalRequestDate.getTime());var H=parseHospitalDate(I.start_date).getTime();var E=parseHospitalDate(I.end_date).getTime();if((H<=J)&&(J<E)){if((E-J<HOSPITAL_YELLOW_THRESHOLD*60*1000)){D="Κλείνει σε ";
var B=Math.round((E-J)/(60*1000));if(B<=HOSPITAL_CHANGES_MINUTES_THRESHOLD){D+=trueRound(B)+" λεπτά"}else{B=Math.round(B/5)*5;D+=trueRound(B)+" λεπτά"}A="yellow50.png"}else{D="ΕΦΗΜΕΡΕΥΕΙ";A="green50.png"}}else{A="red50.png";var D="Ανοίγει σε ";var B=Math.round((H-J)/(60*1000));if(B>=HOSPITAL_OPENS_HOURS_THRESHOLD){var G=B-Math.floor(B/60)*60;
var F=(B-G)/60;if(G>=60-HOSPITAL_HOURS_ROUNDING_THRESHOLD){F++;G-=60}D+=trueRound(F);if(G>=HOSPITAL_HOURS_ROUNDING_THRESHOLD){D+="+"}if((F==1)&&(G<HOSPITAL_HOURS_ROUNDING_THRESHOLD)){D+=" ώρα"}else{D+=" ώρες"}}else{if(B<=HOSPITAL_CHANGES_MINUTES_THRESHOLD){D+=trueRound(B)+" λεπτά"}else{B=Math.round(B/5)*5;
D+=trueRound(B)+" λεπτά"}}}return{"style":A,"text":D}}function parseHospitalDate(F){var E=F.indexOf("-",0);var D=F.indexOf("-",E+1);var C=F.indexOf(" ",D+1);var A=F.indexOf(":",C+1);var B=new Date();B.setMilliseconds(0);B.setSeconds(0);B.setMinutes(F.substring(A+1));B.setHours(F.substring(C+1,A));B.setDate(F.substring(0,E));
B.setMonth(F.substring(E+1,D)-1);B.setFullYear(F.substring(D+1,C));return B}function tempClearHospitals(){for(var A in hospitalsOnCall){var B=hospitalsOnCall[A];removeFromMarkersOnMap(B.lat,B.lng);map.removeOverlay(B.marker);map.removeOverlay(B.markertext);delete hospitalsOnCall[A]}hospitalsOnCall={};
hospitalsRequestBounds=null}function clearHospitals(B){infowindow.close();for(var C in hospitalsOnCallMarkerTxt){var A=hospitalsOnCallMarkerTxt[C];A.setMap(null)}for(var D in hospitalsOnCall){var E=hospitalsOnCall[D];disableClinicsVisible(D,B);if(tobeRemoved(hospitalsOnCall[D],B)){removeFromMarkersOnMap(E.lat,E.lng);
E.marker.setMap(null);E.label.close();delete hospitalsOnCall[D]}}hospitalsOnCall={};hospitalsRequestBounds=null}function disableClinicsVisible(B,A){for(i in clinics_visible){if(clinics_visible[i]==false){for(j in hospitalsOnCall[B].clinics){if((hospitalsOnCall[B].clinics[j])&&(hospitalsOnCall[B].clinics[j].visible)&&(hospitalsOnCall[B].clinics[j].id==A)){hospitalsOnCall[B].clinics[j].visible=false;
break}}}}}function tobeRemoved(B,A){for(i in clinics_visible){if(clinics_visible[i]){for(j in B.clinics){if(B.clinics[j].id==i){return false}}}}return true}function toggleHospitals(B,D){if(infowindow2!=undefined){infowindow2.close()}if(B){var A=map.getBounds();var E={"southwest":{"lat":A.getSouthWest().lat(),"lng":A.getSouthWest().lng()},"northeast":{"lat":A.getNorthEast().lat(),"lng":A.getNorthEast().lng()}};
var F="1";getNewHospitals(E,D,F);if(D==0){for(i in clinics){jQuery("#hospital_id_"+i).get(0).checked=true;clinics_visible[0]=true;clinics_visible[i]=true}}else{clinics_visible[D]=true}}else{if(D==0){for(i in clinics){jQuery("#hospital_id_"+i).get(0).checked=false;clinics_visible[0]=false;clinics_visible[i]=false
}}else{clinics_visible[D]=false;var C=true;for(i in clinics_visible){if(clinics_visible[i]){C=false;break}}if(C){jQuery("#hospitals").get(0).checked=false}}clearHospitals(D)}if(isDutiesChecked()){$("#allDuties").attr("src","images/new/various/efimereuonta-sel.png")}else{$("#allDuties").attr("src","images/new/various/efimereuonta.png")
}}function getNewHospitals(B,A,C){jQuery.ajax({type:"POST",url:"functs/hospitals.jsp",data:{"sw_lat":B.southwest.lat,"sw_lng":B.southwest.lng,"ne_lat":B.northeast.lat,"ne_lng":B.northeast.lng,"clinic_id":A,"duration":C},dataType:"json",success:function(E){hospitalServerDate=parseHospitalDate(E.date);
hospitalRequestDate=new Date();hospitals=E.duties;for(var D in hospitals){var F=hospitals[D];if(hospitalsOnCall[F.hospId]==undefined){addHospital(F,A)}else{for(j in hospitalsOnCall[F.hospId].clinics){if(hospitalsOnCall[F.hospId].clinics[j].id==A){hospitalsOnCall[F.hospId].clinics[j].visible=true;break
}}}}}})}function addHospital(K,A){K.clinics.push({"id":A,"visible":true});hospitalsOnCall[K.hospId]=K;var G="images/new/markers/health-pin.png";var J=new google.maps.LatLng(K.lat,K.lng);var D=new google.maps.Marker({map:map,position:J,icon:G,optimized:false,zIndex:100});D.hospitaldata=K;D.hospitaldata.clinic_id=A;
markersOnMap.push({"lat":J.lat(),"lng":J.lng(),"name":K.hospName,"marker":D});google.maps.event.addListener(D,"click",function(){if(infowindow2!=undefined){infowindow2.close()}infowindow.setContent(getHospitalInfo(this.hospitaldata));infowindow.open(map,D)});google.maps.event.addListener(D,"rightclick",function(){addContextMenu(2,J)
});google.maps.event.addListener(map,"click",function(){infowindow.close()});var I=getHospitalTip(K);var E="font-weight:bold; font-size:12px; line-height:14px; padding:1px 2px 5px; width:81px; height:14px; background-image: url(images/new/various/green50_hosp.png);background-repeat:no-repeat; color: black; white-space: nowrap;";
var F=new MarkerText(D,18,-65,E,I.text);hospitalsOnCallMarkerTxt[K.hospId]=F;var C={disableAutoPan:false,alignBottom:true,pixelOffset:new google.maps.Size(19,-10),zIndex:null,boxStyle:{opacity:0.95,width:"300px"},closeBoxURL:"",infoBoxClearance:new google.maps.Size(1,1),isHidden:false,pane:"mapPane",maxWidth:"800px",enableEventPropagation:false};
var B=new InfoBox(C);var H='<div class="pharmacy">';H+='<div style="font-size:11px;">';H+="Ανοίγει: <b>"+K.start_date.substring(K.start_date.indexOf(" "),K.start_date.length)+"</b><br/>";H+="Κλείνει: <b>"+K.end_date.substring(K.end_date.indexOf(" "),K.end_date.length)+"</b>";H+="</div>";H+="</div>";B.setContent(H);
B.open(map,D);D.setMap(map);F.setMap(map);hospitalsOnCall[K.hospId].marker=D;hospitalsOnCall[K.hospId].markertext=F;hospitalsOnCall[K.hospId].label=B;hospitalsOnCall[K.hospId].clinic_id=A}function getHospitalInfo(F){var C='<div class="myInfoBox">';C+='<div class="infoBox-inner">';C+="<b>"+F.hospName+"</b><br />";
var A=F.phone;if(A>0.01){C+="<b>Τηλ: </b>"+Math.round(A)+"<br />"}else{if((A!="0.0")&&(A!="")&&(A!=undefined)){C+="Τηλ: "+A+"<br />"}}if((F.clinics)&&(F.clinics.length>0)){C+="<b>Κλινικές:</b><br>"}for(j in F.clinics){if((F.clinics[j].id!=0)){if(F.clinics[j].visible){C+="<b><i>"+clinics[F.clinics[j].id]+"</i></b><br />"
}else{C+=clinics[F.clinics[j].id]+"<br />"}}}var D=new RegExp(/"/g);var E=F.hospName.toString();var B="Νοσοκομείο: "+E.replace(D,"");C+='<br><span id="hosp_address"></span>';C+='<div class="info-route">';C+="<a href=\"javascript:setRouteDirection('"+F.lat+"','"+F.lng+"','from','"+B+"')\">";C+='<img src="images/new/various/start-route.png" style="border:0px; margin-right:3px;" title="Διαδρομή από" alt="Διαδρομή από" />Διαδρομή από</a>';
C+="<a href=\"javascript:setRouteDirection('"+F.lat+"','"+F.lng+"','to','"+B+"')\">";C+='<img src="images/new/various/stop-route.png" style="border:0px; margin-right:3px;" title="Διαδρομή προς" alt="Διαδρομή προς" />Διαδρομή έως</a>';C+="</div>";C+="</div>";C+="</div>";C+='<div class="infoBox-bottom"></div>';
$.ajax({type:"POST",url:"functs/revGeoResults.jsp",data:{"pointX":F.lng,"pointY":F.lat},dataType:"json",success:function(H){if(H.revGeoResults[0]){var G="<font size='2'>"+H.revGeoResults[0].roadName+" ";if(H.revGeoResults[0].roadNumber1!=0){G+=H.revGeoResults[0].roadNumber1+" "}if(H.revGeoResults[0].roadNumber2!=0){G+=H.revGeoResults[0].roadNumber2+" "
}G+="<br>"+H.revGeoResults[0].roadMunicipality+", "+H.revGeoResults[0].roadZip+"</font><br>"}$("#hosp_address").html(G)}});return C}function updateHospitals(){var E=[];for(i in clinics_visible){if((i==0)&&(clinics_visible[i])){E=[0];break}if(clinics_visible[i]){E.push(i)}}var B=E.join(",");if(E.length>0){var A=map.getBounds();
var C={"southwest":{"lat":A.getSouthWest().lat(),"lng":A.getSouthWest().lng()},"northeast":{"lat":A.getNorthEast().lat(),"lng":A.getNorthEast().lng()}};var D="1";getNewHospitals(C,B,D)}}function renewHospitals(){var E=[];for(i in clinics_visible){if((i==0)&&(clinics_visible[i])){E=[0];break}if(clinics_visible[i]){E.push(i)
}}var B=E.join(",");tempClearHospitals();if(E.length>0){var A=map.getBounds();var C={"southwest":{"lat":A.getSouthWest().lat(),"lng":A.getSouthWest().lng()},"northeast":{"lat":A.getNorthEast().lat(),"lng":A.getNorthEast().lng()}};var D=$("#hospitals_hours").val();getNewHospitals(C,B,D)}};
