﻿// wszystko co ma byc w document ready!!
var currMessage = null;
var idLastMessage = null;
var bColorRow = false;


$('document').ready(function() {
    /*poczatek document ready*/
    setTimeout(function() {
        $('#social-facebook').show();
    }, 3000);
        
        
    $('#najlepsze-tydzien').attr('href', '#');
    $('#najlepsze-tydzien').click(function() {
        najlepszeArtykulyTydzien();
        return false;
    });

    $('#najlepsze-z-miesiaca').attr('href', '#');
    $('#najlepsze-z-miesiaca').click(function() {
        najlepszeArtykulyMiesiac();
        return false;
    });

    $('#social-facebook').hover(function() {
        $('#social-facebook').stop(true, false).animate({
            left: '0'
        }, "medium", function() {
            // Animation complete.
            });
    }, function() {
        $('#social-facebook').stop(true, false).animate({
            left: '-200'
        }, "medium", function() {
            // Animation complete.
            });
    });
		
    $('#subCat').click(function() {
        if($('#subCategories').css('display') == 'none')
            $('#subCategories').slideDown();
        else
            $('#subCategories').slideUp();
    });

    $('.lit').children('a').click(function() {
        var lit = $(this).parent();
        $('#subCatAjax').remove();
        $.get('/ajax.html', {
            action: 'getSubCategories', 
            lit: lit.attr('id')
            }, function(data) {
            lit.append(data);
        });
    });

    $('#search').click(function() {
        var text = $('#searchKeyword').val();

        if((text.length) < 3) {
            $('#search').attr('disable', 'disabled');
            return false;
        }
    });
		
    //if($("#textMessage").val() == '') {
    //$('#sendMessage').attr('disabled', true);
    //}

    $("#sendMessage").click(function() {
        addMessage();
    });

    /*
    $("#textMessage").keyup(function() {
        if($("#textMessage").val() !== '')
            $('#sendMessage').removeAttr('disabled');
        else
            $('#sendMessage').attr('disabled', 'disabled');
    });
    */

    if($('#messages').children().size()==0) {
        $('#ajax_loader').show();
        update(1);
    }
    
    
    setInterval("update();", 10000);

    $('#email').change(function() {
        if($('#email').attr('checked')) {
            $.post('ajax.html', {
                action: 'cron_email', 
                status: 1
            }, function(result) {
                $('#email').parent().html(result);
            });
        }
        else {
            $.post('ajax.html', {
                action: 'cron_email', 
                status: 0
            }, function(result) {
                $('#email').parent().html(result);
            });
        }
    });
    
    $('#feed').change(function() {
        if($('#feed').attr('checked')) {
            $.post('ajax.html', {
                action: 'cron_feed', 
                status: 1
            }, function(result) {
                $('#feed').parent().html(result);
            });
        }
        else {
            $.post('ajax.html', {
                action: 'cron_feed', 
                status: 0
            }, function(result) {
                $('#feed').parent().html(result);
            });
        }
    });


    //
    $('.delete_friend').click(function(){
        var id_friend = $(this).data('id_friend');
        var friend_name = $(this).data('friend_name');
        window.location= base_url + "znajomi,usun," + id_friend + "," + friend_name + ".html";
        return false;
    });
    $('.close_box2').click(function(){
        $('#confirm2').hide();
        return false;
    });
    $('.show_box2').click(function(){
        var friend_name = $(this).data('friend_name');
        $('#confirm2 .box .center .loader p b').text(friend_name);
        $('#confirm2').show();
        return false;
    });
     
    $('.delete_checked_messages').click(function(){
        if ($(this).data('confirm') == 'confirm'){
            $('#confirm3').show();
        } else {
            $('.submit_confirm3').click();
        }
         
        return false;
    });
    $('.close_box3').click(function(){
        $('#confirm3').hide();
        return false;
    });
    $('.submit_confirm3').click(function(){
        $('#confirm3').hide();
        $("#sendForm").click();
    });
    $('.delete_poem_confirm').click(function(){
        var idpost = $(this).data('idpost');
        var iduser = $(this).data('iduser');
        $('#confirm-del-art').show();
        $('#confirm_art').data('idpost', idpost);
        $('#confirm_art').data('iduser', iduser);
        $('#confirm_art').attr('data-idpost', idpost);
        $('#confirm_art').attr('data-iduser', iduser);
        return false;
    });
     
    $('.delete_poem_submit').click(function(){
        var idpost = $(this).data('idpost');
        var iduser = $(this).data('iduser');

        $('#confirm-del-art').hide();
        $('#default_profil_' + idpost).hide();
        //return false;
        //$('#profil_ajax_loader').show();
        if(idpost !== '') {
            $.get('/ajax.html', {
                action: 'deleteArt', 
                iIdPost: idpost
            }, function(status) {
                if(status == 'ok') {
                    //updateProfil($(this));
                    $('#alert').fadeIn(1000);
                    $('#default_profil_' + idpost).remove();
                }
            });
        
        }
         
        return false;
    });
    $('.close_del_art').click(function(){
        $('#confirm-del-art').hide();
        return false;
    });
    $('.poem_tabs').click(function(){
         
         
        var obj = $(this);
         
        var url = $(this).attr('href');
        var action = $(this).data('action');
        var tm = new Date();
        url = url +'?' + tm.getTime();
         
        $("#header1").attr('class', 'header1');
        var parent = $(this).parent('div').attr('id');
        if (parent == 'header2') {
            $("#" + parent).attr('class', parent + '-selected');
            $("#header3").attr('class', 'header3');
            $("#header4").attr('class', 'header4');
        } else if(parent == 'header3') {
            $("#" + parent).attr('class', parent + '-selected');
            $("#header2").attr('class', 'header2');
            $("#header4").attr('class', 'header4');
        }

        var category_id = obj.data('category_id');
         
        if (category_id != 'undefined') {
            var data = '&action='+action+'&category_id='+category_id;
        } else {
            var data = '&action='+action;
        }
         
        $.ajax({
            url: url,
            type: 'post',
            data: data,
            success: function(html){
                $('div#document').html(html);
            }
        });
        return false;
    });
     
     
    $("#fileInput").uploadify({
        "uploader"  : "/js/jquery.uploadify/uploadify.swf",
        "script"    : "/js/jquery.uploadify/uploadify.php",
        "cancelImg" : "/js/jquery.uploadify/cancel.png",
        "margin-left": "100px",
        "auto"      : true,
        "folder"    : "/dane/Awatary",
        'fileDesc': 'JPG (*.jpg), GIF (*.gif), PNG (*.png)',
        'fileExt': '*.jpg;*.gif;*.png;',
        'buttonImg' : '/js/jquery.uploadify/change_avatar.png',
        'wmode': 'transparent',

        onComplete: function(a, b, c, d, e) {
            if (d == 'false') {
            } else {
                $("#changeAvatar").html("<img src='/images/ajax-loader.gif' />");
                $(".box_count .left").html("<img src='/images/ajax-loader.gif' />");

                $.getJSON('/ajax.html',{
                    action: 'avatar', 
                    file:d
                }, function(data) {
                    //$("#info-avatar").empty();
                    //$("#info-avatar").append('<div>');
                    //$("#info-avatar").children('div').addClass('top');
                    //$("#info-avatar").children('div').html("<p>"+data.error+"</p>");

                    $(".box_count .left").html("<img src='/dane/Awatary/"+d+"' />");
                    $("#changeAvatar").html("<img src='/dane/Awatary/"+d+"' />");

                    $('#changeAvatar').prepend('<p style="color: orange">'+data['error']+'</p>');

                    return false;
                });
            }
        }
    });
     

    $('#submit_report').click(function(){
        var data = $('#form_report').serialize();
        var url = $('#form_report').attr('action');
        //alert(data);
        $.ajax({
            type: 'post',
            url: url,
            data: data,
            success: function(msg){
                if(msg == 'success') {
                    $('#form_report')[0].reset();
                    $('#report-box-info').find('p').html('<p style="color: green">Twój zgłoszenie zostało wysłane.</p>');
                } else if (msg == 'error') {
                    $('#report-box-info').find('p').html('<p style="color: red">Wystąpił błąd.</p>');
                } else if (msg == 'error-capcha') {
                    $('#report-box-info').find('p').html('<p style="color: red">Wpisz poprawny kod z obrazka.</p>');
                }
                $('#recaptcha_reload').click();
                $('#report-box-info').show();
                
                setTimeout(function(){
                    $('#report-box-info').hide();
                }, 10000);

                
            }
            
        });
        return false;        
    });
/*koniec document ready*/
});
    

	
function closePrompt() {
    $('#confirm').hide();
}

