/// <reference path="AJAXProfileMaintenance.aspx" />

function ButtonGetProfile_onclick() 
{
   Sys.Services.ProfileService.load(["FavoriteColor","PetsName","HomePageSettings"],onSuccess,onFailed,"gettingData");   
}

function ButtonSaveProfile_onclick() 
{
    Sys.Services.ProfileService.properties.FavoriteColor = $get("TextFavoriteColor").value;
    Sys.Services.ProfileService.properties.PetsName = $get("TextPetsName").value;
    Sys.Services.ProfileService.properties.HomePageSettings.News = $get("TextNews").value;
    Sys.Services.ProfileService.properties.HomePageSettings.Weather = $get("TextWeather").value;
    Sys.Services.ProfileService.properties.HomePageSettings.Sports = $get("TextSports").value;
    Sys.Services.ProfileService.save(["FavoriteColor","PetsName","HomePageSettings"],onSuccess,onFailed,"savingData");   

}

function onSuccess(result, userContext, methodName)
{
    if(userContext == "gettingData")
    {
       $get("TextFavoriteColor").value = Sys.Services.ProfileService.properties.FavoriteColor;
       $get("TextPetsName").value = Sys.Services.ProfileService.properties.PetsName;
       $get("TextNews").value = Sys.Services.ProfileService.properties.HomePageSettings.News;
       $get("TextWeather").value = Sys.Services.ProfileService.properties.HomePageSettings.Weather;
       $get("TextSports").value = Sys.Services.ProfileService.properties.HomePageSettings.Sports;
    }
}

function onFailed(result, userContext, methodName)
{
  alert("Wystąpił błąd:\n"  + result.get_message());
}
