jQuery.namespace("bravofly.apps");bravofly.apps.AbstractPage=function(proto){var i,self=this;for(i in proto){if(proto.hasOwnProperty(i)){bravofly.apps.AbstractPage.prototype[i]=proto[i];}}
if(this.ready instanceof Function){jQuery(document).ready(jQuery.proxy(self.ready,self));}
if(this.init instanceof Function){self.init.apply(self);}
return this;};bravofly.apps.AbstractPage.prototype={log:function(msg){typeof console!=="undefined"&&console.log instanceof Function&&console.log(msg);}};;jQuery.widget("bravofly.suggester",jQuery.ui.autocomplete,{options:{label:"",startupLabel:"",groupOpening:false,readonly:false,hasCaption:false,selectOnDocClick:true,modules:["airports"],tmplInput:"${label} - ${labelNote}",tmplItem:"${label} - <span class=\"sgt-note\">${labelNote}</span>",tmplGroup:"${label}"},requestIndex:0,GROUP_VALUE:100,CODE_NOT_FOUND:"NOTFOUND",CLASS_FOCUS:"ui-autocomplete-focus",CLASS_MENU_GROUP:"ui-menu-group",valueField:null,isMenuOpen:false,lastSearch:null,bufferSelection:"",elementLabel:"",_create:function(){jQuery.ui.autocomplete.prototype._create.apply(this,arguments);this.valueType=null;this.menu._setOption("blur",function(event,ui){});this.menu._setOption("focus",function(event,ui){});var self=this,nameBuffer=this.element[0].name,blurFunc=jQuery.proxy(this.blur,this);if(this.options.selectOnDocClick!==false){jQuery(document).bind("click",{instance:this},jQuery.proxy(this.blurByDocument,this));}
this.option("select",jQuery.proxy(this._joinFunc([this.option("select"),this.select]),this));this.option("open",jQuery.proxy(this._joinFunc([this.option("open"),this.open]),this));this.valueField=jQuery('<input type="hidden" name="'+nameBuffer+'" value="" />').insertBefore($(this.element));this.element[0].name=nameBuffer+"_label";if(this.isValidItem(this.options.item)){this.item(this.options.item);}else if(this.options.value){this.value(this.options.value);}else{this.element.val(this.options.startupLabel);this.valuteType="startupLabel";}
if(this.options.readonly){this.element.attr("readonly",true);}else{this.element.bind("click",jQuery.proxy(function(){this._resetField();},this));}
this.element.bind("focus",jQuery.proxy(this._joinFunc([this.option("focus"),this.focus]),this));this.element.bind("blur",jQuery.proxy(this._joinFunc([this.option("blur"),this.blur]),this));this.element.bind("keydown.autocomplete",jQuery.proxy(this._keyDown,this));},isValidItem:function(item){if(!(item instanceof Object)){return;}
return item.value&&item.label;},_joinFunc:function(funcList){return function(){for(var i=0,k=funcList.length;i<k;i+=1){if(funcList[i]&&funcList[i]instanceof Function){funcList[i].apply(this,arguments);}}};},keyDown:function(event){this._keyDown(event);},_keyDown:function(event){if(this.element.attr("readonly")){event.preventDefault();event.stopPropagation();return;}
var keyCode=jQuery.ui.keyCode;switch(event.keyCode){case keyCode.ESCAPE:event.preventDefault();event.stopPropagation();if(this.menu.element.is(":visible")){this._selectFirst();}else{this._setValueByItem(this.selectedItem);}
break;case keyCode.DOWN:this._manageScroll({menu:this.menu,event:event});this.reloadSelection();break;case keyCode.TAB:if(!this.selectedItem){this._selectFirst(event,false);}else{this.element.select();this._resetField();}
break;case keyCode.UP:this._manageScroll({menu:this.menu,event:event});this.reloadSelection();break;case keyCode.LEFT:case keyCode.RIGHT:case keyCode.SHIFT:this.frozeSelection();break;case keyCode.ENTER:case keyCode.NUMPAD_ENTER:if(this.menu.element.is(":visible")){event.preventDefault();event.stopPropagation();}
break;case keyCode.BACKSPACE:if(this.element.val().length<=3){jQuery.ui.autocomplete.prototype.close.apply(this,[event]);this.isMenuOpen=false;}
break;default:break;}},_manageScroll:function(item){var $item,$menuItems,edge=".ui-menu-item:not(."+this.CLASS_MENU_GROUP+")",menu=item.menu,event=item.event,code=event?event.keyCode:null,keyCode=jQuery.ui.keyCode;if(!menu.active){menu.activate(event,jQuery(menu.element.children(edge+":first")));return;}
$menuItems=menu.active[code==keyCode.DOWN?"nextAll":"prevAll"](":not(."+this.CLASS_MENU_GROUP+")");if(!this.options.groupOpening&&menu.active&&!menu.active.hasClass(this.CLASS_MENU_GROUP)){$next=$menuItems.eq(0);menu.activate(event,$next.length?$next:menu.element.children(code==keyCode.DOWN?edge+":first":edge+":last"));return;}
for(var i=0,l=$menuItems.length;i<l;i++){$item=jQuery($menuItems.get(i));if($item.is(":visible")){break;}}
if($item){menu.activate(event,$item);}},reloadSelection:function(){this.term=this.bufferSelection;},frozeSelection:function(){this.bufferSelection=this.term;this.term=this.element.val();},_selectFirst:function(event,stopEvents){var item=jQuery("li:not(."+this.CLASS_MENU_GROUP+"):first",this.menu.element[0]).data("item.autocomplete");if(this.menu.element.is(":visible")){this._trigger("selectitem",event,{item:item});this._trigger("select",event,{item:item});this.close();}else if(this.valueField.val()===""){this._trigger("selectitem",event,{item:item});this._trigger("select",event,{item:{code:this.CODE_NOT_FOUND}});}},_search:function(value,response){if(value.length<3){return;}
this._showLoader(true);this.source({"key":value,"modules":this.options.modules,"lang":this.options.lang||"en"},response||this.response);this.term=this.lastSearch=value;},_response:function(content){var data;this._showLoader(false);if(content&&content.items&&content.items instanceof Array){if(content.items.length){data=[content.items];jQuery.ui.autocomplete.prototype._response.call(this,data);}else{this.close();}}else{data=[{error:{code:100,message:"Malformed data"}}];this.close();}},_renderMenu:function(ul,items){var markup,$gli,$li,label,groupClass,groupClassItem,self=this,reReplaceLabel=/[^a-zA-Z0-9]/g,term=this.term||"",searchString=term.replace(/[?*\\\/+]/g,""),reSearch=new RegExp(searchString,"gi");jQuery.each(items[0],function(gIdx,group){label=group.label.replace(reReplaceLabel,"_");groupClass=self.options.groupCaptionClass;groupClassItem="group-"+label;group.entries=self._regroupByChild(group.entries);if(self.options.hasCaption===true&&groupClass&&groupClass!==""){$gli=jQuery("<li class='"+self.CLASS_MENU_GROUP+"'></li>").append(jQuery("<a></a>").html(group.label).addClass(groupClass)).appendTo(ul);$gli.data("item.autocomplete",{dom:$gli,type:group.type,label:group.label,value:self.GROUP_VALUE,itemClassName:groupClassItem,isOpen:group.options&&group.options.open?true:false});}
self.setTemplateCache(group.type,'input',group.inputTemplate||self.options.tmplInput);self.setTemplateCache(group.type,'item',group.itemTemplate||self.options.tmplItem);jQuery.each(group.entries,function(iIdx,item){item.type=group.type;$li=self._renderItem(item,reSearch);$li.addClass(groupClassItem).appendTo(ul);});});this.term="";},_renderItem:function(item,reSearch){var textItem="",indent=this.options.indent||"<span class=\"ui-menu-item-indent\">&gt;</span>";var itemClone=jQuery.extend(true,{},item);itemClone.label=itemClone.label.replace(reSearch,function(match_word){return"<b>"+match_word+"</b>";});textItem=this._processTmpl(this.getTemplateCache(item.type,'item'),itemClone);return jQuery("<li></li>").data("item.autocomplete",item).append(jQuery("<a></a>").html(item.child?indent+textItem:textItem));},_processTmpl:function(tmpl,data){var reBuff=/\$\{(\w+?)\}/g;if(!tmpl){return;}
return tmpl.replace(reBuff,function(key,match,idx,src){return data&&data[match]||"";});},setTemplateCache:function(type,area,template){var cache=this._tmplCache;if(!cache){cache={};}
if(!cache[type]){cache[type]={};}
cache[type][area]=template;this._tmplCache=cache;},getTemplateCache:function(type,area){var c=this._tmplCache;return c&&c[type]&&c[type][area];},_regroupByChild:function(list){var i,item,pItem,childBuff,self=this,order=[],parents={},newlist=[],result=[],orderedChildren;jQuery.each(list,function(idx,item){if(item.child){if(!parents[item.child]){parents[item.child]={item:null,children:null};}
if(!parents[item.child].children){parents[item.child].children={};}
parents[item.child].children[item.code]=item;}else{childBuff=parents[item.code];parents[item.code]={label:item.label,item:item,children:childBuff?childBuff.children:null};}});jQuery.each(parents,function(idx,parent){if(parent.item){result.push(parent.item);}
if(parent.children){orderedChildren=self.orderObjectOfObjectByKey(parent.children,'label');jQuery.each(orderedChildren,function(idx2,child){result.push(child);});}});return result;},orderObjectOfObjectByKey:function(obj,wantedKey){var i,name,size,baseKey,sortedKeys,keys=[],keyValuePairs={},result=[];for(baseKey in obj){keys.push(obj[baseKey][wantedKey]);keyValuePairs[obj[baseKey][wantedKey]]=baseKey;}
size=keys.length;sortedKeys=keys.sort();for(i=0;i<size;i+=1){name=sortedKeys[i];result.push(obj[keyValuePairs[name]]);}
return result;},_normalize:function(items){return items;},_initSource:function(){var self=this,array,url;if(jQuery.isArray(this.options.source)){array=this.options.source;this.source=function(request,response){response($.ui.autocomplete.filter(array,request.term));};}else if(typeof this.options.source==="string"){url=this.options.source;this.source=function(request,response){if(request&&request.key&&request.key.length<3){return;}
if(self.xhr){self.xhr.abort();self.xhr=null;}
self.requestIndex+=1;self.xhr=jQuery.ajax({"url":url,"data":jQuery.param(request,true),"autocompleteRequest":self.requestIndex,"success":function(data,status,xhr){if(this.autocompleteRequest===self.requestIndex){response(data);}},"error":function(){if(this.autocompleteRequest===self.requestIndex){response([]);}}});};}else{this.source=this.options.source;}},close:function(event){var self=this;if(this.selectedItem&&this.selectedItem.value!=this.GROUP_VALUE){jQuery.ui.autocomplete.prototype.close.apply(this,[event]);this.isMenuOpen=false;setTimeout(function(){self.menu.element.empty();},1);}},open:function(event){this.isMenuOpen=true;this.element.trigger("open");},select:function(event,data){var tmpl,item=this.setItem(data),keyCode=jQuery.ui.keyCode;this.element.select();if(event&&event.keyCode!=keyCode.TAB){event.preventDefault();event.stopPropagation();}
this.selectedItem=item;this.elementLabel=this._processTmpl(this.getTemplateCache(item.type,'input'),item);this._trigger("selecteditem",event,{item:item});if(event){this._trigger("selected",event,{item:item});}
return false;},setItem:function(data){if(!data||!data.item){return;}
var item=data.item;if(item.value===this.GROUP_VALUE&&this.option.groupOpening){this.selectGroup.call(this,item);}else if(item.code===this.CODE_NOT_FOUND){item.code="";item.type="";item.value="";item.label="";this.element.val(this.options.startupLabel||"");this.valueField.val("");this.valueType=null;}else{this._setValueByItem(item);}
return item;},_resetField:function(){this.element.val("");this.term="";},focus:function(event,data){if(this.element.val()!==""){this.element.select();}
this.element.addClass(this.CLASS_FOCUS);event.preventDefault();event.stopPropagation();},blur:function(event,data){this.element.removeClass(this.CLASS_FOCUS);if(data&&data.item&&data.item.value!==this.GROUP_VALUE){this.element.val(data.item.label+" ---");}
if(this.valueField.val()!==""&&this.element.val().length<3){this.element.val(this.elementLabel);}},blurByDocument:function(event){if(!this.isMenuOpen){return;}
this._selectFirst();},selectGroup:function(data){jQuery("."+data.itemClassName,this.menu.element).each(function(idx,item){jQuery(item)[data.isOpen?"hide":"show"]();});data.isOpen=!data.isOpen;},label:function(){return this.element.val();},item:function(item){if(item){this.valueField.val(item.value);this.element.val(item.label);this.elementLabel=item.label;this.valueType=item.type;this.selectedItem=item;}else{return{label:this.label(),value:this.value(),type:this.valueType};}},value:function(value){var self=this,val=null;if(value&&value!==""){this._search(value,function(data){self._silentResponse.call(self,value,data);});}else{val=this.valueField.val();}
return val;},_silentResponse:function(value,data){var item=this._searchByCode(data,value);this._setValueByItem(item);this.selectedItem=item;this.elementLabel=this._processTmpl(this.getTemplateCache(item.type,'input'),item);this._showLoader(false);this._trigger("selecteditem");this._trigger("selected",null,data);},_setValueByItem:function(item){if(!item||!item.label||!item.code){return;}
this.element.val(this._processTmpl(this.getTemplateCache(item.type,'input'),item));this.valueField.val(item.code);this.valueType=item.type;},_searchByCode:function(raw,value){if(!raw||raw.data){return;}
var group,items,iSize,found=null,data=raw.items;for(var gl=data.length-1;gl>-1;gl-=1){group=data[gl];for(items=group.entries,iSize=items.length-1;iSize>-1;iSize-=1){if(items[iSize].code===value){found=items[iSize];break;}}}
return found;},_move:function(direction,event){var val;if(!this.menu.element.is(":visible")){if(this.element.val()===""){this.lastSearch=null;}
this.search(this.lastSearch,event);return;}
if(this.menu.first()&&(/^previous/).test(direction)||this.menu.last()&&(/^next/).test(direction)){this.menu.deactivate();return;}},_showLoader:function(load){this.element[load?"addClass":"removeClass"]("sgt-loading");}});;$.namespace("bravofly.apps");bravofly.apps.Tabs=function(config){var id=config.id,indexSelected=config.indexSelected;this._observers=config.observers;this._root=jQuery("#"+id);this._tabsWrapper=this._root.find(".tabs");this._tabsList=this._root.find(".tab");this._panelsList=this._root.find(".panel");this._initBehaviour();this._showPanel(indexSelected);this._highlightTab(indexSelected);};bravofly.utils.inheritance.setProtoGently(bravofly.apps.Tabs,{_getIndexByTab:function(tabDomEl){var len=this._tabsList.length,i=0;while(i<len){var currentTab=this._tabsList[i];if(currentTab===tabDomEl){return i;}
i++;}
return-1;},_initBehaviour:function(){throw new Error("This class cannot be instantiated as it is abstract. Subclass it instead!");},_showPanel:function(indexPanelToShow){var len=this._tabsList.length,i=0;while(i<len){var currentPanel=this._panelsList[i];jQuery(currentPanel).css("display","none");i++;}
if(typeof indexPanelToShow!=="udenfined"){jQuery(this._panelsList[indexPanelToShow]).css("display","block");}},_highlightTab:function(indexTabToShow){var len=this._tabsList.length,i=0;while(i<len){var currentTab=this._tabsList[i];jQuery(currentTab).removeClass("tab-on");jQuery(currentTab).addClass("tab-off");i++;}
if(typeof indexTabToShow!=="udenfined"){jQuery(this._tabsList[indexTabToShow]).removeClass("tab-off");jQuery(this._tabsList[indexTabToShow]).addClass("tab-on");}}});bravofly.apps.Tabs.ev={TAB_SWITCH:0};;$.namespace("bravofly.apps");bravofly.apps.ClickTabs=function(config){bravofly.apps.Tabs.call(this,config);}
bravofly.utils.inheritance.extend(bravofly.apps.ClickTabs,bravofly.apps.Tabs,{_initBehaviour:function(){this._tabsWrapper.bind("click",jQuery.proxy(function(e){if(jQuery(e.target).hasClass("tablink")){return true;}
e.preventDefault();var indexPanelToShow=this._getIndexByTab(e.target);if(indexPanelToShow>-1){this._showPanel(indexPanelToShow);this._highlightTab(indexPanelToShow);}},this));}});;jQuery.namespace("bravofly.apps.errors");bravofly.apps.errors.InlineErrorManager=({_className:'error',_instance:null,_errorBox:null,_errorBoxInner:null,_erroneousFormElement:null,_scrollAnimationEnabled:true,_reset:function(){this._erroneousFormElement&&this._erroneousFormElement.removeClass("erroneousField");this._erroneousFormElement=null;this._errorBoxInner.text("");jQuery(this._errorBox).css("display","none");},_getNextScrollPosition:function(to,from,timePassed,duration){var direction=(from-to>0)?"up":"down";var delta=Math.abs(from-to);var timeProportionalDelta=delta*(timePassed/duration);if(direction==="down"){return from+timeProportionalDelta;}else{return from-timeProportionalDelta;}},_isIE6:function(){return(/MSIE 6\.0/).test(navigator.userAgent);},_smoothScrollTo:function(toY,onEnd){var startTime=new Date().getTime(),duration=100,fromY=jQuery(document).scrollTop(),that=this;(function(){var timePassed=new Date().getTime()-startTime;if(timePassed<duration){var nextY=that._getNextScrollPosition(toY,fromY,timePassed,duration);window.scrollTo(0,nextY);setTimeout(arguments.callee,0);}else{window.scrollTo(0,toY);onEnd&&onEnd();}})();},_positionByStrategy:function(strategy,formEl){var el=jQuery(formEl),elOffset=el.offset();if(strategy===bravofly.apps.errors.InlineErrorManager.displayStrategy.UNDER){this._errorBox.className="under "+this._className+" under-"+this._className;jQuery(this._errorBox).css({"display":"block","left":elOffset.left+"px","top":elOffset.top+30+"px"});}else if(strategy===bravofly.apps.errors.InlineErrorManager.displayStrategy.RIGHT){this._errorBox.className="right "+this._className+" right-"+this._className;jQuery(this._errorBox).css({"display":"block","left":elOffset.left+el.width()+15+"px","top":elOffset.top+"px"});}else if(strategy===bravofly.apps.errors.InlineErrorManager.displayStrategy.OVER){this._errorBox.className="over "+this._className+" over-"+this._className;elOffset.top=elOffset.top-parseInt(jQuery(this._errorBox).css("height"),10)-30;jQuery(this._errorBox).css({"display":"block","left":elOffset.left+"px","top":elOffset.top+"px"});}
return elOffset;},displayError:function(msg,formEl,displayStrategy,displayClass){var that=this;displayStrategy=displayStrategy||bravofly.apps.errors.InlineErrorManager.displayStrategy.UNDER;this._erroneousFormElement=jQuery(formEl);if(!this._errorBox||!this._erroneousFormElement.length||this._isIE6()){alert(msg);formEl&&formEl.focus();return;}
this._className=displayClass||'error';this._errorBoxInner.text(msg);this._erroneousFormElement.addClass("erroneousField");var elementOffSet=this._positionByStrategy(displayStrategy,formEl);if(this._scrollAnimationEnabled===true){this._smoothScrollTo(elementOffSet.top-20,function(){jQuery(formEl).focus();});}},displayMessage:function(msg,formEl,displayStrategy){this.displayError(msg,formEl,displayStrategy,"info");},getInstance:function(){if(!this.instance){this._instance=this.init();}
return this._instance;},enableScrollAnimation:function(enabled){this._scrollAnimationEnabled=enabled;},init:function(){var that=this;this._errorBox=document.createElement("div");this._errorBox.id="flyInlineErrorBox";this._errorBox.className="under";document.body.appendChild(this._errorBox);this._errorBox.innerHTML="<div id='innerFlyInlineErrorBox'></div>"+"<div id='errorPointer'></div>";this._errorBoxInner=jQuery("#innerFlyInlineErrorBox");jQuery(document.body).bind("click",function(){that._reset();});jQuery(document.body).bind("keydown",function(){that._reset();});return this;}});bravofly.apps.errors.InlineErrorManager.displayStrategy={UNDER:1,RIGHT:2,OVER:3};;(function(){var hexcase=0;var b64pad="";function hex_md5(s){return rstr2hex(rstr_md5(str2rstr_utf8(s)));}
function b64_md5(s){return rstr2b64(rstr_md5(str2rstr_utf8(s)));}
function any_md5(s,e){return rstr2any(rstr_md5(str2rstr_utf8(s)),e);}
function hex_hmac_md5(k,d)
{return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)));}
function b64_hmac_md5(k,d)
{return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)));}
function any_hmac_md5(k,d,e)
{return rstr2any(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)),e);}
function md5_vm_test()
{return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72";}
function rstr_md5(s)
{return binl2rstr(binl_md5(rstr2binl(s),s.length*8));}
function rstr_hmac_md5(key,data)
{var bkey=rstr2binl(key);if(bkey.length>16)bkey=binl_md5(bkey,key.length*8);var ipad=Array(16),opad=Array(16);for(var i=0;i<16;i++)
{ipad[i]=bkey[i]^0x36363636;opad[i]=bkey[i]^0x5C5C5C5C;}
var hash=binl_md5(ipad.concat(rstr2binl(data)),512+data.length*8);return binl2rstr(binl_md5(opad.concat(hash),512+128));}
function rstr2hex(input)
{try{hexcase;}catch(e){hexcase=0;}
var hex_tab=hexcase?"0123456789ABCDEF":"0123456789abcdef";var output="";var x;for(var i=0;i<input.length;i++)
{x=input.charCodeAt(i);output+=hex_tab.charAt((x>>>4)&0x0F)
+hex_tab.charAt(x&0x0F);}
return output;}
function rstr2b64(input)
{try{b64pad;}catch(e){b64pad='';}
var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var output="";var len=input.length;for(var i=0;i<len;i+=3)
{var triplet=(input.charCodeAt(i)<<16)|(i+1<len?input.charCodeAt(i+1)<<8:0)|(i+2<len?input.charCodeAt(i+2):0);for(var j=0;j<4;j++)
{if(i*8+j*6>input.length*8)output+=b64pad;else output+=tab.charAt((triplet>>>6*(3-j))&0x3F);}}
return output;}
function rstr2any(input,encoding)
{var divisor=encoding.length;var i,j,q,x,quotient;var dividend=Array(Math.ceil(input.length/2));for(i=0;i<dividend.length;i++)
{dividend[i]=(input.charCodeAt(i*2)<<8)|input.charCodeAt(i*2+1);}
var full_length=Math.ceil(input.length*8/(Math.log(encoding.length)/Math.log(2)));var remainders=Array(full_length);for(j=0;j<full_length;j++)
{quotient=Array();x=0;for(i=0;i<dividend.length;i++)
{x=(x<<16)+dividend[i];q=Math.floor(x/divisor);x-=q*divisor;if(quotient.length>0||q>0)
quotient[quotient.length]=q;}
remainders[j]=x;dividend=quotient;}
var output="";for(i=remainders.length-1;i>=0;i--)
output+=encoding.charAt(remainders[i]);return output;}
function str2rstr_utf8(input)
{var output="";var i=0;var x,y;while(i<input.length)
{x=input.charCodeAt(i);y=i+1<input.length?input.charCodeAt(i+1):0;if(0xD800<=x&&x<=0xDBFF&&0xDC00<=y&&y<=0xDFFF)
{x=0x10000+((x&0x03FF)<<10)+(y&0x03FF);i++;}
if(x<=0x7F)
output+=String.fromCharCode(x);else if(x<=0x7FF)
output+=String.fromCharCode(0xC0|((x>>>6)&0x1F),0x80|(x&0x3F));else if(x<=0xFFFF)
output+=String.fromCharCode(0xE0|((x>>>12)&0x0F),0x80|((x>>>6)&0x3F),0x80|(x&0x3F));else if(x<=0x1FFFFF)
output+=String.fromCharCode(0xF0|((x>>>18)&0x07),0x80|((x>>>12)&0x3F),0x80|((x>>>6)&0x3F),0x80|(x&0x3F));i+=1;}
return output;}
function str2rstr_utf16le(input)
{var output="";for(var i=0;i<input.length;i++)
output+=String.fromCharCode(input.charCodeAt(i)&0xFF,(input.charCodeAt(i)>>>8)&0xFF);return output;}
function str2rstr_utf16be(input)
{var output="";for(var i=0;i<input.length;i++)
output+=String.fromCharCode((input.charCodeAt(i)>>>8)&0xFF,input.charCodeAt(i)&0xFF);return output;}
function rstr2binl(input)
{var i,output=Array(input.length>>2);for(i=0;i<output.length;i++)
output[i]=0;for(i=0;i<input.length*8;i+=8)
output[i>>5]|=(input.charCodeAt(i/8)&0xFF)<<(i%32);return output;}
function binl2rstr(input)
{var output="";for(var i=0;i<input.length*32;i+=8)
output+=String.fromCharCode((input[i>>5]>>>(i%32))&0xFF);return output;}
function binl_md5(x,len)
{x[len>>5]|=0x80<<((len)%32);x[(((len+64)>>>9)<<4)+14]=len;var a=1732584193;var b=-271733879;var c=-1732584194;var d=271733878;for(var i=0;i<x.length;i+=16)
{var olda=a;var oldb=b;var oldc=c;var oldd=d;a=md5_ff(a,b,c,d,x[i+0],7,-680876936);d=md5_ff(d,a,b,c,x[i+1],12,-389564586);c=md5_ff(c,d,a,b,x[i+2],17,606105819);b=md5_ff(b,c,d,a,x[i+3],22,-1044525330);a=md5_ff(a,b,c,d,x[i+4],7,-176418897);d=md5_ff(d,a,b,c,x[i+5],12,1200080426);c=md5_ff(c,d,a,b,x[i+6],17,-1473231341);b=md5_ff(b,c,d,a,x[i+7],22,-45705983);a=md5_ff(a,b,c,d,x[i+8],7,1770035416);d=md5_ff(d,a,b,c,x[i+9],12,-1958414417);c=md5_ff(c,d,a,b,x[i+10],17,-42063);b=md5_ff(b,c,d,a,x[i+11],22,-1990404162);a=md5_ff(a,b,c,d,x[i+12],7,1804603682);d=md5_ff(d,a,b,c,x[i+13],12,-40341101);c=md5_ff(c,d,a,b,x[i+14],17,-1502002290);b=md5_ff(b,c,d,a,x[i+15],22,1236535329);a=md5_gg(a,b,c,d,x[i+1],5,-165796510);d=md5_gg(d,a,b,c,x[i+6],9,-1069501632);c=md5_gg(c,d,a,b,x[i+11],14,643717713);b=md5_gg(b,c,d,a,x[i+0],20,-373897302);a=md5_gg(a,b,c,d,x[i+5],5,-701558691);d=md5_gg(d,a,b,c,x[i+10],9,38016083);c=md5_gg(c,d,a,b,x[i+15],14,-660478335);b=md5_gg(b,c,d,a,x[i+4],20,-405537848);a=md5_gg(a,b,c,d,x[i+9],5,568446438);d=md5_gg(d,a,b,c,x[i+14],9,-1019803690);c=md5_gg(c,d,a,b,x[i+3],14,-187363961);b=md5_gg(b,c,d,a,x[i+8],20,1163531501);a=md5_gg(a,b,c,d,x[i+13],5,-1444681467);d=md5_gg(d,a,b,c,x[i+2],9,-51403784);c=md5_gg(c,d,a,b,x[i+7],14,1735328473);b=md5_gg(b,c,d,a,x[i+12],20,-1926607734);a=md5_hh(a,b,c,d,x[i+5],4,-378558);d=md5_hh(d,a,b,c,x[i+8],11,-2022574463);c=md5_hh(c,d,a,b,x[i+11],16,1839030562);b=md5_hh(b,c,d,a,x[i+14],23,-35309556);a=md5_hh(a,b,c,d,x[i+1],4,-1530992060);d=md5_hh(d,a,b,c,x[i+4],11,1272893353);c=md5_hh(c,d,a,b,x[i+7],16,-155497632);b=md5_hh(b,c,d,a,x[i+10],23,-1094730640);a=md5_hh(a,b,c,d,x[i+13],4,681279174);d=md5_hh(d,a,b,c,x[i+0],11,-358537222);c=md5_hh(c,d,a,b,x[i+3],16,-722521979);b=md5_hh(b,c,d,a,x[i+6],23,76029189);a=md5_hh(a,b,c,d,x[i+9],4,-640364487);d=md5_hh(d,a,b,c,x[i+12],11,-421815835);c=md5_hh(c,d,a,b,x[i+15],16,530742520);b=md5_hh(b,c,d,a,x[i+2],23,-995338651);a=md5_ii(a,b,c,d,x[i+0],6,-198630844);d=md5_ii(d,a,b,c,x[i+7],10,1126891415);c=md5_ii(c,d,a,b,x[i+14],15,-1416354905);b=md5_ii(b,c,d,a,x[i+5],21,-57434055);a=md5_ii(a,b,c,d,x[i+12],6,1700485571);d=md5_ii(d,a,b,c,x[i+3],10,-1894986606);c=md5_ii(c,d,a,b,x[i+10],15,-1051523);b=md5_ii(b,c,d,a,x[i+1],21,-2054922799);a=md5_ii(a,b,c,d,x[i+8],6,1873313359);d=md5_ii(d,a,b,c,x[i+15],10,-30611744);c=md5_ii(c,d,a,b,x[i+6],15,-1560198380);b=md5_ii(b,c,d,a,x[i+13],21,1309151649);a=md5_ii(a,b,c,d,x[i+4],6,-145523070);d=md5_ii(d,a,b,c,x[i+11],10,-1120210379);c=md5_ii(c,d,a,b,x[i+2],15,718787259);b=md5_ii(b,c,d,a,x[i+9],21,-343485551);a=safe_add(a,olda);b=safe_add(b,oldb);c=safe_add(c,oldc);d=safe_add(d,oldd);}
return Array(a,b,c,d);}
function md5_cmn(q,a,b,x,s,t)
{return safe_add(bit_rol(safe_add(safe_add(a,q),safe_add(x,t)),s),b);}
function md5_ff(a,b,c,d,x,s,t)
{return md5_cmn((b&c)|((~b)&d),a,b,x,s,t);}
function md5_gg(a,b,c,d,x,s,t)
{return md5_cmn((b&d)|(c&(~d)),a,b,x,s,t);}
function md5_hh(a,b,c,d,x,s,t)
{return md5_cmn(b^c^d,a,b,x,s,t);}
function md5_ii(a,b,c,d,x,s,t)
{return md5_cmn(c^(b|(~d)),a,b,x,s,t);}
function safe_add(x,y)
{var lsw=(x&0xFFFF)+(y&0xFFFF);var msw=(x>>16)+(y>>16)+(lsw>>16);return(msw<<16)|(lsw&0xFFFF);}
function bit_rol(num,cnt)
{return(num<<cnt)|(num>>>(32-cnt));}
if(!window.bravofly)
{bravofly={};}
if(!bravofly.utils)
{bravofly.utils={};}
bravofly.utils.MD5={hex_md5:hex_md5,hex_hmac_md5:hex_hmac_md5,b64_md5:b64_md5,b64_hmac_md5:b64_hmac_md5,any_md5:any_md5,rstr2hex:rstr2hex,rstr_md5:rstr_md5,str2rstr_utf8:str2rstr_utf8};})();;jQuery.namespace("bravofly.utils");bravofly.utils.XHRCache=function(config){this.cache={};this.limit=(config&&config.limit)||null;};bravofly.utils.XHRCache.prototype={cache:null,limit:null,data:{},config:{},add:function(key,value,settings){if(!value||value.readyState===undefined){return false;}
this.stopLoading();this.cache[key]=value;this.config[key]=settings;return true;},getXHR:function(key){return this.cache[key];},getData:function(key){return this.data[key];},setData:function(key,data){this.data[key]=data;},getConfig:function(key){return this.config[key];},setConfig:function(key,data){this.config[key]=data;},remove:function(key){if(this.cache&&this.cache[key]){if(typeof this.cache[key].abort!="unknown"){this.cache[key]["_aborted"]=true;this.cache[key].abort&&this.cache[key].abort();}
this.cache[key]=null;delete this.cache[key];}
if(this.data){this.data[key]=null;delete this.data[key];}
if(this.config){this.config[key]=null;delete this.config[key];}},exists:function(key){return this.cache[key]!=undefined;},ready:function(key){var xhr=this.cache[key];return!!(xhr&&xhr.readyState===4);},stopLoading:function(){var key,cache=this.cache;for(key in cache){if(!cache.hasOwnProperty(key)){return;}
if(cache[key].readyState!=4){this.remove(key);}}}};;jQuery.namespace("bravofly.apps.capitanprice");bravofly.apps.capitanprice.DataVO=function(config){if(config){this.setData(config);}};bravofly.apps.capitanprice.DataVO.prototype={params:null,setData:function(data){this.params=this._formatParameters(data);},getData:function(){this.params.p=this.getMD5();return this.params;},getMD5:function(){return this._generateMD5(this.params);},isValid:function(){return this._validateParameters(this.params);},_formatParameters:function(config){var p={a:config.arrivalAirport||config.a,d:config.departureAirport||config.d,x:config.xrate||config.x,l:config.locale||config.l,m:config.currency||config.m,r:this._formatDate(config.returnDate||config.r),o:this._formatDate(config.outboundDate||config.o),outboundFrom:this._formatDate(config.fromDepartureDate),outboundTo:this._formatDate(config.toDepartureDate),returnFrom:this._formatDate(config.fromReturnDate),returnTo:this._formatDate(config.toReturnDate)};if(!p.returnTo){delete p.returnTo;}
if(!p.returnFrom){delete p.returnFrom;}
if(!p.r){delete p.r;}
return p;},_formatDate:function(d){var month,day;if(typeof(d)==="string"){return d;}
if(d instanceof Date){month=d.getMonth()+1;day=d.getDate();d=d.getFullYear()+""+(month<10?"0"+month:month)+""+(day<10?"0"+day:day);}
return d;},_validateParameters:function(params){var rule,valid=true,reAirport=/^\w{3}$/,reNumber=/^\d+?(\.\d+)*$/,reText=/^[a-zA-Z-_]+$/,reYmd=/^\d{8}$/,reYmdOpt=/^(\d{8})*|null$/,rules=[{f:"a",r:reAirport},{f:"a",r:reAirport},{f:"d",r:reAirport},{f:"x",r:reNumber},{f:"r",r:reYmdOpt},{f:"o",r:reYmd},{f:"m",r:/^\w{3}$/},{f:"l",r:reText},{f:"outboundFrom",r:reYmdOpt},{f:"outboundTo",r:reYmdOpt},{f:"returnFrom",r:reYmdOpt},{f:"returnTo",r:reYmdOpt}],rsize=rules.length;for(rsize>=0;rsize-=1;){rule=rules[rsize];if(!rule.r.test(params[rule.f])){valid=false;if(typeof(console)!=="undefined"){console.log("DataVO.validateParameters: wrong "+rule.f+": "+params[rule.f]);}
break;}}
return valid;},_generateMD5:function(params){var md5=["f02c5a",params.d,params.a,params.o];if(params.r){md5.push(params.r);}
md5=md5.concat(params.m,params.l,params.x);if(params.outboundFrom){md5.push(params.outboundFrom);}
if(params.outboundTo){md5.push(params.outboundTo);}
if(params.returnFrom&&params.returnTo){md5=md5.concat(params.returnFrom,params.returnTo);}
return bravofly.utils.MD5.hex_md5(md5.join(""));}};;jQuery.widget("bravofly.pricematrix",{cells:[],nodeMessage:null,retries:1,retryOnError:[408,504],searches:{},xhrCache:null,lastSearchMD5:null,isReady:false,messages:{_tpl:"<div class=\"text\">#{text}</div>",load:"Please wait, loading...",info:"Indicative prices exposed.",fail:"Load failed, retry later."},ATTRIBUTE_INDEX:"matrix:index",ATTRIBUTE_COORD_X:"matrix:x",ATTRIBUTE_COORD_Y:"matrix:y",CLASS_PRICEMATRIX:"pricematrix-box",_create:function(){this.xhrCache=new bravofly.utils.XHRCache;this.searches={};this.isReady=false;this.lastSearchMD5=null;if(this.options.autoload===true){this.init();this.load(this.options);}},init:function(){this.cells=this._findCells();this.nodeMessage=this._createMessageNode();this.isReady=true;},_findCells:function(){var $list,target=this.options.target||this.element,self=this;jQuery(target).addClass(this.CLASS_PRICEMATRIX);$list=jQuery("td",target).filter(function(idx,node){return parseInt(this.getAttribute(self.ATTRIBUTE_INDEX),10)>-1?true:false;});return this._orderByAttribute($list,this.ATTRIBUTE_INDEX);},_orderByAttribute:function(cells,name){var node,id,ids=[],list={},ordered=[];if(!cells.length){return;}
jQuery.each(cells,function(idx,item){node=item;id=node.getAttribute(name);list[id]=node;ids.push(id);});ids.sort(function(a,b){return a-b;});while(ids.length){id=ids.shift();ordered.push(list[id]);}
return ordered;},load:function(config){if(!config||!config.url){return;}
jQuery.extend(this.messages,config.messages||{});var xhrOk,params=new bravofly.apps.capitanprice.DataVO(config),url=config.url,settings={url:url,data:params.getData(),context:this,dataType:"json"},md5=params.getMD5(),xhr=this.xhrCache.getXHR(md5);if(!params.isValid()){return;}
this.lastSearchMD5=md5;if(xhr&&xhr.readyState==4){this._loadSuccess(md5,xhr.data?xhr.data:this.xhrCache.getData(md5),'cache');}else if(!xhr){this.xhrCache.stopLoading();settings.success=(function(code){return function(data,text,xhr){this._loadSuccess.call(this,code,data,text,xhr);};})(md5);settings.error=(function(code){return function(xhr,statusText,message){this._loadFailure.call(this,code,xhr,statusText,message);};})(md5);this.setMessage(this.messages.load);xhrOk=this.xhrCache.add(md5,jQuery.ajax(settings),settings);if(!xhrOk){this._log({code:"PM105",text:"Failed to init XHR."});}}},_loadSuccess:function(md5,data,textStatus,xhr){var xhrData,message,opts=this.options;if(data==='loading'){return;}
if(this.xhrCache.ready(md5)&&textStatus==='success'){this.xhrCache.stopLoading();this.xhrCache.setData(md5,data);}else if(textStatus==='cache'){1;}else{this._log({code:"PM101",text:"XHR not ready and status unknown ("+textStatus+")."});return;}
this.datasource=data;if(xhr&&!data&&!xhr._aborted){this._log({code:"PM103",text:"Data null and not aborted."});}
if(data&&data.hasOwnProperty("validation")&&data.validation=="error"){this._log({code:"PM104",text:"Error in loading data"});}else if(this.lastSearchMD5==md5){this._populate();}
this.setMessage(this.messages.info);opts.success instanceof Function&&opts.success.apply(this,arguments);},_loadFailure:function(md5,xhr,statusText,message){var settings=this.xhrCache.getConfig(md5),opts=this.options;this.xhrCache.remove(md5);if(jQuery.inArray(xhr.status,this.retryOnError)>-1&&this.retries>0){xhrOk=this.xhrCache.add(md5,jQuery.ajax(settings),settings);if(!xhrOk){this._log({code:"PM105",text:"Failed to init XHR."});}
this.retries-=1;return;}
this.setMessage(this.messages.fail);if(xhr._aborted){return;}
this._log({code:"PM100",text:"Pricematrix._loadFailure: failed to load bestprice resource: "+statusText+" - "+message,xhr:xhr&&xhr.status,dump:1});opts.failure instanceof Function&&opts.failure.apply(this,arguments);},_log:function(err){if(typeof(console)=="object"&&err){console.log(err.code+" - "+err.text);}
if(err&&err.dump){this._dumpState(err);}},_populate:function(){var i,size,cellData,$cell,renderer,deco={},cells=this.cells||this._findCells(),target=this.target,ds=this.datasource||{},source=ds.data,currency=ds.currency;if(!source||!(source instanceof Array)){this._log({code:-1,text:"Pricematrix._populate: no source. "+source});return;}
if(!cells){this._log({code:-2,text:"Pricematrix._populate: no cells"});return;}
this.listen(false);deco.currency=this.options.longCurrency==="false"?currency:"";renderer=this.options.render instanceof Function?this.options.render:this.render;size=source.length-1;for(i=0;i<=size;i+=1){cellData=source[i]?this._getCellData(source[i],deco):null;renderer.apply(this,[jQuery(cells[i]),cellData]);}
this.listen(true);},_createMessageNode:function(){var div,target=this.options.target||this.element,className="matrix-message",node=jQuery("."+className,target);if(node.length===0){div=document.createElement("div");div.className=className;jQuery(target).append(div);node=div;}else{node=node.get(0);}
return node;},setMessage:function(msg){var txt=this.messages._tpl;this.nodeMessage.innerHTML=txt.replace("#{text}",msg);},clearMessage:function(){this.nodeMessageinnerHTMl="";},render:function($node,data){if(!$node||!$node.length){return;}
$node.html(data?data.value:"");if(data){$node.attr("title",data.title);$node.addClass(data.className);}},clean:function(){this.listen(false);this.cells=null;},listen:function(active){if(this.isListening&&!active){jQuery(this.element).unbind("click");this._isListening=false;}else if(active&&!this._isListening){jQuery(this.element).bind("click",jQuery.proxy(this._handleEvent,this));this._isListening=true;}},_getCellData:function(source,deco){var data={value:source.amount+" "+deco.currency,className:""},labels=this.options.labels||{};if(!source.type){return data;}
data.type=source.type;switch(source.type){case 100:data.className="pointer bestprice";data.title=labels.select||"[select]";break;case 200:data.className="pointer under";data.title=labels.select||"[select]";break;case 300:data.className="pointer over";data.title=labels.select||"[select]";break;case 400:data.className="pointer search";data.title=data.value=labels.search||"[search]";break;case 500:data.className="pointer normal";data.title=labels.missing||"[missing]";break;case null:default:data.className="unknown";data.value="null";break;}
return data;},_handleEvent:function(evt){var obj={},node=evt.target,source=this.datasource&&this.datasource.data,id=node&&node.getAttribute(this.ATTRIBUTE_INDEX),x=node&&node.getAttribute(this.ATTRIBUTE_COORD_X),y=node&&node.getAttribute(this.ATTRIBUTE_COORD_Y);if(!id){return;}
jQuery().extend(source[id],obj);obj.id=id;obj.coords={x:x,y:y};jQuery.extend(obj,source[id]);jQuery.publish("/pricematrix/cell/select",[obj]);},_dumpState:function(err){var stk=err.xhr,data={error:"["+err.code+"] "+err.text,location:window.location.href,userAgent:navigator.userAgent,lastRequest:this.rawRequest,responseText:!stk?'N/A':stk.hasOwnProperty("responseText")&&stk.responseText!==""?stk.responseText:stk.hasOwnProperty("message")?stk.message:stk.transport?stk.transport.status:"No status",cookieEnabled:String(navigator.cookieEnabled)};jQuery.ajax({url:'/vg1/search/jslogger.action',dataType:'json',data:data});}});;jQuery.namespace("bravofly.apps.capitanprice");bravofly.apps.capitanprice.SingleRouteSearch=function(config){var target=config.target;if(!target){return;}
this._cache=new bravofly.utils.XHRCache();this.target=typeof(target)==='string'?jQuery((/^#/).test(target)?target:"#"+target):target.nodeType==1?jQuery(target):null;this.subscribe(config.updateOn);this.datasource=config.data||{};if(config.autoload){this.load();}};bravofly.apps.capitanprice.SingleRouteSearch.prototype={target:null,datasource:null,_cache:null,_handleEvent:function(data){this.load(data);},subscribe:function(action){if(typeof(action)!=="string"){return;}
if(jQuery.subscribe){jQuery.subscribe(action,jQuery.proxy(this._handleEvent,this));}},unsubscribe:function(action){if(typeof(action)!=="string"){return;}
if(jQuery.unsubscribe){jQuery.unsubscribe(action);}},load:function(config){var data=jQuery.extend(this.datasource,config),params=new bravofly.apps.capitanprice.DataVO(data),settings={url:data.url||"/capitanprice/Search",data:params.getData(),context:this,success:jQuery.proxy(this.load_OK,this),error:jQuery.proxy(this.load_KO,this)};if(!params.isValid()){if(typeof(console)!="undefined"){console.log("SingleRouteSearch: invalid parameters.");}
this.show(false);return;}
if(this._cache.exists(params.getMD5())){this.load_OK(this._cache.getXHR(params.getMD5()),'cache',null);}else{this._cache.add(params.getMD5(),jQuery.ajax(settings));}},load_OK:function(data,textStatus,jqXHR){var results=data.split?data.split("|"):["-"];if(results[0]!="-"){this.show(true);jQuery(".price",this.target).html(results[0]);}else{jQuery(".price",this.target).html('');this.show(false);}},load_KO:function(jqXHR,textStatus,errorThrown){this.show(false);},show:function(show){if(!this.target){return;}
this.target.css("display",show?"block":"none");}};;jQuery.namespace("bravofly.apps.searches");bravofly.apps.searches.Flight=function(config){var cOptions=config.options||{};this.dictionary=config.dictionary||{};this.options={formName:cOptions.formName||"searchform",xrate:cOptions.xrate||1,locale:cOptions.locale||"it",currency:cOptions.currency||"EUR",longCurrency:cOptions.longCurrency,calendar:config.calendar||{},suggester:{arrival:config.suggester.arrival,departure:config.suggester.departure},hasEmail:config.hasEmail};this.capitanPriceUrl=config.capitanPriceUrl||"/capitanprice/Search";};bravofly.apps.searches.Flight.prototype={dictionary:null,airportDeparture:null,airportArrival:null,calendarOutbound:null,calendarReturn:null,hiddenDayOutbound:null,hiddenDayReturn:null,hiddenMonthYearOutbound:null,hiddenMonthYearReturn:null,errorTooltip:null,form:null,init:function(){var self=this;this._populateDomVariables();this._setupAutocompleters();jQuery(':input[name="roundtrip"]').click(jQuery.proxy(this.roundTripSelected,this));this.airportDeparture[0].focus();this.errorTooltip=bravofly.apps.errors.InlineErrorManager.getInstance();this.form.bind("submit",jQuery.proxy(this.validate,this));jQuery(document).ready(jQuery.proxy(self.ready,self));},ready:function(){this._setupCalendars();this.attachEvents();},attachEvents:function(){var self=this,dict=this.dictionary||{};jQuery(this.switchAirports).bind('click',jQuery.proxy(this.swapDestinations,this));jQuery("select[name='adults']").change(function(){self.publishForm();});jQuery("select[name='childs']").change(function(){self.publishForm();});jQuery("select[name='infants']").change(function(){self.publishForm();});jQuery(self.airportDeparture).bind("select",function(){self.publishForm();});jQuery(self.airportArrival).bind("select",function(){self.publishForm();});},_bindHelpButtons:function(){var i,self=this,dict=this.dictionary,buttons=[{id:"helpButtonAdults",dictKey:"helpAdults"},{id:"helpButtonEmail",dictKey:"helpEmail"}];for(i=1;i>=0;i-=1){jQuery("#"+buttons[i].id).bind("click",{instance:buttons[i]},function(evt){var strategy=bravofly.apps.errors.InlineErrorManager.displayStrategy;evt.preventDefault();evt.stopPropagation();return self.errorTooltip.displayMessage(dict[evt.data.instance.dictKey],evt.target,strategy.OVER);});}},detachEvents:function(){jQuery(this.switchAirports).unbind('click');jQuery("select[name='adults']").unbind("change");jQuery("select[name='childs']").unbind("change");jQuery("select[name='infants']").unbind("change");jQuery("helpButtonAdults").unbind("click");},_populateDomVariables:function(){this.outboundHiddenDay=jQuery(":input[name='outboundDay']");this.outboundHiddenMonthYear=jQuery(":input[name='outboundMonthYear']");this.returnHiddenDay=jQuery(":input[name='returnDay']");this.returnHiddenMonthYear=jQuery(":input[name='returnMonthYear']");this.calendarReturnBox=jQuery("#calendar-return-container");this.bestPrice=jQuery("#bestprice");this.bestPriceContainer=jQuery("#capitanprice");this.switchAirports=jQuery("#switchAirports");this.form=jQuery("form[name='"+this.options.formName+"']");},swapDestinations:function(){var dep=this.airportDeparture.suggester("item"),arr=this.airportArrival.suggester("item");this.airportDeparture.suggester("item",arr);this.airportArrival.suggester("item",dep);this.publishForm();},_setupAutocompleters:function(){var SELECT_EVENT="itemSelected",confSuggDeparture=this.options.suggester.departure,confSuggArrival=this.options.suggester.arrival;this.airportArrival=jQuery("#arrivalAirport").suggester(confSuggArrival);this.airportDeparture=jQuery("#departureAirport").suggester(confSuggDeparture);},_setupCalendars:function(){var prefix,pricematrixConf,options=this.options,calendar=options&&options.calendar||{},today=new Date(),outboundDate=new Date(today.getFullYear(),today.getMonth(),today.getDate()+1),returnDate=new Date(today.getFullYear(),today.getMonth(),today.getDate()+8);jQuery.datepicker.setDefaults(jQuery.datepicker.regional[this.options.locale]);this.calendarOutbound=jQuery("#calendar-outbound").calendar({dateFormat:calendar.dateFormat||'dd/mm/yy',numberOfMonths:calendar.numberOfMonths||1,showButtonPanel:calendar.showButtonPanel||false,inline:calendar.inline||false,hideOnDisable:calendar.hideOnDisable||false,disabled:calendar.disabled||false,defaultDate:outboundDate,minDate:today,pricematrix:{active:calendar&&calendar.hasPricematrix,config:jQuery.proxy(this._getPricematrixConfOutbound,this)},onSelect:jQuery.proxy(function(){this.updateReturnCalendar(arguments);this.calendarOutbound.calendar("hide");this.populateDateFields(arguments[1],arguments[1],arguments[2],"outbound");},this)});this.calendarReturn=jQuery("#calendar-return").calendar({dateFormat:calendar.dateFormat||'dd/mm/yy',numberOfMonths:calendar.numberOfMonths||1,showButtonPanel:calendar.showButtonPanel||false,inline:calendar.inline||false,hideOnDisable:calendar.hideOnDisable||false,disabled:calendar.disabled||false,defaultDate:returnDate,minDate:today,gotoCurrent:true,pricematrix:{active:calendar&&calendar.hasPricematrix,config:jQuery.proxy(this._getPricematrixConfReturn,this)},onBeforeGenerate:jQuery.proxy(this._beforeGenerateReturnCal,this),onSelect:jQuery.proxy(function(){this.populateDateFields(arguments[0],arguments[1],arguments[2],"return");},this)});this.updateReturnCalendar();this.calendarOutbound.calendar("setDate",outboundDate);this.calendarReturn.calendar("setDate",returnDate);this.populateDateFields(null,null,{selectedDay:returnDate.getDate(),selectedMonth:returnDate.getMonth(),selectedYear:returnDate.getFullYear()},"return");this.populateDateFields(null,null,{selectedDay:outboundDate.getDate(),selectedMonth:outboundDate.getMonth(),selectedYear:outboundDate.getFullYear()},"outbound");},_beforeGenerateReturnCal:function(event,inst){var outCal=this.calendarOutbound,retCal=this.calendarReturn,outDate=outCal.calendar("getDate"),retDate=retCal.calendar("getDate"),outMonth=outDate&&outDate.getMonth(),outYear=outDate&&outDate.getFullYear(),rangeStart,rangeEnd,outNumOfMonths=retCal.calendar("option","numberOfMonths");rangeStart=new Date(outDate.getFullYear(),outDate.getMonth(),1);rangeEnd=new Date(outDate.getFullYear(),outDate.getMonth()+outNumOfMonths,0);if(!retDate){return;}
if(inst.firstRender&&retDate>rangeStart&&retDate<rangeEnd){inst.drawMonth=outMonth;inst.drawYear=outYear;}else if(inst.firstRender&&retDate>rangeEnd){inst.drawMonth=inst.drawMonth-1;}},_getPricematrixConfOutbound:function(range){var calcConf,message,conf=this._getPricematrixConf(),dict=this.dictionary,dates=conf.returnDate?conf.returnDate.match(/(\d{4})(\d{2})(\d{2})/):[];message=dict["pricematrixInfo"+(this.isRoundTrip()?"Roundtrip":"")];message=message.replace("#{tripType}",dict.outboundTrip).replace("#{tripReverseType}",dict.returnTrip).replace("#{date}",dates[3]+"/"+dates[2]+"/"+dates[1]);calcConf={fromDepartureDate:range[0],toDepartureDate:range[1],fromReturnDate:conf.returnDate,toReturnDate:conf.returnDate,messages:{info:message}};jQuery.extend(true,conf,calcConf);return conf;},_getPricematrixConfReturn:function(range){var calcConf,message,conf=this._getPricematrixConf();var dict=this.dictionary,dates=conf.outboundDate?conf.outboundDate.match(/(\d{4})(\d{2})(\d{2})/):[];message=dict.pricematrixInfoRoundtrip;message=dates.length?message.replace("#{tripType}",dict.returnTrip).replace("#{tripReverseType}",dict.outboundTrip).replace("#{date}",dates[3]+"/"+dates[2]+"/"+dates[1]):"";calcConf={fromDepartureDate:conf.outboundDate,toDepartureDate:conf.outboundDate,fromReturnDate:range[0],toReturnDate:range[1],messages:{info:message}};jQuery.extend(true,conf,calcConf);return conf;},_getPricematrixConf:function(type){var opts=this.options,dict=this.dictionary;return{active:false,arrivalAirport:this.airportArrival.suggester("value")||null,departureAirport:this.airportDeparture.suggester("value")||null,outboundDate:this.calendarOutbound.calendar("getFormattedDate","yymmdd"),returnDate:this.calendarReturn.calendar("getFormattedDate","yymmdd"),messages:{load:dict.pricematrixLoad,info:dict.pricematrixInfo,fail:dict.pricematrixFail},autoload:false,longCurrency:opts.longCurrency,currency:opts.currency,locale:opts.locale,xrate:opts.xrate,url:opts.calendar.capitanPriceUrl,time:Math.random(),sign:'f02c5a'};},publishForm:function(){var params={outboundDate:this.calendarOutbound&&this.calendarOutbound.calendar("getDate"),returnDate:this.calendarReturn&&this.calendarReturn.calendar("getDate"),departureAirport:this.airportDeparture&&this.airportDeparture.suggester("value"),arrivalAirport:this.airportArrival&&this.airportArrival.suggester("value"),adults:jQuery("select[name='adults']").val(),children:jQuery("select[name='childs']").val(),infants:jQuery("select[name='infants']").val(),isRound:this.isRoundTrip()};jQuery.publish("/action/update",[params]);},getLastSearch:function(){var cookie=jQuery.cookie(this.option.cookie.searches||"mysearches"),match=cookie?cookie.match(/((?:\w+\|){7})&$/):null,values=match instanceof Array&&match[1]?match[1].split("|"):null;if(!values){return{};}
return{airportDeparture:values[0],airportArrival:values[1],outboundDate:values[2],returnDate:values[3],adults:values[4],children:values[5],infants:values[6]};},updateReturnCalendar:function(context,newDate,calendar){var date,dOut=this.calendarOutbound.calendar("getDate"),dRet=this.calendarReturn.calendar("getDate");this.calendarReturn.calendar("setMinDate",dOut);if(dOut>dRet){date=new Date(dOut.getFullYear(),dOut.getMonth(),(dOut.getDate()));this.populateDateFields(null,null,{selectedDay:date.getDate(),selectedMonth:date.getMonth(),selectedYear:date.getFullYear()},"return");}},populateDateFields:function(context,dateString,datepicker,prefix){var M=parseInt(datepicker.selectedMonth,10)+1,d=(parseInt(datepicker.selectedDay,10)<10?"0":"")+datepicker.selectedDay,m=""+(M<10?"0":"")+M;this[prefix+"HiddenDay"].val(d);this[prefix+"HiddenMonthYear"].val(m+""+datepicker.selectedYear);this.publishForm();},roundTripSelected:function(evt){var isRound=this.isRoundTrip();this.calendarReturn.calendar(isRound?"enable":"disable");jQuery(this.calendarReturnBox).css("display",isRound?"block":"none");this.publishForm();return true;},isRoundTrip:function(){return jQuery(':input[name="roundtrip"]:checked').val()==="true";},airportFieldSelected:function(event,ui){var isRound=jQuery(':input[name="roundtrip"]:checked').val()==="true",calOutbound=this.airportDeparture.suggester("value")!=="",calReturn=this.airportArrival.suggester("value")!=="";this.calendarOutbound.calendar((!isRound&&calOutbound&&calReturn)||(isRound&&calOutbound&&calReturn)?"enable":"disable");this.calendarReturn.calendar(isRound&&calOutbound&&calReturn?"enable":"disable");return false;},isAirportFieldFilled:function(){return this.airportDeparture.suggester("value")!==""&&this.airportArrival.suggester("value")!=="";},validate:function(){var pax=0,form=this.form.get(0),strategy=bravofly.apps.errors.InlineErrorManager.displayStrategy,tooltip=this.errorTooltip,dict=this.dictionary;if(this.airportDeparture.suggester("value")===""){tooltip.displayError(dict.errorSearchSelectdepartureairport,this.airportDeparture,strategy.UNDER);return false;}
if(this.airportArrival.suggester("value")===""){tooltip.displayError(dict.errorSearchSelectarrivalairport,this.airportArrival,strategy.UNDER);return false;}
if(this.calendarOutbound.calendar("getDate")===null||!(/^\d{2}$/).test(jQuery('#outboundDay').val())||!(/^\d{6}$/).test(jQuery('#outboundMonthYear').val())){tooltip.displayError(dict.searchValidateDate,jQuery('#calendar-outbound'),strategy.UNDER);return false;}
if(this.isRoundTrip()&&(this.calendarReturn.calendar("getDate")===null||!(/^\d{2}$/).test(jQuery('#returnDay').val())||!(/^\d{6}$/).test(jQuery('#returnMonthYear').val()))&&(this.calendarOutbound.calendar("getDate")>this.calendarReturn.calendar("getDate"))){tooltip.displayError(dict.searchValidateDate2,jQuery("#calendar-return"),strategy.UNDER);return false;}
if(this.options.hasEmail&&!(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/).test(jQuery('#email').val())){tooltip.displayError(dict.errorUserregistrationEmail,jQuery('#email'),strategy.UNDER);return false;}
if(form.elements["infants"].value>form.elements["adults"].value){tooltip.displayError(dict.searchValidateInfants,form.elements["infants"],strategy.UNDER);return false;}
pax=parseInt(form.elements["infants"].value,10)
+parseInt(form.elements["childs"].value,10)
+parseInt(form.elements["adults"].value,10);if(pax>9){openWindow('/vg1/others/popupgroups.action','top=10,left=500,height=150,width=500');return false;}
return true;},getAirportArrival:function(){return this.airportArrival;},getAirportDeparture:function(){return this.airportDeparture;},getCalendarOutbound:function(){return this.calendarOutbound;},getCalendarReturn:function(){return this.calendarReturn;}};;jQuery.namespace("bravofly.volagratis.homepage");bravofly.volagratis.homepage.page=new bravofly.apps.AbstractPage({searchFlight:null,init:function(){var conf=bravofly.store.Homepage;this.searchFlight=new bravofly.apps.searches.Flight({dictionary:conf.dictionary,suggester:{departure:conf.suggesterDeparture||{},arrival:conf.suggesterArrival||{}},calendar:{inline:true},config:{locale:conf.locale,currency:conf.currency,longCurrency:conf.longCurrency,xrate:conf.xrate,hasPricematrix:conf.pricematrixInCalendar,hasEmail:conf.notEmptyUserRegistration},cookie:bravofly.store.Homepage.cookie});this.searchFlight.init();this._legacyAppendTakeOverParameter();},ready:function(){var flight=this.searchFlight,store=(bravofly&&bravofly.store)||{};this._setupTabs.call(self);this.capitanPrice=new bravofly.apps.capitanprice.SingleRouteSearch({target:"#capitanprice",updateOn:"/action/update",autoload:true,data:{arrivalAirport:null,departureAirport:null,outboundDate:null,returnDate:null,longCurrency:store.Homepage.longCurrency,currency:store.Homepage.currency||"EUR",locale:store.Homepage.locale||"it",xrate:store.Homepage.xrate||1,url:"/capitanprice/Search"}});flight.publishForm();if(store.pinIE9&&store.pinIE9.active){bravofly.utils&&bravofly.utils.pinIE9&&bravofly.utils.pinIE9.showPinnedSitePrompt("pinDiscover");}},_setupTabs:function(){var tabs1=new bravofly.apps.ClickTabs({id:"tabs",indexSelected:0}),tabs2=new bravofly.apps.ClickTabs({id:"vg_seo_banner_content",indexSelected:0}),tabs3=new bravofly.apps.ClickTabs({id:"vg_banner_vacanze_content",indexSelected:0});},_legacyAppendTakeOverParameter:function(){var url=window.location.toString();if(!url){return;}
var res=/takeover=([^\&]+)/.exec(url);if(res&&res[1]){var img=document.createElement("img");img.src="http://adlev.neodatagroup.com/ad/srtg.jsp?ac=1&c="+res[1];img.width=1;img.height=1;img.border=0;document.body.appendChild(img);}}});bravofly.volagratis.homepage.expandCollapse=function(targetId){var $div=jQuery("#vgp"+targetId);$div.css("display",$div.css("display")=="none"?"block":"none");return false;};;
