$(document).ready(function(){if($("form#SkySales").attr("action")!="Payment.aspx"){initTabs(".tabset")}initPopup(".popup","a.popup-opener");initExpander(".expand-taxes-1",".expand-opener-taxes-1");initExpander(".expand-taxes-2",".expand-opener-taxes-2");initExpander(".expand-stops-1",".expand-opener-stops-1","#expand-image-stops-1");initExpander(".expand-stops-2",".expand-opener-stops-2","#expand-image-stops-2")});function initPopup(a,b){$(a).hide();$(b).click(function(){var c=$("."+this.rel);if(!$(this).hasClass("opened")){$(a).hide();$(b).removeClass("opened");$(c).css({display:"block",top:findPosY(this)+10,left:findPosX(this)+145+$(this).width()});$(this).addClass("opened")}else{$(c).hide();$(this).removeClass("opened")}return false})}function initExpander(b,c,a){$(b).hide();$(c).click(function(){if(!$(this).hasClass("opened")){$(b).hide();$(c).removeClass("opened");$(b).show();$(this).addClass("opened");if(a){var d=$(a).attr("csrc");$(a).attr("src",d)}}else{$(b).hide();$(this).removeClass("opened");if(a){var d=$(a).attr("osrc");$(a).attr("src",d)}}return false})}function findPosY(b){var a=0;while(b.offsetParent){a+=b.offsetTop;b=b.offsetParent}return a}function findPosX(b){var a=0;while(b.offsetParent){a+=b.offsetLeft;b=b.offsetParent}return a}function initTabs(a){$(a).each(function(e,d){var c=$(d);var b=$(d).find("a.tab");var f=0;b.each(function(h,g){this._box=$("#"+g.href.substr(g.href.indexOf("#")+1));if($(g).hasClass("active")){this._box.show();f=h}else{this._box.hide()}g.onclick=function(){if(!$(this).hasClass("active")){b.get(f)._box.hide();b.eq(f).removeClass("active");this._box.show();$(this).addClass("active");f=h;$(".popup").css({display:"none"});$("a.popup-opener").removeClass("opened")}return false}})})}function showLightbox(a){var b=$("<div class='overlayer'/>").appendTo("body").eq(0);var d=$("#lightbox-upgrade");var c=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;$(b).css({opacity:0});$(a).css({display:"none"}).css({opacity:0});$(d).css({display:"block",top:100+c,"margin-left":-$(d).width()/2}).animate({opacity:1},{duration:300});$(b).css({display:"block",height:document.documentElement.scrollHeight}).animate({opacity:0.7},{duration:400,queue:false});$("a.btn-error-ok").click(function(){$(a).animate({opacity:0},300,function(){$(a).css({display:"none"})});$(b).animate({opacity:0},400,function(){$(b).css({display:"none"})});$("div[id^='lightbox-error']").hide();return false});return false}function showLightInsurancebox(a){var b=$("<div class='overlayer'/>").appendTo("body").eq(0);var d=$("#lightbox-upgrade-insurance");var c=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;$(b).css({opacity:0});$(a).css({display:"none"}).css({opacity:0});$(d).css({display:"block",top:100+c,"margin-left":-$(d).width()/2}).animate({opacity:1},{duration:300});$(b).css({display:"block",height:document.documentElement.scrollHeight}).animate({opacity:0.7},{duration:400,queue:false});$("a.btn-error-ok").click(function(){$(a).animate({opacity:0},300,function(){$(a).css({display:"none"})});$(b).animate({opacity:0},400,function(){$(b).css({display:"none"})});$("div[id^='lightbox-error']").hide();return false});return false}function ShowInsuranceValidationError(){$("#lightbox-error-nooutbound-insurance").show();showLightInsurancebox(".lightbox");return false}function selectedFare(a){this.currentFare=$("input[name='ControlGroupSelectView$UpdatePanelViewAvailabilityInput$AvailabilityInputSelectView$market"+(a)+"']:checked");this.upgradeFare=$(this.currentFare).parent().next("td").children("input");this.marketSet=$("input[name='ControlGroupSelectView$UpdatePanelViewAvailabilityInput$AvailabilityInputSelectView$market"+(a)+"']");this.market=a;this.isValid=function(){return(this.currentFare.length!=0)?true:false};this.isMarketValid=function(){return(this.marketSet.length!=0)?true:false};this.isUpgradeable=function(){if($(this.currentFare).parent().attr("class")!="field-jazeera-easy"){return false}if(this.getPrice(this.upgradeFare)==NaN){return false}return true};this.getPrice=function(b){price=parseFloat($(b).next("label").text().replace(/[^0-9.]/g,""));return price};this.getTimeDate=function(b){timeDate=$(this.currentFare).attr("value").split("~");timeDate=(b=="depart")?timeDate[11].split(" "):timeDate[13].split(" ");splitDate=timeDate[0].split("/");splitTime=timeDate[1].split(":");return(new Date(splitDate[2],splitDate[0]-1,splitDate[1],splitTime[0],splitTime[1]))};this.getUpgradeDiff=function(){diff=this.getPrice(this.upgradeFare)-this.getPrice(this.currentFare);return diff};this.doUpgrade=function(){this.currentFare.attr("checked",false);this.upgradeFare.attr("checked",true);return true};this.doClear=function(){this.currentFare.attr("checked",false);return true}}var sf=new Array();function fareUpgrade(){var b=false;var c=0;sf[0]=new selectedFare("1");sf[1]=new selectedFare("2");if(sf[0].isMarketValid()&&!sf[0].isValid()){$("#lightbox-error-nooutbound").show();showLightbox(".lightbox");return false}if(sf[1].isMarketValid()&&!sf[1].isValid()){$("#lightbox-error-noreturn").show();showLightbox(".lightbox");return false}if(sf[1].isMarketValid()&&sf[0].isMarketValid()&&sf[1].getTimeDate("depart")-sf[0].getTimeDate("arrive")<5400000){$("#lightbox-error-timediff").show();showLightbox(".lightbox");return false}$(".upgrade-components").show();$("#upgrade-0,#upgrade-1").hide();for(var a=0;a<sf.length;a++){if(sf[a].isValid()&&sf[a].isUpgradeable()){$("#upgrade-"+(a)).children("span:first").text(sf[a].getUpgradeDiff());$("#upgrade-"+(a)).children("span:last").text(" "+SKYSALES.Resource.currencyCultureInfo.symbol);$("#upgrade-"+(a)).show();b=true;$("input[@name='upgrade-radio-"+(a)+"']").click(function(){pd=parseFloat($(this).siblings("span").text());if($(this).attr("value")=="yes"){c+=pd}else{c-=pd}$(".block-bottom").children(".price-box").text(c)})}}if(b){showLightbox(".lightbox");$("#upgrade-continue").click(function(){for(var d=0;d<sf.length;d++){if($("input[@name='upgrade-radio-"+(d)+"']:checked").attr("value")=="yes"){sf[d].doUpgrade()}}$("#lightbox-upgrade").hide();sf=new Array();__doPostBack($("a[type='submit']").attr("name"),"")})}else{sf=new Array();__doPostBack($("a[type='submit']").attr("name"),"")}}$(window).resize(function(){var a=$(".opened");if(a.length){var c=document.getElementsByTagName("a");var b;for(var d=0;d<c.length;d++){if(c[d].className.indexOf("opened")!=-1){b=c[d];break}}$("."+$(a).attr("rel")).css({left:findPosX(b)+145+$(".opened").width()})}});