﻿/// <reference path="jquery-1.2.6-vsdoc.js" />

var login_reg = /^[\w\-]{3,32}$/;
var pass_reg = /^.{6,32}$/;

function ValidateInput(input, reg) {
    var result = reg.test($(input)[0].value);
    if (!result) SetInputState(input, "error");
    else SetInputState(input, "valid");
    return result;
}
function SetInputState(input, state) {
    $(input).removeClass("important valid common error").addClass(state);
}
function doAjax(url, params, onSuccess, onError) {
    $.ajax({
        type: "GET",
        dataType: "html",
        url: url,
        data: params,
        success: onSuccess,
        error: onError        
    });
}
function onLoginCheck(result) {
    if (result == "false")
        SetInputState($("#LoginInput"), "error");
}
function onLoginCheckError(error) {
    alert("Error");
}

var last_check = "";
$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $("#ajax-ind").show();
        });
        $().ajaxStop(function() {
            $("#ajax-ind").hide();
        });
        // Login init
        $("#LoginList").accordion();
        $("#ld-close").click(function() { $("#logindisplay").hide(500);$("#EnterLink").show(500); return false; });
        $("#LoginInput").blur(function() {
            if (last_check != $(this)[0].value) {
                if (ValidateInput(this, login_reg))
                    doAjax("Serialer/Account/CheckLogin", { login: $(this)[0].value }, onLoginCheck, onLoginCheckError);
                last_check = $(this)[0].value;
            }
        });
        $("#PassInput").blur(function() {
            ValidateInput(this, pass_reg);
        });
        $("#EnterLink").click(function() {
            $(this).hide(500);
            $("#logindisplay").show(500);
            $("#LoginInput").focus();
            return false;
        })

        $("#cmdLogin").click(function() {
            var password_hash = hex_hmac_sha1($("#PassInput")[0].value, $("#Challenge")[0].value);
        });
    }
);


var last_check = "";
$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $("#ajax-ind2").show();
        });
        $().ajaxStop(function() {
            $("#ajax-ind2").hide();
        });
        // Login init
        $("#LoginList2").accordion();
        $("#ld-close2").click(function() { $("#logindisplay2").hide(500);$("#EnterLink2").show(500); return false; });
        $("#EnterLink2").click(function() {
            $(this).hide(500);
            $("#logindisplay2").show(500);
            $("#LoginInput2").focus();
            return false;
        })

        $("#cmdLogin2").click(function() {
            var password_hash = hex_hmac_sha1($("#PassInput")[0].value, $("#Challenge")[0].value);
        });
    }
);

var last_check = "";
$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $("#ajax-ind3").show();
        });
        $().ajaxStop(function() {
            $("#ajax-ind3").hide();
        });
        // Login init
        $("#LoginList3").accordion();
        $("#ld-close3").click(function() { $("#logindisplay3").hide(500);$("#EnterLink3").show(500); return false; });
        $("#EnterLink3").click(function() {
            $(this).hide(500);
            $("#logindisplay3").show(500);
            $("#LoginInput3").focus();
            return false;
        })

        $("#cmdLogin3").click(function() {
            var password_hash = hex_hmac_sha1($("#PassInput")[0].value, $("#Challenge")[0].value);
        });
    }
);

var last_check = "";
$(document).ready
(
    function() {
        // Ajax init
        $().ajaxStart(function() {
            $("#ajax-ind4").show();
        });
        $().ajaxStop(function() {
            $("#ajax-ind4").hide();
        });
        // Login init
        $("#LoginList4").accordion();
        $("#ld-close4").click(function() { $("#logindisplay4").hide(500);$("#EnterLink4").show(500); return false; });
        $("#EnterLink4").click(function() {
            $(this).hide(500);
            $("#logindisplay4").show(500);
            $("#LoginInput4").focus();
            return false;
        })

        $("#cmdLogin").click(function() {
            var password_hash = hex_hmac_sha1($("#PassInput")[0].value, $("#Challenge")[0].value);
        });
    }
);
