var kalendar = function () { this.dny = function () { //hlavicka var objekt = this; this.datepicker.innerHTML = ''; var header = document.createElement ('div'); header.className = 'header'; this.datepicker.appendChild (header); var title = document.createElement ('div'); title.className = 'title'; header.appendChild (title); var titleText = document.createElement ('span'); titleText.className = 'titleText'; titleText.style.cursor = 'pointer'; titleText.innerHTML = this.nazvyMesicu[this.datum.getMonth()] + ' ' + this.datum.getFullYear(); titleText.onclick = function () { objekt.mesice (); } title.appendChild (titleText); var previous = document.createElement ('div'); previous.className = 'previous'; previous.innerHTML = '«'; previous.onclick = function () { objekt.datum.setMonth (objekt.datum.getMonth () - 1); objekt.dny (); } title.appendChild (previous); var next = document.createElement ('div'); next.className = 'next'; next.innerHTML = '»'; next.onclick = function () { objekt.datum.setMonth (objekt.datum.getMonth () + 1); objekt.dny (); } title.appendChild (next); var closeButton = document.createElement ('div'); closeButton.className = 'closeButton'; closeButton.innerHTML = 'x'; closeButton.onclick = function () { objekt.zavri (); } title.appendChild (closeButton); //telo var body = document.createElement ('div'); body.className = 'body'; this.datepicker.appendChild (body); var days = document.createElement ('div'); days.className = 'days'; body.appendChild (days); var titles = document.createElement ('div'); titles.className = 'titles'; days.appendChild (titles); for (var dny = 0; dny < 7; dny++) { var title = document.createElement ('div'); title.className = 'title day day' + dny; title.innerHTML = this.nazvyDnu[dny].substr (0, 2); days.appendChild (title); } var zacatekMesice = new Date (this.datum.getFullYear (), this.datum.getMonth (), 1, 6); var denVTydnu = zacatekMesice.getDay (); var danyMesic = this.datum.getMonth (); var vybranyRok = this.vybraneDatum.getFullYear (); var vybranyMesic = this.vybraneDatum.getMonth (); var vybranyDen = this.vybraneDatum.getDate (); var aktualniRok = this.aktualniDatum.getFullYear (); var aktualniMesic = this.aktualniDatum.getMonth (); var aktualniDen = this.aktualniDatum.getDate (); var casVMilisekundach = zacatekMesice.getTime () - (denVTydnu * 86400000); if (denVTydnu == 0) casVMilisekundach -= 7 * 86400000; for (var tydny = 0; tydny < 6; tydny++) { var week = document.createElement ('div'); week.className = 'week week' + tydny; days.appendChild (week); for (var dny = 0; dny < 7; dny++) { casVMilisekundach += 86400000; var noveDatum = new Date (casVMilisekundach); var jinyMesic = ''; if (noveDatum.getMonth () != danyMesic) jinyMesic = ' otherMonth'; var dnes = ''; if (noveDatum.getFullYear () == aktualniRok && noveDatum.getMonth () == aktualniMesic && noveDatum.getDate () == aktualniDen) dnes = ' today'; var vybrany = ''; if (noveDatum.getFullYear () == vybranyRok && noveDatum.getMonth () == vybranyMesic && noveDatum.getDate () == vybranyDen) vybrany = ' selected'; var day = document.createElement ('div'); day.className = 'day day' + dny + jinyMesic + dnes + vybrany; day.innerHTML = noveDatum.getDate (); day.konecneDatum = noveDatum; day.onclick = function () { objekt.konecneDatum = this.konecneDatum; objekt.klikNaDen (); } week.appendChild (day); } } } this.mesice = function () { //hlavicka var objekt = this; this.datepicker.innerHTML = ''; var header = document.createElement ('div'); header.className = 'header'; this.datepicker.appendChild (header); var title = document.createElement ('div'); title.className = 'title'; header.appendChild (title); var titleText = document.createElement ('span'); titleText.className = 'titleText'; titleText.style.cursor = 'pointer'; titleText.innerHTML = this.datum.getFullYear(); titleText.onclick = function () { objekt.roky (); } title.appendChild (titleText); var previous = document.createElement ('div'); previous.className = 'previous'; previous.innerHTML = '«'; previous.onclick = function () { objekt.datum.setFullYear (objekt.datum.getFullYear () - 1); objekt.mesice (); } title.appendChild (previous); var next = document.createElement ('div'); next.className = 'next'; next.innerHTML = '»'; next.onclick = function () { objekt.datum.setFullYear (objekt.datum.getFullYear () + 1); objekt.mesice (); } title.appendChild (next); var closeButton = document.createElement ('div'); closeButton.className = 'closeButton'; closeButton.innerHTML = 'x'; closeButton.onclick = function () { objekt.zavri (); } title.appendChild (closeButton); //telo var body = document.createElement ('div'); body.className = 'body'; this.datepicker.appendChild (body); var months = document.createElement ('div'); months.className = 'months'; body.appendChild (months); var vybranyRok = this.vybraneDatum.getFullYear (); var vybranyMesic = this.vybraneDatum.getMonth (); var aktualniRok = this.aktualniDatum.getFullYear (); var aktualniMesic = this.aktualniDatum.getMonth (); for (var mesice = 0; mesice < 12; mesice++) { var dnes = ''; if (this.datum.getFullYear () == aktualniRok && mesice == aktualniMesic) dnes = ' today'; var vybrany = ''; if (this.datum.getFullYear () == vybranyRok && mesice == vybranyMesic) vybrany = ' selected'; var month = document.createElement ('div'); month.className = 'month month' + mesice + dnes + vybrany; month.innerHTML = this.nazvyMesicu[mesice].substr (0, 3); month.konecnyMesic = mesice; month.onclick = function () { objekt.datum.setMonth (this.konecnyMesic); objekt.dny (); } months.appendChild (month); } } this.roky = function () { //hlavicka var objekt = this; this.datepicker.innerHTML = ''; var pocatecniRok = this.datum.getFullYear() - (this.datum.getFullYear() % 20); var header = document.createElement ('div'); header.className = 'header'; this.datepicker.appendChild (header); var title = document.createElement ('div'); title.className = 'title'; header.appendChild (title); var titleText = document.createElement ('span'); titleText.className = 'titleText'; titleText.style.cursor = 'pointer'; titleText.innerHTML = pocatecniRok + '-' + (pocatecniRok + 19); title.appendChild (titleText); var previous = document.createElement ('div'); previous.className = 'previous'; previous.innerHTML = '«'; previous.onclick = function () { objekt.datum.setFullYear (objekt.datum.getFullYear () - 20); objekt.roky (); } title.appendChild (previous); var next = document.createElement ('div'); next.className = 'next'; next.innerHTML = '»'; next.onclick = function () { objekt.datum.setFullYear (objekt.datum.getFullYear () + 20); objekt.roky (); } title.appendChild (next); var closeButton = document.createElement ('div'); closeButton.className = 'closeButton'; closeButton.innerHTML = 'x'; closeButton.onclick = function () { objekt.zavri (); } title.appendChild (closeButton); //telo var body = document.createElement ('div'); body.className = 'body'; this.datepicker.appendChild (body); var years = document.createElement ('div'); years.className = 'years'; body.appendChild (years); var vybranyRok = this.vybraneDatum.getFullYear (); var aktualniRok = this.aktualniDatum.getFullYear (); for (var roky = 0; roky < 20; roky++) { var dnes = ''; if ((roky + pocatecniRok) == aktualniRok) dnes = ' today'; var vybrany = ''; if ((roky + pocatecniRok) == vybranyRok) vybrany = ' selected'; var year = document.createElement ('div'); year.className = 'year year' + roky + dnes + vybrany; year.innerHTML = roky + pocatecniRok; year.konecnyRok = roky + pocatecniRok; year.onclick = function () { objekt.datum.setFullYear (this.konecnyRok); objekt.mesice (); } years.appendChild (year); } } this.cas = function () { //hlavicka var objekt = this; this.datepicker.innerHTML = ''; var header = document.createElement ('div'); header.className = 'header'; this.datepicker.appendChild (header); var title = document.createElement ('div'); title.className = 'title'; header.appendChild (title); var titleText = document.createElement ('span'); titleText.className = 'titleText'; titleText.style.cursor = 'pointer'; titleText.innerHTML = this.konecneDatum.getDate () + ' ' + this.nazvyMesicu[this.konecneDatum.getMonth ()].substr (0, 3) + ', ' + this.konecneDatum.getFullYear (); title.appendChild (titleText); var closeButton = document.createElement ('div'); closeButton.className = 'closeButton'; closeButton.innerHTML = 'x'; closeButton.onclick = function () { objekt.zavri (); } title.appendChild (closeButton); //telo var body = document.createElement ('div'); body.className = 'body'; this.datepicker.appendChild (body); var time = document.createElement ('div'); time.className = 'time'; body.appendChild (time); this.hour = document.createElement ('input'); this.hour.className = 'hour'; this.hour.type = 'text'; this.hour.maxlength = 2; this.hour.value = doplnNulu (this.datum.getHours ()); time.appendChild (this.hour); this.minutes = document.createElement ('input'); this.minutes.className = 'minutes'; this.minutes.type = 'text'; this.minutes.maxlength = 2; this.minutes.value = doplnNulu (this.datum.getMinutes ()); time.appendChild (this.minutes); var separator = document.createElement ('div'); separator.className = 'separator'; separator.innerHTML = ':'; time.appendChild (separator); var ok = document.createElement ('input'); ok.className = 'ok'; ok.type = 'submit'; ok.value = 'OK'; ok.onclick = function () { objekt.konecneDatum.setHours (objekt.hour.value); objekt.konecneDatum.setMinutes (objekt.minutes.value); objekt.klikNaCas (); } time.appendChild (ok); } this.klikNaDen = function () { this.input.value = this.konecneDatum.getFullYear () + '-' + doplnNulu (this.konecneDatum.getMonth () + 1) + '-' + doplnNulu (this.konecneDatum.getDate ()); if (this.nactiCas) this.cas (); else this.zavri (); } this.klikNaCas = function () { this.input.value = this.konecneDatum.getFullYear () + '-' + doplnNulu (this.konecneDatum.getMonth () + 1) + '-' + doplnNulu (this.konecneDatum.getDate ()) + ' ' + doplnNulu (this.konecneDatum.getHours ()) + ':' + doplnNulu (this.konecneDatum.getMinutes ()); this.zavri (); } this.zavri = function () { document.body.removeChild (this.datepicker); this.zobrazeno = false; } this.zobraz = function (id, nactiCas) { this.nactiCas = nactiCas; if (this.zobrazeno) this.zavri (); this.zobrazeno = true; this.vybraneDatum = new Date (); this.aktualniDatum = new Date (); this.datum = new Date (); var objekt = this; this.input = document.getElementById (id); this.datepicker = document.createElement ('div'); this.datepicker.className = 'datepicker'; var poziceInputu = getElementAbsolutePos (this.input); this.datepicker.style.left = poziceInputu.x + this.posunX + 'px'; this.datepicker.style.top = poziceInputu.y + this.posunY + 'px'; document.body.appendChild (this.datepicker); var zadanyDatum = this.input.value.split (/\D+/); zadanyDatum[0] *= 1; zadanyDatum[1] -= 1; zadanyDatum[2] *= 1; zadanyDatum[3] *= 1; zadanyDatum[4] *= 1; var testovaciDatum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2], zadanyDatum[3], zadanyDatum[4]); if (testovaciDatum.getFullYear () == zadanyDatum[0] && testovaciDatum.getMonth () == zadanyDatum[1] && testovaciDatum.getDate () == zadanyDatum[2] && testovaciDatum.getHours () == zadanyDatum[3] && testovaciDatum.getMinutes () == zadanyDatum[4]) { this.datum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2], zadanyDatum[3], zadanyDatum[4]); this.vybraneDatum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2], zadanyDatum[3], zadanyDatum[4]); } else { var testovaciDatum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2]); if (testovaciDatum.getFullYear () == zadanyDatum[0] && testovaciDatum.getMonth () == zadanyDatum[1] && testovaciDatum.getDate () == zadanyDatum[2]) { this.datum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2], this.aktualniDatum.getHours (), this.aktualniDatum.getMinutes ()); this.vybraneDatum = new Date (zadanyDatum[0], zadanyDatum[1], zadanyDatum[2], this.aktualniDatum.getHours (), this.aktualniDatum.getMinutes ()); } } this.dny (); } this.posunY = 3; this.posunX = 215; this.nazvyMesicu = new Array ('Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'); this.nazvyDnu = new Array ('Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota', 'Neděle'); this.zobrazeno = false; };