$(document).ready(function () { $('#button_cancel').on('click', function () { window.location.href = 'index.php'; }); var _delay = null, $_picker = $('#pckuptime'), $_total_trigger = $('[data-app-data="trigger_total"]'), $_loader = $("#loader"), $_total_text = $("#total"); $_picker.datetimepicker({ timeFormat:'hh:mm tt', dateFormat: 'yy/mm/dd', minDate: new Date() }); var options = { componentRestrictions: {country: "uk"} }; var input = document.getElementById('book_from'); new google.maps.places.Autocomplete(input, options); var input2 = document.getElementById('book_to'); new google.maps.places.Autocomplete(input2, options); var input3 = document.getElementById('book_via'); new google.maps.places.Autocomplete(input3, options); var $_book_car = $_total_trigger.filter('#book_car'); var $_book_payment = $('#book_payment'); $_total_trigger.on('blur keyup change', function(){ var book_type_element = $_total_trigger.filter('#book_car'); book_type_element.closest('.dropdown').css('background', 'transparent'); if(_delay){ clearTimeout(_delay); _delay = null; } _delay = setTimeout(function() { $_total_text.attr('data-status','false'); var book_from = $_total_trigger.filter('#book_from').val(); var book_to = $_total_trigger.filter('#book_to').val(); var book_via = $_total_trigger.filter('#book_via').val(); var book_child = $_total_trigger.filter('#book_child').val(); var book_seat = $_total_trigger.filter('#book_seat').val(); var book_type_element = $_total_trigger.filter('#book_car'); var book_type = book_type_element.val(); var data = { from: book_from, to: book_to, via: book_via, child: book_child, seat: book_seat, type: book_type, action: 'total' }; $_total_text.attr('data-status','false'); if( ['saloon', 'estate','mpv', 'large_mpv' ].indexOf(book_type) === -1 ) { book_type_element.closest('.dropdown').css('background', 'rgba(243, 21, 34, 0.6)'); } else { book_type_element.closest('.dropdown').css('background', 'transparent'); } $_loader.show(); $_total_text.text(''); $_total_text.attr('data-status','false'); $.getJSON("app/json.php", data, function (data) { $_total_text.text(data['text']); $_total_text.attr('data-status',data['status']); $_loader.hide(); }); }, 1000); }); $('[data-action="map"]').on('click', function(){ var _t = $(this); $('#ref').val(_t.attr('data-ref')); $('.pickermap').show(); $('#us3-address').val( $(_t.attr('data-ref')).val() ); $('#us3-address').change(); }); $("#map_save").on('click', function(){ var location = $("#map").locationpicker('location'); console.log(location); $('.pickermap').hide(); $_total_trigger.filter( $('#ref').val() ).val( location.name ); $_total_trigger.change(); }); $("#map_cancel").on('click', function () { $('.pickermap').hide(); }); $('#map').locationpicker({ zoom: 12, radius: false, enableAutocomplete: true, location: { latitude: 51.5060865, longitude: -0.1334393 }, inputBinding: { locationNameInput: $('#us3-address') }, autocompleteOptions:{ componentRestrictions: {country: "uk"} }, onchanged: function (currentLocation, radius, isMarkerDropped) { //var mapContext = $(this).locationpicker('map'); //mapContext.map.setZoom(13); } }); $('#book_form').on('submit', function(e){ if( ['saloon', 'estate','mpv', 'large_mpv' ].indexOf($_book_car.val()) === -1 ) { $_book_car.closest('.dropdown').css('background', 'rgba(243, 21, 34, 0.6)'); return false; } else { $_book_car.closest('.dropdown').css('background', 'transparent'); } if( $_book_payment.val() !== 'cash' && $_book_payment.val() !== 'paypal') { $_book_payment.closest('.dropdown').css('background', '#ffcccf'); return false; } else { $_book_payment.closest('.dropdown').css('background', 'transparent'); } if( $_total_text.attr('data-status') === 'false' ) return false; if (typeof grecaptcha === "undefined"){ return false; } var response = grecaptcha.getResponse(); if(response.length === 0){ return false; } return true; }); $('[name="book_car"], [name="book_payment"]').on('change', function(){ $(this).closest('.dropdown').css('background', 'transparent'); }); $_total_text.text('-'); $_picker.change(); }); /* acwave 2018 */