var typeMenu, chart, trendLine;

function InitialWhenDReady() {
    typeMenu = wijmo.Control.getControl("#typeMenu");
    chart = wijmo.Control.getControl("#movingAChart");
    if (chart) {
        trendLine = chart.series[1];
    }
}

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

    chart.beginUpdate();

    trendLine.type = arg;
    trendLine.name = arg[0] + "MA";

    chart.endUpdate();
}

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

    chart.beginUpdate();

    trendLine.period = host.value;

    chart.endUpdate();
}