﻿Type.registerNamespace("HOME");
var common = new COMMON.UIUtil();

var HIGHLIGHTID = "highlights";
var BULLETINID = "Bulletins";
var PUBLICATIONID = "Publications";
var ANNUALREPORTID = "AnnualReports";
var FINALCIALID = "FinancialDocuments";

HOME.UIManager = function() {
}

HOME.UIManager.prototype = {
    AttachEvents: function() {
        //$addHandler($get("Button2"), "click", removeCssClassMethod);
    },

    LoadDynamicData: function() {
        var documentServiceClient = new ITICClients.DocumentClient();
        documentServiceClient.getHighlights(this.callback_highlight, this.callback_error, common.showwaitscreen, HIGHLIGHTID);
        documentServiceClient.getBulletinsForHome(this.callback_Bulletin, this.callback_error, common.showwaitscreen, BULLETINID);
        //documentServiceClient.getPublications(this.callback_Publication, this.callback_error, common.showwaitscreen, PUBLICATIONID);
        documentServiceClient.getAnnualReport(this.callback_Annual, this.callback_error, common.showwaitscreen, ANNUALREPORTID);
        documentServiceClient.getFinancialDocuments(this.callback_Financial, this.callback_error, common.showwaitscreen, FINALCIALID);
    },

    callback_highlight: function(result) {
        try {
            //populate result
            if (result.IsSuccess = "true") {
                $get(HIGHLIGHTID).innerHTML = result.Result;
                common.hidewaitscreen();
            }

            //if need to navigate
            var navurl = new String(result.NavigateURL);
            if (navurl.trim() != "null" && navurl.trim() != "") {
                window.location = navurl;
            }
        }
        catch (e) {
            //need to show communication error
            //show error dialog
            alert(e.message);
        }
        finally {
            //hidewait screen
        }
    },

    callback_Bulletin: function(result) {
        try {
            //populate result
            if (result.IsSuccess = "true") {
                $get(BULLETINID).innerHTML = result.Result;
                common.hidewaitscreen();
            }

            //if need to navigate
            var navurl = new String(result.NavigateURL);
            if (navurl.trim() != "null" && navurl.trim() != "") {
                window.location = navurl;
            }
        }
        catch (e) {
            //need to show communication error
            //show error dialog
        }
        finally {
            //hidewait screen
        }
    },

    callback_Publication: function(result) {
        try {
            //populate result
            if (result.IsSuccess = "true") {
                $get(PUBLICATIONID).innerHTML = result.Result;
                common.hidewaitscreen();
            }

            //if need to navigate
            var navurl = new String(result.NavigateURL);
            if (navurl.trim() != "null" && navurl.trim() != "") {
                window.location = navurl;
            }
        }
        catch (e) {
            //need to show communication error
            //show error dialog
        }
        finally {
            //hidewait screen
        }
    },

    callback_Annual: function(result) {
        try {
            //populate result
            if (result.IsSuccess = "true") {
                $get(ANNUALREPORTID).innerHTML = result.Result;
                common.hidewaitscreen();
            }

            //if need to navigate
            var navurl = new String(result.NavigateURL);
            if (navurl.trim() != "null" && navurl.trim() != "") {
                window.location = navurl;
            }
        }
        catch (e) {
            //need to show communication error
            //show error dialog
        }
        finally {
            //hidewait screen
        }
    },

    callback_Financial: function(result) {
        try {
            //populate result
            if (result.IsSuccess = "true") {
                $get(FINALCIALID).innerHTML = result.Result;
                common.hidewaitscreen();
            }

            //if need to navigate
            var navurl = new String(result.NavigateURL);
            if (navurl.trim() != "null" && navurl.trim() != "") {
                window.location = navurl;
            }
        }
        catch (e) {
            //need to show communication error
            //show error dialog
        }
        finally {
            //hidewait screen
        }
    },

    callback_error: function(result) {
//        var uiUtil = new COMMON.UIUtil();
//        uiUtil.showServiceException(result);
//        uiUtil.hidewaitscreen();
    },

    dispose: function() {
        //disposed
    }
}

HOME.UIManager.registerClass('HOME.UIManager', null, Sys.IDisposable)

//page load function
function pageLoad() {
    var uiManger = new HOME.UIManager();
    uiManger.LoadDynamicData();
}

// Notify ScriptManager that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();