$(document).ready(function() {

//DISABLES CACHING OF XML
        $.ajaxSetup ({ 
        // Disable caching of AJAX responses */ 
        cache: false 
        });

    //initialise map
    $("#map").css({
        height: 330,
        width: 490
    });

    var myLatLng = new google.maps.LatLng(51.507060, -0.012617);
    MYMAP.init('#map', myLatLng, 12);

    // Selection of correct XML doc based on drop down menu selection
    var DropDownSelection = $("#ctl00_mainContent_catDropdown").val();
    var xmlDoc;
    var ListingType;

    // Select appropriate xml file
    if (DropDownSelection == "119") {
        xmlDoc = "/xml/venues/Art_and_Theatre.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "120") {
        xmlDoc = "/xml/venues/Attractions.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "121") {
        xmlDoc = "/xml/venues/Bars_and_Clubs.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "122") {
        xmlDoc = "/xml/venues/Free_to_Do.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "123") {
        xmlDoc = "/xml/venues/Restaurants_and_Cafes.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "124") {
        xmlDoc = "/xml/venues/Places_to_Stay.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "125") {
        xmlDoc = "/xml/venues/Shopping.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "126") {
        xmlDoc = "/xml/events/Upcoming_Events.xml";
        ListingType = "event";
    } else if (DropDownSelection == "127") {
        xmlDoc = "/xml/venues/Advice_Centres.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "128") {
        xmlDoc = "/xml/venues/Children's_Services.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "129") {
        xmlDoc = "/xml/venues/Education_and_employment_Advice.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "130") {
        xmlDoc = "/xml/venues/Health_and_Wellbeing.xml";
        ListingType = "venue";
    } else if (DropDownSelection == "131") {
        xmlDoc = "/xml/events/events.xml";
        ListingType = "event";
    } else if (DropDownSelection == "283") {
        xmlDoc = "/xml/venues/Hidden_Gems.xml";
        ListingType = "venue";
    } 

    // filter checkboxes:
    $("#ctl00_mainContent_dlrRep_TaxList_0").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_1").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_2").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_3").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_4").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_5").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_6").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_7").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_8").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#ctl00_mainContent_dlrRep_TaxList_9").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });
    //Time filters
    $("#TimeToday").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#Time7").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#Time14").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#Time28").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        }
    });

    $("#TimeMoreThan28").click(function() {
        if ($(this).is(':checked')) {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
        } else {
            removeMarkers();
            MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);

        }
    });
    

    $("#mySelect").change(function() {
        SetMapToSelectedStation();
        removeMarkers();
        MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);
    });

    if (ListingType == "venue") {
        $("#EventTimeOptions").css("display", "none");
    }

    // add DLR polylines to map (not using encoded anymore as using v3 of the map api
    MYMAP.placeMarkersStations("/xml/stations/markersStations.xml");

    // on load function
    MYMAP.onload(xmlDoc, ListingType);

    //*****************************
    // Station drop down functionality
    $.ajax({
        type: "GET",
        url: "/xml/stations/markersStations.xml",
        dataType: "xml",
        success: function(xml) {
            var select = $('#mySelect');
            select.append("<option value=''>All Stations</option>");
            $(xml).find('marker').each(function() {
                var name = $(this).find('name').text();
                select.append("<option value='" + name + "'>" + name + "</option>");
            });

            // get the query string value of the station if available
            var station = GetParameterInQueryString("station");
            $("#mySelect").val(station);
            SetMapToSelectedStation();
            //removeMarkers();
            //MYMAP.ReFreshMapMarkers(xmlDoc, ListingType);            
        }
    });

    // check all checkboxes
    $("#CheckboxTbl1").find(':checkbox').each(function() {
        this.checked = true;
    });
    $("#CheckboxTbl2").find(':checkbox').each(function() {
        this.checked = true;
    });

});

var markers = new Array();
var dateCheck = new Array();

var MYMAP = {
    map: null,
    bounds: null
}

