﻿$('document').ready(function () {

    $('#iframe').scrollTo({ top: 162, left: 207 }, 1000);

    $('.formNews input').change(function () {
        $(this).css({ 'background-color': '#595959' });
    });

    $('.formRating input').change(function () {
        $(this).css({ 'background-color': '#595959' });
    });

    $('#submitButtonForNewsletter').click(function () {

        var name = $('input[name="news_lastname"]');
        var vorname = $('input[name="news_firstname"]');
        var email = $('input[name="news_email"]');
        var test = true;

        if (!notemptystring(name.val())) {
            name.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(vorname.val())) {
            vorname.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(email.val())) {
            email.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!isemail(email.val())) {
            email.css({ 'background-color': '#FF7979' });
            test = false;
        }


        if (test) { $('form[name=jaform]').submit(); }

    });



    $('.unsubnews input').change(function () {
        $(this).css({ 'background-color': '#595959' });
    });

    $('#submitButtonForUnsubNewsletter').click(function () {

        var email = $('input[name="unsubnews_email"]');
        var test = true;

        if (!notemptystring(email.val())) {
            email.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!isemail(email.val())) {
            email.css({ 'background-color': '#FF7979' });
            test = false;
        }


        if (test) { $('form[name=unsubnews]').submit(); }

    });


    $('.formTell input').change(function () {
        $(this).css({ 'background-color': '#595959' });
    });

    $('#submitButtonForTellaFriend').click(function () {

        var name1 = $('input[name="name1"]');
        var name2 = $('input[name="name2"]');
        var email1 = $('input[name="email1"]');
        var email2 = $('input[name="email2"]');
        var test = true;

        if (!notemptystring(name1.val())) {
            name1.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(name2.val())) {
            name2.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(email1.val())) {
            email1.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!isemail(email1.val())) {
            email1.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(email2.val())) {
            email2.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!isemail(email2.val())) {
            email2.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (test) { $('form[name=tellafriend]').submit(); }

    });

    $('#submitbuttonforrating').click(function () {

        var test = true;
        var frage1 = $('input[name="frage1"]');
        var frage2 = $('input[name="frage2"]');
        var frage3 = $('input[name="frage3"]');
        var frage4 = $('input[name="frage4"]');
        var frage5 = $('input[name="frage5"]');
        var frage6 = $('input[name="frage6"]');
        var frage7 = $('input[name="frage7"]');
        var frage8 = $('input[name="frage8"]');
        var frage9 = $('input[name="frage9"]');
        var frage10 = $('input[name="frage10"]');

        var name = $('input[name="rating_lastname"]');
        var vorname = $('input[name="rating_name"]');
        var mail = $('input[name="rating_email"]');

        if (!notemptystring(name.val())) {
            name.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (!notemptystring(vorname.val())) {
            vorname.css({ 'background-color': '#FF7979' });
            test = false;
        }

        if (notemptystring(mail.val())) {
            if (!isemail(mail.val())) {
                mail.css({ 'background-color': '#FF7979' });
                test = false;
            }
        }

        if (!notemptystring(frage1.val()) || !notemptystring(frage2.val()) || !notemptystring(frage3.val()) || !notemptystring(frage4.val()) || !notemptystring(frage5.val()) || !notemptystring(frage6.val())) {
            alert("Bitte geben Sie zu jeder Frage eine Bewertung ab!");
            test = false;
        }

        if (test) { $('form[name=ratingform]').submit(); }
    });

});

function rate(value, name, css, width) {
    var frage = $('input[name="' + name + '"]');

    left = width - 20;

    frage.val(value);
    //alert(frage.val());
    renewcss(name);
    //$('li.' + name).children().css({ 'width': '20px', 'background-image': 'url(/images/srating_leer.png)', 'z-index': '0', 'background-color': 'red' });
    $('.' + name + ' a.' + css + '').css({ 'width': '' + width + 'px', 'background-image': 'url(/images/srating_voll.png)' , 'left':'0px', 'z-index' : '-10'});
}

function renewcss(name) {
    for (i = 1; i < 11; i++) {
        $('.' + name + ' a.onestar').css({ 'width': '20px', 'background-image': 'none', 'left': '0px', 'z-index': '0' });
        $('.' + name + ' a.twostars').css({ 'width': '20px', 'background-image': 'none', 'left': '20px', 'z-index': '0' });
        $('.' + name + ' a.threestars').css({ 'width': '20px', 'background-image': 'none', 'left': '40px', 'z-index': '0' });
        $('.' + name + ' a.fourstars').css({ 'width': '20px', 'background-image': 'none', 'left': '60px', 'z-index': '0' });
        $('.' + name + ' a.fivestars').css({ 'width': '20px', 'background-image': 'none', 'left': '80px', 'z-index': '0' });
    }
}



