// FUNCTION: Override default alert functionality to check for AGK JavaScript requests.
(function(p) {
    window.alert = function() {

        sData = arguments[0];

        if (sData.indexOf("|JS|") == 0) {
            sData = sData.substr(4);
            escapedStr = sData.replace(/"/g, '\\"').replace(/\n/g, '');
            eval(JSON.parse(sData).func_name + "('" + escapedStr + "');");
        } else {
            return p.apply(this, arguments);
        }
    };
})(window.alert);

// FUNCTION: Update Title Bar with AGK Data
function UpdateTitleBar(data) {
    // Convert data to a JavaScript object
    data = JSON.parse(data);

    // Update title bar (tab titles) with user and click count
    document.title = "Score: " + data.int_data[0];

}

// FUNCTION: Update Header with AGK Data
function UpdateHeader(data) {
    // Convert data to a JavaScript object
    data = JSON.parse(data);

    document.getElementById("userName").textContent = data.str_data[0];
}