$(document).ajaxStart(function() { Pace.restart(); });
$(function() {
	$( "form.validate" ).submit(function( event ) {

	var access = true;
	$(this).find('.required').each(function() {
		var v = $(this).val();

		if(v == null) v='';
		if((v.replace(/\s+/g, '')) == '') {
			//alert('e');
			access = false;
			$(this).parents(".form-group").addClass("has-error");
		}
		else {
			//alert('s');
			$(this).parents(".form-group").removeClass("has-error");
		}
	});
	if(access) {
		return;
	}
	else {
		$("html, body").animate({ scrollTop: $('.has-error').offset().top - 50 }, "slow");
	}
	event.preventDefault();
	
	});
});


$(function(){
$(document).on( 'click', '.show-garagedetails', function () {
	var garagedetails = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-garegemodels .modal-garagebody').html(loader);
    $('#popup-garegemodels').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Garage/garage_popup',            
				data: {'garagedetails':garagedetails},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-garegemodels .modal-garagebody').html(result);
					
				}
	});
});
});

$(function(){
$(document).on( 'click', '.show-offersdetails', function () {
	var offersvaldetails = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-offersmodels .modal-offersbody').html(loader);
    $('#popup-offersmodels').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Offers/offers_popup',            
				data: {'offersvaldetails':offersvaldetails},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-offersmodels .modal-offersbody').html(result);
					
				}
	});
});
});

$(function(){
$(document).on( 'click', '.show-bookingdetails', function () {
	var bookindetailsval = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-bokkingModel .modal-bookinbody').html(loader);
    $('#popup-bokkingModel').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Booking/booking_popup',            
				data: {'bookindetailsval':bookindetailsval},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-bokkingModel .modal-bookinbody').html(result);
					
				}
	});
});
});

$(function(){
$(document).on( 'click', '.show-garageservicedetails', function () {
	var garageservicedetailsval = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-garegeservicemodels .modal-garageservicebody').html(loader);
    $('#popup-garegeservicemodels').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Garage/service_popup',            
				data: {'garageservicedetailsval':garageservicedetailsval},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-garegeservicemodels .modal-garageservicebody').html(result);
					
				}
	});
});
});


$(function(){
$(document).on( 'click', '.show-pooldetails', function () {
	var pooldetailsget = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-pooldetailsmodel .modal-poolbody').html(loader);
    $('#popup-pooldetailsmodel').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Pool/pool_popup',            
				data: {'pooldetailsget':pooldetailsget},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-pooldetailsmodel .modal-poolbody').html(result);
					
				}
	});
});
});



$(function(){
$(document).on( 'click', '.show-requestedetails', function () {
	var requestdetailsget = $(this).attr("data-id");
	var loader = '<p class="text-center"><img src="'+base_url+'assets/images/ajax-loader-4.gif" /></p>';
    $('#popup-reguestdetailsmodel .modal-requestbody').html(loader);
    $('#popup-reguestdetailsmodel').modal({show:true});
	$.ajax({		
				type: "POST",
				url: base_url+'Pool/request_popup',            
				data: {'requestdetailsget':requestdetailsget},
				cache: false,
				success: function(result)
				
				{
					
					$('#popup-reguestdetailsmodel .modal-requestbody').html(result);
					
				}
	});
});
});

//////ADMIN IMG UPLOADING/////

$('#profile_pic').on("change", function() {
	readURL(this);
});


$('#profileimg-form').change(function() {
	$('form#profilepic-form-img').submit();
});

$( document ).ready(function() {
	if($('#rich_editor').length == 1) { CKEDITOR.replace('rich_editor'); }
});

function initMap() {
	var input = document.getElementById('pac-input');
	var autocomplete = new google.maps.places.Autocomplete(input);

	autocomplete.addListener('place_changed', function() {
		var place = autocomplete.getPlace();
		if (!place.geometry) {
			return;
		}
		jQuery('#store_name').val(place.name);
		jQuery('#place_id').val(place.place_id);
	});
}

$(document).on('change', 'select[name="category"]', function(event) {
    var userTypeId = $(this).val().trim();

    jQuery('[id="dispTags"]').removeClass('hide');
    jQuery('[id^="tag_"]').prop('checked', false);

    var catTags = mapped_tags[userTypeId];
    jQuery.each(catTags, function(tag_id,tag_data) {
	  jQuery('[id="tag_'+tag_data+'"]').prop('checked', true);
	});
})