var DATAMANAGER = {}; //Namespace

DATAMANAGER.DataTableManager_cl = new Class.create({
    initialize: function () {
        this.className = "DataTableManager_cl";
    },
    generateDefaultTableByMonth_px: function (nMonth, nYear) {
        var datumStart = Date.parse('1.' + nMonth + '.' + nYear);
        var datumEnd = Date.parse('1.' + (nMonth + 1 > 12 ? 1 : nMonth + 1) + '.' + (nMonth + 1 > 12 ? nYear + 1 : nYear));
        var datenSaetze = [];

        datenSaetze.push({datum: datumStart.toString('dd.MM.yyyy'), tag: 1, monat: nMonth, jahr: nYear, tagesnamen: datumStart.toString('dddd'), daten: {}});
        for (var nIndex = 2, max = 31; nIndex <= max; nIndex++) {
            var newDate = datumStart.addDays(1);
            if (newDate >= datumEnd)
                break;

            datenSaetze.push({datum: newDate.toString('dd.MM.yyyy'), tag: nIndex, monat: nMonth, jahr: nYear, tagesnamen: newDate.toString('dddd'), daten: {}});
        }

        return datenSaetze;
    },
    generateHTMLTableByData: function (jsonObject) {

        if (jsonObject === null || jsonObject === undefined || jsonObject === "") {
            console.log("[" + this.className + "] Keine Übergabe.");
            return "";
        }

        var markup_s = "";
        var nMod = 7;
        var aTage_s = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"];
        var nTageUberspringen = 0;
        //Tablecolumns überspringen wenn nicht begint bei Montag
        if (jsonObject[0].tagesnamen !== "Montag") {
            for (var nIndex = 0, max = 7; nIndex < max; nIndex++) {
                if (aTage_s[nIndex] === jsonObject[0].tagesnamen) {
                    nTageUberspringen = nIndex;
                    break;
                }
            }
        }
        //markup_s += "<tr>";
        for (var nIndex = 0, max = 7 * 6; nIndex < max; nIndex++) {
            if (nIndex % nMod === 0 || nIndex === 0) {
                markup_s += "<tr>";
                //console.log("neue Zeile " + nIndex + "% " + nMod + " = 0");
            }
            if (nIndex < nTageUberspringen || nIndex - nTageUberspringen >= jsonObject.length) {
                markup_s += "<td>&nbsp;</td>";
                continue;
            }
            //console.log(jsonObject[nIndex - nTageUberspringen].datum);
            markup_s += "<td class='cl_EditColumn'><div data-item='"+JSON.stringify(jsonObject[nIndex - nTageUberspringen].daten)+"' data-id='" + (nIndex - nTageUberspringen) + "' data-nmonat='" + jsonObject[nIndex - nTageUberspringen].monat + "' data-jahr='" + jsonObject[nIndex - nTageUberspringen].jahr + "'>" + jsonObject[nIndex - nTageUberspringen].datum + "</div></td>";

            if (nIndex + 1 % nMod === 0 && nIndex > 0)
                markup_s += "</tr>";
        }
        markup_s += "</tr>";

        return markup_s;
    }


});