(function($) { function minisiteCalWidget(el, params) { var now = new Date(); var thismonth = now.getMonth(); var thisyear = now.getFullYear(); var thisDay = now.getDate(); var thisiso2 = 'it'; var elId = el.attr('id'); var thisinput = ''; var thiscallback = ''; var thisDayStart = ''; var thisOthMonths = false; var opts = { month: thismonth, year: thisyear, dayStart: thisDayStart, siteIso2: thisiso2, inputId: thisinput, callBack: thiscallback, othMonths: thisOthMonths }; $.extend(opts, params); // Restrizioni giorni ABS var restrPeriods = new Array(); var hasRestrictions = false; var sD = opts.dayStart.substr(6,2); var sM = opts.dayStart.substr(4,2); var sY = opts.dayStart.substr(0,4); var sJD = new Date(sY,sM,sD); var sMkTJD = parseInt((sJD.getTime()/1000),10); var mJD = new Date(opts.year,opts.month,1); var mLJD = new Date(opts.year,opts.month+1,0); var checkJD = (sJD >= mJD) ? sJD : mJD ; if(typeof portal_restrictions != 'undefined'){ if(typeof portal_restrictions[params.cityId] != 'undefined'){ if(typeof portal_restrictions[params.cityId][params.strType] != 'undefined'){ $.each(portal_restrictions[params.cityId][params.strType],function(i){ var startBound = new Date(parseInt(this['fromMkTime'],10)*1000); var endBound = new Date(parseInt(this['toMkTime'],10)*1000); if((checkJD >= startBound || mLJD >= startBound) && checkJD <= endBound) { if(opts.inputId=='checkout' || opts.inputId=='checkoutM') { // Se ci sono delle restrizioni per il checkout aggiunto il MinStay if(sMkTJD >= this['fromMkTime'] && sMkTJD <= this['toMkTime']){ if(!opts.othMonths){ selMinStay = this['minstay']-1; sDateWithMinStay = sJD; sDateWithMinStay.setDate(sDateWithMinStay.getDate()+selMinStay); opts.dayStart = String(sDateWithMinStay.getFullYear())+minsiteCalendarGetData(sDateWithMinStay.getMonth())+minsiteCalendarGetData(sDateWithMinStay.getDate()); } } } restrPeriods.push(this); hasRestrictions = true; //return false; } }); } } } // console.log(hasRestrictions); // Fine Restrizioni ABS if(opts.siteIso2 == 'en') opts.siteIso2 = ''; //console.log($.datepicker.regional[opts.siteIso2]); // Traduzioni gestite da file esterno ABS_calWidgetStrings.js if(typeof window.ABS_calWidgetStrings != 'undefined' && typeof window.ABS_calWidgetStrings[opts.siteIso2] != 'undefined'){ var monthNames = window.ABS_calWidgetStrings[opts.siteIso2]['monthNames']; var dayNames = window.ABS_calWidgetStrings[opts.siteIso2]['dayNamesShort']; } else { var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; } month = i = parseInt(opts.month); year = parseInt(opts.year); var m = 0; var table = '
'; mounth2 = (month*1 < 10) ? '0'+month*1 : month*1; getMounth = (now.getMonth()*1 < 10) ? '0'+now.getMonth()*1 : now.getMonth()*1; // next month if (month == 11) { var next_month = ''; } else { var next_month = ''; } // previous month if(opts.dayStart != '' && (String(year)+String(mounth2))*1 <= ((opts.dayStart).substr(0,6))*1){ var prev_month = ''; } else if (month == 0) { var prev_month = ''; } else { var prev_month = ''; } table += ('
'+monthNames[month]+' '+year+'
'); table += (''); table += ''; for (d=0; d<7; d++) { table += ''; } table += ''; var days = getDaysInMonth(month,year); var firstDayDate=new Date(year,month,1); var firstDay=firstDayDate.getDay(); var prev_days = getDaysInMonth(month,year); var firstDayDate=new Date(year,month,1); var firstDay=firstDayDate.getDay(); var prev_m = month == 0 ? 11 : month-1; var prev_y = prev_m == 11 ? year - 1 : year; var prev_days = getDaysInMonth(prev_m, prev_y); firstDay = (firstDay == 0 && firstDayDate) ? 7 : firstDay; var i = 0; for (j=0;j<42;j++){ // Se ci sono restrizioni controllo giorno per giorno se va attivato o meno (di default il giorno è attivo) activeClass = ' clickdata'; onClickBehavior = 'onclick="minisiteCalendarsetDatas(this, \''+ opts.callBack +'\', \''+ opts.inputId +'\', \''+ elId +'\');"'; disabledClassAppend=''; checkType = opts.inputId; if(checkType == 'checkinM') checkType = 'checkin'; if(checkType == 'checkoutM') checkType = 'checkout'; if ((j String(now.getFullYear())+String(minsiteCalendarGetData(getMounth)) ) || ( opts.dayStart != '' && String(prev_y)+String(minsiteCalendarGetData(prev_m))+String(minsiteCalendarGetData(prev_days-firstDay+j+1)) > parseInt(opts.dayStart) ) ) { /******************************************************* Controllo data restrictions */ if(hasRestrictions){ thisSquareDate = new Date(year,month-1,(prev_days-firstDay+j+1)); thisSquareDateWeekDay = thisSquareDate.getDay(); thisSquareMkTime = parseInt((thisSquareDate.getTime()/1000),10); $.each(restrPeriods,function(i,v){ if(thisSquareMkTime >= v['fromMkTime'] && thisSquareMkTime <= v['toMkTime']){ if(typeof v['days'][thisSquareDateWeekDay][checkType] != 'undefined' && v['days'][thisSquareDateWeekDay][checkType] == 0){ activeClass = ''; onClickBehavior = ''; disabledClassAppend='-disabled'; } return false; } }); } /******************************************************* */ table += (''); } else { table += (''); } } else if ((j>=firstDay+getDaysInMonth(month,year))) { // Giorni mese successivo i = i+1; nextYearTd = (month+2 > 12) ? year+1 :year; nextMounthTd = (month+2 > 12) ? month+2-12 : month+2; thisSquareDate = new Date(nextYearTd,minsiteCalendarGetData(nextMounthTd)-1,minsiteCalendarGetData(i)); /******************************************************* Controllo data restrictions */ if(hasRestrictions){ thisSquareDateWeekDay = thisSquareDate.getDay(); thisSquareMkTime = parseInt((thisSquareDate.getTime()/1000),10); $.each(restrPeriods,function(i,v){ if(thisSquareMkTime >= v['fromMkTime'] && thisSquareMkTime <= v['toMkTime']){ if(typeof v['days'][thisSquareDateWeekDay][checkType] != 'undefined' && v['days'][thisSquareDateWeekDay][checkType] == 0){ activeClass = ''; onClickBehavior = ''; disabledClassAppend='-disabled'; } return false; } }); } /******************************************************* */ var nsD = opts.dayStart.substr(6,2); var nsM = opts.dayStart.substr(4,2); var nsY = opts.dayStart.substr(0,4); var nsJD = new Date(nsY,nsM,nsD); if(thisSquareDate > nsJD){ table += (''); } else { table += (''); } } else if( (String(year)+String(minsiteCalendarGetData(mounth2))+String(minsiteCalendarGetData(j-firstDay+1))==String(now.getFullYear())+String(minsiteCalendarGetData(getMounth))+String(minsiteCalendarGetData(thisDay))) && ( ( opts.dayStart != '' && (String(year)+String(mounth2)+minsiteCalendarGetData(j-firstDay+1) > parseInt(opts.dayStart)) ) || ( opts.dayStart == '' && (String(year)+String(mounth2)+minsiteCalendarGetData(j-firstDay+1) > String(now.getFullYear())+String(minsiteCalendarGetData(getMounth))+String(minsiteCalendarGetData(thisDay))) ) ) ) { // Giorni mese corrente /******************************************************* Controllo data restrictions */ if(hasRestrictions){ thisSquareDate = new Date(year,month,minsiteCalendarGetData(j-firstDay+1)); thisSquareDateWeekDay = thisSquareDate.getDay(); thisSquareMkTime = parseInt((thisSquareDate.getTime()/1000),10); $.each(restrPeriods,function(i,v){ if(thisSquareMkTime >= v['fromMkTime'] && thisSquareMkTime <= v['toMkTime']){ if(typeof v['days'][thisSquareDateWeekDay][checkType] != 'undefined' && v['days'][thisSquareDateWeekDay][checkType] == 0){ activeClass = ''; onClickBehavior = ''; disabledClassAppend='-disabled'; } return false; } }); } /******************************************************* */ table += (''); } else if( opts.dayStart != '' && (String(year)+String(mounth2)+minsiteCalendarGetData(j-firstDay+1) > parseInt(opts.dayStart)) ) { /******************************************************* Controllo data restrictions */ if(hasRestrictions){ thisSquareDate = new Date(year,month,minsiteCalendarGetData(j-firstDay+1)); thisSquareDateWeekDay = thisSquareDate.getDay(); thisSquareMkTime = parseInt((thisSquareDate.getTime()/1000),10); $.each(restrPeriods,function(i,v){ if(thisSquareMkTime >= v['fromMkTime'] && thisSquareMkTime <= v['toMkTime']){ if(typeof v['days'][thisSquareDateWeekDay][checkType] != 'undefined' && v['days'][thisSquareDateWeekDay][checkType] == 0){ activeClass = ''; onClickBehavior = ''; disabledClassAppend='-disabled'; } return false; } }); } /******************************************************* */ table += (''); } else if( // Giorni precedenti alla data di inizio opts.dayStart != '' && (String(year)+String(mounth2)+minsiteCalendarGetData(j-firstDay+1) <= parseInt(opts.dayStart)) ) { table += (''); } else { /******************************************************* Controllo data restrictions */ if(hasRestrictions){ thisSquareDate = new Date(year,month,minsiteCalendarGetData(j-firstDay+1)); thisSquareDateWeekDay = thisSquareDate.getDay(); thisSquareMkTime = parseInt((thisSquareDate.getTime()/1000),10); $.each(restrPeriods,function(i,v){ if(thisSquareMkTime >= v['fromMkTime'] && thisSquareMkTime <= v['toMkTime']){ if(typeof v['days'][thisSquareDateWeekDay][checkType] != 'undefined' && v['days'][thisSquareDateWeekDay][checkType] == 0){ activeClass = ''; onClickBehavior = ''; disabledClassAppend='-disabled'; } return false; } }); } /******************************************************* */ table += (''); } if (j%7==6) table += (''); } if(elId=='cal1'){ table += ('
' + dayNames[d] + '
'+(prev_days-firstDay+j+1)+''+ (prev_days-firstDay+j+1) +''+ i +''+ i +''+(j-firstDay+1)+''+(j-firstDay+1)+''+(j-firstDay+1)+''+(j-firstDay+1)+'
'+ trad['available_checkin_dates'] +'
'); } else { table += ('
'+ trad['available_checkout_dates'] +'
'); } el.html(table); } function getDaysInMonth(month,year) { var daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31]; if ((month==1)&&(year%4==0)&&((year%100!=0)||(year%400==0))){ return 29; }else{ return daysInMonth[month]; } } // jQuery plugin initialisation $.fn.minisiteCalWidget = function(params) { minisiteCalWidget(this, params); return this; }; })(jQuery); function minisiteCalendarsetDatas(myEl,calls,input,elmid){ if(input!=''){ val4input = (myEl.id.replace('d_','')).split('-'); $('#'+ input).val(minsiteCalendarGetData(val4input[2]) +'-'+ minsiteCalendarGetData(val4input[1]) +'-'+ val4input[0]); if(calls!=''){ setTimeout(calls ,1); } } } function minsiteCalendarGetData(val){ return (val*1 < 10) ? '0'+String(val*1) : String(val*1) ; } function setRoomMinisite(nrooms, label_adults, label_children, label_children_age, label_room, element) { var form = element.parents('form'); var myResults = ''; if (nrooms > 1) // se viene scelta più di una camera... { for (var i=2; i<=nrooms; i++) // preparo la stringa da accodare alla prima camera, contenente i campi necessari { myResults = myResults + '
  • '+ label_room +' '+ i +':
  • '; myResults = myResults + '
  • '+ ''+ ''+ '
  • '+ '
  • '+ ''+ ''+ '
  • '+ '
  • '; } $('li.room1.roomTitle', form).remove(); // rimuovo il titolo della camera 1 (per evitare duplicazioni nel caso sia già presente: vedi istruzione successiva) $('li.room1:first', form).before('
  • '+ label_room +' 1:
  • '); // aggiungo il titolo della camera 1, prima del primo campo della camera 1 $('li.room1:last', form).nextAll().remove(); // rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1 $('li.room1:last', form).after(myResults); // aggiungo dopo l'ultimo elemento della camera 1, la stringa preparata in precedenza } else // se viene scelta una sola camera... { $('li.room1.roomTitle', form).remove(); // rimuovo il titolo della camera 1 $('li.room1:last', form).nextAll().remove(); // rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1 } } function createSelectMinisite(num, init, label, labels, selected){ if(label != ""){ label = " "+ label; } if(labels != ""){ labels = " "+ labels; } else { labels = label; } var mySel = ""; for(var k=init; k<=num; k++){ if(k!=init) label = labels; if (selected != 0 && selected == k){ mySel = mySel + "\n" + ''; // solo numero } else { mySel = mySel + "\n" + ''; // solo numero } } return mySel; } function setChildAgeMinisite(nchild, chdid, roomn, label_children_age,elem){ var selectHtml = ""; if(nchild > 0){ selectHtml = ''; for (var cc=1; cc<=nchild; cc++) { selectHtml = selectHtml + ''; } } if($('#'+chdid)){ $('#'+chdid).html(selectHtml); } //setAdultsNumberDeals(nchild,elem); } function setChildNumberMinisite(value,elem){ var maxChildrenToSet = ABSInfo['maxpax']-value; childrenSelect = $('select',$(elem).parent().next()); numChildren = childrenSelect.val(); placesLeft = ABSInfo['maxpax']-value-numChildren; childrenAgeWrap = $(elem).parent().next().next(); $('option', $(childrenSelect)).each(function(index) { if(placesLeft < 0){ if($(this).val() > maxChildrenToSet) { $(this).attr('disabled','disabled'); } else if($(this).val() == maxChildrenToSet){ $(this).removeAttr('disabled'); $(this).attr('selected','selected'); } else { $(this).removeAttr('disabled'); } } else { if($(this).val() > maxChildrenToSet) { $(this).attr('disabled','disabled'); } else { $(this).removeAttr('disabled'); } } }); if(placesLeft < 0){ selectToRemove = (placesLeft*-1); if($('select', $(childrenAgeWrap)).length <= selectToRemove) { $(childrenAgeWrap).empty(); } else { $('select', $(childrenAgeWrap)).each(function(index) { if(index >= $('select',$(elem).parent().next()).val()){ $(this).remove(); } }); } } }