var contactUsUrl="https://www.trekam.net/trek/BookingRequest.asp";getElementTextValue=function(a){if(a!=null&&a.childNodes.length>0){return a.firstChild.nodeValue}};priceLoader=function(a){this._instanceId=priceLoader.prototype._newInstance(this);this._instances=null;this._newInstance=null;this.settings=a;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;this.txt=MooTools.lang.get("priceLoader");this.onParseSuccess=function(b){this.the_xml=b;this.initCurrency()};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)},initCurrency:function(a){if(this.settings.IP_currency){this.setIpCurrency()}else{if(typeof(this.settings.currency)=="string"){this.changeCurrency(this.settings.currency)}else{this.currency=this.settings.currency;this._setIpCountryCurrency()}}},div_id:"",currency:"",currencyName:"",tourcode:"",the_xml:"",noResults:"",availabilityStatus:{contactUs:"Contactus",notAvailable:"Unavailable",available:"Available",limited:"Limited",guaranteed:"Guaranteed"},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=this.txt.monthsShort;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},availability:function(d,c,b,a){if(d<=0){if(this.settings.allowContact){return this.availabilityStatus.contactUs}else{return this.availabilityStatus.notAvailable}}if(d<4){return this.availabilityStatus.limited}if(a=="Y"){return this.availabilityStatus.guaranteed}if(d>=4||d=="4+"||d=="6+"){return this.availabilityStatus.available}return""},availabilityStatusClass:function(b,a){if(b<=0){if(this.settings.allowContact){return this.availabilityStatus.contactUs}else{return this.availabilityStatus.notAvailable}}if(a=="Y"){return this.availabilityStatus.guaranteed}return this.availabilityStatus.available},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);if(this.settings.callback){this.settings.callback()}},setIpCurrency:function(){injectScript("https://www.trekam.net/trek/API/IP_Currency.asp?brand="+this.brand+"&callback=priceLoader.prototype._instances["+this._instanceId+"].changeCurrency")},_setIpCountryCurrency:function(){injectScript("https://www.trekam.net/trek/API/IP_Country.asp?brand="+this.brand+"&callback=priceLoader.prototype._instances["+this._instanceId+"].setIpCountryCurrency")},setIpCountryCurrency:function(b){country_override=Browser.getQueryStringValue("country");if(country_override>""){b=country_override}var a=this.currency[b];if(a==null){a=this.currency["default"]}this.changeCurrency(a)},setCurrency:function(a){if(a=="ALL"){this.currency_select=true;a="GBP"}this.currency=a;this.currencyFormat=this.txt["priceFormat"+a];this.currencyName=this.txt["currencyName"+a]},formatPrice:function(a){return this.currencyFormat.replace("#price#",a)},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))}},getBookingFunction:function(){if(this.settings.googleAnalytics){return function(){form=$(this.getProperty("formId"));_gaq.push(["_linkByPost",form]);form.submit()}}else{return function(){$(this.getProperty("formId")).submit()}}},createPriceElement:function(d,b){var a="";var e="";for(ii=0;ii<d.length;ii++){if(d[ii].getElementsByTagName("Currency")[0].firstChild.nodeValue==this.currency){var a=getElementTextValue(d[ii].getElementsByTagName("Value")[0]);var e=getElementTextValue(d[ii].getElementsByTagName("Saving")[0])}}var c=new Element("td");if(b>""){discountEl=new Element("span");discountEl.addClass("price-discounted");discountEl.set("text",this.txt.pricePrefixNow+" "+this.formatPrice(a));c.adopt(discountEl);if(e!=null){savingEl=new Element("span");savingEl.addClass("price-saving");savingEl.set("text",this.txt.pricePrefixSave+" "+this.formatPrice(e));c.adopt(savingEl)}}else{c.set("text",this.formatPrice(a))}return c},createPriceGrid:function(p){var b=p.getElementsByTagName("Trip");if(b.length==0){var K=new Element("div",{id:this.div_id}).set("html",this.noResults);K.replaces($(this.div_id));return}var Q=new Element("table");var y=new Element("thead");var E=new Element("tbody");var h=new Element("tr");var L=new Element("td");var J=new Element("th");var j=new Element("input");j.setProperty("type","hidden");var B=new Element("form");B.setProperty("method","POST");B.setProperty("action","https://www.trekam.net/trek/BookingDirect.asp");B.adopt(j.clone().setProperty("name","Currency").setProperty("value",this.currency)).adopt(j.clone().setProperty("name","Offer").setProperty("value","internal"));Q.addClass("price-grid");var k=h.clone().adopt(L.clone().set("html","<hr noshade>").setProperty("colspan","5"));var c=h.clone().addClass("header").addClass("even");c.adopt(J.clone().set("text",this.txt.columnDates).setProperty("width","27%")).adopt(J.clone().set("text",this.txt.columnPrice).setProperty("width","16%")).adopt(J.clone().set("text",this.txt.columnStatus).setProperty("width","17%")).adopt(J.clone().set("text",this.txt.columnPax).setProperty("width","15%")).adopt(J.clone().set("text",this.txt.columnBook).setProperty("width","17%"));y.adopt(c);E.adopt(k.clone());var f=true;var l="";var D="";var I="";var C=function(S){var R=contactUsUrl+"?trip_code="+this.getProperty("tripCode");window.open(R,"","width=600,height=620,status=0,toolbar=0,location=0,scrollbars=1");return false};var r=new Element("input");r.setProperty("type","button").setProperty("value",this.txt.buttonBook);var z=new Element("input");z.setProperty("type","button").setProperty("value",this.txt.buttonCall);for(i=0;i<b.length;i++){var o=h.clone();if(f){o.addClass("even")}f=!f;var G=getElementTextValue(b[i].getElementsByTagName("Ref")[0]);var M=getElementTextValue(b[i].getElementsByTagName("RecID")[0]);var g=getElementTextValue(b[i].getElementsByTagName("Depart")[0]);var m=getElementTextValue(b[i].getElementsByTagName("Return")[0]);var a=getElementTextValue(b[i].getElementsByTagName("AvailabilityReal")[0]);var H=b[i].getElementsByTagName("Closed")[0];var F=(H.childNodes.length>0)?H.firstChild.nodeValue:"N";var t=getElementTextValue(b[i].getElementsByTagName("Options")[0]);var d=getElementTextValue(b[i].getElementsByTagName("Availability")[0]);var P=getElementTextValue(b[i].getElementsByTagName("Guaranteed")[0]);var x=b[i].getElementsByTagName("Offer")[0];if(x.childNodes.length>0){x=x.firstChild.nodeValue}else{x=""}var e=g.split("-");var D=this.availability(d,t,F,P);var n=this.availabilityStatusClass(d,P);var O=null;if(D!=this.availabilityStatus.notAvailable){O=r.clone().setProperty("formId","booking-form-"+M);O.addEvent("click",this.getBookingFunction())}a=parseInt(a);var A=this.createPriceElement(b[i].getElementsByTagName("Cost"),x);var q=B.clone().setProperty("id","booking-form-"+M);q.adopt(j.clone().setProperty("name","recId").setProperty("value",M)).adopt(j.clone().setProperty("name","Offer"+M).setProperty("value",x));l=this.calendarDate(g);l+=" - ";l+=this.calendarDate(m);I=this.paxSelect(a);q.adopt(I);o.set("year",e[0]);o.adopt(L.clone().set("text",l).addClass("dates")).adopt(A);var u=this.txt["availabilityAlt"+n];var s=new Element("span").setProperty("title",u).addClass("statusIndicator"+n);var v=this.txt["availability"+D];if(D==this.availabilityStatus.contactUs){link=new Element("A");link.setProperty("href",contactUsUrl+"?trip_code="+G).setProperty("target","_new");link.set("text",v);link.setProperty("tripCode",G);link.addEvent("click",C);link.addClass("contactLink");statusEl=L.clone().adopt(link);O=z.clone().setProperty("tripCode",G);O.addEvent("click",C)}else{if(D==this.availabilityStatus.notAvailable){statusEl=L.clone().set("text",v)}else{statusEl=L.clone().set("text",v);statusEl.addClass("bluetxt")}}s.inject(statusEl,"top");o.adopt(statusEl);if(O!=null){if(D!=this.availabilityStatus.contactUs){o.adopt(L.clone().adopt(q)).adopt(L.clone().adopt(O))}else{o.adopt(L.clone()).adopt(L.clone().adopt(O))}}else{o.adopt(L.clone()).adopt(L.clone())}E.adopt(o)}E.adopt(k.clone());Q.adopt(y);Q.adopt(E);var w=new Element("p");w.addClass("txt");var N=this.txt.intro+' <span class="header">'+this.currencyName+"</span>.";B.adopt(w.clone().set("html",N));this.currency_flags(B);B.adopt(Q);B.replaces($(this.div_id));B.setProperty("id",this.div_id);document.body.style.cursor="default"},insertYearBreaks:function(){year=0;table=$(this.div_id).getElement("table");tbody=table.getElement("tbody");rows=tbody.getElements("tr");rows.each(function(b,a){if(year!=b.get("year")){year=b.get("year");yearRow=new Element("tr");yearCell=new Element("td");yearCell.set("text",year);yearCell.setStyle("font-weight","bold");yearCell.setStyle("padding-top","10px");yearCell.setStyle("padding-bottom","10px");yearRow.adopt(yearCell);yearRow.inject(b,"before")}})},removeYearBreaks:function(){maxColumns=0;table=$(this.div_id).getElement("table");tbody=table.getElement("tbody");rows=tbody.getElements("tr");rows.each(function(a){cells=a.getElements("td");maxColumns=(cells.length>maxColumns)?cells.length:maxColumns});rows.each(function(a){cells=a.getElements("td");if(cells.length<maxColumns){a.dispose()}})},makeSortable:function(){table=$(this.div_id).getElement("table");var a=new SortingTable(table,{zebra:true});a.prices=this;a.oldSorting=a.sort_by_header;a.sort_by_header=function(b){this.prices.removeYearBreaks();this.oldSorting(b);if(a.headers[0]==b){this.prices.insertYearBreaks()}};a.conversions=$A([{matcher:/^(\d{4})$/,conversion_function:function(b){year=$(b.row.getElementsByTagName("td")[0]).get("text");year=this.conversion_matcher.exec(year);if(year!=null){return year[0]}}},{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);if(c!=null){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);comparisonValue="00000000000000000000000000000000".substr(0,32-b[1].length).concat(b[1]);if(b!=null){return comparisonValue}}},{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);if(b!=null){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.callback=function(){if(tabs){tabs.rerender()}};prices=new priceLoader(a);prices._createPriceGrid=prices.createPriceGrid;prices.createPriceGrid=function(c){this._createPriceGrid(c);this.insertYearBreaks()};prices.loadRemote(b);return prices};
