
function openRestaurantRating( contentObjectId )
{
    var win = new Window({className: "mac_os_x", width:660, height: 300, destroyOnClose: true, recenterAuto: false, title: "Restaurantbewertung", draggable: false, resizable: false});
    win.setAjaxContent( "/gourmetreise/ajax/restaurant_rating_html?objectId=" + contentObjectId );
    win.showCenter(true);
}

function submitRestaurantRating()
{
    if ( !checkRestaurantRatingRequiredFields() )
    {
        alert( 'Bitte füllen Sie alle Felder aus um Ihre Bewertung abzugeben.' );
        return;
    }

    $('restaurantRatingForm').request({
        onSuccess: function( transport )
        {
            if ( transport.responseText == calcRestaurantRating() )
                window.location.reload();
            else
                alert( 'Ihre Bewertung konnte nicht gespeichert werden, bitte versuchen Sie es etwas später wieder.' );
        }
    })
}

function calcRestaurantRating()
{
    var ratingSum = 0;
    var rating;

    rating = parseInt( $('foodRatingSelector').options[$('foodRatingSelector').selectedIndex].value );
    if ( rating != -1 ) ratingSum += rating;

    rating = parseInt( $('beverageRatingSelector').options[$('beverageRatingSelector').selectedIndex].value );
    if ( rating != -1 ) ratingSum += rating;

    rating = parseInt( $('serviceRatingSelector').options[$('serviceRatingSelector').selectedIndex].value );
    if ( rating != -1 ) ratingSum += rating;

    rating = parseInt( $('ambienceRatingSelector').options[$('ambienceRatingSelector').selectedIndex].value );
    if ( rating != -1 ) ratingSum += rating;

    rating = parseInt( $('costPerformanceRatingSelector').options[$('costPerformanceRatingSelector').selectedIndex].value );
    if ( rating != -1 ) ratingSum += rating;

    $('restaurantRatingResult').innerHTML = ratingSum;
    $('blueStarBarClassBlock').className = "star" + Math.round( ratingSum / 17 );

    checkRestaurantRatingRequiredFields();

    return ratingSum;
}

function checkRestaurantRatingRequiredFields()
{
    var rating;
    var val;
    var submitButtonActivated = true;

    rating = parseInt( $('foodRatingSelector').options[$('foodRatingSelector').selectedIndex].value );
    if ( rating == -1 ) submitButtonActivated = false;

    rating = parseInt( $('beverageRatingSelector').options[$('beverageRatingSelector').selectedIndex].value );
    if ( rating == -1 ) submitButtonActivated = false;

    rating = parseInt( $('serviceRatingSelector').options[$('serviceRatingSelector').selectedIndex].value );
    if ( rating == -1 ) submitButtonActivated = false;

    rating = parseInt( $('ambienceRatingSelector').options[$('ambienceRatingSelector').selectedIndex].value );
    if ( rating == -1 ) submitButtonActivated = false;

    rating = parseInt( $('costPerformanceRatingSelector').options[$('costPerformanceRatingSelector').selectedIndex].value );
    if ( rating == -1 ) submitButtonActivated = false;

    val = parseInt( $('visitedDaySelector').options[$('visitedDaySelector').selectedIndex].value );
    if ( val == 0 ) submitButtonActivated = false;

    val = parseInt( $('visitedMonthSelector').options[$('visitedMonthSelector').selectedIndex].value );
    if ( val == 0 ) submitButtonActivated = false;

    val = parseInt( $('visitedYearSelector').options[$('visitedYearSelector').selectedIndex].value );
    if ( val == 0 ) submitButtonActivated = false;

    $('ratingSubmitButton').disabled = !submitButtonActivated;

    return submitButtonActivated;
}


function loadRestaurantComments( contentObjectId, offset )
{
    var url = '/gourmetreise/ajax/restaurant_comments_html?objectId=' + contentObjectId + '&offset=' + offset;

    new Ajax.Request(url, {
        method: 'get',
        onSuccess: function( transport )
        {
            $('allRestaurantComments').innerHTML = transport.responseText;
        }
    });
}

function handleFrontpageLightbox( onlyOnce )
{
    if ( onlyOnce )
    {
        if ( jQuery.cookie('FrontpagePopupWasShown' ) == '1' ) return;

        jQuery.cookie('FrontpagePopupWasShown', '1', { expires: 365 });
    }

    jQuery("#frontpage-lightbox" ).dialog({
        modal: true,
        autoOpen: true,
        draggable: false,
        resizable: false,
        width: 975
    });
}

function closeFrontpageLightbox()
{
    jQuery("#frontpage-lightbox" ).dialog( "close" );
}

