if(typeof (IXIGO)=="undefined"){IXIGO={}}IXIGO.data={flightTripDuration:2,defaultStartDay:5,homeCookie:"homeCookie"};
IXIGO.Cookie.Home={};IXIGO.Cookie.Home.read=function(A){var B=IXIGO.Cookie.read(IXIGO.data.homeCookie);
A+="=";if(B&&B.indexOf(A)!==-1){var C=B.substring(B.indexOf(A)+A.length);return C.substring(0,C.indexOf(":"))
}return null};IXIGO.FareAlerts=function(){var C=null;var B,D;var F=$("#statusBox");var E,A,G;var H;this.fareAlerts=[];
this.init=function(K,I){C=this;H=K&&IXIGO.isArray(K);G=$("table.ixiGrid");E=$("#farealertMsgBox");A=$("#farealertMsg");
this.fareAlerts=K;this.form=H?document.forms["form"]:document.forms["fareAlertForm"];IXIGO.Alert.init();
$('input[type="radio"]',".form-body").addClass("radioButton");$("#newFareAlert").click(function(){C.showNewAlertForm()
}).mouseover(function(M){IXIGO.buttonHover("#newFareAlert","","")}).mouseout(function(M){IXIGO.buttonHover("#newFareAlert","","")
});$("#delFareAlerts").click(function(){}).mouseover(function(M){IXIGO.buttonHover("#delFareAlerts","","")
}).mouseout(function(M){IXIGO.buttonHover("#delFareAlerts","","")});$("#backToGrid").click(function(){$("#fareAlertForm").hide();
$("#fareAlertGrid").fadeIn("normal")});$("#saveOrUpdate").click(function(){C.saveOrUpdate()}).mouseover(function(M){IXIGO.buttonHover("#saveOrUpdate","b-","-bg-2")
}).mouseout(function(M){IXIGO.buttonHover("#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";var 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.Home.read("flight");var L=this.form;var 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();
var K=$("input:radio[@name $= 'journeyType'][@checked]").val();$("#alertReturnOption").animate({"opacity":(J==1&&K==1?"show":"hide")})
};this.showCalendar=function(I){var J=Date.today();var 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());
var 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 J=this.form;
var I=J["fareAlertId"].value;var K=(parseInt(I,10)>0)?["edit"]:["create"];K[K.length]=$("input:radio[@name $= 'alertType'][@checked]").val();
K[K.length]=$("select[@id $= 'originCity']").val();K[K.length]=$("select[@id $= 'destCity']").val();K[K.length]=$("input:radio[@name $= 'journeyType'][@checked]").val();
if(K[1]=="1"){K[K.length]=J["calendarInputId1"].value.replace(new RegExp("/","g"),"");if(K[4]=="1"){K[K.length]=J["calendarInputId2"].value.replace(new RegExp("/","g"),"")
}else{K[K.length]=""}}else{K[K.length]=$("select[@id $= 'leaving']").val();K[K.length]=""}K[K.length]=J["maxPrice"].value||0;
K[K.length]=$("input:radio[@name $= '"+(K[1]=="1"?"specificDateFrequency":"lowestFareFrequency")+"'][@checked]").val();
if(K[0]=="edit"){K[K.length]=I;K[K.length]=J["status"].value=="true"?1:0}this.registerOrSaveAlert(J["email"].value,"/secure/auth/alerts?q="+K.join("~"))
}};this.validate=function(){var L=null;var I=Date.today();var N=this.form;var K=$("input:radio[@name $= 'alertType']").val();
var 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.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="+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="+J+"&redirectTo="+I
}},error:function(K){},beforeSend:function(K){K.setRequestHeader("Accept","text/javascript")}})};this.invokeBulkDelete=function(){this.hideErrors();
var J=[];var I=$("td input:checkbox[@checked]","table.ixiGrid");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,K){var I=K.target;
while(I!==L&&!I.getAttribute("invoke")){I=I.parentNode}var J=I.getAttribute("invoke");if(J){this.hideErrors();
args=I.id.split("-");if(J=="edit"){this.showEditAlertForm(args[1])}}K.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(M){if(M<0){return }var L=this.fareAlerts[M];var K=this.form;this.resetForm();
K["fareAlertId"].value=L.id;K["status"].value=L.status;$("input:radio[@name $= 'alertType'][@value = '"+L.alertType+"']")[0].checked=true;
$("input:radio[@name $= 'journeyType'][@value = '"+L.journeyType+"']")[0].checked=true;$("select[@id $= 'originCity']").val(L.originCity);
$("select[@id $= 'destCity']").val(L.destCity);if(L.alertType==1){K["calendarInputId1"].value=L.leaveDate.toPaddedDate();
if(L.journeyType==1){K["calendarInputId2"].value=L.returnDate.toPaddedDate()}else{var I=K["calendarInputId1"].value.split("/");
var J=new Date(parseInt(I[2],10),parseInt(I[1],10)-1,parseInt(I[0],10)+2);K["calendarInputId2"].value=J.toPaddedDate()
}this.setWeekDay("#cal1WeekDay","#calendarInputId1");this.setWeekDay("#cal2WeekDay","#calendarInputId2")
}else{if(L.alertType==2){$("select[@id $= 'leaving']").val(L.leaving);this.setCalendarInputs()}}K["maxPrice"].value=L.maxPrice>0?L.maxPrice.toFixed(0):"";
$("input:radio[@name $= '"+(L.alertType=="1"?"specificDateFrequency":"lowestFareFrequency")+"'][@value = '"+L.frequency+"']")[0].checked=true;
$(".form-header label","#fareAlertForm").html("edit this fare alert!");$("div.selectButton","#saveOrUpdate").html("edit fare alert");
this.changeFormForAlertType();$("#fareAlertGrid").hide();$("#fareAlertForm").fadeIn("normal")};this.getAlertIndexById=function(M){var L=this.fareAlerts;
var J=-1,I=L.length;for(var K=0;K<I;K++){if(L[K].id===M){J=K;break}}return J};this.showErrorsOverGrid=function(I){A.html(I);
E.css({"background-color":"#FBE3D4","color":"#D12E18"}).show()};this.showErrorsInForm=function(K){var I=F.find("ul");
if(IXIGO.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")
})}};