
var cookieProvider=null;var alertWindow=null;var EVENT_REFRESH_TIME=1800000;var RELOAD_ON_ERROR_TIME=60000;var errorLoadMsg='<span style="color:red">Load error.</span>';var eventStore=null;var ferryStore=null;var weatherStore=null;var webcamStore=null;var allItemsFlagArray=new Array("(All Districts)","(All Routes)","(All Routes)");var allItemsProp={district:'(All Districts)',road:'(All Routes)',popularRoute:'(All Routes)'};var map;var MIN_ZOOM=5;var MAX_ZOOM=13;var startLat=54.8833;var startLong=-122.6667;var startZoom=MIN_ZOOM;var prevLL=null;var prevZoom=null;var MAX_LAT=68;var MIN_LAT=47;var MIN_LONG=-150;var MAX_LONG=-100;var mapPanelGutterWidth=3;var mapPanelGutterHeight=28;var insetMap=null;var mapWindow=null;var insetPrevLL=null;var insetPrevZoom=null;var icon_road_cond=new google.maps.MarkerImage("images/map/road.png",new google.maps.Size(33,33),null,new google.maps.Point(16,16));var icon_road_cond_major=new google.maps.MarkerImage("images/map/RoadCondition_major.png",new google.maps.Size(33,33),null,new google.maps.Point(16,16));var icon_road_cond_cluster=new google.maps.MarkerImage("images/map/roads.png",new google.maps.Size(33,33),null,new google.maps.Point(16,16));var icon_road_cond_major_cluster=new google.maps.MarkerImage("images/map/RoadCondition_major_cluster.png",new google.maps.Size(33,33),null,new google.maps.Point(16,16));var icon_incident=new google.maps.MarkerImage("images/map/incident.png",new google.maps.Size(32,32),null,new google.maps.Point(16,16));var icon_incident_major=new google.maps.MarkerImage("images/map/Incident_major.png",new google.maps.Size(32,32),null,new google.maps.Point(16,16));var icon_incident_cluster=new google.maps.MarkerImage("images/map/incidents.png",new google.maps.Size(32,32),null,new google.maps.Point(16,16));var icon_incident_major_cluster=new google.maps.MarkerImage("images/map/Incident_major_cluster.png",new google.maps.Size(32,32),null,new google.maps.Point(16,16));var icon_current_event=new google.maps.MarkerImage("images/map/cone.png",new google.maps.Size(30,33),null,new google.maps.Point(15,16));var icon_current_event_major=new google.maps.MarkerImage("images/map/Event_major.png",new google.maps.Size(30,33),null,new google.maps.Point(15,16));var icon_current_event_cluster=new google.maps.MarkerImage("images/map/cones.png",new google.maps.Size(31,33),null,new google.maps.Point(15,16));var icon_current_event_major_cluster=new google.maps.MarkerImage("images/map/Event_major_cluster.png",new google.maps.Size(31,33),null,new google.maps.Point(15,16));var icon_future_event=new google.maps.MarkerImage("images/map/future.png",new google.maps.Size(30,33),null,new google.maps.Point(15,16));var icon_future_event_major=new google.maps.MarkerImage("images/map/future_major.png",new google.maps.Size(31,33),null,new google.maps.Point(15,16));var icon_future_event_cluster=new google.maps.MarkerImage("images/map/futures.png",new google.maps.Size(30,33),null,new google.maps.Point(15,16));var icon_future_event_major_cluster=new google.maps.MarkerImage("images/map/future_major_cluster.png",new google.maps.Size(31,33),null,new google.maps.Point(15,16));var icon_ferry=new google.maps.MarkerImage("images/map/ferry.png",new google.maps.Size(34,34),null,new google.maps.Point(17,17));var icon_ferry_cluster=new google.maps.MarkerImage("images/map/ferries.png",new google.maps.Size(38,38),null,new google.maps.Point(19,19));var icon_weather=new google.maps.MarkerImage("images/map/weather.png",new google.maps.Size(34,34),null,new google.maps.Point(17,17));var icon_weather_major=new google.maps.MarkerImage("images/map/weather_major.png",new google.maps.Size(42,29),null,new google.maps.Point(21,15));var icon_weather_cluster=new google.maps.MarkerImage("images/map/weathers.png",new google.maps.Size(34,34),null,new google.maps.Point(17,17));var icon_weather_major_cluster=new google.maps.MarkerImage("images/map/weathers_major.png",new google.maps.Size(42,29),null,new google.maps.Point(21,15));var icon_cam=new google.maps.MarkerImage("images/map/cam.png",new google.maps.Size(34,28),null,new google.maps.Point(17,14));var icon_cam_e=new google.maps.MarkerImage("images/map/cam_e.png",new google.maps.Size(34,28),null,new google.maps.Point(17,14));var icon_cam_w=new google.maps.MarkerImage("images/map/cam_w.png",new google.maps.Size(34,28),null,new google.maps.Point(17,14));var icon_cam_n=new google.maps.MarkerImage("images/map/cam_n.png",new google.maps.Size(28,34),null,new google.maps.Point(14,17));var icon_cam_s=new google.maps.MarkerImage("images/map/cam_s.png",new google.maps.Size(28,34),null,new google.maps.Point(14,17));var icon_cam_ne=new google.maps.MarkerImage("images/map/cam_ne.png",new google.maps.Size(38,38),null,new google.maps.Point(19,19));var icon_cam_nw=new google.maps.MarkerImage("images/map/cam_nw.png",new google.maps.Size(38,38),null,new google.maps.Point(19,19));var icon_cam_se=new google.maps.MarkerImage("images/map/cam_se.png",new google.maps.Size(38,38),null,new google.maps.Point(19,19));var icon_cam_sw=new google.maps.MarkerImage("images/map/cam_sw.png",new google.maps.Size(38,38),null,new google.maps.Point(19,19));var icon_cam_cluster=new google.maps.MarkerImage("images/map/cams.png",new google.maps.Size(38,32),null,new google.maps.Point(19,16));function startcycle()
{$("#cycler").after('<div id="pager" />').cycle({fx:'fade',timeout:5000,speed:0000,cleartype:true,cleartypeNoBg:true,pager:'#pager',pause:0,delay:2000});positionWelcomePagesImagery();}
function pausecycle(){$("#cycler").cycle('pause');}
function resumecycle(){$("#cycler").cycle('resume');}
function positionWelcomePagesImagery(){var PSAoverlap=75;var PSAdiff=$('#psacontainer').width()-PSAoverlap;if(PSAdiff<0){PSAdiff=0;}
var Left=($(window).width()/2)-($('#cyclewrapper').outerWidth()/2)-PSAdiff-75;if(Left<0){Left=0;}
Left=0;$('#psacontainer').css("left",Left);$('#cyclewrapper').css("left",Left+PSAdiff);}
function PSA_mouseovertoggle(el_id,img){var a=Ext.query("#"+el_id+" img");a&&a[0]&&(a[0].src=img);}
function ExpandAll(expand){var gridPanel=Ext.getCmp('listView');var view=gridPanel.getView();if(expand){view.expandAllGroups();}else{view.collapseAllGroups();}}
function zoomToBounds(lat_lo,lng_lo,lat_hi,lng_hi){MarkerClusterer.prototype.infoWindow.close();var sw=new google.maps.LatLng(lat_lo,lng_lo);var ne=new google.maps.LatLng(lat_hi,lng_hi);var bd=new google.maps.LatLngBounds(sw,ne);map.fitBounds(bd);return false;}
function DbcPushpinLayer(opts){var _this=this;for(key in opts){this[key]=opts[key];}
if(this.dataStore){this.dataStore.on("load",function(){this.loadStatus=2;_this.addLayerPins();});}
this.mapLayer=null;this.layerPinsAdded=false;DbcPushpinLayer.prototype.allLayers.push(this);this.showByDefault=false;document.layerForm[this.layerShortName+"Box"].checked=cookieProvider.get(this.layerShortName+"Checked",document.layerForm[this.layerShortName+"Box"].checked);if(document.layerForm[this.layerShortName+"Box"].checked===true){this.showByDefault=true;this.updateLayer();}}
DbcPushpinLayer.prototype.allLayers=[];DbcPushpinLayer.prototype.layerClusteringCallback=function(_this){return function(clusters){var clshapes=null;for(var i=0;i<clusters.length;++i){var cluster=clusters[i];var clusterShape=cluster.getClusterIcon();if(!clusterShape||clusterShape.getTitle())continue;clusterShape.setTitle(cluster.getMarkers().length+" "+_this.clusterInfoHeaderSuffix);clshapes=cluster.getMarkers();var desc=_this.getClusterDescription(_this,clshapes);var zoomInTxt="";if(map.getZoom()<MAX_ZOOM){zoomInTxt="&nbsp;<a onclick='zoomToBounds("+cluster.getBounds().toUrlValue()+")' class='infoWindowZoomIn'>zoom in</a>";}
clusterShape.setDescription(zoomInTxt+"<p />"+desc.desc);if(desc.hasMajorEvent){clusterShape.setIcon(_this.getMajorClusterItemIcon(_this));}}}}
DbcPushpinLayer.prototype.addLayerPins=function(){var _this=this;if(!map)GetMap();if(!this.dataStore||this.dataStore.loadStatus<2){return;}
if(this.layerPinsAdded){return;}
this.layerPinsAdded=true;if(this.mapLayer){this.mapLayer.DeleteAllShapes();map.DeleteShapeLayer(this.mapLayer);}
this.mapLayer=new MarkerClusterer(map,[],{maxZoom:MAX_ZOOM,gridSize:60,zoomOnClick:false,displayInfoWindowOnClick:true,callback:this.layerClusteringCallback(this),visible:false,styles:[{url:this.clusterIconPath.url,showSum:false,anchor:[14,14],zIndex:this.zIndex}]});var mapLayer=this.mapLayer;var oldSnapshot;var oldData;if(this.dataStoreFilter){if(this.dataStore.isFiltered()){oldSnapshot=this.dataStore.snapshot;oldData=this.dataStore.data;}
this.dataStore.filterBy(this.dataStoreFilter);}
this.dataStore.each(function(ev,index,totalItems){try{var veLL=new google.maps.LatLng(ev.get('latitude'),ev.get('longitude'));var pin=new OffsetableMarker({position:veLL});var title=ev.get('title');pin.setTitle(title);pin.isMajorEvent=((ev.get('severity')=='Major')||(ev.json&&ev.json.warnings&&ev.json.warnings.description));pin["description"]=_this.getItemDescription(ev);pin.setIcon(_this.getItemIcon(_this,ev));pin.setZIndex(_this.zIndex);google.maps.event.addListener(pin,'click',function(){mapLayer.infoWindow.setContent("<h3 id='infoWindowTitle'>"+pin.getTitle()+"</h3>"+pin.description);mapLayer.infoWindow.open(map,pin);});mapLayer.addMarker(pin);}
catch(e){}});if(this.dataStoreFilter){this.dataStore.clearFilter(false);if(oldData)this.dataStore.data=oldData;if(oldSnapshot)this.dataStore.snapshot=oldSnapshot;if(oldData||oldSnapshot)this.dataStore.fireEvent('datachanged',this.dataStore);}
this.updateLayer();var isHide=true;for(var i=0;i<DbcPushpinLayer.prototype.allLayers.length;i++){if(DbcPushpinLayer.prototype.allLayers[i].showByDefault&&!DbcPushpinLayer.prototype.allLayers[i].layerPinsAdded){isHide=false;break;}}
if(isHide){Ext.MessageBox.hide();}}
DbcPushpinLayer.prototype.updateLayer=function(){if(this.dataStore.loadStatus==0){if(!Ext.MessageBox.isVisible()){Ext.MessageBox.wait('Retrieving data...','Please wait...');}
this.dataStore.load();}
if(this.mapLayer){if(document.layerForm[this.layerShortName+"Box"].checked===true){this.mapLayer.show();}else{this.mapLayer.hide();}}
cookieProvider.set(this.layerShortName+"Checked",document.layerForm[this.layerShortName+"Box"].checked);}
DbcPushpinLayer.prototype.getItemIcon=function(me,ev){return me.iconPath;}
DbcPushpinLayer.prototype.getMajorClusterItemIcon=function(me){return me.clusterIconPathMajor;}
DbcPushpinLayer.prototype.getClusterDescription=function(_this,clshapes){var desc="";var hasMajorEvent=false;if(clshapes.length>_this.maxClusterInfoItemsWOScrollbar){desc+='<div class="cluster_description">';}
for(var j=0;j<clshapes.length;j++){var clshp=clshapes[j];desc+='<b>'+clshp.getTitle()+'</b>';desc+=" ";desc+=clshp.description;desc+="<br/><br/>";if(clshp.isMajorEvent){hasMajorEvent=true;}}
if(clshapes.length>_this.maxClusterInfoItemsWOScrollbar){desc+="</div>";}
return{desc:desc,hasMajorEvent:hasMajorEvent};}
var dbcWeatherLayer=null;var dbcFerryLayer=null;var dbcWebcamLayer=null;var dbcCurrentPlanedEventsLayer=null;var dbcFuturePlanedEventsLayer=null;var dbcIncidentsLayer=null;var dbcRoadConditionsLayer=null;function OnMouseDown(e){Ext.getCmp('zoomMenu').hide();}
function getMapPermalink(ele){var ctrLatLon=map.GetCenter();var zl=map.GetZoomLevel();var url=window.location.href;if(url.indexOf("&z=")>-1){url=url.replace(/&z=[^&]*/,"&z="+zl);}
else{url+="&z="+zl;}
if(url.indexOf("&ll=")>-1){url=url.replace(/&ll=[^&]*/,"&ll="+ctrLatLon.Latitude.toFixed(5)+","+ctrLatLon.Longitude.toFixed(5));}
else{url+="&ll="+ctrLatLon.Latitude.toFixed(5)+","+ctrLatLon.Longitude.toFixed(5);}
ele.href=url;}
function isMapVisible(){return document.getElementById("mapLayersForm").style.display==="block";}
function updateMapUrl(map){if(map&&isMapVisible()){var c=map.getCenter();if(!isNaN(c.lat())&&!isNaN(c.lng())){if(!isSameUrlMapCoord(c.lat(),c.lng(),map.getZoom().toString())){updateUrl(["ll","z"],[c.toUrlValue(6),map.getZoom().toString()]);}}}else{updateUrl(["ll","z"],["",""]);}}
function isSameUrlMapCoord(lat,lng,z){if(lat&&lng&&z){var url=window.location.href;if(url.indexOf("#mapView&")>-1){filterStrArr=url.substr(url.indexOf("&")+1).split("&");var filters={};for(i=0;i<filterStrArr.length;i++){var filterItemArr=filterStrArr[i].split("=");filters[filterItemArr[0]]=decodeURIComponent(filterItemArr[1]);}
var coords=filters.ll.split(",");var zoom=filters.z;if(z!=zoom){return false;}
var prec=100*zoom;var dLat=(parseFloat(lat)*prec)-(parseFloat(coords[0])*prec);var dLng=(parseFloat(lng)*prec)-(parseFloat(coords[1])*prec);if((dLat>10||dLat<-10)||(dLng>10||dLng<-10)){return false;}
return true;}}
return false;}
function GetMap(){var slat=((prevLL)?prevLL.lat().toString():startLat);var slon=((prevLL)?prevLL.lng().toString():startLong);var latlng=new google.maps.LatLng(slat,slon);var myOptions={zoom:((prevZoom)?prevZoom:MIN_ZOOM),maxZoom:MAX_ZOOM,minZoom:MIN_ZOOM,center:latlng,scaleControl:true,scaleControlOptions:{position:google.maps.ControlPosition.BOTTOM_LEFT},mapTypeId:google.maps.MapTypeId.ROADMAP};map=new google.maps.Map(Ext.getDom("myMap"),myOptions);var allowedBounds=new google.maps.LatLngBounds(new google.maps.LatLng(MIN_LAT,MIN_LONG),new google.maps.LatLng(MAX_LAT,MAX_LONG));google.maps.event.addListener(map,'idle',function(){updateMapUrl(map);});google.maps.event.addListener(MarkerClusterer.prototype.infoWindow,'domready',function(){Ext.getDom('infoWindowTitle').parentNode.style.overflow='hidden';});}
function updateMap(){var sz=((prevZoom)?prevZoom:startZoom);var slat=((prevLL)?prevLL.lat().toString():startLat);var slon=((prevLL)?prevLL.lng().toString():startLong);var url=decodeURIComponent(window.location.href);var m=url.match(/&ll=([^&]*)/);if(m){var sll=m[1].split(",");slat=parseFloat(sll[0]);slon=parseFloat(sll[1]);}
m=url.match(/&z=([^&]*)/);if(m){sz=parseInt(m[1]);}
map.setCenter(new google.maps.LatLng(slat,slon));map.setZoom(sz);prevLL=map.getCenter();prevZoom=sz;}
function mapResize(){var w=null;var el=Ext.getCmp("mapView");if(el&&el.getResizeEl()&&el.getInnerWidth()){w=Ext.getCmp("mapView").getInnerWidth()-mapPanelGutterWidth;}
var h=Ext.getBody().getViewSize().height-103-mapPanelGutterHeight;if(map){map.getDiv().style.width=w&&(w+"px");map.getDiv().style.height=h&&(h+"px");updateMap();google.maps.event.trigger(map,'resize');}}
function GetInsetMap(){var latlng=new google.maps.LatLng(54.8833,-122.6667);var myOptions={zoom:12,center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP,maxZoom:MAX_ZOOM,minZoom:MIN_ZOOM,scaleControl:true,scaleControlOptions:{position:google.maps.ControlPosition.BOTTOM_LEFT}};insetMap=new google.maps.Map(Ext.getDom("myInsetMap"),myOptions);}
function insetMapResize(){var w=mapWindow.getInnerWidth()-3;var h=mapWindow.getInnerHeight()-3;if(insetMap!==null){var ll=insetMap.getCenter();insetMap.getDiv().style.width=w&&(w+"px");insetMap.getDiv().style.height=h&&(h+"px");google.maps.event.trigger(insetMap,'resize');insetMap.setCenter(ll);}}
var insetPin;function showMap(id){var ev=eventStore.getById(id);var veLL=new google.maps.LatLng(ev.get('latitude'),ev.get('longitude'));if(insetPin)insetPin.setMap(null);insetPin=new google.maps.Marker({position:veLL,visible:true});insetPin.setTitle(ev.get('title'));var severity=ev.get('severity');if(ev.get('eventType')=='Road Condition'){if(severity=='Major'){insetPin.setIcon(icon_road_cond_major);}else{insetPin.setIcon(icon_road_cond);}}
else if(ev.get('eventType')=='Incident'){if(severity=='Major'){insetPin.setIcon(icon_incident_major);}else{insetPin.setIcon(icon_incident);}}
else if(ev.get('eventType')=='Future Planned'){if(severity=='Major'){insetPin.setIcon(icon_future_event_major);}else{insetPin.setIcon(icon_future_event);}}else{if(severity=='Major'){insetPin.setIcon(icon_current_event_major);}else{insetPin.setIcon(icon_current_event);}}
insetPin.setMap(insetMap);insetMap.setCenter(veLL);insetMap.setZoom(10);mapWindow.show();mapWindow.center();}
function getWebcamRegionTpl(region){var tpl=new Ext.XTemplate('<div class="webcam-heading">Click on a webcam thumbnail image for more information.</div>','<tpl for=".">','<tpl if="region==\''+region+'\'">','<div class="thumb-wrap" id="cam{id}">','<div class="newCamLabel"><tpl if="isNew==\'true\'">New!</tpl>&nbsp;</div>','<a href="http://images.drivebc.ca/bchighwaycam/pub/html/dbc/{id}.html" target="_blank">','<div class="thumb"><img src="http://images.drivebc.ca/bchighwaycam/pub/cameras/tn/{id}.jpg" title="{name}" alt="Camera: {name}"></div>','<span><b>{name}</b> - {caption}</span></a></div>','</tpl>','</tpl>','<div class="x-clear"></div>');return tpl;}
function getWebcamDataView(tpl){var dv=new Ext.DataView({store:webcamStore,tpl:tpl,autoHeight:true,multiSelect:false,overClass:'x-view-over',itemSelector:'div.thumb-wrap',emptyText:'No webcams to display',iconCls:'webcamIcon'});return dv;}
function eventStoreReload(){Ext.MessageBox.wait('Refreshing events...','Please wait...');eventStore.reload();var searchTriggerField=Ext.getCmp('searchTriggerField');if(searchTriggerField){searchTriggerField.reset();}}
function webcamStoreReload(){webcamStore.reload();}
function ferryStoreReload(){ferryStore.reload();}
function weatherStoreReload(){weatherStore.reload();}
function typeOf(value){var s=typeof value;if(s==='object'){if(value){if(value instanceof Array){s='array';}}else{s='null';}}
return s;}
function updateUrl(filter,value){var url=window.location.href;if(filter){if(typeOf(filter)==='array'){if(typeOf(value)!=='array'||filter.length!=value.length){return url;}
for(var x=0;x<filter.length;x++){url=modUrl(url,filter[x],value[x]);}}else{url=modUrl(url,filter,value)}
if(window.location.href!=url){window.location.href=url;}}
return url;}
function modUrl(url,filter,value){if(url.indexOf("&"+filter+"=")>-1){var re=new RegExp("&"+filter+"="+"[^&]*");url=url.replace(re,(value?("&"+filter+"="+encodeURIComponent(value)):""));}else if(value){url+="&"+filter+"="+encodeURIComponent(value);}
return url;}
function isEventsChecked(){if(Ext.getCmp("Current Planned")){if(Ext.getCmp("Current Planned").getValue()!==true){return false;}}
if(Ext.getCmp("Incident")){if(Ext.getCmp("Incident").getValue()!==true){return false;}}
if(Ext.getCmp("Road Condition")){if(Ext.getCmp("Road Condition").getValue()!==true){return false;}}
if(Ext.getCmp("Future Planned")){if(Ext.getCmp("Future Planned").getValue()!==true){return false;}}
return true;}
var updateSearchFlag=false;function updateSearch(f,s){if(updateSearchFlag){return;}
updateSearchFlag=true;try{var mtp=Ext.getCmp("center-panel");if(mtp.getActiveTab().id!="listView"){return;}
var url=updateUrl(f,s);var filterStrArr=[];if(url.indexOf("#listView&")>-1){filterStrArr=url.substr(url.indexOf("&")+1).split("&");}
var filters={};for(i=0;i<filterStrArr.length;i++){var filterItemArr=filterStrArr[i].split("=");filters[filterItemArr[0]]=decodeURIComponent(filterItemArr[1]);if(filterItemArr[0].toLowerCase()!=="eventtype"){setFilterRadioBox('filterBox1',false);}}
var cbx='';if(filters.eventType){var values=filters.eventType.split('|');if(values){cbx=Ext.getCmp("Current Planned");cbx.setValue((values.inArray("Current Planned"))?"true":"false");cbx=Ext.getCmp("Incident");cbx.setValue((values.inArray("Incident"))?"true":"false");cbx=Ext.getCmp("Road Condition");cbx.setValue((values.inArray("Road Condition"))?"true":"false");cbx=Ext.getCmp("Future Planned");cbx.setValue((values.inArray("Future Planned"))?"true":"false");}
filters.eventType=values;}else{if(isEventsChecked()){filters.eventType=["Road Condition","Incident","Current Planned","Future Planned"];}
else{filters['eventType']=[];}}
cbx=Ext.getCmp("filterSeverityCombo");if(filters.severity){setFilterRadioBox('filterBox2',true);if(cbx.value!=filters.severity){cbx.setValue(filters.severity);}}
else{cbx.setValue("");}
if(filters.district||f==='district'){setFilterRadioBox('filterBox3',true);if((filters.district=processComboBoxes("filterDistrictCombo",4,filters.district))==null){updateUrl('district',allItemsProp.district);}}
if(filters.road||f==='road'){setFilterRadioBox('filterBox4',true);if((filters.road=processComboBoxes("filterRouteCombo",4,filters.road))===null){updateUrl('road',allItemsProp.road);}}
if(filters.popularRoute||f==='popularRoute'){setFilterRadioBox('filterBox5',true);if((filters.popularRoute=processComboBoxes("filterPopularRouteCombo",4,filters.popularRoute))==null){updateUrl('popularRoute',allItemsProp.popularRoute);}}
eventStore.filterBy(function(r){for(i in filters){var ri=r.get(i);if(Ext.isArray(ri)){if(filters[i]&&!filters[i].arrayInArray(ri)){return false;}}else{if(filters[i]&&!(filters[i]==ri||(Ext.isArray(filters[i])&&filters[i].inArray(ri)))){return false;}}}
return true;});}catch(e){}finally{updateSearchFlag=false;}}
function processComboBoxes(cbxBaseName,numCbx,value){var bAllItemsFl=false;var cbxArray=new Array();for(i=0;i<numCbx;i++){cbxArray[i]=Ext.getCmp(cbxBaseName+i);}
var values=null;if(value){values=value.split('|');}
if(values){values=values.unique(true);if(allItemsProp.district===values[0]||allItemsProp.popularRoute===values[0]||allItemsProp.road===values[0]){var tArr=values;values=[];values[0]=tArr[0];bAllItemsFl=true;}
for(i=0;i<numCbx;i++){if(i<values.length){cbxArray[i].ownerCt.setVisible(true);cbxArray[i].setValue(values[i]);cbxArray[i].nextSibling().setDisabled(bAllItemsFl);}else{if(i==values.length&&!bAllItemsFl){cbxArray[i].ownerCt.setVisible(true);cbxArray[i].setValue('');if(values.length==1&&values[0].trim()===''){cbxArray[i-1].nextSibling().setDisabled(true);}else{cbxArray[i-1].nextSibling().setDisabled(false);}
cbxArray[i].nextSibling().setDisabled(true);}else{cbxArray[i].ownerCt.setVisible(false);cbxArray[i].setValue('');cbxArray[i].nextSibling().setDisabled(true);}}}}else{for(i=0;i<cbxArray.length;i++){if(i>0){cbxArray[i].ownerCt.setVisible(false);cbxArray[i].setValue('');}else{if(cbxBaseName==='filterDistrictCombo')
cbxArray[i].setValue(allItemsProp.district);else if(cbxBaseName==='filterPopularRouteCombo')
cbxArray[i].setValue(allItemsProp.popularRoute);else if(cbxBaseName==='filterRouteCombo')
cbxArray[i].setValue(allItemsProp.road);}
cbxArray[i].nextSibling().setDisabled(true);}}
if(bAllItemsFl){return null;}
return values;}
function setFilterRadioBox(radioName,bValue){var filterRadioBox=Ext.getCmp(radioName);if(filterRadioBox)filterRadioBox.setValue(bValue);}
Array.prototype.arrayInArray=function(tArray){var i1,i2;if(!tArray||tArray.length===0)return false;for(i1=0;i1<this.length;i1++){for(i2=0;i2<tArray.length;i2++){if(this[i1]===tArray[i2]){return true;}}}
return false;}
Array.prototype.inArray=function(value){var i;for(i=0;i<this.length;i++){if(this[i]===value){return true;}}
return false;};Array.prototype.unique=function(b){var a=[],i,l=this.length;for(i=0;i<l;i++){if(a.indexOf(this[i],0,b)<0){a.push(this[i]);}}
return a;};function clearComboBoxes(filter){if(!filter)return;var baseName=null;var all="";if(filter==='district'){baseName='filterDistrict';all=allItemsProp.district;}else if(filter==='road'){baseName='filterRoute';all=allItemsProp.road;}else if(filter==='popularRoute'){baseName='filterPopularRoute';all=allItemsProp.popularRoute;}
if(baseName!==null){for(var i=0;i<4;i++){if(i===0){Ext.getCmp(baseName+'Combo'+i).setValue(all);}else{Ext.getCmp(baseName+'Combo'+i).setValue('');}
Ext.getCmp(baseName+'Btn'+i).setDisabled(true);}}}
function clearSearch(){if(updateSearchFlag===true){return;}
var url=window.location.href;if(url.indexOf("&")==-1){return;}
var etPos=url.indexOf("&eventType");var etVal="";if(etPos>0){var etEnd=url.indexOf("&",etPos+1);if(etEnd<0){etVal=url.substr(etPos);}else{etVal=url.substr(etPos,etEnd-etPos);}}
url=url.substr(0,url.indexOf("&"))+etVal;window.location.href=url;clearComboBoxes('district');clearComboBoxes('road');clearComboBoxes('popularRoute');}
function initEvtFilters(){clearComboBoxes('district');clearComboBoxes('road');clearComboBoxes('popularRoute');hideCbxPanels();setFilterRadioBox('filterBox1',true);if(Ext.getCmp("Current Planned")){Ext.getCmp("Current Planned").setValue("true");}
if(Ext.getCmp("Incident")){Ext.getCmp("Incident").setValue("true");}
if(Ext.getCmp("Road Condition")){Ext.getCmp("Road Condition").setValue("true");}
if(Ext.getCmp("Future Planned")){Ext.getCmp("Future Planned").setValue("true");}}
function hideCbxPanels(){Ext.getCmp("filterDistrictPanel0").setVisible(false);Ext.getCmp("filterDistrictPanel1").setVisible(false);Ext.getCmp("filterDistrictPanel2").setVisible(false);Ext.getCmp("filterDistrictPanel3").setVisible(false);Ext.getCmp("filterRoutePanel0").setVisible(false);Ext.getCmp("filterRoutePanel1").setVisible(false);Ext.getCmp("filterRoutePanel2").setVisible(false);Ext.getCmp("filterRoutePanel3").setVisible(false);Ext.getCmp("filterPopularRoutePanel0").setVisible(false);Ext.getCmp("filterPopularRoutePanel1").setVisible(false);Ext.getCmp("filterPopularRoutePanel2").setVisible(false);Ext.getCmp("filterPopularRoutePanel3").setVisible(false);Ext.getCmp("filterDistrictBtn0").setDisabled(true);Ext.getCmp("filterDistrictBtn1").setDisabled(true);Ext.getCmp("filterDistrictBtn2").setDisabled(true);Ext.getCmp("filterDistrictBtn3").setDisabled(true);Ext.getCmp("filterRouteBtn0").setDisabled(true);Ext.getCmp("filterRouteBtn1").setDisabled(true);Ext.getCmp("filterRouteBtn2").setDisabled(true);Ext.getCmp("filterRouteBtn3").setDisabled(true);Ext.getCmp("filterPopularRouteBtn0").setDisabled(true);Ext.getCmp("filterPopularRouteBtn1").setDisabled(true);Ext.getCmp("filterPopularRouteBtn2").setDisabled(true);Ext.getCmp("filterPopularRouteBtn3").setDisabled(true);}
Ext.onReady(function(){Ext.History.init();Ext.QuickTips.init();cookieProvider=new Ext.state.CookieProvider();Ext.state.Manager.setProvider(cookieProvider);var conn=new Ext.data.Connection({timeout:3000});conn.request({url:'static/alerts.html',success:function(response,opts){if(response.responseText.substr(0,11)=='<!--Live-->'){alertWindow=new Ext.Window({id:'alert-window',layout:'fit',width:500,height:450,closeAction:'hide',plain:true,title:'Alerts',modal:true,resizable:true,iconCls:'insetMapIcon',items:[{html:response.responseText}],buttons:[{text:'Close',handler:function(){alertWindow.hide();}}]});document.getElementById("alertButton").style.display="block";Ext.MessageBox.hide();alertWindow.show();}}});var eventsReader=new Ext.data.ArrayReader({idIndex:10},[{name:'title'},{name:'latitude',type:'float'},{name:'longitude',type:'float'},{name:'district'},{name:'road'},{name:'direction'},{name:'eventType'},{name:'severity'},{name:'lastUpdated',type:'date',dateFormat:'Y-m-d H:i:s.0'},{name:'description'},{name:'ateid'},{name:'trafficPattern'},{name:'popularRoute'}]);var ferriesReader=new Ext.data.ArrayReader(null,[{name:'title'},{name:'latitude',type:'float'},{name:'longitude',type:'float'},{name:'url'}]);var webcamsReader=new Ext.data.ArrayReader(null,[{name:'id',mapping:0},{name:'name',mapping:1},{name:'title',mapping:1},{name:'caption',mapping:2},{name:'credit',mapping:3},{name:'orientation',mapping:4},{name:'latitude',mapping:5},{name:'longitude',mapping:6},{name:'shortmessage',mapping:7},{name:'longmessage',mapping:8},{name:'regionGroup',mapping:9},{name:'regionHighwayGroup',mapping:10},{name:'regionHighwayCameraOrder',mapping:11},{name:'region',mapping:12},{name:'highwayNumber',mapping:13},{name:'highwayLocationDescription',mapping:14},{name:'elevation',mapping:15},{name:'weatherStation',mapping:16},{name:'forecastID',mapping:17},{name:'uploadPeriod',mapping:18},{name:'isNew',mapping:19}]);eventStore=new Ext.data.GroupingStore({reader:eventsReader,autoLoad:false,url:'data/events.json',loadStatus:0,sortInfo:{field:'severity',direction:"ASC"},listeners:{load:function(){loadStatus=2;var d=new Date();d.setTime(d.getTime()+EVENT_REFRESH_TIME);document.getElementById('eventsLastUpdated').innerHTML='Up-to-date. <br><span style="padding-left: 10px; color:purple"><b>Refresh at: </b>'+d.toLocaleTimeString()+'</span>';eventStore.sort();if(mainTabPanel.getActiveTab().id=="listView"){updateSearch();}},exception:function(){var d=new Date();d.setTime(d.getTime()+EVENT_REFRESH_TIME);document.getElementById('eventsLastUpdated').innerHTML=errorLoadMsg+'<br><span style="padding-left: 10px; color:purple"><b>Retry at: </b>'+d.toLocaleTimeString()+'</span>';Ext.MessageBox.hide();}}});webcamStore=new Ext.data.Store({reader:webcamsReader,autoLoad:false,loadStatus:0,url:'data/webcams.json',listeners:{load:function(){loadStatus=2;document.getElementById('webcamsLastUpdated').innerHTML='Up-to-date.';webcamStore.sort([{field:'regionGroup'},{field:'regionHighwayGroup'},{field:'regionHighwayCameraOrder'}]);},exception:function(){var d=new Date();d.setTime(d.getTime()+RELOAD_ON_ERROR_TIME);document.getElementById('webcamsLastUpdated').innerHTML=errorLoadMsg+'<br><span style="padding-left: 10px; color:purple"><b>Retry at: </b>'+d.toLocaleTimeString()+'</span>';Ext.MessageBox.hide();window.setTimeout(webcamStoreReload,RELOAD_ON_ERROR_TIME);}}});ferryStore=new Ext.data.Store({reader:ferriesReader,autoLoad:false,loadStatus:0,url:'data/ferries.json',listeners:{load:function(){loadStatus=2;document.getElementById('ferriesLastUpdated').innerHTML='Up-to-date.';},exception:function(){var d=new Date();d.setTime(d.getTime()+RELOAD_ON_ERROR_TIME);document.getElementById('ferriesLastUpdated').innerHTML=errorLoadMsg+'<br><span style="padding-left: 10px; color:purple"><b>Retry at: </b>'+d.toLocaleTimeString()+'</span>';Ext.MessageBox.hide();window.setTimeout(ferryStoreReload,RELOAD_ON_ERROR_TIME);}}});weatherStore=new Ext.data.JsonStore({autoLoad:false,loadStatus:0,url:'data/wx.json',fields:[{name:"title",mapping:"location.name"},{name:"latitude",mapping:"location.lat"},{name:"longitude",mapping:"location.lon"}],listeners:{load:function(){loadStatus=2;document.getElementById('weatherLastUpdated').innerHTML='Up-to-date.';},exception:function(){var d=new Date();d.setTime(d.getTime()+RELOAD_ON_ERROR_TIME);document.getElementById('weatherLastUpdated').innerHTML=errorLoadMsg+'<br><span style="padding-left: 10px; color:purple"><b>Retry at: </b>'+d.toLocaleTimeString()+'</span>';Ext.MessageBox.hide();window.setTimeout(weatherStoreReload,RELOAD_ON_ERROR_TIME);}}});var vancIslandTpl=getWebcamRegionTpl('Vancouver Island');var borderCamsTpl=getWebcamRegionTpl('Border Cams');var lowerMainTpl=getWebcamRegionTpl('Lower Mainland');var northernTpl=getWebcamRegionTpl('Northern');var southIntTpl=getWebcamRegionTpl('Southern Interior');var vancIslandDV=getWebcamDataView(vancIslandTpl);var borderCamsDV=getWebcamDataView(borderCamsTpl);var lowerMainDV=getWebcamDataView(lowerMainTpl);var northernDV=getWebcamDataView(northernTpl);var southIntDV=getWebcamDataView(southIntTpl);var infofield=new Ext.form.Label({text:eventStore.getCount()+' items'});eventStore.on('datachanged',function(){var count=eventStore.getCount();if(count==1){infofield.setText('1 item');}else{infofield.setText(count+' items');}});var zoomMenu=new Ext.menu.Menu({id:'zoomMenu',items:[{text:'Province of BC',handler:function(){map.setCenter(new google.maps.LatLng(54.8833,-122.6667));map.setZoom(5);}},'-',{text:'Lower Mainland (Vancouver)',handler:function(){map.setCenter(new google.maps.LatLng(49.680379,-123.310727));map.setZoom(8);}},{text:'Vancouver Island (Victoria)',handler:function(){map.setCenter(new google.maps.LatLng(49.550482,-126.403422));map.setZoom(7);}},{text:'Rocky Mountain (Cranbrook)',handler:function(){map.setCenter(new google.maps.LatLng(50.26087,-116.267892));map.setZoom(8);}},{text:'West Kootenay (Nelson)',handler:function(){map.setCenter(new google.maps.LatLng(49.735525,-117.621932));map.setZoom(8);}},{text:'Okanagan-Shuswap (Kelowna)',handler:function(){map.setCenter(new google.maps.LatLng(49.821447,-119.682865));map.setZoom(8);}},{text:'Thompson-Nicola (Kamloops)',handler:function(){map.setCenter(new google.maps.LatLng(50.617186,-120.586622));map.setZoom(8);}},{text:'Cariboo (Williams Lake)',handler:function(){map.setCenter(new google.maps.LatLng(52.008978,-123.464205));map.setZoom(7);}},{text:'Peace (Fort St. John)',handler:function(){map.setCenter(new google.maps.LatLng(56.292124,-122.62188));map.setZoom(7);}},{text:'Fort George (Prince George)',handler:function(){map.setCenter(new google.maps.LatLng(53.868489,-121.596946));map.setZoom(7);}},{text:'Bulkley Stikine (Smithers)',handler:function(){map.setCenter(new google.maps.LatLng(54.834876,-127.637288));map.setZoom(8);}},{text:'Skeena (Prince Rupert)',handler:function(){map.setCenter(new google.maps.LatLng(53.486002,-129.494713));map.setZoom(7);}}]});var filterSeverityCombo=new Ext.form.ComboBox({id:'filterSeverityCombo',stateful:false,valueField:"id",forceSelection:true,readOnly:true,displayField:"id",triggerAction:'all',mode:'local',emptyText:'Select severity...',listWidth:135,width:106,store:new Ext.data.SimpleStore({fields:['id'],data:[['(All Severities)'],['Major'],['Normal']]}),listeners:{select:function(combo,record,index){updateSearch("severity",(index===0?"":record.get('id')));}}});var filterEventTypeChkbxGroup=new Ext.form.CheckboxGroup({id:'filterEventTypeChkbxGroup',stateful:false,fieldLabel:'Select Event Type',columns:[160,120,180,180],items:[{boxLabel:'<img style="width:25px;vertical-align:middle" src="'+icon_road_cond.url+'"/>Road Condition',id:'Road Condition',checked:true},{boxLabel:'<img style="width:25px;vertical-align:middle" src="'+icon_incident.url+'"/>Incident',id:'Incident',checked:true},{boxLabel:'<img style="width:25px;vertical-align:middle" src="'+icon_current_event.url+'"/>Current Planned Event',id:'Current Planned',checked:true},{boxLabel:'<img style="width:25px;vertical-align:middle" src="'+icon_future_event.url+'"/>Future Planned Event',id:'Future Planned',checked:true}],listeners:{change:function(checkbox,checked){var values="";if(checked){for(var i=0;i<checked.length;i++){if(checked[i].getValue()===true){if(values)values+="|";values+=checked[i].getId();}}}
updateSearch("eventType",values);}}});var districtStoreAll=new Ext.data.SimpleStore({fields:["id"],data:[[allItemsFlagArray[0]],['Lower Mainland'],['Vancouver Island'],['Rocky Mountain'],['West Kootenay'],['Okanagan Shuswap'],['Thompson Nicola'],['Cariboo'],['Peace'],['Fort George'],['Bulkley Stikine'],['Skeena']]});var districtStore=new Ext.data.SimpleStore({fields:["id"],data:[['Lower Mainland'],['Vancouver Island'],['Rocky Mountain'],['West Kootenay'],['Okanagan Shuswap'],['Thompson Nicola'],['Cariboo'],['Peace'],['Fort George'],['Bulkley Stikine'],['Skeena']]});var filterDistrictCombo0=new Ext.form.ComboBox({id:'filterDistrictCombo0',stateful:false,valueField:"id",readOnly:true,forceSelection:true,displayField:"id",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select District',listWidth:200,width:200,store:districtStoreAll,listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterDistrictCombo',4)===false){if(!noValuesCheck('filterDistrictCombo',4,'district')){updateSearch("district",combineComboValues('filterDistrictCombo',4));}}else{combo.reset();}}}});var filterDistrictCombo1=new Ext.form.ComboBox({id:'filterDistrictCombo1',stateful:false,valueField:"id",readOnly:true,forceSelection:true,displayField:"id",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select District',listWidth:200,width:200,store:districtStore,listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterDistrictCombo',4)===false){updateSearch("district",combineComboValues('filterDistrictCombo',4));}else{combo.reset();}}}});var filterDistrictCombo2=new Ext.form.ComboBox({id:'filterDistrictCombo2',stateful:false,valueField:"id",readOnly:true,forceSelection:true,displayField:"id",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select District',listWidth:200,width:200,store:districtStore,listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterDistrictCombo',4)===false){updateSearch("district",combineComboValues('filterDistrictCombo',4));}else{combo.reset();}}}});var filterDistrictCombo3=new Ext.form.ComboBox({id:'filterDistrictCombo3',stateful:false,valueField:"id",readOnly:true,forceSelection:true,displayField:"id",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select District',listWidth:200,width:200,store:districtStore,listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterDistrictCombo',4)===false){updateSearch("district",combineComboValues('filterDistrictCombo',4));}else{combo.reset();}}}});var routeStoreAll=new Ext.data.JsonStore({url:"data/highways.json",autoLoad:true,fields:[{name:"route",mapping:"name"}],listeners:{load:function(s,r,o){var ar=Ext.data.Record.create(["route"]);ar.data={route:allItemsFlagArray[1]};try{s.insert(0,[ar]);}
catch(e){}}}});var routeStore=new Ext.data.JsonStore({url:"data/highways.json",autoLoad:true,fields:[{name:"route",mapping:"name"}],listeners:{load:function(s,r,o){}}});var popularRouteStoreAll=new Ext.data.JsonStore({url:"data/popularroutes.json",autoLoad:true,fields:[{name:'popularRoute',mapping:"name"}],listeners:{load:function(s,r,o){var ar=Ext.data.Record.create(["popularRoute"]);ar.data={popularRoute:allItemsFlagArray[2]};try{s.insert(0,[ar]);}
catch(e){}}}});var popularRouteStore=new Ext.data.JsonStore({url:"data/popularroutes.json",autoLoad:true,fields:[{name:'popularRoute',mapping:"name"}],listeners:{load:function(s,r,o){}}});var filterRouteCombo0=new Ext.form.ComboBox({id:'filterRouteCombo0',stateful:false,valueField:"route",autoSelect:true,readOnly:true,forceSelection:true,displayField:"route",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Route',listWidth:350,width:350,store:routeStoreAll,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterRouteCombo',4)===false){if(!noValuesCheck('filterRouteCombo',4,'road')){updateSearch("road",combineComboValues('filterRouteCombo',4));}}else{combo.reset();}}}});var filterRouteCombo1=new Ext.form.ComboBox({id:'filterRouteCombo1',stateful:false,valueField:"route",autoSelect:true,readOnly:true,forceSelection:true,displayField:"route",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Route',listWidth:350,width:350,store:routeStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterRouteCombo',4)===false){if(!noValuesCheck('filterRouteCombo',4,'road')){updateSearch("road",combineComboValues('filterRouteCombo',4));}}else{combo.reset();}}}});var filterRouteCombo2=new Ext.form.ComboBox({id:'filterRouteCombo2',stateful:false,valueField:"route",autoSelect:true,readOnly:true,forceSelection:true,displayField:"route",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Route',listWidth:350,width:350,store:routeStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterRouteCombo',4)===false){if(!noValuesCheck('filterRouteCombo',4,'road')){updateSearch("road",combineComboValues('filterRouteCombo',4));}}else{combo.reset();}}}});var filterRouteCombo3=new Ext.form.ComboBox({id:'filterRouteCombo3',stateful:false,valueField:"route",autoSelect:true,readOnly:true,forceSelection:true,displayField:"route",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Route',listWidth:350,width:350,store:routeStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterRouteCombo',4)===false){if(!noValuesCheck('filterRouteCombo',4,'road')){updateSearch("road",combineComboValues('filterRouteCombo',4));}}else{combo.reset();}}}});var filterPopularRouteCombo0=new Ext.form.ComboBox({id:'filterPopularRouteCombo0',stateful:false,valueField:"popularRoute",autoSelect:true,readOnly:true,forceSelection:true,displayField:"popularRoute",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Popular Route',listWidth:350,width:350,store:popularRouteStoreAll,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterPopularRouteCombo',4)===false){if(!noValuesCheck('filterPopularRouteCombo',4,'road')){updateSearch("popularRoute",combineComboValues('filterPopularRouteCombo',4));}}else{combo.reset();}}}});var filterPopularRouteCombo1=new Ext.form.ComboBox({id:'filterPopularRouteCombo1',stateful:false,valueField:"popularRoute",autoSelect:true,readOnly:true,forceSelection:true,displayField:"popularRoute",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Popular Route',listWidth:350,width:350,store:popularRouteStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterPopularRouteCombo',4)===false){if(!noValuesCheck('filterPopularRouteCombo',4,'road')){updateSearch("popularRoute",combineComboValues('filterPopularRouteCombo',4));}}else{combo.reset();}}}});var filterPopularRouteCombo2=new Ext.form.ComboBox({id:'filterPopularRouteCombo2',stateful:false,valueField:"popularRoute",autoSelect:true,readOnly:true,forceSelection:true,displayField:"popularRoute",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Popular Route',listWidth:350,width:350,store:popularRouteStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterPopularRouteCombo',4)===false){if(!noValuesCheck('filterPopularRouteCombo',4,'road')){updateSearch("popularRoute",combineComboValues('filterPopularRouteCombo',4));}}else{combo.reset();}}}});var filterPopularRouteCombo3=new Ext.form.ComboBox({id:'filterPopularRouteCombo3',stateful:false,valueField:"popularRoute",autoSelect:true,readOnly:true,forceSelection:true,displayField:"popularRoute",triggerAction:'all',mode:'local',emptyText:'Please select...',fieldLabel:'Select Popular Route',listWidth:350,width:350,store:popularRouteStore,getListParent:function(){return this.el.up('.x-menu');},iconCls:'no-icon',listeners:{select:function(combo,record,index){if(isCbxValueDuplicated('filterPopularRouteCombo',4)===false){if(!noValuesCheck('filterPopularRouteCombo',4,'road')){updateSearch("popularRoute",combineComboValues('filterPopularRouteCombo',4));}}else{combo.reset();}}}});function descRenderer(value,metaData,record,rowIndex,colIndex,store){return'<div style="white-space:normal !important;">'+value+' [<a href="javascript:showMap('+record.get('ateid')+')">View on map</a>]</div>';}
function routeRenderer(value,metaData,record,rowIndex,colIndex,store){return'<div style="white-space:normal !important;">'+value+' '+record.get('direction')+'</div>';}
function typeRenderer(value,metaData,record,rowIndex,colIndex,store){var icon='';if(value=='Incident')
{icon=dbcIncidentsLayer.getItemIcon(dbcIncidentsLayer,record).url;}
else if(value=='Current Planned'){icon=dbcCurrentPlanedEventsLayer.getItemIcon(dbcCurrentPlanedEventsLayer,record).url;}
else if(value=='Future Planned'){icon=dbcFuturePlanedEventsLayer.getItemIcon(dbcFuturePlanedEventsLayer,record).url;}
else if(value=='Road Condition'){icon=dbcRoadConditionsLayer.getItemIcon(dbcRoadConditionsLayer,record).url;}
return'<img src="'+icon+'" alt="'+value+'" title="'+value+'" />';}
var listGridPanel=new Ext.grid.GridPanel({region:'center',title:'Events List',id:'listViewGrid',store:eventStore,stateful:false,iconCls:'listGridIcon',frame:false,autoHeight:true,autoWidth:true,header:false,anchor:'100%',stripeRows:true,cm:new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:"ID",width:40,hidden:true,dataIndex:'ateid'},{header:"Type",width:50,dataIndex:'eventType',align:'center',renderer:typeRenderer},{header:"Severity",width:45,dataIndex:'severity'},{header:"Cause",width:110,hidden:true,dataIndex:'title'},{header:"District",width:100,hidden:true,dataIndex:'district'},{header:"Route",width:120,dataIndex:'road',renderer:routeRenderer},{header:"Direction",width:70,hidden:true,dataIndex:'direction'},{header:"Traffic Pattern",width:110,hidden:true,dataIndex:'trafficPattern'},{header:"Description",width:400,dataIndex:'description',renderer:descRenderer},{header:"Last Updated",width:120,renderer:Ext.util.Format.dateRenderer('Y-m-d g:i A'),dataIndex:'lastUpdated'}]}),view:new Ext.grid.GroupingView({id:"listGroupingView",forceFit:true,emptyText:"No events found",deferEmptyText:true,groupTextTpl:'{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})',getRowClass:function(record,index){var sev=record.get('severity');if(sev=='Major'){return'severity-major';}
else{return'';}}}),tbar:[{text:'Refresh data',iconCls:'update',handler:function(b,e){location.reload(true);}},{xtype:'tbfill'},{text:'Print',iconCls:'print',handler:function(){Ext.ux.GridPrinter.print(listGridPanel);}}],bbar:new Ext.Toolbar({items:[infofield],height:20}),columnLines:true,collapsible:false,animCollapse:false});function showPanel(name,bArray){if(!name||!bArray||bArray.length===0){return;}
for(i=0;i<bArray.length;i++){var panel=Ext.getCmp(name+i);panel.setVisible(bArray[i]);}}
var filterFormPanel=new Ext.FormPanel({labelAlign:'top',frame:false,id:'filterFormPanel',bodyStyle:'padding: 5px 5px 0px 5px',layout:'form',header:false,border:false,items:[{xtype:'radiogroup',id:'mainRadioGroup',fieldLabel:'View',columns:[60,120,100,100,120],items:[{boxLabel:'All',id:'filterBox1',name:'filterBox',inputValue:1,checked:true,handler:function(rbx,checked){if(checked){showPanel('filterDistrictPanel',[false,false,false,false]);showPanel('filterRoutePanel',[false,false,false,false]);showPanel('filterPopularRoutePanel',[false,false,false,false]);clearSearch();}}},{boxLabel:'Major Events',id:'filterBox2',name:'filterBox',inputValue:2,handler:function(rbx,checked){if(checked){showPanel('filterDistrictPanel',[false,false,false,false]);showPanel('filterRoutePanel',[false,false,false,false]);showPanel('filterPopularRoutePanel',[false,false,false,false]);clearSearch();updateSearch("severity",'Major');}}},{boxLabel:'By District',id:'filterBox3',name:'filterBox',inputValue:3,handler:function(rbx,checked){if(checked){showPanel('filterDistrictPanel',[true,false,false,false]);showPanel('filterRoutePanel',[false,false,false,false]);showPanel('filterPopularRoutePanel',[false,false,false,false]);clearSearch();}}},{boxLabel:'By Route',id:'filterBox4',name:'filterBox',inputValue:4,handler:function(rbx,checked){if(checked){showPanel('filterDistrictPanel',[false,false,false,false]);showPanel('filterRoutePanel',[true,false,false,false]);showPanel('filterPopularRoutePanel',[false,false,false,false]);clearSearch();}}},{boxLabel:'By Popular Route',id:'filterBox5',name:'filterBox',inputValue:5,handler:function(rbx,checked){if(checked){showPanel('filterDistrictPanel',[false,false,false,false]);showPanel('filterRoutePanel',[false,false,false,false]);showPanel('filterPopularRoutePanel',[true,false,false,false]);clearSearch();}}}]}]});var filterAllPanel=new Ext.FormPanel({labelAlign:'top',labelWidth:600,frame:false,id:'filterAllPanel',bodyStyle:'padding: 0px 5px 5px 5px',autoWidth:true,header:false,border:false,layout:'form',items:[filterEventTypeChkbxGroup]});var filterDistrictPanel0=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterDistrictPanel0',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select District:'}},filterDistrictCombo0,{xtype:'button',id:'filterDistrictBtn0',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterDistrictPanel1=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterDistrictPanel1',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select District:'}},filterDistrictCombo1,{xtype:'button',id:'filterDistrictBtn1',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterDistrictPanel2=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterDistrictPanel2',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select District:'}},filterDistrictCombo2,{xtype:'button',id:'filterDistrictBtn2',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterDistrictPanel3=new Ext.FormPanel({labelAlign:'side',labelWidth:130,frame:false,id:'filterDistrictPanel3',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select District:'}},filterDistrictCombo3,{xtype:'button',id:'filterDistrictBtn3',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterRoutePanel0=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterRoutePanel0',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterRouteCombo0,{xtype:'button',id:'filterRouteBtn0',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterRoutePanel1=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterRoutePanel1',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterRouteCombo1,{xtype:'button',id:'filterRouteBtn1',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterRoutePanel2=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterRoutePanel2',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterRouteCombo2,{xtype:'button',id:'filterRouteBtn2',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterRoutePanel3=new Ext.FormPanel({labelAlign:'side',labelWidth:130,frame:false,id:'filterRoutePanel3',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterRouteCombo3,{xtype:'button',id:'filterRouteBtn3',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterPopularRoutePanel0=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterPopularRoutePanel0',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterPopularRouteCombo0,{xtype:'button',id:'filterPopularRouteBtn0',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterPopularRoutePanel1=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterPopularRoutePanel1',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterPopularRouteCombo1,{xtype:'button',id:'filterPopularRouteBtn1',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterPopularRoutePanel2=new Ext.FormPanel({labelAlign:'side',labelWidth:100,frame:false,id:'filterPopularRoutePanel2',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterPopularRouteCombo2,{xtype:'button',id:'filterPopularRouteBtn2',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});var filterPopularRoutePanel3=new Ext.FormPanel({labelAlign:'side',labelWidth:130,frame:false,id:'filterPopularRoutePanel3',bodyStyle:'padding: 0px 5px 5px 5px',layout:'hbox',autoWidth:true,header:false,border:false,items:[{xtype:'box',id:'cbxLbl',width:130,autoEl:{cn:'Select Route:'}},filterPopularRouteCombo3,{xtype:'button',id:'filterPopularRouteBtn3',text:'Remove',handler:bhndRemoveCbx,style:{marginLeft:'5px'}}]});function bhndRemoveCbx(btn,evntObj){var cbx=btn.previousSibling();var cbxNum=cbx.getId().substr(cbx.getId().search(/[0-9]/));var cbxBaseName=cbx.getId().substr(0,cbx.getId().search(/[0-9]/));var allVal=combineComboValues(cbxBaseName,4);var allValAr=allVal.split('|');allValAr.splice(cbxNum,1);var filterType='';if(cbxBaseName==='filterDistrictCombo')filterType='district';if(cbxBaseName==='filterRouteCombo')filterType='road';if(cbxBaseName==='filterPopularRouteCombo')filterType='popularRoute';updateSearch(filterType,combineValues(allValAr));}
function isCbxValueDuplicated(comboName,num){if(!num||num===0){return false;}
var cbxArray=new Array();var cnt=0;for(i=0;i<num;i++){try{var value=Ext.getCmp(comboName+i).getValue();if(value==='undefined'||value===''||value===null){;}else{cbxArray[cnt++]=value;}}catch(err){return false;}}
if(cbxArray.unique(true).length!=cbxArray.length){Ext.Msg.alert('Duplicate','This value is already selected.  Please select another.');return true;}
return false;}
function noValuesCheck(comboName,num,filterName){var values=combineComboValues(comboName,num);if(values.length===0){var cbx=Ext.getCmp(comboName+"1");cbx.ownerCt.setVisible(false);updateUrl(filterName,'');return true;}
return false;}
function combineComboValues(comboName,num){if(!num||num===0){return null;}
var array=new Array();for(i=0;i<num;i++){try{array[i]=Ext.getCmp(comboName+i).getValue();}catch(err){}}
var values=combineValues(array);return values;}
function combineValues(array){var values='';for(i=0;i<array.length;i++){var x=array[i];if(values&&x){values+='|';}
values+=x;}
return values;}
var listPanel=new Ext.Panel({id:'listView',frame:false,title:'Events List',iconCls:'listGridIcon',bodyStyle:'padding:5px 5px 0',layout:'anchor',autoWidth:true,items:[filterAllPanel,filterFormPanel,filterDistrictPanel0,filterDistrictPanel1,filterDistrictPanel2,filterDistrictPanel3,filterRoutePanel0,filterRoutePanel1,filterRoutePanel2,filterRoutePanel3,filterPopularRoutePanel0,filterPopularRoutePanel1,filterPopularRoutePanel2,filterPopularRoutePanel3,listGridPanel]});hideCbxPanels();var feedbackPanel=new Ext.FormPanel({labelAlign:'top',id:'feedback',frame:true,monitorValid:true,title:'Feedback',iconCls:'feedbackIcon',bodyStyle:'padding:5px 5px 0',width:600,layout:'form',items:[{xtype:'fieldset',title:'',autoHeight:true,layout:'fit',padding:10,items:[{xtype:'label',style:{marginBottom:'50px',marginTop:'50px',font:'bold 12px verdana',color:'#696969'},anchor:'100% 20%',html:'The Ministry of Transportation and Infrastructure encourages your feedback and questions regarding DriveBC. However, before contacting us please check to see if your question has already been answered in our <a href = "#faq">"Frequently Asked Questions" page</a>.'}]},{xtype:'textfield',fieldLabel:'Name (Optional)',tabIndex:1,allowBlank:true,name:'name',anchor:'100%'},{xtype:'textfield',fieldLabel:'Email (Optional)',tabIndex:4,allowBlank:true,name:'email',vtype:'email',anchor:'100%'},{xtype:'radiogroup',fieldLabel:'Please rate the DriveBC website',items:[{boxLabel:'Excellent',name:'rating',inputValue:'Excellent'},{boxLabel:'Good',name:'rating',inputValue:'Good'},{boxLabel:'Fair',name:'rating',inputValue:'Fair'},{boxLabel:'Poor',name:'rating',inputValue:'Poor'},{boxLabel:'No rating',name:'rating',inputValue:'No rating',checked:true}]},{xtype:'textarea',id:'comments',name:'comments',fieldLabel:'Comments and suggestions (Optional)',tabIndex:5,allowBlank:true,height:300,anchor:'100%'}],buttons:[{text:'Reset',tabIndex:6,handler:function(){feedbackPanel.getForm().reset();}},{text:'Submit',formBind:true,tabIndex:7,handler:function(){var form=feedbackPanel.getForm();form.submit({clientValidation:false,url:'feedback/DriveBCFeedback.php',waitMsg:'Sending information...',success:function(form,action){Ext.MessageBox.alert('Thanks!','Feedback sent to the DriveBC team.');form.reset();},failure:function(form,action){switch(action.failureType){case Ext.form.Action.CLIENT_INVALID:Ext.Msg.alert('Error','Form fields may not be submitted with invalid values');break;case Ext.form.Action.CONNECT_FAILURE:Ext.Msg.alert('Error','Communication failed');break;case Ext.form.Action.SERVER_INVALID:Ext.Msg.alert('Error',action.result.msg);break;default:Ext.Msg.alert('Error','Send message failed.');break;}}});}}]});var tabPanelTpl=new Ext.Template('<li class="{cls}" id="{id}"><a class="x-tab-strip-close" onclick="return false;"></a>','<a class="x-tab-right" onclick="return false;"><em class="x-tab-left">','<span class="x-tab-strip-inner"><span class="x-tab-strip-text {iconCls}">{text}</span></span>','</em></a></li>');tabPanelTpl.disableFormats=true;tabPanelTpl.compile();var webcamPanel=new Ext.TabPanel({id:'webcams',activeTab:0,deferredRender:true,title:'Webcam List',itemTpl:tabPanelTpl,iconCls:'webcamIcon',items:[{title:'Vancouver Island',autoHeight:true,items:vancIslandDV},{title:'Lower Mainland',items:lowerMainDV},{title:'Border Cams',items:borderCamsDV},{title:'Southern Interior',items:southIntDV},{title:'Northern',items:northernDV}]});var mainTabPanel=new Ext.TabPanel({renderTo:"mainTabPanel",id:'center-panel',deferredRender:true,monitorResize:true,activeTab:0,tabWidth:150,autoWidth:true,itemTpl:tabPanelTpl,tabCls:'tab-header',defaults:{autoHeight:true,autoScroll:false},items:[{autoLoad:'static/welcome.html',id:'welcome',title:'Welcome',autoHeight:false,height:700,iconCls:'welcomeIcon',bodyStyle:'background-color:#9BBEDF'},{contentEl:'mapTab',id:'mapView',title:'Map View',iconCls:'mapIcon',tbar:[{text:'Zoom to',iconCls:'zoomMenu',menu:zoomMenu}]},listPanel,webcamPanel,{autoLoad:'static/faq.html',id:'faq',title:'FAQ',iconCls:'faqIcon'},{autoLoad:'static/links.html',id:'links',title:'Related Links',iconCls:'nav'},feedbackPanel,{autoLoad:'static/help.html',id:'help',title:'Help',iconCls:'helpIcon'},{autoLoad:'static/new.html',id:'new',title:'What\'s New?',iconCls:'newIcon'}]});mainTabPanel.on('tabchange',function(tabPanel,tab){if(!Ext.History.getToken()||Ext.History.getToken().indexOf(tab.id)!==0){Ext.History.add(tab.id);}
if(tab.id=="mapView"){document.getElementById("mapLayersForm").style.display="block";}
else{document.getElementById("mapLayersForm").style.display="none";updateMapUrl(null);initEvtFilters();}});Ext.History.on('change',function(token){if(token){var tokenParts=token.split("&");var activeTab=tokenParts[0];if(mainTabPanel.getActiveTab().id!=activeTab){mainTabPanel.setActiveTab(activeTab);}
switch(activeTab){case"listView":updateSearch();break;case"mapView":updateMap();break;default:break;}}else{mainTabPanel.setActiveTab('welcome');}});mapWindow=new Ext.Window({id:'inset-map',layout:'fit',width:500,height:450,closeAction:'hide',plain:true,title:'Event Map Viewer',modal:true,resizable:true,iconCls:'insetMapIcon',items:{contentEl:'insetMapDiv'}});mainTabPanel.on('afterlayout',function(){mapResize();});mapWindow.on('afterlayout',function(){insetMapResize();});var urlParts=window.location.href.split("#");var activeTab="";if(urlParts.length>1){var tokenParts=urlParts[1].split("&");activeTab=tokenParts[0];}
if(activeTab!==""){mainTabPanel.setActiveTab(activeTab);}
if(!map){GetMap();}
dbcWeatherLayer=new DbcPushpinLayer({layerName:"weather forecast",layerShortName:"Weather",dataStore:weatherStore,zIndex:900,iconPath:icon_weather,clusterIconPath:icon_weather_cluster,clusterIconPathMajor:icon_weather_major_cluster,clusterInfoHeaderSuffix:"Locations",maxClusterInfoItemsWOScrollbar:2,getItemIcon:function(_this,ev){if(ev.json.warnings&&ev.json.warnings.description){return icon_weather_major;}else{return icon_weather;}},getItemDescription:function(ev){var desc="";if(ev.json.warnings&&ev.json.warnings.description){desc+="<div class='weatherWarning'>"+ev.json.warnings.description+"</div>";}
desc+="<table cellspacing='0' cellpadding='0' style='text-align:center'><tr>";for(var i=0;i<ev.json.forecast.forecasts.length;i++){desc+="<td>"+ev.json.forecast.forecasts[i].when+"</td>";}
desc+="</tr><tr>";for(i=0;i<ev.json.forecast.forecasts.length;i++){desc+="<td><img alt='"+ev.json.forecast.forecasts[i].description+"' src='http://www.weatheroffice.gc.ca/weathericons/"+
ev.json.forecast.forecasts[i].icon+"'/></td>";}
desc+="</tr><tr align='center'>";for(i=0;i<ev.json.forecast.forecasts.length;i++){desc+="<td><ul>";desc+="<li class='hight' title='high'>"+(ev.json.forecast.forecasts[i].high?(ev.json.forecast.forecasts[i].high+"&deg;C"):"&nbsp;")+"</li>";desc+="<li class='lowt' title='low'>"+(ev.json.forecast.forecasts[i].low?(ev.json.forecast.forecasts[i].low+"&deg;C"):"&nbsp;")+"</li>";desc+="</ul></td>";}
desc+="</tr></table><br/>Courtesy: <a href='http://www.weatheroffice.gc.ca'>Environment Canada</a>";return desc;}});dbcFerryLayer=new DbcPushpinLayer({layerName:"ferry",layerShortName:"Ferry",dataStore:ferryStore,zIndex:905,iconPath:icon_ferry,clusterIconPath:icon_ferry_cluster,clusterInfoHeaderSuffix:"Ferries",maxClusterInfoItemsWOScrollbar:10,getItemDescription:function(ev){return'<a target="_blank" href="'+ev.get('url')+'">'+ev.get('title')+' information.</a>';}});dbcWebcamLayer=new DbcPushpinLayer({layerName:"webcam",layerShortName:"Webcam",dataStore:webcamStore,zIndex:901,iconPath:icon_cam,clusterIconPath:icon_cam_cluster,clusterInfoHeaderSuffix:"Webcams",maxClusterInfoItemsWOScrollbar:2,getItemDescription:function(ev){imgurl='http://images.drivebc.ca/bchighwaycam/pub/cameras/'+ev.get('id')+'.jpg';clickurl='http://images.drivebc.ca/bchighwaycam/pub/html/dbc/'+ev.get('id')+'.html';var isNew=(ev.get("isNew")=="true")?"<div class=\"newCamLabel\">New!</div>":"";desc=isNew+ev.get('caption')+' <br/> '+'<a target="webcamWindow" href="'+clickurl+'"><img class="WebCamImg" src="'+imgurl+'"/></a>';return desc;},getItemIcon:function(_this,ev){var orient=ev.get('orientation');if(orient=='N'){return icon_cam_n;}else if(orient=='S'){return icon_cam_s;}else if(orient=='E'){return icon_cam_e;}else if(orient=='W'){return icon_cam_w;}else if(orient=='NE'){return icon_cam_ne;}else if(orient=='SE'){return icon_cam_se;}else if(orient=='NW'){return icon_cam_nw;}else if(orient=='SW'){return icon_cam_sw;}else{return icon_cam;}},getClusterDescription:function(_this,clshapes){desc='<div class="cluster_description"><table border=0 cellspacing=20 >';desc+='<tr>';for(var j=0;j<clshapes.length;j++){var clshp=clshapes[j];var pinDesc=clshp.description;pinDesc=pinDesc.replace('/pub/cameras/','/pub/cameras/tn/');desc+="<td valign=\"bottom\"><b>"+clshp.getTitle()+"</b> - "+pinDesc+"</td>";if((j%2)==1){desc+="</tr><tr>";}}
desc+='</tr></table></div>';desc=desc.replace(/WebCamImg/g,"WebCamImgCluster");return{desc:desc,hasMajorEvent:false};}});dbcFuturePlanedEventsLayer=new DbcPushpinLayer({layerName:"future planned events",layerShortName:"FuturePlanEvent",dataStore:eventStore,zIndex:904,iconPath:icon_future_event,clusterIconPath:icon_future_event_cluster,clusterIconPathMajor:icon_future_event_major_cluster,clusterInfoHeaderSuffix:"Future Planned Events",maxClusterInfoItemsWOScrollbar:3,getItemDescription:function(ev){var desc='<u>'+ev.get('road')+' '+ev.get('direction')+'</u> - '+ev.get('description');if(ev.get('severity')=='Major'){desc='<font color="#FF0000">'+desc+'</font>';}
return desc;},getItemIcon:function(_this,ev){if(ev.get('severity')=='Major'){return icon_future_event_major;}else{return icon_future_event;}},dataStoreFilter:function(record,id){return record.get('eventType')=='Future Planned';}});dbcCurrentPlanedEventsLayer=new DbcPushpinLayer({layerName:"current planned events",layerShortName:"CurrentPlanEvent",dataStore:eventStore,zIndex:903,iconPath:icon_current_event,clusterIconPath:icon_current_event_cluster,clusterIconPathMajor:icon_current_event_major_cluster,clusterInfoHeaderSuffix:"Current Planned Events",maxClusterInfoItemsWOScrollbar:3,getItemDescription:function(ev){var desc='<u>'+ev.get('road')+' '+ev.get('direction')+'</u> - '+ev.get('description');if(ev.get('severity')=='Major'){desc='<font color="#FF0000">'+desc+'</font>';}
return desc;},getItemIcon:function(_this,ev){if(ev.get('severity')=='Major'){return icon_current_event_major;}else{return icon_current_event;}},dataStoreFilter:function(record,id){return record.get('eventType')=='Current Planned';}});dbcIncidentsLayer=new DbcPushpinLayer({layerName:"incidents",layerShortName:"Incident",dataStore:eventStore,zIndex:906,iconPath:icon_incident,clusterIconPath:icon_incident_cluster,clusterIconPathMajor:icon_incident_major_cluster,clusterInfoHeaderSuffix:"Incidents",maxClusterInfoItemsWOScrollbar:3,getItemDescription:function(ev){var desc='<u>'+ev.get('road')+' '+ev.get('direction')+'</u> - '+ev.get('description');if(ev.get('severity')=='Major'){desc='<font color="#FF0000">'+desc+'</font>';}
return desc;},getItemIcon:function(_this,ev){if(ev.get('severity')=='Major'){return icon_incident_major;}else{return icon_incident;}},dataStoreFilter:function(record,id){return record.get('eventType')=='Incident';}});dbcRoadConditionsLayer=new DbcPushpinLayer({layerName:"road conditions",layerShortName:"RoadCond",dataStore:eventStore,zIndex:902,iconPath:icon_road_cond,clusterIconPath:icon_road_cond_cluster,clusterIconPathMajor:icon_road_cond_major_cluster,clusterInfoHeaderSuffix:"Road Conditions",maxClusterInfoItemsWOScrollbar:3,getItemDescription:function(ev){var desc='<u>'+ev.get('road')+' '+ev.get('direction')+'</u> - '+ev.get('description');if(ev.get('severity')=='Major'){desc='<font color="#FF0000">'+desc+'</font>';}
return desc;},getItemIcon:function(_this,ev){if(ev.get('severity')=='Major'){return icon_road_cond_major;}else{return icon_road_cond;}},dataStoreFilter:function(record,id){return record.get('eventType')=='Road Condition';}});var eventJson=Ext.Ajax.request({url:'data/events.json',success:function(response,opts){if(eventJson.conn.getResponseHeader("Last-Modified")&&eventJson.conn.getResponseHeader("Date")&&(new Date(eventJson.conn.getResponseHeader("Last-Modified"))).getElapsed(new Date(eventJson.conn.getResponseHeader("Date")))>1800000){location.href="http://www.th.gov.bc.ca/drivebc/news_v2.aspx";}
else{eventStore.loadStatus=1;eventStore.loadData(Ext.decode(response.responseText));}},disableCaching:true});webcamStore.loadStatus=1;webcamStore.load();GetInsetMap();});
