if(typeof (IXIGO)=="undefined"){IXIGO={}}IXIGO.data={baseURL:"http://"+window.location.hostname+":"+window.location.port,flightTripDuration:2,defaultStartDay:5};
(function(A,B){A.iXiSearch={name:"iXiSearch",order:["t","fs","hs","ts","bs","ds","fo","ho","to","bo","tf"]};
A.setIxiSearch=function(E,I){var D=this,H=D.iXiSearch,G=D.read(H.name),C,F=D.findLocInIxiSearch(E);if(F>-1){C=(G?G.split("."):new Array(H.order.length));
C[F]=I;D.set(H.name,C.join("."))}};A.readIxiSearch=function(D){var C=this,F=C.read(C.iXiSearch.name),E=C.findLocInIxiSearch(D);
return(F&&E>-1?F.split(".")[E]:B)};A.findLocInIxiSearch=function(D){var E,C,F=this.iXiSearch.order;for(E=0,C=F.length;
E<C;E++){if(F[E]===D){return E}}return -1}})(IXIGO.Service.CookieManager.prototype);IXIGO.FareAlerts=function(){var C=null,B,D,F=$("#statusBox"),E,A,G,H;
this.fareAlerts=[];this.init=function(K,I){C=this;H=K&&IXIGO.Utils.isArray(K);G=$("table.ixi-grid.f-alert");
E=$("#farealertMsgBox");A=$("#farealertMsg");this.fareAlerts=K;this.form=document.forms["fareAlertForm"];
$('input[type="radio"]',".form-body").addClass("radioButton");$("#newFareAlert").click(function(){C.showNewAlertForm()
}).mouseover(function(M){IXIGO.Utils.onHoverButton("#newFareAlert","","")}).mouseout(function(M){IXIGO.Utils.onHoverButton("#newFareAlert","","")
});$("#delFareAlerts").click(function(){}).mouseover(function(M){IXIGO.Utils.onHoverButton("#delFareAlerts","","")
}).mouseout(function(M){IXIGO.Utils.onHoverButton("#delFareAlerts","","")});$("#backToGrid").click(function(){$("#fareAlertForm").hide();
$("#fareAlertGrid").fadeIn("normal")});$("#saveOrUpdate").click(function(){C.saveOrUpdate()}).mouseover(function(M){IXIGO.Utils.onHoverButton("#saveOrUpdate","b-","-bg-2")
}).mouseout(function(M){IXIGO.Utils.onHoverButton("#saveOrUpdate","b-","-bg-2")});G.find("thead th:first input.checkBox").click(function(){var M=this.checked;
G.find("tbody tr:not(.noresult)").each(function(){$(this).find("td:first input.checkBox")[0].checked=M
})});G.find("tbody").click(function(M){C.onClickFareAlert(this,M)});$("input:radio[name $= 'alertType']").click(function(){C.changeFormForAlertType()
});$("input:radio[name $= 'journeyType']").click(function(){C.changeFormForJourneyType()});$("#calendarInputId1").click(function(M){M.stopPropagation();
C.showCalendar("calendarInputId1");C.hideErrors()}).focus(function(){C.showCalendar("calendarInputId1");
C.hideErrors()}).keypress(function(M){return M.keyCode!=13}).change(function(){C.setWeekDay("#cal1WeekDay","#calendarInputId1");
C.checkReturnDate("#calendarInputId1","#calendarInputId2")});$("#calendarInputId2").click(function(M){M.stopPropagation();
C.showCalendar("calendarInputId2");C.hideErrors()}).focus(function(){C.showCalendar("calendarInputId2");
C.hideErrors()}).keypress(function(M){return M.keyCode!=13}).change(function(){C.setWeekDay("#cal2WeekDay","#calendarInputId2")
});D=Date.today();D.setFullYear(D.getFullYear()+1);B=D.clone();B.setMonth(B.getMonth()-1);if(I){I=I.split("-");
if(I[1]==="edit"){try{var L=parseInt(I[2],10);this.showEditAlertForm(this.getAlertIndexById(L))}catch(J){}}}if(!H){this.fillForm();
$("#shareAlerts").click(function(){var N="iXiGO Fare Alerts",M="/html/info/tell-a-friend.ixi?provider=email&channel=email&id=200811273773&link="+window.location+"&title="+document.title+"&custom={'tool':'"+N+"'}";
window.open(M,"iXiGO","scrollbars=no,menubar=no,width=490,height=520,resizable=no,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100");
return false})}else{if(A.html()){E.show()}}};this.resetForm=function(){this.hideErrors();this.form.reset()
};this.fillForm=function(){var N=IXIGO.Cookie.readIxiSearch("fs"),L=this.form,M=window.location.href.split("/");
if(M.length>4&&M[3].toLowerCase()=="alerts"){if(M[4]){$("select[id $= 'originCity']").val(M[4].toUpperCase())
}if(M[5]){$("select[id $= 'destCity']").val(M[5].toUpperCase())}if(M[6]){var K=Date.fromFlatDate(M[6]);
if(K&&!K.before(Date.today())){$("input:radio[name $= 'alertType'][value = '1']")[0].checked=true;L["calendarInputId1"].value=K.toPaddedDate();
this.setWeekDay("#cal1WeekDay","#calendarInputId1");if(M[7]){var J=Date.fromFlatDate(M[7]);if(J&&!J.before(K)){$("input:radio[name $= 'journeyType'][value = '1']")[0].checked=true;
L["calendarInputId2"].value=Date.fromFlatDate(M[7]).toPaddedDate()}else{$("input:radio[name $= 'journeyType'][value = '2']")[0].checked=true;
K.setDate(K.getDate()+2);L["calendarInputId2"].value=K.toPaddedDate()}}else{$("input:radio[name $= 'journeyType'][value = '2']")[0].checked=true;
K.setDate(K.getDate()+2);L["calendarInputId2"].value=K.toPaddedDate()}this.setWeekDay("#cal2WeekDay","#calendarInputId2")
}else{if(K){this.setCalendarInputs()}else{$("input:radio[name $= 'alertType'][value = '2']")[0].checked=true;
$("select[id $= 'leaving']").val(M[6]);this.setCalendarInputs()}}}else{this.setCalendarInputs()}this.changeFormForAlertType();
if(M[8]&&!isNaN(M[8])){$("#maxPrice").val(M[8])}}else{if(N){var M=N.split("/");$("select[id $= 'originCity']").val(M[0]);
$("select[id $= 'destCity']").val(M[1]);var I=Date.fromFlatDate(M[2]);if(!I.before(Date.today())){L["calendarInputId1"].value=I.toPaddedDate();
this.setWeekDay("#cal1WeekDay","#calendarInputId1");if(M[3]===""){$("input:radio[name $= 'journeyType'][value = '2']")[0].checked=true;
I.setDate(I.getDate()+2);L["calendarInputId2"].value=I.toPaddedDate()}else{$("input:radio[name $= 'journeyType'][value = '1']")[0].checked=true;
L["calendarInputId2"].value=Date.fromFlatDate(M[3]).toPaddedDate()}this.setWeekDay("#cal2WeekDay","#calendarInputId2")
}else{this.setCalendarInputs()}}else{$("select[id $= 'originCity']").val($("#alertFromOptions").attr("org_city"));
$("select[id $= 'destCity']").val($("#alertToOptions").attr("dest_city"));this.setCalendarInputs()}}L["fareAlertId"].value=0
};this.setCalendarInputs=function(){var I=Date.today();I.setDate(I.getDate()+IXIGO.data.defaultStartDay-I.getDay());
if(I.sameDay(Date.today())||I.before(Date.today())){I.setDate(I.getDate()+7)}this.form["calendarInputId1"].value=I.toPaddedDate();
this.setWeekDay("#cal1WeekDay","#calendarInputId1");I.setDate(I.getDate()+2);this.form["calendarInputId2"].value=I.toPaddedDate();
this.setWeekDay("#cal2WeekDay","#calendarInputId2")};this.changeFormForAlertType=function(){var I=$("input:radio[name $= 'alertType'][checked]").val();
if(I==1){$.showHide($("#alertSpecificDatesOption, #specificDateFreqOption"),$("#alertLeavingOption, #lowestFareFreqOption"));
this.changeFormForJourneyType(I)}else{if(I==2){$.showHide($("#alertLeavingOption, #lowestFareFreqOption"),$("#alertSpecificDatesOption, #specificDateFreqOption"))
}}};this.changeFormForJourneyType=function(I){var J=I||$("input:radio[name $= 'alertType'][checked]").val(),K=$("input:radio[name $= 'journeyType'][checked]").val();
$("#alertReturnOption").animate({"opacity":(J==1&&K==1?"show":"hide")})};this.showCalendar=function(I){var J=Date.today(),K;
if(I==="calendarInputId1"){$("#"+I).calendar({minDate:J,maxDate:B})}else{if(I==="calendarInputId2"){K=Date.fromPaddedDate(this.form["calendarInputId1"].value);
K=K?K:J;$("#"+I).calendar({minDate:K,maxDate:D})}}};this.setWeekDay=function(I,K){var J=Date.fromPaddedDate($(K).val());
if(!J){$(I).html("").fadeOut(200)}else{$(I).html(J.getWeekDay()).fadeIn(200)}};this.checkReturnDate=function(L,J){var K=Date.fromPaddedDate($(L).val()),I=Date.fromPaddedDate($(J).val());
if(K&&(!I||I.before(K))){K.setDate(K.getDate()+IXIGO.data.flightTripDuration);$(J).val(K.toPaddedDate()).trigger("change")
}};this.saveOrUpdate=function(){this.hideErrors();if(this.validate()){var K=this.form,J=K["fareAlertId"].value,I=K["email"].value,L=(parseInt(J,10)>0)?["edit"]:["create"];
L[L.length]=$("input:radio[name $= 'alertType'][checked]").val();L[L.length]=$("select[id $= 'originCity']").val();
L[L.length]=$("select[id $= 'destCity']").val();L[L.length]=$("input:radio[name $= 'journeyType'][checked]").val();
if(L[1]=="1"){L[L.length]=K["calendarInputId1"].value.replace(new RegExp("/","g"),"");if(L[4]=="1"){L[L.length]=K["calendarInputId2"].value.replace(new RegExp("/","g"),"")
}else{L[L.length]=""}}else{L[L.length]=$("select[id $= 'leaving']").val();L[L.length]=""}L[L.length]=K["maxPrice"].value||0;
L[L.length]=$("input:radio[name $= '"+(L[1]=="1"?"specificDateFrequency":"lowestFareFrequency")+"'][checked]").val();
L[L.length]=($("input:radio[name$='alertSendingType']:checked").val()==="1"?"sms":"email");L[L.length]="";
if(L[0]=="edit"){L[L.length]=J;L[L.length]=K["status"].value=="true"?1:0}this.registerOrSaveAlert(I,"/secure/auth/alerts?q="+L.join("~"))
}};this.validate=function(){var L=null,I=Date.today(),N=this.form,K=$("input:radio[name $= 'alertType']").val(),M=N["maxPrice"].value;
if($("select[id $= 'originCity']").val()==="none"){L="please select an airport for departure"}else{if($("select[id $= 'destCity']").val()==="none"){L="please select an airport for arrival"
}else{if($("select[id $= 'originCity']").val()==$("select[id $= 'destCity']").val()){L="the departure and arrival airports can't be same."
}else{if(K==1){var O=Date.fromPaddedDate(N["calendarInputId1"].value);if(!O){L="please enter departure date in the dd/mm/yyyy format"
}else{if(!O.between(I,B)){L="the departure date has to be within next 11 months."}else{if($("input:radio[name $= 'journeyType']").val()==1){var J=Date.fromPaddedDate(N["calendarInputId2"].value);
if(!J){L="please enter return date in the dd/mm/yyyy format."}else{if(O&&J.before(O)){L="the return date cannot be before departure date."
}else{if(!J.between(I,D)){L="the return date has to be within next 12 months."}}}}}}}}}}if(!L){if(M&&isNaN(M)){L="max price is not a number."
}else{if(!N["email"].value){L="please enter user email."}else{if(!IXIGO.Utils.isValidEmail(N["email"].value)){L="user email is not valid."
}}}}if(L){this.showErrorsInForm(L);return false}return true};this.registerOrSaveAlert=function(J,I){$.ajax({type:"GET",url:(H?"/secure":"")+"/user/action/farealerts",data:"action=exists&user="+encodeURIComponent(J),dataType:"json",success:function(K){if(K.response){window.location.href=I
}else{window.location.href=(H?"/secure":"")+"/user/action/farealerts?action=register&user="+encodeURIComponent(J)+"&redirectTo="+I
}},error:function(K){},beforeSend:function(K){K.setRequestHeader("Accept","text/javascript")}})};this.invokeBulkDelete=function(){this.hideErrors();
var J=[],I=$("td input:checkbox[checked]","table.f-alert");if(I.length>0){I.each(function(){J[J.length]=this.value
});IXIGO.Alert.show({type:"warn",msg:"your fare "+(J.length==1?"alert":"alerts")+" will be deleted permanently?",buttons:["ok","cancel"]},function(K){if(K=="ok"){window.location.href="/secure/auth/alerts?q=delete~"+J.join("-")
}})}else{this.showErrorsOverGrid("no fare alert selected to delete")}return false};this.onClickFareAlert=function(L,J){var I=$(J.target).closest("[invoke]"),K=I.attr("invoke");
if(K){this.hideErrors();args=I.attr("id").split("-");if(K=="edit"){this.showEditAlertForm(args[1])}}J.stopPropagation()
};this.showNewAlertForm=function(){this.resetForm();this.fillForm();this.changeFormForAlertType();$(".form-header label","#fareAlertForm").html("create your fare alert!");
$("div.selectButton","#saveOrUpdate").html("create fare alert");$("#fareAlertGrid").hide();$("#fareAlertForm").fadeIn("normal")
};this.showEditAlertForm=function(N){if(N<0){return }var J=this,M=J.fareAlerts[N],L=J.form;J.resetForm();
L["fareAlertId"].value=M.id;L["status"].value=M.status;$("input:radio[name $= 'alertType'][value = '"+M.alertType+"']")[0].checked=true;
$("input:radio[name $= 'journeyType'][value = '"+M.journeyType+"']")[0].checked=true;$("select[id $= 'originCity']").val(M.originCity);
$("select[id $= 'destCity']").val(M.destCity);if(M.alertType==1){L["calendarInputId1"].value=M.leaveDate.toPaddedDate();
if(M.journeyType==1){L["calendarInputId2"].value=M.returnDate.toPaddedDate()}else{var I=L["calendarInputId1"].value.split("/"),K=new Date(parseInt(I[2],10),parseInt(I[1],10)-1,parseInt(I[0],10)+2);
L["calendarInputId2"].value=K.toPaddedDate()}J.setWeekDay("#cal1WeekDay","#calendarInputId1");J.setWeekDay("#cal2WeekDay","#calendarInputId2")
}else{if(M.alertType==2){$("select[id $= 'leaving']").val(M.leaving);J.setCalendarInputs()}}if(M.senderType==="sms"){$("input:radio[name $= 'alertSendingType'][value = '1']")[0].checked=true
}else{$("input:radio[name $= 'alertSendingType'][value = '0']")[0].checked=true}L["maxPrice"].value=M.maxPrice>0?M.maxPrice.toFixed(0):"";
$("input:radio[name $= '"+(M.alertType=="1"?"specificDateFrequency":"lowestFareFrequency")+"'][value = '"+M.frequency+"']")[0].checked=true;
$("#fareAlertHeader").html("edit this fare alert!");$("#saveOrUpdate").html("edit fare alert");J.changeFormForAlertType();
$("#fareAlertGrid").hide();$("#fareAlertForm").fadeIn("normal")};this.getAlertIndexById=function(M){var L=this.fareAlerts,J=-1,I=L.length,K;
for(K=0;K<I;K++){if(L[K].id===M){J=K;break}}return J};this.showErrorsOverGrid=function(I){A.html(I);E.addClass("error").show()
};this.showErrorsInForm=function(K){var I=F.find("ul");if(IXIGO.Utils.isArray(K)){var J=[];$(msg).each(function(L,M){J[L]="<li>"+M+"</li>"
});I.html(J.join(""))}else{if(typeof (K)=="string"){I.html(K)}}F.fadeIn("normal")};this.hideErrors=function(){F.hide();
E.hide();G.find("tbody tr").each(function(){$(this).removeClass("error")})}};
