jQuery(document).ready(function($){
$('.popup-gallery').magnificPopup({
    delegate: 'a',
    type: 'image',
    gallery:{
      enabled:true
    }
  });

$('.popup-modal').magnificPopup({
    type: 'inline',
    preloader: false,
    focus: '#username',
    modal: true
});
$(document).on('click', '.popup-modal-dismiss', function (e) {
    e.preventDefault();
    $.magnificPopup.close();
});
  
$("#datepicker").datepicker();

});

jQuery(document).ready(function(){



    jQuery('<div class="overlay"></div>').insertBefore(".content-wrapper");
});

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

        reader.onload = function (e) {
            jQuery('#'+id).attr('src', e.target.result);
        };
        reader.readAsDataURL(input.files[0]);
    }
}

function setModal(header_msg,body_msg){
    jQuery('[id="modal_body_msg"]').html(body_msg);
    jQuery('[id="modal_header_msg"]').html(header_msg);
    jQuery('[id="errModal"]').modal('show');
}

function slideTo(id){
    jQuery('html, body').animate({
        scrollTop: jQuery('[id="'+id+'"]').offset().top
    }, 800);
}

function modalTrigger(header,body_html){
    jQuery('[id="modal_content"]').html(body_html);
    jQuery('[id="modal_header"]').html(header);

    jQuery('[id="popup_modal"]').modal('show');
}

function modalHide(){
    jQuery('[id="popup_modal"]').modal('hide');
}

function addModalLoader(){
    jQuery("[id='modal_content']").addClass('relative height_200');
    jQuery("[id='modal_content']").prepend("<div id='modal_loader_body' class='loader'></div>");
}

function remModalLoader(){
    jQuery("[id='modal_loader_body']").remove();
    jQuery("[id='modal_content']").removeClass('relative height_200');
}

function showFullScreenLoader(){
    var thisObj = jQuery('.overlay');
    thisObj.css("display",'block');

    thisObj.addClass('relative');
    thisObj.prepend("<div id='fullScreenLoaderBody' class='loader'></div>");
}

function remFullScreenLoader(){
    var thisObj = jQuery('.overlay');
    thisObj.css("display",'none');

    jQuery('[id="fullScreenLoaderBody"]').remove();
    thisObj.removeClass('relative');
}




function abc(wish_id){
  modalTrigger('Wish Details','');
  var data = {wish_id:wish_id};
  var url = base_url+'Wish/view_single_wish';
  var result = post_ajax(url, data);
  jQuery('[id="modal_content"]').html(result);
}














function viewImageModal(title,img_src){
  if(title=='' || title==undefined || title=='undefined' || title==null || title=='null'||
     img_src=='' || img_src==undefined || img_src=='undefined' || img_src==null || img_src=='null'){
    return false;
  }
  body_html = '<div style="text-align:center">'+
          '<img src="'+img_src+'" onerror="this.src=\''+base_url+'assets/images/no_image.png\';" height="400px" width="auto">'+
            '</div>';
  modalTrigger(title,body_html);
}

// function initLocSearch_1() {
//  var input = document.getElementById('loc_search_1');
//  var options = {componentRestrictions: {country: country_flag}};
//  var autocomplete = new google.maps.places.Autocomplete(input, options);
// }
// google.maps.event.addDomListener(window,'load',initLocSearch_1);
// function initLocSearch_2() {
//  var input = document.getElementById('loc_search_2');
//  var options = {componentRestrictions: {country: country_flag}};
//  var autocomplete = new google.maps.places.Autocomplete(input, options);
// }
// google.maps.event.addDomListener(window,'load',initLocSearch_2);
// function initLocSearch_3() {
//  var input = document.getElementById('loc_search_3');
//  var options = {componentRestrictions: {country: country_flag}};
//  var autocomplete = new google.maps.places.Autocomplete(input, options);
// }
// google.maps.event.addDomListener(window,'load',initLocSearch_3);

function post_ajax(url, data) {
  var result = '';
  $.ajax({
        type: "POST",
        url: url,
    data: data,
    success: function(response) {
      result = response;
    },
    error: function(response) {
      result = 'error';
    },
    async: false
    });
    
    return result;
}



