
﻿
var BmlGoogleMapsSearch=Class.create(BmlGoogleMaps,{geoTolerance:0.00001,initialize:function($super,mapElementId,delivElementId,collectElementId,selectedCompanyCallbackFn,selectedBuffetCallbackFn){$super(mapElementId);this.tblDeliveries=$(delivElementId);this.tblCollections=$(collectElementId);this.selectedCompanyCallbackFn=selectedCompanyCallbackFn;this.selectedBuffetCallbackFn=selectedBuffetCallbackFn;},setCustomerPostcode:function(customerPostcode){this.customerPostcode=customerPostcode;},clearSearchResults:function(){this.clearMarkers();this.clearTableRows(this.tblDeliveries);this.clearTableRows(this.tblCollections);},clearTableRows:function(tableElement){while(tableElement.childNodes.length>0){tableElement.removeChild(tableElement.childNodes[0]);}},applySearchResults:function(searchLocations){this.clearSearchResults();this.buffetArea=searchLocations.buffetArea;this.searchLocations=searchLocations.list;this.searchLocationsIndex=0;this.addSearchResultsNext();},addSearchResultsNext:function(){var thisObj=this;if(this.searchLocationsIndex<this.searchLocations.length){var index=this.searchLocationsIndex;this.searchLocationsIndex++;var location=this.searchLocations[index];if((Math.abs(location.lat)>this.geoTolerance)||(Math.abs(location.lng)>this.geoTolerance)){var point=new google.maps.LatLng(location.lat,location.lng);this.showAddress(location,point);}else{this.geocodeShowAddress(location);}}else{var bHaveDeliveries=(this.tblDeliveries.childNodes.length>0);var bHaveCollections=(this.tblCollections.childNodes.length==0);var regLink="<a href='mailto:enquiries@bringmelunch.org.uk?subject=Request an office delivery'>Click here</a>";if(this.buffetArea){var strInit=bHaveDeliveries?"If your company isn't listed, we ":"You company hasn't been registered yet, but we ";this.addInteractiveRow(this.tblDeliveries,"Buffet Only","#E3E300","#ECF2B4","Buffet delivery service",strInit+"can still deliver buffet orders directly to your workplace",function(){thisObj.selectBuffetArea();});}
var infoText=(bHaveDeliveries)?"Not in the list? "+regLink+" to tell us where you work.":"Unfortunately there are no <span class='infoHighlight'>workplaces registered</span> with this postcode. "+regLink+" to tell us where you work.";this.addNoLocationsRow(this.tblDeliveries,infoText);if(bHaveCollections){this.addNoLocationsRow(this.tblCollections,"Unfortunately there are no <span class='infoHighlight'>collection locations</span> registered in your area. <a href='mailto:enquiries@bringmelunch.org.uk?subject=Notify me when a service is available'>Click here</a> if you wish to be notified when a service arrives in your area.");}}},onAfterShowAddress:function(location,point){this.addSearchResultsNext();},onAddedCompanyToMarker:function(marker,company){this.addCompanyToTable(marker,company);},onMarkerClick:function(marker){if(getViewDeliveriesElement){var targetElement=getViewDeliveriesElement();if(targetElement!=null){while(targetElement.childNodes.length>0){targetElement.removeChild(targetElement.childNodes[0]);}
for(var index=0;index<marker.companies.length;index++){this.addCompanyToThisTable(marker,marker.companies[index],targetElement);}
openViewDeliveriesForm();}}},addCompanyToTable:function(marker,company){var tblLocation=null;var location=company.locations[0];if(location.locType=="deliver"){tblLocation=this.tblDeliveries;}else{tblLocation=this.tblCollections;}
this.addCompanyToThisTable(marker,company,tblLocation);},selectBuffetArea:function(){var thisObj=this;this.geocodePostcode(this.customerPostcode,function(addressObj){thisObj.selectedBuffetCallbackFn(addressObj);});},addCompanyToThisTable:function(marker,company,tblLocation){var thisObj=this;var location=company.locations[0];var linkText="";var borderCol="";var backCol="";if(location.locType=="deliver"){linkText="Deliver here";borderCol="#298B00";backCol="#91FF98";}else{linkText="Collect here";borderCol="#2B51FF";backCol="#60C2FF";}
this.addInteractiveRow(tblLocation,linkText,borderCol,backCol,location.office,location.loc,function(){thisObj.onSelectedCompany(company);return false;});},addInteractiveRow:function(tblLocation,linkText,borderCol,backCol,rowTitle,rowDesc,onClickFn){var thisObj=this;var officeRow=appendNewElement(tblLocation,"tr","d_norm");var officeCell=appendNewElement(officeRow,"td","maploc",-1,{style:"padding: 4px;"});var officeTable=appendNewElement(officeCell,"table","maploc",-1,{style:"width: 100%;"});var officeBody=appendNewElement(officeTable,"tbody","maploc");var locationRow=appendNewElement(officeBody,"tr","maploc");var linkCell=appendNewElement(locationRow,"td","maplocaction",-1,{rowSpan:'2',style:"text-align: center; border-color: "
+borderCol+"; background-color: "+backCol+";"});linkCell.innerHTML=linkText;var locationCell=appendNewElement(locationRow,"td","maplochead");locationCell.innerHTML=rowTitle;var addrRow=appendNewElement(officeBody,"tr","maploc");var addrCell=appendNewElement(addrRow,"td","maploc",-1,{style:"padding-bottom: 8px;"});addrCell.innerHTML=rowDesc;attachEventToElement(officeCell,"click",onClickFn);attachEventToElement(officeCell,"mouseover",function(){thisObj.setClass([officeCell,officeTable,officeBody,locationRow,addrRow,addrCell],"maphighloc");thisObj.setClass([locationCell],"maphighlochead");thisObj.setClass([linkCell],"maphighlocaction");});attachEventToElement(officeCell,"mouseout",function(){thisObj.setClass([officeCell,officeTable,officeBody,locationRow,addrRow,addrCell],"maploc");thisObj.setClass([locationCell],"maplochead");thisObj.setClass([linkCell],"maplocaction");});},setClass:function(elems,className){for(var n=0;n<elems.length;n++){elems[n].setAttribute('class',className);elems[n].setAttribute('className',className);}},getCompanyLinkText:function(location){if(location.locType=="deliver"){return"Deliver my order here";}else if(location.locType=="collect"){return"I will collect my order from here";}
return"";},onSelectedCompany:function(company){this.selectedCompanyCallbackFn(company.locations);},addNoLocationsRow:function(tblLocation,caption){var officeRow=appendNewElement(tblLocation,"tr","d_norm");var officeCell=appendNewElement(officeRow,"td","mappopup",-1,{colSpan:'2',style:"padding-top: 8px; padding-bottom: 8px; padding-left: 32px;"});officeCell.innerHTML=caption;}});