// map initialisation
MYMAP.init = function(selector, latLng, zoom) {
    var myOptions = {
        zoom: zoom,
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    this.map = new google.maps.Map($(selector)[0], myOptions);

}

// onload function
MYMAP.onload = function(filename, ListingType) {
    $("#NoResults").css("display", "none");
    var i = 1;
    var activeWindow;

    var ResultCount = false;

    $.get(filename, function(xml) {
        //loop through each xml node 'marker'
        $(xml).find("marker").each(function() {

            //set variable values
            var name = $(this).find('name').text();
            var link = $(this).find('contentId').text();
            var Address = $(this).find('address').text();
            var web = $(this).find('webAddress').text();
            var tel = $(this).find('contactNumber').text();
            var lat = $(this).find('latitude').text();
            var lng = $(this).find('longitude').text();
            var desc = $(this).find('fullDescription').text();
            var NearestStation = $(this).find('nearestStation').text();
            var StationLink = $(this).find('nearestStationLink').text();

            // Get date diff in days for use with time filter
            var DateFrom = new Date();
            var DateTo = new Date();

            // Get date values
            DateFrom = $(this).find('dateFrom').text();
            DateTo = $(this).find('dateTo').text();

            if (DateFrom.length > 0) {

                var DateFromNew = DateFrom.substring(0, 10);
                var DateToNew = DateTo.substring(0, 10);

                var currentTime = new Date();
                var month = currentTime.getMonth() + 1;
                var day = currentTime.getDate();
                var year = currentTime.getFullYear();

                var TodaysDate = day + "/" + month + "/" + year;

                var minutes = 1000 * 60;
                var hours = minutes * 60;
                var days = hours * 24;

                var foo_date1 = getDateFromFormat(DateFromNew, "d/M/y");
                var foo_date2 = getDateFromFormat(TodaysDate, "d/M/y");

                var foo_date3 = getDateFromFormat(DateToNew, "d/M/y");

                var diff_date = Math.round((foo_date1 - foo_date2) / days);
                var diff_date2 = Math.round((foo_date3 - foo_date2) / days);

            } else {
                // Need to be set if a venue
                var diff_date = "";
                var diff_date2 = "";
            }

            // need to set this for view link function in panel
            cat0 = $(this).find('category0').text();

            var ShowStation = true;

            // check the results are filtered by station too if something other than 'all stations' is selected.
            var stationValue = GetParameterInQueryString("station");

            if (stationValue == "") {
                // if it doesn't have a specific staiton selected then we'll show anyway
                ShowStation = true;
            } else {
                // check what station filter to apply
                if (stationValue != NearestStation) {
                    ShowStation = false;
                }
            }

            // check event is not in the past
            if ((diff_date >= 0 && diff_date < 99999 || diff_date2 > 0) && (ShowStation == true)) {

                ResultCount = true;

                // set marker
                var point = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));

                var icon = "/images/mapping/markers/" + i + ".png";

                var marker = new google.maps.Marker({
                    position: point,
                    icon: icon,
                    map: MYMAP.map
                });

                // set infowindow properties
                var infoWindow = new google.maps.InfoWindow();

                var LimitedDesc = desc.substring(0, 150);

                if (ListingType == "venue") {

                    var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                }
                else {
                    var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                }
                google.maps.event.addListener(marker, 'click', function() {
                    // close info window if one is already open
                    if (activeWindow != null) activeWindow.close();
                    infoWindow.setContent(html);
                    infoWindow.open(MYMAP.map, marker);
                    activeWindow = infoWindow;
                });

                var htmlMinor = "<div style='width:260px; height: 55px; overflow:hidden;'><p><strong><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/></p></div>";
                google.maps.event.addListener(marker, 'mouseover', function() {

                    if (activeWindow != null) activeWindow.close();
                    infoWindow.setContent(htmlMinor);
                    infoWindow.open(MYMAP.map, marker);
                    activeWindow = infoWindow;
                });
                // Panel functionality
                var uniqueCat = cat0.substring(0, 3);

                // add markers to array so we can remove them later
                marker.category = cat0;
                marker.date = diff_date;
                markers.push(marker);

                $("#EventList").append("<p style='margin-bottom:10px;' class=" + uniqueCat + " title=" + diff_date + "><strong><span style='font-size:1.1em;'>" + i + ".&nbsp;&nbsp;<img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + "> " + name + " </a></span></strong>" + "<br />" + desc + " <br /> <a href='#' title=" + uniqueCat + i + ">View on Map</a>&nbsp;&nbsp;&nbsp;<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a></p>");

                $("a[title='" + uniqueCat + i + "']").click(function() {

                    var myLatLng = new google.maps.LatLng(lat, lng);
                    MYMAP.map.panTo(myLatLng);
                    MYMAP.map.setZoom(15);

                    if (activeWindow != null) activeWindow.close();
                    // if its a venue...
                    if (ListingType == "venue") {

                        var infoWindow = new google.maps.InfoWindow(
                {
                    content: "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>",
                    position: myLatLng
                });
                    }
                    else {
                        // if its an event...
                        var infoWindow = new google.maps.InfoWindow(
                {
                    content: "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>",
                    position: myLatLng
                });
                    }
                    infoWindow.open(MYMAP.map);
                    activeWindow = infoWindow;
                });

                i++;

                // check querystrng for id. loop through xml (doing here) and check against it. if matches panTo location of event/venuw
                var PanToId = GetParameterInQueryString("itemId");

                if (PanToId != "") {
                    if (link == PanToId) {
                        var myLatLng = new google.maps.LatLng(lat, lng);
                        MYMAP.map.panTo(myLatLng);
                        MYMAP.map.setZoom(15);

                        //Open up infowindow
                        if (ListingType == "venue") {

                            var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                        }
                        else {
                            var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                        }
                        if (activeWindow != null) activeWindow.close();
                        infoWindow.setContent(html);
                        infoWindow.open(MYMAP.map, marker);
                        activeWindow = infoWindow;
                    }
                }
            }

        });
        // if not results show a message
        if (ResultCount == false) {
            $("#NoResults").css("display", "block");
        }
    });

}

// remove markers and panel info function
function removeMarkers() {
    for (var i = 0; i < markers.length; i++) {
        markers[i].setMap(null);
        $("#EventList p").empty();
    }
}