function getCustomerDetails(customer_id){

    if(customer_id=='' || customer_id==undefined || customer_id=='undefined' || customer_id==null || customer_id=='null'){
        return true;
    }
    modalTrigger('Customer Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Customer/getCustomerData",{'customer_id':customer_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var customer_data = jQuery.parseJSON(resp).data;
    
console.log(customer_data);
    jQuery.each(customer_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            customer_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="customerProfileImg" src="'+base_url+customer_data['profile_photo']+'" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>Customer Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Customer Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ customer_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Phone</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+customer_data['code']+customer_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Email ID</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ customer_data['email_id']+'</label></div>'+
                    '</div> '+
                   
                    
                    '<div class="row">'+
                      '<div class="col-md-3">Address</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+customer_data['address']+'</label></div>'+
                    '</div> '+

                   
                    '<div class="row">'+
                      '<div class="col-md-3">Area</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+customer_data['area']+'</label></div>'+
                    '</div> '+

                    

                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="customerProfileImg"]').error(function() {
        jQuery('[id="customerProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}




function getGarageDetails(garage_id){

    if(garage_id=='' || garage_id==undefined || garage_id=='undefined' || garage_id==null || garage_id=='null'){
        return true;
    }
    modalTrigger('Garage Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Garage/getGarageData",{'garage_id':garage_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var garage_data = jQuery.parseJSON(resp).data;
    
console.log(garage_data);
    jQuery.each(garage_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            garage_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="garageProfileImg" src="'+base_url+garage_data['profile_pic']+'" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>Garage Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Garage Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ garage_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Phone</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+garage_data['code']+garage_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Email ID</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ garage_data['email']+'</label></div>'+
                    '</div> '+
                   
                    '<div class="row">'+
                      '<div class="col-md-3">Garage Code</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+garage_data['garage_code']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Address</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+garage_data['address']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Location</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ garage_data['location']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Website</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+garage_data['website']+'</label></div>'+
                    '</div> '+
                      '<div class="row">'+
                      '<div class="col-md-3">Working Hours</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+garage_data['working_hours']+'</label></div>'+
                    '</div> '+

                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="garageProfileImg"]').error(function() {
        jQuery('[id="garageProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}




function getExpressDetails(express_id){

    if(express_id=='' || express_id==undefined || express_id=='undefined' || express_id==null || express_id=='null'){
        return true;
    }
    modalTrigger('Express Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Express/getExpressData",{'express_id':express_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var express_data = jQuery.parseJSON(resp).data;
    
console.log(express_data);
    jQuery.each(express_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            express_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="garageProfileImg" src="'+base_url+express_data['profile_photo']+'" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>Express Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Express Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ express_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Phone</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+express_data['code']+express_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Email ID</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ express_data['email']+'</label></div>'+
                    '</div> '+
                   
                    '<div class="row">'+
                      '<div class="col-md-3">Garage Code</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+express_data['garage_code']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Address</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+express_data['address']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Location</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ express_data['location']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Website</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+express_data['website']+'</label></div>'+
                    '</div> '+
                      '<div class="row">'+
                      '<div class="col-md-3">Working Hours</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+express_data['working_hours']+'</label></div>'+
                    '</div> '+

                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="garageProfileImg"]').error(function() {
        jQuery('[id="garageProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}



function getPosDetails(pos_id){

    if(pos_id=='' || pos_id==undefined || pos_id=='undefined' || pos_id==null || pos_id=='null'){
        return true;
    }
    modalTrigger('Pos Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Pos/getPosData",{'pos_id':pos_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var pos_data = jQuery.parseJSON(resp).data;
    
console.log(pos_data);
    jQuery.each(pos_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            pos_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="garageProfileImg" src="'+base_url+pos_data['profile_photo']+'" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>POS Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Express Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ pos_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Phone</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+pos_data['code']+pos_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Email ID</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ pos_data['email_id']+'</label></div>'+
                    '</div> '+
                   
                    '<div class="row">'+
                      '<div class="col-md-3">POS Code</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+pos_data['pos_code']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Address</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+pos_data['address']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Location</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ pos_data['location']+'</label></div>'+
                    '</div> '+

                    
                    '</div> '+
                      '<div class="row">'+
                      '<div class="col-md-3">Working Hours</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+pos_data['working_from']+' to '+pos_data['working_to']+'</label></div>'+
                    '</div> '+

                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="garageProfileImg"]').error(function() {
        jQuery('[id="garageProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}
function getRoad_assistDetails(assist_id){

    if(assist_id=='' || assist_id==undefined || assist_id=='undefined' || assist_id==null || assist_id=='null'){
        return true;
    }
    modalTrigger('Road assist Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Road_assist/getRoad_assistData",{'assist_id':assist_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var assist_data = jQuery.parseJSON(resp).data;
    
console.log(assist_data);
    jQuery.each(assist_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            assist_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="garageProfileImg" src="'+base_url+assist_data['profile_photo']+'" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>Roadassist Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Roadassist Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ assist_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Phone</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['code']+assist_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Email ID</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ assist_data['email_id']+'</label></div>'+
                    '</div> '+
                   
                    '<div class="row">'+
                      '<div class="col-md-3">Roadassist Code</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['road_assist_code']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Address</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['address']+'</label></div>'+
                    '</div> '+

                    '</div> '+
                      '<div class="row">'+
                      '<div class="col-md-3">Working Hours</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['working_from']+' to '+assist_data['working_to']+'</label></div>'+
                    '</div> '+

                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="garageProfileImg"]').error(function() {
        jQuery('[id="garageProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}

function getPospartsDetails(Posparts_id){

    if(Posparts_id=='' || Posparts_id==undefined || Posparts_id=='undefined' || Posparts_id==null || Posparts_id=='null'){
        return true;
    }
    modalTrigger('Pos Parts Details','');
    addModalLoader();

    var resp = post_ajax(base_url+"Pos_parts/getPospartsData",{'Posparts_id':Posparts_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var assist_data = jQuery.parseJSON(resp).data;
    
console.log(assist_data);
    jQuery.each(assist_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            assist_data[index] = ' -- ';
        }
    });
    var html =  '<div class="col-xs-12">'+
                  '<div class="col-md-2">'+
                    '<div class="row">'+
                      '<img  id="garageProfileImg" src="" height="100" width="100" />'+
                    '</div>'+
                  '</div> '+
                  '<div class="col-md-10">'+
                    '<div class="row"><label><b>Pos Parts Details</b></label></div>'+
                    '<div class="row">'+
                      '<div class="col-md-3">Part Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ assist_data['name']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Part Number</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['code']+assist_data['phone_no']+'</label></div>'+
                    '</div> '+
                    '<div class="row">'+
                      '<div class="col-md-3">Unique Name</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+ assist_data['email']+'</label></div>'+
                    '</div> '+
                   
                    '<div class="row">'+
                      '<div class="col-md-3">Price</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['garage_code']+'</label></div>'+
                    '</div> '+

                    '<div class="row">'+
                      '<div class="col-md-3">Quentity</div>'+
                      '<div class="col-md-1">:</div>'+
                      '<div class="col-md-6"><label>'+assist_data['address']+'</label></div>'+
                    '</div> '+

                   
                  '</div> '+
                '</div>';

    remModalLoader();
    jQuery('[id="modal_content"]').html(html);

    jQuery('[id="garageProfileImg"]').error(function() {
        jQuery('[id="garageProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}





///////////////////////////location///////////////////////////////////




///////////////////////////location///////////////////////////////////


var autocomplete = new google.maps.places.Autocomplete($("#location")[0], {});

google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();

var label_address = place.adr_address;

//label_address.find('span').attr('class="country-name"', '');

var lat = place.geometry.location.lat();
var lng = place.geometry.location.lng();
$('#lat').val(lat);
$('#lng').val(lng);
var latlng;
latlng = new google.maps.LatLng(lat, lng);

new google.maps.Geocoder().geocode({'latLng' : latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var country = null, countryCode = null, city = null, cityAlt = null;
var c, lc, component;
for (var r = 0, rl = results.length; r < rl; r += 1) {
var result = results[r];
if (!country && result.types[0] === 'country') {
country = result.address_components[0].long_name;
countryCode = result.address_components[0].short_name;
}

if (country) {
break;
}
}

}
}

});



});


function ratelocation(){

    var autocomplete = new google.maps.places.Autocomplete(jQuery("#location")[0], {});

google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();

var label_address = place.adr_address;

//label_address.find('span').attr('class="country-name"', '');

var lat = place.geometry.location.lat();
var lng = place.geometry.location.lng();
jQuery('#lat').val(lat);
jQuery('#lng').val(lng);
var latlng;
latlng = new google.maps.LatLng(lat, lng);

new google.maps.Geocoder().geocode({'latLng' : latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var country = null, countryCode = null, city = null, cityAlt = null;
var c, lc, component;
for (var r = 0, rl = results.length; r < rl; r += 1) {
var result = results[r];
if (!country && result.types[0] === 'country') {
country = result.address_components[0].long_name;
countryCode = result.address_components[0].short_name;
}

if (country) {
break;
}
}

}
}

});



});
}



