/**
 * jQuery Library required
 */

$(document).ready(function(){
    createSendFriendPopup();
    $('a#sendFriend').click(function(){
        $('#sendFriendDialog').dialog('open');
    });

    $('#sendFriendButton').click(function() {

        $('#formFriendDialog').ajaxSubmit({
            dataType: 'json',
            success: function(responseText, statusText){
                if (responseText.error == true)
                {
                 /*   alert('Fehler: Bitte �berpr�fen sie ihre angaben.'); */
                	$('#sendFriendDialog > #message').html('<strong><i>Fehler: Bitte &uuml;berpr&uuml;fen Sie Ihre Angaben.</i></strong>');
                }
                else
                {
                 /*   alert('Wein wurde erfolgreich einem Freund empfohlen.'); */
                	$('#sendFriendDialog > #message').html('<strong><i>Nachricht wurde erfolgreich gesendet.</i></strong>');
                	$('#formFriendDialog').resetForm();
                	setTimeout("$('#sendFriendDialog > #message').html(''); $('#sendFriendDialog').dialog('close')",3000);
                }
            }
        });
    });

    $.blockUI.defaults.message = null;
    $.blockUI.defaults.overlayCSS.opacity = '0';
    $.blockUI.defaults.fadeOut = 1;

    $().ajaxStart($.blockUI).ajaxStop($.unblockUI);


});

function createSendFriendPopup() {
    $('#sendFriendDialog').dialog({
        autoOpen: false,
        bgiframe: true,
        width: 400,
        height: 400,
        resizable: false,
        open: function() {
            $(this).parent().parent().children().each(function() {
                if ($(this).hasClass('ui-resizable-handle')) {
                    $(this).css('display','block');
                }
            });
        }
    });
}

function getRandom(min, max) {
    if (min > max) { return (-1); }
    if (min == max) { return (min); }
    return (min + parseInt(Math.random() * (max-min+1)));
}