// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require materialize
//= require materialize-sprockets
//= require_tree .

var map;
var markers = [];

var initMap = function() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 33.999656, lng: -118.087183},
    zoom: 5
  });

  $('#date').on('submit', fetchParams)
  var infoWindow = new google.maps.InfoWindow({map: map});

  // Try HTML5 geolocation.
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
      };

      infoWindow.setPosition(pos);
      infoWindow.setContent('You are here.');
      map.setCenter(pos);
    }, function() {
      handleLocationError(true, infoWindow, map.getCenter());
    });
  } else {
    // Browser doesn't support Geolocation
    handleLocationError(false, infoWindow, map.getCenter());
  }
};


function fetchParams(e) {
  e.preventDefault();
  var date = $('#date').serialize()
  $.getJSON('/sats?'+date, null, fetchSats);
}

function fetchSats(response) {
  deleteMarkers();
  for (var i = 0; i < response.length; i++) {
    var sat = response[i];
    placeMarkers(sat.latitude, sat.longitude)
    //Append input into form with sat id
    $('.sat-locations').append('<li><input type="radio" name="sat_id" value=" class="new-event-sat-location"'+sat.id+'">'+sat.address+'</li>')

  }
}
$()
$('form').on('click','.sat-locations', function(event){
  event.preventDefault();
  var checked = $(":checked").val();
  console.log(checked);
})

function eventParams(e){
  e.preventDefault();
  var sat = $('#date').serialize()

}
function placeMarkers(lat, lng) {

    var latlng = new google.maps.LatLng(lat, lng);
    new_marker = new google.maps.Marker({
      position: latlng,
      map: map
    });
    markers.push(new_marker);
}

// Sets the map on all markers in the array.
var setMapOnAll = function(map) {
  for (var i = 0; i < markers.length; i++) {
    markers[i].setMap(map);
  }
}

// Removes the markers from the map, but keeps them in the array.
var clearMarkers = function() {
  setMapOnAll(null);
}

// Deletes all markers in the array by removing references to them.
var deleteMarkers = function() {
  clearMarkers();
  markers = [];
}

@@ -797,2194 +797,4 @@
 e .%0A
-%0Avar map;%0Avar markers = %5B%5D;%0A%0Avar initMap = function() %7B%0A  map = new google.maps.Map(document.getElementById('map'), %7B%0A    center: %7Blat: 33.999656, lng: -118.087183%7D,%0A    zoom: 5%0A  %7D);%0A%0A  $('#date').on('submit', fetchParams)%0A  var infoWindow = new google.maps.InfoWindow(%7Bmap: map%7D);%0A%0A  // Try HTML5 geolocation.%0A  if (navigator.geolocation) %7B%0A    navigator.geolocation.getCurrentPosition(function(position) %7B%0A      var pos = %7B%0A        lat: position.coords.latitude,%0A        lng: position.coords.longitude%0A      %7D;%0A%0A      infoWindow.setPosition(pos);%0A      infoWindow.setContent('You are here.');%0A      map.setCenter(pos);%0A    %7D, function() %7B%0A      handleLocationError(true, infoWindow, map.getCenter());%0A    %7D);%0A  %7D else %7B%0A    // Browser doesn't support Geolocation%0A    handleLocationError(false, infoWindow, map.getCenter());%0A  %7D%0A%7D;%0A%0A%0Afunction fetchParams(e) %7B%0A  e.preventDefault();%0A  var date = $('#date').serialize()%0A  $.getJSON('/sats?'+date, null, fetchSats);%0A%7D%0A%0Afunction fetchSats(response) %7B%0A  deleteMarkers();%0A  for (var i = 0; i %3C response.length; i++) %7B%0A    var sat = response%5Bi%5D;%0A    placeMarkers(sat.latitude, sat.longitude)%0A    //Append input into form with sat id%0A    $('.sat-locations').append('%3Cli%3E%3Cinput type=%22radio%22 name=%22sat_id%22 value=%22 class=%22new-event-sat-location%22'+sat.id+'%22%3E'+sat.address+'%3C/li%3E')%0A%0A  %7D%0A%7D%0A$()%0A$('form').on('click','.sat-locations', function(event)%7B%0A  event.preventDefault();%0A  var checked = $(%22:checked%22).val();%0A  console.log(checked);%0A%7D)%0A%0Afunction eventParams(e)%7B%0A  e.preventDefault();%0A  var sat = $('#date').serialize()%0A%0A%7D%0Afunction placeMarkers(lat, lng) %7B%0A%0A    var latlng = new google.maps.LatLng(lat, lng);%0A    new_marker = new google.maps.Marker(%7B%0A      position: latlng,%0A      map: map%0A    %7D);%0A    markers.push(new_marker);%0A%7D%0A%0A// Sets the map on all markers in the array.%0Avar setMapOnAll = function(map) %7B%0A  for (var i = 0; i %3C markers.length; i++) %7B%0A    markers%5Bi%5D.setMap(map);%0A  %7D%0A%7D%0A%0A// Removes the markers from the map, but keeps them in the array.%0Avar clearMarkers = function() %7B%0A  setMapOnAll(null);%0A%7D%0A%0A// Deletes all markers in the array by removing references to them.%0Avar deleteMarkers = function() %7B%0A  clearMarkers();%0A  markers = %5B%5D;%0A%7D%0A

fix js for map