
function removeHTMLTags(inputcode) {
        var strInputCode = inputcode;
        strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
        return strTagStrippedText;
}


// JavaScript Document
$(document).ready(function () {

    //EXTERNES FENSTER ÖFFNEN 
    $("a[rel='external']").click(function (event) {
        window.open($(this).attr("href"));
        event.preventDefault();
    });

    //buchen
    $('a.buchpauschale').click(function () {
        //var buchpauschale = $(this).parents("div").children('h3').children('a').html()
        var buchpauschale = $(this).attr("alt");
        $("#fpauschale option").each(function () {
            if ($(this).val() == buchpauschale) {
                $(this).attr("selected", "selected");
                $("#fpauschale2").val(removeHTMLTags($(this).text()));
                $.scrollTo($('#buchungspanel'), 800, { offset: -20 });
                // window.location.href = "#buchungspanel";
            }
        });
    });
    $('#fpauschale').change(function () {
        $("#fpauschale2").val(removeHTMLTags($(this + "option:selected").text()));
    });
    // Autovalue
    $('.message').focus(
	    function () { if ($(this).val() == $(this).attr("title")) { $(this).val('') } },
		function () { if ($(this).val() == '') { $(this).val($(this).attr("title")) } }
	);
    $('.message').blur(
		function () { if ($(this).val() == '') { $(this).val($(this).attr("title")) } }
	);
    $('#buchung').submit(function () {
        $("#recap").val('assigned');
    });

    /* FADE THINGS */
    $(".fade").hover(function () {
        $(this).animate({ opacity: 0.40 }, 100);
    }, function () {
        $(this).animate({ opacity: 1 }, 100);
    });

    $("#miniform").tabs("#miniform form.pane", { tabs: 'h4', effect: 'slide', initialIndex: null });

    if ($("#slideshow a").length > 0) {
        $('#slideshow a').overlay({
            target: '#gallery',
            expose: {
                maskId: 'exposeMask',
                color: '#533524',
                opacity: 0.95
            }
        }).gallery({
            speed: 800
        });
    }

    if ($(".panoramaIFrame a").length > 0) {

        $('.panoramaIFrame a').overlay({
            target: '#panorama',
            expose: {
                maskId: 'exposeMask',
                color: '#533524',
                opacity: 0.95
            },
            onBeforeLoad: function (event, index) {
                var addToIframe = this.getTrigger().attr("href");
                $("#panoramaFrame").attr("src", "");
                $("#panoramaFrame").attr("src", addToIframe);
            }
        });
    }

   
    //Navigation
    $('ul#nav ul').stop().css({ 'display': 'block' }); // Fallback remove
    $('ul#nav ul').hide();

    $('ul#nav li').hover(
		    function () {
		        $(this).children('ul').slideDown(200);
		    },
		    function () {
		        $(this).children('ul').slideUp(100);
		    }
	    );


    //Datepicker
    //Delete Date Config for using english format
    Date.abbrDayNames = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'];
    Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'];
    Date.monthNames = ['Januar', 'Februar', 'Maerz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
    Date.firstDayOfWeek = 1;
    Date.format = 'dd. mmmm yyyy';

    $('input#anreise').datePicker({ clickInput: true });
    $('input#abreise').datePicker({ clickInput: true });
    $('input#fanreise').datePicker({ clickInput: true });
    $('input#fabreise').datePicker({ clickInput: true });


    $('#fkinderalter').keydown(function (event) {
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 32) {
            if (event.keyCode == 32) { $('#fkinderalter').val($('#fkinderalter').val() + ',') }
        }
        else {
            if ((event.keyCode > 9 && event.keyCode < 48) || event.keyCode > 57) { event.preventDefault(); }
        }
    });

    // Form validierung
    $("#buchung").validate({
        ignore: ".ignore",
        submitHandler: function (form) {
            form.submit();
        },
        rules: {
            fanreise: "required",
            fabreise: "required",
            ferwachsene: "required",
            fanrede: "required",
            fvorname: "required",
            fname: "required",
            ftelefon: "required",
            femail: {
                required: true,
                email: true
            }
        },
        messages: {
            fanreise: "Geben Sie bitte den Anreisetag ein",
            fabreise: "Geben Sie bitte den Abreisetag ein",
            ferwachsene: "Geben Sie die Anzahl Erwachsener pro Zimmer ein",
            fanrede: "Geben Sie bitte Ihre Anrede ein",
            fvorname: "Geben Sie bitte Ihren Vornamen ein",
            fname: "Geben Sie bitte Ihren Namen ein",
            ftelefon: "Geben Sie bitte Ihre aktuelle Telefonnummer ein",
            femail: "Geben Sie bitte eine korrekte E-Mail-Adresse ein"
        }
    });

    //Ausgewählte Pauschalen einblenden (Buchungsanfrage)
    $('#fpauschale.directlink').change(function () {
        $("#f").val("");
        $("#buchung input, #buchung select").addClass("ignore");
        $("#buchung").attr("action", "default.aspx?SIid=" + $.getUrlVar('SIid') + "&LAid=" + $.getUrlVar('LAid') + "&ARid=" + $(this).val());
        $("#buchung").submit();
    });

    
});


$.extend({
    getUrlVars: function() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name) {
        return $.getUrlVars()[name];
    }
});
