﻿function ShowVidCaps(productId) {
    //Call existing global function to obtain a reference to the window manager
    var oManager = GetRadWindowManager();
    //Show a particular existing window
    var wnd = oManager.open("VidCaps.aspx?ProductId=" + productId, "VidCaps");
}

function HideCategory(categoryId) {
    RemoveCategoryFromScreen(categoryId);
    SaveHiddenCategoryIntoProfile(categoryId);    
}

function RemoveCategoryFromScreen(categoryId) {
    var categoryObj = document.getElementById("CategoryLine_" + categoryId);
    categoryObj.parentNode.removeChild(categoryObj);
}

function SaveHiddenCategoryIntoProfile(categoryId) {
    
    var hiddenCategories = Sys.Services.ProfileService.properties.HiddenCategories;
    hiddenCategories = hiddenCategories + categoryId + ',';
    Sys.Services.ProfileService.properties.HiddenCategories = hiddenCategories;

    // Save profile information.
    Sys.Services.ProfileService.save(null,
    SaveCompletedCallback, ProfileFailedCallback, null);
}

function ShowCategory(categoryId) {
    RemoveCategoryFromScreen(categoryId);
    SaveShownCategoryIntoProfile(categoryId);
}

function SaveShownCategoryIntoProfile(categoryId) {

    var hiddenCategories = Sys.Services.ProfileService.properties.HiddenCategories;
    hiddenCategories = hiddenCategories.replace(categoryId + ',', '');
    Sys.Services.ProfileService.properties.HiddenCategories = hiddenCategories;

    // Save profile information.
    Sys.Services.ProfileService.save(null,
    SaveCompletedCallback, ProfileFailedCallback, null);

}

// This is the callback function called 
// if the profile was saved successfully.
function SaveCompletedCallback(numProperties, userContext, methodName) {

    // Hide the area that contains 
    // the controls to set the profile properties.
    //SetProfileControlsVisibility("hidden");
    RefreshProductsAndStores();
}

function RefreshProductsAndStores() {
    var storesByLatestUpdate =
            document.getElementById('StoresByLatestUpdate');
    var storesByAlphabeticalOrder =
            document.getElementById('StoresByAlphabeticalOrder');
    var latelyAddedFrame =
            document.getElementById('LatelyAddedFrame');
    if(storesByLatestUpdate)
        storesByAlphabeticalOrder.contentWindow.location.reload(true);
    if(storesByAlphabeticalOrder)
        storesByLatestUpdate.contentWindow.location.reload(true);
    if (latelyAddedFrame)
        latelyAddedFrame.contentWindow.location.reload(true);
}

// This is the callback function called 
// if the profile load or save operations failed.
function ProfileFailedCallback(error_object, userContext, methodName) {
    alert("Profile service failed with message: " +
    error_object.get_message());
}

// Loads the profile of the current
// authenticated user.
function LoadProfile() {
    Sys.Services.ProfileService.load(null,
    LoadCompletedCallback, ProfileFailedCallback, null);
}

// Reads the profile information and displays it.
function LoadCompletedCallback(numProperties, userContext, methodName) {
    
}

// This is the callback function called 
// if the profile load or save operations failed.
function ProfileFailedCallback(error_object, userContext, methodName) {
    alert("Profile service failed with message: " +
    error_object.get_message());
}

function pageLoad() {
    LoadProfile();
}

function OnClientTabSelected(sender, args) {
    var tab = args.get_tab();
    if (tab.get_index() == 0) {
        //__doPostBack('VisibleCategoriesPanel', '');
    }
    else if (tab.get_index() == 1) {
        //__doPostBack('HiddenCategoriesPanel', '');
    }
}

function ShowAddCategoriesWindow()
{
    //Call existing global function to obtain a reference to the window manager
    var oManager = GetRadWindowManager();
    //Show a particular existing window
    oManager.open (null, "AddCategoriesWindow");
}

function AddCategoriesWindowClose(sender, args) {
    sender.BrowserWindow.PostBackOnMainPage();
    RefreshProductsAndStores();
}

function RefreshStores() {
    var storesByLatestUpdate =
        document.getElementById('StoresByLatestUpdate');
    var storesByAlphabeticalOrder =
        document.getElementById('StoresByAlphabeticalOrder');
    alert(storesByLatestUpdate);
    alert(storesByAlphabeticalOrder);
}