﻿/// <reference path="../jquery-1.3.2.js" />
//jQuery(function($) {



$(document).ready(function() {
    //hide login screen and edit buttons
    $("#login, .edit, .close, .ckfinderframe").hide();
    clearLogin();

    //when already logged in show edit buttons
    if ($.session("admin") == "true") {
        if ($(".editorvisible").size() == 0) {
            $(".edit").show();
        }
    }

    //event handlers for login screen
    //double click footer to show screen
    $("#footer").dblclick(function() { $("#login").slideDown(); clearLogin(); });

    //click close image to hide screen
    $("#imgclose").click(function() { $("#login").slideUp(); clearLogin(); });

    //login button
    $("#Aanmelden").click(function() {

        $.ajax({
            type: "POST",
            url: "testpagemethod.aspx/GetAuthorisation",
            data: "{user:'" + $("#username").val() + "'," + "password:'" + $("#password").val() + "'}",
            contentType: "application/json;  charset=utf-8",
            dataType: "json",
            success: function(xhr) {
                if (xhr.d == "true") {
                    $(".edit").show(); $.session("admin", "true"); $("#login").slideUp();
                }
                else {
                    if (xhr.d == "unknown username") {
                        clearLogin();
                    }
                    if (xhr.d == "incorrect password") {
                        $("#password").val('');
                    }
                    alert(xhr.d);
                    $(".edit").hide();
                }
            },
            error: function(xhr, error) {
                clearLogin();
                alert("Technical error. Login not possible at this time");
                $(".edit").slideUp();

            }
        });
    });

    function clearLogin() {
        if ($.session("admin") != "true") $.session("admin", "false");
        $("#username, #password").val('');

    }
});



//  $.ajax({
//      type: "POST",
//      url: "iovmain.aspx/GetDate",
//      data: "{}",
//      contentType: "application/json; charset=utf-8",
//      dataType: "json",
//      success: function(msg) {
//        // Replace the div's content with the page method's return.
//        alert(msg.d);
//        //$("#Result").text(msg.d);
//      }
//    });