function showBox() {
    $('#confirm').show();
}

function deleteCount() {
    window.location="http://<?=$_SERVER['SERVER_NAME']?>/ustawienia,del-count.html";
}
	
function closeBox2() {
    $('#confirm2').hide();
}

function showBox2(obj, name) {
    var url = $(obj).attr('href');

    $('#dell_user').val(url);
    $('#confirm2 .box .center #loader p b').text(name);
    $('#confirm2').show();
}

function deleteFriend() {
    var url = $('#dell_user').val();
    if(url != "")
        window.location=url;
}
	
function closeBox() {
    $('#confirm3').fadeOut();
}

function sendFormular() {
    $("#sendForm").click();
}
	
/* js/arts.js */
$('document').ready(function() {
    $('#art-of-day-feed').live('click', function() {
        if($('#art-of-day-feed').attr('checked') == true) {
            $('#status-art-of-day').html('<img style="margin-left: 30px" src="/images/ajax-loader2.gif" />');
            $.post('/ajax.html', {
                action: 'art-of-day-feed'
            }, function(result) {
                if(result == '1') {
                    $('#status-art-of-day').html('<p style="font-size: 11px; text-align: center; color: green; font-weight: bold;">Dodano wpis na tablicy.</p>');
                }
                else {
                    $('#status-art-of-day').html(result);
                }
            });
        }
    });
});

