BWQualityHomepage = {
/**
*Apply custom date ranges
*f
*Last Modifed: 2010-07-06
*/
applyCustomDates: function() {
var view = $('view').value;
// Check to see if the start_date falls after the end_date, if so, swap them.
var start_year = $('select_start_year_'+view).value;
var end_year = $('select_end_year_'+view).value;
var start_month = $('select_start_month_'+start_year+'_'+view).value;
var end_month = $('select_end_month_'+end_year+'_'+view).value;
if(parseInt(start_year) > parseInt(end_year)) {
// Swap years.
$('select_start_year_'+view).value = end_year;
$('select_end_year_'+view).value = start_year;
start_year = $('select_start_year_'+view).value;
end_year = $('select_end_year_'+view).value;
// Update the years.
BWQualityHomepage.changeCustomStartEndYear();
// Swap months.
$('select_start_month_'+start_year+'_'+view).value = end_month;
$('select_end_month_'+end_year+'_'+view).value = start_month;
start_month = $('select_start_month_'+start_year+'_'+view).value;
end_month = $('select_end_month_'+end_year+'_'+view).value;
}
else if (parseInt(start_year) == parseInt(end_year) && parseInt(start_month) > parseInt(end_month)) {
// Swap months
$('select_start_month_'+start_year+'_'+view).value = end_month;
$('select_end_month_'+end_year+'_'+view).value = start_month;
start_month = $('select_start_month_'+start_year+'_'+view).value;
end_month = $('select_end_month_'+end_year+'_'+view).value;
}
// Save-the-date...
if(start_month.length == 1) start_month = '0'+start_month;
if(end_month.length == 1) end_month = '0'+end_month;
// Build dates from the start/end year/month.
var end_day = $('ldom_'+end_year+'_'+end_month).value;
if(end_day.length == 1) end_day = '0'+end_day;
var start_date = start_year+'-'+start_month+'-01';
var end_date = end_year+'-'+end_month+'-'+end_day;
$('fromdate').value = start_date;
$('todate').value = end_date;
BWQualityHomepage.changeTimePeriod(3, true);
},
/**
*Changes the custom start end year by hiding and redrawing the corresponding months
*
*Last Modified: 2010-07-06
*/
changeCustomStartEndYear: function() {
var view = $('view').value;
// Get the currently selected start and end years.
var start_year = $('select_start_year_'+view).value;
var end_year = $('select_end_year_'+view).value;
// Get the ids of all the start month drop-downs.
var start_month_dd_ids = $$("select[id^='select_start_month_']");
// Hide all the start month drop downs except for the one which corresponds to the currently
// selected value in the start year.
for (i = 0; i < start_month_dd_ids.length; i++) {
if(start_month_dd_ids[i].id == 'select_start_month_'+start_year+'_'+view) $(start_month_dd_ids[i].id).show();
else $(start_month_dd_ids[i].id).hide();
}
// Get the ids of all the end month drop-downs.
var end_month_dd_ids = $$("select[id^='select_end_month_']");
// Hide all the end month drop downs except for the one which corresponds to the currently
// selected value in the end year.
for (i = 0; i < end_month_dd_ids.length; i++) {
if(end_month_dd_ids[i].id == 'select_end_month_'+end_year+'_'+view) $(end_month_dd_ids[i].id).show();
else $(end_month_dd_ids[i].id).hide();
}
},
/**
*
* Change the grade that we are viewing
*
*@param string grade
*
* @author Jessica Bailey
*
* created 2010-06-23
* last modified 2010-07-07
*/
changeGrade: function(grade){
// Update the selected grade in the hidden variable, and in all panels.
$('grade').value = grade;
// If we aren't a subscriber, those controls won't be there, so please check.
if($('selection_grade_dropdown_overview')) {
var options = $('selection_grade_dropdown_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == grade) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_grade_dropdown_charts')) {
options = $('selection_grade_dropdown_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == grade) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_grade_dropdown_off_spec_summary')) {
options = $('selection_grade_dropdown_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == grade) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_grade_dropdown_sample_data')) {
options = $('selection_grade_dropdown_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == grade) options[i].selected = true;
else options[i].selected = false;
}
}
var chart_type = $('chart_type').value;
var graph_criteria = $('graph_criteria').value;
switch($('view').value){
case 'overview':
if(chart_type == 'dist') BWQualityHomepage.overviewDistGraphs();
else if(chart_type=='time') BWQualityHomepage.overviewTimeGraphs();
else if(chart_type=='pie')BWQualityHomepage.overviewPieGraphs();
//BWQualityHomepage.redrawTable('overview_datatable', 1);
break;
case 'charts':
BWQualityHomepage.redrawGraph('charts', chart_type, graph_criteria);
break;
case 'off_spec_summary':
BWQualityHomepage.redrawTable('off_spec_summary_table', 1, '');
break;
case 'sample_data':
if($('sample_datatable')) BWQualityHomepage.redrawTable('sample_datatable', 1, '');
break;
case 'compare':
// Redo the compare drop-downs.
BWQualityHomepage.compareSelector();
BWQualityHomepage.redrawGraph('compare', chart_type, graph_criteria);
break;
}
BWQualityHomepage.logClick(0);
},
// The selected Region in the compare panel was changed, so show the appropriate port drop-down.
changeSelectedRegion: function() {
// Figure out which region is currently selected in the region drop down.
var selected_region = $('compare_region_code').value;
if(selected_region == '') {
$('select_region').value = '';
$('port_compare_dropdowns').hide();
} else {
// Save the selected region in the hidden variable.
$('select_region').value = selected_region;
// Get the ids of all the port drop downs.
var port_dd_ids = $$("select[id^='port_select_']");
$('port_compare_dropdowns').hide();
// Hide all the port drop downs except for the one which corresponds to the currently
// selected value in the region drop down.
for (i = 0; i < port_dd_ids.length; i++) {
if(port_dd_ids[i].id == 'port_select_'+selected_region) {
$(port_dd_ids[i].id).show();
$('port_compare_dropdowns').show();
}
else $(port_dd_ids[i].id).hide();
}
}
},
/**
*Change the time period we are viewing
*
*@param string time_period
*
*@author Jessica Bailey
*
*created 2010-06-25
*last modified 2010-07-06
*/
changeTimePeriod: function(time_period, force_refresh){
var view = $('view').value;
// Get the name of the time period.
var tp_name = '30 Day';
if(time_period == 1) tp_name = '3 Month';
if(time_period == 2) tp_name = '1 Year';
if(time_period == 3) tp_name = 'Custom Dates';
// Swap the times
var old_period = $('time_period').value;
// Update the selected time period in the hidden variable, and in all panels.
$('time_period').value = time_period;
// If we aren't a subscriber, those controls won't be there, so please check.
if($('selection_time_dropdown_overview')) {
var options = $('selection_time_dropdown_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == time_period) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_charts')) {
options = $('selection_time_dropdown_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == time_period) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_off_spec_summary')) {
options = $('selection_time_dropdown_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == time_period) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_sample_data')) {
options = $('selection_time_dropdown_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == time_period) options[i].selected = true;
else options[i].selected = false;
}
}
// Update the date_start and date_end.
if(time_period == 0) $('fromdate').value = $('date_30days').value;
else if(time_period == 1) $('fromdate').value = $('date_3months').value;
else if(time_period == 2) $('fromdate').value = $('date_1year').value;
if(time_period < 3) $('todate').value = $('date_now').value;
// If we are using a custom time period, show and get the custom date_start and date_end values.
if(time_period == 3) {
// Set the 'using custom dates' flag to true.
$('custom_dates').value = 1;
$('date_controls_'+view).show();
// Refresh our values for start/end year/month for all views.
var start_year = $('select_start_year_'+view).value;
var end_year = $('select_end_year_'+view).value;
var start_month = $('select_start_month_'+start_year+"_"+view).value;
var end_month = $('select_end_month_'+end_year+"_"+view).value;
if($('selection_time_dropdown_overview')) {
var options = $('select_start_year_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_year_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_start_month_'+start_year+'_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_month) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_month_'+end_year+'_overview').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_month) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_charts')) {
var options = $('select_start_year_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_year_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_start_month_'+start_year+'_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_month) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_month_'+end_year+'_charts').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_month) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_off_spec_summary')) {
var options = $('select_start_year_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_year_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_start_month_'+start_year+'_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_month) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_month_'+end_year+'_off_spec_summary').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_month) options[i].selected = true;
else options[i].selected = false;
}
}
if($('selection_time_dropdown_sample_data')) {
var options = $('select_start_year_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_year_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_year) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_start_month_'+start_year+'_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == start_month) options[i].selected = true;
else options[i].selected = false;
}
var options = $('select_end_month_'+end_year+'_sample_data').options;
for(var i = 0; i < options.length; i++) {
if(options[i].value == end_month) options[i].selected = true;
else options[i].selected = false;
}
}
// Start date is easy, it's the first of the month indicated in our start
// year/month drop-down.
if(start_month.length == 1) start_month = '0'+start_month;
if(end_month.length == 1) end_month = '0'+end_month;
// End date needs to be the LAST date of the month showing, so retrieve
// whatever the last date of that month is.
var last_day = $('ldom_'+end_year+'_'+end_month).value;
$('fromdate').value = start_year+'-'+start_month+'-01';
$('todate').value = end_year+'-'+end_month+'-'+last_day;
} else {
// Set the 'using custom dates' flag to false.
$('custom_dates').value = 0;
$('date_controls_'+view).hide();
}
// Only update the graph if we changed the time period
if(time_period != old_period || force_refresh) {
var chart_type = $('chart_type').value;
var graph_criteria = $('graph_criteria').value;
switch($('view').value){
case 'overview':
if(chart_type == 'dist') BWQualityHomepage.overviewDistGraphs();
else if(chart_type=='time') BWQualityHomepage.overviewTimeGraphs();
else if(chart_type=='pie') BWQualityHomepage.overviewPieGraphs();
//BWQualityHomepage.redrawTable('overview_datatable', 1);
break;
case 'charts':
BWQualityHomepage.redrawGraph('charts', chart_type, graph_criteria);
break;
case 'off_spec_summary':
BWQualityHomepage.redrawTable('off_spec_summary_table', 1, '');
break;
case 'sample_data':
BWQualityHomepage.redrawTable('sample_datatable', 1, '');
break;
case 'compare':
// Redo the compare drop-downs.
BWQualityHomepage.compareSelector();
BWQualityHomepage.redrawGraph('compare', chart_type, graph_criteria);
break;
}
}
BWQualityHomepage.logClick(0);
},
changeView: function(view) {
BWQualityHomepage.updateKeyToSwirly();
// Disable this so that pre-selected tab cab be loaded (used by dropdown menu)
// if(view == $('view').value && view != 'compare') return;
var chart_type = $('chart_type').value;
var graph_criteria = $('graph_criteria').value;
var grade = $('grade').value;
var time_period = $('time_period').value;
// Do we want to show the custom dates for this view?
if(time_period == 3){
// If we aren't a subscriber, those controls won't be there, so please check.
if($('date_controls_'+view)) $('date_controls_'+view).show();
} else {
if($('date_controls_'+view)) $('date_controls_'+view).hide();
}
$('view').value = view;
//Unselect all the tabs
$('overview_tab').className = 'tab';
$('charts_tab').className = 'tab';
$('off_spec_summary_tab').className = 'tab';
$('sample_data_tab').className = 'tab';
$('compare_tab').className = 'tab';
//Select the selected tab
$(view+'_tab').className = 'tab sel';
switch(view){
case 'overview':
//hide all the other panels
$('charts_panel').hide();
$('off_spec_summary_panel').hide();
$('sample_data_panel').hide();
$('compare_panel').hide();
//show the current panel
$('overview_panel').show();
if($('is_subscriber')){
//set the radio buttons
if($('overview_select_graph_'+chart_type)){
$('overview_select_graph_'+chart_type).checked = true;
}
//set the drop downs
$('selection_grade_dropdown_overview').value = grade;
$('selection_time_dropdown_overview').value = time_period;
//BWQualityHomepage.updateGuide();
//redraw the graphs as necessary
if(chart_type == 'dist') BWQualityHomepage.overviewDistGraphs();
else if(chart_type == 'time') BWQualityHomepage.overviewTimeGraphs();
else if(chart_type == 'pie') BWQualityHomepage.overviewPieGraphs();
//BWQualityHomepage.redrawTable('overview_datatable', 1);
}
break;
case 'charts':
//hide all the other panels
$('overview_panel').hide();
$('off_spec_summary_panel').hide();
$('sample_data_panel').hide();
$('compare_panel').hide();
//show the current panel
$('charts_panel').show();
if($('is_subscriber')){
//set the radio buttons
if($('charts_select_graph_'+chart_type)){
$('charts_select_graph_'+chart_type).checked = true;
}
if($('charts_select_graph_'+graph_criteria)){
$('charts_select_graph_'+graph_criteria).checked = true;
}
//set the drop downs
if($('selection_grade_dropdown_charts')){
$('selection_grade_dropdown_charts').value = grade;
}
if($('selection_time_dropdown_charts')){
$('selection_time_dropdown_charts').value = time_period;
}
BWQualityHomepage.redrawGraph('charts', chart_type, graph_criteria);
}
break;
case 'off_spec_summary':
//hide all the other panels
$('overview_panel').hide();
$('charts_panel').hide();
$('sample_data_panel').hide();
$('compare_panel').hide();
//show the current panel
$('off_spec_summary_panel').show();
//set the drop downs
if($('selection_grade_dropdown_off_spec_summary')){
$('selection_grade_dropdown_off_spec_summary').value = grade;
}
if($('selection_time_dropdown_off_spec_summary')){
$('selection_time_dropdown_off_spec_summary').value = time_period;
}
//update the off_spec_summary as needed
BWQualityHomepage.redrawTable('off_spec_summary_table', 1, '');
break;
case 'sample_data':
//hide all the other panels
$('overview_panel').hide();
$('off_spec_summary_panel').hide();
$('charts_panel').hide();
$('compare_panel').hide();
//show the current panel
$('sample_data_panel').show();
//set the drop downs
if($('selection_grade_dropdown_sample_data')){
$('selection_grade_dropdown_sample_data').value = grade;
}
if($('selection_time_dropdown_sample_data')){
$('selection_time_dropdown_sample_data').value = time_period;
}
//update the sample data page
BWQualityHomepage.redrawTable('sample_datatable', 1, '');
break;
case 'compare':
// Hide all the other panels.
$('overview_panel').hide();
$('off_spec_summary_panel').hide();
$('charts_panel').hide();
$('sample_data_panel').hide();
// Show the compare panel.
$('compare_panel').show();
// Get the selected region and port (if there is anything selected).
var select_region = $('select_region').value;
var select_port = '';
if(select_region != '') {
var select_port = $('port_select_'+select_region).value;
}
$('select_port').value = select_port;
if($('is_subscriber')){
//set the radio buttons
if($('compare_select_graph_'+chart_type)){
$('compare_select_graph_'+chart_type).checked = true;
}
if($('compare_select_graph_'+graph_criteria)){
$('compare_select_graph_'+graph_criteria).checked = true;
}
//set the drop downs
if($('selection_grade_dropdown_compare')){
$('selection_grade_dropdown_compare').value = grade;
}
if($('selection_time_dropdown_compare')){
$('selection_time_dropdown_compare').value = time_period;
}
// Redo the compare drop-downs.
BWQualityHomepage.compareSelector();
BWQualityHomepage.redrawGraph('compare', chart_type, graph_criteria);
}
break;
}
BWQualityHomepage.updateKey();
BWQualityHomepage.logClick(0);
},
compareSelector: function() {
// Get the grade, start, and end dates.
var grade = $('grade').value;
var start_date = $('fromdate').value;
var end_date = $('todate').value;
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var select_port = $('select_port').value.replace(' ', '_');
var select_region = $('select_region').value;
new Ajax.Updater($('quality_compare_selector'), '/quality/_quality_compare_selector.php?grade='+grade+'&start_date='+start_date+'&end_date='+end_date+'&port_code='+port_code+'®ion_code='+region_code+'&select_port='+select_port+'&select_region='+select_region, {'evalScripts': true});
},
goToPrices: function(portstring) {
// What grade and time period are we on? We're going to pass that through to prices.
var grade = $('grade').value;
var time_period = $('time_period').value;
window.location='/prices/port/'+portstring+'/?grade='+grade+'&time_period='+time_period;
},
logClick: function(page) {
var port_code = $('port_code').value;
var region_code = $('region_code').value;
var grade = $('grade').value;
var repname = $('repname').value;
var view = $('view').value;
var time_period = $('time_period').value;
var graph_criteria = $('graph_criteria').value;
var chart_type = $('chart_type').value;
if(port_code != '') pagename = '/quality/port/'+port_code.replace(' ', '/').toLowerCase()+'/';
else if(region_code != '') pagename = '/quality/region/'+region_code;
else pagename = '/quality/';
var page_sub = repname;
page_sub += ' '+grade;
var analytics = pagename+grade+'/';
switch(time_period) {
case '0':
page_sub += ' 30 Day';
analytics += '30day/';
break;
case '1':
page_sub += ' 3 Month';
analytics += '3month/';
break;
case '2':
page_sub += ' 1 Year';
analytics += 'year/';
break;
case '3':
page_sub += ' Custom Dates';
analytics += 'custom/';
break;
}
var graph_criteria_word = '';
switch(graph_criteria) {
case "water":
graph_criteria_word = "Water";
break;
case "catfines":
graph_criteria_word = "Al + Si";
break;
case "sulphur":
graph_criteria_word = "Sulphur";
break;
}
var chart_type_word = '';
switch(chart_type) {
case "dist":
chart_type_word = "Distribution Graph";
break;
case "time":
chart_type_word = "Time Series Graph";
break;
case "pie":
chart_type_word = "Pie Chart";
break;
}
switch(view) {
case 'overview':
page_sub += ' Overview ' + chart_type_word +'s';
analytics += 'overview/'+chart_type+'/';
break;
case 'charts':
page_sub += ' ' + graph_criteria_word + ' ' + chart_type_word;
analytics += 'charts/'+graph_criteria+'/'+chart_type+'/';
break;
case 'off_spec':
page_sub += ' Off-Spec Summary';
analytics += 'offspec/';
break;
case 'sample_data':
if(page == 0) {
page_sub += ' Sample Data';
analytics += 'sample_data/';
} else {
page_sub += ' Sample Data Page '+page;
analytics += 'sample_data/page_'+page+'/';
}
break;
case 'compare':
page_sub += ' Compare ' + graph_criteria_word + ' ' + chart_type_word;
analytics += 'compare/'+graph_criteria+'/'+chart_type+'/';
break;
}
new Ajax.Request('/misc/_faux_page_view.php',
{
method:'get',
parameters: {faux_page_main: 'Bunkerworld Quality', faux_page_sub: page_sub, faux_pagename: pagename}
});
// Change the page title.
document.title = 'Bunkerworld Quality - '+page_sub;
var pageTracker = _gat._getTracker($('analytics_id').value+'');
pageTracker._trackPageview(analytics);
},
/**
* Draws the graphs on the overview
*
* @author Jessica Bailey
*
* Created 2010-06-25
*/
overviewDistGraphs: function(){
//change the chart_type to be dist
$('chart_type').value = "dist";
//Get the start date and end date, port, and grade
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var grade = $('grade').value;
var fromdate = $('fromdate').value;
var todate = $('todate').value;
$('quality_graph_catfines').update(''); //clear the old graph
$('quality_graph_water').update(''); //clear the old graph
$('quality_graph_sulphur').update(''); //clear the old graph
PM.global.newExtendedGraph($('quality_graph_catfines'), '/quality/_quality_distchart.php?port_code='+port_code+'&graph_criteria=catfines®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&mini=1', {createGraphDIV: true, width: '180px', height: '195px'});
PM.global.newExtendedGraph($('quality_graph_water'), '/quality/_quality_distchart.php?port_code='+port_code+'&graph_criteria=water®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&mini=1', {createGraphDIV: true, width: '180px', height: '195px'});
PM.global.newExtendedGraph($('quality_graph_sulphur'), '/quality/_quality_distchart.php?port_code='+port_code+'&graph_criteria=sulphur®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&mini=1', {createGraphDIV: true, width: '180px', height: '195px'});
},
overviewPieGraphs: function(){
// Change the chart_type to be pie
$('chart_type').value = "pie";
// Get the start date and end date, port, and grade
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var grade = $('grade').value;
var fromdate = $('fromdate').value;
var todate = $('todate').value;
$('quality_graph_catfines').update(""); //clear the old graph
$('quality_graph_water').update("
"); //clear the old graph
$('quality_graph_sulphur').update("
"); //clear the old graph
new Ajax.Updater($('quality_graph_catfines'), '/quality/_quality_piechart.php?port_code='+port_code+'&graph_criteria=catfines®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=overview&mini=1');
new Ajax.Updater($('quality_graph_water'), '/quality/_quality_piechart.php?port_code='+port_code+'&graph_criteria=water®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=overview&mini=1');
new Ajax.Updater($('quality_graph_sulphur'), '/quality/_quality_piechart.php?port_code='+port_code+'&graph_criteria=sulphur®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=overview&mini=1');
},
overviewTimeGraphs: function(){
// Change the chart_type to be time
$('chart_type').value = "time";
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var grade = $('grade').value;
var fromdate = $('fromdate').value;
var todate = $('todate').value;
$('quality_graph_catfines').update(''); //clear the old graph
$('quality_graph_water').update(''); //clear the old graph
$('quality_graph_sulphur').update(''); //clear the old graph
PM.global.newExtendedGraph($('quality_graph_catfines'), "/quality/_quality_timechart.php?graph_criteria=catfines&port_code="+port_code+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&view=overview&mini=1'", {createGraphDIV: true, width: '180px', height: '195px'});
PM.global.newExtendedGraph($('quality_graph_water'), "/quality/_quality_timechart.php?graph_criteria=water&port_code="+port_code+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&view=overview&mini=1'", {createGraphDIV: true, width: '180px', height: '195px'});
PM.global.newExtendedGraph($('quality_graph_sulphur'), "/quality/_quality_timechart.php?graph_criteria=sulphur&port_code="+port_code+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&view=overview&mini=1'", {createGraphDIV: true, width: '180px', height: '195px'});
},
redrawGraph: function(panel, chart_type, graph_criteria) {
// Blat titles.
if(panel == 'charts' && $('quality_title_charts')) $('quality_title_charts').update('');
if(panel == 'compare') {
if($('quality_title_compare1')) $('quality_title_compare1').update('');
if($('quality_title_compare2')) $('quality_title_compare2').update('');
}
$('chart_type').value = chart_type;
$('graph_criteria').value = graph_criteria;
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var grade = $('grade').value;
var fromdate = $('fromdate').value;
var todate = $('todate').value;
var time_period = $('time_period').value;
var select_region = $('select_region').value;
var select_port = $('select_port').value.replace(' ', '_');
var width=550;
if(panel == 'compare') width = 505;
// Make sure that the div for the graph is actually there (won't be there if we aren't a subscriber).
if($('bw_quality_graph_'+panel)) {
// Swirly icon while we are waiting.
$('bw_quality_graph_'+panel).update("
"); //clear the old graph
// If this is a flotr graph we need to blat the old contents of the divs.
if(chart_type == 'dist' || chart_type == 'time')
$('bw_quality_graph_'+panel).update('');
// Update the title for this graph, if there is one.
var region_title = '';
if(panel == 'charts') new Ajax.Updater($('quality_title_charts'), '/quality/_quality_graph_title.php?grade='+grade+'&graph_criteria='+graph_criteria+'&time_period='+time_period+'&fromdate='+fromdate+'&todate='+todate+'®ion_code='+region_title+'&port_code='+port_code);
if(panel == 'compare') {
// If both graphs are the same, hide the second one. Otherwise, show it.
if(port_code == select_port && region_code == select_region) $('compare2').hide();
else $('compare2').show();
// Is this Worldwide?
var region_title = region_code;
if(region_title == '') region_title = 'Worldwide';
// Update the titles for the comparison graphs.
new Ajax.Updater($('quality_title_compare1'), '/quality/_quality_graph_title.php?grade='+grade+'&graph_criteria='+graph_criteria+'&time_period='+time_period+'&fromdate='+fromdate+'&todate='+todate+'®ion_code='+region_title+'&port_code='+port_code);
// Is this Worldwide?
var region_title = select_region;
if(region_title == '') region_title = 'Worldwide';
// Update the titles for the comparison graphs.
new Ajax.Updater($('quality_title_compare2'), '/quality/_quality_graph_title.php?grade='+grade+'&graph_criteria='+graph_criteria+'&time_period='+time_period+'&fromdate='+fromdate+'&todate='+todate+'®ion_code='+region_title+'&port_code='+select_port);
if(chart_type == 'dist') {
// Blat second div.
$('bw_quality_graph_compare2').update('');
// Update both graphs
PM.global.newExtendedGraph($('bw_quality_graph_compare'), "/quality/_quality_distchart.php?port_code="+port_code+"&graph_criteria="+graph_criteria+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&chartsize=big", {createGraphDIV: true, width: width+'px', height: '270px'});
PM.global.newExtendedGraph($('bw_quality_graph_compare2'), "/quality/_quality_distchart.php?port_code="+select_port+"&graph_criteria="+graph_criteria+"®ion_code="+select_region+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&chartsize=big", {createGraphDIV: true, width: width+'px', height: '270px'});
} else if(chart_type == 'time') {
// Blat second div.
$('bw_quality_graph_compare2').update('');
// Update both graphs
PM.global.newExtendedGraph($('bw_quality_graph_compare'), "/quality/_quality_timechart.php?view=compare&port_code="+port_code+"&graph_criteria="+graph_criteria+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&full_dates=1", {createGraphDIV: true, width: width+'px', height: '270px'});
PM.global.newExtendedGraph($('bw_quality_graph_compare2'), "/quality/_quality_timechart.php?view=compare&port_code="+select_port+"&graph_criteria="+graph_criteria+"®ion_code="+select_region+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&full_dates=1", {createGraphDIV: true, width: width+'px', height: '270px'});
} else {
// Update the graphs
new Ajax.Updater($('bw_quality_graph_compare'), '/quality/_quality_piechart.php?port_code='+port_code+'&graph_criteria='+graph_criteria+'®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=compare');
new Ajax.Updater($('bw_quality_graph_compare2'), '/quality/_quality_piechart.php?port_code='+select_port+'&graph_criteria='+graph_criteria+'®ion_code='+select_region+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=compare');
}
} else {
if(chart_type == 'dist') PM.global.newExtendedGraph($('bw_quality_graph_'+panel), "/quality/_quality_distchart.php?port_code="+port_code+"&graph_criteria="+graph_criteria+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&chartsize=big", {createGraphDIV: true, width: width+'px', height: '270px'});
else if(chart_type == 'time') PM.global.newExtendedGraph($('bw_quality_graph_'+panel), "/quality/_quality_timechart.php?view=charts&port_code="+port_code+"&graph_criteria="+graph_criteria+"®ion_code="+region_code+"&grade="+grade+"&fromdate="+fromdate+"&todate="+todate+"&view=charts&full_dates=1", {createGraphDIV: true, width: width+'px', height: '270px'});
else if(chart_type == 'pie') new Ajax.Updater($('bw_quality_graph_'+panel), '/quality/_quality_piechart.php?port_code='+port_code+'&graph_criteria='+graph_criteria+'®ion_code='+region_code+'&grade='+grade+'&fromdate='+fromdate+'&todate='+todate+'&view=charts');
}
}
},
redrawTable: function(table_id, page, sortby) {
if(!table_id) return;
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var grade = $('grade').value;
var fromdate = $('fromdate').value;
var todate = $('todate').value;
// If we are sorting by something, reset the page.
if(sortby != '' && page != 0) page = 1;
$(table_id).update("
");
if(table_id == 'off_spec_summary_table') {
var sortdir = 'ASC';
// If we are sorting by date, percentage, or value, sort desc.
if(sortby == 'value_that_failed' || sortby == 'percent' || sortby == 'sampled_date' || sortby == '') sortdir = 'DESC';
// Are sorting by the same column? If so, swap sort order.
if(sortby == $('off_spec_sort').value) {
if($('off_spec_sort_dir').value == 'ASC') sortdir = 'DESC';
else sortdir = 'ASC';
} else {
if(sortby == '') sortby = $('off_spec_sort').value;
}
$('off_spec_sort').value = sortby;
$('off_spec_sort_dir').value = sortdir;
new Ajax.Updater($(table_id),'/quality/_quality_off_spec_summary.php?grade='+grade+'®ion_code='+region_code+'&fromdate='+fromdate+'&todate='+todate+'&port_code='+port_code+'&page='+page+'&sortby='+sortby+'&sortdir='+sortdir, {'evalScripts': true});
} else {
// Are sorting by the same column? If so, swap sort order.
if(sortby == $('sample_sort').value) {
if($('sample_sort_dir').value == 'ASC') $('sample_sort_dir').value = 'DESC';
else $('sample_sort_dir').value = 'ASC';
} else {
if(sortby == '') sortby = $('sample_sort').value;
$('sample_sort_dir').value = 'DESC';
}
$('sample_sort').value = sortby;
sortdir = $('sample_sort_dir').value;
new Ajax.Updater($(table_id),'/quality/_quality_sample_data.php?grade='+grade+'®ion_code='+region_code+'&fromdate='+fromdate+'&todate='+todate+'&port_code='+port_code+'&table_id='+table_id+'&page='+page+'&sortby='+sortby+'&sortdir='+sortdir, {'evalScripts': true});
}
BWQualityHomepage.logClick(page);
},
showHideChartGuide: function(view, show) {
if(show) {
$(view+'_chart_guide_show').hide();
$(view+'_chart_guide_hide').show();
$(view+'_chart_guide').show();
} else {
$(view+'_chart_guide_show').show();
$(view+'_chart_guide_hide').hide();
$(view+'_chart_guide').hide();
}
},
updateKey: function() {
// Update the key.
var graph_criteria = $('graph_criteria').value;
var chart_type = $('chart_type').value;
var view = $('view').value;
var port_code = $('port_code').value.replace(' ', '_');
var region_code = $('region_code').value;
var select_port = $('select_port').value.replace(' ', '_');
var select_region = $('select_region').value;
if($('quality_key_'+view))
new Ajax.Updater($('quality_key_'+view),'/quality/_quality_key.php?port_code='+port_code+'®ion_code='+region_code+'&select_port='+select_port+'&select_region='+select_region+'&view='+view+'&chart_type='+chart_type+'&graph_criteria='+graph_criteria, {'evalScripts': true});
},
updateKeyToSwirly: function() {
var view = $('view').value;
// We need to let the graph redraw before updating the key, since it's the redrawing that sets the hidden variables
// to the correct state (that we need for updateKey). But in the meantime, put the swirly working icon in place
// of the key.
if($('quality_key_'+view))
$('quality_key_'+view).update("
");
},
/**
* Changes the text of the Chart Guide
*
* @author Jessica Bailey
*
* created 2010-06-28
* last modified 2010-07-06
*/
updateGuide: function(){
var view = $('view').value;
var desc = '';
var chart_type = $('chart_type').value;
switch(chart_type){
case "dist":
desc="X-axis is the tested value in appropriate units. Y-axis is % of samples. Orange bar is % samples where the result fell outside of the ISO 8217 specification, but within the 95% Confidence Limit for the test in question (NC). Red bar is % samples that were off-specification according to ISO 8217 (OS).";
break;
case "time":
desc="X-axis is time - either date, week of year, month of year, or year. Y-axis is tested value in appropriate units. The area between the Orange line and the red line is the limit where a result in question falls above the limit in the ISO 8217 specification, but within the 95% Confidence Limit for the test in question. Red line is the outside ISO 8217 specification limit for the test in question. Light blue line is average tested value from all samples on that given day/week/month/year. Grey line is the maximum, and dark blue line the minimum tested values.";break;
break;
case "pie":
desc = "
Blue represents the % that were within the range 30-50 mg/kg.
Grey represents the % within the range 50-80 mg/kg.
Orange represents the % that were above the limit in the ISO 8217 specification, but still falls within the 95% confidence limits.
Red represents the % that exceed the ISO 8217 specification limit of 80mg/kg and the 95% confidence limits.
Orange represents % of samples that were outside the ISO 8217 specification limit of 0.5% V/V however falls within the 95% Confidence limits.
Red % of samples that were outside the ISO 8217 specification limit of 0.5% V/V.
Blue % of samples > 1.5% m/m sulphur and within the max ISO 8217 specification limit of 4.5% m/m.
Orange represents % of samples > 4.5% m/m ISO 8217 specification max limit but still within the 95% confidence limit.
Red represents % of samples that exceeded the ISO 8217 specification limit of 4.5% m/m.