Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <script>
  2.         var membersTable;
  3.         var geocoder;
  4.         var map;
  5.         var i = 0;
  6.         var delay = 0;
  7.         var agencyCount = 0;
  8.         var iconURL;
  9.         var localURL = 'http://hosting.frontpageltd.co.uk';
  10.  
  11.         function initialize() {
  12.             geocoder = new google.maps.Geocoder();
  13.             var mapOptions = {
  14.                 center: { lat: 55.362, lng: -3.443 },
  15.                 zoom: 6
  16.             };
  17.             map = new google.maps.Map(document.getElementById('map-canvas'),
  18.                 mapOptions);
  19.         }
  20.         function codeAddress(address) {
  21.  
  22.             geocoder.geocode({ 'address': address }, function (results, status) {
  23.                 if (status == google.maps.GeocoderStatus.OK) {
  24.                     return results;
  25.                 }
  26.             });
  27.         }
  28.  
  29.         function PostcodeAnywhere_Interactive_ListCounties_v1_00Begin(Key, UserName) {
  30.             var script = document.createElement("script"),
  31.                 head = document.getElementsByTagName("head")[0],
  32.                 url = "http://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/ListCounties/v1.00/json3.ws?";
  33.  
  34.             // Build the query string
  35.             url += "&Key=" + encodeURIComponent(Key);
  36.             url += "&UserName=" + encodeURIComponent(UserName);
  37.             url += "&callback=PostcodeAnywhere_Interactive_ListCounties_v1_00End";
  38.  
  39.             script.src = url;
  40.  
  41.             // Make the request
  42.             script.onload = script.onreadystatechange = function () {
  43.                 if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
  44.                     script.onload = script.onreadystatechange = null;
  45.                     if (head && script.parentNode)
  46.                         head.removeChild(script);
  47.                 }
  48.             }
  49.  
  50.             head.insertBefore(script, head.firstChild);
  51.         }
  52.  
  53.         google.maps.event.addDomListener(window, 'load', initialize);
  54.  
  55.         function AddInfoWindow(entry, entryIconURL, position) {
  56.             var contentString = '<div class="agencyMapMarker" style="font-family: sans-serif !important; font-weight: normal !important; max-width: 500px; white-space: nowrap; overflow: auto;"><table><tbody><tr><td><b>' + entry.MemberName + '</b><br>' + entry.MemberAddress1 + '<br>' + entry.MemberAddress2 + '<br>' + entry.MemberAddress3 + '<br>' + entry.MemberCity + '<br>' + entry.MemberCounty + '<br>' + entry.MemberPostcode + '<br>' + entry.MemberEmail + '<br>' + entry.MemberWebsite + '<br>' + entry.MemberTelephone + '</td><td><img src="' + entryIconURL + '" style="width: 36px; height: 50px; float: right; display: block; margin: 0 0 10px 10px;"></td></tr></tbody></table></div>';
  57.             var infowindow = new google.maps.InfoWindow({
  58.                 content: contentString,
  59.                 maxWidth: 500
  60.             });
  61.  
  62.             return infowindow;
  63.         }
  64.  
  65.         function AddAgencyMarker(entry, position, entryIconURL) {
  66.             // Initialise the icon URL
  67.  
  68.  
  69.             var marker = new google.maps.Marker({
  70.                 position: position,
  71.                 map: map,
  72.                 icon: entryIconURL,
  73.                 title: entry.MemberName
  74.             });
  75.  
  76.             return marker;
  77.         }
  78.  
  79.         function GetNearestAgencyDataForCounty(location) {
  80.             $.ajax({
  81.                 type: 'POST',
  82.                 url: '/umbraco/Surface/FindAnAgentSurface/FilterAgentsByCounty?county=' + location,
  83.                 dataType: "JSON",
  84.  
  85.                 success: function (data) {
  86.                     membersTable.clear().draw();
  87.                     membersTable.rows.add(data);
  88.                     membersTable.draw();
  89.                 }
  90.             });
  91.         }
  92.  
  93.         function GetNearestAgencyDataForTown(location) {
  94.             $.ajax({
  95.                 type: 'POST',
  96.                 url: '/umbraco/Surface/FindAnAgentSurface/FilterAgentsByTown?town=' + location,
  97.                 dataType: "JSON",
  98.  
  99.                 success: function (data) {
  100.                     membersTable.clear().draw();
  101.                     membersTable.rows.add(data);
  102.                     membersTable.draw();
  103.                 }
  104.             });
  105.         }
  106.  
  107.         function GetNearestAgencyDataForPostcode(postcode) {
  108.             $.ajax({
  109.                 type: 'POST',
  110.                 url: '/umbraco/Surface/FindAnAgentSurface/GetNearestAgencyDataForPostcode?postcode=' + postcode,
  111.                 success: function (result) {
  112.                     result = JSON.parse(result);
  113.  
  114.                     result.forEach(function (entry) {
  115.  
  116.                         var latLng = new google.maps.LatLng(entry.Latitude, entry.Longitude);
  117.  
  118.  
  119.                         iconURL = localURL + '/CLIAIcons/BeginnerMarker.png';
  120.  
  121.                         if (entry.AccreditedLevel == 'Master')
  122.                             iconURL = localURL + '/CLIAIcons/MasterMarker.png';
  123.                         else if (entry.AccreditedLevel == "Ambassador")
  124.                             iconURL = localURL + '/CLIAIcons/AmbassadorMarker.png';
  125.                         else if (entry.AccreditedLevel == "Accredited")
  126.                             iconURL = localURL + '/CLIAIcons/AccreditedMarker.png';
  127.                         var currentMarker = AddAgencyMarker(entry, latLng, iconURL);
  128.                         var currentInfoWindow = AddInfoWindow(entry, iconURL, latLng);
  129.  
  130.                         google.maps.event.addListener(currentMarker, 'click', function () {
  131.                             currentInfoWindow.open(map, currentMarker);
  132.                         });
  133.                     });
  134.                 }
  135.  
  136.             });
  137.         }
  138.  
  139.         function GetAllCountiesForDropdown() {
  140.  
  141.             var items = "";
  142.             $.ajax({
  143.                 type: "GET",
  144.                 url: "/umbraco/Surface/FindAnAgentSurface/GetAllCountiesForDropdown",
  145.                 dataType: "JSON",
  146.                 success: function (data) {
  147.                     $.each(data, function (index, item) {
  148.                         $('#selectCountyDropdown').append("<option>" + item + "</option>");
  149.                     });
  150.                 }
  151.             });
  152.         }
  153.  
  154.         function GetAllTownsForDropdown() {
  155.             var items = "";
  156.             $.ajax({
  157.                 type: "GET",
  158.                 url: '/umbraco/Surface/FindAnAgentSurface/GetAllTownsForDropdown',
  159.                 dataType: "JSON",
  160.                 success: function (data) {
  161.                     $.each(data, function (index, item) {
  162.                         $('#selectTownDropdown').append("<option>" + item + "</option>");
  163.                     });
  164.                 }
  165.             })
  166.         }
  167.  
  168.         $(document).ready(function () {
  169.             //Fancybox set up
  170.             $('#KeyMaster').fancybox({
  171.                 'transitionIn': 'fade',
  172.                 'transitionOut': 'fade',
  173.                 'width': 'auto',
  174.                 'overlayShow': true
  175.             });
  176.             $('#KeyAmbassador').fancybox({
  177.                 'transitionIn': 'fade',
  178.                 'transitionOut': 'fade',
  179.                 'width': 'auto',
  180.                 'overlayShow': true
  181.             });
  182.             $('#KeyAccredited').fancybox({
  183.                 'transitionIn': 'fade',
  184.                 'transitionOut': 'fade',
  185.                 'width': 'auto',
  186.                 'overlayShow': true
  187.             });
  188.             $('#KeyBeginner').fancybox({
  189.                 'transitionIn': 'fade',
  190.                 'transitionOut': 'fade',
  191.                 'width': 'auto',           
  192.                 'overlayShow': true
  193.             });
  194.             // Find an agent map functions
  195.              membersTable = $('#membersList').DataTable({
  196.    
  197.                       data: null,    
  198.                             columns: [
  199.                     { data: 'MemberName' },
  200.                     { data: 'AccreditedLevel' },
  201.                     { data: 'MemberCity' },
  202.                     { data: "MemberCounty" },
  203.                     { data: "MemberPostcode" },
  204.                     { data: "MemberTelephone" },
  205.                     { data: "MemberWebsite" },
  206.                     { data: "MemberEmail" }
  207.  
  208.                             ]
  209.             });
  210.             GetAllCountiesForDropdown();
  211.             GetAllTownsForDropdown();
  212.  
  213.  
  214.             $('.filterByLetter').click(function (e) {
  215.                 e.preventDefault();
  216.                 var clickedFilterLetter = $(this).attr("data-id");
  217.                 $('#membersListContainer').css("visibility", "visible");
  218.                 $.ajax({
  219.                     url: "/umbraco/Surface/FindAnAgentSurface/FilterAgentsByLetter?letter=" + clickedFilterLetter,
  220.                     type: "POST",
  221.                     dataType: "JSON",
  222.  
  223.                     success: function (data) {
  224.                         membersTable.clear().draw();
  225.                         membersTable.rows.add(data);
  226.                         membersTable.draw();
  227.                     }
  228.                 });
  229.             });
  230.  
  231.  
  232.             $('#postcode').bind("enterKey", function (e) {
  233.                 postcode = $('#postcode').val();
  234.                 $('#map-error-msg').empty();
  235.  
  236.                 if (!postcode.length > 0) {
  237.                     $('#map-error-msg').append('<span style="color: #cc0066;">* Please type a postcode into the search field.</span>');
  238.                     return false;
  239.                 }
  240.  
  241.                 if (postcode.length < 5) {
  242.                     $('#map-error-msg').append('<span style="color: #cc0066;">* It appears the postcode you entered is invalid.</span>');
  243.                     return false;
  244.                 }
  245.                 codeAddress($('#postcode').val());
  246.                 GetNearestAgencyDataForPostcode($('#postcode').val());
  247.             });
  248.             $('#postcode').keyup(function (e) {
  249.                 if (e.keyCode == 13) {
  250.                     $(this).trigger("enterKey");
  251.                 }
  252.             });
  253.  
  254.             $('#searchByCounty').click(function (e) {
  255.                 var selectedCounty = $('#selectCountyDropdown').find(":selected").text();
  256.                 GetNearestAgencyDataForCounty(selectedCounty);
  257.             });
  258.  
  259.             $('#searchByTown').click(function (e) {
  260.                 var selectedCounty = $('#selectTownDropdown').find(":selected").text();
  261.                 GetNearestAgencyDataForTown(selectedCounty);
  262.             });
  263.  
  264.             $('#submitPostcode').click(function (e) {
  265.                 postcode = $('#postcode').val();
  266.                 $('#map-error-msg').empty();
  267.  
  268.                 if (!postcode.length > 0) {
  269.                     $('#map-error-msg').append('<span style="color: #cc0066;">* Please type a postcode into the search field.</span>');
  270.                     return false;
  271.                 }
  272.  
  273.                 //if(!isValidPostcode(postcode)) {
  274.                 if (postcode.length < 5) {
  275.                     $('#map-error-msg').append('<span style="color: #cc0066;">* It appears the postcode you entered is invalid.</span>');
  276.                     return false;
  277.                 }
  278.                 codeAddress($('#postcode').val());
  279.                 GetNearestAgencyDataForPostcode($('#postcode').val());
  280.             });
  281.  
  282.             //$.ajax({
  283.             //    type: 'POST',
  284.             //    url: 'http://services.postcodeanywhere.co.uk/StoreFinder/Interactive/RetrieveNearest/v1.20/json.ws?Key=UE91-CZ45-TZ49-BN82&Origin=WR2 6NJ&MaximumItems=50&MaximumRadius=30&MaximumTime=120&DistanceType=FastestByRoad&LocationLists=',
  285.             //    success: function (result) {
  286.             //        alert(result);
  287.             //    }
  288.             //});
  289.         });
  290.     </script>
  291.        
  292.        
  293.     <script src="/scripts/jquery.tablesorter.min.js"></script>
  294.        
  295.     <script type="text/javascript">
  296.         $(document).ready(function () {
  297.             $("#AgencyList").tablesorter();
  298.             }
  299.         );
  300.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement