// Datos pasirinkimo funkcija function show_calendar(target_input, date_value) { // Menesiai var months = ["Sausis", "Vasaris", "Kovas", "Balandis", "Gegužė", "Birželis", "Liepa", "Rugpjūtis", "Rugsėjis", "Spalis", "Lapkritis", "Gruodis"]; // Savaites dienos var weekdays = ["Sek", "Pir", "Ant", "Tre", "Ket", "Pen", "Šeš"]; // Savaites pradzia (1 - pirmadienis) var weekstart = 1; // Nuoroda "Isvalyti" var link_clear = "Išvalyti"; // Nuoroda "Siandien" var link_today = "Šiandien"; // Neteisingos datos pranesimas var alert_msg = "Neteisingas datos formatas: "; var datetime = (date_value == null || date_value == "" ? new Date() : get_date_value(date_value, alert_msg)); var prev_month = new Date(datetime); prev_month.setMonth(datetime.getMonth() - 1); var next_month = new Date(datetime); next_month.setMonth(datetime.getMonth() + 1); var firstday = new Date(datetime); firstday.setDate(1); firstday.setDate(1 - (7 + firstday.getDay() - weekstart) % 7); var dt_lastday = new Date(next_month); dt_lastday.setDate(0); var today = new Date(); today = new String (today.getFullYear() + "-" + addZero(today.getMonth() + 1) + "-" + addZero(today.getDate())); // Puslapio HTML kodo pradzia var output = new String ( "\n" + "\n" + "\n" + "Kalendorius\n" + "\n" + "\n" + "\n" + "
\n" ); // Kalendoriaus lenteles pradzia output += "\n" + "\n" + "\n" + "\n" + "\n"+ "\n"; var current_day = new Date(firstday); // Savaites dienu eilute output += "\n"; for (var n = 0; n < 7; n ++) { output += "\n"; } output += "\n"; // Kalendoriaus lentele while (current_day.getMonth() == datetime.getMonth() || current_day.getMonth() == firstday.getMonth()) { // Savaites dienu eilute output += "\n"; for (var n_current_wday = 0; n_current_wday < 7; n_current_wday ++) { // Pasirinktos dienos langelis if (current_day.getDate() == datetime.getDate() && current_day.getMonth() == datetime.getMonth()) { output += "\n"; current_day.setDate(current_day.getDate() + 1); } output += "\n"; } // Nuoroda "Isvalyti" ir "Siandien" output += "\n" + "\n"+ "\n"+ "\n"+ "\n"; // Kalendoriaus lenteles ir HTML kodo pabaiga output += "
\n" + "<<\n" + "\n" + "" + months[datetime.getMonth()] + " " + datetime.getFullYear() + "\n" + "\n" + ">>\n" + "
\n" + weekdays[(weekstart + n) % 7] + "\n" + "
\n"; } // Savaitgaliu langeliai else if (current_day.getDay() == 0 || current_day.getDay() == 6) { output += "\n"; } // Kitu dienu langeliai else { output += "\n"; } // Sio menesio dienu nuorodos if (current_day.getMonth() == datetime.getMonth()) { output += "\n"; } // Kito menesio dienu nuorodos else { output += "\n"; } output += current_day.getDate() + "
\n" + "" + link_clear + "\n" + "\n" + " \n"+ "\n" + "" + link_today + "\n" + "
\n" + "
\n" + "\n" + "\n"; var CalendarWindow = window.open("", "Calendar", "width=210,height=190,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=250,left=250"); CalendarWindow.opener = self; var CalendarDocument = CalendarWindow.document; CalendarDocument.write(output); CalendarDocument.close(); } // Is laukelio gautos datos reiksmes tikrinimas function get_date_value(date_value, alert_msg) { var reg_date = /^(\d+)\-(\d+)\-(\d+)$/; if (!reg_date.exec(date_value)) { return alert(alert_msg + date_value); } else { return (new Date (RegExp.$1, RegExp.$2 - 1, RegExp.$3)); } } // Datos perdavimas laukeliui function return_date_value(datetime) { return (new String (datetime.getFullYear() + "-" + addZero(datetime.getMonth() + 1) + "-" + addZero(datetime.getDate()))); } // 0 pridejimas prie vienzenklio menesio arba savaites dienos function addZero(str) { str = str + ''; if (str.length == 1) { return '0' + str; } else { return str; } }