// if two digit year input dates after this year considered 20 century. var NUM_CENTYEAR = 30; // is time input control required by default var BUL_TIMECOMPONENT = false; // are year scrolling buttons required by default var BUL_YEARSCROLL = true; var calendars = []; var RE_NUM = /^\-?\d+$/; function calendarInt(obj_target, obj_dateFormat, obj_timeFormat) { // assing methods this.gen_date = cal_gen_date1; this.gen_time = cal_gen_time1; this.gen_tsmp = cal_gen_tsmp1; this.prs_date = cal_prs_date1; this.prs_time = cal_prs_time1; this.prs_tsmp = cal_prs_tsmp1; this.cal_validate = cal_validate1; this.popup = cal_popup1; // validate input parameters if (!obj_target) return cal_error("Error calling the calendar: no target control specified"); if (obj_target.value == null) return cal_error("Error calling the calendar: parameter specified is not valid tardet control"); this.target = obj_target; this.dateFormat = obj_dateFormat; this.timeFormat = obj_timeFormat; this.time_comp = BUL_TIMECOMPONENT; this.year_scroll = BUL_YEARSCROLL; // register in global collections this.id = calendars.length; calendars[this.id] = this; } function cal_popup1 (str_datetime) { this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value); if (!this.dt_current){return;} var obj_calwindow = window.open( '/js/calendar.jsp?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id, 'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+ ',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes' ); obj_calwindow.opener = window; obj_calwindow.focus(); } // timestamp generating function function cal_gen_tsmp1 (dt_datetime) { return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime)); } // date generating function function cal_gen_date1 (dt_datetime) { return formatDate(dt_datetime, this.dateFormat); } // time generating function function cal_gen_time1 (dt_datetime) { return formatDate(dt_datetime, this.timeFormat); } // // timestamp parsing function // * use jsp when submitting calendar fields // * use date parameter if it is in correct format // function cal_validate1 (str_datetime) { // if no parameter specified return current timestamp if (!str_datetime) return (new Date()); // if positive integer treat as milliseconds from epoch if (RE_NUM.exec(str_datetime)) return new Date(str_datetime); // else treat as date in string format var tmpDate = new Date(); if (this.time_comp) { tmpDate.setTime(getDateFromFormat(str_datetime,this.dateFormat + " " + this.timeFormat)); } else { tmpDate.setTime(getDateFromFormat(str_datetime,this.dateFormat)); } if (tmpDate.getTime() == 0) { return cal_error("Invalid date format " + this.dateFormat + " " + this.timeFormat); } return tmpDate; } // // timestamp parsing function // * use in calendar control // * use date parameter if it is in correct format // * otherwise set date to today // function cal_prs_tsmp1 (str_datetime) { // if no parameter specified return current timestamp if (!str_datetime) return (new Date()); // if positive integer treat as milliseconds from epoch if (RE_NUM.exec(str_datetime)) return new Date(str_datetime); // else treat as date in string format return this.prs_date(str_datetime); } // // date parsing function // * use in calendar control // * use date parameter if it is in correct format // * otherwise set date to today // function cal_prs_date1 (str_date) { if (!str_date) return null; var tmpDate = new Date(); var timeComponent = getDateFromFormat(str_date,this.dateFormat + " " + this.timeFormat); if (this.time_comp && timeComponent > 0) { tmpDate.setTime(timeComponent); } else { var dateComponent = getDateFromFormat(str_date,this.dateFormat); if (dateComponent > 0 ) { tmpDate.setTime(dateComponent); } } return tmpDate; } // // time parsing function // * use in calendar control // * use time parameter if it is in correct format // * otherwise set date to today // function cal_prs_time1 (str_time, dt_date) { if (!dt_date) return null; var tmpDate = new Date(); tmpDate = dt_date; if (str_time!='') { tmpDate.setTime(getDateFromFormat(formatDate(dt_date, "dd.MM.yyyy") + " " + str_time, "dd.MM.yyyy " + this.timeFormat)); } if (tmpDate.getTime() == 0) { return cal_error("Invalid date format"); } return tmpDate; } function cal_error (str_message) { alert (str_message); return null; }