$(function () {
    $('#sysactions li.send a').click(function () {
        sendPageFriend();
        return false;
    });
});

function sendPageFriend() {
    if (!$('#sendPageFriend').length) {
        var stf = $('<div>')
            .attr('id','sendPageFriend')
            .attr('style','padding: 0px 7px')
            .hide();
        $('#panelContent').prepend(stf);
        stf.load(LANGROOT + '/send-page/friend/',function () {
            stf.fadeIn();
            $('#sendPageFriendForm').submit(function () {
                //zmena value buttonu
                var v1 = $('#sendPageFriendFormSubmit').val();
                var v2 = $('#sendPageFriendFormSubmit').attr('rel');
                $('#sendPageFriendFormSubmit').attr('disabled','disabled').val(v2).attr('rel',v1);
                $('#sendPageFriendFormUrl').val(window.location.href);
                $.post(this.action,$(this).serialize(),function (response) {
                    
                    //response ako JSON
                    eval('var r = '+response+';');
                    
                    //odstranenie reportov
                    $('div.report',stf).remove();
                    
                    if (r.status == 'OK') {
                        stf.prepend('<div class="report report_INFO"><span class="ico ico_INFO">&nbsp;</span>'+r.message+'</div>');
                        $('#sendPageFriendFormSubmit').val(v1).attr('rel',v2);
                        window.setTimeout(function () {
                            stf.fadeOut(function () {
                                $(this).remove();
                            });
                        },1500);
                    } else {
                        stf.prepend('<div class="report report_ERROR"><span class="ico ico_ERROR">&nbsp;</span>'+r.message+'</div>');
                        $('#sendPageFriendFormSubmit').removeAttr('disabled').val(v1).attr('rel',v2);
                    }
                });
                return false;
            });
        });
    } else {
        $('#sendPageFriend').fadeOut(function () {
            $(this).remove();
        });
    }
    // $.get(LANGROOT + '/send-to-friend/',function () {
    //     
    // });
}