var ChildAges={currentQuery:{ptcSelect:null,agesInput:null,ageRange:{min:0,max:99},ptc:null,callback:null},rowTemplate:new Template('<div class="paxAgeInput"><span>#{paxType} #{paxIndex} Age</span><select class="paxAge">#{options}</select></div>'),init:function(f,d,b){if(!$(f)){return}var g=$(f).id.split("_");var a=this._fieldName(g,"ptc");var c=this._fieldName(g,"ages");var e=this._fieldName(g,"ageSpec");this.currentQuery={ptcSelect:$(a),ageField:$(c),specField:$(e),ageRange:{min:d,max:b},callback:null}},doPopup:function(j,d,f,a,b){if(paxTypes.get(a)){this.ptc=paxTypes.get(a);if(d==null){d=this.ptc.minAge}if(f==null){f=this.ptc.maxAge}a=this.ptc.singular}else{this.ptc=null}this.init(j,d,f);this.currentQuery.callback=b;var g=$F(this.currentQuery.ptcSelect);if(g==0){this.currentQuery.ageField.value="";this.updateSpec(this.currentQuery.specField,this.currentQuery.ageField)}else{var h=$F(this.currentQuery.ageField).split("|");var e="";for(var c=0;c<g;c++){e+=this.rowTemplate.evaluate({paxType:this.ptc.singular,paxIndex:(c+1),options:this.options(d,f,(h.length>c?h[c]:null))})}$("ageRangeFloatyContent").update(e);$("ageRangeFloaty").style.width="308px";$("ageRangeFloaty").style.height="auto";Event.stopObserving($("ageRangeFloaty").select(".floatyCloseButton")[0],"click");Event.observe($("ageRangeFloaty").select(".floatyCloseButton")[0],"click",ChildAges.popupCancel);if(this.ptc!=null&&this.ptc.popup!=null&&(j.form!=null&&(j.form.id=="railForm"||j.form.id=="entryForm"))){$("ageRangeFloatyWarning").update(this.ptc.popup)}else{$("ageRangeFloatyWarning").update("")}showFloaty("ageRangeFloaty",null,{element:this.currentQuery.ptcSelect,left:(this.currentQuery.ptcSelect.hasClassName("bookTourPax")?-270:30),top:(this.currentQuery.ptcSelect.hasClassName("bookTourPax")?30:0)},{onActivate:function(){$("ageRangeFloaty").select("select")[0].focus()}})}},options:function(b,e,d){if(d==null){d=b}var a="";for(var c=b;c<=e;c++){a+='<option value="'+c+'"'+(c==d?' selected="selected"':"")+">"+c+"</option>"}return a},_fieldName:function(d,a){var b=d.indexOf("ptc");if(b==-1){b=d.indexOf("ageSpec")}if(b==-1){b=d.indexOf("ages")}var c=d.clone();c[b]=a;return $(c.flatten().compact().join("_"))},popupCommit:function(){hideFloaty("ageRangeFloaty");var c=$("ageRangeFloatyContent").select("select");var b=new Array();for(var a=0;a<c.length;a++){b[a]=$F(c[a])}this.currentQuery.ageField.value=b.join("|");if(this.currentQuery.specField){this.updateSpec(this.currentQuery.specField,this.currentQuery.ageField)}if(Object.isFunction(this.currentQuery.callback)){this.currentQuery.callback()}this.currentQuery.ptcSelect.focus()},popupCancel:function(){hideFloaty("ageRangeFloaty");AniteDDB.setValue(ChildAges.currentQuery.ptcSelect,$F(ChildAges.currentQuery.ageField).split("|").nonBlanks().length);this.currentQuery=null},updateSpec:function(d,c){if(!$(d)){return}if($F(c)==""){d.update("&nbsp;")}else{var a=$F(c).split("|").nonBlanks().flatten();var b=(a.length==1?"Age: ":"Ages: ")+a.join(", ");d.update(b)}},setAges:function(b,a){if(!$(b)){return}this.init(b);this.currentQuery.ageField.value=a.split("|").nonBlanks().flatten().join("|");this.updateSpec(this.currentQuery.specField,this.currentQuery.ageField)},refresh:function(a){this.init(a);if(this.currentQuery.specField){this.updateSpec(this.currentQuery.specField,this.currentQuery.ageField)}}};Object.extend(Array.prototype,{nonBlanks:function(){return this.select(function(a){return a!=null&&a!=""})}});function searchPanelGetAges(){var h=this.id.split("_");var g=h[h.length-1];var c=paxTypes.get(g);if(!c){return}if(c.ageRestricted){currentAgeRangeQuery={type:c,id:h.slice(0,h.length-2)};var d=[currentAgeRangeQuery.id,"ages",currentAgeRangeQuery.type.code];var b=$([currentAgeRangeQuery.id,"ptc",currentAgeRangeQuery.type.code].flatten().compact().join("_"));var e=$(d.flatten().compact().join("_"));if($(b)==null){alert([currentAgeRangeQuery.id,"ptc",currentAgeRangeQuery.type.code].flatten().compact().join("_"));return}if($F(b)==0){var f=[currentAgeRangeQuery.id,"ageSpec",currentAgeRangeQuery.type.code];var a=$(f.flatten().compact().join("_"));e.value="";ChildAges.updateSpec(a,e);if(typeof ciPaxChange=="function"){ciPaxChange.call(this)}}else{ChildAges.doPopup(b,c.minAge,c.maxAge,c.code,(typeof ciPaxChange=="function"?ciPaxChange.bindAsEventListener(this):null))}}};
