var PLOT_URL = BASE_DOMAIN + 'climate/enso/monitoring/index.html';

var DATA_FILES = new Array(6);
DATA_FILES[0]  = '/climate/enso/nino_1.txt';
DATA_FILES[1]  = '/climate/enso/nino_2.txt';
DATA_FILES[2]  = '/climate/enso/nino_3.txt';
DATA_FILES[3]  = '/climate/enso/nino_3.4.txt';
DATA_FILES[4]  = '/climate/enso/nino_4.txt';
DATA_FILES[5]  = '/climate/enso/iod_1.txt';

var IMAGE_FILES = new Array(6);
IMAGE_FILES[0]  = '/climate/enso/monitoring/nino1.png';
IMAGE_FILES[1]  = '/climate/enso/monitoring/nino2.png';
IMAGE_FILES[2]  = '/climate/enso/monitoring/nino3.png';
IMAGE_FILES[3]  = '/climate/enso/monitoring/nino3_4.png';
IMAGE_FILES[4]  = '/climate/enso/monitoring/nino4.png';
IMAGE_FILES[5]  = '/climate/enso/monitoring/iod1.png';

var POSTSCRIPT_FILES = new Array(6);
POSTSCRIPT_FILES[0]  = '/climate/enso/monitoring/nino1.eps';
POSTSCRIPT_FILES[1]  = '/climate/enso/monitoring/nino2.eps';
POSTSCRIPT_FILES[2]  = '/climate/enso/monitoring/nino3.eps';
POSTSCRIPT_FILES[3]  = '/climate/enso/monitoring/nino3_4.eps';
POSTSCRIPT_FILES[4]  = '/climate/enso/monitoring/nino4.eps';
POSTSCRIPT_FILES[5]  = '/climate/enso/monitoring/iod1.eps';

function xmlHttpStatusProceed() {
    var response = xmlHttp.responseText;
    document.getElementById('dataDate').innerHTML
        = '<strong>' + response + '</strong>';
    document.getElementById('control-set').style.visibility = 'visible';
    updatePlotView(2);

    return;
}

function xmlHttpStatusError() {
    xmlHttpStatusProceed();
    
    return;
}

function loadBookmarkedProduct(paramType) {
    document.getElementById('control-set').style.visibility = 'hidden';
    sendRequest(PLOT_URL, 'text/html');

    return;
}

function updatePlotView(plotNumber) {
    document.getElementsByName('viewPlot')[0].selectedIndex = plotNumber;
    document.getElementById('nino-graph').src = IMAGE_FILES[plotNumber];
    document.getElementById('right-floater').innerHTML
        = getDataLink(plotNumber);

    return;
}

function getDataLink(plotNumber) {
    var dataLink = '<div class="content-item">' +
                   '<p><a href="' + POSTSCRIPT_FILES[plotNumber] +
                   '" target="_blank" title="Download">PostScript version</a>' +
                   '<br /><a href="' + DATA_FILES[plotNumber] +
                   '" target="_blank" title="Opens in a new window">Data sorted by date</a>';

    if (plotNumber == 5) {
        dataLink += '<br /><a href="indices/iod-area-map.gif" target="_blank" title="Opens in a new window">IOD area map</a>';
        dataLink += '<br /><a href="/climate/IOD/" target="_blank" title="Opens in a new window">IOD impacts</a>';
    }
    else {
        dataLink += '<br /><a href="/climate/enso/ensorain.comp.shtml" target="_blank" title="Opens in a new window">ENSO impacts</a>';
    }

    dataLink += '</p></div>';
    
    return dataLink;
}

function showNinoMap() {
    document.getElementById('nino-map').style.visibility = 'visible';

    return;
}

function hideNinoMap() {
    document.getElementById('nino-map').style.visibility = 'hidden';

    return;
}

function plotBack() {
    var selectedIndex = document.getElementsByName('viewPlot')[0].selectedIndex;
    var optionsSize = document.getElementsByName('viewPlot')[0].options.length;

    if (selectedIndex == 0) {
        document.getElementsByName('viewPlot')[0].selectedIndex
            = optionsSize - 1;
    }
    else {
        document.getElementsByName('viewPlot')[0].selectedIndex -= 1;
    }

    updatePlotView(document.getElementsByName('viewPlot')[0].value);

    return;
}

function plotNext() {
    var selectedIndex = document.getElementsByName('viewPlot')[0].selectedIndex;
    var optionsSize = document.getElementsByName('viewPlot')[0].options.length;

    if (selectedIndex == optionsSize - 1) {
        document.getElementsByName('viewPlot')[0].selectedIndex = 0;
    }
    else {
        document.getElementsByName('viewPlot')[0].selectedIndex += 1;
    }

    updatePlotView(document.getElementsByName('viewPlot')[0].value);

    return;
}