function showArtOfDay() {
    if($('#art_of_day_button-min').children().eq(0).attr('id') != 'show-art-of-day')
        $('#art_of_day_button-min').append("<div id='show-art-of-day'><div class='close'><a href='' onclick='$(this).parent().parent().remove(); return false'>X</a></div><p>Ten utwór jest utworem dnia.</p><span id='status-art-of-day'><input id='art-of-day-feed' type='checkbox' />Podziel sie nim ze znajomimy dodając wpis na tablicy!</span></p></div>");
}

function deleteArt(idPost, iUser, obj) {
    //$('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $('#profil_ajax_loader').show();
    if(idPost !== '') {
        $.get('/ajax.html', {
            action: 'deleteArt', 
            iIdPost: idPost
        }, function(status) {
            if(status == 'ok') {
                updateProfil(obj);
            }
        });
    }
}

function updateProfil(obj) {
    $('#alert').fadeIn(1000);
    var target = $(obj).parent().parent().parent();
    target.next('div').remove();
    target.remove();
    $('#profil_ajax_loader').hide();

    setInterval(function() {
        if($('#alert').attr('display') !== 'none') {
            $('#alert').fadeOut(1000);
        }
    }, 3000);

return true;
}

// iIdUser - numer uzytkownika - wlasciciela profilu
// iPage - numer strony
// iLimit - liczba wynikow wyswietlanych na stronie
// iCount - liczba wszystkich zwroconych wynikow ktore nalezy wyswietlic


function najnowszeArtykuly() {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.getJSON('/ajax.html', {
        action: 'najnowszeArtykuly'
    }, function(positions) {
        if(positions == null)
            showError();
        else
            updateDocument(positions);
       
        $("#header1").attr('class', 'header1-selected');
        $("#header2").attr('class', 'header2');
        $("#header3").attr('class', 'header3');
    });
}

function najnowszeArtykulyKategoria(iCategory) {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.getJSON('/ajax.html', {
        action: 'najnowszeArtykulyKategoria', 
        category: iCategory
    }, function(positions) {
        if(positions == null)
            showError();
        else
            updateDocument(positions);

        $("#header1").attr('class', 'header1-selected');
        $("#header2").attr('class', 'header2');
        $("#header3").attr('class', 'header3');
    });
}

function najlepszeArtykulyMiesiac() {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.post('/najlepsze-z-miesiaca.html', {
        action: 'najlepszeArtykulyMiesiac'
    }, function(positions) {
        if(positions == null)
            showError();
        else {
            //updateDocument(positions);
            $('#document').html(positions);
        }

        $("#header1").attr('class', 'header1');
        $("#header2").attr('class', 'header2');
        $("#header3").attr('class', 'header3-selected');
    });
}

function najlepszeArtykulyMiesiacKategoria(iCategory) {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.getJSON('/ajax.html', {
        action: 'najlepszeArtykulyMiesiacKategoria', 
        category: iCategory
    }, function(positions) {
        if(positions == null)
            showError();
        else
            updateDocument(positions);

        $("#header1").attr('class', 'header1');
        $("#header2").attr('class', 'header2');
        $("#header3").attr('class', 'header3-selected');
    });
}

function najlepszeArtykulyTydzien() {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.post('/najlepsze-z-tygodnia.html', {
        action: 'najlepszeArtykulyTydzien'
    }, function(positions) {

        if(positions == null) {
            showError();
        }
        else {
            //updateDocument(positions);
            $('#document').html(positions);
        }

        $("#header1").attr('class', 'header1');
        $("#header2").attr('class', 'header2-selected');
        $("#header3").attr('class', 'header3');
        return true
    });
}

function najlepszeArtykulyTydzienKategoria(iCategory) {
    $('#document').html("<img class='ajax-loader' src='images/ajax-loader.gif' />");
    $.getJSON('/ajax.html', {
        action: 'najlepszeArtykulyTydzienKategoria',
        category: iCategory
    }, function(positions) {
        if(positions == null) {
            showError();
        }
        else
            updateDocument(positions);

        $("#header1").attr('class', 'header1');
        $("#header2").attr('class', 'header2-selected');
        $("#header3").attr('class', 'header3');
    });
}

