

$.fn.racunaj = function () {



    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 hou = document.getElementById("hour");
    var hour = hou.options[hou.selectedIndex].value;

    var dataString = '&zip=' + plz + '&passengers=' + personen + '&hour=' + hour;

    console.log(dataString);
    //alert(dataString);
    $.ajax
	    ({
		type: "POST",
		url: "scripts/get_price_home.php",
		data: dataString,
		dataType: "json",
		cache: false,
		success: function (html)
		{
//                    console.log(html[0] + ' nula');
//                    console.log(html[1] + ' jedan');
//                    console.log(html[2] + ' dva');
//                    console.log(html + ' blank');
		    console.log(html);
		    console.log(html[0]);

		    // alert(html[0]);
		    if (html[0] !== '') {

//			var rueck_price = html[1];
//			var gesamt = (+html[0] + +html[1]);
			var price = parseFloat(html[0]).toFixed(2).replace(".", ",");
//			rueck_price = parseFloat(rueck_price).toFixed(2).replace(".", ",");
//			gesamt = parseFloat(gesamt).toFixed(2).replace(".", ",");
			$("#price").text(price);
//			$("#pricereturn").html(rueck_price);
//			$("#gesamt").html(gesamt);

		    } else {
			$("#price").text('0,00');
//			$("#pricereturn").html('0,00');
//			$("#pricereturnstrike").html('0,00');
//			$("#gesamt").html('0,00');
		    }
		}
	    });
};


$("#hour").change(function () {
    console.log('aaaaa');
    $().racunaj();
});
$("#zip").change(function () {
    console.log('aaaaa');
    $().racunaj();
});
$("#passengers").change(function () {
    console.log('aaaaa');
    $().racunaj();
});
$().racunaj();


function buchenZum() {

    var way = $("#way").val();
    var zip = $("#zip").val();
    var pickupdate = $("#pickupdate").val();
    var hour = $("#hour").val();
    var minute = $("#minute").val();
    var passengers = $("#passengers").val();

//    if (way != "none" && zip != "none" && pickupdate && pickupdate != '' && hour != "none" && minute != "none" && passengers != "none") {
//	console.log('OK');
//    } else {
//	console.log('ERROR');
//	return false;
//
//    }


    if (zip === 'none') {
	$().info('select', 'zip', 'Bitte Postleitzahl auswählen.');
	return false;
    }
    if (way === 'none') {
	$().info('select', 'zip', 'Bitte Richtung auswählen.');
	return false;
    }
    if (passengers === 'none') {
	$().info('select', 'zip', 'Bitte Personenzahl auswählen.');
	return false;
    }
    if (hour === 'none') {
	$().info('select', 'zip', 'Bitte Stunde auswählen.');
	return false;
    }
    if (minute === 'none') {
	$().info('select', 'zip', 'Bitte Minute auswählen.');
	return false;
    }
    if (pickupdate) {
	if (pickupdate === '') {
	    $().info('select', 'pickupdate', 'Bitte Abholdatum auswählen.');
	    return false;
	}
    } else {
	return false;
    }

    if (way == 'ZUM') {
	window.location.href = 'zum-flughafen.php?zip=' + zip + '&pickupdate=' + pickupdate + '&hour=' + hour + '&minute=' + minute + '&passengers=' + passengers;
    } else {
	window.location.href = 'vom-flughafen.php?zip=' + zip + '&pickupdate=' + pickupdate + '&hour=' + hour + '&minute=' + minute + '&passengers=' + passengers;
    }
}



$.fn.info = function (inp, id, msg) {
    // $("#loading").dialog('close');
    if (inp === 'select') {
//         $('#' + id).addClass('valid');
//        $("#select2-" + id + "-container").next("span").addClass('valid');
    } else {
	$('.' + id).addClass('valid');

    }



    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);
		}
	    });



    /*  var SplitText = "Title";
     var $dialog = $('<div></div>')
     .html(SplitText)
     .dialog({
     autoOpen: false,
     modal: true,
     draggable: false,
     show: {effect: "fade", duration: 300},
     width: 'auto',
     height: 'auto',
     resizable: false,
     //dialogClass: 'dialog_fixed_valid',
     title: 'ACHTUNG !',
     buttons: {
     Ok: function () {
     $('#orderX').hide();
     $('#order').show();
     $(this).dialog("close"); //closing on Ok click
     $('html, body').animate({
     scrollTop: $("#" + id).offset().top - 150
     }, {complete: function () {
     $("#" + id).effect('shake', 500);
     }}, 1000);
     }}
     });
     $dialog.dialog('open');
     $dialog.html('<br><center><strong>' + msg + '</strong></center>');*/
    return false;
};
