LibManager.require("locations.LocationManager");
LibManager.require("Scheduler");
LibManager.require("cookie");
LibManager.getScriptParam("FastTrackController","lookup",function(_1){
if(_1==""){
_1="fullFastTrack";
}
LibManager.require("locations.lookups."+_1);
});
var FastTrackController={levelDetail:[],levelLocs:[],cookieFieldList:["startDay","startMonth","startYear","startMonthYearCombi","nights","adults","children","infants","starsRange","searchString"],formEl:null,ftSearchStringRow:"",ftRootLocId:"ftRootLoc",ftLocationsId:"ftLocations",init:function(){
Scheduler.schedule("ftLoaded","FastTrackController.attach('')");
},attach:function(_2){
if(_2==null){
_2="";
}
LocationManager.seperateTreeIntoLevels(locLookup_fastTrack,1,this.levelLocs);
var _3=$("ftRootLoc"+_2);
var _4=$("ftLocations"+_2);
var _5=_3;
do{
_5=_5.parentNode;
}while(_5.nodeName!="FORM");
this.formEl=_5;
var _6=this.getLocLevel(_3);
this.addLevelDetail("ftRootLoc",_6,"");
if(this.levelDetail[_6].cookieVal.length){
for(var i=0;i<_3.options.length;i++){
if(_3.options[i].value==this.levelDetail[_6].cookieVal){
_3.options[i].selected=true;
break;
}
}
}
Event.observe(_3,"change",this.changeChildLevel.bindAsEventListener(this),false);
switch(_6){
case (1):
var _8=this.createLocEls(_2,"Region",2);
this.appendLocSelect(_4,_8);
this.populateSel(_2,2);
Event.observe(_8,"change",this.changeChildLevel.bindAsEventListener(this),false);
var _9=this.createLocEls(_2,"Location",3);
this.appendLocSelect(_4,_9);
this.populateSel(_2,3);
Event.observe(_9,"change",this.onBotLocChange.bindAsEventListener(this),false);
break;
case (2):
var _9=this.createLocEls(_2,"Location",3);
this.appendLocSelect(_4,_9);
this.populateSel(_2,3);
Event.observe(_9,"change",this.onBotLocChange.bindAsEventListener(this),false);
break;
}
for(var i=0;i<this.cookieFieldList.length;i++){
var el=this.formEl[this.cookieFieldList[i]];
if(typeof el!="undefined"){
if(typeof el.nodeName=="undefined"){
for(var x=0;x<el.length;x++){
this.addCookieWatcher(el[x]);
}
}else{
this.addCookieWatcher(el);
}
}
}
var _c=($("ftDisplayStringSearch").value=="true");
if(!_c){
$("ftSearchStringRow").hide();
this.clearSearchString();
}else{
this.addWhiteBoxWatcher();
}
},addCookieWatcher:function(el){
var _e=getCookie(el.name);
if(_e.length){
switch(el.nodeName){
case ("SELECT"):
for(var i=0;i<el.options.length;i++){
if(el.options[i].value==_e){
el.options[i].selected=true;
break;
}
}
break;
case ("INPUT"):
switch(el.getAttribute("type")){
case ("text"):
el.value=_e;
break;
case ("radio"):
case ("checkbox"):
if(el.value==_e){
el.checked=true;
}
break;
}
break;
}
}
Event.observe(el,"change",this.setFieldCookie);
},addWhiteBoxWatcher:function(){
Event.observe($("ftRootLoc"),"change",this.clearSearchString);
Event.observe($("ftRegion"),"change",this.clearSearchString);
Event.observe($("ftLocation"),"change",this.clearSearchString);
},setFieldCookie:function(e){
var _11=Event.element(e);
setTimeout("setCookie( '"+_11.name+"', '"+_11.value+"', '', '/' )",0);
},addLevelDetail:function(sel,_13,_14){
this.levelDetail[_13]={level:_13,select:sel,title:_14,cookieVal:getCookie("ftLocLevel"+_13)};
},createLocEls:function(_15,_16,_17){
var _18=_16.toLowerCase();
var sel=document.createElement("select");
sel.name=_18+"Code";
sel.className="level-"+_17;
sel.id="ft"+_16+_15;
this.addLevelDetail("ft"+_16,_17,_18);
return sel;
},appendLocSelect:function(_1a,_1b){
var _1c=document.createElement("div");
_1c.className="formField";
_1c.appendChild(_1b);
var _1d=document.createElement("div");
_1d.className="formRow";
_1d.appendChild(_1c);
_1a.appendChild(_1d);
},populateSel:function(_1e,_1f){
var _20=this.levelDetail[_1f];
var _21=$(_20.select+_1e);
var _22=this.levelDetail[_1f-1].select+_1e;
var _23=$(_22);
var _24=_23.options[_23.options.selectedIndex].value;
if(_24.length){
var _25=LocationManager.getLookupBranchByCode(this.levelLocs,_1f-1,_24,true);
}else{
_25=[];
}
_21.options.length=0;
if(_25.length){
_21.options[0]=new Option("Choose an optional "+_20.title,"");
for(var i=0;i<_25.length;i++){
_21.options[_21.options.length]=new Option(_25[i][2].title,_25[i][2].code);
if(_25[i][2].code==_20.cookieVal){
_21.options[_21.options.length-1].selected=true;
}
}
_21.disabled=false;
}else{
_21.options[0]=new Option("No optional "+_20.title+" choices","");
_21.disabled=true;
}
},changeChildLevel:function(e){
var _28=Event.element(e);
var uid="";
if(_28.id.match("_")){
uid="_"+_28.id.split("_")[1];
}
var _2a=this.getLocLevel(_28)+1;
this.setLocCookie(_2a-1,_28.options[_28.options.selectedIndex].value);
do{
this.populateSel(uid,_2a);
_2a++;
}while(_2a<this.levelDetail.length);
},onBotLocChange:function(e){
var _2c=getTarg(e);
this.setLocCookie(this.getLocLevel(_2c),_2c.options[_2c.options.selectedIndex].value);
},setLocCookie:function(_2d,val){
setTimeout("setCookie( 'ftLocLevel"+_2d+"', '"+val+"', '', '/' );",0);
},clearSearchString:function(){
$("ftSearchString").value="";
setTimeout("deleteCookie('searchString', '/');",0);
},getLocLevel:function(el){
var _30=el.className.match(/.?level\-([0-9]+).?/i);
return parseInt(RegExp.$1);
}};
LibManager.isLoaded(["LocationManager","Scheduler","locLookup_fastTrack","getCookie","setCookie"],FastTrackController.init);

