/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){

    /////////////////////////////////////////////////////////////
    $("#personalEnter").css('visibility', 'visible');
    $("#personalEnter").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        buttons: {
            Ok: function() {
                $.getJSON("/html/scripts/loginPersonal.php", {
                    login2: $("#login2").val(),
                    passw2: $("#passw2").val(),
                    time: new Date().getTime()
                    },
                function(obj){
                    if(obj.logged==1){
                        $.cookie("audit", null, {
                            path: "/html"
                        });
                        $.cookie("audit", obj.audit, {
                            path: "/html"
                        });
                        $("#personalEnter").dialog('close');
                        window.location.replace("/html/azs.html");
                    }
                    else {
                        $("#personalEnter").dialog('close');
                        $("#loginError2").dialog('open');
                    }
                });
            }
        }
    });
    /////////////////////////////////////////////////////////////
    $("#legalEnter").css('visibility', 'visible');
    $("#legalEnter").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        buttons: {
            Ok: function() {
                $.getJSON("/html/scripts/loginClient.php", {
                    login: $("#login").val(),
                    passw: $("#passw").val(),
                    time: new Date().getTime()
                    },
                function(obj){
                    if(obj.cid!=0){
                        //alert(obj.cid);
                        $.cookie("cid", obj.cid, {
                            path: "/html"
                        });
                        $("#legalEnter").dialog('close');
                        window.location.replace("/html/legal");
                    }
                    else {
                        $("#legalEnter").dialog('close');
                        $("#loginError").dialog('open');
                    }
                });
            }
        }
    });
    /////////////////////////////////////////////////////////////
    $("#loginError").css('visibility', 'visible');
    $("#loginError").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
                $("#legalEnter").dialog('open');
            }
        }
    });
    /////////////////////////////////////////////////////////////
    $("#loginError2").css('visibility', 'visible');
    $("#loginError2").dialog({
        autoOpen: false,
        bgiframe: true,
        modal: true,
        buttons: {
            Ok: function() {
                $(this).dialog('close');
                $("#personalEnter").dialog('open');
            }
        }
    });
    /////////////////////////////////////////////////////////////
});

function enterLegal(){
    $("#legalEnter").dialog('option', 'title', 'Вход для юридических лиц');
    $("#legalEnter").dialog('open');
}

function enterPersonal(){
    $("#personalEnter").dialog('option', 'title', 'Вход для сотрудников');
    $("#personalEnter").dialog('open');
}

function logout(){
    $.cookie("cid", null, {
        path: "/html"
    });
    //window.location.replace("http://rally2014.ru/html/");
    document.location.href='/html/';
}