function showError() {
    $('#document').empty();
    $('#document').append('<div>');
                          
    oDiv = $('#document').children('div').eq(0);
    oDiv.attr('id', 'showMessage');
    oDiv.css('padding', '20px 0px 0px 70px');

    oDiv.append('<div>');
    oMsg = oDiv.children('div').eq(0);
    oMsg.attr('id', 'msgInfo2');
    oMsg.append('<div>');
    oMsg.append('<div>');
    oMsg.append('<div>');

    oMsg.children('div').eq(0).addClass('msg_up');
    oMsg.children('div').eq(1).addClass('msg_center');
    oMsg.children('div').eq(2).addClass('msg_down');

    oCenter = oMsg.children('div').eq(1);
    oCenter.append('<div>');
    oCenter.append('<div>');

    oLeft = oCenter.children('div').eq(0);
    oLeft.addClass('left');
    oLeft.append('<img>');
    oLeft.children('img').attr('alt', 'znaczek info');
    oLeft.children('img').attr('src', '/images/znaczek.png');


    oRight = oCenter.children('div').eq(1);
    oRight.addClass('right');
    oRight.append('<p>');
    oRight.children('p').css('color', 'red');
    oRight.children('p').text('Brak artykłów w serwisie poezje.pl');

    $('#document').append('<div>');
    $('#document').children('div').eq(1).addClass('position-down');
}

function updateDocument(positions) {
    if(positions.length > 0) {
        $('#document').empty();
        for(i=0; i<positions.length; i++) {
            $('#document').append('<div>');
            var oPosition = $('#document').children('div').last();
            oPosition.addClass('position');
            oPosition.attr('id', positions[i].sMotyw+'-mini');
                
            oPosition.append('<div>');
            oPosition.append('<div>');

            var oBackground = oPosition.children('div').eq(1);
            oBackground.addClass('background');
            oBackground.append('<div>');
            oBackground.append('<div>');
            oBackground.append('<div>');

            var oPositionLeft = oPosition.children('div').eq(0);
            oPositionLeft.addClass('points_left');

            var oPoints = oBackground.children('div').eq(0);
            oPoints.addClass('add_point');
            oPoints.attr('id', positions[i].iId);
            oPoints.append('<p>');
            oPoints.append('<a class="glos_minus" href=""><img src="images/minus.png" /></a>');
            oPoints.append('<a class="glos_plus" href=""><img src="images/plus.png" /></a>');

            oPoints.children('p').text(positions[i].punkty);

            var oTitle = oBackground.children('div').eq(1);
            oTitle.addClass('title');

            oTitle.append('<p>');
            oTitle.append('<p>');

            oTitle.children('p').eq(0).append('<a href="/utwor,'+positions[i].iId+','+positions[i].sTytulUrl+'.html">'+positions[i].sTytul+'</a>');

                
            oTitle.children('p').eq(1).append('<span><i>Autor: <a href="/profil,'+positions[i].userId+','+positions[i].autor+'.html">'+positions[i].autor+'</a></i></span>');
            oTitle.children('p').eq(1).append('<span><i>Kategoria: <a href="/utwory,'+positions[i].kategoriaUrl+'.html">'+positions[i].kategoria+'</a></i></span>');
            oTitle.children('p').eq(1).append('<span><i>Komentarze: <a href="utwor,'+positions[i].iId+','+positions[i].sTytulUrl+'.html#comments">'+positions[i].iLiczbaKomentarzy+'</a></i></span>');
 
            //oTitle.children('p').eq(1).children('span').eq(2).children('i').text('Komentarzy:');
            //oTitle.children('p').eq(1).children('span').eq(2).children('a').text(positions[i].iLiczbaKomentarzy);
            //oTitle.children('p').eq(1).children('span').eq(2).children('a').attr('href', '/utwor,'+positions[i].iId+','+positions[i].sTytulUrl+'.html');

            var oDate = oBackground.children('div').eq(2);
            oDate.addClass('date');
            oDate.html('<span>'+positions[i].day+'</span>'+positions[i].date);

            $('#document').append('<div>');
            $('#document').children('div').last().attr('class', 'status');
            $('#document').children('div').last().attr('style', 'margin: -60px 0px 0px 60px; position: absolute; width: 81px; height: 35px; background: url("/images/chmura.png"); *margin: 0px 0px 0px 0px; display: none; padding: 8px 5px 5px 15px; font-size: 11px; color: #fff;');

            $('#document').append('<div>');
            $('#document').children('div').last().addClass('bar');
        }

        $('#document').append('<div>');
        $('#document').children('div').last().addClass('position-down');
    }
    return true;
}


function addMessage() {
    var textMessage = $("#textMessage").val();
    if( textMessage.length > 0) {
        $("#textMessage").val('');
        $.get('/chat.html', {
            action: 'addMessage', 
            text: textMessage
        }, function() {
            update(0);
            $("#textMessage").val('');
        });
    }
}

