
if(typeof Autocompleter=='undefined')
throw("Simbora requires including script.aculo.us' controls.js library");Ajax.lastRequestTime={};Ajax.Responders.register({onCreate:function(request){if(!request.options.requestGroup)
request.options.requestGroup='root';Ajax.lastRequestTime[request.options.requestGroup]=request.createTime=Date.now();}});Ajax.Request.prototype.respondToReadyState_=Ajax.Request.prototype.respondToReadyState;Ajax.Request.prototype.respondToReadyState=function(readyState){if(Ajax.lastRequestTime[this.options.requestGroup]==this.createTime){this.respondToReadyState_(readyState);}}
function isLastRequest(request){return Ajax.lastRequestTime==request.request.createTime;}
Effect.PAIRS['show']=['Show','Hide'];Effect.Show=function(element){element=$(element);element.show();};Effect.Hide=function(element){element=$(element);element.hide();};function SMap(){}
SMap.prototype={initializeOnLoad:function(){google.load("maps","2.x");google.setOnLoadCallback(this.initialize.bind(this));},initialize:function(){$('panel_c').innerHTML="Loading map...";if(google!==undefined&&GBrowserIsCompatible()){this.setup();}else{document.write('Browser not compatible to maps.');}
$('panel_c').innerHTML="";},setup:function(){this.map=new google.maps.Map2(document.getElementById("map"));this.geocoder=new GClientGeocoder();this.sp_remoteHtmlFunc=new Hash();this.markers=new SMarkers(this.map);this.directions=new SMap.Directions();this.map.enableScrollWheelZoom();this.map.enableContinuousZoom();this.map.getContainer().style.overflow="hidden";this.map.addMapType(G_PHYSICAL_MAP);this.map.addControl(new GLargeMapControl());var mapControl=new GHierarchicalMapTypeControl();mapControl.clearRelationships();mapControl.addRelationship(G_SATELLITE_MAP,G_HYBRID_MAP,"Labels",true);this.map.addControl(mapControl);this.map.setMapType(G_PHYSICAL_MAP);function SDSwitchControl(){}
SDSwitchControl.prototype=new GControl();SDSwitchControl.prototype.initialize=function(map){var container=new Element('div',{'id':'navdir_switch_control','style':'display:none'});content='<div class="gc"><div class="gci" id="navdir_switch">'+'-</div></div>';Element.insert(container,{bottom:content});map.getContainer().appendChild(container);return container;}
SDSwitchControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(120,7));}
function DateTimeControl(){}
DateTimeControl.prototype=new GControl();DateTimeControl.prototype.initialize=function(map){var container=new Element('div',{'id':'datetime_control','style':'display:none'});content='<div class="gc"><div class="gci" '+'id="navdir_saddrDate">'+'-</div></div>'+'<div class="gc"><div class="gci" '+'id="navdir_saddrTime">'+'-</div></div>'+'<div class="gc"><div class="gci" '+'id="navdir_daddrDate">'+'-</div></div>'+'<div class="gc"><div class="gci" '+'id="navdir_daddrTime">'+'-</div></div>';Element.insert(container,{bottom:content});map.getContainer().appendChild(container);return container;}
DateTimeControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(200,7));}
this.map.addControl(new SDSwitchControl());this.map.addControl(new DateTimeControl());var point=new google.maps.LatLng(35,0);this.map.setCenter(point);this.markers.fitZoom();this.map.setCenter(point);spage.resizeApp();},addMarker:function(marker_id,lat,lng,html_info){var point=new google.maps.LatLng(lat,lng);this.markers.add(marker_id,point,html_info);},addMarker_infoWindowFrom:function(marker_id,lat,lng,remoteHtmlFunc){var point=new google.maps.LatLng(lat,lng);this.markers.add_remoteInfoWindow(marker_id,point,remoteHtmlFunc);},showPlace:function(marker_id,lat,lng,zoom,html_info){this.addMarker(marker_id,lat,lng,html_info);this.map.setZoom(zoom);this.markers.openInfoWindow(marker_id);},showPlace_infoWindowFrom:function(marker_id,lat,lng,zoom,remoteHtmlFunc){this.addMarker_infoWindowFrom(marker_id,lat,lng,remoteHtmlFunc);this.map.setZoom(zoom);this.markers.zoomOn(marker_id);},searchPlace:function(address,remoteHtmlFunc){this.sp_remoteHtmlFunc.set(address,remoteHtmlFunc);this.geocoder.getLocations(address,this.searchPlaceHandle.bind(this));},searchPlaceHandle:function(response){var accuracy,address,country,state,county,city,district,postalCode,street,lat,lng;if(!response||response.Status.code!=200){accuracy=address=country=state=county=city=district=postalCode=street=lat=lng="";}
else{var place=response.Placemark[0];var zooms=[0,4,6,10,12,15,16,16,16,16];var zoom=zooms[place.AddressDetails.Accuracy];accuracy=place.AddressDetails.Accuracy;address=place.address;country=getPlacemarkProperty(place,'CountryNameCode');state=getPlacemarkProperty(place,'AdministrativeAreaName');county=getPlacemarkProperty(place,'SubAdministrativeAreaName');city=getPlacemarkProperty(place,'LocalityName');district=getPlacemarkProperty(place,'DependentLocalityName');postalCode=getPlacemarkProperty(place,'PostalCodeNumber');street=getPlacemarkProperty(place,'ThoroughfareName');lat=place.Point.coordinates[1];lng=place.Point.coordinates[0];}
eval(this.sp_remoteHtmlFunc.get(response.name));this.sp_remoteHtmlFunc.unset(response.name);},clear:function(){this.markers.clearAll();},checkResize:function(){this.map.checkResize();}};SMap.Directions=Class.create({initialize:function(){this.directions=new GDirections(null,null);this.doShow=false;GEvent.addListener(this.directions,"load",this.onLoad.bind(this));},onLoad:function(){this._clearLast();if(this.doShow==true){this._show();this.doShow=false;}},load:function(waypoints){if(waypoints==null){return}
var gwaypoints=new Array();for(var i=0,len=waypoints.length;i<len;++i){var tmp=new GLatLng(waypoints[i][0],waypoints[i][1]);gwaypoints.push(tmp);}
this.directions.loadFromWaypoints(gwaypoints,{locale:'pt_BR',preserveViewport:true,getSteps:true,getPolyline:true});},show:function(waypoints){this.doShow=true;this.load(waypoints);},_clearLast:function(){if(this.lastPoly){smap.map.removeOverlay(this.lastPoly);}},_show:function(){var poly=this.directions.getPolyline();var bounds=this.directions.getBounds();smap.map.addOverlay(poly);this.lastPoly=poly;}});SMap.SearchPlace=Class.create({initialize:function(address,options){if(address.length<5)
return;this.onComplete=options.onComplete;this.evalScripts=options.evalScripts;smap.geocoder.getLocations(address,this.searchPlaceHandle.bind(this));},searchPlaceHandle:function(response){if(!response||response.Status.code!=200){var place={accuracy:'',address:'',country:'',state:'',county:'',city:'',district:'',postalCode:'',street:'',lat:'',lng:''};}else{var place={};var _place=response.Placemark[0];var zooms=[0,4,6,10,12,15,16,16,16,16];place.zoom=zooms[_place.AddressDetails.Accuracy];place.accuracy=_place.AddressDetails.Accuracy;place.address=_place.address;place.country=getPlacemarkProperty(_place,'CountryNameCode');place.state=getPlacemarkProperty(_place,'AdministrativeAreaName');place.county=getPlacemarkProperty(_place,'SubAdministrativeAreaName');place.city=getPlacemarkProperty(_place,'LocalityName');place.district=getPlacemarkProperty(_place,'DependentLocalityName');place.postalCode=getPlacemarkProperty(_place,'PostalCodeNumber');place.street=getPlacemarkProperty(_place,'ThoroughfareName');place.lat=_place.Point.coordinates[1];place.lng=_place.Point.coordinates[0];}
if(!this.evalScripts)
this.onComplete(place);else
eval(this.onComplete);}});function SMarkers(map){this.map=map;this.markers=new Hash();this.html_info=new Hash();}
SMarkers.prototype={clearAll:function(){this.map.clearOverlays();this.markers=new Hash();this.html_info=new Hash();},clear:function(marker_id){if(this.markers.get(marker_id)!=undefined){this.map.removeOverlay(this.markers.get(marker_id));}},_add:function(marker_id,point){if(this.markers.get(marker_id)!=undefined){this.clear(marker_id)}
this.markers.set(marker_id,new google.maps.Marker(point));GEvent.addListener(this.markers.get(marker_id),'infowindowopen',this.onOpenInfoWindow.bind(this));this.map.addOverlay(this.markers.get(marker_id));},add:function(marker_id,point,html_info){this._add(marker_id,point);this.html_info.set(marker_id,html_info);google.maps.Event.addListener(this.markers.get(marker_id),"click",function(){smap.markers.openInfoWindow(marker_id);});},add_remoteInfoWindow:function(marker_id,point,remoteHtmlFunc){this._add(marker_id,point);eval(remoteHtmlFunc);},add_remoteInfoWindow2:function(marker_id,html_info){this.html_info.set(marker_id,html_info);google.maps.Event.addListener(this.markers.get(marker_id),"click",function(){smap.markers.openInfoWindow(marker_id);});},load:function(data){this.loadFromHandler(data);},loadFrom:function(url,opt){if(opt.clear){this.clearAll();}
if(opt.fit_zoom){google.maps.DownloadUrl(url,this.loadFromHandler_fitZoom);}else{google.maps.DownloadUrl(url,this.loadFromHandler);}},loadFromHandler:function(data){var markers=eval(data);for(var i=0;i<markers.length;++i){var point=new google.maps.LatLng(parseFloat(markers[i]["lat"]),parseFloat(markers[i]["lng"]));smap.markers.add(markers[i]["id"],point,markers[i]["html_info"]);}},loadFromHandler_fitZoom:function(data){smap.markers.loadFromHandler(data);smap.markers.fitZoom();},loadFromXmlHandler:function(data){var xml=google.maps.Xml.parse(data);var markers=xml.documentElement.getElementsByTagName("marker");for(var i=0;i<markers.length;i++){}},fitZoom:function(){var bounds=new google.maps.LatLngBounds();this.markers.each(function(pair){bounds.extend(pair.value.getLatLng());});var zoom=this.map.getBoundsZoomLevel(bounds);this.map.setZoom(zoom);this.map.setCenter(bounds.getCenter());},zoomOn:function(marker_id){this.zoomOnWith(marker_id,14);},zoomOnWith:function(marker_id,zoom){this.map.setZoom(zoom);this.map.setCenter(this.markers.get(marker_id).getLatLng());},openInfoWindow:function(marker_id){this._tmp_marker_id=marker_id;this.markers.get(marker_id).openInfoWindowHtml(this.html_info.get(marker_id));},onOpenInfoWindow:function(marker){this.resizeInfoWindow(this._tmp_marker_id,'place_'+this._tmp_marker_id);},resizeInfoWindow:function(marker_id,resize_as_id){var infoWindow=this.map.getInfoWindow();var newSize=$(resize_as_id).getDimensions();infoWindow.reset(this.markers.get(marker_id).getLatLng(),infoWindow.getTabs(),new GSize(newSize.width,newSize.height),null,null);},resizeInfoWindowToSmall:function(marker_id,resize_as_id){var infoWindow=this.map.getInfoWindow();var div=$('place_'+marker_id);div.addClassName('small');div.removeClassName('big');infoWindow.reset(this.markers.get(marker_id).getLatLng(),infoWindow.getTabs(),new GSize(250,120),null,null);},resizeInfoWindowToBig:function(marker_id,resize_as_id){var infoWindow=this.map.getInfoWindow();var div=$('place_'+marker_id);div.removeClassName('small');div.addClassName('big');infoWindow.reset(this.markers.get(marker_id).getLatLng(),infoWindow.getTabs(),new GSize(300,260),null,null);}};function getPlacemarkProperty(placemark,property_name){for(var property in placemark){if((property==property_name)){return String(placemark[property]);}else if(typeof(placemark[property])=='object'){var r=this.getPlacemarkProperty(placemark[property],property_name);if(r!=null)return r;}}
return null;}
function SPage(){}
SPage.prototype={resizeApp:function(){var h=this.getMainHeight();$('map').style.height=h+'px';$('panel_c').style.height=h+'px';smap.checkResize();},getMainHeight:function(){document.viewport.getDimensions();document.viewport.getHeight()
return document.viewport.getHeight()-
$('header').getHeight()-
$('tab').getHeight()-
$('footer').getHeight()-
5;},getMainWidth:function(){return document.documentElement.clientWidth;},setPanelStyle:function(style){if(style=='fullMap'){$('map').addClassName('fullSize');$('main').removeClassName('fullSize');smap.checkResize();}else if(style=='split'){$('map').removeClassName('fullSize');$('panel').removeClassName('fullSize');Element.show('map');smap.checkResize();}else if(style=='noMap'){$('map').removeClassName('fullSize');$('panel').addClassName('fullSize');Element.hide('map');}},setActiveTab:function(element){$$('#tab span').invoke('removeClassName','active');$(element).addClassName('active');},setActivePanel:function(element){$$('#panel > div').invoke('hide');$(element).show();},myridesShow:function(){this.setPanelStyle('split');this.setActiveTab('myrides');this.setActivePanel('panel_c');},myplacesShow:function(){this.setPanelStyle('split');this.setActiveTab('myplaces');this.setActivePanel('panel_c');},mycontactsShow:function(){this.setPanelStyle('split');this.setActiveTab('mycontacts');this.setActivePanel('panel_c');},showPlace:function(infoWindowId,options){smap.markers.openInfoWindow(infoWindowId);if(options.zoom){smap.markers.zoomOn(infoWindowId);}},routeVehicleTypeUpdate:function(value){if(value=='person'){$('route_seats').hide();}
else if(value=='car'){$('route_seats').show();}},showRoute:function(infoWindowId,waypoints,options){smap.markers.openInfoWindow(infoWindowId);if(options.drawPolyline){smap.directions.show(waypoints);}else{smap.directions.load(waypoints);}
if(options.zoom){smap.markers.zoomOn(infoWindowId);}},settingsShow:function(){Element.hide('panel_c');this.setPanelStyle('noMap');$$('#settings_tab span').invoke('removeClassName','active');Element.show('settings');},settingsCancel:function(){Element.hide('settings');this.setPanelStyle('split');Element.show('panel_c');},accountSettingsShow:function(){this.settingsShow();$('account_settings_tab').addClassName('active');},securitySettingsShow:function(){this.settingsShow();$('security_settings_tab').addClassName('active');},talktousShow:function(){Element.hide('panel_c');this.setPanelStyle('noMap');Element.show('talktous');},talktousCancel:function(){Element.hide('talktous');this.setPanelStyle('split');Element.show('panel_c');},loginShow:function(){Element.show('login_c');Element.hide('signup_c');Element.hide('reset_passwd_c');$('login').removeClassName('bigger');},signupShow:function(){Element.hide('login_c');Element.show('signup_c');Element.hide('reset_passwd_c');$('login').addClassName('bigger');},resetPasswdShow:function(){$('login').addClassName('bigger');Element.hide('login_c');Element.hide('signup_c');Element.show('reset_passwd_c');},myrideShow:function(){Element.show('myride');Element.hide('route_form');},routeFormShow:function(){Element.hide('myride');Element.show('route_form');},showIntoMapOpenInfoWindow:function(marker_id,to_be_showed_id,resize_as_id){$(to_be_showed_id).show();smap.markers.resizeInfoWindow(marker_id,resize_as_id);},hideIntoMapOpenInfoWindow:function(marker_id,to_be_showed_id,resize_as_id){$(to_be_showed_id).hide();smap.markers.resizeInfoWindow(marker_id,resize_as_id);}};MyInPlaceEditor=Class.create(Ajax.InPlaceEditor,{initialize:function($super,element,options){options=Object.extend({okControl:false,cancelControl:'link',rows:1},options||{});$super(element,'',options);},postProcessEditField:function($super){$super();if(this.options.onPostProcessEditField)
this.options.onPostProcessEditField(this);},checkForEscapeOrReturn:function($super,e){$super(e);if(this.options.onKeyDown)
this.options.onKeyDown(this,e);},getText:function(){return this.editor_value||'';},handleFormSubmission:function(e){this.editor_value=$F(this._controls.editor);if(this.options.onFormSubmission)
this.options.onFormSubmission(this,e,this.editor_value);if(e)Event.stop(e);return false;},wrapUp:function($super){$super();if(this.options.onWrapUp)
this.options.onWrapUp(this);}});SPage.AjaxForm=Class.create({initialize:function(url,remoteFuncOptions,options){this.remoteFuncOptions=remoteFuncOptions;this.options=options;this.url=url;if(!this.url)
alert('missing url');this._parameters={};},get:function(name){return this._parameters[name];},set:function(name,value){this._parameters[name]=value;},extend:function(parms){this._parameters=Object.extend(this._parameters,parms);},render:function(){var _parameters=Object.clone(this._parameters);this._prototype2railsparam(_parameters);this.parameters=new Hash(_parameters);},toQueryString:function(){this.render();return this.parameters.toQueryString();},submit:function(options){if(this.options.before)
eval(this.options.before);options=Object.extend(Object.clone(this.remoteFuncOptions),options);options=Object.extend(options,{parameters:this.toQueryString()+(options.parameters?'&'+options.parameters:'')});new Ajax.Request(this.url,options);},_prototype2railsparam:function(p){redo=false;for(var i in p){if(typeof(p[i])=='object'){for(var j in p[i]){p[i+'['+j+']']=p[i][j];}
delete p[i];redo=true;}}
if(redo){this._prototype2railsparam(p);}}});SPage.SlideDownMenu=Class.create({initialize:function(elementsSelector,options){this.options=options;this.elements=$$(elementsSelector);this.onClickElements=$$(elementsSelector+' > a');if(this.elements.length>0){this.setup();this.show(this.elements[0]);}},setup:function(){this.bonClick=this.onClick.bindAsEventListener(this);this.onClickElements.invoke('observe','click',this.bonClick);},onClick:function(event){var element=Event.element(event);this.show(element.ancestors()[0]);Event.stop(event);},show:function(element){if(element!=this.lastActiveSlideDownMenuElement){if(this.lastActiveSlideDownMenuElement!=undefined){this.lastActiveSlideDownMenuElement.removeClassName('active');this.lastActiveSlideDownMenuElement.select(".slider_content")[0].hide();}
element.addClassName('active');element.select(".slider_content")[0].show();this.lastActiveSlideDownMenuElement=element;if(this.options.onShow){if(this.options.evalOnShow){eval(this.options.onShow);}
else{this.options.onShow(element);}}}}});SPage.SearchPlaceField_=Class.create({initialize:function(element,options){this.element=$(element);this.update=$(this.element.id+'_auto_complete');this.array=options.autocompleterData;this.options=options;this.options.afterUpdateElement=this.onAutocompleterUpdateElement.bind(this);this.autocompleterText='';this.setObservers();this.setAutocomplete();},setObservers:function(){Event.observe(this.element,'change',this.onChange.bindAsEventListener(this));},setAutocomplete:function(){this.autocompleter=new Autocompleter.Local(this.element.id,this.update.id,this.array,this.options);},onChange:function(event){var element=Event.element(event);if(this.autocompleter.active==true)
return;if(element.value==this.autocompleterText)
return;var options={};if(!this.options.evalScripts){options.onComplete=this.onSearchedPlaceWrapper.bind(this);options.evalScripts=false;new SMap.SearchPlace(element.value,options);}else{options.onComplete=this.options.onSearchedPlace;options.evalScripts=true;new SMap.SearchPlace(element.value,options);}},onAutocompleterUpdateElement:function(text,li){this.autocompleterText=text.value;if(this.options.inPlaceEdit)
this.ipe.inPlaceEditToggle({});if(!this.options.evalScripts)
this.options.onAutoCompletedPlace(this.element,text,li);else
eval(this.options.onAutoCompletedPlace);},onSearchedPlaceWrapper:function(place){if(this.options.inPlaceEdit)
this.ipe.inPlaceEditToggle({});this.options.onSearchedPlace(this.element,place);}});SPage.SearchPlaceField=Class.create({initialize:function(ajaxForm,searchPlaceOptions,options){this.ajaxForm=ajaxForm;this.options=options;this.searchPlaceOptions=searchPlaceOptions;this.setup();},setup:function(){this.ajaxForm.set('addr',{});var options=Object.extend({frequency:0.1,partialChars:1,ignoreCase:true,evalScripts:false,onAutoCompletedPlace:this.onAutoCompletedPlace.bind(this),onSearchedPlace:this.onSearchedPlace.bind(this)},this.searchPlaceOptions);new SPage.SearchPlaceField_('addr',Object.extend({},options));},onAutoCompletedPlace:function(element,text,li){id=li.down('span.id').innerHTML;lat=li.down('span.lat').innerHTML;lng=li.down('span.lng').innerHTML;this.ajaxForm.get(element.id).place={id:id};this.showPlace(element.id,lat,lng);this.isDatetimeSetup=false;this.ajaxForm.submit();},onSearchedPlace:function(element,place){this.ajaxForm.get(element.id).place=place;this.showPlace(element.id,place.lat,place.lng);this.isDatetimeSetup=false;this.ajaxForm.submit();},showPlace:function(tag,lat,lng){smap.addMarker(tag,lat,lng,'Loading...');smap.markers.zoomOnWith(tag,8);}});SPage.IpeSearchPlaceField=Class.create(SPage.SearchPlaceField,{initialize:function($super,ajaxForm,searchPlaceOptions,options){$super(ajaxForm,searchPlaceOptions,options);this.ipeNeedingWrapUp={};},onAutoCompletedPlace:function($super,element,text,li){this.ipeNeedingWrapUp[element.id]=true;this.ipe.handleFormSubmission();$super(element,text,li);},onSearchedPlace:function($super,element,place){this.ipeNeedingWrapUp[element.id]=true;$super(element,place);},setup:function(){this.bonIpeFormCustomization=this.onIpeFormCustomization.bind(this);this.bonIpePostProcessEditField=this.onIpePostProcessEditField.bind(this);this.bonIpeSubmission=this.onIpeSubmission.bind(this);this.bonIpeWrapUp=this.onIpeWrapUp.bind(this);this.ipe=new MyInPlaceEditor('navdir_saddr_place',{onFormCustomization:this.bonIpeFormCustomization,onPostProcessEditField:this.bonIpePostProcessEditField,onFormSubmission:this.bonIpeSubmission,onWrapUp:this.bonIpeWrapUp,formClassName:this.options.ipeFormClassName,tag:'saddr'});},onIpeFormCustomization:function(ipe,form){var tag=ipe.options.tag;var autoCompleteElement=new Element('div',{'id':tag+'_auto_complete','class':'autocomplete'});form.appendChild(autoCompleteElement);var inputElement=form.childElements()[0];inputElement.id=tag;var time=$('navdir_'+tag+'_time');var time_label=$('navdir_'+tag+'_time_label')
time.addClassName('on_place_edit_mode');time_label.addClassName('on_place_edit_mode');},onIpePostProcessEditField:function(ipe){var tag=ipe.options.tag;var options=Object.extend({frequency:0.1,partialChars:1,ignoreCase:true,evalScripts:false,onAutoCompletedPlace:this.onAutoCompletedPlace.bind(this),onSearchedPlace:this.onSearchedPlace.bind(this)},this.searchPlaceOptions);this[tag].place=new SPage.SearchPlaceField_(tag,options);if(tag=='saddr')
Event.observe($(tag),'keydown',this.onIpePlaceKeyDown.bindAsEventListener(this));},onIpeSubmission:function(ipe,e,value){},onIpeKeyDown:function(e){if(e.keyCode==Event.KEY_TAB){this.daddr.ipe_place.enterEditMode(e);}},onIpeWrapUp:function(ipe){if(this.options.onIpeWrapUp)
this.options.onIpeWrapUp(ipe);},ipeWrapUpWhoNeeds:function(){for(var i in this.ipeNeedingWrapUp){if(this.ipeNeedingWrapUp[i]){this[i].ipe_place.wrapUp();delete this.ipeNeedingWrapUp[i];}}}});SPage.NavDirFields2=Class.create({initialize:function(ajaxForm,searchPlaceOptions,datetimeOptions,options){this.ajaxForm=ajaxForm;this.searchPlaceOptions=searchPlaceOptions;this.datetimeSetup(datetimeOptions);this.ipeNeedingWrapUp={};}});SPage.NavDirFields=Class.create(SPage.SearchPlaceField,{initialize:function($super,ajaxForm,searchPlaceOptions,datetimeOptions,options){$super(ajaxForm,searchPlaceOptions,options);this.datetimeSetup(datetimeOptions);this.ipeNeedingWrapUp={place:{},time:{}};},onAutoCompletedPlace:function($super,element,text,li){this.ipeNeedingWrapUp.place[element.id]=true;this[element.id].ipe_place.handleFormSubmission();$super(element,text,li);},onSearchedPlace:function($super,element,place){this.ipeNeedingWrapUp.place[element.id]=true;$super(element,place);},setup:function(){this.saddr={};this.daddr={};this.ajaxForm.set('saddr',{});this.ajaxForm.set('daddr',{});this.bonIpePlaceFormCustomization=this.onIpePlaceFormCustomization.bind(this);this.bonIpePlacePostProcessEditField=this.onIpePlacePostProcessEditField.bind(this);this.bonIpePlaceWrapUp=this.onIpePlaceWrapUp.bind(this);this.saddr.ipe_place=new MyInPlaceEditor('navdir_saddr_place',{onFormCustomization:this.bonIpePlaceFormCustomization,onPostProcessEditField:this.bonIpePlacePostProcessEditField,onWrapUp:this.bonIpePlaceWrapUp,formClassName:this.options.ipePlaceFormClassName,okControl:'button',inputExample:this.options.placeExample,tag:'saddr'});this.daddr.ipe_place=new MyInPlaceEditor('navdir_daddr_place',{onFormCustomization:this.bonIpePlaceFormCustomization,onPostProcessEditField:this.bonIpePlacePostProcessEditField,onWrapUp:this.bonIpePlaceWrapUp,formClassName:this.options.ipePlaceFormClassName,okControl:'button',inputExample:this.options.placeExample,tag:'daddr'});this.bonIpeTimeFormCustomization=this.onIpeTimeFormCustomization.bind(this);this.bonIpeTimePostProcessEditField=this.onIpeTimePostProcessEditField.bind(this);this.bonIpeTimeWrapUp=this.onIpeTimeWrapUp.bind(this);this.bonIpeTimeSubmission=this.onIpeTimeSubmission.bind(this);this.saddr.ipe_time=new MyInPlaceEditor('navdir_saddr_time',{onFormCustomization:this.bonIpeTimeFormCustomization,onPostProcessEditField:this.bonIpeTimePostProcessEditField,onFormSubmission:this.bonIpeTimeSubmission,onWrapUp:this.bonIpeTimeWrapUp,formClassName:this.options.ipeTimeFormClassName,okControl:'button',inputExample:this.options.timeExample,tag:'saddr'});this.daddr.ipe_time=new MyInPlaceEditor('navdir_daddr_time',{onFormCustomization:this.bonIpeTimeFormCustomization,onPostProcessEditField:this.bonIpeTimePostProcessEditField,onFormSubmission:this.bonIpeTimeSubmission,onWrapUp:this.bonIpeTimeWrapUp,formClassName:this.options.ipeTimeFormClassName,okControl:'button',inputExample:this.options.timeExample,tag:'daddr'});},onIpePlaceFormCustomization:function(ipe,form){var tag=ipe.options.tag;var autoCompleteElement=new Element('div',{'id':tag+'_auto_complete','class':'autocomplete'});form.appendChild(autoCompleteElement);var inputElement=form.childElements()[0];inputElement.id=tag;var time=$('navdir_'+tag+'_time');var time_label=$('navdir_'+tag+'_time_label')
time.addClassName('on_place_edit_mode');time_label.addClassName('on_place_edit_mode');},onIpePlacePostProcessEditField:function(ipe){var tag=ipe.options.tag;var options=Object.extend({frequency:0.1,partialChars:1,ignoreCase:true,evalScripts:false,onAutoCompletedPlace:this.onAutoCompletedPlace.bind(this),onSearchedPlace:this.onSearchedPlace.bind(this)},this.searchPlaceOptions);this[tag].place=new SPage.SearchPlaceField_(tag,options);if(tag=='saddr'){Event.observe($(tag),'keydown',this.onIpePlaceKeyDown.bindAsEventListener(this));}
$$('#navdir_'+tag+'_place-inplaceeditor .editor_cancel_link')[0].insert({before:ipe.options.inputExample});},onIpePlaceSubmission:function(ipe,e,value){},onIpePlaceKeyDown:function(e){if(e.keyCode==Event.KEY_TAB){this.daddr.ipe_place.enterEditMode(e);}},onIpePlaceWrapUp:function(ipe){var tag=ipe.options.tag;var time=$('navdir_'+tag+'_time');var time_label=$('navdir_'+tag+'_time_label')
time.removeClassName('on_place_edit_mode');time_label.removeClassName('on_place_edit_mode');},onIpeTimeFormCustomization:function(ipe,form){var tag=ipe.options.tag;var label=$('navdir_'+tag+'_time_label')
label.addClassName('on_edit_mode');form.insert(ipe.options.inputExample);},onIpeTimePostProcessEditField:function(ipe){var tag=ipe.options.tag;$$('#navdir_'+tag+'_time-inplaceeditor .editor_cancel_link')[0].insert({before:ipe.options.inputExample});},onIpeTimeWrapUp:function(ipe){var tag=ipe.options.tag;var label=$('navdir_'+tag+'_time_label')
label.removeClassName('on_edit_mode');},onIpeTimeSubmission:function(ipe,e,value){this.ajaxForm.get(ipe.options.tag).time=value;this.ipeNeedingWrapUp.time[ipe.options.tag]=true;if(ipe.options.tag=='saddr'){this.ajaxForm.get('daddr').time={};}
this.ajaxForm.submit();},ipeWrapUpWhoNeeds:function(){for(var i in this.ipeNeedingWrapUp){for(var j in this.ipeNeedingWrapUp[i]){if(this.ipeNeedingWrapUp[i][j]){this[j][i=='place'?'ipe_place':'ipe_time'].wrapUp();delete this.ipeNeedingWrapUp[i][j];}}}},placeIpeOnClick:function(event){if(!this.placeIpeFirstTime){var element=Event.element(event);var tag=element.ancestors()[1].id;if(tag[7]=='s'){this.daddr.place.ipe.inPlaceEditToggle({});}
else{this.saddr.place.ipe.inPlaceEditToggle({});}
this.placeIpeFirstTime=true;}},datetimeSetup:function(options){if(spage.navdir_saddrDate)
spage.navdir_saddrDate.destroy();if(spage.navdir_saddrTime)
spage.navdir_saddrTime.destroy();if(spage.navdir_daddrDate)
spage.navdir_daddrDate.destroy();if(spage.navdir_daddrTime)
spage.navdir_daddrTime.destroy();$('datetime_control').show();options.callback=this.datetimeAdditionalParameters.bind(this);options.onShow=this.onDateTimeShow;options.onHide=this.onDateTimeHide;options.afterUpdateElement=this.onDateTimeChosen.bind(this);this.saddrDate=new Ajax.SelectBox('navdir_saddrDate',options.url,Object.extend({requestGroup:'saddrDate'},options));this.saddrTime=new Ajax.SelectBox('navdir_saddrTime',options.url,Object.extend({requestGroup:'saddrTime'},options));$('navdir_saddrDate').hide()
$('navdir_saddrTime').hide()
this.daddrDate=new Ajax.SelectBox('navdir_daddrDate',options.url,Object.extend({requestGroup:'daddrDate'},options));this.daddrTime=new Ajax.SelectBox('navdir_daddrTime',options.url,Object.extend({requestGroup:'daddrTime'},options));spage.navdir_saddrDate=this.saddrDate;spage.navdir_saddrTime=this.saddrTime;spage.navdir_daddrDate=this.daddrDate;spage.navdir_daddrTime=this.daddrTime;$('datetime_control').hide();},datetimeAdditionalParameters:function(element,entry){var ret_param=this.ajaxForm.toQueryString();if(element.id=='navdir_saddrDate'||element.id=='navdir_saddrTime')
ret_param+='&group=source_';else if(element.id=='navdir_daddrDate'||element.id=='navdir_daddrTime')
ret_param+='&group=destination_';if(element.id=='navdir_saddrDate'||element.id=='navdir_daddrDate')
ret_param+='day';else if(element.id=='navdir_saddrTime'||element.id=='navdir_daddrTime')
ret_param+='hour';return ret_param;},switchSetup:function(options){if(spage.navdir_switchControl)
spage.navdir_switchControl.destroy();$('navdir_switch_control').show();spage.navdir_switchControl=new SelectBox.Local('navdir_switch',{array:options.switchData,afterUpdateElement:this.onSwitched.bind(this)});$('navdir_switch_control').hide();},switchShow:function(){if(!this.isSwitchSetup){this.switchSetup(this.options);this.isSwitchSetup=true;$('navdir_switch_control').show();}},datetimeShow:function(){if(!this.isDatetimeSetup){this.isDatetimeSetup={};this.saddrDate.retrieveChoices();this.saddrTime.retrieveChoices();this.daddrDate.retrieveChoices();this.daddrTime.retrieveChoices();$('datetime_control').show();}},onSwitched:function(text,li){tag=li.down('span.tag').innerHTML;if(tag=='saddr'){$('navdir_daddrDate').hide()
$('navdir_saddrDate').show()
$('navdir_daddrTime').hide()
$('navdir_saddrTime').show()}
else if(tag=='daddr'){$('navdir_daddrDate').show()
$('navdir_saddrDate').hide()
$('navdir_daddrTime').show()
$('navdir_saddrTime').hide()}
smap.markers.zoomOn(tag);},onDateTimeChosen:function(element,li){if(!this.isDatetimeSetup[element.id]){this.isDatetimeSetup[element.id]=true;return;}
value=li.down('span.value').innerHTML;this.ajaxForm.get('saddr').time={};this.ajaxForm.get('daddr').time={};this.ajaxForm.get(element.id.indexOf('saddr')!=-1?'saddr':'daddr').time=value;this.ajaxForm.submit();if(element.id.indexOf('Date')!=-1){if(element.id.indexOf('saddr')!=-1)
this.saddrTime.retrieveChoices();else
this.daddrTime.retrieveChoices();}},onDateTimeShow:function(update){smap.map.disableScrollWheelZoom();update.show();update.scrollTop=update.lastScrollTop;Effect.Appear(update,{duration:0.15});},onDateTimeHide:function(update){new Effect.Fade(update,{duration:0.15});update.lastScrollTop=update.scrollTop;update.scrollTop=0;smap.map.enableScrollWheelZoom();},showPlace:function(tag,lat,lng){smap.addMarker(tag,lat,lng,'Loading...');if(tag=='saddr')
smap.markers.zoomOnWith(tag,8);}});SPage.SortableStops=Class.create({initialize:function(containerElement,routeId,ajaxForm,options){this.ajaxForm=ajaxForm;this.ajaxForm.set('route',{id:routeId});this.options=options;Sortable.create(containerElement,{onChange:this.onChange.bind(this),onUpdate:this.onUpdate.bind(this)});this.setupTimeWorkAround();this.setupLatlngs();$(containerElement).addClassName('sortable');},setupTimeWorkAround:function(){this.times=new Array();for(var i=0,len=this.options.stopsData.length;i<len;++i){this.times.push(this.options.stopsData[i].time);}},setupLatlngs:function(){this.latlngs={};for(var i=0,len=this.options.stopsData.length;i<len;++i){this.latlngs[this.options.stopsData[i].id]=new Array(this.options.stopsData[i].lat,this.options.stopsData[i].lng);}},onChange:function(list){var waypoints=this.getWaypoints(list);smap.directions.show(waypoints);},onUpdate:function(list){this.updateAjaxForm(list);this.ajaxForm.submit();},getWaypoints:function(element){var containerElement=$(element.id).ancestors()[0];var ids=containerElement.childElements().pluck('id');var waypoints=new Array();for(var i=0,len=ids.length;i<len;++i){waypoints.push(this.latlngs[parseInt(ids[i].gsub(/stop_/,''))]);}
return waypoints;},updateAjaxForm:function(containerElement){this._stops={};containerElement.childElements().each(this.updateAjaxFormEach.bind(this));this.ajaxForm.set('stops',this._stops);},updateAjaxFormEach:function(e,index){var id=e.id.sub(/stop_/,'');var time=this.estimateTime(index);this._stops[index]={id:id,time:time};},estimateTime:function(i){return this.times[i];}});function getHtmlFrom(ajaxEscapedRemoteFunction){var str;eval(ajaxEscapedRemoteFunction);return str;}
spage=new SPage();smap=new SMap();