  function readURL(input,ids) {
        
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
          
            jQuery(ids).attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

jQuery('body').on('change','#jform_cover',function(){
   
    readURL(this,'.sellerimg1');
});
jQuery('body').on('change','#jform_shoplogo',function(){
   
    readURL(this,'.sellerimg2');
});

    initialize();

    var oldMarker;

    function initialize() {
    var  icon = "green";
     var latlng = {lat:<?php echo $lg; ?>,lng:<?php echo $lt; ?>};
    var map = new google.maps.Map(document.getElementById('map_canvas'), {
      zoom: 12,
      center: latlng
    });
    icon = "http://maps.google.com/mapfiles/ms/icons/" + icon + ".png";
    var marker = new google.maps.Marker({
      position: latlng,
      map: map,
      icon: new google.maps.MarkerImage(icon),
      title: 'saved location'
    });

        google.maps.event.addListener(map, 'click', function(event) {
          
          
          jQuery('#jform_latitude').val(event.latLng.lat());
          jQuery('#jform_logtitude').val(event.latLng.lng());
            placeMarker(event.latLng);
        });

        function placeMarker(location) {
          var iconBase = '//maps.google.com/mapfiles/kml/shapes/';

          var infowindow = new google.maps.InfoWindow({
            content: 'Your location'
          });
           icon = "red";
           icon = "http://maps.google.com/mapfiles/ms/icons/" + icon + ".png";
            marker1 = new google.maps.Marker({
                position: location,
                map: map,
                icon: new google.maps.MarkerImage(icon),
                animation: google.maps.Animation.BOUNCE
            });

            if (oldMarker != undefined){
                oldMarker.setMap(null);
            }
            oldMarker = marker1;
            map.setCenter(location);
            marker1.addListener('click', function() {
              infowindow.open(map, marker1);
            });

        }


      var input = document.getElementById('pac_input');
    var searchBox = new google.maps.places.SearchBox(input);
    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

    // Bias the SearchBox results towards current map's viewport.
    map.addListener('bounds_changed', function() {
      searchBox.setBounds(map.getBounds());
    });

    var markers = [];
    // Listen for the event fired when the user selects a prediction and retrieve
    // more details for that place.
    searchBox.addListener('places_changed', function() {
      var places = searchBox.getPlaces();

      if (places.length == 0) {
        return;
      }

      // Clear out the old markers.
      markers.forEach(function(marker) {
        marker.setMap(null);
      });
      markers = [];

      // For each place, get the icon, name and location.
      var bounds = new google.maps.LatLngBounds();
      places.forEach(function(place) {
        var icon = {
          url: place.icon,
          size: new google.maps.Size(71, 71),
          origin: new google.maps.Point(0, 0),
          anchor: new google.maps.Point(17, 34),
          scaledSize: new google.maps.Size(25, 25)
        };

        // Create a marker for each place.
        markers.push(new google.maps.Marker({
          map: map,
          icon: icon,
          title: place.name,
          position: place.geometry.location
        }));

        if (place.geometry.viewport) {
          // Only geocodes have viewport.
          bounds.union(place.geometry.viewport);
        } else {
          bounds.extend(place.geometry.location);
        }
      });
      map.fitBounds(bounds);
    });



    }
      jQuery(document).ready(function() {
    
            jQuery(".dropdown img.flag").addClass("flagvisibility");
            jQuery(".dropdown dt a").click(function() {
                jQuery(".dropdown dd ul").toggle();
            });
                        
            jQuery(".dropdown dd ul li a").click(function() {
                var text = jQuery(this).html();
      
        var country_logo = jQuery(this).attr('id');
        
         jQuery( "#countrylogo" ).val( country_logo );
        
                jQuery(".dropdown dt a span").html(text);
                jQuery(".dropdown dd ul").hide();
                jQuery("#result").html("Selected value is: " + getSelectedValue("sample"));
            });
                        
            function getSelectedValue(id) {
                return jQuery("#" + id).find("dt a span.value").html();
            }
            jQuery(document).bind('click', function(e) {
                var $clicked = jQuery(e.target);
                if (! $clicked.parents().hasClass("dropdown"))
                    jQuery(".dropdown dd ul").hide();
            });
      jQuery(".dropdown img.flag").toggleClass("flagvisibility");


      
        });