function update(start) {
    var message = null;
    var tmpIdLastMessage = null;
    
    var d = new Date();
    var tm = d.getTime();

    if(start == 1) {
        $('#messages').html('<div class="hello">rozpocznij rozmowę...</div>');
        $.ajax({
            url: '/chat.html',
            type: 'get',
            async: true,
            data: {
                action: 'getMessages', 
                bStart: start, 
                iIdLastMessage: idLastMessage, 
                tm: tm
            },
            success: function(html) {
                message = html;
                $('#ajax_loader').hide();
                if(message !== null) {
                    if (message != 'null') {
                        $('.hello').empty();
                        $("#messages").html(message);
                        idLastMessage = $('.message').eq(0).data('id_message');
                    }
                   
                } 
            }
        });
    } else {
        start = 0;
        $.ajax({
            url: '/chat.html',
            dataType: 'json',
            data: {
                action: 'getMessages', 
                bStart: start, 
                iIdLastMessage: idLastMessage, 
                tm: tm
            },
            async: true,
            success: function(messageJSON) {
                message = messageJSON;
                $('#ajax_loader').hide();
                if(message !== null) {
                    $('.hello').empty();
                    for(i=0; i<message.length; i++) {
                        $("#messages").prepend('<div>');
                        element = $("#messages").children('div').eq(0);

                        if (bColorRow) {
                            element.addClass('message-white');
                            bColorRow = false;
                        } else {
                            element.addClass('message');
                            bColorRow = true;
                        }

                        element.append('<div>');
                        autor = element.children('div').eq(0);
                        autor.addClass('autor');
                        if (message[i].login != undefined) {
                            autor.html("<a href='http://"+message[i].login+".poezje.pl'>"+message[i].login+"</a>");
                        } else {
                            autor.html("<a href='http://poezje.pl'>brak</a>");    
                        }

                        var data = new Date();
                        var year = data.getFullYear(message[i].data);
                        var month = data.getMonth();// + 1;
                        if(month<10) {
                            month = '0'+month;
                        }
                        var day = data.getDate()-1;
                        if(day<10) {
                            day = '0'+day;
                        }
                        var hours = data.getHours(); // cos tu kurwa jest nie tak bo mi sie zle data wyswietla :)
                        if(hours<10) {
                            hours = '0'+hours;
                        }
                        var min = data.getMinutes() + 1;
                        if(min<10) {
                            min = '0'+min;
                        }
                        var sec = data.getSeconds() + 1;
                        if(sec<10){
                            sec = '0'+sec;
                        }
                        data = hours+':'+min+':'+sec+' '+day+'.'+month+'.'+year;
                        data = new Date();
                        data.setTime( message[i].data*1000);
                        data = data.toLocaleString();

                        element.append('<div>');
                        date = element.children('div').eq(1);
                        date.addClass('date');
                        date.text(data);

                        element.append('<div>');
                        text = element.children('div').eq(2);
                        text.addClass('text');
                        text.html(message[i].text);
                        tmpIdLastMessage = message[i].id;
                    }
                    idLastMessage = tmpIdLastMessage;
                }
            }
        });
    }
}


function changeFont(size) {
    $('#document').find('.text').css("font-size", size);
}

function changeColor(color) {
    //$('#document').children().children('.text').css("color", color);
    $('#document').find('.text').css("color", color);
//showColorPicker();
}

function showColorPicker() {
    if($('#colorPicker').css('display') == 'none') {
        $('#colorPicker').show();
    } else {
        $('#colorPicker').hide();
    }
}

function artOfDay(obj, userId, postId) {
    $(obj).remove();
    $('#document .header .title h1').append('<img id="art-of-day-loader" src="/images/ajax-loader3.gif" />');
    $.post('/ajax.html', {
        action: 'art-of-day', 
        userId: userId, 
        postId: postId
    }, function(result) {
        $('#art-of-day-loader').remove();
        $('#document .header .title h1').append(result);
    });
}
	
/* js/comments.js  */
function showMessage(text) {
    $('.showMsg').empty();
    $('.showMsg').append('<div>');
    msgInfo2 = $('.showMsg').children('div');
    msgInfo2.attr('id', 'msgInfo2');
    msgInfo2.append('<div>');
    msgInfo2.append('<div>');
    msgInfo2.append('<div>');

    msgInfo2.children('div').eq(0).addClass('msg_up');
    msgInfo2.children('div').eq(1).addClass('msg_center');
    msgInfo2.children('div').eq(2).addClass('msg_down');

    center = msgInfo2.children('div').eq(1);

    center.append('<div>');
    center.append('<div>');

    center.children('div').eq(0).addClass('left');
    center.children('div').eq(1).addClass('right');

    center.children('div').eq(0).html('<img src="/images/znaczek.png" alt="znaczek info" />');
    center.children('div').eq(1).html(text);
    $('.showMsg').fadeIn();

    setTimeout(function() {
        $('.showMsg').fadeOut();
    }, 4000);
}

function editComment(obj, iId, sTime) {
    sText = $(obj).parent().parent().children('.text').text();
    $(obj).hide();
    $(obj).parent().parent().children('.text').html('<table class="comment-edit"><tr><td><textarea id="sNewText">'+sText+'</textarea></td></tr><tr><td><input type="button" onclick="saveComment(this, \''+iId+'\', \''+sTime+'\'); return false;" value="" style="background-image: url(\'/images/zapisz.jpg\'); background-repeat: no-repeat; width: 61px; height: 21px; border-width: 0px" /></td></tr></table>');

}