// re fresh markers function (actioned whenever a checkbox is changed)
MYMAP.ReFreshMapMarkers = function(filename, ListingType) {
    // remove no results panel, set up variables needed for function
    $("#NoResults").css("display", "none");
    var i = 0;
    var CatArray = new Array();
    var t = 1;
    var activeWindow;

    var ResultCount = false;
    // Get labels of all ticked checkboxes
    $("#CheckboxTbl1").find(':checkbox').each(function() {
        if (this.checked == true) {
            var CatLabel = $(this).parent().find("label").text();
            CatArray[i] = CatLabel;
            i++;
        }
    });

    var CatArrayLength = CatArray.length;

    // reading in xml doc.
    $.get(filename, function(xml) {
        $(xml).find("marker").each(function() {

            var name = $(this).find('name').text();
            var link = $(this).find('contentId').text();
            var Address = $(this).find('address').text();
            var web = $(this).find('webAddress').text();
            var tel = $(this).find('contactNumber').text();
            var lat = $(this).find('latitude').text();
            var lng = $(this).find('longitude').text();
            var desc = $(this).find('fullDescription').text();
            var NearestStation = $(this).find('nearestStation').text();
            var StationLink = $(this).find('nearestStationLink').text();

            var DateFrom = new Date();
            var DateTo = new Date();

            DateFrom = $(this).find('dateFrom').text();
            DateTo = $(this).find('dateTo').text();
            // date check
            if (DateFrom.length > 0) {

                var DateFromNew = DateFrom.substring(0, 10);
                var DateToNew = DateTo.substring(0, 10);

                var currentTime = new Date();
                var month = currentTime.getMonth() + 1;
                var day = currentTime.getDate();
                var year = currentTime.getFullYear();

                var TodaysDate = day + "/" + month + "/" + year;

                var minutes = 1000 * 60;
                var hours = minutes * 60;
                var days = hours * 24;

                var foo_date1 = getDateFromFormat(DateFromNew, "d/M/y");
                var foo_date2 = getDateFromFormat(TodaysDate, "d/M/y");

                var foo_date3 = getDateFromFormat(DateToNew, "d/M/y");

                var diff_date = Math.round((foo_date1 - foo_date2) / days);
                var diff_date2 = Math.round((foo_date3 - foo_date2) / days);

            } else {
                var diff_date = "";
                var diff_date2 = "";
            }
            // assign all categories from venue/event
            cat0 = $(this).find('category0').text();
            cat1 = $(this).find('category1').text();
            cat2 = $(this).find('category2').text();
            cat3 = $(this).find('category3').text();
            cat4 = $(this).find('category4').text();
            cat5 = $(this).find('category5').text();
            cat6 = $(this).find('category6').text();
            cat7 = $(this).find('category7').text();
            cat8 = $(this).find('category8').text();
            cat9 = $(this).find('category9').text();
            // variables for showing/hiding event/venue - both these need to be true to be shown
            var ShowCat = false;
            var ShowTime = false;

            if (ListingType == "venue") {
                // date doesn't matter with venues
                ShowTime = true;
            }

            if (diff_date == "") {
                // if it doesn't have a start date then we'll show anyway
                ShowTime = true;
            } else {
                // check what time filters apply
                $("#CheckboxTbl2").find(':checkbox').each(function() {
                    if (this.checked == true) {
                        var TimeLabel = $(this).val();
                        if (TimeLabel == "Today") {
                            if (diff_date >= 0 && diff_date <= 0) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "7") {
                            if (diff_date >= 0 && diff_date <= 7) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "14") {
                            if (diff_date >= 7 && diff_date <= 14) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "28") {
                            if (diff_date >= 14 && diff_date <= 28) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "TimeMoreThan28") {
                            if (diff_date >= 28) {
                                ShowTime = true;
                            }
                        }

                        if (TimeLabel == "Today") {
                            if (diff_date2 >= 0 && diff_date2 <= 0) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "7") {
                            if (diff_date2 >= 0 && diff_date2 <= 7) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "14") {
                            if (diff_date2 >= 7 && diff_date2 <= 14) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "28") {
                            if (diff_date2 >= 14 && diff_date2 <= 28) {
                                ShowTime = true;
                            }
                        } else if (TimeLabel == "TimeMoreThan28") {
                            if (diff_date2 >= 28) {
                                ShowTime = true;
                            }
                        }

                    }

                });
            }
            // check if any of the ticked cats match
            for (p = 0; p < CatArrayLength; p++) {
                if (cat0 == CatArray[p] || cat1 == CatArray[p] || cat2 == CatArray[p] || cat3 == CatArray[p] || cat4 == CatArray[p] || cat5 == CatArray[p] || cat6 == CatArray[p] || cat7 == CatArray[p] || cat8 == CatArray[p] || cat9 == CatArray[p]) {
                    ShowCat = true;
                }
            }

            var ShowStation = true;

            // check the results are filtered by station too if something other than 'all stations' is selected.
            var stationValue = $("#mySelect").val();

            if (stationValue == "") {
                // if it doesn't have a specific staiton selected then we'll show anyway
                ShowStation = true;
            } else {
                // check what station filter to apply
                if (stationValue != NearestStation) {
                    ShowStation = false;
                }
            }

            if (ShowCat == true && ShowTime == true && ShowStation == true) {
                // show event/venue
                ResultCount = true;

                var point = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));

                var icon = "/images/mapping/markers/" + t + ".png";

                var marker = new google.maps.Marker({
                    position: point,
                    icon: icon,
                    map: MYMAP.map
                });

                var infoWindow = new google.maps.InfoWindow();

                var LimitedDesc = desc.substring(0, 150);

                if (ListingType == "venue") {

                    var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                }
                else {
                    var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                }

                google.maps.event.addListener(marker, 'click', function() {

                    if (activeWindow != null) activeWindow.close();
                    infoWindow.setContent(html);
                    infoWindow.open(MYMAP.map, marker);
                    activeWindow = infoWindow;
                });

                var htmlMinor = "<div style='width:260px; height: 55px; overflow:hidden;'><p><strong><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='95%'/></p></div>";
                google.maps.event.addListener(marker, 'mouseover', function() {

                    if (activeWindow != null) activeWindow.close();
                    infoWindow.setContent(htmlMinor);
                    infoWindow.open(MYMAP.map, marker);
                    activeWindow = infoWindow;
                });

                var uniqueCat = cat0.substring(0, 3);

                marker.category = cat0;
                marker.date = diff_date;
                markers.push(marker);

                $("#EventList").append("<p style='margin-bottom:10px;' class=" + uniqueCat + " title=" + diff_date + "><strong><span style='font-size:1.1em;'>" + t + ".&nbsp;&nbsp;<img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">" + name + "</a></span></strong>" + "<br />" + desc + " <br /> <a href='#' title=" + uniqueCat + t + ">View on Map</a>&nbsp;&nbsp;&nbsp;<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a></p>");

                $("a[title='" + uniqueCat + t + "']").click(function() {

                    var myLatLng = new google.maps.LatLng(lat, lng);
                    MYMAP.map.panTo(myLatLng);
                    MYMAP.map.setZoom(15);

                    if (activeWindow != null) activeWindow.close();
                    if (ListingType == "venue") {

                        var infoWindow = new google.maps.InfoWindow(
                {
                    content: "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>",
                    position: myLatLng
                });
                    }
                    else {
                        var infoWindow = new google.maps.InfoWindow(
                {
                    content: "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>",
                    position: myLatLng
                });
                    }
                    infoWindow.open(MYMAP.map);

                    activeWindow = infoWindow;
                });

                t++;
            }

            // check querystrng for id. loop through xml (doing here) and check against it. if matches panTo location of event/venuw
            var PanToId = GetParameterInQueryString("itemId");

            if (PanToId != "") {
                if (link == PanToId) {
                    var myLatLng = new google.maps.LatLng(lat, lng);
                    MYMAP.map.panTo(myLatLng);
                    MYMAP.map.setZoom(15);

                    //Open up infowindow
                    if (ListingType == "venue") {

                        var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                    }
                    else {
                        var html = "<strong><p style='width:250px;'><span style='color:#113B92;'>" + name + "</span></strong><hr color='#00bbb4' width='92%'/>" + LimitedDesc + "...<br />" +
                       "<a href='/ThingsToDoDetails.aspx?id=" + link + "' class=" + uniqueCat + ">View Item Page</a><br/><br/><strong>Period: </strong>"
                       + DateFromNew + " - " + DateToNew + "<br /><strong>Web: </strong><a href='http://" + web + "' target='_blank'>" + web
                       + "</a><br /><strong>Address: </strong>" + Address + "<br /><strong>Nearest Station:</strong> <img src='/images/mapping/dlr_small.png' style='width:16px; height:13px;'/>&nbsp;&nbsp;<a href='http://www.tfl.gov.uk/gettingaround/transportaccessibility/dlr/" + StationLink + ".aspx' target='_blank'>" + NearestStation + "</a></p>";
                    }
                    if (activeWindow != null) activeWindow.close();
                    infoWindow.setContent(html);
                    infoWindow.open(MYMAP.map, marker);
                    activeWindow = infoWindow;
                }
            }

        });
        if (ResultCount == false) {
            $("#NoResults").css("display", "block");
        }
    });
}


