/** * Filename.......: calendar.js * Project........: Popup Calendar * Last Modified..: $Date: 2002/07/22 18:17:05 $ * CVS Revision...: $Revision: 1.2 $ * Copyright......: 2001, 2002 Richard Heyes */ /** * Global variables */ dynCalendar_layers = new Array(); dynCalendar_mouseoverStatus = false; dynCalendar_mouseX = 0; dynCalendar_mouseY = 0; /** * The calendar constructor * * @access public * @param string objName Name of the object that you create * @param string callbackFunc Name of the callback function * @param string OPTIONAL Optional layer name * @param string OPTIONAL Optional images path */ function dynCalendar(objName, callbackFunc) { /** * Properties */ // Todays date this.today = new Date(); this.date = this.today.getDate(); this.month = this.today.getMonth(); this.year = this.today.getFullYear(); this.objName = objName; this.callbackFunc = callbackFunc; this.CcallbackFunc = null ; this.ClosecallbackFunc = null; this.imagesPath = arguments[2] ? arguments[2] : 'images/'; this.layerID = arguments[3] ? arguments[3] : 'dynCalendar_layer_' + dynCalendar_layers.length; this.offsetX = 5; this.offsetY = 5; this.useMonthCombo = true; this.useYearCombo = true; this.yearComboRange = 10; this.yearComboRangeUp = 10; this.currentMonth = this.month; this.currentYear = this.year; /** * Public Methods */ this.show = dynCalendar_show; this.writeHTML = dynCalendar_writeHTML; this.close = dynCalendar_close; this.cancel = dynCalendar_cancel; this.callback = dynCalendar_callback; this.setLayerPositionNear = dynCalendar_setLayerPositionNear; this.setLayerPositionStatic = dynCalendar_setLayerStaticPosition // Accessor methods this.defyears = defyears; this.setOffset = dynCalendar_setOffset; this.setOffsetX = dynCalendar_setOffsetX; this.setOffsetY = dynCalendar_setOffsetY; this.setImagesPath = dynCalendar_setImagesPath; this.setMonthCombo = dynCalendar_setMonthCombo; this.setYearCombo = dynCalendar_setYearCombo; this.setCurrentMonth = dynCalendar_setCurrentMonth; this.setCurrentYear = dynCalendar_setCurrentYear; this.setYearComboRange = dynCalendar_setYearComboRange; /** * Private methods */ // Layer manipulation this._getLayer = dynCalendar_getLayer; this._hideLayer = dynCalendar_hideLayer; this._showLayer = dynCalendar_showLayer; this._setLayerPosition = dynCalendar_setLayerPosition; this._setHTML = dynCalendar_setHTML; // Miscellaneous this._getDaysInMonth = dynCalendar_getDaysInMonth; //this._mouseover = dynCalendar_mouseover; /** * Constructor type code */ dynCalendar_layers[dynCalendar_layers.length] = this; //this.writeHTML(); } /** * Shows the calendar, or updates the layer if * already visible. * * @access public * @param integer month Optional month number (0-11) * @param integer year Optional year (YYYY format) */ function dynCalendar_show() { // Variable declarations to prevent globalisation var month, year, monthnames, numdays, thisMonth, firstOfMonth; var ret, row, i, cssClass, linkHTML, previousMonth, previousYear; var nextMonth, nextYear, prevImgHTML, prevLinkHTML, nextImgHTML, nextLinkHTML; var monthComboOptions, monthCombo, yearComboOptions, yearCombo, html; this.currentMonth = month = arguments[0] != null ? arguments[0] : this.currentMonth; this.currentYear = year = arguments[1] != null ? arguments[1] : this.currentYear; monthnames = new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Decembre'); daynames = new Array('Lun','Mar','Mer','Jeu','Ven','Sam','Dim'); numdays = this._getDaysInMonth(month, year); thisMonth = new Date(year, month, 1); firstOfMonth = thisMonth.getDay(); if( ( this.nbr!=undefined ) && ( this.nbr!='' ) ){ this.yearComboRange = this.nbr; this.yearComboRangeUp = this.max; } if((this.sel!='')&&(this.sel!=undefined)){ this.yearComboSelected = thisMonth.getFullYear()-20; }else{ this.yearComboSelected = thisMonth.getFullYear(); } // First few blanks up to first day ret = new Array(new Array()); // Modification du premier jour si premier jour est un dimanche var premierjour = 0; if ( firstOfMonth == 0 ){ premierjour = 7; }else{ premierjour = firstOfMonth; } for(i=1; i this.date && month >= this.month && year >= this.year ) || ( month > this.month && year >= this.year ) || ( year > this.year ) ){ linkHTML = '' + (i++) + ''; cssClass = ( cssClass == '' )? 'VEL_Recherche_Calendar_jour' : cssClass; }else{ linkHTML = '' + (i++) + ''; cssClass = ( cssClass == '' )? 'VEL_Recherche_Calendar_jour_pas' : cssClass; } //linkHTML = '' + (i++) + ''; ret[row][ret[row].length] = '' + linkHTML + ''; } // Format the HTML for(i=0; i 11){ nextMonth = 0; nextYear++; } if ( ( previousMonth >= this.month && previousYear >= this.year ) || previousYear > this.year ){ prevImgHTML = ''; prevLinkHTML = '' + prevImgHTML + ''; }else{ prevImgHTML = ''; prevLinkHTML = ''; } nextImgHTML = ''; nextLinkHTML = '' + nextImgHTML + ''; closeLinkHTML = ''; cancelLinkHTML = '' + 'Meilleur prix ' + ''; /** * Build month combo */ if (this.useMonthCombo) { monthComboOptions = ''; for (i=0; i<12; i++) { selected = (i == thisMonth.getMonth() ? 'selected="selected"' : ''); monthComboOptions += ''; } monthCombo = ''; } else { monthCombo = monthnames[thisMonth.getMonth()]; } /** * Build year combo */ if (this.useYearCombo) { yearComboOptions = ''; for (i = thisMonth.getFullYear() - this.yearComboRange; i <= (thisMonth.getFullYear() + this.yearComboRangeUp); i++) { selected = (i == this.yearComboSelected ? 'selected="selected"' : ''); yearComboOptions += ''; } yearCombo = ''; } else { yearCombo = thisMonth.getFullYear(); } html = ''; // html += ''; html += ''; html += ''; html += ''; for (c=0; c<7;++c ){ html += ''; } html += ''; html += ''; html += '' + ret.join('\n') + ''; html += ''; html += ''; html += '
' + prevLinkHTML + '' + yearCombo + '' + monthCombo + '' + nextLinkHTML + ''+ closeLinkHTML+'
  ' + closeLinkHTML + '
' + prevLinkHTML + '' + monthCombo + ' ' + yearCombo + ''+ nextLinkHTML + '
' + daynames[c] + '
' + cancelLinkHTML + '
'; this._setHTML(html); if (!arguments[0] && !arguments[1]) { this._showLayer(); this._setLayerPosition(); } } /* Appelle la fonction de callback */ function dynCalendar_callback(jour,moi,annee){ this._hideLayer(); if (this.callbackFunc != null ){ this.callbackFunc(jour,moi,annee); } this.callbackFunc = null; } function dynCalendar_cancel(){ this._hideLayer(); if (this.CcallbackFunc != null ){ this.CcallbackFunc(); } this.CcallbackFunc = null; } /** */ function dynCalendar_close(){ this.callbackFunc = null; if (this.ClosecallbackFunc != null ){ this.ClosecallbackFunc(); } this.CcallbackFunc = null; this._hideLayer(); } /** * Writes HTML to document for layer * * @access public */ function dynCalendar_writeHTML() { /*if (is_ie5up || is_nav6up || is_gecko) { document.write(''); document.write('
'); } */ } /** * Sets the offset to the mouse position * that the calendar appears at. * * @access public * @param integer Xoffset Number of pixels for vertical * offset from mouse position * @param integer Yoffset Number of pixels for horizontal * offset from mouse position */ function dynCalendar_setOffset(Xoffset, Yoffset) { this.setOffsetX(Xoffset); this.setOffsetY(Yoffset); } /** * Sets the X offset to the mouse position * that the calendar appears at. * * @access public * @param integer Xoffset Number of pixels for horizontal * offset from mouse position */ function dynCalendar_setOffsetX(Xoffset) { this.offsetX = Xoffset; } /** * Sets the Y offset to the mouse position * that the calendar appears at. * * @access public * @param integer Yoffset Number of pixels for vertical * offset from mouse position */ function dynCalendar_setOffsetY(Yoffset) { this.offsetY = Yoffset; } /** * Sets the images path * * @access public * @param string path Path to use for images */ function dynCalendar_setImagesPath(path) { this.imagesPath = path; } /** * Turns on/off the month dropdown * * @access public * @param boolean useMonthCombo Whether to use month dropdown or not */ function dynCalendar_setMonthCombo(useMonthCombo) { this.useMonthCombo = useMonthCombo; } /** * Turns on/off the year dropdown * * @access public * @param boolean useYearCombo Whether to use year dropdown or not */ function dynCalendar_setYearCombo(useYearCombo) { this.useYearCombo = useYearCombo; } /** * Sets the current month being displayed * * @access public * @param boolean month The month to set the current month to */ function dynCalendar_setCurrentMonth(month) { this.currentMonth = month; } /** * Sets the current month being displayed * * @access public * @param boolean year The year to set the current year to */ function dynCalendar_setCurrentYear(year) { this.currentYear = year; } /** * Sets the range of the year combo. Displays this number of * years either side of the year being displayed. * * @access public * @param integer range The range to set */ function dynCalendar_setYearComboRange(range) { this.yearComboRange = range; } /** * Returns the layer object * * @access private */ function dynCalendar_getLayer() { var layerID = this.layerID; if (document.getElementById(layerID)) { return document.getElementById(layerID); } else if (document.all(layerID)) { return document.all(layerID); } } /** * Hides the calendar layer * * @access private */ function dynCalendar_hideLayer() { this._getLayer().style.visibility = 'hidden'; } /** * Shows the calendar layer * * @access private */ function dynCalendar_showLayer() { this._getLayer().style.visibility = 'visible'; } /** * Sets the layers position * * @access private */ function dynCalendar_setLayerPosition() { this._getLayer().style.top = (dynCalendar_mouseY + this.offsetY) + 'px'; this._getLayer().style.left = (dynCalendar_mouseX + this.offsetX) + 'px'; } function dynCalendar_setLayerPositionNear( el ){ if ( el != undefined && el != null ){ this._getLayer().style.left = ( getLeft(el) - 22 ) +'px'; this._getLayer().style.top = ( getTop(el) + 20 ) +'px'; } } function dynCalendar_setLayerStaticPosition( x,y ){ this._getLayer().style.left = x +'px'; this._getLayer().style.top = y +'px'; } /** * Sets the innerHTML attribute of the layer * * @access private */ function dynCalendar_setHTML(html) { this._getLayer().innerHTML = html; } /** * Returns number of days in the supplied month * * @access private * @param integer month The month to get number of days in * @param integer year The year of the month in question */ function dynCalendar_getDaysInMonth(month, year) { monthdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; if (month != 1) { return monthdays[month]; } else { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28); } } function defyears(mi,ma,sel) { this.nbr = mi; this.max = ma; this.sel = sel; } var VEL_Recherche_Calendar = new dynCalendar('VEL_Recherche_Calendar', null,'/images/','VEL_Recherche_Calendar');