function saveComment(obj, iId, sTime) {
    var Today = new Date();
    var Month = Today.getMonth();
    var Day = Today.getDate();
    if(Day<=9)
        Day = '0'+Day;
    var Year = Today.getFullYear();
    var Hour = Today.getHours();
    if(Hour<=9)
        Hour = '0'+Hour;
    var Minutes = Today.getMinutes();
    if(Minutes<=9)
        Minutes = '0'+Minutes;
    var Seconds = Today.getSeconds();
    if(Seconds<=9)
        Seconds = '0'+Seconds;

    $(obj).parent().parent().parent().parent().parent('.text').parent('.text').children().eq(0).children().eq(1).show();
    $(obj).parent().parent().parent().parent().parent('.text').parent('.text').children().eq(1).html('('+sTime+')'+'<span class="commentUpdate">Ostatnia aktualizacja: '+Hour+':'+Minutes+':'+Seconds+' '+Day+'.'+Month+'.'+Year+'</span>');
    $(obj).parent().parent().parent().parent().parent('.text').parent('.text').children().eq(0).children().eq(1).css('display', 'inline');
    sText = $(obj).parent().parent().parent().children().eq(0).children().children().val();

    $.post('/ajax.html', {
        action: 'updateComment', 
        id: iId, 
        text: sText
    }, function(status) {
        if(status == 'ok') {
            $(obj).parent().parent().parent().parent().parent('.text').parent('.text').prepend('<p id="status-comment" style="color: green; text-align: center;">Komentarz został zapisany</p>');

            $(obj).parent().parent().parent().children().eq(0).children().html('<p class="text">'+sText+'</p>');
            $(obj).remove();

            setTimeout(function() {
                $('#status-comment').remove();
            }, 3000);
        }
    });
}

function addCommentForArt(user_id, post_id, user_name, avatar) {
    text = $('#sCommentText').val();
    userId = user_id;
    postId = post_id;
    userName = user_name;
    if(userId == '') {
        showMessage('<p style="color: red">Musisz się zalogwać aby dodać komentarz</p>');
        return false;
    }
    $.post('/ajax.html', {
        action: 'addCommentForArt', 
        sText: text, 
        iIdUser: userId, 
        sUser: userName, 
        iIdPost: postId
    }, function(status) {
        if(status!='Nie wpisałeś treści komentarza!') {
            //getCommentsForArt(post_id);
            showMessage('<p style="color: green">Twój komentarz został dodany.</p>');

            last_div = $('#comments').children().eq(0);
    
            if(last_div.attr('class') == 'comment-white') {
                sClass = 'comment';
            }
            else {
                sClass = 'comment-white'
            }

            var currentTime = new Date()
            var month = currentTime.getMonth() + 1
            var day = currentTime.getDate()
            var year = currentTime.getFullYear()
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()
            var seconds = currentTime.getSeconds()

            var sDate = hours+':'+minutes+':'+seconds+', '+day+'.'+month+'.'+year+' ';

            if(avatar == '')
                avatar = 'domyslny.png';
           
           
            $('#comments').append('<div class="'+sClass+'"><div class="left"><a href="/profil,'+user_id+','+user_name+'.html"><img style="width: 44px; height: 44px;" src="'+avatar+'" /></a></div><div class="text"><p class="name"><span>'+user_name+'</span><a class="editComment" href="" onclick="editComment(this, \''+status+'\', \''+sDate+'\');return false;"><img src="/images/edytuj_.png" /></a></p><p class="comment_date">('+sDate+')</p><p class="text">'+text+'</p></div><div class="pen"></div></div>');
            $('#commentsError').hide();
            $('#sCommentText').val('');
            if($('.comment-header').css('display')=='none')
                $('.comment-header').show();

            if($('#comments').css('display')=='none')
                $('#comments').show();
        //$('.showForm').hide();
        }
        else {
            showMessage('<p style="color: red">'+status+'</p>');
        }
        return false;
    });
}

