// prihlaseni
function ajaxLogin()
{
    login = $('#FRMlogin').val();
    pwd = $('#FRMpassword').val();
    ref = $('#referrer').val();

    $.post('/ajax/user/login/', {
        login:login,
        password:pwd,
        referrer:ref
    }, ajaxLoginCallback, 'json');
}

function ajaxLoginCallback(data)
{
    if (data.status == 'ALL_OK')
    {
        ref = $('#referrer').val();
        if (ref != '' || ref != 'undefined')
        {
            url = 'http://' + window.location.hostname + ref;
            window.location = url;
        } else {
            window.location.reload();
        }
    } else {
        $.jGrowl(data.msg, {
            "theme":"error"
        });

        if ( typeof(data.referrer)!='undefined' && (data.referrer != '') && (data.referrer != 'undefined')) {
            url = 'http://' + window.location.hostname + data.referrer;
            window.location = url;
        }

    }
}

function ajaxPasswordRemind()
{
    login = $('#FRMlogin2').val();
    email = $('#FRMemail').val();

    $.post('/ajax/user/password-remind/', {
        login:login,
        email:email
    }, ajaxPasswordRemindCallback, 'json');
}

function ajaxPasswordRemindCallback(data)
{
    if (data.status == 'ALL_OK')
    {
        $("#password_remind").hide();
        $.jGrowl(data.msg, {
            "theme":"info"
        });
    } else {
        $.jGrowl(data.msg, {
            "theme":"error"
        });
    }
}


// zobrazeni a skryti header_login
function header_display_login(l) {
    if ($("#password_remind").length > 0) {
        $("#password_remind").hide();
    }
    if ($("#header_login_control_box").length > 0) {
        $("#header_login_control_box").css('left', l);
        $("#header_login_control_box").toggle('fast');
        $('#FRMlogin').focus();
        return false;
    }
}

// zobrazeni a skryti password_remind
function header_display_password_remind(l) {
    if ($("#header_login_control_box").length > 0) {
        $("#header_login_control_box").hide();
    }
    if ($("#password_remind").length > 0) {
        $("#password_remind").css('left', l);
        $("#password_remind").toggle('fast');
        $('#FRMlogin2').focus();
        return false;
    }
}

function showUserProfil(userId){
    $.fancybox({
        'width'             : 800,
        'height'            : 600,
        'href'              : '/detske-hriste/profil/show-profil/userId/'+userId+'/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function setMood(){
    $.fancybox({
        'width'             : 400,
        'height'            : 300,
        'href'              : '/detske-hriste/profil/set-mood/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function newMoodSaved(){
    $.fancybox.close();
    window.location.reload();
}

function sendStatus(){
    var status = $('#mujStav').val() ;
    $.post('/detske-hriste/uzivatel/save-status/', {
        statusText:status
    }, statusSaved, 'json');
    $('#mujStav').val('') ;
    return false;
}

function statusSaved(data){
    $.jGrowl( 'Uloženo', {
        "theme":"info"
    } );
}

function moodSet(){
    $.fancybox.close();
    window.location.reload();
}

function fancyboxResize(){
    $.fancybox.resize();
}

function addNewFriend(x){
    $.fancybox({
        'width'             : 400,
        'height'            : 150,
        'href'              : '/detske-hriste/kamaradi/add-new-friend/friendId/'+x+'/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function friendAdded(){
    $.fancybox.close();
}

function fancyboxClose(){
    $.fancybox.close();
}

function userLicence(){
    $.fancybox({
        'width'             : 600,
        'height'            : 400,
        'href'              : '/user/licence/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function deleteFriend(x){
    $.fancybox({
        'width'             : 400,
        'height'            : 150,
        'href'              : '/detske-hriste/kamaradi/delete-friend/friendId/'+x+'/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function friendDeleted(){
    $.fancybox.close();
    window.location.reload();
}

function newMessage(userId){
    $.fancybox({
        'width'             : 400,
        'height'            : 350,
        'href'              : '/detske-hriste/zpravy/new/userId/'+userId,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function bonzUser(userId){
    $.fancybox({
        'width'             : 400,
        'height'            : 350,
        'href'              : '/detske-hriste/zpravy/bonz-user/userId/'+userId,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function setOnline(){
    $.post('/ajax/user/online/', {stamp:new Date().getTime()}, setOnlineCallback, 'json')
}

function setOnlineCallback(data){
    if (data.status == 'OK'){
        if(data.msg != ''){
            fancyboxInfoText(data.msg)
        };
        if(data.chat != 0){
            $('#onlineChatAlert').html('CHAT<br /><a href="#" onclick="return onlineChat(0)"><span><img src="/_clip/icon_chat.png" style="cursor: pointer;" title="Chatovat" /></span></a>');
            $('#onlineChatAlert').pngFix();
        };
    }
}

function mujStavInit(){
    $('#mujStav').val('Moje nálada je ...');
    $('#mujStav').click(function() {
        if( $('#mujStav').val()=='Moje nálada je ...' ){
            $('#mujStav').val('');
        }
    });
    $('#mujStav').blur(function() {
        if( $('#mujStav').val()=='' ){
            $('#mujStav').val('Moje nálada je ...');
        }
    });
}

function messageSended(){
    $.fancybox.close();
    window.location.reload();
}

function fancyboxInfo(){
    $.fancybox({
        'width'             : 400,
        'height'            : 200,
        'href'              : '/user/fancybox-info/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function fancyboxInfoText(t){
    $.fancybox({
        'width'             : 400,
        'height'            : 200,
        'href'              : '/user/fancybox-info/?t='+t,
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

function buyFinished(){
    $.fancybox.close();
    window.location.reload();
}

function onlineChat(userId){
    $('#onlineChatAlert').html('');
    $.fancybox({
        'width'             : 800,
        'height'            : 500,
        'href'              : '/detske-hriste/online-chat/chat/userId/'+userId+'/',
        'transitionIn'	: 'elastic',
        'transitionOut'	: 'elastic',
        'type'              : 'iframe'
    });
    $('#fancybox-wrap').pngFix();
    return false;
}

