/*------------------------------------------------------------------- * Generic class that enables you to manage a stack of objects * Nurun @Copyright *------------------------------------------------------------------*/ StackObject = function(){ this.objects = new Array(); } StackObject.prototype.addObject = function(obj){ if(this.getObject(obj.id)==null) this.objects[this.objects.length] = obj; else this.objects[this.getIndex(obj.id)] = obj; } StackObject.prototype.getObject = function(id){ var returnValue = null; for(var count=0;count see calendar.js // Need a refactorisation var CONST_MONTHS_en = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); function getMonths(curLocale,defLocale) { try { var months = eval("CONST_MONTHS_"+curLocale); return months; } catch(e1) { try { var defMonths = eval("CONST_MONTHS_"+defLocale); return defMonths; } catch(e2) { return eval("CONST_MONTHS_en"); } } } function getDays(curLocale,defLocale) { try { var months = eval("CONST_DAYS_"+curLocale); return months; } catch(e1) { try { var defMonths = eval("CONST_DAYS_"+defLocale); return defMonths; } catch(e2) { return eval("CONST_DAYS_en"); } } } //Constructor Calendar = function(id, currentDate){ this.base = AbstractObject; this.base(id); this.dateObject = currentDate; this.month = currentDate.getMonth(); this.date = currentDate.getDate(); this.day = currentDate.getDay(); this.year = currentDate.getFullYear(); this.dates = new Array(); this.maximumDate = null; currentDate.setDate(1); this.firstDay = currentDate.getDay(); currentDate.setDate(this.date); } Calendar.prototype = new AbstractObject; Calendar.prototype.setMaximumDate = function(maximumDate) { this.maximumDate = maximumDate; } //Render the calendar Calendar.prototype.writeCalendar = function(check, container){ var calString = '
'; calString += ''; //calString += ''; calString += ''; if (check.indexOf("first")!=-1) { //calString += ''; calString += ''; }else { //calString += ''; calString += ''; } //calString += ''; //calString += ''; //calString += ''; //calString += ''; //calString += ''; calString += ''; calString += ''; var DAYS = getDays(getCurrentLocale(),getDefaultLocale()); for(i=0;i'; } calString += ''; for(var j=0;j<42;j++){ var displayNum = (j-this.firstDay+1); var dateToKnow = buildTempDate(this.year,this.month,displayNum); this.dates[j] = dateToKnow; if(j getLength((this.month), this.year)){ calString += ''; }else if(this.maximumDate!=null && dateToKnow>buildCompareDate(this.maximumDate)) { calString += ''; }else if(displayNum<(new Date()).getDate() && this.month==(new Date()).getMonth() && this.year==(new Date()).getFullYear()){ calString += ''; }else if(j%7==6 || j%7==0){ calString += ''; }else{ calString += ''; } if(j%7==6){ calString += ''; } } calString += ''; calString += '
 ' + CONST_MONTHS[this.month] + ', ' + this.year + '
 ' + getMonths(getCurrentLocale(),getDefaultLocale())[this.month] + ', ' + this.year + ' 
 ' + displayNum + '' + displayNum + '' + displayNum + '' + displayNum + '
'; calString += '
'; getObj(container).innerHTML = calString; } //set current date Calendar.prototype.setIndex = function(index,notify){ var date = this.dates[index]; this.currentDate = buildDate(date); this.refreshSelection(); //alert(date); for(var i=2;i<8;i++) { //get line with values var p = getObj(this.id).childNodes[0].childNodes[0].childNodes[i].childNodes; if(p==null) continue; for(var pi=0;pi=(new Date()).getMonth() && this.currentPeriod.getFullYear()==(new Date()).getFullYear() ) || ( this.currentPeriod.getFullYear()>(new Date()).getFullYear() )) && this.currentPeriod < this.maxDate) { this.createCalendars(this.currentPeriod); } else { this.currentPeriod.setMonth(this.currentPeriod.getMonth()-compare); } } EuropcarCalendar.prototype.show = function(){ getObj(this.container).style.display = "block"; } EuropcarCalendar.prototype.hide = function(){ getObj(this.container).style.display = "none"; } //europcar form var CONST_PREFIX = "reservation"; var CONST_DIFF = 2; //difference between two dates var CONST_CHECKOUT = "checkout"; var CONST_CHECKIN = "checkin"; var CONST_SELECT_DAYS = "day"; var CONST_SELECT_MONTHYEAR = "monthyear"; var CONST_SELECT_HOUR = "hour"; var CONST_SELECT_MINUTE = "minute"; EuropcarForm = function(){ this.base = AbstractObject; this.base("EuropcarForm"); //specific creation of months this.init(CONST_CHECKOUT); this.init(CONST_CHECKIN); //get the limit of date this.maxDateCheckout = (maximumDate!=null)?buildDate(maximumDate):buildDate(this.getMaximumDate(CONST_CHECKOUT)); //this.maxDateCheckin = (maximumDate!=null)?buildDate(maximumDate):buildDate(this.getMaximumDate(CONST_CHECKIN)); this.maxDateCheckin = buildDate(this.getMaximumDate(CONST_CHECKIN)); this.maxDateCheckout.setMonth(this.maxDateCheckout.getMonth()); this.maxDateCheckin.setMonth(this.maxDateCheckin.getMonth()); //intiliaze calendars var myDate = buildDate(this.getDate(CONST_CHECKOUT)); //this.setSelect(CONST_CHECKOUT,buildCompareDate(myDate)); myDate.setDate(myDate.getDate()+CONST_DIFF); //this.setSelect(CONST_CHECKIN,buildCompareDate(myDate)); } EuropcarForm.prototype = new AbstractObject; EuropcarForm.prototype.createEuropcarCalendar = function(where,date){ var myEuropcarCalendar = new EuropcarCalendar(where, buildCompareDate(date),where+"calendar"); if(where==CONST_CHECKOUT) myEuropcarCalendar.setMaxDate(this.maxDateCheckout); else myEuropcarCalendar.setMaxDate(this.maxDateCheckin); myEuropcarCalendar.show(); myEuropcarCalendar.addParentListener(this); } EuropcarForm.prototype.closeCalendar = function(where) { var myEuropcarCalendar = new EuropcarCalendar(where, new Date(),where+"calendar"); myEuropcarCalendar.show(); myEuropcarCalendar.hide(); } EuropcarForm.prototype.setDateFromCalendar = function(date){ this.setSelect(this.srcEvent.id,date); this.verifyRules(this.srcEvent.id); this.eventFromChangeDay(CONST_CHECKOUT); } EuropcarForm.prototype.eventFromSelect = function(where){ var date = this.getDate(where); this.setSelect(where,date); this.verifyRules(where); } EuropcarForm.prototype.eventFromSelectDay = function(where){ var date = this.getDate(where); this.verifyRules(where); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EuropcarForm.prototype.eventFromChangeDay = function(where){ var date = this.getDate(where); var now = new Date(); //alert(now.getDate()); if (findDay(date)==now.getDate()) if (findMonth(date)==now.getMonth()) if (findYear(date)==now.getYear()){ var selectHour = CONST_PREFIX+where+CONST_SELECT_HOUR; var selectMinute = CONST_PREFIX+where+CONST_SELECT_MINUTE; var hours = (now.getHours()+2)%23; setValue(selectHour, hours ); setValue(selectMinute, Math.round(now.getMinutes()/15) * 15); } } EuropcarForm.prototype.show = function(where){ this.createEuropcarCalendar(where, buildDate(this.getDate(where))); } EuropcarForm.prototype.verifyRules = function(where){ if(this.getDate(CONST_CHECKOUT)>this.getDate(CONST_CHECKIN)) { var myDate = buildDate(this.getDate(where)); if(where == CONST_CHECKOUT) { var now = new Date(); //alert(now.getDate()); if (findDay(myDate)==now.getDate()) if (findMonth(myDate)==now.getMonth()) if (findYear(myDate)==now.getYear()){ var selectHour = CONST_PREFIX+where+CONST_SELECT_HOUR; var selectMinute = CONST_PREFIX+where+CONST_SELECT_MINUTE; var hours = (now.getHours()+2)%23; setValue(selectHour, hours ); setValue(selectMinute, Math.round(now.getMinutes()/15) * 15); } myDate.setDate(myDate.getDate()+CONST_DIFF); this.setSelect(CONST_CHECKIN,buildCompareDate(myDate)); } else { // myDate.setDate(myDate.getDate()-CONST_DIFF); // this.setSelect(CONST_CHECKOUT,buildCompareDate(myDate)); } } } EuropcarForm.prototype.setSelect = function(where,date){ var day = findDay(date); var month = findMonth(date); var year = findYear(date); var selectDay = CONST_PREFIX+where+CONST_SELECT_DAYS; var selectMonthYear = CONST_PREFIX+where+CONST_SELECT_MONTHYEAR; getObj(selectDay).options.length = 0; var firstDay = 0; /** uncomment this part to make the first month beginning at the current day */ //if((new Date()).getMonth()==month && (new Date()).getFullYear()==year) // firstDay = (new Date()).getDate()-1; for(var count=firstDay;count0){ if(parseInt(obj.options[count].value.replace("_",""),10) year2 is a new year year2++; incrementYear=false; } else if(value==11) { //December --> year2 will be increased at the following loop incrementYear=true; } // var concatStr = year + "" + ((value<10)?"0"+value:value) + "00"; var correspondingDate = concatStr; if(maxDate != null && correspondingDate>maxDate) break; //getObj(selectMonthYear).options[count] = new Option(eval("CONST_MONTHS_"+currentLocale)[value] + " " + year,((value<10)?"0"+value:value)+"_"+year); //getObj(selectMonthYear).options[count] = new Option(getMonths(getCurrentLocale(),getDefaultLocale())[value] + " " + year,((value<10)?"0"+value:value)+"_"+year); //10663 getObj(selectMonthYear).options[count] = new Option(getMonths(getCurrentLocale(),getDefaultLocale())[value] + " " + year2,((value<10) ? "0"+value : value) + "_" + year2); } var selectedIndex = parseInt(obj.selectedIndex,10); var newDate = new Date(); newDate.setMonth(getSelectValue(where+"Month")); newDate.setFullYear(getSelectValue(where+"Year")); var currentDate = new Date(); var oneMonthPerMillesecond = 1000*3600*24*30; // nb of month between the current date and the start of the promotion //selectedIndex = Math.round((newDate.getTime()-currentDate.getTime()) /oneMonthPerMillesecond); //***** 10663 Choice of the month to pre-select in the list ******** //1st case: the opening date of the promotion is a future date // ==> this opening date is selected in the list if(newDate.getTime()>currentDate.getTime()) { selectedIndex = 0; } //2nd case: the opening date is past // ==> the current month is selected else { //Nb of month between the current date and the opening promotion date nbMonthes = Math.round((currentDate.getTime() - newDate.getTime()) / oneMonthPerMillesecond); selectedIndex = nbMonthes; } getObj(selectMonthYear).selectedIndex = selectedIndex; } EuropcarForm.prototype.getDate = function(from){ var days = getSelectValue(CONST_PREFIX+from+CONST_SELECT_DAYS); var month = getSelectValue(CONST_PREFIX+from+CONST_SELECT_MONTHYEAR).split("_")[0]; var year = getSelectValue(CONST_PREFIX+from+CONST_SELECT_MONTHYEAR).split("_")[1]; var concatDat = year+month+((days<10)?"0"+days:days); return parseInt(concatDat,10); } EuropcarForm.prototype.getMaximumDate = function(from){ var days = getMaxValue(CONST_PREFIX+from+CONST_SELECT_DAYS); var month = getMaxValue(CONST_PREFIX+from+CONST_SELECT_MONTHYEAR).split("_")[0]; var year = getMaxValue(CONST_PREFIX+from+CONST_SELECT_MONTHYEAR).split("_")[1]; return parseInt(year+month+days,10); } /*----------------------------*/ function getMaxValue(id) { return getObj(id).options[getObj(id).options.length-1].value; } function getSelectValue(id) { var returnValue = ""; if(getObj(id).options[getObj(id).selectedIndex].value!="") returnValue = getObj(id).options[getObj(id).selectedIndex].value; else returnValue = getObj(id).options[0].value; return returnValue; } function setValue (id, val){ for(var i=0;i