function addCommentForUser(user_id, post_id, user_name, autor_id, avatar) {
    text = $('#sCommentText').val();
    $.post('/ajax.html', {
        action: 'addCommentForUser', 
        sText: text, 
        iIdAutor: user_id, 
        sUser: user_name, 
        iIdPost: post_id, 
        iIdUser: autor_id
    }, function(status) {
        if(status!='Nie wpisałeś treści komentarza!') {
            //getCommentsForUser(post_id);
            $('#commentError').children('#msgInfo2').children('.msg_center').children('.right').html('<p style="color: green;">Twój komentarz został dodany.</p>');
            $('#commentError').fadeIn(1000);

            last_div = $('#comments').children().eq(0);

            if(last_div.attr('class') == 'comment-white') {
                sClass = 'comment';
            }
            else {
                sClass = 'comment-white'
            }

            var currentTime = new Date()
            var month = currentTime.getMonth() + 1
            var day = currentTime.getDate()
            var year = currentTime.getFullYear()
            var hours = currentTime.getHours()
            var minutes = currentTime.getMinutes()
            var seconds = currentTime.getSeconds()

            var sDate = hours+':'+minutes+':'+seconds+', '+day+'.'+month+'.'+year;

            if(avatar == '')
                avatar = 'domyslny.png';

            $('#comments').append('<div class="'+sClass+'"><div class="left"><a href="/profil,'+user_id+','+user_name+'.html"><img style="width: 44px; height: 44px;" src="'+avatar+'" /></a></div><div class="text"><p class="name"><span>'+user_name+'</span><a class="editComment" href="" onclick="editComment(this, \''+status+'\', \''+sDate+'\');return false;"><img src="/images/edytuj_.png" /></a></p><p class="comment_date">('+sDate+')</p><p class="text">'+text+'</p></div><div class="pen"></div></div>');
            $('#sCommentText').val("");
            $('#commentsError').hide();

            if($('#comment-header').css('display')=='none')
                $('#comment-header').show();

            if($('#comments').css('display')=='none')
                $('#comments').show();

            setInterval(function() {
                if($('#commentError').attr('display') !== 'none') {
                    $('#commentError').fadeOut(1000);
                }
            }, 3000);
    }
    else {
        $('#commentError').children('#msgInfo2').children('.msg_center').children('.right').html('<p style="color: green;">'+status+'</p>');

        $('#commentError').fadeIn(1000);
        $('#sCommentText').val("");

        setInterval(function() {
            if($('#commentError').attr('display') !== 'none') {
                $('#commentError').fadeOut(1000);
            }
        }, 3000);
    }
});
}

function show_plus() {
    $('#menu-art .plus').css('background-image', 'url("/images/plus_act.png")');
    $('#menu-art .plus a').css('font-weight', 'bold');
    $('#menu-art .plus a').css('color', '#6e633d');

    $('#menu-art .minus').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .minus a').css('font-weight', 'normal');
    $('#menu-art .minus a').css('color', '#fff');
        
    $('#menu-art .report').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .report a').css('font-weight', 'normal');
    $('#menu-art .report a').css('color', '#fff');

    $('#menu-art .comments').css('background-image', 'url("/images/komentarze_unact.png")');
    $('#menu-art .comments a').css('font-weight', 'normal');
    $('#menu-art .comments a').css('color', '#fff');

    $('.comments-box').hide();
    $('.minus-box').hide();
    $('.plus-box').hide();
    $('.report-box').hide();
    $('.plus-box').show();
}

function show_comments() {
    $('#menu-art .comments').css('background-image', 'url("/images/komentarze_act.png")');
    $('#menu-art .comments a').css('font-weight', 'bold');
    $('#menu-art .comments a').css('color', '#6e633d');
        
    $('#menu-art .report').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .report a').css('font-weight', 'normal');
    $('#menu-art .report a').css('color', '#fff');

    $('#menu-art .minus').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .minus a').css('font-weight', 'normal');
    $('#menu-art .minus a').css('color', '#fff');

    $('#menu-art .plus').css('background-image', 'url("/images/plus_unact.png")');
    $('#menu-art .plus a').css('font-weight', 'normal');
    $('#menu-art .plus a').css('color', '#fff');

    $('.comments-box').hide();
    $('.minus-box').hide();
    $('.plus-box').hide();
    $('.report-box').hide();
    $('.comments-box').show();
}

function show_minus() {
    $('#menu-art .minus').css('background-image', 'url("/images/minus_act.png")');
    $('#menu-art .minus a').css('font-weight', 'bold');
    $('#menu-art .minus a').css('color', '#6e633d');
        
    $('#menu-art .report').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .report a').css('font-weight', 'normal');
    $('#menu-art .report a').css('color', '#fff');

    $('#menu-art .comments').css('background-image', 'url("/images/komentarze_unact.png")');
    $('#menu-art .comments a').css('font-weight', 'normal');
    $('#menu-art .comments a').css('color', '#fff');

    $('#menu-art .plus').css('background-image', 'url("/images/plus_unact.png")');
    $('#menu-art .plus a').css('font-weight', 'normal');
    $('#menu-art .plus a').css('color', '#fff');

    $('.comments-box').hide();
    $('.minus-box').hide();
    $('.plus-box').hide();
    $('.report-box').hide();
    $('.minus-box').show();
}
    
