var createLateAvailGrid=function(o){var O=new Element("table");var B=new Element("tbody");var w=new Element("thead");var j=new Element("tr");var I=new Element("td");var H=new Element("th");var k=new Element("input");k.setProperty("type","hidden");var z=new Element("form");z.setProperty("method","POST");z.setProperty("action","https://www.trekam.net/trek/BookingDirect.asp");z.adopt(k.clone().setProperty("name","Currency").setProperty("value",this.currency)).adopt(k.clone().setProperty("name","Offer").setProperty("value","internal"));O.addClass("price-grid");var e=j.clone().addClass("header").addClass("even");e.adopt(H.clone().set("text","Start / End Dates").setProperty("width","26%")).adopt(H.clone().set("text","Tour Name").setProperty("width","19%")).adopt(H.clone().set("text","Days").setProperty("width","7%")).adopt(H.clone().set("text","Departs").setProperty("width","15%")).adopt(H.clone().set("text","Price\n"+this.currencyPrefix).setProperty("width","13%")).adopt(H.clone().set("text","# of Travellers").setProperty("width","10%")).adopt(H.clone().set("text","Book").setProperty("width","10%"));w.adopt(e);var c=o.getElementsByTagName("Trip");var g=true;var l="";var K="";var A="";var G="";var D=function(s){$(this.getProperty("formId")).submit()};var p=new Element("input");p.setProperty("type","button").setProperty("value","Book");for(i=0;i<c.length;i++){var n=j.clone();if(!g){n.addClass("alt")}g=!g;var J=getElementTextValue(c[i].getElementsByTagName("RecID")[0]);var N=getElementTextValue(c[i].getElementsByTagName("Ref")[0]);var h=getElementTextValue(c[i].getElementsByTagName("Depart")[0]);var m=getElementTextValue(c[i].getElementsByTagName("Return")[0]);var d=getElementTextValue(c[i].getElementsByTagName("Name")[0]);var b=getElementTextValue(c[i].getElementsByTagName("AvailabilityReal")[0]);var a=c[i].getElementsByTagName("Cost");var E=c[i].getElementsByTagName("Closed")[0];var C=(E.childNodes.length>0)?E.firstChild.nodeValue:"N";var t=getElementTextValue(c[i].getElementsByTagName("Options")[0]);var f=getElementTextValue(c[i].getElementsByTagName("Availability")[0]);var v=c[i].getElementsByTagName("Offer")[0];if(v.childNodes.length>0){v=v.firstChild.nodeValue}else{v=""}if((!this.offers_only)||(this.offers_only&&(v>""))){var x=N.match(/^[A-Z]\w[A-Z]?/);n.setAttribute("tour",x);for(ii=0;ii<a.length;ii++){if(a[ii].getElementsByTagName("Currency")[0].firstChild.nodeValue==this.currency){var K=this.currencyPrefix+getElementTextValue(a[ii].getElementsByTagName("Value")[0])}}var M=p.clone().setProperty("formId","booking-form-"+J);M.addEvent("click",D);b=parseInt(b);var y=I.clone();if(v>""){y.addClass("redtxt");K="Web Special\n"+K}y.set("text",K);var q=z.clone().setProperty("id","booking-form-"+J);q.adopt(k.clone().setProperty("name","recId").setProperty("value",J)).adopt(k.clone().setProperty("name","Offer"+J).setProperty("value",v));l=this.calendarDate(h);l+=" - ";l+=this.calendarDate(m);G=this.paxSelect(b);q.adopt(G);var A=this.AvailDisp(f,t,C);n.adopt(I.clone().set("text",l).addClass("dates")).adopt(I.clone().set("text",d).addClass("Name")).adopt(I.clone().addClass("Days")).adopt(I.clone().addClass("Town")).adopt(y);if(b>0){n.adopt(I.clone().adopt(q)).adopt(I.clone().adopt(M))}else{n.adopt(I.clone()).adopt(I.clone())}B.adopt(n)}}O.adopt(w);O.adopt(B);var u=new Element("p");u.addClass("txt");var L='The following prices are in <span class="header">'+this.currencyName+"</span> and only valid for online bookings.";z.adopt(u.clone().set("html",L));this.currency_flags(z);z.adopt(O);z.replaces($(this.div_id));z.setProperty("id",this.div_id);document.body.style.cursor="default";var r=new XML();r.div_id=this.div_id;var F={};F.onSuccess=function(s){XmlTours=s.getElementsByTagName("Tour");if(XmlTours.length==0){return false}$(this.div_id).getElements("tr").each(function(P){x=P.getAttribute("tour");if(x){for(i=0;i<XmlTours.length;i++){TourRefNode=XmlTours[i].getElementsByTagName("Ref");if(TourRefNode.length==1){if(TourRefNode[0].childNodes.length>0){TourRef=TourRefNode[0].childNodes[0].nodeValue;if(TourRef==x){tourUrl=XmlTours[i].getElementsByTagName("URL")[0].firstChild.nodeValue;tourLength=XmlTours[i].getElementsByTagName("Days")[0].firstChild.nodeValue;tourTown=XmlTours[i].getElementsByTagName("Departs")[0].firstChild.nodeValue;P.getElements("td").each(function(Q){if(Q.hasClass("Name")){tourname=Q.get("text");Q.empty();Q.set("html",'<a href="'+tourUrl+'">'+tourname+"</td>")}if(Q.hasClass("Days")){Q.set("text",tourLength)}if(Q.hasClass("Town")){Q.set("text",tourTown)}})}}}}}})};if(this.tourDetailsXml){r.loadRemote(this.tourDetailsXml,F)}};var lateAvailability=function(b){var c=escape("Brand="+b.program);var a="https://www.trekam.net/trek/API/HTTP-API.asp";a+="?service=LateAvailabilityByBrand&params="+c;prices=new priceLoader(b);prices.program=b.program;prices.offers_only=false;if(b.offers_only){prices.offers_only=b.offers_only}if(b.tourDetailsXml){prices.tourDetailsXml=b.tourDetailsXml}prices.createPriceGrid=createLateAvailGrid;prices.onParseSuccess=function(d){this.the_xml=d;this.createPriceGrid(d);this.makeSortable()};prices.loadRemote(a);return prices};