$(function(){Z.TabMenu={init:function(){$('#tabs div.tabs-content').hide();$('ul.main-menu li a').removeClass('menu-active');$('ul.main-menu li a').removeClass('menu-first');$('ul.main-menu li a#'+activeMenu).addClass('menu-active');$('ul.main-menu li a#'+activeMenu).addClass('menu-first');$('#tabs ul li').removeClass('active');$('#tabs ul li a#'+activeMenu).parent().addClass('active');var tabId=$('#left').find(' #tabs ul li a#'+activeMenu).attr('class').replace('tab-menu','');$('div#tab'+tabId).show();}}});
;$(document).ready(function(){Z.Flight={firstURL:'post/flight-post.php',secondURL:'post/flight-post-ver-hotels.php',staticURL:'',ie:'Microsoft Internet Explorer',dealsURL:'http://'+document.domain+'/advertise/index2.php',contentEl:null,contentId:null,selectedLink:0,selectedAdvertiser:'',browser:(navigator.appName=='Microsoft Internet Explorer')?'ie':'',email_od:'post/flight-email-od-post.php',arr_unselected:new Array(),count_unselected:0,count_selected:0,item_selected:0,top_flight_search_id:'',init:function(tab){var El=this;this.contentEl=tab;this.contentId=$(tab)[0].id;this.firstURL='post/flight-post.php';this.secondURL='post/flight-post-ver-hotels.php';this.staticURL='';var currentTime=new Date();currentTime.setDate(currentTime.getDate()+20);var month=currentTime.getMonth()+1;var day=currentTime.getDate();var year=currentTime.getFullYear();if(currentTime.getMonth()>month){year++;}
var today=month+"/"+day+"/"+year;currentTime.setDate(currentTime.getDate()+7);var month2=currentTime.getMonth()+1;var day2=currentTime.getDate();var year2=currentTime.getFullYear();if(currentTime.getMonth()>month2){year2++;}
var today2=month2+"/"+day2+"/"+year2;$("#"+this.contentId+' #date1').val(today);$("#"+this.contentId+' #date2').val(today2);var try1=false;$("#"+this.contentId+" #city1").autocomplete("post/flight-post.php",{delay:10,minChars:3,matchSubset:1,matchContains:1,cacheLength:10,selectFirst:true,width:'450px',errormsg:'Enter City or Airport Code or Name',onItemSelect:function(){$("#city2").focus();}});$("#"+this.contentId+" #city2").autocomplete("post/flight-post.php",{delay:10,minChars:3,matchSubset:1,matchContains:1,cacheLength:10,selectFirst:true,width:'450px',errormsg:'Enter City or Airport Code or Name',onItemSelect:function(){$("#date1").focus();}});var dates=$("#"+this.contentId+" #date1, #"+this.contentId+" #date2").datepicker({defaultDate:"+1w",showButtonPanel:true,minDate:0,changeMonth:true,changeYear:true,numberOfMonths:2,showOn:"both",buttonImage:"http://hotels.asia.com/images/icon-cal.gif",buttonImageOnly:true,onSelect:function(selectedDate){if(this.id=="date1"&&!try1){var dd=selectedDate.split('/');var tmpdate=new Date(dd[2],parseInt(dd[0],10)-1,dd[1]);tmpdate.setDate(tmpdate.getDate()+7);var m=tmpdate.getMonth()+1;var d=tmpdate.getDate();var y=tmpdate.getFullYear();var t=m+"/"+d+"/"+y;$("#"+El.contentId+' #date2').val(t);}
if(this.id=="date1"){var option="minDate",instance=$(this).data("datepicker"),date=$.datepicker.parseDate(instance.settings.dateFormat||$.datepicker._defaults.dateFormat,selectedDate,instance.settings);dates.not(this).datepicker("option",option,date);}},beforeShow:function(input,inst){var dateMin=0;if(input.id==="date2"){var dd=$("#"+El.contentId+' #date1').val().split('/');var dd2=$("#"+El.contentId+' #date2').val().split('/');var tmpdate=new Date(dd[2],parseInt(dd[0],10)-1,dd[1]);tmpdate.setDate(tmpdate.getDate()+1);dateMin=tmpdate;inst.drawMonthEx=0;if(parseInt(dd[2],10)<parseInt(dd2[2],10)){inst.drawMonthEx=-1;inst.txtboxclick=true;}else if(parseInt(dd[0],10)<parseInt(dd2[0],10)){inst.drawMonthEx=-1;inst.txtboxclick=true;}}
return{minDate:dateMin};},beforeShowDay:function(date){var dd1=dates[0].value.split('/');var dd2=dates[1].value.split('/');var dates1=[new Date(dd1[2],parseInt(dd1[0],10)-1,dd1[1]),new Date(dd2[2],parseInt(dd2[0],10)-1,dd2[1])];if(dates1[0]<=date&&dates1[1]>=date){return[true,'ui-state-highlight'];}else{}
return[true,''];},onClose:function(input,inst){if(!date2Popup){date2Popup=true;if(inst.id=='date1'){setTimeout(function(){$("#"+El.contentId+" #date2").datepicker("show");},300);}}}});var date2Popup=false;$("#"+El.contentId+' #one_way').click(function(){if($(this).attr('checked')){$("#"+El.contentId+' #return_block').fadeOut('slow');}});$("#"+El.contentId+' #roundtrip').click(function(){if($(this).attr('checked')){$("#"+El.contentId+' #return_block').fadeIn('slow');}});$("#"+El.contentId+' .search-back').click(function(){$("#"+El.contentId+' .trip_inside3').slideUp('fast',function(){$("#"+El.contentId+' .trip_inside').fadeIn('slow');});return false;});$("#"+El.contentId+' #date1').blur(function(){var currentTime=new Date();var dd=$("#"+El.contentId+' #date1').val().split('/');var tmpdate=new Date(dd[2],parseInt(dd[0],10)-1,dd[1]);if(tmpdate<currentTime)$("#"+El.contentId+' #date1').val(today);});$("#"+El.contentId+' #date2').blur(function(){var currentTime=new Date();var dd=$("#"+El.contentId+' #date2').val().split('/');var tmpdate=new Date(dd[2],parseInt(dd[0],10)-1,dd[1]);if(tmpdate<currentTime)$("#"+El.contentId+' #date2').val(today2);});$("#"+El.contentId+' #date1').click(function(){});$("#"+El.contentId+' #date2').click(function(){});$("#"+El.contentId+' #city1').dblclick(function(){$(this).val('');});$("#"+El.contentId+' #city2').dblclick(function(){$(this).val('');});$("#"+El.contentId+' #city1').click(function(){if($(this).val()!='Enter a City or Airport Code'&&$(this).val()!=''){$(this).focus();$(this).select();}});$("#"+El.contentId+' #city2').click(function(){if($(this).val()!='Enter a City or Airport Code'&&$(this).val()!=''){$(this).focus();$(this).select();}});$("#"+El.contentId+' #search-btn').click(function(){var exit=false;var searchtype=(this.id=='search-btn')?'air':'air_hotel';$("#"+El.contentId+' .vtip').each(function(){if($(this).is(":visible")){$(this).fadeOut('fast',function(){$(this).fadeIn('fast');});exit=true;}});if(exit){exit=false;return exit;}
var city1=$("#"+El.contentId+' #city1').val();var city2=$("#"+El.contentId+' #city2').val();var date1=$("#"+El.contentId+' #date1').val();var date2=$("#"+El.contentId+' #date2').val();var adults=$("#"+El.contentId+' #adults').val();var flighttype=($("#"+El.contentId+' #one_way').attr('checked')?1:2);if(city1==''||city1.length<3||city1=='Enter a City or Airport Code'){alert('Enter a City or Airport Code');$("#"+El.contentId+' #city1').fadeOut('fast');$("#"+El.contentId+' #city1').fadeIn('fast');$("#"+El.contentId+' #city1').focus();$("#"+El.contentId+' #city1').select();return false;}
if(city2==''||city2.length<3||city2=='Enter a City or Airport Code'){alert('Enter a City or Airport Code');$("#"+El.contentId+' #city2').fadeOut('fast');$("#"+El.contentId+' #city2').fadeIn('fast');$("#"+El.contentId+' #city2').focus();$("#"+El.contentId+' #city2').select();return false;}
if(!globalObj.isDate(date1)){date1=today;$("#"+El.contentId+' #date1').val(date1);$("#"+El.contentId+' #date1').focus();$("#"+El.contentId+' #date1').select();}
if(!globalObj.isDate(date2)){date2=today;$("#"+El.contentId+' #date2').val(date2);$("#"+El.contentId+' #date2').focus();$("#"+El.contentId+' #date2').select();}
var d1=new Date(date1.split('/')[2],date1.split('/')[0]-1,date1.split('/')[1],23,59);var d2=new Date(date2.split('/')[2],date2.split('/')[0]-1,date2.split('/')[1],23,59);if((d2.getTime()-d1.getTime())<0){$("#"+El.contentId+' #date1').val(date2);$("#"+El.contentId+' #date2').val(date1);date1=$("#"+El.contentId+' #date1').val();date2=$("#"+El.contentId+' #date2').val();}
$.cookie('city1'+document.domain,city1,{expires:null});$.cookie('city2'+document.domain,city2,{expires:null});El.search();return false;});$("#"+El.contentId+' #compare').click(function(){El.arr_unselected=new Array();El.count_unselected=0;El.checkPopupBlocker=false;globalObj.createPrePopWinLimit=1;El.count_selected=0;El.item_selected=0;El.compare();var city1=$("#"+El.contentId+' #city1').val();var city2=$("#"+El.contentId+' #city2').val();$('#subscribe-od').html('Subscribe for Deals '+city1+' to '+city2);$('#searc-more').html("Search for more best deals on <b>"+city2.split('-')[0]+"</b>");});$("#"+El.contentId+' #edit-btn').click(function(){$("#"+El.contentId+' .trip_inside3').slideUp();$("#"+El.contentId+' .trip_inside1').slideDown();$("#"+El.contentId+' #cancel-btn').show();return false;});$("#"+El.contentId+' #cancel-btn').click(function(){$("#"+El.contentId+' .trip_inside1').slideUp();$("#"+El.contentId+' .trip_inside3').slideDown();return false;});$("#"+El.contentId+' .error-notification').click(function(){$(this).fadeOut();return false;});$("#"+this.contentId+" #city1").focus();},search:function(){var El=this;var from=$("#"+El.contentId+' #city1').val();var to=$("#"+El.contentId+' #city2').val();var flighttype=($("#"+El.contentId+' #one_way').attr('checked')?1:2);var date1=$("#"+El.contentId+' #date1').val();var date2=$("#"+El.contentId+' #date2').val();var searchtype=$("#"+El.contentId+' #searchtype').val();var adults=$("#"+El.contentId+' #adults').val();var guid=globalObj.guidGenerator();var exit=false;$("#"+El.contentId+' #div-compare-btn').hide();$("#"+El.contentId+' .front-banner').css({background:'url("http://fliasia.s3.amazonaws.com/widget-wide/images/advertisers/desc-trip-mama2.png") no-repeat scroll 0 0 transparent'});$('.vtip').each(function(){if($(this).is(":visible")){$(this).fadeOut('normal',function(){$(this).fadeIn('normal');});exit=true;}});if(exit){exit=false;return exit;}
var city1=from;var city2=to;if(city1==city2){$("#"+El.contentId+' .trip_inside1').show();$("#"+El.contentId+' .trip_inside2').hide();$("#"+El.contentId+' .trip_inside3').hide();alert('Arrival airport must be different');var el=$("#"+El.contentId+' #city2')[0];el.focus();el.select();return;}
$("#"+El.contentId+' #search-result').html('');$("#"+El.contentId+' #search-result-flight').html('');$("#"+El.contentId+' #search-result-hotel').html('');$("#"+El.contentId+' .trip_inside2').show();$("#"+El.contentId+' .trip_inside1').slideUp();$("#"+El.contentId+' #edit-btn').hide();$("#"+El.contentId+' #btn-back').hide();selectedLink=0;$("#"+El.contentId+' #block-bar-title').html('<b>Checking fares from top travel sites...</b>Please be patient while we update your new itinerary');$("#"+El.contentId+' #div-btn-back').hide();$("#"+El.contentId+' #your-trip').html('Your '+city2.split('-')[0]+' Trip:');$("#"+El.contentId+' #your-trip-date').html('Departure: '+date1+'&nbsp;&nbsp;'+'Return: '+date2);$('#trip-to-date').html('Departure: '+date1+'&nbsp;&nbsp;'+'Return: '+date2);pattern=new RegExp(/\(([^}]+)\)/);var newString1=pattern.exec(city1);var newString2=pattern.exec(city2);var a=(newString1!=undefined)?newString1[1]:city1;var b=(newString2!=undefined)?newString2[1]:city2;var cityInfo1=city1.split('-')[0];cityInfo1=cityInfo1.split(',')[0]+' '+a;var cityInfo2=city2.split('-')[0];cityInfo2=cityInfo2.split(',')[0]+' '+b;var qkey=city2.split('-')[0];qkey=qkey.split(',')[0];dealsURL='http://'+document.domain+'/deals/deals.php?q='+encodeURIComponent(qkey);$('#trip-to').html(cityInfo1+" to "+cityInfo2);var ttt=' Flights ';$("#"+El.contentId+' #sub-heading-2-title').html('Compare '+city2.split('-')[0]+ttt);$("#"+El.contentId+' #selected').html('<div id="" style="" class="box"><br class="clear" /></div><div id="" style="" class="box"><br class="clear" /></div><div id="" style="" class="box"><br class="clear" /></div><div id="" style="" class="box"><br class="clear" /></div>');$("#"+El.contentId+' #msg-compare1').hide();$("#"+El.contentId+' .flight-info').hide();$("#"+El.contentId+' #trip-title').html('Your '+city1+' Trip');$("#"+El.contentId+' #l-from-to').html('City: '+city1);$("#"+El.contentId+' #l-tickets').html('Depart: '+date1+' Return: '+date2);$("#"+El.contentId+' #l-travellers').html('Travellers: '+adults);$("#"+El.contentId+' #trip_inside2').show();$("#"+El.contentId+' #gointo').html(city1+', '+city1+' '+'Depart: '+date1+' Return: '+date2);$("#"+El.contentId+' #od').html("Your "+city1.split('-')[0]+' to '+city2.split('-')[0]+' Trip');pattern=new RegExp(/\(([^}]+)\)/);var newString1=pattern.exec(city1);var newString2=pattern.exec(city2);var a=(newString1!=undefined)?newString1[0]:city1;var b=(newString2!=undefined)?newString2[0]:city2;searchtype='air_hotel';var firstData='';var firstDataCount='';var secondData='';var secondDataCount='';var xId=0;function setFirst(res){var div='<div id="" style="height: 60px;background:url(http://fliasia.s3.amazonaws.com/fliasia-2/images/selectbutton-small.png) #EFEFEF no-repeat center center !important;" class="result-box box"></div>';div+='<div id="" style="height: 60px;background:url(http://fliasia.s3.amazonaws.com/fliasia-2/images/selectbutton-small.png) #EFEFEF no-repeat center center !important;" class="result-box box"></div>';div+='<div id="" style="height: 60px;background:url(http://fliasia.s3.amazonaws.com/fliasia-2/images/selectbutton-small.png) #EFEFEF no-repeat center center !important;" class="result-box box"></div>';div+='<div id="" style="height: 60px;background:url(http://fliasia.s3.amazonaws.com/fliasia-2/images/selectbutton-small.png) #EFEFEF no-repeat center center !important;" class="result-box box"></div>';$("#"+El.contentId+' #selected').html(div);$("#"+El.contentId+' .box').click(function(){$($('#search-result .result-box .result-box-icon:visible')[0]).trigger('click');});$("#"+El.contentId+' #msg-compare1').show();var ret=jQuery.parseJSON(res);$("#"+El.contentId+' #edit-btn').show();$("#"+El.contentId+' #btn-back').show();$("#"+El.contentId+' .trip_inside2').hide();$("#"+El.contentId+' .trip_inside1').hide();$("#"+El.contentId+' .trip_inside3').show();$("#"+El.contentId+' #icon-arrow').show();$("#"+El.contentId+' .edit-btn').show();var pattern=new RegExp(/\(([^}]+)\)/);var guid=globalObj.guidGenerator();if(res.indexOf('Please correct the items below in red')<0){var child=ret.channel.supplier;firstDataCount=$(child).length;El.top_flight_search_id=ret.top_flight_search_id;if($(child).length<1){$("#"+El.contentId+' #div-compare-btn').hide();$("#"+El.contentId+' .front-banner').css({background:'url("http://fliasia.s3.amazonaws.com/widget-wide/images/advertisers/desc-trip-mama2.png") no-repeat scroll 0 0 transparent'});$("#"+El.contentId+' #search-result').append('<span style="text-align: left;"> <h2>No results found.</h2></span>');$("#"+El.contentId+' #block-bar-title').html('<b></b>');}else{$("#"+El.contentId+' #div-compare-btn').show();$("#"+El.contentId+' .front-banner').css({background:'url("http://fliasia.s3.amazonaws.com/widget-wide/images/desc-trip-mama6.png") no-repeat scroll 0 0 transparent'});$("#"+El.contentId+' #div-btn-back').show();$("#"+El.contentId+' #block-bar-title').html('<b>Select 3 or more site to compare</b>Pick from your favorite travel site');pattern=new RegExp(/\(([^}]+)\)/);var newString1=pattern.exec(city1);var newString2=pattern.exec(city2);var c1=(newString1!=undefined)?newString1[0]:city1;var c2=(newString2!=undefined)?newString2[0]:city2;var country=city1.split('-');country=country[0].split(',');country=country[country.length-1];country=country.replace(/^\s+|\s+$/g,"");var pop_url=window.location.protocol+'//'+document.domain+"/loader-bw.php?template="+encodeURIComponent(category_name)+"&country="+encodeURIComponent(country)+"&widget_type=flight&memberid="+memberid+"&visitor="+guid+"&type=flight&from="+c1+"&to="+c2;xId=globalObj.displayResult(El,child,'Flights',xId,'search-result',pop_url);}
$("#"+El.contentId+' #search-result input[type=submit]').fadeOut('normal');if($("#"+El.contentId+' .check').length<3){$("#"+El.contentId+' .check').trigger('click');$("#"+El.contentId+' #block-bar-title').html('<b>You are now ready to compare.</b>');}}else{$("#"+El.contentId+' #search-result').append('<span style="text-align: left;"> <h2>No results found.</h2></span>');$("#"+El.contentId+' .edit-btn').show();$("#"+El.contentId+' #div-btn-back').show();}}
function getFirst(){return $.ajax({url:El.firstURL,data:{q:0,city1:a,city2:b,date1:date1,date2:date2,adults:adults,flighttype:flighttype,searchtype:'air',visitor:guid,browser:El.browser},success:function(res1){firstData=res1;return;}});}
function setSecond(res){var ret=jQuery.parseJSON(res);if(res.indexOf('Please correct the items below in red')<0){var child=ret.channel.supplier;secondDataCount=$(child).length;if($(child).length<1){}else{xId=globalObj.displayResult(El,child,'Flights + Hotels',xId,'search-result-flight');}
$("#"+El.contentId+' #search-result input[type=submit]').fadeOut('normal');if($("#"+El.contentId+' .check').length<3){$("#"+El.contentId+' .check').trigger('click');$("#"+El.contentId+' #block-bar-title').html('<b>You are now ready to compare.</b>');}}else{$("#"+El.contentId+' #search-result').append('<span style="text-align: left;"> <h2>No results found.</h2></span>');$("#"+El.contentId+' .edit-btn').show();$("#"+El.contentId+' #div-btn-back').show();}}
function getSecond(){return $.ajax({url:El.secondURL,data:{q:0,city1:a,city2:b,date1:date1,date2:date2,adults:adults,flighttype:flighttype,searchtype:'air_hotel',browser:El.browser},success:function(res2){secondData=res2;return;}});}
function done(){setFirst(firstData);var c=city2.split(' - ')[0];$("#"+El.contentId+' #sec-flights-hotels').hide();$("#"+El.contentId+' #sec-flights').html(""+c+"<b> Flights</b>("+firstDataCount+') sites found');globalObj.setResultBox(El);}
$.when(getFirst()).then(done).fail(function(){});return false;},compare:function(el){var El=el!=undefined?el:this;var sArray=new Array();var winId=new Array();globalObj.supplierClick=new Array();$('#more-supplier').hide();var date1=$("#"+El.contentId+' #date1').val();var date2=$("#"+El.contentId+' #date2').val();$('#trip-to-date').html('Departure: '+date1+'&nbsp;&nbsp;'+'Return: '+date2);var city1=$("#"+El.contentId+' #city1').val();var city2=$("#"+El.contentId+' #city2').val();pattern=new RegExp(/\(([^}]+)\)/);var newString1=pattern.exec(city1);var newString2=pattern.exec(city2);var a=(newString1!=undefined)?newString1[1]:city1;var b=(newString2!=undefined)?newString2[1]:city2;var cityInfo1=city1.split('-')[0];cityInfo1=cityInfo1.split(',')[0]+' '+a;var cityInfo2=city2.split('-')[0];cityInfo2=cityInfo2.split(',')[0]+' '+b;$('#trip-to').html(cityInfo1+" to "+cityInfo2);globalObj.compare(El);return false;},subscribe:function(el){var El=el!=undefined?el:this;var city1=$("#"+El.contentId+' #city1').val();var city2=$("#"+El.contentId+' #city2').val();var email=$('#subs-in-news').val();var browser='';if($.browser.webkit){browser='chrome';}else if($.browser.safari){browser='safari';}else if($.browser.opera){browser='opera';}else if($.browser.msie){browser='msie';}else if($.browser.mozilla){browser='mozilla';}
$.ajax({url:El.email_od,data:{email:encodeURIComponent(email),from:encodeURIComponent(city1),to:encodeURIComponent(city2),browser:encodeURIComponent(browser)},success:function(res){}});}}});
