var mode = 'start'; var starttd = ''; var endtd = ''; var lastFormEntry; function switchCalendar(id) { document.getElementById("calendar2025").style.display = "none"; document.getElementById("calendar2024").style.display = "none"; document.getElementById("link2025").style.color = "#000000"; document.getElementById("link2024").style.color = "#000000"; document.getElementById('calendar' + id).style.display = 'block'; document.getElementById('link' + id).style.color = '#dd0000'; } function makeCalendarActive(Year) { for(i = 1; i <= 12; i++) { for(j = 1; j <= 38; j++) { td = document.getElementById('d' + j + '.' + i + '.' + Year); //alert(td); if(td) { //alert (i +' ' + j); td.onmouseover = function() { // funkcja podswietlajaca na czerwono nazwy dni jak sie najedzie myszka if(this.className == 'day_reserved' || this.className == 'weekend_reserved') this.style.color = '#ffffff'; else this.style.color = '#ff0000'; idx = this.id.indexOf('.'); my = this.id.substring(idx+1, this.id.length); d = this.id.substring(1, idx); idx=my.indexOf('.'); m=my.substring(0,idx); y=my.substring(idx+1,my.length); //alert('m ' + m); //alert('d ' + d); //alert('y ' + y); //alert(d+'.'+m+'.'+y); //x = document.getElementById('d' + realYear(m) + '_' + d); //if(x.style.color == '#ff0000') // x.style.color = '#ff0001'; //else // x.style.color = '#ff0000'; //document.getElementById('m' + m).style.color = '#ff0000'; } td.onmouseout = function() {// funkcja zmieniajaca na czarno nazwy dni jak kursor z nich zjezdza this.style.color = '#000000'; idx = this.id.indexOf('.'); my = this.id.substring(idx+1, this.id.length); d = this.id.substring(1, idx); idx=my.indexOf('.'); m=my.substring(0,idx); y=my.substring(idx+1,my.length); //x = document.getElementById('d' + realYear(m) + '_' + d); //if(x.style.color == '#ff0001') // x.style.color = '#ff0000'; //else // x.style.color = '#000000'; //document.getElementById('m' + m).style.color = '#000000'; } if(td.className == 'day_selected' || td.className == 'weekend_selected') { td.onmouseover = function() { document.getElementById('si' + this.id).style.display = 'block'; } td.onmouseout = function() { document.getElementById('si' + this.id).style.display = 'none'; } } if(td.className != 'day_selected' && td.className != 'day_reserved' && td.className != 'weekend_selected' && td.className != 'weekend_reserved' && td.className != 'day_reserved_selected' && td.className != 'day_selected_reserved' && td.className != 'weekend_reserved_selected' && td.className != 'weekend_selected_reserved') { td.style.cursor = 'hand'; td.onclick = function() { //alert('przed mode'); if(mode == 'stop') { // Zaznaczamy jesli ktos nie kliknal 2x w to samo pole if(starttd != this.id) { endtd = this.id; //alert(mode); selectCalendar(true, starttd, endtd); mode = 'start'; } } else { // mode == start this.style.backgroundColor=''; this.className += '_clicked'; //alert(mode); // Usuwanie poprzedniego zaznaczenia clearCalendar(true); mode = 'stop'; starttd = this.id; endtd = ''; } } } } } } } function selectCalendar(useForm, start, end) { //alert('select'); if(start == '' || end == '') { //alert('niestety nie udalo sie'); return; } // disableForm(true); // Rozbijamy id //idx = start.indexOf('x'); //startd = parseInt(start.substring(idx+1, start.length)); //startm = parseInt(start.substring(0, idx)); idx = start.indexOf('.'); my = start.substring(idx+1, start.length); d = parseInt(start.substring(1, idx)); idx=my.indexOf('.'); m=parseInt(my.substring(0,idx)); y=parseInt(my.substring(idx+1,my.length)); startd=d; startm=m; starty=y; //idx = end.indexOf('x'); //endd = parseInt(end.substring(idx+1, end.length)); //endm = parseInt(end.substring(0, idx)); idx = end.indexOf('.'); my = end.substring(idx+1, end.length); d = parseInt(end.substring(1, idx)); idx=my.indexOf('.'); m=parseInt(my.substring(0,idx)); y=parseInt(my.substring(idx+1,my.length)); endd=d; endm=m; endy=y; //alert('endd:'+endd+'=='+'startd:'+startd); // Sprawdzamy czy zaznaczamy w przod czy w tyl if((starty > endy) || (starty == endy && endm < startm) || (startm == endm && endd < startd)) { back = true; //alert('back'); } else back = false; // Zmienne tymczasowe do petli tempd = startd; tempm = startm; tempy = starty; if((document.getElementById('d' + startd + '.' + startm + '.' + starty).className.indexOf('_first', 0) != -1 && back == false) || (document.getElementById('d' + startd + '.' + startm + '.' + starty).className.indexOf('_last', 0) != -1 && back == true)) { return; } do { // Inkrementujemy lub dekrementujemy date if(back == false) { if(tempm < 12) { if(tempd < 31) { //alert('back=false, tempd='+tempd); tempd++; } else { //alert('back=false, tempd='+tempd); tempd = 1; tempm++; } } else { if(tempd < 31) { //alert('back=false, tempd='+tempd); tempd++; } else { //alert('back=false, tempd='+tempd); tempd = 1; tempm = 1; tempy++; } } } else { if (tempm > 1) { if(tempd > 1) { //alert('back=true, tempd='+tempd); tempd--; } else { //alert('back=true, tempd='+tempd); tempd = 31; tempm--; } } else { if(tempd > 1) { //alert('back=true, tempd='+tempd); tempd--; } else { //alert('back=true, tempd='+tempd); tempd = 31; tempm = 12; tempy--; } } } // Pobieramy komorke tabeli td = document.getElementById('d' + tempd + '.' + tempm + '.' + tempy); if(td) { td.style.backgroundColor=''; td.className += '_clicked'; //alert('dotad doszlismy'); // Jesli natrafimy na istniejaca rezerwacje... if(td.className.indexOf('_reserved', 0) != -1 || td.className.indexOf('_selected', 0) != -1) { //idx = td.id.indexOf('.'); //endm = parseInt(td.id.substring(0, idx)); idx = td.id.indexOf('.'); my = td.id.substring(idx+1, td.id.length); //d = end.id.substring(1, idx); idx=td.id.indexOf('.'); endm=parseInt(my.substring(0,idx)); //y=my.substring(idx+1,my.length); //alert('rez'); break; } tdid = td.id; //alert(tdid + '=' + td.id); } else { tdid = 'd0.0.'+ starty; } } while(end != tdid); endtd = 'd' + tempd + '.' + tempm + '.' + tempy; starttd = start; // Jesli do tylu to odwracamy daty if(back == true) { temp = endd; endd = startd; startd = temp; temp = endm; endm = startm; startm = temp; temp = endtd; endtd = starttd; starttd = temp; temp = endy; endy=starty; starty=temp; } if(useForm == true) { // Wpisujemy wartosci do formularza tmp_starttd=document.getElementById(starttd); idx = starttd.indexOf('.'); d = parseInt(starttd.substring(1, idx)); document.reservation_form.start_d.value = d; document.reservation_form.start_m.value = startm; document.reservation_form.start_y.value = starty; tmp_endtd=document.getElementById(endtd); idx = endtd.indexOf('.'); d = parseInt(endtd.substring(1, idx)); document.reservation_form.end_d.value = d; document.reservation_form.end_m.value = endm; document.reservation_form.end_y.value = endy; } //alert('almost good'); // disableForm(false); } function clearCalendar(clearForm) { //alert("clear calendar"); if(starttd != '' && endtd != '') { if(clearForm == true) { document.reservation_form.start_d.value = ''; document.reservation_form.start_m.value = ''; document.reservation_form.start_y.value = ''; document.reservation_form.end_d.value = ''; document.reservation_form.end_m.value = ''; document.reservation_form.end_y.value = ''; } //idx = starttd.indexOf('x'); //startd = starttd.substring(idx+1, starttd.length); //startm = starttd.substring(0, idx); idx = starttd.indexOf('.'); my = starttd.substring(idx+1, starttd.length); d = parseInt(starttd.substring(1, idx)); idx=my.indexOf('.'); m=parseInt(my.substring(0,idx)); y=parseInt(my.substring(idx+1,my.length)); startd=d; startm=m; starty=y; //idx = endtd.indexOf('x'); //endd = endtd.substring(idx+1, endtd.length); //endm = endtd.substring(0, idx); idx = endtd.indexOf('.'); my = endtd.substring(idx+1, endtd.length); d = parseInt(endtd.substring(1, idx)); idx=my.indexOf('.'); m=parseInt(my.substring(0,idx)); y=parseInt(my.substring(idx+1,my.length)); endd=d; endm=m; endy=y; tempd = startd; tempm = startm; tempy = starty; do { td = document.getElementById('d' + tempd + '.' + tempm + '.' + tempy); if(td) { td.className = td.className.replace('_clicked', ''); //td.style.backgroundColor=''; tdid = td.id; } else { tdid = 'd0.0.'+ starty; } if(tempm < 12) { if(tempd < 31) { tempd++; } else { tempd = 1; tempm++; } } else { if(tempd < 31) { tempd++; } else { tempd = 1; tempm = 1; tempy++; } } } while(endtd != tdid); starttd = ''; endtd = ''; } } function hideCalendar(Year) { document.getElementById("calendar"+(Year+1)).style.display = "none"; } function makeSubmit() { // document.reservation.ok.type = 'button'; } function start(Year) { makeCalendarActive(Year); makeCalendarActive((Year+1)); makeSubmit(); }