function show_report(){
    $('#menu-art .report').css('background-image', 'url("/images/minus_act.png")');
    $('#menu-art .report a').css('font-weight', 'bold');
    $('#menu-art .report a').css('color', '#6e633d');
        
        
        
    $('#menu-art .minus').css('background-image', 'url("/images/minus_unact.png")');
    $('#menu-art .minus a').css('font-weight', 'normal');
    $('#menu-art .minus a').css('color', '#fff');

    $('#menu-art .comments').css('background-image', 'url("/images/komentarze_unact.png")');
    $('#menu-art .comments a').css('font-weight', 'normal');
    $('#menu-art .comments a').css('color', '#fff');

    $('#menu-art .plus').css('background-image', 'url("/images/plus_unact.png")');
    $('#menu-art .plus a').css('font-weight', 'normal');
    $('#menu-art .plus a').css('color', '#fff');
        
    $('.comments-box').hide();
    $('.minus-box').hide();
    $('.plus-box').hide();
    $('.report-box').hide();
    $('.report-box').show();
    //set_default_tab('.report');
    //unset_default_tab('.minus');
    //unset_default_tab('.comments');
    //unset_default_tab('.plus');
        
    return false;
}
    
function unset_default_tab(cl){
    $('#menu-art '+cl).css('background-image', 'url("/images/komentarze_unact.png")');
    $('#menu-art '+cl+' a').css('font-weight', 'normal');
    $('#menu-art '+cl+' a').css('color', '#ffffff');
    $(cl + '-box').hide();
}
function set_default_tab(cl){
    $('#menu-art '+cl).css('background-image', 'url("/images/minus_act.png")');
    $('#menu-art '+cl+' a').css('font-weight', 'bold');
    $('#menu-art '+cl+' a').css('color', '#6e633d');
    $(cl + '-box').show();
}

function updateInterests() {
    $('doucment').ready(function() {
        sText = $('#sZainteresowania').val();
        $.getJSON('/ajax.html', {
            action: 'updateInterests', 
            text: sText
        }, function() {
            $('#countMsg #msgInfo2 .msg_center .right p').text('Twoje dane zostały zmienione.');
            $('#countMsg').fadeIn();

            setTimeout(function() {
                $('#countMsg').fadeOut();
            }, 2000);
            updateSidebarLeftInterests(sText);
        });
    });
}

function updateAbout() {
    $('doucment').ready(function() {
        sText = $('#sAbout').val();
        $.getJSON('/ajax.html', {
            action: 'updateAbout', 
            text: sText
        }, function() {
            $('#countMsg #msgInfo2 .msg_center .right p').text('Twoje dane zostały zmienione.');
            $('#countMsg').show();

            setTimeout(function() {
                $('#countMsg').fadeOut();
            }, 2000);
            updateSidebarLeftAbout(sText);
        });
    });
}

function updateSidebarLeftInterests(text) {
    $('doucment').ready(function() {
        $('#sidebarLeftInterests p').html(text);

    });
}

function updateSidebarLeftAbout(text) {
    $('doucment').ready(function() {
        $('#sidebarLeftHobby p').html(text);

    });
}

function changeProfileStyle(motyw, idUser) {
    $.post('/ajax.html', {
        action: 'changeProfileStyle', 
        sMotyw: motyw, 
        iIdUser: idUser
    }, function(status) {
        if(status == 'ok') {
            updateProfile();
        }
    });
}

function updateProfile() {
    $('#msgShow #msgInfo2').show();
    $('#msgShow').fadeIn();
    $('#styles .styles').hide();

    setTimeout(function(){
        document.location.href='/moj-profil.html';
    }, 1000);
}

/* js/avatar.js */


function runUploadify() {
    $('fileInputUploader').fileUpload(function() {
        //alert('poszlo');
        });
}

function showPrompt() {
    $('#confirm3').fadeIn();
    return this.status;
}

function deleteMsg(obj, val) {
    var iId = $(obj).attr('data-id');
    div = $(obj).parent('td').parent('tr').fadeOut();

    $.post('/ajax.html', {
        action: 'deleteMsg', 
        id: iId, 
        trash: val
    }, function(status) {
        if(status == 'ok') {
            $('#msgStatus-poczta').html('<p>wiadomość została usunięta</p>');
            $('#msgStatus-poczta').fadeIn();

            setTimeout(function() {
                $('#msgStatus-poczta').fadeOut('slow');
            }, 3000);
        }
    })
}

function selectAll() {
    $('.inp').attr('checked', true)
}

function unselectAll() {
    $('.inp').attr('checked', false)
}

function refreshStyle(motyw) {
    $(".changeStyle").attr('id', motyw);
    $('#showError #msgInfo2 .msg_center .right p:last').text('Motyw został zapisany!');

    $('#showError #msgInfo2').fadeIn('2000');
    setTimeout(function() {
        $('#showError #msgInfo2').fadeOut('2000');
    }, 2000);

}

function changeStyle(motyw, postId) {    
    $(".showAjaxLoader").show();
    $.post('/ajax.html', {
        action: 'changeStyle',
        sMotyw: motyw, 
        iPostId: postId
    }, function(status) {
        if(status == 'ok') {
            refreshStyle(motyw);
        }
        $(".showAjaxLoader").hide();
    })
}

	
