function show_calendar(str_target, str_date) { var arr_months = ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"]; var week_days = ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"]; var n_weekstart = 1; if (str_date != null && str_date != "") { if (str2dt2(str_date) == false) { alert("Неверный формат даты: "+str_date); return; } } var dt_date = (str_date == null || str_date =="" ? new Date() : str2dt2(str_date)); var dt_prev_month = new Date(dt_date); dt_prev_month.setMonth(dt_date.getMonth()-1); if (dt_date.getMonth()%12 != (dt_prev_month.getMonth()+1)%12) { dt_prev_month.setMonth(dt_date.getMonth()); dt_prev_month.setDate(0); } var dt_prev_year = new Date(dt_date); dt_prev_year.setMonth(dt_date.getMonth()-12); var dt_next_month = new Date(dt_date); dt_next_month.setMonth(dt_date.getMonth()+1); if ((dt_date.getMonth() + 1)%12 != dt_next_month.getMonth()%12) dt_next_month.setDate(0); var dt_next_year = new Date(dt_date); dt_next_year.setMonth(dt_date.getMonth()+12); var dt_firstday = new Date(dt_date); dt_firstday.setDate(1); dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7); var dt_lastday = new Date(dt_next_month); dt_lastday.setDate(0); var str_buffer = new String ( "\n"+ "\n"+ "\n"+ " Выбор даты\n"+ "\n"+ "\n"+ "\n"+ "\n\n"+ "\n"+ "\n\n" ); var dt_current_day = new Date(dt_firstday); str_buffer += "\n"; for (var n=0; n<7; n++) str_buffer += "\n"; str_buffer += "\n"; while (dt_current_day.getMonth() == dt_date.getMonth() || dt_current_day.getMonth() == dt_firstday.getMonth()) { str_buffer += "\n"; for (var n_current_wday=0; n_current_wday<7; n_current_wday++) { if (dt_current_day.getDate() == dt_date.getDate() && dt_current_day.getMonth() == dt_date.getMonth()) str_buffer += " \n"; dt_current_day.setDate(dt_current_day.getDate()+1); } str_buffer += "\n"; } str_buffer += ""; str_buffer += "
«  "+ "<" +arr_months[dt_date.getMonth()]+" "+dt_date.getFullYear()+""+ ">  »
"+ week_days[(n_weekstart+n)%7]+"
"; else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6) str_buffer += " "; else str_buffer += " "; if (dt_current_day.getMonth() == dt_date.getMonth()) str_buffer += ""+ ""; else str_buffer += ""+ ""; str_buffer += dt_current_day.getDate()+"
Текущая дата: "+dt2dtstr2(new Date())+"
\n" + "\n" + "\n"; var vWinCal = window.open("", "Calendar", "width=240,height=180,status=no,resizable=no,top=200,left=200"); vWinCal.opener = self; vWinCal.focus(); var calc_doc = vWinCal.document; calc_doc.write (str_buffer); calc_doc.close(); } function str2dt2 (str_date) { var re_date = /^(\d+)\.(\d+)\.(\d+)$/; if (!re_date.exec(str_date)) { return (false); } else { var arrD = new Array(); var m, d, Y; arrD = str_date.split("."); d = parseInt(correct_number(arrD[0])); m = parseInt(correct_number(arrD[1])) - 1; Y = parseInt(arrD[2]); return (new Date(Y, m, d)); //return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1)); } } function dt2dtstr2 (dt_date) { var bday, bmonth; bday = dt_date.getDate().toString(); bmonth = (dt_date.getMonth()+1).toString(); if (bmonth.length == 1) { bmonth = "0" + bmonth; } if (bday.length == 1) { bday = "0" + bday; } return (new String ( bday+"."+bmonth+"."+dt_date.getFullYear())); } function correct_number(strIn) { var res; if (strIn.length = 2 && (strIn.substr(0, 1) == '0')) { res = strIn.substr(1, 1); } else { res = strIn; } return (res); }