$(document).ready(function ($http) {
    $("#pickupdate").datepicker({
	prevText: '<i class="fa fa-chevron-left"></i>',
	nextText: '<i class="fa fa-chevron-right"></i>',
	prevStatus: "",
	prevJumpText: "<<",
	prevJumpStatus: "",
	nextStatus: "",
	nextJumpText: ">>",
	nextJumpStatus: "",
	currentText: "heute",
	currentStatus: "",
	todayText: "heute",
	todayStatus: "",
	clearText: "-",
	clearStatus: "",
	closeText: "schließen",
	closeStatus: "",
	monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
	monthNamesShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
	dayNames: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
	dayNamesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
	dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
	showMonthAfterYear: false,
	dateFormat: "dd.mm.yy",
	firstDay: 1,
	minDate: 0,
	maxDate: "+3M",
	showWeek: true
    });
    $("#pickupdatereturn").datepicker({
	prevText: '<i class="fa fa-chevron-left"></i>',
	nextText: '<i class="fa fa-chevron-right"></i>',
	prevStatus: "",
	prevJumpText: "<<",
	prevJumpStatus: "",
	nextStatus: "",
	nextJumpText: ">>",
	nextJumpStatus: "",
	currentText: "heute",
	currentStatus: "",
	todayText: "heute",
	todayStatus: "",
	clearText: "-",
	clearStatus: "",
	closeText: "schließen",
	closeStatus: "",
	monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
	monthNamesShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
	dayNames: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],
	dayNamesShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
	dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
	showMonthAfterYear: false,
	dateFormat: "dd.mm.yy",
	firstDay: 1,
	minDate: 0,
	maxDate: "+3M",
	showWeek: true
    })
});
$(document).ready(function () {
    $("#price").html('0.00');
    $("#pricereturn").html('0.00');
    $("#km").html('0');
    $("#min").html('0');
    var nightstunde;
    var child_seat_price;
    var booster_seat_price;
    var carrycot_price;
    var night_price_wien;
    var creditcard_price;
    $.ajax({type: "POST",
	url: 'libs/json_options.php',
	data: '',
	dataType: 'json',
	cache: false,
	success: function (result) {
	    nightstunde = result.nightprice;
	    child_seat_price = result.child_seat_price;
	    booster_seat_price = result.booster_seat_price;
	    carrycot_price = result.carrycot_price;
	    night_price_wien = result.night_price_wien;
	    creditcard_price = result.creditcard_price;
	}
    });
    $.fn.insert = function () {
	waitingDialog.show('Bitte warten...');
	var pickupdateval = $("#pickupdate").val();
	var hourval = $("#hour").val();
	var minuteval = $("#minute").val();
	var abholadresseval = $("#abholadresse").val();
	var zieladresseval = $("#zieladresse").val();
	var addaddressval = $("#addaddress").val();
	var zusatzadresse1val = $("#zusatzadresse1").val();
	var zusatzadresse2val = $("#zusatzadresse2").val();
	var zusatzadresse3val = $("#zusatzadresse3").val();
	var passengersval = $("#passengers").val();
	var suitcasesval = $("#suitcases").val();
	var handluggageval = $("#handluggage").val();
	var boosterseatval = $("#boosterseat").val();
	var childseatval = $("#childseat").val();
	var carrycotval = $("#carrycot").val();
	var paymentval = $("#payment").val();
	var salutationval = $("#salutation").val();
	var nameval = $("#name").val();
	var surnameval = $("#surname").val();
	var phoneval = $("#phone").val();
	var emailval = $("#email").val();
	var noteval = $("#note").val();
	var rueckfahrtval = $("#rueckfahrt").val();
	var pickupdatereturnval = $("#pickupdatereturn").val();
	var hourreturnval = $("#hourreturn").val();
	var minutereturnval = $("#minutereturn").val();
	var priceval = $("#prhin").val();
	var pricereturnval = $("#prrue").val();
	var dataString = 'pickupdate=' + pickupdateval + '&hour=' + hourval + '&minute=' + minuteval + '&zip=' + '&addaddress=' + addaddressval + '&passengers=' + passengersval + '&suitcases=' + suitcasesval + '&handlugage=' + handluggageval + '&boosterseat=' + boosterseatval + '&childseat=' + childseatval + '&carrycot=' + carrycotval + '&payment=' + paymentval + '&salutation=' + salutationval + '&name=' + nameval + '&surname=' + surnameval + '&phone=' + phoneval + '&email=' + emailval + '&note=' + noteval + '&rueckfahrt=' + rueckfahrtval + '&pickupdatereturn=' + pickupdatereturnval + '&hourreturn=' + hourreturnval + '&minutereturn=' + minutereturnval + '&price=' + priceval + '&pricereturn=' + pricereturnval + '&abholadresse=' + abholadresseval + '&zieladresse=' + zieladresseval + '&zusatzadresse1=' + zusatzadresse1val + '&zusatzadresse2=' + zusatzadresse2val + '&zusatzadresse3=' + zusatzadresse3val;
	$.ajax({
	    type: "POST",
	    url: "libs/insert_ab.php",
	    data: dataString,
	    dataType: "json",
	    cache: false,
	    success: function (html) {
		if (html[0] === 'ERROR') {
		    window.scrollTo(0, 0);
		    waitingDialog.hide();
		    swal({
			title: "FEHLER!",
			text: "Es ist ein Fehler aufgetreten. Bitte versuchen Sie es später noch einmal oder rufen Sie uns an",
			html: true
		    });
		    return false;
		} else {
		    window.scrollTo(0, 0);
		    waitingDialog.hide();
		    swal({
			title: "VIELEN DANK FÜR IHRE BESTELLUNG!",
			text: "Wir werden Ihre Bestellung so schnell wie möglich bearbeiten.<br>Ihre Bestelldaten werden Ihnen in Kürze per Email übermittelt.",
			html: true
		    },
			    function () {
				$("#formreset")[0].reset();
			    });
		}
	    }
	});
    };
    $.fn.info = function (id, msg) {
	swal({
	    title: "ACHTUNG!",
	    text: "" + msg + "",
	    html: true
	},
		function () {
		    $('html, body').animate({
			scrollTop: $("#" + id).offset().top - 150
		    }, {complete: function () {
			    $("#shake-" + id).effect('highlight', 500);
			}}, 1000);
		    return false;
		});
    };
    $.fn.validate = function () {
	route();
	var pickupdateval = $("#pickupdate").val();
	var hourval = $("#hour").val();
	var minuteval = $("#minute").val();
	var abholadresseval = $("#abholadresse").val();
	var zieladresseval = $("#zielabholadresse").val();
	var addaddressval = $("#addaddress").val();
	var zusatzadresse1val = $("#zusatzadresse1").val();
	var zusatzadresse2val = $("#zusatzadresse2").val();
	var zusatzadresse3val = $("#zusatzadresse3").val();
	var passengersval = $("#passengers").val();
	var suitcasesval = $("#suitcases").val();
	var handluggageval = $("#handluggage").val();
	var boosterseatval = $("#boosterseat").val();
	var childseatval = $("#childseat").val();
	var carrycotval = $("#carrycot").val();
	var paymentval = $("#payment").val();
	var salutationval = $("#salutation").val();
	var nameval = $("#name").val();
	var surnameval = $("#surname").val();
	var phoneval = $("#phone").val();
	var emailval = $("#email").val();
	var noteval = $("#note").val();
	var rueckfahrtval = $("#rueckfahrt").val();
	var pickupdatereturnval = $("#pickupdatereturn").val();
	var hourreturnval = $("#hourreturn").val();
	var minutereturnval = $("#minutereturn").val();
	if (pickupdateval == '') {
	    $().info('pickupdate', 'Bitte Abholdatum auswählen.');
	    return false;
	}
	if (hourval == 'none') {
	    $().info('hour', 'Bitte Abholzeit Stunde auswählen.');
	    return false;
	}
	if (minuteval == 'none') {
	    $().info('minute', 'Bitte Abholzeit Minute auswählen.');
	    return false;
	}
	if (abholadresseval == '') {
	    $().info('abholadresse', 'Bitte Abholadresse auswählen.');
	    return false;
	}
	if (zieladresseval == '') {
	    $().info('zieladresse', 'Bitte Zieladresse auswählen.');
	    return false;
	}
	if (addaddressval >= '1') {
	    if (zusatzadresse1val == '') {
		$().info('zusatzadresse1', 'Bitte Zusatzadresse 1 auswählen.');
		return false;
	    }
	}
	if (addaddressval >= '2') {
	    if (zusatzadresse2val == '') {
		$().info('zusatzadresse2', 'Bitte Zusatzadresse 2 auswählen.');
		return false;
	    }
	}
	if (addaddressval >= '3') {
	    if (zusatzadresse3val == '') {
		$().info('zusatzadresse3', 'Bitte Zusatzadresse 3 auswählen.');
		return false;
	    }
	}
	if (passengersval == 'none') {
	    $().info('passengers', 'Bitte Personen auswählen.');
	    return false;
	}
	if (nameval == '') {
	    $().info('name', 'Bitte Vorname eingeben.');
	    return false;
	}
	if (surnameval == '') {
	    $().info('surname', 'Bitte Nachname eingeben');
	    return false;
	}
	if (phoneval == '') {
	    $().info('phone', 'Bitte Telefonnummer eingeben');
	    return false;
	}
	if (emailval != '') {
	    var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
	    if (!re.test(emailval)) {
		$().info('email', 'Ungültige E-Mail Adresse.');
		return false;
	    }
	} else {
	    $().info('email', 'Bitte E-Mail Adresse eingeben.');
	    return false;
	}
	if (rueckfahrtval == '1') {
	    if (pickupdatereturnval == '') {
		$().info('pickupdatereturn', 'Bitte Abholdatum auswählen. (Rückfahrt)');
		return false;
	    }
	    if (hourreturnval == 'none') {
		$().info('hourreturn', 'Bitte Abholzeit Stunde auswählen. (Rückfahrt)');
		return false;
	    }
	    if (minutereturnval == 'none') {
		$().info('minutereturn', 'Bitte Abholzeit Minute auswählen. (Rückfahrt)');
		return false;
	    }
	}
	var agb = $('input[name=agb]:checked').val();
	if (agb != "1") {
	    $().info('agb', 'Bitte AGB akzeptieren.');
	    return false;
	}
	$().insert();
    }
    $.fn.time_block = function (pickupdate_id, hour_id, minute_id, way) {
	var pickupdate = $('#' + pickupdate_id).val();
	if (pickupdate !== '') {
	    var stdn = document.getElementById(hour_id);
	    var hour = stdn.options[stdn.selectedIndex].value;
	    var mint = document.getElementById(minute_id);
	    var minute = mint.options[mint.selectedIndex].value;
	    var dataString = 'pickupdate=' + pickupdate + '&hour=' + hour + '&minute=' + minute + '&way=' + way;
	    $.ajax
		    ({
			type: "POST",
			url: "libs/get_time_block.php",
			data: dataString,
			cache: false,
			success: function (html)
			{
			    if (html === 'stop_time') {
				swal({
				    title: "ACHTUNG!",
				    text: '<br><center><strong>Für diesen Zeit (' + hour + ':' + minute + ') sind alle Autos beschäftigt,<br>versuchen 10-15 Minuten früher oder später.</strong></center>',
				    html: true
				});
				$("#" + minute_id).val('none');
				return false;
			    } else if (html === 'stop_hour') {
				swal({
				    title: "ACHTUNG!",
				    text: '<br><center><strong>Für diesen Zeit (' + hour + ':00 - ' + hour + ':55) sind alle Autos beschäftigt.</strong></center>',
				    html: true
				});
				$("#" + hour_id).val('none');
				return false;
			    } else if (html === 'stop_day') {
				swal({
				    title: "ACHTUNG!",
				    text: '<br><center><strong>Für diesen Tag (' + pickupdate + ') sind alle Autos beschäftigt.</strong></center>',
				    html: true
				});
				$("#" + pickupdate_id).val('');
				$("#" + hour_id).val('none');
				$("#" + minute_id).val('none');
				return false;
			    } else {
			    }
			}
		    });
	}
    };
    $('#addaddress').change(function () {
	var val = $('#addaddress').val();
	if (val >= '1') {
	    $("#aa1").fadeIn(500);
	    $("#aa2").fadeOut(500);
	    $("#aa3").fadeOut(500);
	}
	if (val >= '2') {
	    $("#aa1").fadeIn(500);
	    $("#aa2").fadeIn(500);
	    $("#aa3").fadeOut(500);
	}
	if (val >= '3') {
	    $("#aa1").fadeIn(500);
	    $("#aa2").fadeIn(500);
	    $("#aa3").fadeIn(500);
	}
	if (val == '0') {
	    $("#aa1").fadeOut(500);
	    $("#aa2").fadeOut(500);
	    $("#aa3").fadeOut(500);
	}
	route();
    });
    $('#passengers').change(function () {
	var val = $('#passengers').val();
	route();
    });
    $('#suitcases').change(function () {
	var val = $('#suitcases').val();
	route();
    });
    $('#childseat').change(function () {
	var val = $('#childseat').val();
	route();
    });
    $('#boosterseat').change(function () {
	var val = $('#boosterseat').val();
	route();
    });
    $('#carrycot').change(function () {
	var val = $('#carrycot').val();
	route();
    });
    $('#payment').change(function () {
	var val = $('#payment').val();
	route();
    });
    $('#pickupdate').change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
    });
    $('#hour').change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
	route();
    });
    $('#minute').change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
    });
    $('#pickupdatereturn').change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'ZUM');
    });
    $('#hourreturn').change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'ZUM');
	route();
    });
    $('#minutereturn').change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'ZUM');
    });
    $('#rueckfahrt').change(function () {
	var val = $('#rueckfahrt').val();
	if (val == '1') {
	    $("#rueckfahrtfields").fadeIn(500);
	} else {
	    $("#rueckfahrtfields").fadeOut(500);
	}
	route();
    });
    var directionsService;
    var directionsDisplay;
    var map;
    function initialize() {
	directionsService = new google.maps.DirectionsService();
	var geocoder;
	geocoder = new google.maps.Geocoder();
	directionsDisplay = new google.maps.DirectionsRenderer({
	    animation: google.maps.Animation.DROP,
	    draggable: false
	});
	var vienna = new google.maps.LatLng(48.208174, 16.373819);
	var mapOptions = {
	    zoom: 16,
	    center: vienna
	}
	map = new google.maps.Map(document.getElementById('mapa'), mapOptions);
	directionsDisplay.setMap(map);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    var autocomplete_start;
    autocomplete_start = new google.maps.places.Autocomplete(document.getElementById('abholadresse'), {
	select: function (event, ui) {
	}
    });
    var autocomplete_end;
    autocomplete_end = new google.maps.places.Autocomplete(document.getElementById('zieladresse'), {
	select: function (event, ui) {
	}
    });
    var autocomplete_a1;
    autocomplete_a1 = new google.maps.places.Autocomplete(document.getElementById('zusatzadresse1'), {
	select: function (event, ui) {
	}
    });
    var autocomplete_a2;
    autocomplete_a2 = new google.maps.places.Autocomplete(document.getElementById('zusatzadresse2'), {
	select: function (event, ui) {
	}
    });
    var autocomplete_a3;
    autocomplete_a3 = new google.maps.places.Autocomplete(document.getElementById('zusatzadresse3'), {
	select: function (event, ui) {
	}
    });
    google.maps.event.addListener(autocomplete_start, 'place_changed', function () {
	route();
    });
    google.maps.event.addListener(autocomplete_end, 'place_changed', function () {
	route();
    });
    google.maps.event.addListener(autocomplete_a1, 'place_changed', function () {
	route();
    });
    google.maps.event.addListener(autocomplete_a2, 'place_changed', function () {
	route();
    });
    google.maps.event.addListener(autocomplete_a3, 'place_changed', function () {
	route();
    });
    function route() {
	var pocetak = $('#abholadresse').val();
	var kraj = $('#zieladresse').val();
	var start = pocetak;
	var end = kraj;
	if (pocetak == '' || kraj == '') {
	    return false;
	}
	var zusatz1;
	var zusatz2;
	var zusatz3;
	var zusatzX1;
	var zusatzX2;
	var zusatzX3;
	if ($('#addaddress').val() >= '1') {
	    zusatz1 = $('#zusatzadresse1').val();
	} else {
	    zusatz1 = '';
	}
	if ($('#addaddress').val() >= '2') {
	    zusatz2 = $('#zusatzadresse2').val();
	} else {
	    zusatz2 = '';
	}
	if ($('#addaddress').val() >= '3') {
	    zusatz3 = $('#zusatzadresse3').val();
	} else {
	    zusatz3 = '';
	}
	if (zusatz1 !== '') {
	    zusatzX1 = zusatz1;
	} else {
	    zusatzX1 = '';
	}
	if (zusatz2 !== '') {
	    zusatzX2 = zusatz2;
	} else {
	    zusatzX2 = '';
	}
	if (zusatz3 !== '') {
	    zusatzX3 = zusatz3;
	} else {
	    zusatzX3 = '';
	}
	var checkboxArray = [zusatzX1, zusatzX2, zusatzX3];
	var waypts = [];
	for (var i = 0; i < checkboxArray.length; i++) {
	    var adresanesto = checkboxArray[i];
	    if (adresanesto !== "") {
		waypts.push({
		    location: adresanesto,
		    stopover: true});
	    }
	}
	var request = {
	    origin: start,
	    destination: end,
	    waypoints: waypts,
	    optimizeWaypoints: false,
	    travelMode: google.maps.TravelMode.DRIVING};
	var totaldistance = 0;
	var totalduration = 0;
	directionsService.route(request, function (response, status) {
	    if (status == google.maps.DirectionsStatus.OK) {
		directionsDisplay.setDirections(response);
		var route = response.routes[0];
		for (var i = 0; i < route.legs.length; i++) {
		    totaldistance = totaldistance + route.legs[i].distance.value;
		    totalduration = totalduration + route.legs[i].duration.value;
		}
		var seconds = totalduration;
		var duration_min = parseInt(Math.ceil((seconds * 10 / 60)) / 10);
		var date = new Date(seconds * 1000);
		var hh = date.getUTCHours();
		var mm = date.getUTCMinutes();
		var ss = date.getSeconds();
		if (mm < 10) {
		    mm = "0" + mm;
		}
		if (ss < 10) {
		    ss = "0" + ss;
		}
		var mins = Math.floor(seconds / 60);
		var km = (totaldistance / 1000).toFixed(1);
		document.getElementById('km').innerHTML = km;
		document.getElementById('min').innerHTML = mins;
		var persn = $('#passengers').val();
		var koffer = $('#suitcases').val();
		if (persn == 'none') {
		    persn = 0;
		}
		if (koffer == 'none') {
		    koffer = 0;
		}
		if (koffer <= 2) {
		    var per_min = 0.17;
		    var per_km = 1.49;
		}
		if (persn <= 3) {
		    var per_min = 0.17;
		    var per_km = 1.49;
		}
		if (koffer == 3 || koffer == 4) {
		    var per_min = 0.56;
		    var per_km = 1.79;
		}
		if (persn == 4) {
		    var per_min = 0.56;
		    var per_km = 1.79;
		}
		if (koffer <= 8 && koffer >= 5) {
		    var per_min = 0.99;
		    var per_km = 2.28;
		}
		if (persn <= 8 && persn >= 5) {
		    var per_min = 0.99;
		    var per_km = 2.28;
		}
		var pr_min = (duration_min * per_min);
		var pr_km = ((totaldistance / 1000).toFixed(1) * per_km);
		var total_km = (totaldistance / 1000).toFixed(1);
		if (total_km <= 5000) {
		    var km_set = -0.10;
		}
		if (total_km <= 400) {
		    var km_set = -0.25;
		}
		if (total_km <= 300) {
		    var km_set = -0.16;
		}
		if (total_km <= 200) {
		    var km_set = -0.14;
		}
		if (total_km <= 39) {
		    var km_set = -0.29;
		}
		if (total_km <= 38) {
		    var km_set = -0.28;
		}
		if (total_km <= 37) {
		    var km_set = -0.28;
		}
		if (total_km <= 36) {
		    var km_set = -0.27;
		}
		if (total_km <= 35) {
		    var km_set = -0.27;
		}
		if (total_km <= 34) {
		    var km_set = -0.27;
		}
		if (total_km <= 33) {
		    var km_set = -0.26;
		}
		if (total_km <= 32) {
		    var km_set = -0.25;
		}
		if (total_km <= 31) {
		    var km_set = -0.24;
		}
		if (total_km <= 30) {
		    var km_set = -0.23;
		}
		if (total_km <= 29) {
		    var km_set = -0.21;
		}
		if (total_km <= 28) {
		    var km_set = -0.19;
		}
		if (total_km <= 27) {
		    var km_set = -0.17;
		}
		if (total_km <= 26) {
		    var km_set = -0.15;
		}
		if (total_km <= 25) {
		    var km_set = -0.13;
		}
		if (total_km <= 24) {
		    var km_set = -0.11;
		}
		if (total_km <= 23) {
		    var km_set = -0.09;
		}
		if (total_km <= 22) {
		    var km_set = -0.07;
		}
		if (total_km <= 21) {
		    var km_set = -0.06;
		}
		if (total_km <= 20) {
		    var km_set = -0.05;
		}
		if (total_km <= 19) {
		    var km_set = 0.0;
		}
		if (total_km <= 18) {
		    var km_set = 0.05;
		}
		if (total_km <= 17) {
		    var km_set = 0.10;
		}
		if (total_km <= 16) {
		    var km_set = 0.15;
		}
		if (total_km <= 15) {
		    var km_set = 0.25;
		}
		if (total_km <= 14) {
		    var km_set = 0.35;
		}
		if (total_km <= 13) {
		    var km_set = 0.45;
		}
		if (total_km <= 12) {
		    var km_set = 0.55;
		}
		var ab_price = (pr_km + (pr_km * km_set));
		if (ab_price <= 15.00) {
		    ab_price = 15.00;
		}
		var bs = $('#boosterseat').val();
		var cs = $('#childseat').val();
		var cc = $('#carrycot').val();
		if (bs == 1) {
		    ab_price = ab_price + booster_seat_price;
		} else if (bs == 2) {
		    ab_price = ab_price + booster_seat_price + booster_seat_price;
		} else if (bs == 3) {
		    ab_price = ab_price + booster_seat_price + booster_seat_price + booster_seat_price;
		}
		if (cs == 1) {
		    ab_price = ab_price + child_seat_price;
		} else if (cs == 2) {
		    ab_price = ab_price + child_seat_price + child_seat_price;
		} else if (cs == 3) {
		    ab_price = ab_price + child_seat_price + child_seat_price + child_seat_price;
		}
		if (cc == 1) {
		    ab_price = ab_price + carrycot_price;
		} else if (cc == 2) {
		    ab_price = ab_price + carrycot_price + carrycot_price;
		} else if (cc == 3) {
		    ab_price = ab_price + carrycot_price + carrycot_price + carrycot_price;
		}
		var pay = $('#payment').val();
		if (pay == 'Kreditkarte') {
		    ab_price = ab_price + creditcard_price;
		}
		var stunde = $('#hour').val();
		if (nightstunde.indexOf(stunde) >= 0) {
		    ab_price = ab_price + night_price_wien;
		}
		document.getElementById('price').innerHTML = ab_price.toFixed(2).replace(".", ",");
		$('#prhin').val(ab_price.toFixed(2));
		var stunde = $('#hour').val();
		if (nightstunde.indexOf(stunde) >= 0) {
		    var pricereturn = ab_price - night_price_wien;
		} else {
		    var pricereturn = ab_price;
		}
		var stundeR = $('#hourreturn').val();
		if (nightstunde.indexOf(stundeR) >= 0) {
		    pricereturn = pricereturn + night_price_wien;
		}
		document.getElementById('pricereturn').innerHTML = pricereturn.toFixed(2).replace(".", ",");
		$('#prrue').val(pricereturn.toFixed(2));
	    }
	});
    }
    var waitingDialog = waitingDialog || (function ($) {
	'use strict';
	var $dialog = $(
		'<div class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-hidden="true" style="padding-top:15%; overflow-y:visible;">' +
		'<div class="modal-dialog modal-m">' +
		'<div class="modal-content">' +
		'<div class="modal-header"><h3 style="margin:0;"></h3></div>' +
		'<div class="modal-body">' +
		'<div class="progress progress-striped active" style="margin-bottom:0;"><div class="progress-bar" style="width: 100%"></div></div>' +
		'</div>' +
		'</div></div></div>');
	return {
	    show: function (message, options) {
		if (typeof options === 'undefined') {
		    options = {};
		}
		if (typeof message === 'undefined') {
		    message = 'Loading';
		}
		var settings = $.extend({
		    dialogSize: 'm',
		    progressType: '',
		    onHide: null
		}, options);
		$dialog.find('.modal-dialog').attr('class', 'modal-dialog').addClass('modal-' + settings.dialogSize);
		$dialog.find('.progress-bar').attr('class', 'progress-bar');
		if (settings.progressType) {
		    $dialog.find('.progress-bar').addClass('progress-bar-' + settings.progressType);
		}
		$dialog.find('h3').text(message);
		if (typeof settings.onHide === 'function') {
		    $dialog.off('hidden.bs.modal').on('hidden.bs.modal', function (e) {
			settings.onHide.call($dialog);
		    });
		}
		$dialog.modal();
	    },
	    hide: function () {
		$dialog.modal('hide');
	    }
	};
    })(jQuery);
});
