var datePickerOption_AviationAlerts = {
showAnim: 'fadeIn',
duration: 'fast',
dateFormat: 'dd-M-yy',
maxDate: new Date(),
hideIfNoPrevNext: true,
changeMonth: true,
changeYear: true
}
function onRegionChange(expToken_AviationAlerts, defaultSubregion) {
var region = $("#regionPicker" + expToken_AviationAlerts).val();
if(region.toLowerCase() != "all"){
getSubregions($("#regionPicker" + expToken_AviationAlerts).val(), defaultSubregion, true, expToken_AviationAlerts);
}
$("#regionPicker" + expToken_AviationAlerts + " option[value='Select']").remove();
if ($("#rangePicker" + expToken_AviationAlerts + " option").size() == 0){
$("#rangePicker" + expToken_AviationAlerts).append("").
append("").
append("").
append("").
append("");
}
if($("#regionPicker" + expToken_AviationAlerts).val().toLowerCase() == "all"){
$("#subregionPicker" + expToken_AviationAlerts).empty();
$("#subregionPicker" + expToken_AviationAlerts).append("");
$("#subregionPicker" + expToken_AviationAlerts).attr("disabled", "disabled");
}else{
$("subregionPicker" + expToken_AviationAlerts).attr("disabled", "");
}
}
function initChartChangeNoticesForm(expToken_AviationAlerts){
//When region is selected, get subregions, section, and types
$("#regionPicker" + expToken_AviationAlerts).change(function () {
onRegionChange(expToken_AviationAlerts, "");
document.getElementById("subregionPicker" + expToken_AviationAlerts).index = 0;
refreshSectionsAndTypes($("#regionPicker" + expToken_AviationAlerts).val(),"",$("#fromDatePicker" + expToken_AviationAlerts).val(),$("#toDatePicker" + expToken_AviationAlerts).val(),$("#sectionPicker" + expToken_AviationAlerts).val(),$("#rangePicker" + expToken_AviationAlerts).val(),expToken_AviationAlerts);
});
//On date range change, call onDateRangeChange().
//Get alert sections and types, and their counts.
$("#rangePicker" + expToken_AviationAlerts).change(function () {
onDateRangeChange(expToken_AviationAlerts);
refreshSectionsAndTypes($("#regionPicker" + expToken_AviationAlerts).val(),$("#subregionPicker" + expToken_AviationAlerts).val(),$("#fromDatePicker" + expToken_AviationAlerts).val(),$("#toDatePicker" + expToken_AviationAlerts).val(),$("#sectionPicker" + expToken_AviationAlerts).val(),$("#rangePicker" + expToken_AviationAlerts).val(),expToken_AviationAlerts);
});
//Make from and to date text controls into jquery calendars.
$("#fromDatePicker" + expToken_AviationAlerts).datepicker(datePickerOption_AviationAlerts);
$("#toDatePicker" + expToken_AviationAlerts).datepicker(datePickerOption_AviationAlerts);
//From date can't be bigger then to date.
//When from date changed, get alert sections and types, and their counts.
$("#fromDatePicker" + expToken_AviationAlerts).change(function () {
refreshSectionsAndTypes($("#regionPicker" + expToken_AviationAlerts).val(),$("#subregionPicker" + expToken_AviationAlerts).val(),$("#fromDatePicker" + expToken_AviationAlerts).val(),$("#toDatePicker" + expToken_AviationAlerts).val(),$("#sectionPicker" + expToken_AviationAlerts).val(),$("#rangePicker" + expToken_AviationAlerts).val(),expToken_AviationAlerts);
});
//To date can't be smaller the from date.
//When to date changed, get alert sections and types, and their counts.
$("#toDatePicker" + expToken_AviationAlerts).change(function () {
//Only update the counts if the from date is populated...
var fd = $("#fromDatePicker" + expToken_AviationAlerts).val();
if (fd != null && fd != "") {
refreshSectionsAndTypes($("#regionPicker" + expToken_AviationAlerts).val(),$("#subregionPicker" + expToken_AviationAlerts).val(),$("#fromDatePicker" + expToken_AviationAlerts).val(),$("#toDatePicker" + expToken_AviationAlerts).val(),$("#sectionPicker" + expToken_AviationAlerts).val(),$("#rangePicker" + expToken_AviationAlerts).val(),expToken_AviationAlerts);
}
});
}
function getSubregions(value, defaultSubregion, async, expToken_AviationAlerts) {
value=encodeURIComponent(value);
var form = $("#EWPTTChartChangeNoticesForm" + expToken_AviationAlerts);
var params = "getSubregions®ion=" + value;
if (expToken_AviationAlerts == "EXP") {
params += "&expanded=1";
}
showPageLoadingMsg($("#Interstitial_Container"+expToken_AviationAlerts),true, 1);
$.ajax({
url: form.attr("action"),
data: params,
async: async,
success: function (xml) {
$("#subRegionResults" + expToken_AviationAlerts).html(xml);
if (defaultSubregion != null && defaultSubregion != "") {
$("#subregionPicker" + expToken_AviationAlerts).val(defaultSubregion);
}
hidePageLoadingMsg($("#Interstitial_Container"+expToken_AviationAlerts));
}
});
}
function onDateRangeChange(expToken_AviationAlerts) {
var range = $("#rangePicker" + expToken_AviationAlerts).val();
if (range.indexOf("all") != -1 || range.indexOf("select") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val("");
} else if (range.indexOf("specify") != -1) {
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val("");
$("#specify" + expToken_AviationAlerts).show();
} else if (range.indexOf("7 days") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val($.datepicker.formatDate('m/dd/yy', getdDateWithinDays(7)));
} else if (range.indexOf("14 days") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val($.datepicker.formatDate('m/dd/yy', getdDateWithinDays(14)));
} else if (range.indexOf("30 days") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val($.datepicker.formatDate('m/dd/yy', getdDateWithinDays(30)));
} else if (range.indexOf("3 months") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
$("#fromDatePicker" + expToken_AviationAlerts).val($.datepicker.formatDate('m/dd/yy', getdDateWithinMonth(3)));
} else if (range.indexOf("1 year") != -1) {
$("#specify" + expToken_AviationAlerts).hide();
$("#toDatePicker" + expToken_AviationAlerts).val("");
var date = new Date();
date.setFullYear(date.getFullYear()-1,date.getMonth(),1);
$("#fromDatePicker" + expToken_AviationAlerts).val($.datepicker.formatDate('m/dd/yy', date));
}
}
function getdDateWithinDays(day) {
var d = new Date();
var dt = d.getTime();
var t = day * 24 * 60 * 60 * 1000;
var nt = dt - t;
d.setTime(nt);
return d;
}
function getdDateWithinMonth(month) {
d = new Date();
m = d.getMonth();
y = d.getFullYear();
if (m < month) {
y = y-1;
tm = month - m;
m = m - tm;
} else {
m = m - month;
}
d.setMonth(m);
d.setFullYear(y);
d.setDate(1);
return d;
}
function displayAlertSections(section, expToken_AviationAlerts){
section = "alertsection" + expToken_AviationAlerts + "_" + section;
$(".Alertsection","#alertSections"+expToken_AviationAlerts).each(function(n){
if ($(this).attr("id") == section) {
$(this).show();
} else {
$(this).hide();
}
});
}
function refreshSectionsAndTypes(region, subregion, from_date, to_date, alertSection, dateRange, expToken_AviationAlerts, forceRemove) {
if(forceRemove == null){
forceRemove=false;
}
if(to_date == null || to_date == ''){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
if (curr_date < 10) {
curr_date = "0" + curr_date;
}
if (curr_month < 10) {
curr_month = "0" + curr_month;
}
to_date=curr_month + "-" + curr_date + "-" + curr_year;
}
region = encodeURIComponent(region);
subregion = encodeURIComponent(subregion);
from_date = encodeURIComponent(from_date);
to_date = encodeURIComponent(to_date);
alertSection = encodeURIComponent(alertSection);
dateRange = encodeURIComponent(dateRange)
var form = $("#EWPTTChartChangeNoticesForm"+expToken_AviationAlerts);
var params = "refreshSectionsAndTypes®ion=" + region + "&subregion=" + subregion + "&fromDate=" + from_date + "&toDate=" + to_date + "&alertSection=" + alertSection + "&range=" + dateRange;
if (expToken_AviationAlerts == "EXP") {
params += "&expanded=1";
}
showPageLoadingMsg($("#Interstitial_Container"+expToken_AviationAlerts),true,1);
//Get the number of items in the section drop down, before it gets updated.
var numSectionItems = $("#sectionPicker").children().length;
$.post(form.attr("action"), params,
function (xml) {
hidePageLoadingMsg($("#Interstitial_Container"+expToken_AviationAlerts));
$("#alerts" + expToken_AviationAlerts).html(xml);
$("#sectionPicker" + expToken_AviationAlerts).val(alertSection);
displayAlertSections(alertSection, expToken_AviationAlerts);
//If the number of items is less then new one, remove the "select a chart..." item.
if ((numSectionItems != 0 && numSectionItems < $("#sectionPicker").children().length) || forceRemove){
$("#sectionPicker" + expToken_AviationAlerts + " option[value='select']").remove();
}
});
}