var adult = {
    check: function() {
        if ($.cookie('sextime_adult') == null) adult.displayWarning();
    },
    
    displayWarning: function() {
        document.write('<div id="adult" style="z-index:100000;position:absolute;top:0;left:0;width:100%;height:100%;background:yellow;text-align:center">');
        document.write('<b>STRONA TYLKO DLA DOROSŁYCH</b><br />');
        document.write('<b>UWAGA! TA STRONA ZAWIERA TREŚCI EROTYCZNE!</b><br /><br />');
        document.write('Jeśli nie ukończyłes 18-go roku życia, nie chcesz oglądać tego typu treści lub jest to niezgodne<br />');
        document.write('z prawem twojego kraju, nie wolno Ci wchodzić dalej!<br /><br />');
        document.write('<input type="checkbox" id="isadult" /> Mam ukończone 18 lat. Nie pokazuj mi więcej tego ostrzeżenia.<br /><br />');
        document.write('>> <a href="javascript:void(0)" onclick="adult.confirm()">WEJDŹ NA STRONE</a> <<');
        document.write('</div>');
        $(document).ready(function(){$('#adult').css('height', $('body').height() + 'px')});
    },
    
    confirm: function() {        
        if ($('#isadult').attr('checked')) {
            $.cookie('sextime_adult', 1, { expires: 7, path: '/'});
            $('#adult').remove();
        } else {
            alert('Musisz zaznaczyć pole, jeśli jesteś pełnoletni');
        }
    }
}

var comments = {
    init: function() {
        $('#sidebar div.box').after('<div class="box"><form id="comments-form" action="komentuj.html" method="post" onsubmit="return comments.submit()"></form></div>');
        $('#comments-form').html('Nick: (max 15 znaków)<br /><input type="text" class="text" name="nick" /><br />Komentarz: (max 200 znaków)<br /><textarea name="comment"></textarea><br /><div class="center"><input type="submit" value="Dodaj komentarz" /></div>');
    },
    
    submit: function() {
        $('#comments-form input[type=submit]').attr('disabled', 'disabled');
    
        $.ajax({
            type: "POST",
            url: "komentuj.html",
            data: $('#comments-form').serialize(),
            dataType: "json",
            success: function(response){
                if (response.error_msg) {
                    alert(response.error_msg);
                } else {
                    $('#comments-form input.text,#comments-form textarea').val('');
                    alert(response.message);
                }
                
                $('#comments-form input[type=submit]').attr('disabled', '');
            },
            error: function(response){
                alert(response.responseText);
            }
        });
        
        return false;
    }
}

$(document).ready(function(){
    comments.init();
});
