// JScript source code

//contains calls to silverlight.js, example below loads Page.xaml
function createSilverlight() {

    Silverlight.createObjectEx({
        source: "BankingDemo.xap",
        parentElement: document.getElementById("SilverlightControlHost"),
        id: "SilverlightControl",
        properties: {
            width: "100%",
            height: "100%",
            version: "1.1",
            enableHtmlAccess: "true",
            isWindowless: "true"
        },
        events: {
            onLoad: SLContainerLoaded //, 
            //onError:  function  ( ) { alert ( 'error' ); } 

        },
        initParams: "screen=Main"
    });

    // Give the keyboard focus to the Silverlight control by default
    document.body.onload = function() {
        var silverlightControl = document.getElementById('SilverlightControl');
        if (silverlightControl)
            silverlightControl.focus();
    }
}

// On main SL container load, initialize other SL container
// and set handlers
function SLContainerLoaded(sender, args) {

    //   createBillPayHistories();
    //    ResizeSLContainer

    // Resize main container    
    sender.content.onResize = ResizeSLContainer;

    // Resize main container
    var slPlugin = document.getElementById("SilverlightControl");
}

function ResizeSLContainer() {
    var slPlugin = document.getElementById("SilverlightControl");



    // Scale canvas
    slPlugin.Content.MainWindow.ScaleContainer(slPlugin.content.actualHeight, slPlugin.content.actualWidth);

    // Resize main container
    if (slPlugin.content.actualHeight > 0) {
        slPlugin.width = (slPlugin.content.actualHeight / 744) * 1005;
    }

}

// SL container for MiniBillGraphs on the Bill Pay screen
function createBillPayHistories() {
    Silverlight.createObjectEx({
        source: "ClientBin/BankingDemo.xap",
        parentElement: document.getElementById("BillPaySLHost"),
        id: "BillPaySLControl",
        properties: {
            width: "100%",
            height: "100%",
            version: "1.1",
            enableHtmlAccess: "true"

        },
        events: {
        //onLoad: BillPaySLContainerLoaded
    },
    initParams: "screen=BillPayHistories"
});

}

// On load for the Bill Pay MiniGraphs SL Container
// set handlers for bill pay history graphs to popup the detailed graph
function BillPaySLContainerLoaded() {
    var control = document.getElementById("BillPaySLControl");
    control.Content.BillPaySLContainer.showHistoryWindow = onShowHistoryWindow;
    control.Content.BillPaySLContainer.hideHistoryWindow = onHideHistoryWindow;
}

// Show detailed history window handler
function onShowHistoryWindow(sender, args) {

    var control = document.getElementById("BillPayPopupSL");
    control.Content.BillPayPopup.showPopup(args.GraphID);

    //var control = document.getElementById("SilverlightControl");    
    //control.Content.BillPayScreen.showHistory();    
}

// Hide detailed history window handler
function onHideHistoryWindow(sender, args) {

    var control = document.getElementById("BillPayPopupSL");
    control.Content.BillPayPopup.hidePopup();
    //var control = document.getElementById("SilverlightControl");    
    //control.Content.BillPayScreen.hideHistory();
}


// Create SL container for detailed history window
function createBillPayPopup() {
    Silverlight.createObjectEx({
        source: "ClientBin/BankingDemo.xap",
        parentElement: document.getElementById("BillPayPopupSLHost"),
        id: "BillPayPopupSL",
        properties: {
            width: "485px",
            height: "297.472px",
            version: "1.1",
            enableHtmlAccess: "true"
        },
        events: {
    },
    initParams: "screen=BillPayPopup"
});

}


