﻿function onResized(sender, eventArgs) {
    var root = sender.get_element().content;
    var gridMain = root.findName("gridMain");
    if (gridMain != null) {
        gridMain.Height = root.actualHeight;
        gridMain.Width = root.actualWidth;
    }
}

function onSourceDownloadProgressChanged(sender, eventArgs) {
    var root = sender.get_element().content;
    var progress = Math.round((eventArgs.get_progress() * 100));
    updateDownloadStatus(root, progress);
}

function onSourceDownloadComplete(sender, eventArgs) {
    var root = sender.get_element().content;
    updateDownloadStatus(root, 100);
}

function updateDownloadStatus(root, progress) {
    if (root != null) {
        var txtProgress = root.findName("txtStatus");
        if (txtProgress != null) txtProgress.Text = progress.toString() + "%";
        var uxProgressBar = root.findName("uxProgressBar");
        if (uxProgressBar != null) {
            progress = Math.min(Math.max(0, progress), 100);
            uxProgressBar.ScaleX = progress / 100;
        }
    }
}
