$(document).ready(function () {
    $("#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
    })
});
function sat21_22_23() {
    var arr = ["00", "01", "02", "03", "04", "05", "06", "07"];
    jQuery.each(arr, function (index, value) {
	$("#hour option[value=" + this + "]").prop("disabled", true);
    });
}
function ponisti() {
    var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
    jQuery.each(arr, function (index, value) {
	$("#hour option[value*=" + this + "]").prop("disabled", false);
    });
}
function sat(vreme) {
    if (vreme === '00' || vreme === '01' || vreme === '02' || vreme === '03' || vreme === '04' || vreme === '05' || vreme === '06' || vreme === '07') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else
    if (vreme === '08') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else
    if (vreme === '09') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else
    if (vreme === '10') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '11') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '12') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '13') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '14') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '15') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '16') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '17') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '18') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '19') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '20') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '21') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    } else if (vreme === '22' || vreme === '23') {
	var arr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
	jQuery.each(arr, function (index, value) {
	    $("#hour option[value=" + this + "]").prop("disabled", true);
	});
    }
}
$.fn.racunaj = function () {
    var cit = document.getElementById("city");
    var city = cit.options[cit.selectedIndex].value;
    var plzxx = document.getElementById("zip");
    var plz = plzxx.options[plzxx.selectedIndex].value;
    var pers = document.getElementById("passengers");
    var personen = pers.options[pers.selectedIndex].value;
    var koff = document.getElementById("suitcases");
    var koffer = koff.options[koff.selectedIndex].value;
    var hand = document.getElementById("handluggage");
    var handluggage = hand.options[hand.selectedIndex].value;
    var hou = document.getElementById("hour");
    var hour = hou.options[hou.selectedIndex].value;
    var booster = document.getElementById("boosterseat");
    var boosterseat = booster.options[booster.selectedIndex].value;
    var child = document.getElementById("childseat");
    var childseat = child.options[child.selectedIndex].value;
    var carry = document.getElementById("carrycot");
    var carrycot = carry.options[carry.selectedIndex].value;
    var zusatz = document.getElementById("zusatzadresse");
    var zusatzadresse = zusatz.options[zusatz.selectedIndex].value;
    var pay = document.getElementById("payment");
    var payment = pay.options[pay.selectedIndex].value;
    var a1z = document.getElementById("aa1zip");
    var aa1zip = a1z.options[a1z.selectedIndex].value;
    var a2z = document.getElementById("aa2zip");
    var aa2zip = a2z.options[a2z.selectedIndex].value;
    var a3z = document.getElementById("aa3zip");
    var aa3zip = a3z.options[a3z.selectedIndex].value;
    var rueckfahrt = $("input:radio[name=return]:checked").val();
    var houret = document.getElementById("hourreturn");
    var hourreturn = houret.options[houret.selectedIndex].value;
    var dataString = 'city=' + city + '&zip=' + plz + '&passengers=' + personen + '&suitcases=' + koffer + '&hour=' + hour + '&boosterseat=' + boosterseat + '&childseat=' + childseat + '&carrycot=' + carrycot + '&zusatzadresse=' + zusatzadresse + '&payment=' + payment + '&aa1zip=' + aa1zip + '&aa2zip=' + aa2zip + '&aa3zip=' + aa3zip + '&rueckfahrt=' + rueckfahrt + '&hourreturn=' + hourreturn + '&handluggage=' + handluggage + '&way=ZUM';
    $.ajax
	    ({
		type: "POST",
		url: "libs/get_price.php",
		data: dataString,
		dataType: "json",
		cache: false,
		success: function (html)
		{
		    if (html[0] !== '') {
			var rueck_price = html[1];
			var price = parseFloat(html[0]).toFixed(2).replace(".", ",");
			rueck_price = parseFloat(rueck_price).toFixed(2).replace(".", ",");
			$("#price").text(price);
			$("#pricereturn").text(rueck_price);
		    } else {
			$("#price").text('0,00');
			$("#pricereturn").text('0,00');
		    }
		}
	    });
};
$(document).ready(function () {
    $('#pickupdate').change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
	var map_zum_abholdatum = $(this).val();
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth() + 1;
	var yyyy = today.getFullYear();
	if (dd < 10) {
	    dd = '0' + dd;
	}
	if (mm < 10) {
	    mm = '0' + mm;
	}
	var danas = dd + '.' + mm + '.' + yyyy;
	var sati = new Date().getHours();
	sati = ("0" + sati).slice(-2);
	var min = new Date().getMinutes();
	var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
	var day = currentDate.getDate();
	var month = currentDate.getMonth() + 1;
	var year = currentDate.getFullYear();
	if (day < 10) {
	    day = '0' + day;
	}
	if (month < 10) {
	    month = '0' + month;
	}
	var sutra = day + '.' + month + '.' + year;
	if (map_zum_abholdatum === danas)
	{
	    sat(sati);
	} else {
	    ponisti();
	}
	if (sati === '21' || sati === '22' || sati === '23')
	{
	    if (map_zum_abholdatum === sutra) {
		sat21_22_23();
	    }
	}
    });
    $("#city").change(function () {
	$("#street").html('<option value="none" selected>Strasse auswählen...</option>');
	$.get('libs/get_zip.php?plz=' + $(this).val(), function (data) {
	    $("#zip").html(data);
	});
	$().racunaj();
    });
    $("#zip").change(function () {
	$.get('libs/get_strasse.php?strasse=' + $(this).val(), function (data) {
	    $("#street").html(data);
	});
	$().racunaj();
    });
    $("#aa1zip").change(function () {
	$.get('libs/get_strasse.php?strasse=' + $(this).val(), function (data) {
	    $("#aa1street").html(data);
	});
	$().racunaj();
    });
    $("#aa2zip").change(function () {
	$.get('libs/get_strasse.php?strasse=' + $(this).val(), function (data) {
	    $("#aa2street").html(data);
	});
	$().racunaj();
    });
    $("#aa3zip").change(function () {
	$.get('libs/get_strasse.php?strasse=' + $(this).val(), function (data) {
	    $("#aa3street").html(data);
	});
	$().racunaj();
    });
    $("#payment").change(function () {
	$().racunaj();
    });
    $("#passengers").change(function () {
	$().racunaj();
    });
    $("#suitcases").change(function () {
	$().racunaj();
    });
    $("#boosterseat").change(function () {
	$().racunaj();
    });
    $("#zusatzadresse").change(function () {
	var addrs = $(this).val();
	if (addrs === '1') {
	    $("#aa2street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa3street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa2housenumber").val('');
	    $("#aa3housenumber").val('');
	    $("#add1x").fadeIn(500);
	    $("#add2x").fadeOut(500);
	    $("#add3x").fadeOut(500);
	}
	if (addrs === '2') {
	    $("#aa3street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa3housenumber").val('');
	    $("#add1x").fadeIn(500);
	    $("#add2x").fadeIn(500);
	    $("#add3x").fadeOut(500);
	}
	if (addrs === '3') {
	    $("#add1x").fadeIn(500);
	    $("#add2x").fadeIn(500);
	    $("#add3x").fadeIn(500);
	}
	if (addrs === '0') {
	    $("#aa1street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa2street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa3street").html('<option value="none" selected>Strasse auswählen...</option>');
	    $("#aa1housenumber").val('');
	    $("#aa2housenumber").val('');
	    $("#aa3housenumber").val('');
	    $("#add1x").fadeOut(500);
	    $("#add2x").fadeOut(500);
	    $("#add3x").fadeOut(500);
	}
	$().racunaj();
    });
    $("#flightnumber").autocomplete({
	minLength: 0,
	source: function (request, response) {
	    $.ajax({
		type: "GET",
		url: 'libs/flugnummer.php?name=' + $("#flightnumber").val(),
		dataType: "json",
		success: function (data) {
		    response(data);
		}
	    });
	},
	select: function (event, ui) {
	}
    });
    $("#departure").autocomplete({
	minLength: 0,
	source: function (request, response) {
	    $.ajax({
		type: "GET",
		url: 'libs/flugort.php?name=' + $("#departure").val(),
		dataType: "json",
		success: function (data) {
		    response(data);
		}
	    });
	},
	select: function (event, ui) {
	}
    });
    $('#email').keyup(function () {
	this.value = this.value.toLowerCase();
    });
    $('#flightnumber').keyup(function () {
	this.value = this.value.toUpperCase();
	if (this.value.match(/[^a-zA-Z0-9 ]/g)) {
	    this.value = this.value.replace(/[^a-zA-Z0-9]/g, '');
	}
    });
    $('#note').keypress(function (e) {
	var c = String.fromCharCode(e.which);
	var key = e.keyCode || e.which;
	if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
	    return;
	}
	if (key === 39 || key === 222) {
	    e.preventDefault();
	    return false;
	}
	var regex = new RegExp("^[a-zA-Z0-9 \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df]");
	var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
	if (regex.test(str)) {
	    return true;
	}
	e.preventDefault();
	return false;
    });
    $('#name, #surname').keypress(function (e) {
	var c = String.fromCharCode(e.which);
	var key = e.keyCode || e.which;
	if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
	    return;
	}
	if (key === 39 || key === 222) {
	    e.preventDefault();
	    return false;
	}
	var regex = new RegExp("^[a-zA-Z \b\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00df]");
	var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
	if (regex.test(str)) {
	    return true;
	}
	e.preventDefault();
	return false;
    });
    $('#phone').keypress(function (e) {
	var c = String.fromCharCode(e.which);
	var key = e.keyCode || e.which;
	if (key === 37 || key === 8 || key === 9 || key === 46 || key === 44) {
	    return;
	}
	if (key === 39 || key === 222) {
	    e.preventDefault();
	    return false;
	}
	var regex = new RegExp("^[0-9+\b]");
	var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
	if (regex.test(str)) {
	    return true;
	}
	e.preventDefault();
	return false;
    });
    $('#email').keypress(function (e) {
	var regex = /^\S*$/;
	var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
	if (regex.test(str)) {
	    return true;
	}
	e.preventDefault();
	return false;
    });
    $("input[name=return]:radio").change(function () {
	var rett = $('input[name=return]:checked').val();
	if (rett === '2') {
	    $("#returnfields").fadeIn(500);
	    $("#rueckinfo").fadeIn(500);
	} else {
	    $("#returnfields").fadeOut(500);
	    $("#rueckinfo").fadeOut(500);
	}
	$().racunaj();
    });
    $("#hour").change(function () {
	$().racunaj();
    });
    $("#hourreturn").change(function () {
	$().racunaj();
    });
    $("#childseat").change(function () {
	$().racunaj();
    });
    $("#carrycot").change(function () {
	$().racunaj();
    });
    $("#hour").change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
    });
    $("#minute").change(function () {
	$().time_block('pickupdate', 'hour', 'minute', 'ZUM');
    });
    $("#pickupdatereturn").change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'VOM');
    });
    $("#hourreturn").change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'VOM');
    });
    $("#minutereturn").change(function () {
	$().time_block('pickupdatereturn', 'hourreturn', 'minutereturn', 'VOM');
    });
    $.fn.insertzum = function () {
	var pickupdate = document.getElementById("pickupdate").value;
	var hr = document.getElementById("hour");
	var hour = hr.options[hr.selectedIndex].value;
	var mn = document.getElementById("minute");
	var minute = mn.options[mn.selectedIndex].value;
	var or = document.getElementById("city");
	var city = or.options[or.selectedIndex].value;
	var plzxx = document.getElementById("zip");
	var zip = plzxx.options[plzxx.selectedIndex].value;
	var str = document.getElementById("street");
	var street = str.options[str.selectedIndex].value;
	var housenumber = document.getElementById("housenumber").value;
	var pers = document.getElementById("passengers");
	var passengers = pers.options[pers.selectedIndex].value;
	var koff = document.getElementById("suitcases");
	var suitcases = koff.options[koff.selectedIndex].value;
	var handl = document.getElementById("handluggage");
	var handluggage = handl.options[handl.selectedIndex].value;
	var kindsh = document.getElementById("boosterseat");
	var boosterseat = kindsh.options[kindsh.selectedIndex].value;
	var cse = document.getElementById("childseat");
	var childseat = cse.options[cse.selectedIndex].value;
	var carr = document.getElementById("carrycot");
	var carrycot = carr.options[carr.selectedIndex].value;
	var aa = document.getElementById("zusatzadresse");
	var zusatzadresse = aa.options[aa.selectedIndex].value;
	var aa1z = document.getElementById("aa1zip");
	var aa1zip = aa1z.options[aa1z.selectedIndex].value;
	var aa1s = document.getElementById("aa1street");
	var aa1street = aa1s.options[aa1s.selectedIndex].value;
	var aa1housenumber = document.getElementById("aa1housenumber").value;
	var aa2z = document.getElementById("aa2zip");
	var aa2zip = aa2z.options[aa2z.selectedIndex].value;
	var aa2s = document.getElementById("aa2street");
	var aa2street = aa2s.options[aa2s.selectedIndex].value;
	var aa2housenumber = document.getElementById("aa2housenumber").value;
	var aa3z = document.getElementById("aa3zip");
	var aa3zip = aa3z.options[aa3z.selectedIndex].value;
	var aa3s = document.getElementById("aa3street");
	var aa3street = aa3s.options[aa3s.selectedIndex].value;
	var aa3housenumber = document.getElementById("aa3housenumber").value;
	var zahl = document.getElementById("payment");
	var payment = zahl.options[zahl.selectedIndex].value;
	var note = document.getElementById("note").value;
	var anr = document.getElementById("salutation");
	var salutation = anr.options[anr.selectedIndex].value;
	var name = document.getElementById("name").value;
	var surname = document.getElementById("surname").value;
	var phone = document.getElementById("phone").value;
	var email = document.getElementById("email").value;
	var retturn = $('input[name=return]:checked').val();
	var pickupdatereturn = document.getElementById("pickupdatereturn").value;
	var hrr = document.getElementById("hourreturn");
	var hourreturn = hrr.options[hrr.selectedIndex].value;
	var mnr = document.getElementById("minutereturn");
	var minutereturn = mnr.options[mnr.selectedIndex].value;
	var departure = document.getElementById("departure").value;
	var flightnumber = document.getElementById("flightnumber").value;
	var km = document.getElementById("km").innerHTML;
	var min = document.getElementById("min").innerHTML;
	var dataString = 'pickupdate=' + pickupdate + '&hour=' + hour + '&minute=' + minute + '&city=' + city + '&zip=' + zip + '&street=' + street + '&housenumber=' + housenumber + '&passengers=' + passengers + '&suitcases=' + suitcases + '&boosterseat=' + boosterseat + '&carrycot=' + carrycot + '&zusatzadresse=' + zusatzadresse + '&aa1zip=' + aa1zip + '&aa1street=' + aa1street + '&aa1housenumber=' + aa1housenumber + '&aa2zip=' + aa2zip + '&aa2street=' + aa2street + '&aa2housenumber=' + aa2housenumber + '&aa3zip=' + aa3zip + '&aa3street=' + aa3street + '&aa3housenumber=' + aa3housenumber + '&payment=' + payment + '&note=' + note + '&salutation=' + salutation + '&name=' + name + '&surname=' + surname + '&phone=' + phone + '&email=' + email + '&retturn=' + retturn + '&pickupdatereturn=' + pickupdatereturn + '&hourreturn=' + hourreturn + '&minutereturn=' + minutereturn + '&departure=' + departure + '&flightnumber=' + flightnumber + '&childseat=' + childseat + '&km=' + km + '&min=' + min + '&handluggage=' + handluggage;
	$.ajax
		({
		    type: "POST",
		    url: "libs/insert_zum.php",
		    data: dataString,
		    dataType: 'json',
		    cache: false,
		    success: function (html)
		    {
			if (html[0] === 'ERROR') {
			    swal({
				title: "FEHLER!",
				text: "Es ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut oder rufen Sie uns an",
				type: "error",
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "OK",
				closeOnConfirm: true,
			    },
				    function (isConfirm) {
					if (isConfirm) {
					    $('#order').show();
					    $('#orderX').hide();
					}
				    });
			} else {
			    $("#formular").fadeOut();
			    $("#danke").fadeIn();
//			    window.scrollTo(0, 0);
			    $('html, body').animate({
				scrollTop: $("#danke").offset().top
			    }, 2000);
			}
		    }
		});
    };
    $.fn.validation = function () {
	var zip = $("#zip").val();
	if (zip === 'none') {
	    $().info('select', 'zip', 'Bitte Postleitzahl auswählen.');
	    return false;
	}
	var street = $("#street").val();
	if (street === 'none') {
	    $().info('select', 'street', 'Bitte Strasse auswählen.');
	    return false;
	}
	var housenumber = $("#housenumber").val();
	if (housenumber === '') {
	    $().info('input', 'housenumber', 'Bitte Hausnummer eingeben.');
	    return false;
	}
	var pickupdate = $("#pickupdate").val();
	if (pickupdate === '') {
	    $().info('input', 'pickupdate', 'Bitte Abholdatum auswählen.');
	    return false;
	}
	var hour = $("#hour").val();
	if (hour === 'none') {
	    $().info('select', 'hour', 'Bitte Stunde auswählen.');
	    return false;
	}
	var minute = $("#minute").val();
	if (minute === 'none') {
	    $().info('select', 'minute', 'Bitte Minute auswählen.');
	    return false;
	}
	var name = $("#name").val();
	if (name === '') {
	    $().info('input', 'name', 'Bitte Vorname eingeben.');
	    return false;
	}
	var surname = $("#surname").val();
	if (surname === '') {
	    $().info('input', 'surname', 'Bitte Nachname eingeben.');
	    return false;
	}
	var email = $("#email").val();
	if (email === '') {
	    $().info('input', 'email', 'Bitte E-Mail eingeben.');
	    return false;
	}
	var emailvalid = $('#email').val();
	var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
	if (!re.test(emailvalid)) {
	    $().info('input', 'email', 'Ungültige E-Mail Adresse.');
	    return false;
	}
	var phone = $("#phone").val();
	if (phone === '') {
	    $().info('input', 'phone', 'Bitte Telefonnummer eingeben.');
	    return false;
	}
	var zusatzadresse = $("#zusatzadresse").val();
	if (zusatzadresse >= 1) {
	    var aa1zip = $("#aa1zip").val();
	    if (aa1zip === 'none') {
		$().info('select', 'aa1zip', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 1)');
		return false;
	    }
	    var aa1street = $("#aa1street").val();
	    if (aa1street === 'none') {
		$().info('select', 'aa1street', 'Bitte Strasse auswählen. (Zusatz-Ziel 1)');
		return false;
	    }
	    var aa1housenumber = $("#aa1housenumber").val();
	    if (aa1housenumber === '') {
		$().info('input', 'aa1housenumber', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 1)');
		return false;
	    }
	}
	if (zusatzadresse >= 2) {
	    var aa2zip = $("#aa2zip").val();
	    if (aa2zip === 'none') {
		$().info('select', 'aa2zip', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 2)');
		return false;
	    }
	    var aa2street = $("#aa2street").val();
	    if (aa2street === 'none') {
		$().info('select', 'aa2street', 'Bitte Strasse auswählen. (Zusatz-Ziel 2)');
		return false;
	    }
	    var aa2housenumber = $("#aa2housenumber").val();
	    if (aa2housenumber === '') {
		$().info('input', 'aa2housenumber', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 2)');
		return false;
	    }
	}
	if (zusatzadresse === 3) {
	    var aa3zip = $("#aa3zip").val();
	    if (aa3zip === 'none') {
		$().info('select', 'aa3zip', 'Bitte Postleitzahl auswählen. (Zusatz-Ziel 3)');
		return false;
	    }
	    var aa3street = $("#aa3street").val();
	    if (aa3street === 'none') {
		$().info('select', 'aa3street', 'Bitte Strasse auswählen. (Zusatz-Ziel 3)');
		return false;
	    }
	    var aa3housenumber = $("#aa3housenumber").val();
	    if (aa3housenumber === '') {
		$().info('input', 'aa3housenumber', 'Bitte Hausnummer eingeben. (Zusatz-Ziel 3)');
		return false;
	    }
	}
	var rueckfahrt = $("input:radio[name=return]:checked").val();
	if (rueckfahrt === '2') {
	    var pickupdatereturn = $("#pickupdatereturn").val();
	    if (pickupdatereturn === '') {
		$().info('input', 'pickupdatereturn', 'Bitte Abholdatum auswählen.(bei Rückfahrt)');
		return false;
	    }
	    var hourreturn = $("#hourreturn").val();
	    if (hourreturn === 'none') {
		$().info('select', 'hourreturn', 'Bitte Stunde auswählen.(bei Rückfahrt)');
		return false;
	    }
	    var minutereturn = $("#minutereturn").val();
	    if (minutereturn === 'none') {
		$().info('select', 'minutereturn', 'Bitte Minute auswählen.(bei Rückfahrt)');
		return false;
	    }
	    var minutereturn = $("#minutereturn").val();
	    if (minutereturn === 'none') {
		$().info('select', 'hourreturn', 'Bitte Minute auswählen.(bei Rückfahrt)');
		return false;
	    }
	    var departure = $("#departure").val();
	    if (departure === '') {
		$().info('input', 'departure', 'Bitte Abflugort eingeben.(bei Rückfahrt)');
		return false;
	    }
	    var flightnumber = $("#flightnumber").val();
	    if (flightnumber === '') {
		$().info('input', 'flightnumber', 'Bitte Flugnummer auswählen.(bei Rückfahrt)');
		return false;
	    }
	}
	var agb = $('input[name=agb]:checked').val();
	if (agb != "1") {
	    $().info('checkbox', 'agb', 'Bitte AGB akzeptieren.');
	    return false;
	}
	$().insertzum();
    };
    $('#order').click(function () {
	$('#order').hide();
	$('#orderX').show();
	$().validation();
    });
});
$.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') {
			    $().info_block('Für diesen Zeit (' + hour + ':' + minute + ') sind alle Autos beschäftigt,versuchen 10-15 Minuten früher oder später.');
			    return false;
			} else if (html === 'stop_hour') {
			    $().info_block('Für diesen Zeit (' + hour + ':00 - ' + hour + ':55) sind alle Autos beschäftigt.');
			    return false;
			} else if (html === 'stop_day') {
			    $().info_block('Für diesen Tag (' + pickupdate + ') sind alle Autos beschäftigt.');
			    return false;
			} else {
			    $().racunaj();
			}
		    }
		});
    }
};
$.fn.info = function (inp, id, msg) {
    swal({
	title: "FEHLER!",
	text: "" + msg + "",
	type: "error",
	confirmButtonColor: "#DD6B55",
	confirmButtonText: "OK",
	closeOnConfirm: true,
    },
	    function (isConfirm) {
		if (isConfirm) {
		    $('html, body').animate({
			scrollTop: $("#" + id).offset().top - 300
		    }, {complete: function () {
			    $('#orderX').hide();
			    $('#order').show();
			    $("#" + id).effect('shake', 500);
			}}, 1000);
		}
	    });
    return false;
};
$.fn.info_block = function (msg) {
    swal({
	title: "FEHLER!",
	text: "" + msg + "",
	type: "error",
	confirmButtonColor: "#DD6B55",
	confirmButtonText: "OK",
	closeOnConfirm: true,
    },
	    function (isConfirm) {
		if (isConfirm) {
		}
	    });
    return false;
};
$(document).ready(function () {
    function checkParams() {
	var field = 'zip';
	var url = window.location.href;
	if (url.indexOf('?' + field + '=') != -1)
	    return true;
	else if (url.indexOf('&' + field + '=') != -1)
	    return true;
	return false
    }
    if (checkParams()) {
	var url_string = window.location.href;
	var url = new URL(url_string);
	var zipcity = url.searchParams.get("zip");
	var pickupdate = url.searchParams.get("pickupdate");
	var hour = url.searchParams.get("hour");
	var minute = url.searchParams.get("minute");
	var passengers = url.searchParams.get("passengers");
	var fields = zipcity.split('X');
	var zip = fields[0];
	var city = fields[1];
	$('#city').val(city);
	$("#street").html('<option value="none" selected>Strasse auswählen...</option>');
	$.get('libs/get_zip.php?plz=' + city, function (data) {
	    $("#zip").html(data);
	    $("#zip").val(zip);
	    $.get('libs/get_strasse.php?strasse=' + zip, function (data) {
		$("#street").html(data);
		$("#pickupdate").val(pickupdate);
		$("#hour").val(hour);
		$("#minute").val(minute);
		$("#passengers").val(passengers);
		$().racunaj();
		setTimeout(function () {
		    from = getSelectedText('street') + ' ' + document.getElementById('housenumber').value + ', ' + getZip('zip') + ' ' + getSelectedText('city');
		    calcRoute();
		}, 1000);
	    });
	});
    }
});
