// CalendarTextBox
// Portions © SoftComplex - http://www.softcomplex.com
// MWLibrary adaptation by SSe
var NUM_CENTYEAR = 30;
var BUL_YEARSCROLL = true;
var RE_DATE = /^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d)?\d{2}))$/;
var RE_DOUBLE = /^\-?\d+$/;
var calendars = [];
function calendar1(obj_target) {
this.gen_date = cal_gen_date1;
this.prs_date = cal_prs_date1;
this.popup    = cal_popup1;
if (!obj_target || obj_target.value == null) return cal_error("CalendarTextBox : Invalid call!");
this.target = obj_target;
this.year_scroll = BUL_YEARSCROLL;
this.id = calendars.length;
calendars[this.id] = this;	}
function cal_popup1 (str_datetime) {
this.dt_current = this.prs_date(str_datetime ? str_datetime : this.target.value);
if (!this.dt_current) return;
var obj_calwindow = window.open(
'',
'CalendarTextBox', 'width=200,height=180,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
);
obj_calwindow.document.clear();
obj_calwindow.document.write('<html><head><title>Calendrier<\/title>');
obj_calwindow.document.write('<script>');
obj_calwindow.document.write('var ARR_WEEKDAYS = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"];');
obj_calwindow.document.write('var ARR_MONTHS = ["Janvier", "F&eacute;vrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Ao&ucirc;t", "Septembre", "Octobre", "Novembre", "D&eacute;cembre"];');
obj_calwindow.document.write('var NUM_WEEKSTART = 1;');
obj_calwindow.document.write('var STR_ICONPATH = \'/img/\';');
obj_calwindow.document.write('var re_url = new RegExp(\'datetime=(\\-?\\d+)\');');
obj_calwindow.document.write('var dt_current = new Date(' + this.dt_current.valueOf() + ');');
obj_calwindow.document.write('var re_id = new RegExp(\'id=(\\d+)\');');
obj_calwindow.document.write('var num_id = new Number(' + this.id + ');');
obj_calwindow.document.write('var obj_caller = (window.opener ? window.opener.calendars[num_id] : null);');
obj_calwindow.document.write('if (obj_caller && obj_caller.year_scroll) {');
obj_calwindow.document.write('var dt_prev_year = new Date(dt_current);');
obj_calwindow.document.write('dt_prev_year.setFullYear(dt_prev_year.getFullYear() - 1);');
obj_calwindow.document.write('if (dt_prev_year.getDate() != dt_current.getDate()) dt_prev_year.setDate(0);');
obj_calwindow.document.write('var dt_next_year = new Date(dt_current);');
obj_calwindow.document.write('dt_next_year.setFullYear(dt_next_year.getFullYear() + 1);');
obj_calwindow.document.write('if (dt_next_year.getDate() != dt_current.getDate()) dt_next_year.setDate(0);');
obj_calwindow.document.write('}');
obj_calwindow.document.write('var dt_prev_month = new Date(dt_current);');
obj_calwindow.document.write('dt_prev_month.setMonth(dt_prev_month.getMonth() - 1);');
obj_calwindow.document.write('if (dt_prev_month.getDate() != dt_current.getDate()) dt_prev_month.setDate(0);');
obj_calwindow.document.write('var dt_next_month = new Date(dt_current);');
obj_calwindow.document.write('dt_next_month.setMonth(dt_next_month.getMonth() + 1);');
obj_calwindow.document.write('if (dt_next_month.getDate() != dt_current.getDate()) dt_next_month.setDate(0);');
obj_calwindow.document.write('var dt_firstday = new Date(dt_current);');
obj_calwindow.document.write('dt_firstday.setDate(1);');
obj_calwindow.document.write('dt_firstday.setDate(1 - (7 + dt_firstday.getDay() - NUM_WEEKSTART) % 7);');
obj_calwindow.document.write('function set_datetime(n_datetime, b_close) {');
obj_calwindow.document.write('if (!obj_caller) return;');
obj_calwindow.document.write('var dt_datetime = new Date(n_datetime);');
obj_calwindow.document.write('if (!dt_datetime) return;');
obj_calwindow.document.write('if (b_close) {');
obj_calwindow.document.write('window.close();');
obj_calwindow.document.write('obj_caller.target.value = (document.cal');
obj_calwindow.document.write('? obj_caller.gen_tsmp(dt_datetime)');
obj_calwindow.document.write(': obj_caller.gen_date(dt_datetime)');
obj_calwindow.document.write(');');
obj_calwindow.document.write('obj_caller.target.focus();');
obj_calwindow.document.write('}');
obj_calwindow.document.write('else obj_caller.popup(dt_datetime.valueOf());');
obj_calwindow.document.write('}');
obj_calwindow.document.write('<\/script>');
obj_calwindow.document.write('<\/head>');
obj_calwindow.document.write('<body><table cellspacing="0" border="0" width="100%" ID="Table1">');
obj_calwindow.document.write('<tr><td class=YearHeader>');
obj_calwindow.document.write('<table cellspacing="1" cellpadding="3" border="0" width="100%" ID="Table2">');
obj_calwindow.document.write('<tr><td colspan="7"><table cellspacing="0" cellpadding="0" border="0" width="100%" ID="Table3">');
obj_calwindow.document.write('<tr><script>');
obj_calwindow.document.write('document.write(');
obj_calwindow.document.write('\'<td>\'+(obj_caller&&obj_caller.year_scroll?\'<a href="javascript:set_datetime(\'+dt_prev_year.valueOf()+\')"><img src="\'+STR_ICONPATH+\'prev_year.gif" width="16" height="16" border="0" alt="<<"><\/a>&nbsp;\':\'\')+\'<a href="javascript:set_datetime(\'+dt_prev_month.valueOf()+\')"><img src="\'+STR_ICONPATH+\'prev.gif" width="16" height="16" border="0" alt="<"><\/a><\/td>\'+');
obj_calwindow.document.write('\'<td class=YearHeader align="center" width="100%">\'+ARR_MONTHS[dt_current.getMonth()]+\' \'+dt_current.getFullYear() + \'<\/td>\'+');
obj_calwindow.document.write('\'<td><a href="javascript:set_datetime(\'+dt_next_month.valueOf()+\')"><img src="\'+STR_ICONPATH+\'next.gif" width="16" height="16" border="0" alt=">"><\/a>\'+(obj_caller && obj_caller.year_scroll?\'&nbsp;<a href="javascript:set_datetime(\'+dt_next_year.valueOf()+\')"><img src="\'+STR_ICONPATH+\'next_year.gif" width="16" height="16" border="0" alt=">>"><\/a>\':\'\')+\'<\/td>\'');
obj_calwindow.document.write(');');
obj_calwindow.document.write('<\/script><\/tr><\/table><\/td><\/tr><tr><script>');
obj_calwindow.document.write('for (var n=0; n<7; n++)');
obj_calwindow.document.write('document.write(\'<td class=WeekHeader align="center">\'+ARR_WEEKDAYS[(NUM_WEEKSTART+n)%7]+\'<\/td>\');');
obj_calwindow.document.write('document.write(\'<\/tr>\');');
obj_calwindow.document.write('var dt_current_day = new Date(dt_firstday);');
obj_calwindow.document.write('while (dt_current_day.getMonth() == dt_current.getMonth() ||');
obj_calwindow.document.write('dt_current_day.getMonth() == dt_firstday.getMonth()) {');
obj_calwindow.document.write('document.write(\'<tr>\');');
obj_calwindow.document.write('for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {');
obj_calwindow.document.write('if (dt_current_day.getDate() == dt_current.getDate() &&');
obj_calwindow.document.write('dt_current_day.getMonth() == dt_current.getMonth())');
obj_calwindow.document.write('document.write(\'<td class=SelectedItem align="center" width="14%">\');');
obj_calwindow.document.write('else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)');
obj_calwindow.document.write('document.write(\'<td class=WeekEndItem align="center" width="14%">\');');
obj_calwindow.document.write('else ');
obj_calwindow.document.write('document.write(\'<td class=WeekItem align="center" width="14%">\');');
obj_calwindow.document.write('document.write(\'<a href="javascript:set_datetime(\'+dt_current_day.valueOf() +\', true);">\');');
obj_calwindow.document.write('if (dt_current_day.getMonth() == this.dt_current.getMonth())');
obj_calwindow.document.write('document.write(\'<span class=CurrentMonth>\');');
obj_calwindow.document.write('else ');
obj_calwindow.document.write('document.write(\'<span class=OtherMonth>\');');
obj_calwindow.document.write('document.write(dt_current_day.getDate()+\'<\/font><\/a><\/td>\');');
obj_calwindow.document.write('dt_current_day.setDate(dt_current_day.getDate()+1);');
obj_calwindow.document.write('}');
obj_calwindow.document.write('document.write(\'<\/tr>\');');
obj_calwindow.document.write('}');
obj_calwindow.document.write('<\/script><\/table><\/tr><\/td><\/table><\/body><\/html>');
obj_calwindow.document.write('<link rel=stylesheet href=/css/sccalendartextbox.css>');
obj_calwindow.document.close();
obj_calwindow.opener = window;
obj_calwindow.focus();	}
function cal_gen_date1 (dt_datetime) {	return ((dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "/" + (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "/" + dt_datetime.getFullYear()); }
function cal_prs_date1 (str_date) {
if (!str_date) return (new Date());
if (RE_DOUBLE.exec(str_date)) return new Date(str_date);
if (!RE_DATE.exec(str_date))return cal_error("Veuillez saisir une date valide au format jj/MM/aaaa");
var arr_date = str_date.split('/');
var dt_date = new Date();
if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
dt_date.setFullYear(arr_date[2]);
dt_date.setMonth(arr_date[1]-1);
dt_date.setDate(arr_date[0]);
return (dt_date)	}
function cal_error (str_message) { alert (str_message); return null; }