<script language="javascript" type="text/javascript">
        function Login_OnClick()
        {
            if (document.getElementById("txtUsername").value == "")
            {
                alert("Wprowadź nazwę użytkownika");
                document.getElementById("txtUsername").focus();
                return;
            }
            if (document.getElementById("txtPassword").value == "")
            {
                alert("Wprowadź hasło");
                document.getElementById("txtPassword").focus();
                return;
            }
                Sys.Services.AuthenticationService.set_defaultLoginCompletedCallback(OnLoginCompleted);
                Sys.Services.AuthenticationService.set_defaultFailedCallback(OnFailed);
                Sys.Services.AuthenticationService.set_defaultLogoutCompletedCallback(OnLogoutCompleted);
                Sys.Services.AuthenticationService.login(document.getElementById("txtUsername").value, document.getElementById("txtPassword").value, false,null,null,null,null,"User Context");
                return;
            }
            function Logout_OnClick()
            {
                Sys.Services.AuthenticationService.logout(null, null, null, null);
            }
            function OnLoginCompleted(validCredentials, userContext, methodName)
            {
                if (validCredentials == true)
                {
                    document.getElementById("divLogin").style.display = 'none';
                    document.getElementById("divHome").style.display = 'block';
                    document.getElementById("divProfile").style.display = 'block';
                    LoadProfile();
                }
                else
                {
                    alert("Nieprawidłowe dane!");
                    document.getElementById("txtUsername").focus();
                }
                return;
            }
            function OnFailed(error, userContext, methodName)
            {
                alert("Próba zalogowania się zakończyła się niepowodzeniem. Szczegóły: " + error.get_message() + ". " + error.get_statusCode());
                return;
            }
            function OnLogoutCompleted(result)
            {
                document.getElementById("divLogin").style.display = 'block';
                document.getElementById("divHome").style.display = 'none';
                document.getElementById("divProfile").style.display = 'none';
                return;
            }
            // Profile w Ajaksie
            function LoadProfile()
            {
                Sys.Services.ProfileService.load(null, OnLoadCompletedCallback, OnProfileFailedCallback, null);
            }
            // Czyta informacje profilu i wyświetla je.
            function OnLoadCompletedCallback(numProperties, userContext, methodName)
            {
                // Pobiera dane kontaktowe.
                document.getElementById("txtFirstName").value = Sys.Services.ProfileService.properties.Contact.FirstName;
                document.getElementById("txtLastName").value = Sys.Services.ProfileService.properties.Contact.LastName;
                document.getElementById("txtAge").value = Sys.Services.ProfileService.properties.Contact.Age;
                document.getElementById("txtEmail").value = Sys.Services.ProfileService.properties.Contact.Email;
                // Pobiera dane adresowe.
                document.getElementById("txtStreet").value = Sys.Services.ProfileService.properties.Address.Street;
                document.getElementById("txtCity").value = Sys.Services.ProfileService.properties.Address.City;
                document.getElementById("txtPostalCode").value =  Sys.Services.ProfileService.properties.Address.PostalCode;
                // Pobiera informacje o kolorze tła.
                document.getElementById("txtBackgroundcolor").value = Sys.Services.ProfileService.properties.Backgroundcolor;
                document.body.bgColor = Sys.Services.ProfileService.properties.Backgroundcolor;
            }
            function OnProfileFailedCallback(error_object, userContext, methodName)
            {
                alert("Błąd usługi profili. Szczegóły: " + error_object.get_message());
            }
            function SaveProfile()
            {
                // Ustawia dane kontaktowe.
                Sys.Services.ProfileService.properties.Contact.FirstName = document.getElementById("txtFirstName").value;
                Sys.Services.ProfileService.properties.Contact.LastName = document.getElementById("txtLastName").value;
                Sys.Services.ProfileService.properties.Contact.Age = document.getElementById("txtAge").value;
                Sys.Services.ProfileService.properties.Contact.Email = document.getElementById("txtEmail").value;
                // Ustawia dane adresowe.
                Sys.Services.ProfileService.properties.Address.Street = document.getElementById("txtStreet").value;
                Sys.Services.ProfileService.properties.Address.City = document.getElementById("txtCity").value;
                Sys.Services.ProfileService.properties.Address.PostalCode = document.getElementById("txtPostalCode").value;
                // Ustawia kolor tła.
                Sys.Services.ProfileService.properties.Backgroundcolor = document.getElementById("txtBackgroundcolor").value;
                // Zapisuje dane profilu.
                Sys.Services.ProfileService.save(null, OnSaveCompletedCallback, OnProfileFailedCallback, null);
            }
            // Funkcja zwrotna, która jest wywoływana, gdy
            // zapisywanie profilu zakończy się powodzeniem.
            function OnSaveCompletedCallback(numProperties, userContext, methodName)
            {
                alert("Profil użytkownika został zapisany!");
                LoadProfile();
            }
            </script>
