//Global var because we need to save the old color.
var highlightCharts = [];

function clearFilterText()
{
    document.getElementById("txtChartNumber").value = "";
    clearFilterColor();
}

function clearFilterColor()
{
    // Close the chart label/details.
    closeDivPopup();

    //checks to see if there was a previous array if not it ignores it.
    if (highlightCharts.length > 0)
    {
        for(i = highlightCharts.length - 1; i >= 0; i --)
        {
            objTemp = window[highlightCharts[i]];

            objTemp.isFiltered = false;

            //Resets the old color
            objTemp.setStrokeStyle({color: objTemp.origColor});
            if (!objTemp.isHidden()) objTemp.redraw(true);

            //deletes the array
            highlightCharts.splice(i, 1);
        }
    }
}

function filterChart()
{
    var sReturnFilterChart;
    var splitChartString;

    // Create a new XML HTTP object for AJAX operation.
    var objTempXmlHttp = getNewXmlHTTPObject();

    // Call the server side code to update the session.
    if (!isXmlHTTPNull(objTempXmlHttp))
        doXMLRequest(objTempXmlHttp, "./jsp/getFilteredCharts.jsp?chartNumber=" + document.getElementById("txtChartNumber").value, "post", false, "", "");

    // sReturnFilterChart = value returned from the zoomToChartBoundary will be null if the chart does not exist
    sReturnFilterChart = (objTempXmlHttp.responseText == "null" ? null : objTempXmlHttp.responseText);

    //Clears previous filterchart
    clearFilterColor();

    if (sReturnFilterChart != null)
    {
        splitChartString = sReturnFilterChart.split("|");

        // Get the charts to highlight.
        highlightCharts = splitChartString[0].split(",");

        // Highlight the polyline(s).
        for(i = 0; i < highlightCharts.length; i++)
        {
            objTemp = window[highlightCharts[i]];
            objTemp.origColor = objTemp.color;
            objTemp.filterColor = strPolylineFilterColor;
            objTemp.isFiltered = true;

            objTemp.setStrokeStyle({color: objTemp.filterColor});
        }

        // Get the bounds.
        eval(splitChartString[1]);

        // Recenter map and apply zoom.
        zoomToBounds(bounds);

    }
    else
        alert(strErrorNoChart);
}
