/* Minification failed. Returning unminified contents.
(2,10): run-time error CSS1031: Expected selector, found 'tmAPI_Screenings('
(2,10): run-time error CSS1025: Expected comma or open brace, found 'tmAPI_Screenings('
(9,14): run-time error CSS1031: Expected selector, found '='
(9,14): run-time error CSS1025: Expected comma or open brace, found '='
(11,10): run-time error CSS1031: Expected selector, found 'tmApi_Room('
(11,10): run-time error CSS1025: Expected comma or open brace, found 'tmApi_Room('
(19,10): run-time error CSS1031: Expected selector, found 'tmFindRoom('
(19,10): run-time error CSS1025: Expected comma or open brace, found 'tmFindRoom('
(23,10): run-time error CSS1031: Expected selector, found 'CreateTrailer('
(23,10): run-time error CSS1025: Expected comma or open brace, found 'CreateTrailer('
(32,10): run-time error CSS1031: Expected selector, found 'AddDays('
(32,10): run-time error CSS1025: Expected comma or open brace, found 'AddDays('
(60,10): run-time error CSS1031: Expected selector, found 'formatYYYYMMDDD('
(60,10): run-time error CSS1025: Expected comma or open brace, found 'formatYYYYMMDDD('
(67,10): run-time error CSS1031: Expected selector, found 'formatHHMM('
(67,10): run-time error CSS1025: Expected comma or open brace, found 'formatHHMM('
(73,10): run-time error CSS1031: Expected selector, found 'formatYYYYMMDDDwd('
(73,10): run-time error CSS1025: Expected comma or open brace, found 'formatYYYYMMDDDwd('
 */

function tmAPI_Screenings(screeningDate, getDataFunc) {
    yy = screeningDate.getFullYear();
    mm = screeningDate.getMonth() + 1;
    dd = screeningDate.getDate();
    $.get('/ticket/screening?year=' + yy + '&month=' + mm + '&day=' + dd, getDataFunc);
}

let theRooms = [];

function tmApi_Room() {
    if (theRooms.length == 0) {
        $.get('/ticket/room', function (data, status) {
            theRooms = data;
        }).done();
    }
}

function tmFindRoom(id) {
    return theRooms.find(function (current) { return current.roomId == id; });
}

function CreateTrailer(youbtube_id) {
    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

}

function AddDays(aDate, days) {
    yy = aDate.getFullYear();
    mm = aDate.getMonth() + 1;
    dd = aDate.getDate() + days;

    if (dd > 28) {
        if (mm == 2) {
            mm = 3;
            dd = 1;
        }
        else if (dd > 30) {
            if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
                ++mm;
                dd = 1;
            }
        }
        else if (dd > 31) {
            ++mm;
            dd = 1;
            if (mm == 13) {
                ++yy;
                mm = 1;
            }
        }
    }
    return new Date(yy, mm - 1, dd, 0, 0, 0, 0);
}

function formatYYYYMMDDD(d) {
    ev = d.getFullYear();
    ho = d.getMonth() + 1;
    nap = d.getDate();
    return '' + ev + '.' + (ho < 10 ? '0' : '') + ho + '.' + (nap < 10 ? '0' : '') + nap + '.';
}

function formatHHMM(d) {
    ora = d.getHours();
    perc = d.getMinutes();
    return (ora < 10 ? '0' : '') + ora + ':' + (perc < 10 ? '0' : '') + perc;
}

function formatYYYYMMDDDwd(d) {
    var weekday = new Array(7);
    weekday[0] = "Vasárnap";
    weekday[1] = "Hétfő";
    weekday[2] = "Kedd";
    weekday[3] = "Szerda";
    weekday[4] = "Csütörtök";
    weekday[5] = "Péntek";
    weekday[6] = "Szombat";
    return formatYYYYMMDDD(d) + ' ' + weekday[d.getDay()];
}

