// JavaScript Document
if ( typeof(window.auth) == 'undefined' ) {
    var auth = null;
}
var $loginbox = null;


function check_auth(){

    if ( typeof(auth) != 'object' || auth == null ){
        return false;
    }
    
    var pola = [ 'id', 'imie', 'nazwisko', 'firma', 'email', 'telefon' ]
    for ( a = 0; a < pola.length; a++ ) {
        if ( typeof(auth[pola[a]]) == 'undefined' ) {
            return false;
        }
    }
    
    return true;
}

$(function(){
    //dla
    $('a.auth').click( function( event ){
        
        if ( !check_auth() ) { //wyswietlam box do logowania
            event.preventDefault();
            
            if( $loginbox ){
                $loginbox.dialog('open');
            }else{
                $loginbox = $('<div id="loginbox"><div class="loading">&nbsp;</div></div>');
                $('body').append( $loginbox );

                $loginbox.dialog({
                    'disabled': true,
                    'autoOpen': true,
                    'draggable': true,
                    'height': 200,
                    'width': 450,
                    //'hide': 'blind' ,
                    //'maxHeight': false,
                    //'maxWidth': false,
                    //'minHeight': false,
                    //'minWidth': false,
                    //position: 'center' or 'left' or 'right' or 'top' or [ 0, 0 ] or [ 'top', 'center' ],
                    'resizable': false,
                    //'show': 'slide',
                    //'stack' : false,
                    //'title': 'Logowanie',
                    //'zIndex' : 1000,
                    'modal': true
                });
                
                $loginbox.load( LANG_URL_PATH + '/login.html',  function(){
                    var title = $loginbox.find('div.page_cont_450').html();
                    $loginbox.find('div.page_cont_450').hide();
                    $loginbox.dialog('option', 'title', title);
                    $loginbox.dialog('option', 'disabled', false);

                    $loginbox.dialog('close');
                    $loginbox.dialog('option', 'hide', 'blind');
                    $loginbox.dialog('open');
                });
            }
            
            return false;
        }

//         if ( this.href ){
//             event.preventDefault();
//             window.location = this.href;
//             return false;
//         }
    });
});


