var Class = { create: function(param) { var cls = function() { if (this.initialize) this.initialize(); }; cls.prototype = param; if (cls.initialize) cls.initialize(); return cls; } } var Calendar = Class.create({ initialize: function(){ this.calX = 0; this.calY = 0; this.dropYearMonth = null; this.dropDay = null; this.dropYearMonthNext = null; this.dropDayNext = null; this.currentMonth = 0; }, dayHeaders: new Array('M','T','W','T','F','S','S'), months: new Array('Feb-2013','Mar-2013','Apr-2013','May-2013','Jun-2013','Jul-2013','Aug-2013','Sep-2013','Oct-2013','Nov-2013','Dec-2013','Jan-2014','Feb-2014','Mar-2014','Apr-2014','May-2014','Jun-2014','Jul-2014','Aug-2014','Sep-2014','Oct-2014','Nov-2014','Dec-2014','Jan-2015','Feb-2015','Mar-2015','Apr-2015','May-2015','Jun-2015','Jul-2015','Aug-2015','Sep-2015','Oct-2015','Nov-2015','Dec-2015','Jan-2016'), monthDates: new Array('201302','201303','201304','201305','201306','201307','201308','201309','201310','201311','201312','201401','201402','201403','201404','201405','201406','201407','201408','201409','201410','201411','201412','201501','201502','201503','201504','201505','201506','201507','201508','201509','201510','201511','201512','201601'), monthMatrix: new Array( new Array(0,0,0,0,101,102,103,104,105,106,107,208,109,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0), new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0), new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0), new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0), new Array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0), new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0), new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0), new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0), new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0), new Array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0), new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0), new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0), new Array(0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0,0,0,0,0,0), new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0), new Array(0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,0,0,0,0,0,0,0) ), handleSyncDates: function(){ this.fixDays(this.dropYearMonth,this.dropDay); if( this.dropYearMonthNext && this.dropDayNext && this.nights ) { if( this.nights>0 ) this.handleSyncDatesF(); else this.handleSyncDatesB(); } }, fixDays: function(dropYearMonth, dropDay){ var day = $(dropDay).val(); var mday_index = 0; $(this.monthDates).each(function(index,value){ if( value==$(dropYearMonth).val() ) mday_index=index; }); var mday = this.monthMatrix[mday_index]; var min = 31; $(mday).each(function(index,value){ if( value>0 && value0 && value<32 ) max=value; }); if( daymax ) $(dropDay).val(max); }, handleSyncDatesF: function(){ var day = parseInt($(this.dropDay).val()); var nights = this.nights; for(var i=0; i0) { j++; if( j==mday.length || mday[j]==0 ) { i++; if( i==this.monthDates.length ) { i--; j--; break; } else { mday = this.monthMatrix[i]; j = 0; while(j=0; i--) if( this.monthDates[i] == $(this.dropYearMonth).val() ) { var mday = this.monthMatrix[i]; for(var j=mday.length-1; j>=0; j--) { if(mday[j] == day) { while(nights<0) { j--; if( j<0 || mday[j]==0 || mday[j]>31 ) { i--; if( i==-1 ) { i++; j++; break; } else { mday = this.monthMatrix[i]; j = mday.length-1; while(j>=0 && mday[j]==0) j--; } } nights ++; } $(this.dropYearMonthNext).val(this.monthDates[i]); $(this.dropDayNext).val(mday[j]); return; } } }*/ }, syncDates: function(dropYearMonthObj, dropDayObj, dropYearMonthNextObj, dropDayNextObj, days){ this.dropYearMonth = dropYearMonthObj; this.dropDay = dropDayObj; this.dropYearMonthNext = dropYearMonthNextObj; this.dropDayNext = dropDayNextObj; this.nights = days; this.handleSyncDates(); }, move_month: function(dir){ if (dir==1) { ++this.currentMonth; this.draw_calendar(); } else { --this.currentMonth; this.draw_calendar(); } }, handle_click: function(isoIn){ isoIn = "" + isoIn; $(this.dropDay).val(parseInt(isoIn.substring(6,8),10)); $(this.dropYearMonth).val(isoIn.substring(0,6)); $(this.dropfinalyear).val(isoIn.substring(6,8)+"/"+ isoIn.substring(4,6)+"/"+ isoIn.substring(0,4)); this.handleSyncDates(); this.hide_calendar(); }, open_cal1: function(dropYearMonthObj, dropDayObj){ this.dropYearMonth = dropYearMonthObj; this.dropDay = dropDayObj; this.dropYearMonthNext = null; this.dropDayNext = null; this.nights = 0; for (i=0;i0) tmpHtml = '<<'; else tmpHtml = ' '; table_top += '' + tmpHtml + '\n'; table_top += '' + this.months[month] + '\n'; if(month<(this.monthMatrix.length-1)) tmpHtml = '>>'; else tmpHtml = ' '; table_top += '' + tmpHtml + '\n'; table_top += '\n'; table_top += '\n'; table_top += '\n'; for (dh=0;dh'; table_top += '\n'; table_top += '\n'; print_string = ''; thisMonth = this.monthMatrix[month]; for (rw=0;rw<42;rw++) { if (rw!=0 && rw!=(thisMonth.length-1) && (rw%7==0)) print_string += "\n"; if (thisMonth[rw]!=0) { var box = ""; if( this.monthDates[month]==$(this.dropYearMonth).val() && ($(this.dropDay).val()==thisMonth[rw] || $(this.dropDay).val()==(thisMonth[rw]-200)) ) box = " style='border:1px solid black'"; var clickDate = (this.monthDates[month]*100 + thisMonth[rw]); if (thisMonth[rw]>200) print_string += '' + thisMonth[rw]%200 + ''; //print_string += '' + thisMonth[rw]%200 + ''; else if (thisMonth[rw]>100) print_string += '' + thisMonth[rw]%100 + ''; else print_string += '' + thisMonth[rw] + ''; } else print_string += ' '; } print_string += '\n'; print_string += 'close\n'; print_string += '\n'; this.element.html(table_top + print_string); $(this.element).css({'left':this.calX+'px', 'top':this.calY+'px'}); $(this.element).show(); } }); var myCalendar = new Calendar(); function openCal1(obj) { myCalendar.element = $('#calendar'); var pos = $('#hbook_cal1').offset(); myCalendar.calX=pos.left; myCalendar.calY=pos.top-235; myCalendar.open_cal2($('#date1m'), $('#date1d'), $('#datef'), $('#date2m'), $('#date2d'), $('#datef1'), $("#nights").val()); } function openCal2(obj) { myCalendar.element = $('#calendar'); var pos = $('#hbook_cal2').offset(); myCalendar.calX = pos.left; myCalendar.calY = pos.top-235; myCalendar.open_cal2($('#date2m'), $('#date2d'),$('#datef1'), $('#date1m'), $('#date1d'),$('#datef'), -$("#nights").val()); } function calcCal1(){ myCalendar.element = $('#calendar'); myCalendar.syncDates($('#date1m'), $('#date1d'), $('#date2m'), $('#date2d'), $("#nights").val()); } function calcCal2() { myCalendar.element = $('#calendar'); myCalendar.syncDates($('#date2m'), $('#date2d'), $('#date1m'), $('#date1d'), -$("#nights").val()); } function tr_openCal1(obj) { myCalendar.element = $('#calendar'); //alert($(obj)); var pos = $('#tr_cal1').offset(); myCalendar.calX=pos.left; myCalendar.calY=pos.top; //myCalendar.open_cal1($('tr_date1m'), $('tr_date1d')); myCalendar.open_cal2($('#tr_date1m'), $('#tr_date1d'), $('#tr_date2m'), $('#tr_date2d'), 1); } function tr_openCal2(obj) { myCalendar.element = $('#calendar'); var pos = $('#tr_cal2').offset(); myCalendar.calX=pos.left; myCalendar.calY=pos.top; myCalendar.open_cal1($('#tr_date2m'), $('#tr_date2d')); } function calcHotelCal1() { myCalendar.syncDates($('#hbook_date1m'), $('#hbook_date1d'), $('#hbook_date2m'), $('#hbook_date2d'), $('#hbook_nights').val()); } function calcHotelCal2() { myCalendar.syncDates($('#hbook_date2m'), $('#hbook_date2d'), $('#hbook_date1m'), $('#hbook_date1d'), -$('#hbook_nights').val()); }