﻿/// <reference path='ProfileRes.js' />
Type.registerNamespace("Microsoft.Com.Profile");
Microsoft.Com.Profile.ViewProfile =
{
    initialize: function(path, containerDiv, loadingDiv, errorDiv, currentTab) {
        this._containerDiv = containerDiv;
        this._loadingDiv = loadingDiv;
        this._errorDiv = errorDiv;
        this._currentTab = currentTab;
        this._serverPath = path;
    },
    UpdateProfileTab: function(appName, app, user, locale, brand) {
        if (appName == this._currentTab || this._active) {
            return;
        }
        this._active = true;
        this._currentTab = appName;
        $(".VerticalTabs .TabOn").removeClass("TabOn").addClass("TabOff");
        $("#" + appName).parent().removeClass("TabOff").addClass("TabOn");

        $("#" + this._containerDiv).hide();
        $("#" + this._errorDiv).hide();
        $("#" + this._loadingDiv).show();

        PageMethods.set_path(this._serverPath + "ViewProfile.aspx");
        PageMethods.GetSubProfileData(app, user, locale, brand, this.SubProfileSuccess, this.SubProfileError);


    },

    SubProfileSuccess: function(data, textStatus) {
        Microsoft.Com.Profile.ViewProfile._active = false;
        var error = true;
        try {
            document.getElementById(Microsoft.Com.Profile.ViewProfile._containerDiv).innerHTML = data;
            error = false;
        }
        catch (excep) {
        }
        if (error) {
            $("#" + Microsoft.Com.Profile.ViewProfile._loadingDiv).hide();
            $("#" + Microsoft.Com.Profile.ViewProfile._errorDiv).show();
        }
        else {
            $("#" + Microsoft.Com.Profile.ViewProfile._errorDiv).hide();
            $("#" + Microsoft.Com.Profile.ViewProfile._loadingDiv).hide();
            $("#" + Microsoft.Com.Profile.ViewProfile._containerDiv).show();
        }
    },

    SubProfileError: function(data, textStatus) {
        Microsoft.Com.Profile.ViewProfile._active = false;
        $("#" + Microsoft.Com.Profile.ViewProfile._loadingDiv).hide();
        $("#" + Microsoft.Com.Profile.ViewProfile._errorDiv).show();
    }
}



