var Calendar=_cl={servData:{today:new Date(),weekdays:[],months:[],type:"",nDays:320,nHours:0,txtBackNextMonth:[],userDay:-1,monthDay:-1},finalDate:null,lay:null,allCalendars:[],layNameDay:[],changeMonth:false,active:false,actualPicker:-1,onlyBooking:false,dateInSession:false,nomCampOb:[],load:function(){var b=dom.getElementsById("ciudadDestino");for(var c=0;c<b.length;c++){_cl.nomCampOb[c]=[];_cl.nomCampOb[c].push(["destinoLbl_"+c,true])}_cl.nomCampOb.push(["passangersLbl",true]);_cl.SD=_cl.servData;_cl.allC=_cl.allCalendars;var a=_cl.SD.today.getMonth();_cl.SD.today=new Date(_cl.SD.today.getFullYear(),_cl.SD.today.getMonth(),_cl.SD.today.getDate(),parseInt(_cl.SD.today.getHours()+_cl.SD.nHours));if(a!=_cl.SD.today.getMonth()){_cl.changeMonth=true}_cl.finalDate=new Date(_cl.SD.today.getFullYear(),_cl.SD.today.getMonth(),parseInt(_cl.SD.today.getDate()+_cl.SD.nDays));for(var c=0;c<arguments.length;c++){_cl.create(arguments[c],c)}},create:function(a,e){_cl.allC.push([a[1][0],a[1][1],a[1][2],a[1][3]]);_auxDay=(_cl.SD.today.getMonth().toString().length>1)?_cl.SD.today.getDate().toString():"0"+parseInt(_cl.SD.today.getMonth()+1).toString();_cl.layNameDay[e]=a[1][3];if(_cl.layNameDay[e]!=null){_cl.layNameDay[e].className="weekDay4 ftl"}_cl.listDays=a[1][0];_cl.listDays.cont=e;_cl.listMonthYears=a[1][1];_cl.listMonthYears.cont=e;if(!_cl.dateInSession){_cl.listDays.selectedIndex=_cl.SD.today.getDate()-1;_cl.listMonthYears.selectedIndex=forms.getSelectedByValue(_cl.listMonthYears,_cl.SD.today.getFullYear().toString()+_auxDay)}var d=_cl.getCbDate(_cl.listDays,_cl.listMonthYears);if(_cl.layNameDay[e]!=null){_cl.layNameDay[e].innerHTML=_cl.returnDayWeek(d)}_cl.listDays.onchange=_cl.returnListDays;_cl.listMonthYears.onchange=_cl.returnListMonthsAndYears;var c=document.createElement("a");c.href="#";c.contId=e;c.onclick=function(){_cl.actualPicker=this.contId;_cl.init(a[1],this,this.contId);return false};var b=document.createElement("img");b.className="icoCalendar";b.src=config.urlImg+"calendar.gif";c.appendChild(b);page.$(a[0]).appendChild(c)},getCbDay:function(a){return a.value},getCbMonth:function(a){return parseInt(a.value.substr(4,6),10)-1},getCbYear:function(a){return parseInt(a.value.substr(0,4),10)},getCbDate:function(b,a){return new Date(_cl.getCbYear(a),_cl.getCbMonth(a),_cl.getCbDay(b))},init:function(f,d,g){if(!_cl.active||g==0){_cl.inputReturn=[];_cl.inputReturn.day=f[0];_cl.inputReturn.month=f[1];_cl.inputReturn.hour=f[2];_cl.inputReturn.nameDay=f[3];idInput=_cl.inputReturn.day.id;var a=_cl.inputReturn.day.value;var e=parseInt(_cl.inputReturn.month.value.substr(4,6),10)-1;var c=parseInt(_cl.inputReturn.month.value.substr(0,4),10);_cl.deleteCalendars();var b=document.createElement("div");b.setAttribute("id","CAL_"+idInput);b.className="calendar";_cl.lay=b;_cl.paint(a,e,c,b);b.style.display="block";b.style.left=(f[2]!=null)?xy.getX(f[2])-(-1*f[2].offsetWidth)-(-1*5)+"px":xy.getX(d)-(-1*d.childNodes[0].offsetWidth)+2+"px";b.style.top=(f[2]!=null)?xy.getY(f[2])+"px":xy.getY(d)+"px"}else{return false}},deleteCalendars:function(){for(var a=0;a<_cl.allC.length;a++){if(page.$("CAL_"+_cl.allC[a][0].id)){page.$("CAL_"+_cl.allC[a][0].id).parentNode.removeChild(page.$("CAL_"+_cl.allC[a][0].id))}}},cleanCalendars:function(){_cl.allCalendars=[]},returnDayWeek:function(c,b,e){var a=(arguments.length==1)?c.getDay():new Date(e,b,c).getDay();a=(a==0)?6:a-1;return _cl.SD.weekdays[a]},returnDateLists:function(b,c,a,f){_cl.deleteCalendars();var e=parseInt(c.value.substr(4,6),10)-1;var d=parseInt(c.value.substr(0,4),10);if(_cl.layNameDay[a]!=null){_cl.layNameDay[a].innerHTML=_cl.returnDayWeek(b,e,d)}_cl.compareDates(b,e,d,a,f)},returnListDays:function(){_cl.returnDateLists(this.value,this.parentNode.parentNode.getElementsByTagName("select")[1],this.cont,"d")},returnListMonthsAndYears:function(){_cl.returnDateLists(this.parentNode.parentNode.getElementsByTagName("select")[0].value,this,this.cont,"m")},compareDates:function(B,w,o,v,g){var l=[];var a=(_cl.changeMonth)?0:1;var h=false;for(var b=0;b<_cl.allC.length;b++){l[b]={date:new Date(_cl.allC[b][1].value.substr(4,6)+"/"+_cl.allC[b][0].value+"/"+_cl.allC[b][1].value.substr(0,4))};var A=new Date(_cl.SD.today.getFullYear(),_cl.SD.today.getMonth(),_cl.SD.today.getDate());if(l[b].date<A){_auxDay1=parseInt(_cl.SD.today.getMonth()+2,10).toString();_cl.allC[b][1].selectedIndex=forms.getSelectedByValue(_cl.allC[b][1],_cl.SD.today.getFullYear().toString()+_auxDay1);if(!_cl.onlyBooking){var r=A.getDate()-1;var f=forms.getSelectedByValue(_cl.allC[b][1],A.getFullYear().toString()+_auxDay);if(b==0){r=_cl.allC[b][0].value-1;f++;h=true}if(b>0){if(_cl.allC[b][3]!=null&&(l[b-1].date-A==0)&&l[b].date<A){_cl.allC[b][3].innerHTML=_cl.returnDayWeek(_cl.allC[b][0].value,_cl.allC[b][1].value.substr(4,6),A.getFullYear())}}else{_cl.allC[b][0].selectedIndex=r;_cl.allC[b][1].selectedIndex=f;if(_cl.allC[b][3]!=null){_cl.allC[b][3].innerHTML=_cl.returnDayWeek(_cl.allC[b][0].value,_cl.allC[b][1].value.substr(4,6)-1,A.getFullYear())}}}l[b]={date:new Date(_cl.allC[b][1].value.substr(4,6)+"/"+_cl.allC[b][0].value+"/"+_cl.allC[b][1].value.substr(0,4))}}if(b>0&&!_cl.active&&_cl.SD.type!="hotels"){if(_cl.allCalendars[b][0].form==_cl.allCalendars[b-1][0].form&&l[b].date<l[b-1].date){if(((v>0&&g=="d")||_cl.actualPicker>0)&&!(l[b-1].date>=_cl.finalDate)&&parseInt(_cl.allC[b][0].value,10)<parseInt(_cl.allC[b-1][0].value,10)&&_cl.allC[b-1][1].value.substr(0,4)==_cl.allC[b][1].value.substr(0,4)){if(_cl.allC[b-1][1].value.substr(0,4)>_cl.SD.today.getFullYear()){var t=parseInt(_cl.allC[b-1][1].value.substr(4,6),10);var s=12*(_cl.allC[b-1][1].value.substr(0,4)-_cl.SD.today.getFullYear());var p=_cl.SD.today.getMonth();var z=parseInt(1+(t+s-p-a),10)}else{var z=parseInt(1+(_cl.allC[b-1][1].value.substr(4,6)-_cl.SD.today.getMonth()-a),10)}if(_cl.allC[b][1].options.length==z){_cl.allC[b][0].selectedIndex=_cl.allC[b-1][0].selectedIndex;_cl.allC[b][1].selectedIndex=_cl.allC[b-1][1].selectedIndex;l[b].date=l[b-1].date}else{_cl.allC[b][1].selectedIndex=z;l[b].date=new Date(_cl.allC[b][1].value.substr(0,4),_cl.allC[b][1].value.substr(4,6)-1,_cl.allC[b][0].value,0,0,0,0);if(_cl.allC[b][3]!=null){_cl.allC[b][3].innerHTML=_cl.returnDayWeek(l[b].date)}}}else{var q=(h)?0:1;_cl.allC[b][0].selectedIndex=_cl.allC[b-q][0].value-1;if(_cl.allC[b-1][1].value.substr(0,4)>_cl.SD.today.getFullYear()){var e=parseInt(_cl.allC[b-1][1].value.substr(4,6),10);var c=parseInt(12*(_cl.allC[b-1][1].value.substr(0,4)-_cl.SD.today.getFullYear())-_cl.SD.today.getMonth(),10);_cl.allC[b][1].selectedIndex=parseInt(e+c,10)-a;l[b].date=new Date(_cl.allC[b-1][1].value.substr(0,4),_cl.allC[b-1][1].value.substr(4,6)-1,_cl.allC[b-1][0].value,0,0,0,0)}else{_cl.allC[b][1].selectedIndex=_cl.allC[b-1][1].value.substr(4,6)-_cl.SD.today.getMonth()-a;l[b].date=new Date(_cl.allC[b][1].value.substr(0,4),_cl.allC[b][1].value.substr(4,6)-1,_cl.allC[b][0].value,0,0,0,0)}if(_cl.allC[b][3]!=null){_cl.allC[b][3].innerHTML=_cl.returnDayWeek(l[b].date)}}}}if(l[b].date>=_cl.finalDate){_cl.allC[b][0].selectedIndex=_cl.finalDate.getDate()-1;if(_cl.allC[b][3]!=null&&!_cl.onlyBooking){_cl.allC[b][3].innerHTML=_cl.returnDayWeek(_cl.finalDate)}}var x=parseInt(_cl.allC[b][1].value.substr(4,6)-1,10);var u=parseInt(_cl.allC[b][1].value.substr(0,4),10);if(_cl.allC[b][0].value>Gdate.dayMonth(x,u)){_cl.allC[b][0].selectedIndex=Gdate.dayMonth(x,u)-1;var k=new Date(_cl.allC[b][1].value.substr(0,4),_cl.allC[b][1].value.substr(4,6)-1,Gdate.dayMonth(w,o));_cl.allC[b][3].innerHTML=_cl.returnDayWeek(k)}}h=false;_cl.actualPicker=-1},paintNavigation:function(l,g,k,f){var a=document.createElement("p");a.className="clear";var m=document.createElement("a");m.setAttribute("href","#");var b=document.createElement("img");b.setAttribute("alt",_cl.SD.txtBackNextMonth[0]);b.setAttribute("title",_cl.SD.txtBackNextMonth[0]);b.src=config.urlImg+"btn_calendarBack.gif";b.className="backmonth";var q=g-1;var e=k;var h=l;if(q<0){q=11;e=k-1}m.onclick=function(){_cl.paint(h,q,e,f,f.getElementsByTagName("table")[0]);return false};m.appendChild(b);a.appendChild(m);var o=document.createElement("span");o.className="txtmonth";o.appendChild(document.createTextNode(_cl.SD.months[g]+" "+k));a.appendChild(o);var r=document.createElement("a");r.setAttribute("href","#");var c=document.createElement("img");c.setAttribute("alt",_cl.SD.txtBackNextMonth[1]);c.setAttribute("title",_cl.SD.txtBackNextMonth[1]);c.src=config.urlImg+"btn_calendarForward.gif";c.className="nextmonth";r.onclick=function(){var p=g+1;var d=k;if(p==12){p=0;d=k+1}_cl.paint(h,p,d,f,f.getElementsByTagName("table")[0]);return false};r.appendChild(c);a.appendChild(r);f.appendChild(a)},paintDayOfWeek:function(b,c){var d=document.createElement("thead");var f=document.createElement("tr");for(i=0;i<b.length;i++){var a=document.createElement("th");var e=document.createElement("abbr");e.title=b[i];e.appendChild(document.createTextNode(b[i].substr(0,2)));a.appendChild(e);f.appendChild(a)}d.appendChild(f);c.appendChild(d)},paintMonth:function(t,z,o,r){var x=(_cl.changeMonth)?0:1;var t=parseInt(t,10);var w=new Date(o,z,1);var m=w.getDay();if(m==0){m=7}if(z>0){previousDay=Gdate.dayMonth(z-1,o);var s=z-1;var l=o}else{previousDay=Gdate.dayMonth(11,o-1);var s=11;var l=o-1}var b=document.createElement("tbody");var c=document.createElement("tr");for(j=previousDay-(m-1)+1;j<=previousDay;j++){var e=document.createElement("td");e.className="cellOtroMes";var B=new Date(l,s,j,_cl.SD.today.getHours(),_cl.SD.today.getMinutes(),_cl.SD.today.getSeconds());e.appendChild(document.createTextNode(""));c.appendChild(e)}var g=m;for(i=1;i<=7-m+1;i++){var e=document.createElement("td");var p=document.createTextNode(i);var A=document.createElement("a");A.setAttribute("href","#");var B=new Date(o,z,i-1,_cl.SD.today.getHours(),_cl.SD.today.getMinutes(),_cl.SD.today.getSeconds());if(B<=_cl.finalDate&&(_cl.SD.today<=B||_cl.SD.today.getDate()==i)){A.appendChild(p);if(A.firstChild.data==t&&z==_cl.inputReturn.month.value.substr(4,6)-1){e.className="nullDat"}A.onclick=function(){_cl.returnSelection(this.firstChild.data,z,o);return false};e.appendChild(A)}else{var h=document.createElement("span");h.appendChild(document.createTextNode(i));h.className="nullDat";e.appendChild(h)}if(B<=_cl.SD.today){r.parentNode.childNodes[0].getElementsByTagName("a")[0].style.display="none"}c.appendChild(e);g++}b.appendChild(c);r.appendChild(b);var y=i;var v=2;if(z==11){var C=0;var q=o+1}else{C=z+1;q=o}var u=0;while((v<=6)&&(parseInt(u)<Gdate.dayMonth(z,o))){var k=document.createElement("tr");for(n=1;n<=7;n++){if(y<=Gdate.dayMonth(z,o)){var e=document.createElement("td");var p=document.createTextNode(y);var A=document.createElement("a");A.setAttribute("href","#");var B=new Date(o,z,y+1,0,0,0,0);if((B<=_cl.finalDate)&&(_cl.SD.today<B)||((_cl.SD.today.getDate()==y)&&(B.getMonth()>=z)&&(B.getMonth()>=o))){A.appendChild(p);if(A.firstChild.data==t&&z==_cl.inputReturn.month.value.substr(4,6)-1){e.className="nullDat"}e.appendChild(A);A.onclick=function(){_cl.returnSelection(this.firstChild.data,z,o);return false}}else{var a=document.createElement("span");a.appendChild(document.createTextNode(y));a.className="nullDat";e.appendChild(a);if(B>_cl.finalDate){r.parentNode.childNodes[0].getElementsByTagName("a")[1].style.display="none"}}u=y;k.appendChild(e)}else{var e=document.createElement("td");e.className="cellOtroMes";e.appendChild(document.createTextNode(""));k.appendChild(e)}y++}b.appendChild(k);v++}},returnSelection:function(f,b,h,c){var k=b+1;if(c==null){var g=_cl.inputReturn.day;var a=_cl.inputReturn.month;var l=_cl.inputReturn.nameDay}else{if(typeof(c[0])=="object"){var g=c[0];var a=c[1];var l=c[3]}else{var g=page.$(c[0]);var a=page.$(c[1]);var l=page.$(c[2])}}g.selectedIndex=parseInt(f)-1;var e=(_cl.changeMonth)?0:1;if(h>_cl.SD.today.getFullYear()){a.selectedIndex=parseInt(k)+(12*(h-_cl.SD.today.getFullYear())-_cl.SD.today.getMonth())-e}else{a.selectedIndex=parseInt(k)-_cl.SD.today.getMonth()-e}if(l!=null){l.innerHTML=_cl.returnDayWeek(new Date(k+"/"+f+"/"+h))}_cl.compareDates(f,b,h);if((c==null)){_cl.lay.style.display="none"}if(_cl.SD.type=="hotels"){Calendar.hotels.setDate()}},paint:function(g,a,h,b){var f=b.childNodes;for(i=f.length-1;i>=0;i--){b.removeChild(f[i])}the_table=document.createElement("table");the_table.cellPadding=0;the_table.cellSpacing=0;var c=document.getElementsByTagName("body")[0];c.appendChild(b);var e=document.createElement("div");e.appendChild(document.createTextNode("b"));e.style.height="1px";e.style.width="1px";e.style.border="1px solid red";e.style.display="inline";e.style.visibility="hidden";e.style.overflow="hidden";c.appendChild(e);_cl.paintNavigation(g,a,h,b);b.appendChild(the_table);_cl.paintDayOfWeek(_cl.SD.weekdays,the_table);_cl.paintMonth(g,a,h,the_table)},setType:function(a){_cl.servData.type=a}};
