var checkboxShowEquation, fitTypeMenu, orderCon, chart, trendLine, lineMarker;

function InitialWhenDReady() {
    checkboxShowEquation = document.getElementById("checkboxShowEquation");
    fitTypeMenu = wijmo.Control.getControl("#fitTypeMenu");
    orderCon = document.getElementById("orderCon");
    chart = wijmo.Control.getControl("#trendChart");
    if (chart) {
        trendLine = chart.series[1];
        lineMarker = c1.getExtender(chart, "LineMarker");
    }
}

function itemClicked(arg) {
    if (!fitTypeMenu || !chart || !trendLine) {
        return;
    }
    fitTypeMenu.header = "FitType: <b>" + arg + "</b>";

    if (orderCon) {
        if (arg === 'Fourier' || arg === 'Polynomial') {
            orderCon.style.display = "";
        } else {
            orderCon.style.display = "none";
        }
    }

    chart.beginUpdate();

    trendLine.fitType = arg;

    chart.endUpdate();
}

function orderChanged(host) {
    if (!chart || !trendLine) {
        return;
    }

    chart.beginUpdate();

    trendLine.order = host.value;

    chart.endUpdate();
}

function getContent() {
    if (!chart || !trendLine || !trendLine.getEquation) {
        return "TrendLine";
    }
    return trendLine.getEquation();
}

function showEquation() {
    if (lineMarker) {
        lineMarker.isVisible = checkboxShowEquation.checked;
    }
}