var hospitalsOnCall={};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(A){for(var B in hospitalsOnCall){var C=hospitalsOnCall[B];disableClinicsVisible(B,A);if(tobeRemoved(hospitalsOnCall[B],A)){removeFromMarkersOnMap(C.lat,C.lng);map.removeOverlay(C.marker);map.removeOverlay(C.markertext);delete hospitalsOnCall[B]}}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(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=$("#hospitals_hours").val();getNewHospitals(E,D,F);if(D==0){if(panelHospitals.currentPanelIdx!=1){panelHospitals.showPanel("panel_hospitals_list")}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}jQuery("#hospitals").get(0).checked=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)
}}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(G,D){G.clinics.push({"id":D,"visible":true});hospitalsOnCall[G.hospId]=G;var E=iconPerCategoryId[HOSPITAL_ICON];var C=new GMarker(new GLatLng(G.lat,G.lng),{"icon":E});C.hospitaldata=G;C.hospitaldata.clinic_id=D;markersOnMap.push({"lat":G.lat,"lng":G.lng,"name":G.hospName});
GEvent.addListener(C,"click",function(){this.openInfoWindow(getHospitalInfo(this.hospitaldata))});var F=getHospitalTip(G);var B='background-image: url("images/'+F.style+'"); color:black; padding:1px; white-space: nowrap;';var A=new MarkerText(C,13,-45,B,F.text);map.addOverlay(C);map.addOverlay(A);hospitalsOnCall[G.hospId].marker=C;
hospitalsOnCall[G.hospId].markertext=A;hospitalsOnCall[G.hospId].clinic_id=D}function getHospitalInfo(C){var B='<div align="left">';B+="<b>"+C.hospName+"</b><br />";var A=C.phone;if(A>0.01){B+="<b>Τηλ: </b>"+Math.round(A)+"<br />"}else{if((A!="0.0")&&(A!="")&&(A!=undefined)){B+="Τηλ: "+A+"<br />"}}B+="<b>Εφημερία από:</b> "+C.start_date+"<br />";
B+="<b>Εφημερία έως:</b> "+C.end_date+"<br />";if((C.clinics)&&(C.clinics.length>0)){B+="<b>Κλινικές:</b><br>"}for(j in C.clinics){if((C.clinics[j].id!=0)){if(C.clinics[j].visible){B+="<b><i>"+clinics[C.clinics[j].id]+"</i></b><br />"}else{B+=clinics[C.clinics[j].id]+"<br />"}}}B+="</div>";B+='<br><span id="hosp_address"></span>';
B+="<a href=\"javascript:setRoutePointFrom('"+C.lat+"','"+C.lng+"')\">";B+='<img src="images/start_hex.png" style="border:0px; margin-right:3px;" title="Διαδρομή από" alt="Διαδρομή από" />';B+="</a>&nbsp;&nbsp;&nbsp;";B+="<a href=\"javascript:setRoutePointTo('"+C.lat+"','"+C.lng+"')\">";B+='<img src="images/stop_hex.png" style="border:0px; margin-right:3px;" title="Διαδρομή έως" alt="Διαδρομή έως" /></a><br><br>&nbsp;';
$.ajax({type:"POST",url:"functs/revGeoResults.jsp",data:{"pointX":C.lng,"pointY":C.lat},dataType:"json",success:function(E){if(E.revGeoResults[0]){var D="<font size='2'>"+E.revGeoResults[0].roadName+" ";if(E.revGeoResults[0].roadNumber1!=0){D+=E.revGeoResults[0].roadNumber1+" "}if(E.revGeoResults[0].roadNumber2!=0){D+=E.revGeoResults[0].roadNumber2+" "
}D+="<br>"+E.revGeoResults[0].roadMunicipality+", "+E.revGeoResults[0].roadZip+"</font><br>"}$("#hosp_address").html(D)}});return B}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=$("#hospitals_hours").val();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)}};