//Station markers
MYMAP.placeMarkersStations = function(filename) {
    var activeWindow;
    $.get(filename, function(xml) {
        $(xml).find("marker").each(function() {

            var name = $(this).find('name').text();
            var address = $(this).find('name').text();
            var lat = $(this).find('lat').text();
            var lng = $(this).find('lng').text();
            var point = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));

            var icon = "/images/mapping/DLR-logo.png";

            var marker = new google.maps.Marker({
                position: point,
                icon: icon,
                map: MYMAP.map
            });

            var infoWindow = new google.maps.InfoWindow();

            var html = '<strong>' + name + '</strong>';

            google.maps.event.addListener(marker, 'click', function() {

                if (activeWindow != null) activeWindow.close();
                infoWindow.setContent(html);
                infoWindow.open(MYMAP.map, marker);
                activeWindow = infoWindow;
            });
            // polyline co-ords
            var stationPathCoordinates1 = [
            new google.maps.LatLng(51.465798777094726, -0.013968944549560547),
new google.maps.LatLng(51.466520629166574, -0.014215707778930664),
new google.maps.LatLng(51.467362775484325, -0.014698505401611328),
new google.maps.LatLng(51.468231640314975, -0.015546083450317382),
new google.maps.LatLng(51.46862596581806, -0.016222000122070312),
new google.maps.LatLng(51.469187372518846, -0.01680135726928711),
new google.maps.LatLng(51.47016313439468, -0.01920461654663086),
new google.maps.LatLng(51.47272942217195, -0.022079944610595703),
new google.maps.LatLng(51.4742798177502, -0.02264857292175293),
new google.maps.LatLng(51.47522874077249, -0.0229489803314209),
new google.maps.LatLng(51.475836843035125, -0.022895336151123047),
new google.maps.LatLng(51.476104138168125, -0.022766590118408203),
new google.maps.LatLng(51.476638723735206, -0.020738840103149414),
new google.maps.LatLng(51.47657190088194, -0.021017789840698242),
new google.maps.LatLng(51.4766520882941, -0.020706653594970703),
new google.maps.LatLng(51.4768391917076, -0.020138025283813476),
new google.maps.LatLng(51.47702629435359, -0.019826889038085937),
new google.maps.LatLng(51.47708643432681, -0.01927971839904785),
new google.maps.LatLng(51.47740049734311, -0.019043684005737304),
new google.maps.LatLng(51.47762100838151, -0.018389225006103515),
new google.maps.LatLng(51.47775465091624, -0.017766952514648437),
new google.maps.LatLng(51.478055345187705, -0.01677989959716797),
new google.maps.LatLng(51.478162258228735, -0.015041828155517578),
new google.maps.LatLng(51.478168940285485, -0.014591217041015625),
new google.maps.LatLng(51.47824912489003, -0.01340031623840332),
new google.maps.LatLng(51.47825580693405, -0.013357400894165039),
new google.maps.LatLng(51.47839612963228, -0.012735128402709961),
new google.maps.LatLng(51.47917791961945, -0.01132965087890625),
new google.maps.LatLng(51.4798060146875, -0.00997781753540039),
new google.maps.LatLng(51.480206921910444, -0.009548664093017578),
new google.maps.LatLng(51.480768186102075, -0.009677410125732422),
new google.maps.LatLng(51.48147643820055, -0.010149478912353515),
new google.maps.LatLng(51.48233167135747, -0.010385513305664062),
new google.maps.LatLng(51.48325370163806, -0.010514259338378906),
new google.maps.LatLng(51.487075251564896, -0.009870529174804687),
new google.maps.LatLng(51.487295715827535, -0.010192394256591797),
new google.maps.LatLng(51.48734916154885, -0.010213851928710937),
new google.maps.LatLng(51.487743321808885, -0.010610818862915039),
new google.maps.LatLng(51.488063992049106, -0.01099705696105957),
new google.maps.LatLng(51.4885182710288, -0.011780261993408203),
new google.maps.LatLng(51.488732047806025, -0.012145042419433593),
new google.maps.LatLng(51.48941345459398, -0.013443231582641601),
new google.maps.LatLng(51.489420135002284, -0.013421773910522461),
new google.maps.LatLng(51.48971407199821, -0.013968944549560547),
new google.maps.LatLng(51.490315300860196, -0.014687776565551757),
new google.maps.LatLng(51.490629272781184, -0.015052556991577148),
new google.maps.LatLng(51.49088312083862, -0.015245676040649414),
new google.maps.LatLng(51.491126947247174, -0.015326142311096191),
new google.maps.LatLng(51.49146429396352, -0.015208125114440918),
new google.maps.LatLng(51.49212227988087, -0.0149613618850708),
new google.maps.LatLng(51.49272681694645, -0.014757513999938964),
new google.maps.LatLng(51.49342152367458, -0.014660954475402832),
new google.maps.LatLng(51.49419637638168, -0.014591217041015625),
new google.maps.LatLng(51.49510814739756, -0.014526844024658203),
new google.maps.LatLng(51.49577943967558, -0.014467835426330566),
new google.maps.LatLng(51.49623698148315, -0.014446377754211425),
new google.maps.LatLng(51.49671455671919, -0.014392733573913574),
new google.maps.LatLng(51.49701178633288, -0.014296174049377441),
new google.maps.LatLng(51.497592881326994, -0.014081597328186035),
new google.maps.LatLng(51.4976496545786, -0.01407623291015625),
new google.maps.LatLng(51.49836432357991, -0.013942122459411621),
new google.maps.LatLng(51.49915578972371, -0.013824105262756347),
new google.maps.LatLng(51.49932276394775, -0.013813376426696777),
new google.maps.LatLng(51.49950309542264, -0.013850927352905273),
new google.maps.LatLng(51.499633334377385, -0.013968944549560547),
new google.maps.LatLng(51.499740196831546, -0.014162063598632812),
new google.maps.LatLng(51.499817004065704, -0.0144195556640625),
new google.maps.LatLng(51.499877113984745, -0.01478433609008789),
new google.maps.LatLng(51.499970618145674, -0.015562176704406738),
new google.maps.LatLng(51.50008081923195, -0.01665651798248291),
new google.maps.LatLng(51.50003406728848, -0.016361474990844726),
new google.maps.LatLng(51.50014092880303, -0.017251968383789062),
new google.maps.LatLng(51.50019102005171, -0.017616748809814453),
new google.maps.LatLng(51.500251129477455, -0.01782059669494629),
new google.maps.LatLng(51.500307899417884, -0.017922520637512207),
new google.maps.LatLng(51.500374687492545, -0.018045902252197265),
new google.maps.LatLng(51.500478208814826, -0.018276572227478027),
new google.maps.LatLng(51.50052162091226, -0.018501877784729004),
new google.maps.LatLng(51.50057171174254, -0.018968582153320312),
new google.maps.LatLng(51.50058506928798, -0.019022226333618164),
new google.maps.LatLng(51.5006151237509, -0.01939237117767334),
new google.maps.LatLng(51.50073534140441, -0.019982457160949707),
new google.maps.LatLng(51.50085555874079, -0.020674467086791992),
new google.maps.LatLng(51.501015848029354, -0.021414756774902344),
new google.maps.LatLng(51.5011427433163, -0.02175271511077881),
new google.maps.LatLng(51.50131304959348, -0.021865367889404297),
new google.maps.LatLng(51.50156349884494, -0.021886825561523437),
new google.maps.LatLng(51.501803928831464, -0.021790266036987304),
new google.maps.LatLng(51.50291256180409, -0.021446943283081054),
new google.maps.LatLng(51.503453511475826, -0.02123236656188965),
new google.maps.LatLng(51.504675633388246, -0.02089977264404297),
new google.maps.LatLng(51.50536347993968, -0.020695924758911133),
new google.maps.LatLng(51.50611809576545, -0.020492076873779297),
new google.maps.LatLng(51.507012933733826, -0.02023458480834961),
new google.maps.LatLng(51.507266690556285, -0.020180940628051758),
new google.maps.LatLng(51.50733012954107, -0.020159482955932617)
            ];

            var stationPathCoordinates2 = [
            new google.maps.LatLng(51.51322956905176, -0.0885772705078125),
new google.maps.LatLng(51.51168049760791, -0.0872039794921875),
new google.maps.LatLng(51.51140005662905, -0.0869894027709961),
new google.maps.LatLng(51.51115967727314, -0.08643150329589844),
new google.maps.LatLng(51.51083916949225, -0.08505821228027344),
new google.maps.LatLng(51.5107991058611, -0.08392095565795898),
new google.maps.LatLng(51.51066556016945, -0.08301973342895508),
new google.maps.LatLng(51.510371758269876, -0.08216142654418945),
new google.maps.LatLng(51.509904342251964, -0.08061647415161133),
new google.maps.LatLng(51.509824213310225, -0.0795435905456543),
new google.maps.LatLng(51.50973072936676, -0.07855653762817383),
new google.maps.LatLng(51.50959718054336, -0.07731199264526367),
new google.maps.LatLng(51.50959718054336, -0.07636785507202148),
new google.maps.LatLng(51.509503696134004, -0.07501602172851562),
new google.maps.LatLng(51.50965060011969, -0.07424354553222656),
new google.maps.LatLng(51.51019814716589, -0.07377147674560547),
new google.maps.LatLng(51.510759042194714, -0.07334232330322265),
new google.maps.LatLng(51.510759042194714, -0.07248401641845703),
new google.maps.LatLng(51.5107723967541, -0.07216215133666992),
new google.maps.LatLng(51.51099942366457, -0.0705099105834961),
new google.maps.LatLng(51.511173031715074, -0.06937265396118164),
new google.maps.LatLng(51.51122644944369, -0.06810665130615234),
new google.maps.LatLng(51.511426765368085, -0.06426572799682617),
new google.maps.LatLng(51.51149353714717, -0.06302118301391601),
new google.maps.LatLng(51.511533600167624, -0.0623774528503418),
new google.maps.LatLng(51.511520245831385, -0.0612187385559082),
new google.maps.LatLng(51.511613726102865, -0.059523582458496094),
new google.maps.LatLng(51.511760623284765, -0.05666971206665039),
new google.maps.LatLng(51.51178733181241, -0.05621910095214844),
new google.maps.LatLng(51.51181404032437, -0.05536079406738281),
new google.maps.LatLng(51.51188081153583, -0.05379438400268555),
new google.maps.LatLng(51.5119342284345, -0.05175590515136719),
new google.maps.LatLng(51.51210783292268, -0.0487518310546875),
new google.maps.LatLng(51.51216124955517, -0.046155452728271484),
new google.maps.LatLng(51.51232149907683, -0.0417780876159668),
new google.maps.LatLng(51.51237491545877, -0.040640830993652344),
new google.maps.LatLng(51.51241497770414, -0.03937482833862305),
new google.maps.LatLng(51.51221466612502, -0.03673553466796875),
new google.maps.LatLng(51.51192087421569, -0.03469705581665039),
new google.maps.LatLng(51.511760623284765, -0.03371000289916992),
new google.maps.LatLng(51.511266512699024, -0.03182172775268555),
new google.maps.LatLng(51.51107955053933, -0.031156539916992187),
new google.maps.LatLng(51.51074568763141, -0.03025531768798828),
new google.maps.LatLng(51.510371758269876, -0.02913951873779297),
new google.maps.LatLng(51.509383501611595, -0.02647876739501953),
new google.maps.LatLng(51.508795879381864, -0.02471923828125),
new google.maps.LatLng(51.508555486285246, -0.023925304412841797),
new google.maps.LatLng(51.50786101021461, -0.020728111267089844),
new google.maps.LatLng(51.50842527282832, -0.023276209831237793),
new google.maps.LatLng(51.508234960183394, -0.022401809692382812),
new google.maps.LatLng(51.50798788644087, -0.02127528190612793),
new google.maps.LatLng(51.50773747249688, -0.020481348037719726),
new google.maps.LatLng(51.50761727331493, -0.020341873168945312),
new google.maps.LatLng(51.50733012954107, -0.020159482955932617),
new google.maps.LatLng(51.507590562342536, -0.01990199089050293),
new google.maps.LatLng(51.507844315947985, -0.018791556358337402),
new google.maps.LatLng(51.507854332508685, -0.01855015754699707),
new google.maps.LatLng(51.50782094396449, -0.01833021640777588),
new google.maps.LatLng(51.50771743932191, -0.017262697219848633),
new google.maps.LatLng(51.50763062879525, -0.016232728958129883),
new google.maps.LatLng(51.50752044596548, -0.014650225639343261),
new google.maps.LatLng(51.50754381810317, -0.013266205787658691),
new google.maps.LatLng(51.507563851354476, -0.012643933296203613),
new google.maps.LatLng(51.507620612185356, -0.012155771255493164),
new google.maps.LatLng(51.50776752224283, -0.011951923370361328),
new google.maps.LatLng(51.50802127486276, -0.011866092681884765),
new google.maps.LatLng(51.50826834842422, -0.011941194534301757),
new google.maps.LatLng(51.508795879381864, -0.01233816146850586),
new google.maps.LatLng(51.509042948742746, -0.012445449829101562),
new google.maps.LatLng(51.50998447105276, -0.012778043746948242),
new google.maps.LatLng(51.510545368712286, -0.012960433959960937),
new google.maps.LatLng(51.511146322827294, -0.012949705123901367),
new google.maps.LatLng(51.511667143314725, -0.01306772232055664),
new google.maps.LatLng(51.51321621521269, -0.013518333435058593),
new google.maps.LatLng(51.51507236129972, -0.01408696174621582),
new google.maps.LatLng(51.51678822763339, -0.014591217041015625),
new google.maps.LatLng(51.51845062013481, -0.015192031860351562),
new google.maps.LatLng(51.51917163898046, -0.01544952392578125),
new google.maps.LatLng(51.522095653950174, -0.017251968383789062),
new google.maps.LatLng(51.52353756481546, -0.018110275268554687),
new google.maps.LatLng(51.52655474907848, -0.020041465759277344),
new google.maps.LatLng(51.52800986825475, -0.021092891693115234),
new google.maps.LatLng(51.52969187467457, -0.02235889434814453),
new google.maps.LatLng(51.530145738776376, -0.02192974090576172),
new google.maps.LatLng(51.530426064343594, -0.021564960479736328),
new google.maps.LatLng(51.53098671029967, -0.020685195922851562),
new google.maps.LatLng(51.53125368213775, -0.020105838775634765),
new google.maps.LatLng(51.531747575910835, -0.019140243530273437),
new google.maps.LatLng(51.53217472296104, -0.01819610595703125),
new google.maps.LatLng(51.5328688283694, -0.016930103302001953),
new google.maps.LatLng(51.53345614006395, -0.015642642974853515),
new google.maps.LatLng(51.53445722207716, -0.013647079467773437),
new google.maps.LatLng(51.535484976706265, -0.011715888977050781),
new google.maps.LatLng(51.536272461303824, -0.010256767272949218),
new google.maps.LatLng(51.53716670695341, -0.009162425994873047),
new google.maps.LatLng(51.53867487249872, -0.0075531005859375),
new google.maps.LatLng(51.5397092049327, -0.006544589996337891),
new google.maps.LatLng(51.54062340177117, -0.005697011947631836),
new google.maps.LatLng(51.541904581035986, -0.003991127014160156)
            ];

            var stationPathCoordinates3 = [
            new google.maps.LatLng(51.50756051247987, -0.012670755386352539),
new google.maps.LatLng(51.50760057895899, -0.010889768600463867),
new google.maps.LatLng(51.50768071181159, -0.009012222290039062),
new google.maps.LatLng(51.50787436562348, -0.007231235504150391),
new google.maps.LatLng(51.5081214399816, -0.005697011947631836),
new google.maps.LatLng(51.508582196691954, -0.00446319580078125),
new google.maps.LatLng(51.50898952845392, -0.003873109817504883),
new google.maps.LatLng(51.50920320923343, -0.0029397010803222656),
new google.maps.LatLng(51.50932340423147, -0.0021457672119140625),
new google.maps.LatLng(51.50989098743811, 0.00048279762268066406),
new google.maps.LatLng(51.510171437706525, 0.0016522407531738281),
new google.maps.LatLng(51.51041182227684, 0.0023603439331054687),
new google.maps.LatLng(51.511667143314725, 0.0034117698669433593),
new google.maps.LatLng(51.51365688983539, 0.004398822784423828),
new google.maps.LatLng(51.51441804505181, 0.0052356719970703125),
new google.maps.LatLng(51.51477858782044, 0.006394386291503906),
new google.maps.LatLng(51.514845354686656, 0.007359981536865234),
new google.maps.LatLng(51.51436463106562, 0.00790715217590332),
new google.maps.LatLng(51.514057499429434, 0.00823974609375),
new google.maps.LatLng(51.51330969200403, 0.008883476257324218),
new google.maps.LatLng(51.51256187230236, 0.009452104568481445),
new google.maps.LatLng(51.51180736319784, 0.009870529174804687),
new google.maps.LatLng(51.51127986710966, 0.009913444519042968),
new google.maps.LatLng(51.510865878560125, 0.009988546371459961),
new google.maps.LatLng(51.510471918221235, 0.010246038436889648),
new google.maps.LatLng(51.510051244945764, 0.010879039764404297),
new google.maps.LatLng(51.50993105186788, 0.011115074157714843),
new google.maps.LatLng(51.50943692143851, 0.012434720993041992),
new google.maps.LatLng(51.50923659676469, 0.013164281845092773),
new google.maps.LatLng(51.50902959367641, 0.014612674713134765),
new google.maps.LatLng(51.50900956106959, 0.01478433609008789),
new google.maps.LatLng(51.50898952845392, 0.015481710433959961),
new google.maps.LatLng(51.509103046492804, 0.0167691707611084),
new google.maps.LatLng(51.50926330677209, 0.01779913902282715),
new google.maps.LatLng(51.50946363132844, 0.019633769989013672),
new google.maps.LatLng(51.509523728523604, 0.021425485610961914),
new google.maps.LatLng(51.509530405984826, 0.0226593017578125),
new google.maps.LatLng(51.50957047073169, 0.02505183219909668),
new google.maps.LatLng(51.50960385799382, 0.027015209197998047),
new google.maps.LatLng(51.50961721289182, 0.02886056900024414),
new google.maps.LatLng(51.50962389033935, 0.030469894409179687),
new google.maps.LatLng(51.509523728523604, 0.03232598304748535),
new google.maps.LatLng(51.50947030879849, 0.03327012062072754),
new google.maps.LatLng(51.50947030879849, 0.03367781639099121),
new google.maps.LatLng(51.509103046492804, 0.03604888916015625),
new google.maps.LatLng(51.50877584667225, 0.03735780715942383),
new google.maps.LatLng(51.508555486285246, 0.037915706634521484),
new google.maps.LatLng(51.508475354971175, 0.03986835479736328),
new google.maps.LatLng(51.50838186825999, 0.04602670669555664),
new google.maps.LatLng(51.50848871019998, 0.047528743743896484),
new google.maps.LatLng(51.50868903816219, 0.04877328872680664),
new google.maps.LatLng(51.50911640153762, 0.05010366439819336),
new google.maps.LatLng(51.509103046492804, 0.051627159118652344),
new google.maps.LatLng(51.50911640153762, 0.05497455596923828),
new google.maps.LatLng(51.508822589647636, 0.06398677825927734),
new google.maps.LatLng(51.50876249152762, 0.06429791450500488),
new google.maps.LatLng(51.50863561745838, 0.0650489330291748),
new google.maps.LatLng(51.508595551889435, 0.0667119026184082),
new google.maps.LatLng(51.50851542064582, 0.06765604019165039),
new google.maps.LatLng(51.50800791949694, 0.06823539733886719),
new google.maps.LatLng(51.507607256702116, 0.06890058517456054),
new google.maps.LatLng(51.507273368348315, 0.07016658782958984),
new google.maps.LatLng(51.50743363506349, 0.0711965560913086),
new google.maps.LatLng(51.50788772102843, 0.07164716720581054),
new google.maps.LatLng(51.509103046492804, 0.07173299789428711),
new google.maps.LatLng(51.51312273822952, 0.07145404815673828),
new google.maps.LatLng(51.51356341375649, 0.07111072540283203),
new google.maps.LatLng(51.514044145833076, 0.0701451301574707),
new google.maps.LatLng(51.51400408502046, 0.06902933120727539),
new google.maps.LatLng(51.514377984568036, 0.06145477294921875)
            ];

            var stationPathCoordinates4 = [
            new google.maps.LatLng(51.50993105186788, 0.011115074157714843),
new google.maps.LatLng(51.50936346916036, 0.011286735534667968),
new google.maps.LatLng(51.509156466648534, 0.01134037971496582),
new google.maps.LatLng(51.50841191758092, 0.011565685272216797),
new google.maps.LatLng(51.50801459718035, 0.011678338050842285),
new google.maps.LatLng(51.50748037941589, 0.01234889030456543),
new google.maps.LatLng(51.50696952782, 0.012971162796020507),
new google.maps.LatLng(51.506405247177604, 0.01390993595123291),
new google.maps.LatLng(51.50597785837158, 0.014601945877075195),
new google.maps.LatLng(51.50529669917622, 0.015717744827270508),
new google.maps.LatLng(51.50488265625811, 0.016543865203857422),
new google.maps.LatLng(51.50443521855256, 0.017445087432861328),
new google.maps.LatLng(51.503703948964045, 0.018990039825439453),
new google.maps.LatLng(51.503430137240024, 0.01960158348083496),
new google.maps.LatLng(51.50320307261127, 0.020095109939575195),
new google.maps.LatLng(51.502845777448655, 0.021500587463378906),
new google.maps.LatLng(51.50273892227642, 0.021854639053344726),
new google.maps.LatLng(51.50246176550566, 0.02315819263458252),
new google.maps.LatLng(51.50239831974273, 0.023571252822875976),
new google.maps.LatLng(51.50219128558609, 0.024923086166381836),
new google.maps.LatLng(51.50204769682834, 0.025818943977355957),
new google.maps.LatLng(51.50203767899114, 0.02691328525543213),
new google.maps.LatLng(51.502014304029124, 0.028501152992248535),
new google.maps.LatLng(51.50206105394115, 0.030137300491333008),
new google.maps.LatLng(51.502104464530824, 0.03124237060546875),
new google.maps.LatLng(51.50221132119075, 0.032942891120910645),
new google.maps.LatLng(51.50227810647596, 0.03438591957092285),
new google.maps.LatLng(51.50235490943297, 0.03611862659454346),
new google.maps.LatLng(51.502401658995616, 0.03775477409362793),
new google.maps.LatLng(51.50244173001112, 0.03871500492095947),
new google.maps.LatLng(51.50296932842923, 0.03974497318267822),
new google.maps.LatLng(51.503703948964045, 0.0402599573135376),
new google.maps.LatLng(51.50385754994252, 0.040351152420043945),
new google.maps.LatLng(51.504107985210226, 0.040726661682128906),
new google.maps.LatLng(51.504191463326954, 0.04183173179626465),
new google.maps.LatLng(51.50423153276867, 0.04229843616485596),
new google.maps.LatLng(51.504261584826814, 0.04402041435241699),
new google.maps.LatLng(51.50417810683855, 0.0455707311630249),
new google.maps.LatLng(51.50408795043946, 0.04716932773590088),
new google.maps.LatLng(51.50400447213312, 0.048767924308776855),
new google.maps.LatLng(51.503744018834425, 0.04922926425933838),
new google.maps.LatLng(51.503082861467384, 0.04982471466064453),
new google.maps.LatLng(51.502845777448655, 0.05003929138183594),
new google.maps.LatLng(51.50259533524416, 0.05046844482421875),
new google.maps.LatLng(51.50257529980835, 0.05194365978240967),
new google.maps.LatLng(51.50248847948469, 0.05340278148651123),
new google.maps.LatLng(51.50239164123622, 0.0550389289855957),
new google.maps.LatLng(51.50231817760012, 0.05661606788635254),
new google.maps.LatLng(51.50227810647596, 0.05808055400848389),
new google.maps.LatLng(51.502228017521226, 0.0598454475402832),
new google.maps.LatLng(51.50218794631781, 0.06151378154754639),
new google.maps.LatLng(51.502171249972626, 0.06242573261260986),
new google.maps.LatLng(51.501690392607, 0.06767749786376953),
new google.maps.LatLng(51.50112938593432, 0.0716257095336914),
new google.maps.LatLng(51.500060782690625, 0.0732564926147461),
new google.maps.LatLng(51.49768305057591, 0.075531005859375),
new google.maps.LatLng(51.4958128370432, 0.07703304290771484),
new google.maps.LatLng(51.494690672089675, 0.07720470428466797),
new google.maps.LatLng(51.493541760302776, 0.07656097412109375),
new google.maps.LatLng(51.49209889983332, 0.07445812225341797),
new google.maps.LatLng(51.4898944414893, 0.06990909576416015)
            ];

            var stationPathCoordinates5 = [
                    new google.maps.LatLng(51.514893, 0.007369),
                    new google.maps.LatLng(51.515812, 0.006554),
                    new google.maps.LatLng(51.516602, 0.005888),
                    new google.maps.LatLng(51.517609, 0.005266),
                    new google.maps.LatLng(51.518364, 0.004826),
                    new google.maps.LatLng(51.519520, 0.004440),
                    new google.maps.LatLng(51.520500, 0.004140),
                    new google.maps.LatLng(51.521568, 0.004054),
                    new google.maps.LatLng(51.522228, 0.004129),
                    new google.maps.LatLng(51.523205, 0.004268),
                    new google.maps.LatLng(51.524124, 0.004365),
                    new google.maps.LatLng(51.524944, 0.004418),
                    new google.maps.LatLng(51.525913, 0.004461),
                    new google.maps.LatLng(51.527210, 0.004429),
                    new google.maps.LatLng(51.528252, 0.004333),
                    new google.maps.LatLng(51.529278, 0.004300),
                    new google.maps.LatLng(51.530247, 0.004279),
                    new google.maps.LatLng(51.531208, 0.004376),
                    new google.maps.LatLng(51.531769, 0.004193),
                    new google.maps.LatLng(51.533142, 0.003024),
                    new google.maps.LatLng(51.534878, 0.001951),
                    new google.maps.LatLng(51.536686, 0.000674),
                    new google.maps.LatLng(51.537605, -0.000173),
                    new google.maps.LatLng(51.538509, -0.001257),
                    new google.maps.LatLng(51.539974, -0.002062),
                    new google.maps.LatLng(51.540863, -0.002686),
                    new google.maps.LatLng(51.541435, -0.003287),
                    new google.maps.LatLng(51.542187, -0.004531),
                    new google.maps.LatLng(51.542454, -0.005668),
                    new google.maps.LatLng(51.542454, -0.006548),
                    new google.maps.LatLng(51.542332, -0.007535),
                    new google.maps.LatLng(51.541985, -0.008672),
                    new google.maps.LatLng(51.541653, -0.009702),
                    new google.maps.LatLng(51.541653, -0.010775),
                    new google.maps.LatLng(51.541851, -0.011977),
                    new google.maps.LatLng(51.542332, -0.012878),
                    new google.maps.LatLng(51.542946, -0.013307),
                    new google.maps.LatLng(51.543705, -0.013415),
                    new google.maps.LatLng(51.544281, -0.013136),
                    new google.maps.LatLng(51.544815, -0.012556),
                    new google.maps.LatLng(51.544762, -0.008565),
                    new google.maps.LatLng(51.544746, -0.008501),
                    new google.maps.LatLng(51.544762, -0.008544)
            ];


            var stationPath1 = new google.maps.Polyline({
                path: stationPathCoordinates1,
                strokeColor: "#20B5B3",
                strokeOpacity: 1,
                strokeWeight: 3
            });

            var stationPath2 = new google.maps.Polyline({
                path: stationPathCoordinates2,
                strokeColor: "#20B5B3",
                strokeOpacity: 1,
                strokeWeight: 3
            });
            var stationPath3 = new google.maps.Polyline({
                path: stationPathCoordinates3,
                strokeColor: "#20B5B3",
                strokeOpacity: 1,
                strokeWeight: 3
            });
            var stationPath4 = new google.maps.Polyline({
                path: stationPathCoordinates4,
                strokeColor: "#20B5B3",
                strokeOpacity: 1,
                strokeWeight: 3
            });
            var stationPath5 = new google.maps.Polyline({
                path: stationPathCoordinates5,
                strokeColor: "#20B5B3",
                strokeOpacity: 1,
                strokeWeight: 3
            });

            stationPath1.setMap(MYMAP.map);
            stationPath2.setMap(MYMAP.map);
            stationPath3.setMap(MYMAP.map);
            stationPath4.setMap(MYMAP.map);
            stationPath5.setMap(MYMAP.map);

        });
    });
}

function GetParameterInQueryString(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function SetMapToSelectedStation() {
    var activeWindow;
    var SelValue = $("#mySelect").val();
    var filename = "/xml/stations/markersStations.xml";
    $.get(filename, function(xml) {
        $(xml).find("marker").each(function() {
            var name = $(this).find('name').text();

            if (name == SelValue) {
                var name = $(this).find('name').text();
                var address = $(this).find('name').text();

                var lat = $(this).find('lat').text();
                var lng = $(this).find('lng').text();

                var myLatLng = new google.maps.LatLng(lat, lng);
                MYMAP.map.panTo(myLatLng);
                MYMAP.map.setZoom(15);

                if (activeWindow != null) activeWindow.close();

                var infowindow = new google.maps.InfoWindow(
                {
                 content: '<strong>' + name + '</strong>',
                 position: myLatLng
                });
                infowindow.open(MYMAP.map);

                activeWindow = infowindow;
            }

        });
    });
}

function SetMapToPosition(lat, lon) {
    var myLatLng = new google.maps.LatLng(lat, lon);
    MYMAP.map.panTo(myLatLng);
    MYMAP.map.setZoom(15);
}
