function checkPostCode (toCheck) { // Permitted letters depend upon their position in the postcode. var alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1 var alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2 var alpha3 = "[abcdefghjkstuw]"; // Character 3 var alpha4 = "[abehmnprvwxy]"; // Character 4 var alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5 // Array holds the regular expressions for the valid postcodes var pcexp = new Array (); // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Expression for postcodes: ANA NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Expression for postcodes: AANA NAA pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i")); // Exception for the special postcode GIR 0AA pcexp.push (/^(GIR)(\s*)(0AA)$/i); // Standard BFPO numbers pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i); // c/o BFPO numbers pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i); // Load up the string to check var postCode = toCheck; // Assume we're not going to find a valid postcode var valid = false; // Check the string against the types of post codes for ( var i=0; i'); $('#map').append('
Loading...
'); } function hide_loader(){ $('#loader_notifier_info').remove(); $('#loader_notifier_info_all').remove(); } var point_info_chache = new Array(); function run_facebox(id, type){ if (point_info_chache[id] == undefined){ jQuery.ajax({ type: "GET", url: 'http://www.drivesafely.org/map_point_details.php', data: "pid="+id+"&type="+type, success: function(msg){ $('#point_div_message_text').html(msg); point_info_chache[id] = msg; } }); } else { $('#point_div_message_text').html(point_info_chache[id]); } $('#point_div_message').slideDown('slow'); $('#point_div_message').css('position','absolute'); $('#point_div_message').css('top','207px'); } if (GBrowserIsCompatible()) { var map; var geo; var reasons=[]; var gmarkers = []; var gmarkers_1 = []; var gmarkers_2 = []; var htmls = []; var gmarkers_end = []; var no_of_villa = 0; var small_map; var map_center_lat; var map_center_lng; var bounds = new GLatLngBounds(); var maxdistance = 50; var area_id = 0; var window_open = 0; var pid = ''; var marker_listener_on = 1; var after_move = 0; var temp_pc = 0; var temp_north = 0; var temp_south = 0; var temp_east = 0; var temp_west = 0; var temp_zoom = 0; var map_margin_h = 0.4; var map_margin_w = 1.2; var after_search = 0; var nop = 0; var hidden=0; var gdir; var geocoder = null; var addressMarker; var GDir1, normalProj, waypoints=[], waypoints2=[], gpolys=[], routeNodes=[], myNode, markerDragged, isDragged, lastIndex, prevIndex; var allGDir1=[]; var rectBounds = new GLatLngBounds( new GLatLng(51.5395, -1.43372), new GLatLng(52.4527, 0.455933) ); // A Rectangle is a simple overlay that outlines a lat/lng bounds on the // map. It has a border of the given weight and color and can optionally // have a semi-transparent background color. function Rectangle(bounds, opt_weight, opt_color) { this.bounds_ = bounds; this.weight_ = opt_weight || 2; this.color_ = opt_color || "#cc0000"; } Rectangle.prototype = new GOverlay(); // Creates the DIV representing this rectangle. Rectangle.prototype.initialize = function(map) { // Create the DIV representing our rectangle var div = document.createElement("div"); div.style.border = this.weight_ + "px solid " + this.color_; div.style.position = "absolute"; // Our rectangle is flat against the map, so we add our selves to the // MAP_PANE pane, which is at the same z-index as the map itself (i.e., // below the marker shadows) map.getPane(G_MAP_MAP_PANE).appendChild(div); this.map_ = map; this.div_ = div; } // Remove the main DIV from the map pane Rectangle.prototype.remove = function() { this.div_.parentNode.removeChild(this.div_); } // Copy our data to a new Rectangle Rectangle.prototype.copy = function() { return new Rectangle(this.bounds_, this.weight_, this.color_, this.backgroundColor_, this.opacity_); } // Redraw the rectangle based on the current projection and zoom level Rectangle.prototype.redraw = function(force) { // We only need to redraw if the coordinate system has changed if (!force) return; // Calculate the DIV coordinates of two opposite corners of our bounds to // get the size and position of our rectangle var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest()); var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast()); // Now position our DIV based on the DIV coordinates of our bounds this.div_.style.width = Math.abs(c2.x - c1.x) + "px"; this.div_.style.height = Math.abs(c2.y - c1.y) + "px"; this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px"; this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px"; } function setupDragZoom() { /* first set of options is for the visual overlay.*/ var boxStyleOpts = { opacity: .2, border: "2px solid red" }; /* second set of options is for everything else */ var otherOpts = { buttonHTML: "", buttonZoomingHTML: "", buttonStartingStyle: {width: '24px', height: '24px'}, overlayRemoveTime: 1000 }; map.addControl(new DragZoomControl(boxStyleOpts, otherOpts, {}), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(15, 110))); } function toggle_logo(elementId) { var source = document.getElementById(elementId); //Terms of use link var divs = source.getElementsByTagName('div'); var current = (divs[14].style.display == 'none') ? 'block' : 'none'; divs[14].style.display = current; //Google Logo link /*var links = source.getElementsByTagName('a'); var current = (links[1].style.display == 'none') ? 'block' : 'none'; links[1].style.display = current;*/ } // This function just makes a pretty table for the EWindow contents // With a close icon function pretty(a,b) { return '
' + b + '
'; } function pretty_info(a,b) { return '' + '
' + a + '
' + b + '
'; } function createIcon(image){ var image_ico = "http://www.drivesafely.org/upload/points_types/"+image; var icon = new GIcon(); icon.image = image_ico; icon.iconAnchor = new GPoint(5, 5); icon.infoWindowAnchor = new GPoint(5, 1); return icon; } function setDirections(directions, fromAddress, toAddress, viaAddress) { directions.load("from: " + fromAddress + viaAddress + " to: " + toAddress, { preserveViewport:true, getPolyline:true, getSteps:false }); } function createMarker_view(point, lat2, lng2, id, in_areas, name, site_id, camera_id, type_of_camera, type, image_icon, image, url, rel_id, additional_markers) { var imageadd = ''; var editlink = ''; var urllink = ''; if(image!=''){ imageadd = ""; } if(name!=''){ name = "
"+ name +""; }else{ name=''; } if(camera_id!=''){ camera_id = "
Camera ID: "+ camera_id +""; }else{ camera_id=''; } if(site_id!=''){ site_id = "
Site ID: "+ site_id +""; }else{ site_id=''; } if(type_of_camera!=''){ type_of_camera = "

"+ type_of_camera +""; }else{ type_of_camera=''; } if(type=='2' && map.getZoom()>=11 && (point.lat()!=lat2 && point.lng()!=lng2) && (lat2!='0.000000' && lng2!='0.000000') ){ // hidden = 1; // show_loader(); var additional_markers_points=[]; var viaAddress = ''; if(additional_markers!=''){ additional_markers_points = additional_markers.split('|'); if(additional_markers_points.length>0){ for(var iii=0;iii1){ for(var jjj=1;jjj<(dr.getNumGeocodes()-1);jjj++){ var mark1 = dr.getMarker(jjj); mark1.getIcon().image = ''; mark1.getIcon().iconSize = new GSize(0, 0); mark1.getIcon().iconAnchor = new GPoint(0, 0); mark1.getIcon().shadow = ''; } } var mark1 = dr.getMarker(0); mark1.getIcon().image = ''; mark1.getIcon().iconSize = new GSize(0, 0); mark1.getIcon().iconAnchor = new GPoint(0, 0); mark1.getIcon().shadow = ''; point2 = mark1.getLatLng(); createMarker_view2(point2, lat2, lng2, id, id, in_areas, name, site_id, camera_id, type_of_camera, type, image_icon, image, url, rel_id); var mark2 = dr.getMarker((dr.getNumGeocodes()-1)); mark2.getIcon().image = ''; mark2.getIcon().iconSize = new GSize(0, 0); mark2.getIcon().iconAnchor = new GPoint(0, 0); mark2.getIcon().shadow = ''; var point2 = mark2.getLatLng(); var ids = (id+1000); createMarker_view2(point2, lat2, lng2, ids, id, in_areas, name, site_id, camera_id, type_of_camera, type, image_icon, image, url, rel_id); /*GEvent.addListener(gp, 'click', function() { marker_listener_on = 0; ew.openOnMarker(marker,html); pid = id; });*/ map.addOverlay(gp); update_pint_types(); } }); }else{ var icon = createIcon(image_icon); var html = "
"+ imageadd + name + camera_id + site_id + type_of_camera +"

Casualty history For more information about this speed enforcement site, click here
"; html = pretty(name,html); var marker = new GMarker(point, icon); marker.mycategory = type; marker.myname = id; //html = pretty_info(name,html); if(pid==id && pid>0 ){ ew.openOnMarker(marker,html); } GEvent.addListener(marker, 'click', function() { marker_listener_on = 0; ew.openOnMarker(marker,html); map.setCenter(marker.getPoint()) //if(in_areas=='n'){ //alert('not in area'); //} pid = id; }); gmarkers.push(marker); map.addOverlay(marker); } // return marker; } function createMarker_view2(point, lat2, lng2, id, id_first, in_areas, name, site_id, camera_id, type_of_camera, type, image_icon, image, url, rel_id) { var icon = createIcon(image_icon); var imageadd = ''; var editlink = ''; var urllink = ''; if(image!=''){ imageadd = ""; } var html = "
"+ imageadd + name + camera_id + site_id + type_of_camera +"

Casualty history For more information about this speed enforcement site, click here
"; html = pretty(name,html); var marker = new GMarker(point, icon); marker.mycategory = type; marker.myname = id; //html = pretty_info(name,html); //pid = id; if(pid==id && pid>0 ){ ew.openOnMarker(marker,html); } GEvent.addListener(marker, 'click', function() { marker_listener_on = 0; ew.openOnMarker(marker,html); map.setCenter(marker.getPoint()) //if(in_areas=='n'){ //alert('not in area'); //} pid = id; }); gmarkers.push(marker); map.addOverlay(marker); // return marker; } function update_pint_types(){ var arr = $("input"); jQuery.each(arr, function() { if(this.name=='box'){ if (this.checked) { show(this.value); } else { hide(this.value); } } }); } function boxclick_distance(mdistance) { var point = map.getCenter(); maxdistance = mdistance; mdistance = mdistance*1.60934; var distance = 0; for (var i=0; i0){ if(distance<=mdistance){ if(gmarkers_1[i] == true){ gmarkers[i].show(); } gmarkers_2[i] = true; }else{ gmarkers[i].hide(); gmarkers_2[i] = false; } }else{ if(gmarkers_1[i] == true){ gmarkers[i].show(); } gmarkers_2[i] = true; } } } // == shows all markers of a particular category, and ensures the checkbox is checked == function show(category) { for (var i=0; i0){ var distance = point.distanceFrom(marker.getPoint())/1000; if(distance>maxdistance){ gmarkers_2[i] = false; } }*/ } update_pint_types(); //boxclick_distance(maxdistance); marker_listener_on = 1; if(after_move == 0 && pid==0){ ew.hide(); //after_move = 1; } map.addOverlay(new Rectangle(rectBounds)); /* allGDir1[0] = new GDirections(); var point1 = new GLatLng(52.204240, -0.980597); var point2 = new GLatLng(51.755940, -0.856933); allGDir1[0].loadFromWaypoints([point1.toUrlValue(6), point2.toUrlValue(6)], {getPolyline:true}); GEvent.addListener(allGDir1[0], "load", function() { var gp = allGDir1[0].getPolyline(); var point = gp.getVertex(gp.getVertexCount() - 1); // snap to last vertex in the polyline waypoints.push(point); map.addOverlay(gp); gpolys.push(gp); }); */ if(hidden==0){ hide_loader(); } }); } function initialize_main_map() { map = new GMap2(document.getElementById("map")); geo = new GClientGeocoder(); reasons[G_GEO_SUCCESS] = "Success"; reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value."; reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address."; reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons."; reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given"; reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded."; reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed."; pid = 0; var center = new GLatLng(51.9984, -0.488892); map.setCenter(center, 9); var marker; toggle_logo('map'); boxclick_distance(50); // Create an EWindow ew = new EWindow(map, E_STYLE_7); map.addOverlay(ew); gdir = new GDirections(map); update_markers(); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); var options = { listingTypes : "blended", searchFormHint : " road name, area or postcode", resultList : document.getElementById("search_results") }; map.addControl(new google.maps.LocalSearch(options), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(-196,-39))); map.enableDoubleClickZoom(); setupDragZoom(); GEvent.addListener(map,'click',function() { after_move = 0; if(marker_listener_on==1){ ew.hide(); pid = 0; }else{ marker_listener_on = 1; } }); GEvent.addListener(map,'zoomend',function() { var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var zoom_d = 0.6; if(map.getZoom()==8){ zoom_d = 0.3; } if(map.getZoom()==10){ zoom_d = (map.getZoom()-9)*1.2; } if(map.getZoom()==11){ zoom_d = (map.getZoom()-9)*1.2; } if(map.getZoom()==12){ zoom_d = (map.getZoom()-9)*1.7; } if(map.getZoom()==13){ zoom_d = (map.getZoom()-9)*2.4; } if(map.getZoom()==14){ zoom_d = (map.getZoom()-9)*4; } if(map.getZoom()==15){ zoom_d = (map.getZoom()-9)*7; } if(map.getZoom()==16){ zoom_d = (map.getZoom()-9)*13; } if(map.getZoom()==17){ zoom_d = (map.getZoom()-9)*20; } var zoom_d2 = 1; if(map.getZoom()==8){ zoom_d2 = 0.5; } if(map.getZoom()>9 && map.getZoom()<12){ zoom_d2 = (map.getZoom()-9)*1.9; } if(map.getZoom()==12){ zoom_d2 = (map.getZoom()-9)*2.4; } if(map.getZoom()==13){ zoom_d2 = (map.getZoom()-9)*3.6; } if(map.getZoom()==14){ zoom_d2 = (map.getZoom()-9)*5.6; } if(map.getZoom()==15){ zoom_d2 = (map.getZoom()-9)*9; } if(map.getZoom()==16){ zoom_d2 = (map.getZoom()-9)*17; } if(map.getZoom()==17){ zoom_d2 = (map.getZoom()-9)*30; } if(southWest.lat()>=(51.5395-(map_margin_h/zoom_d)) && northEast.lat()<=(52.4527+(map_margin_h/zoom_d)) && southWest.lng()>=(-1.43372-(map_margin_w/zoom_d2)) && northEast.lng()<=(0.455933+(map_margin_w/zoom_d2)) ){ after_move = 1; update_markers(); }else{ alert('Sorry - this location was not found in Bedfordshire'); map.setZoom(temp_zoom); } }); GEvent.addListener(map,'moveend',function() { var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var zoom_d = 0.6; if(map.getZoom()==8){ zoom_d = 0.3; } if(map.getZoom()==10){ zoom_d = (map.getZoom()-9)*1.2; } if(map.getZoom()==11){ zoom_d = (map.getZoom()-9)*1.2; } if(map.getZoom()==12){ zoom_d = (map.getZoom()-9)*1.7; } if(map.getZoom()==13){ zoom_d = (map.getZoom()-9)*2.4; } if(map.getZoom()==14){ zoom_d = (map.getZoom()-9)*4; } if(map.getZoom()==15){ zoom_d = (map.getZoom()-9)*7; } if(map.getZoom()==16){ zoom_d = (map.getZoom()-9)*13; } if(map.getZoom()==17){ zoom_d = (map.getZoom()-9)*20; } var zoom_d2 = 1; if(map.getZoom()==8){ zoom_d2 = 0.5; } if(map.getZoom()>9 && map.getZoom()<12){ zoom_d2 = (map.getZoom()-9)*1.9; } if(map.getZoom()==12){ zoom_d2 = (map.getZoom()-9)*2.4; } if(map.getZoom()==13){ zoom_d2 = (map.getZoom()-9)*3.6; } if(map.getZoom()==14){ zoom_d2 = (map.getZoom()-9)*5.6; } if(map.getZoom()==15){ zoom_d2 = (map.getZoom()-9)*9; } if(map.getZoom()==16){ zoom_d2 = (map.getZoom()-9)*17; } if(map.getZoom()==17){ zoom_d2 = (map.getZoom()-9)*30; } if(southWest.lat()>=(51.5395-(map_margin_h/zoom_d)) && northEast.lat()<=(52.4527+(map_margin_h/zoom_d)) && southWest.lng()>=(-1.43372-(map_margin_w/zoom_d2)) && northEast.lng()<=(0.455933+(map_margin_w/zoom_d2)) ){ after_move = 1; update_markers(); }else{ alert('Sorry - this location was not found in Bedfordshire'); map.setCenter(temp_pc); } }); } // ====== Plot a marker after positive reponse to "did you mean" ====== function place(lat,lng) { var point = new GLatLng(lat,lng); map.setCenter(point); //var marker_point = new GMarker(point, { draggable: false}); //map.addOverlay(marker_point); //update_markers(); //document.getElementById("message").innerHTML = ""; } // ====== Geocoding ====== function showAddress() { var search_serial = $("#search_serial").val(); if(search_serial!=''){ show_loader(); jQuery.ajax({ type: "GET", url: 'http://www.drivesafely.org/ajax_search_by_serial.php', data: "search_serial="+search_serial, success: function(msg){ if(msg=='err'){ hide_loader(); alert('Could not find camera serial number "'+search_serial+ '" '); }else{ map.setZoom(14); var lat_lng = msg.split("|"); pid = lat_lng[2]; hide_loader(); place(lat_lng[0],lat_lng[1]); } } }); }else{ var search = $("#search").val(); var s; if (!checkPostCode(search)){ s = search; } else { s = checkPostCode(search); } // ====== Perform the Geocoding ====== geo.getLocations(s, function (result) { //map.clearOverlays(); if (result.Status.code == G_GEO_SUCCESS) { // ===== If there was more than one result, "ask did you mean" on them all ===== if (result.Placemark.length > 1) { document.getElementById("message").innerHTML = "Did you mean: [Clear searching results]"; // Loop through the results for (var i=0; i"+ result.Placemark[i].address+""; } } // ===== If there was a single marker ===== else { //if (result.Placemark.length > 0) { document.getElementById("message").innerHTML = ""; var p = result.Placemark[0].Point.coordinates; place(p[1],p[0]); } } // ====== Decode the error status ====== else { var reason="Code "+result.Status.code; if (reasons[result.Status.code]) { reason = reasons[result.Status.code] } alert('Could not find "'+s+ '" ' + reason); } } ); } } function clear_results(){ document.getElementById("message").innerHTML = '
'; } }else { alert("Sorry, the Google Maps API is not compatible with this browser"); }