getElementTextValue=function(a){if(a.childNodes.length>0){return a.firstChild.nodeValue}};priceLoader=function(a){this._instanceId=priceLoader.prototype._newInstance(this);this._instances=null;this._newInstance=null;this.div_id=a.div_id;this.tourcode=a.tourcode;this.brand=a.brand;if(a.noResults){this.noResults=a.noResults}this.currency_select=a.currency_select;if(a.IP_currency){this.setIpCurrency()}else{this.setCurrency(a.currency)}this.onParseSuccess=function(b){this.the_xml=b;this.createPriceGrid(b);if(a.callback){a.callback()}};if(a.url){this.loadRemote(a.url)}};priceLoader.prototype={_instaceId:null,_instances:new Array(),_newInstance:function(b){var a=this._instances.length;this._instances[a]=b;return a},_delegateCall:function(instanceId,mssg_str){eval("this._instances[instanceId]."+mssg_str)},div_id:"",currency:"",currencyName:"",currencyPrefix:"",tourcode:"",the_xml:"",noResults:"",loadRemote:function(b){var e=this.div_id+"_loading";var a=new Element("img").setProperties({id:e,src:"lib/images/loader.gif"});var d=new Element("div").setStyles({width:"100%",textAlign:"center",padding:"20px"});d.adopt(a);$(this.div_id).adopt(d);var c=new XML();c.loadRemote(b,{callback:this})},calendarDate:function(c){var b=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");var a=c.split("-");if(a[1].charAt(0)=="0"){a[1]=a[1].substr(1,1)}cDate=a[2]+" "+b[a[1]-1]+" "+a[0].substr(2,2);return cDate},AvailDisp:function(c,b,a){if(c==0){c="Contact Us"}else{if(c>=4||c=="4+"||c=="6+"){c="Available"}if(c<4){c="Limited"}}return c},paxSelect:function(d){var c=new Element("select");var a=new Element("option");c.setProperty("name","iPax");for(var b=1;(b<=d&&b<=4);b++){c.adopt(a.clone().setProperty("value",b).set("text",b))}return c},changeCurrency:function(a){this.setCurrency(a);this.createPriceGrid(this.the_xml)},setIpCurrency:function(){injectScript("https://www.trekam.net/trek/API/IP_Currency.asp?brand="+this.brand+"&callback=priceLoader.prototype._instances["+this._instanceId+"].setCurrency")},setCurrency:function(a){if(a=="ALL"){this.currency_select=true;a="GBP"}this.currency=a;switch(a){case"USD":this.currencyName="US Dollars";this.currencyPrefix="US$";break;case"GBP":this.currencyName="Pound Sterling";this.currencyPrefix="GBP£";break;case"EUR":this.currencyName="Euros";this.currencyPrefix="euro";break;case"AUD":this.currencyName="AU Dollars";this.currencyPrefix="AU$";break}},setLoadingCursors:function(a){a.addEvent("mouseover",function(){document.body.style.cursor="pointer"}).addEvent("mouseout",function(){document.body.style.cursor="default"}).addEvent("mousedown",function(){document.body.style.cursor="progress"})},allowCurrency:function(a){if(typeof(this.currency_select)=="boolean"){return this.currency_select}rules=this.currency_select[ip_country];if(rules){if(typeof(rules)=="boolean"){return rules}return(rules.indexOf(a)>-1)}return this.currency_select["default"]},currency_flags:function(b){var k=new Element("p");var d=this.currency_select;if(d){var f=new Element("img");var h=f.clone().setProperty("border","0").setProperty("priceLoader",this._instanceId);var e="./lib/images/flag_small_";if(this.allowCurrency("EUR")){var c=h.clone().setProperty("src",e+"eu.gif").addEvent("click",function(){priceLoader.prototype._delegateCall(this.getProperty("priceLoader"),'changeCurrency("EUR")')});if(this.currency!="EUR"){c.setOpacity(0.6)}this.setLoadingCursors(c)}if(this.allowCurrency("GBP")){var g=h.clone().setProperty("src",e+"uk.gif").addEvent("click",function(){priceLoader.prototype._delegateCall(this.getProperty("priceLoader"),'changeCurrency("GBP")')});if(this.currency!="GBP"){g.setOpacity(0.6)}this.setLoadingCursors(g)}if(this.allowCurrency("USD")){var a=h.clone().setProperty("src",e+"usa.gif").addEvent("click",function(){priceLoader.prototype._delegateCall(this.getProperty("priceLoader"),'changeCurrency("USD")')});if(this.currency!="USD"){a.setOpacity(0.6)}this.setLoadingCursors(a)}if(this.allowCurrency("AUD")){var j=h.clone().setProperty("src",e+"aud.gif").addEvent("click",function(){priceLoader.prototype._delegateCall(this.getProperty("priceLoader"),'changeCurrency("AUD")')});if(this.currency!="AUD"){j.setOpacity(0.6)}this.setLoadingCursors(j)}b.adopt(k.clone().addClass("flags").adopt(c).adopt(g).adopt(a).adopt(j))}},createPriceGrid:function(q){var d=q.getElementsByTagName("Trip");if(d.length==0){var F=new Element("div",{id:this.div_id}).set("html",this.noResults);F.replaces($(this.div_id));return}var L=new Element("table");var w=new Element("thead");var A=new Element("tbody");var k=new Element("tr");var G=new Element("td");var l=new Element("input");l.setProperty("type","hidden");var y=new Element("form");y.setProperty("method","POST");y.setProperty("action","https://www.trekam.net/trek/BookingDirect.asp");y.adopt(l.clone().setProperty("name","Currency").setProperty("value",this.currency)).adopt(l.clone().setProperty("name","Offer").setProperty("value","internal"));L.addClass("price-grid");var m=k.clone().adopt(G.clone().set("html","<hr noshade>").setProperty("colspan","5"));var e=k.clone().addClass("header").addClass("even");e.adopt(G.clone().set("text","Start / End Dates").setProperty("width","27%")).adopt(G.clone().set("text","Price\n"+this.currencyPrefix).setProperty("width","16%")).adopt(G.clone().set("text","Status").setProperty("width","17%")).adopt(G.clone().set("text","Number of Travellers").setProperty("width","15%")).adopt(G.clone().set("text","Book Online").setProperty("width","17%"));w.adopt(e);A.adopt(m.clone());var h=true;var n="";var I="";var z="";var E="";var C=function(M){$(this.getProperty("formId")).submit()};var r=new Element("input");r.setProperty("type","button").setProperty("value","Book Now");var c=0;for(i=0;i<d.length;i++){var p=k.clone();if(h){p.addClass("even")}h=!h;var H=getElementTextValue(d[i].getElementsByTagName("RecID")[0]);var j=getElementTextValue(d[i].getElementsByTagName("Depart")[0]);var o=getElementTextValue(d[i].getElementsByTagName("Return")[0]);var b=getElementTextValue(d[i].getElementsByTagName("AvailabilityReal")[0]);var a=d[i].getElementsByTagName("Cost");var D=d[i].getElementsByTagName("Closed")[0];var B=(D.childNodes.length>0)?D.firstChild.nodeValue:"N";var t=getElementTextValue(d[i].getElementsByTagName("Options")[0]);var f=getElementTextValue(d[i].getElementsByTagName("Availability")[0]);var v=d[i].getElementsByTagName("Offer")[0];if(v.childNodes.length>0){v=v.firstChild.nodeValue}else{v=""}var g=j.split("-");if(g[0]!=c){c=g[0];yearRow=k.clone();yearCell=G.clone();yearCell.set("text",c);yearCell.setStyle("font-weight","bold");yearCell.setStyle("padding-top","10px");yearCell.setStyle("padding-bottom","10px");yearRow.adopt(yearCell);A.adopt(yearRow)}for(ii=0;ii<a.length;ii++){if(a[ii].getElementsByTagName("Currency")[0].firstChild.nodeValue==this.currency){var I=this.currencyPrefix+getElementTextValue(a[ii].getElementsByTagName("Value")[0])}}var K=r.clone().setProperty("formId","booking-form-"+H);K.addEvent("click",C);b=parseInt(b);var x=G.clone();if(v>""){x.addClass("redtxt");I="Web Special\n"+I}x.set("text",I);var s=y.clone().setProperty("id","booking-form-"+H);s.adopt(l.clone().setProperty("name","recId").setProperty("value",H)).adopt(l.clone().setProperty("name","Offer"+H).setProperty("value",v));n=this.calendarDate(j);n+=" - ";n+=this.calendarDate(o);E=this.paxSelect(b);s.adopt(E);var z=this.AvailDisp(f,t,B);p.adopt(G.clone().set("text",n).addClass("dates")).adopt(x);statusEl=G.clone().set("text",z);if(z!="Closed"){statusEl.addClass("bluetxt")}p.adopt(statusEl);if((b>0)&&(z!="Closed")){p.adopt(G.clone().adopt(s)).adopt(G.clone().adopt(K))}else{p.adopt(G.clone()).adopt(G.clone())}A.adopt(p)}A.adopt(m.clone());L.adopt(w);L.adopt(A);var u=new Element("p");u.addClass("txt");var J='The following prices are in <span class="header">'+this.currencyName+"</span> and only valid for online bookings.";y.adopt(u.clone().set("html",J));this.currency_flags(y);y.adopt(L);y.replaces($(this.div_id));y.setProperty("id",this.div_id);document.body.style.cursor="default"},makeSortable:function(){var a=new SortingTable($(this.div_id).getElement("table"),{zebra:true});a.conversions=$A([{matcher:/(\d{2}) (\w{3}) (\d{2})/,conversion_function:function(e){var d=0;var c=$(e.row.getElementsByTagName("td")[this.sort_column]).get("text");c=this.conversion_matcher.exec(c);var b=["January","February","March","April","May","June","July","August","September","October","November","December"];for($i=0;$i<12;$i++){if(b[$i].indexOf(c[2])>-1){d=$i}}if(d<10){d="0"+d}return c[3]+d+c[1]}},{matcher:/.*£(\d*)/,conversion_function:function(d){var c=0;var b=$(d.row.getElementsByTagName("td")[this.sort_column]).get("text");b=this.conversion_matcher.exec(b);return"00000000000000000000000000000000".substr(0,32-b[1].length).concat(b[1])}},{matcher:/(\d*)%/,conversion_function:function(d){var c=0;var b=$(d.row.getElementsByTagName("td")[this.sort_column]).get("text");b=this.conversion_matcher.exec(b);b[1].replace("%","");return"00000000000000000000000000000000".substr(0,32-b[1].length).concat(b[1])}}]).extend(a.conversions);a.sort_by_header(a.headers[0])}};function loadPrices(a){var b="https://www.trekam.net/trek/API/HTTP-API-TourPrices.asp";b+="?TourCode="+a.tourcode;a.url=b;a.callback=function(){if(tabs){tabs.rerender()}};prices=new priceLoader(a);return prices};