var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var availableMonths=[];function daysInMonth(c,b){var a=new Date(b,c,0);return a.getDate()}var createMonthSelection=function(b){var e=b.getElementsByTagName("Trip");if(e.length==0){return}var d;var a;availableMonths=[];var c=new Element("option");for(i=0;i<e.length;i++){departure=e[i].getElementsByTagName("Depart")[0].firstChild.nodeValue;year=departure.substr(0,4);month=departure.substr(5,2);if(month!=d){d=month;a=year;newOpt=c.clone().set("text",months[month-1]+" "+year);newOpt.value=(year+" "+month);availableMonths[availableMonths.length]=newOpt}}};var displayMonthSelection=function(e){var a=e.getElementsByTagName("Trip");if(a.length==0){return}var c=new Element("select");c.setProperty("priceLoader",this._instanceId);c.addEvent("change",function(){priceLoader.prototype._delegateCall(this.getProperty("priceLoader"),'changeMonth("'+this.getProperty("value")+'")')});var k=new Element("tr").setProperty("class","monthSelect");var j=new Element("td").setProperty("colspan","5");var h=new Element("span").set("text","Select your departure month: ");j.adopt(h);j.adopt(c);k.adopt(j);var b=$(this.div_id).getElement("table tr");if(b==null){return}k.inject(b,"after");var f=new Element("option");newOpt=f.clone().set("text","-- select --");c.adopt(newOpt);for(var d=0;d<availableMonths.length;d++){var g=availableMonths[d].clone();if(g.value==this.currentMonth){g.setProperty("selected","true")}c.adopt(g)}};var filterMonths=function(c,e){var d=c.createElement("ArrayOfTrip");var f=c.getElementsByTagName("Trip");if(f.length==0){return d}var a=e.substr(0,4);var b=e.substr(5,2);for(i=0;i<f.length;i++){departure=f[i].getElementsByTagName("Depart")[0].firstChild.nodeValue;year=departure.substr(0,4);e=departure.substr(5,2);if((year==a)&&(e==b)){currentTrip=f[i].cloneNode(true);d.appendChild(currentTrip)}}return d};var changeMonth=function(a){this.currentMonth=a;this.createPriceGrid(this.the_xml)};function loadMonthlyPrices(c){var a=new Date();var f=a.getMonth()+1;var b=a.getFullYear();var d=b+"-"+f+"-01";var g=escape("TourCode="+c.tourcode+"&OfferCode=internal&FromDate="+d+"&ToDate=&iLimit=&iStart=0");var e="https://www.trekam.net/trek/API/HTTP-API.asp?service=TourDeparturesLimited";e+="&params="+g;c.callback=function(){tabs.rerender()};prices=new priceLoader(c);prices.changeMonth=changeMonth;prices.createMonthSelection=createMonthSelection;prices.displayMonthSelection=displayMonthSelection;prices.oldFn=prices.createPriceGrid;prices.createPriceGrid=function(j){var h=filterMonths(this.the_xml,this.currentMonth);prices.oldFn(h)};prices.onParseSuccess=function(h){this.the_xml=h;this.createMonthSelection(h);if(availableMonths.length>0){this.currentMonth=availableMonths[0].value}else{if(f.toString().length==1){f="0"+f}this.currentMonth=b+" "+f}this.initCurrency()};prices.priceGrid=prices.createPriceGrid;prices.createPriceGrid=function(h){prices.priceGrid(h);prices.displayMonthSelection(h);if(tabs){tabs.rerender()}};prices.loadRemote(e);return prices};