var createLateAvailGrid=function(n){var L=new Element("table");var A=new Element("tbody");var v=new Element("thead");var h=new Element("tr");var G=new Element("td");var F=new Element("th");var j=new Element("input");j.setProperty("type","hidden");var y=new Element("form");y.setProperty("method","POST");y.setProperty("action","https://www.trekam.net/trek/BookingDirect.asp");y.adopt(j.clone().setProperty("name","Currency").setProperty("value",this.currency)).adopt(j.clone().setProperty("name","Offer").setProperty("value","internal"));L.addClass("price-grid");var d=h.clone().addClass("header").addClass("even");d.adopt(F.clone().set("text",this.txt.columnDates).setProperty("width","26%")).adopt(F.clone().set("text","Tour Name").setProperty("width","19%")).adopt(F.clone().set("text","Days").setProperty("width","7%")).adopt(F.clone().set("text","Departs").setProperty("width","15%")).adopt(F.clone().set("text",this.txt.columnPrice).setProperty("width","13%")).adopt(F.clone().set("text",this.txt.columnPax).setProperty("width","10%")).adopt(F.clone().set("text",this.txt.columnBook).setProperty("width","10%"));v.adopt(d);var b=n.getElementsByTagName("Trip");var f=true;var k="";var z="";var E="";var o=new Element("input");o.setProperty("type","button").setProperty("value","Book");for(i=0;i<b.length;i++){var m=h.clone();if(!f){m.addClass("alt")}f=!f;var H=getElementTextValue(b[i].getElementsByTagName("RecID")[0]);var K=getElementTextValue(b[i].getElementsByTagName("Ref")[0]);var g=getElementTextValue(b[i].getElementsByTagName("Depart")[0]);var l=getElementTextValue(b[i].getElementsByTagName("Return")[0]);var c=getElementTextValue(b[i].getElementsByTagName("Name")[0]);var a=getElementTextValue(b[i].getElementsByTagName("AvailabilityReal")[0]);var C=b[i].getElementsByTagName("Closed")[0];var B=(C.childNodes.length>0)?C.firstChild.nodeValue:"N";var r=getElementTextValue(b[i].getElementsByTagName("Options")[0]);var e=getElementTextValue(b[i].getElementsByTagName("Availability")[0]);var u=b[i].getElementsByTagName("Offer")[0];if(u.childNodes.length>0){u=u.firstChild.nodeValue}else{u=""}if((!this.offers_only)||(this.offers_only&&(u>""))){var w=getElementTextValue(b[i].getElementsByTagName("Tour")[0]);w=w.replace(" ","");m.setAttribute("tour",w);var J=o.clone().setProperty("formId","booking-form-"+H);J.addEvent("click",this.getBookingFunction());a=parseInt(a);var x=this.createPriceElement(b[i].getElementsByTagName("Cost"),u);var p=y.clone().setProperty("id","booking-form-"+H);p.adopt(j.clone().setProperty("name","recId").setProperty("value",H)).adopt(j.clone().setProperty("name","Offer"+H).setProperty("value",u));k=this.calendarDate(g);k+=" - ";k+=this.calendarDate(l);E=this.paxSelect(a);p.adopt(E);var z=this.availability(e,r,B);m.adopt(G.clone().set("text",k).addClass("dates")).adopt(G.clone().set("text",c).addClass("Name")).adopt(G.clone().addClass("Days")).adopt(G.clone().addClass("Town")).adopt(x);if(a>0){m.adopt(G.clone().adopt(p)).adopt(G.clone().adopt(J))}else{m.adopt(G.clone()).adopt(G.clone())}A.adopt(m)}}L.adopt(v);L.adopt(A);var t=new Element("p");t.addClass("txt");var I='The following prices are in <span class="header">'+this.currencyName+"</span>.";y.adopt(t.clone().set("html",I));this.currency_flags(y);y.adopt(L);y.replaces($(this.div_id));y.setProperty("id",this.div_id);document.body.style.cursor="default";var q=new XML();q.div_id=this.div_id;var D={};D.onSuccess=function(s){XmlTours=s.getElementsByTagName("Tour");if(XmlTours.length==0){return false}$(this.div_id).getElements("tr").each(function(M){w=M.getAttribute("tour");if(w){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==w){tourUrl=XmlTours[i].getElementsByTagName("URL")[0].firstChild.nodeValue;tourLength=XmlTours[i].getElementsByTagName("Days")[0].firstChild.nodeValue;tourTown=XmlTours[i].getElementsByTagName("Departs")[0].firstChild.nodeValue;M.getElements("td").each(function(N){if(N.hasClass("Name")){tourname=N.get("text");N.empty();N.set("html",'<a href="'+tourUrl+'">'+tourname+"</td>")}if(N.hasClass("Days")){N.set("text",tourLength)}if(N.hasClass("Town")){N.set("text",tourTown)}})}}}}}})};if(this.tourDetailsXml){q.loadRemote(this.tourDetailsXml,D)}this.makeSortable()};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.initCurrency()};prices.loadRemote(a);return prices};
