﻿
var result = new Object();
result.initalize = function() {
    this.rentLowSeason = 0;
    this.rentHighSeason = 0;
    this.adults = 0;
    this.children = 0;
    this.daysLowSeason = 0;
    this.daysHighSeason = 0;
    this.totalPerson = 0;
    this.days = 0;
    this.totalRentLowSeason = 0;
    this.totalRentHighSeason = 0;
    this.totalTax = 0;
    this.totalSheet = 0;
}
result.total = function() {
    return this.totalRentLowSeason + this.totalRentHighSeason + this.totalTax + this.totalSheet + cleaning;
};

function customRange(input) {
    return { minDate: (input.id == 'to' ?
                            $('#from').datepick('getDate') : '0'),
        maxDate: ('+1Y')
    };
}
function getPrice() {
    result.initalize();
    result.adults = parseInt($('#Adults').val());
    result.children = parseInt($('#Children').val());
    var from = $('#from').datepick('getDate');
    var to = $('#to').datepick('getDate');

    result.totalPerson = result.adults + (result.children * 0.5);
    result.days = ((to - from) / 1000 / 60 / 60 / 24);

    var currentDate = from;
    for (var i = 0; i < result.days; i++) {
        if (isHighSeason(currentDate, result))
            result.daysHighSeason++;
        else
            result.daysLowSeason++;
        for (var t = 0; t < result.adults; t++)
            result.totalTax += taxAdult;
        for (var tc = 0; tc < result.children; tc++)
            result.totalTax += taxChild;
        currentDate = addDays(currentDate, 1);
    }


    for (var t = 0; t < result.adults + result.children; t++)
        result.totalSheet += washing;

    showPrice();
    return false;
}
function addDays(myDate, days) {
    return new Date(myDate.getTime() + days * 24 * 60 * 60 * 1000);
}
function isHighSeason(day, result) {
    for (var x = 0; x < highSeason.length; x++) {
        if (day >= highSeason[x].start && day <= highSeason[x].end)
            if (result.totalPerson >= 2.5) {
            result.totalRentHighSeason += priceHighHigh;
            return true;
        }
        else {
            result.totalRentHighSeason += priceHighHigh;
            return true;
        }
    }
    if (result.totalPerson >= 2.5) {
        result.totalRentLowSeason += priceLowHigh;
        return false;
    }
    else {
        result.totalRentLowSeason += priceLowLow;
        return false;
    }
}
function showPrice() {
    $('#priceTitel').show();
    $('#price').show();
    $('#priceTotal').show();
    if (result.daysHighSeason > 0) {
        $('#priceDaysHigh').show();
        $('#priceDaysHigh')[0].innerHTML = pricePerDayText + (result.totalPerson >= 2.5 ? priceHighHigh : priceHighLow) + currency + "x " + parseInt(result.daysHighSeason) + daysTex + highSeasonText;
        $('#priceDaysHighTotal').show();
        $('#priceDaysHighTotal')[0].innerHTML = result.totalRentHighSeason + currency;
    }
    else {
        $('#priceDaysHigh').hide();
        $('#priceDaysHighTotal').hide();
    }
    if (result.daysLowSeason > 0) {
        $('#priceDaysLow').show();
        $('#priceDaysLow')[0].innerHTML = pricePerDayText + (result.totalPerson >= 2.5 ? priceLowHigh : priceLowLow) + currency + "x " + parseInt(result.daysLowSeason) + daysTex + lowSeasonText;
        $('#priceDaysLowTotal').show();
        $('#priceDaysLowTotal')[0].innerHTML = result.totalRentLowSeason + currency;
    }
    else {
        $('#priceDaysLow').hide();
        $('#priceDaysLowTotal').hide();
    }
    $('#taxElectricity')[0].innerHTML = taxText;
    $('#taxElectricityTotal')[0].innerHTML = result.totalTax + currency;
    $('#sheets')[0].innerHTML = sheetsText;
    $('#sheetsTotal')[0].innerHTML = result.totalSheet + currency;
    $('#finalClean')[0].innerHTML = finalCleanText;
    $('#finalCleanTotal')[0].innerHTML = cleaning + currency;
    $('#total')[0].innerHTML = totalText;
    $('#grandTotal')[0].innerHTML = result.total() + currency;
    $('#priceTitel')[0].innerHtmal = rentalCostText;
}

    $.datepick.regional['de'] = {
        clearText: 'löschen', clearStatus: 'aktuelles Datum löschen',
        closeText: 'schließen', closeStatus: 'ohne Änderungen schließen',
        prevText: '&#x3c;zurück', prevStatus: 'letzten Monat zeigen',
        prevBigText: '&#x3c;&#x3c;', prevBigStatus: '',
        nextText: 'Vor&#x3e;', nextStatus: 'nächsten Monat zeigen',
        nextBigText: '&#x3e;&#x3e;', nextBigStatus: '',
        currentText: 'heute', currentStatus: '',
        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'],
        monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
        weekHeader: 'Wo', weekStatus: 'Woche des Monats',
        dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
        dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
        dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
        dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'Wähle D, M d',
        dateFormat: 'dd.mm.yy', firstDay: 1,
        initStatus: 'Wähle ein Datum', isRTL: false,
        showMonthAfterYear: false, yearSuffix: ''
    };
