/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 170 2008-12-04 19:03:12Z emartin24 $
 *
 */

$(document).ready(function () {
        $('#contactForm input.contact, #contactForm a.contact').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/contact.php", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["10%",],
                                overlayId: 'contact-overlay',
                                containerId: 'contact-container',
                                onOpen: contact.open,
                                onShow: contact.show,
                                onClose: contact.close
                        });
                });
        });
        $('#angebot1Form input.angebot1, #angebot1Form a.angebot1').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=1", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot1-overlay',
                                containerId: 'angebot1-container',
                                onOpen: angebot1.open,
                                onShow: angebot1.show,
                                onClose: angebot1.close
                        });
                });
        });
        $('#angebot2Form input.angebot2, #angebot2Form a.angebot2').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=2", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot2-overlay',
                                containerId: 'angebot2-container',
                                onOpen: angebot2.open,
                                onShow: angebot2.show,
                                onClose: angebot2.close
                        });
                });
        });
        $('#angebot3Form input.angebot3, #angebot3Form a.angebot3').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=3", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot3-overlay',
                                containerId: 'angebot3-container',
                                onOpen: angebot3.open,
                                onShow: angebot3.show,
                                onClose: angebot3.close
                        });
                });
        });
        $('#angebot4Form input.angebot4, #angebot4Form a.angebot4').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=4", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot4-overlay',
                                containerId: 'angebot4-container',
                                onOpen: angebot4.open,
                                onShow: angebot4.show,
                                onClose: angebot4.close
                        });
                });
        });
        $('#angebot5Form input.angebot5, #angebot5Form a.angebot5').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=5", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot5-overlay',
                                containerId: 'angebot5-container',
                                onOpen: angebot5.open,
                                onShow: angebot5.show,
                                onClose: angebot5.close
                        });
                });
        });
        $('#angebot6Form input.angebot6, #angebot6Form a.angebot6').click(function (e) {
                e.preventDefault();
                // load the contact form using ajax
                $.get("data/angebot.php?id=6", function(data){
                        // create a modal dialog with the data
                        $(data).modal({
                                close: false,
                                position: ["7%",],
                                overlayId: 'angebot6-overlay',
                                containerId: 'angebot6-container',
                                onOpen: angebot6.open,
                                onShow: angebot6.show,
                                onClose: angebot6.close
                        });
                });
        });

        // preload images
        var img = ['cancel.png', 'loading.gif', 'send.png'];
        $(img).each(function () {
                var i = new Image();
                i.src = 'images/contact/' + this;
        });
});

var contact = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#contact-container .contact-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#contact-container .contact-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#contact-subject').length) {
                        h += 26;
                }
                if ($('#contact-cc').length) {
                        h += 22;
                }

                var title = $('#contact-container .contact-title').html();
                $('#contact-container .contact-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#contact-container .contact-content').animate({
                                                height: h
                                        }, function () {
                                                $('#contact-container .contact-title').html(title);
                                                $('#contact-container form').fadeIn(200, function () {
                                                        $('#contact-container #contact-name').focus();

                                                        $('#contact-container .contact-cc').click(function () {
                                                                var cc = $('#contact-container #contact-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#contact-container .contact-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#contact-container .contact-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (contact.validate()) {
                                $('#contact-container .contact-message').fadeOut(function () {
                                        $('#contact-container .contact-message').removeClass('contact-error').empty();
                                });
                                $('#contact-container .contact-title').html('Sende Anfrage...');
                                $('#contact-container form').fadeOut(200);
                                $('#contact-container .contact-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#contact-container .contact-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/contact.php',
                                                        data: $('#contact-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#contact-container .contact-loading').fadeOut(200, function () {
                                                                        $('#contact-container .contact-title').html('Vielen Dank!');
                                                                        $('#contact-container .contact-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: contact.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#contact-container .contact-message:visible').length > 0) {
                                        var msg = $('#contact-container .contact-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                contact.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#contact-container .contact-message').animate({
                                                height: '30px'
                                        }, contact.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#contact-container .contact-message').fadeOut();
                $('#contact-container .contact-title').html('Auf Wiedersehen...');
                $('#contact-container form').fadeOut(200);
                $('#contact-container .contact-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                contact.message = '';
                if (!$('#contact-container #contact-name').val()) {
                        contact.message += 'Bitte Ihren Namen angeben. ';
                }

                var email = $('#contact-container #contact-email').val();
                if (!email) {
                        contact.message += 'Bitte Ihre E-Mail angeben. ';
                }
                else {
                        if (!contact.validateEmail(email)) {
                                contact.message += 'Diese E-Mail ist ung&uuml;ltig. ';
                        }
                }

//                if (!$('#contact-container #contact-message').val()) {
//                        contact.message += 'Bitte eine Nachricht angeben.';
//                }

                if (contact.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        validateEmail: function (email) {
                var at = email.lastIndexOf("@");

                // Make sure the at (@) sybmol exists and
                // it is not the first or last character
                if (at < 1 || (at + 1) === email.length)
                        return false;

                // Make sure there aren't multiple periods together
                if (/(\.{2,})/.test(email))
                        return false;

                // Break up the local and domain portions
                var local = email.substring(0, at);
                var domain = email.substring(at + 1);

                // Check lengths
                if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
                        return false;

                // Make sure local and domain don't start with or end with a period
                if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
                        return false;

                // Check for quoted-string addresses
                // Since almost anything is allowed in a quoted-string address,
                // we're just going to let them go through
                if (!/^"(.+)"$/.test(local)) {
                        // It's a dot-string address...check for valid characters
                        if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
                                return false;
                }

                // Make sure domain contains only valid characters and at least one period
                if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
                        return false;

                return true;
        },
        showError: function () {
                $('#contact-container .contact-message')
                        .html($('<div class="contact-error">').append(contact.message))
                        .fadeIn(200);
        }
};
var angebot1 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot1-container .angebot1-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot1-container .angebot1-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot1-subject').length) {
                        h += 26;
                }
                if ($('#angebot1-cc').length) {
                        h += 22;
                }

                var title = $('#angebot1-container .angebot1-title').html();
                $('#angebot1-container .angebot1-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot1-container .angebot1-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot1-container .angebot1-title').html(title);
                                                $('#angebot1-container form').fadeIn(200, function () {
                                                        $('#angebot1-container #angebot1-name').focus();

                                                        $('#angebot1-container .angebot1-cc').click(function () {
                                                                var cc = $('#angebot1-container #angebot1-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot1-container .angebot1-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot1-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot1.validate()) {
                                $('#angebot1-container .angebot1-message').fadeOut(function () {
                                        $('#angebot1-container .angebot1-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot1-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot1-container form').fadeOut(200);
                                $('#angebot1-container .angebot1-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot1-container .angebot1-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot1-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot1-container .angebot1-loading').fadeOut(200, function () {
                                                                        $('#angebot1-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot1-container .angebot1-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot1.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot1-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot1-container .angebot1-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot1.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot1-container .angebot1-message').animate({
                                                height: '30px'
                                        }, angebot1.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot1-container .angebot1-message').fadeOut();
                $('#angebot1-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot1-container form').fadeOut(200);
                $('#angebot1-container .angebot1-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot1.message = '';
                if (!$('#angebot1-container #angebot-name').val()) {
                        angebot1.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot1-container #angebot-phone').val()) {
                        angebot1.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot1.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot1-container .angebot1-message')
                        .html($('<div class="angebot-error">').append(angebot1.message))
                        .fadeIn(200);
        }
};
var angebot2 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot2-container .angebot2-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot2-container .angebot2-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot2-subject').length) {
                        h += 26;
                }
                if ($('#angebot2-cc').length) {
                        h += 22;
                }

                var title = $('#angebot2-container .angebot2-title').html();
                $('#angebot2-container .angebot2-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot2-container .angebot2-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot2-container .angebot2-title').html(title);
                                                $('#angebot2-container form').fadeIn(200, function () {
                                                        $('#angebot2-container #angebot2-name').focus();

                                                        $('#angebot2-container .angebot2-cc').click(function () {
                                                                var cc = $('#angebot2-container #angebot2-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot2-container .angebot2-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot2-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot2.validate()) {
                                $('#angebot2-container .angebot2-message').fadeOut(function () {
                                        $('#angebot2-container .angebot2-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot2-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot2-container form').fadeOut(200);
                                $('#angebot2-container .angebot2-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot2-container .angebot2-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot2-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot2-container .angebot2-loading').fadeOut(200, function () {
                                                                        $('#angebot2-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot2-container .angebot2-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot2.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot2-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot2-container .angebot2-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot2.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot2-container .angebot2-message').animate({
                                                height: '30px'
                                        }, angebot2.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot2-container .angebot2-message').fadeOut();
                $('#angebot2-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot2-container form').fadeOut(200);
                $('#angebot2-container .angebot2-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot2.message = '';
                if (!$('#angebot2-container #angebot-name').val()) {
                        angebot2.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot2-container #angebot-phone').val()) {
                        angebot2.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot2.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot2-container .angebot2-message')
                        .html($('<div class="angebot-error">').append(angebot2.message))
                        .fadeIn(200);
        }
};
var angebot3 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot3-container .angebot3-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot3-container .angebot3-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot3-subject').length) {
                        h += 26;
                }
                if ($('#angebot3-cc').length) {
                        h += 22;
                }

                var title = $('#angebot3-container .angebot3-title').html();
                $('#angebot3-container .angebot3-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot3-container .angebot3-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot3-container .angebot3-title').html(title);
                                                $('#angebot3-container form').fadeIn(200, function () {
                                                        $('#angebot3-container #angebot3-name').focus();

                                                        $('#angebot3-container .angebot3-cc').click(function () {
                                                                var cc = $('#angebot3-container #angebot3-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot3-container .angebot3-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot3-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot3.validate()) {
                                $('#angebot3-container .angebot3-message').fadeOut(function () {
                                        $('#angebot3-container .angebot3-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot3-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot3-container form').fadeOut(200);
                                $('#angebot3-container .angebot3-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot3-container .angebot3-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot3-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot3-container .angebot3-loading').fadeOut(200, function () {
                                                                        $('#angebot3-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot3-container .angebot3-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot3.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot3-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot3-container .angebot3-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot3.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot3-container .angebot3-message').animate({
                                                height: '30px'
                                        }, angebot3.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot3-container .angebot3-message').fadeOut();
                $('#angebot3-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot3-container form').fadeOut(200);
                $('#angebot3-container .angebot3-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot3.message = '';
                if (!$('#angebot3-container #angebot-name').val()) {
                        angebot3.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot3-container #angebot-phone').val()) {
                        angebot3.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot3.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot3-container .angebot3-message')
                        .html($('<div class="angebot-error">').append(angebot3.message))
                        .fadeIn(200);
        }
};
var angebot4 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot4-container .angebot4-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot4-container .angebot4-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot4-subject').length) {
                        h += 26;
                }
                if ($('#angebot4-cc').length) {
                        h += 22;
                }

                var title = $('#angebot4-container .angebot4-title').html();
                $('#angebot4-container .angebot4-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot4-container .angebot4-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot4-container .angebot4-title').html(title);
                                                $('#angebot4-container form').fadeIn(200, function () {
                                                        $('#angebot4-container #angebot4-name').focus();

                                                        $('#angebot4-container .angebot4-cc').click(function () {
                                                                var cc = $('#angebot4-container #angebot4-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot4-container .angebot4-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot4-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot4.validate()) {
                                $('#angebot4-container .angebot4-message').fadeOut(function () {
                                        $('#angebot4-container .angebot4-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot4-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot4-container form').fadeOut(200);
                                $('#angebot4-container .angebot4-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot4-container .angebot4-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot4-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot4-container .angebot4-loading').fadeOut(200, function () {
                                                                        $('#angebot4-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot4-container .angebot4-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot4.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot4-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot4-container .angebot4-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot4.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot4-container .angebot4-message').animate({
                                                height: '30px'
                                        }, angebot4.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot4-container .angebot4-message').fadeOut();
                $('#angebot4-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot4-container form').fadeOut(200);
                $('#angebot4-container .angebot4-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot4.message = '';
                if (!$('#angebot4-container #angebot-name').val()) {
                        angebot4.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot4-container #angebot-phone').val()) {
                        angebot4.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot4.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot4-container .angebot4-message')
                        .html($('<div class="angebot-error">').append(angebot4.message))
                        .fadeIn(200);
        }
};
var angebot5 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot5-container .angebot5-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot5-container .angebot5-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot5-subject').length) {
                        h += 26;
                }
                if ($('#angebot5-cc').length) {
                        h += 22;
                }

                var title = $('#angebot5-container .angebot5-title').html();
                $('#angebot5-container .angebot5-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot5-container .angebot5-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot5-container .angebot5-title').html(title);
                                                $('#angebot5-container form').fadeIn(200, function () {
                                                        $('#angebot5-container #angebot5-name').focus();

                                                        $('#angebot5-container .angebot5-cc').click(function () {
                                                                var cc = $('#angebot5-container #angebot5-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot5-container .angebot5-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot5-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot5.validate()) {
                                $('#angebot5-container .angebot5-message').fadeOut(function () {
                                        $('#angebot5-container .angebot5-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot5-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot5-container form').fadeOut(200);
                                $('#angebot5-container .angebot5-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot5-container .angebot5-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot5-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot5-container .angebot5-loading').fadeOut(200, function () {
                                                                        $('#angebot5-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot5-container .angebot5-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot5.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot5-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot5-container .angebot5-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot5.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot5-container .angebot5-message').animate({
                                                height: '30px'
                                        }, angebot5.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot5-container .angebot5-message').fadeOut();
                $('#angebot5-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot5-container form').fadeOut(200);
                $('#angebot5-container .angebot5-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot5.message = '';
                if (!$('#angebot5-container #angebot-name').val()) {
                        angebot5.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot5-container #angebot-phone').val()) {
                        angebot5.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot5.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot5-container .angebot5-message')
                        .html($('<div class="angebot-error">').append(angebot5.message))
                        .fadeIn(200);
        }
};
var angebot6 = {
        message: null,
        open: function (dialog) {
                // add padding to the buttons in firefox/mozilla
                if ($.browser.mozilla) {
                        $('#angebot6-container .angebot6-button').css({
                                'padding-bottom': '2px'
                        });
                }
                // input field font size
                if ($.browser.safari) {
                        $('#angebot6-container .angebot6-input').css({
                                'font-size': '.9em'
                        });
                }

                // dynamically determine height
                var h = 280;
                if ($('#angebot6-subject').length) {
                        h += 26;
                }
                if ($('#angebot6-cc').length) {
                        h += 22;
                }

                var title = $('#angebot6-container .angebot6-title').html();
                $('#angebot6-container .angebot6-title').html('Lade...');
                dialog.overlay.fadeIn(200, function () {
                        dialog.container.fadeIn(200, function () {
                                dialog.data.fadeIn(200, function () {
                                        $('#angebot6-container .angebot6-content').animate({
                                                height: h
                                        }, function () {
                                                $('#angebot6-container .angebot6-title').html(title);
                                                $('#angebot6-container form').fadeIn(200, function () {
                                                        $('#angebot6-container #angebot6-name').focus();

                                                        $('#angebot6-container .angebot6-cc').click(function () {
                                                                var cc = $('#angebot6-container #angebot6-cc');
                                                                cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
                                                        });

                                                        // fix png's for IE 6
                                                        if ($.browser.msie && $.browser.version < 7) {
                                                                $('#angebot6-container .angebot6-button').each(function () {
                                                                        if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
                                                                                var src = RegExp.$1;
                                                                                $(this).css({
                                                                                        backgroundImage: 'none',
                                                                                        filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
                                                                                });
                                                                        }
                                                                });
                                                        }
                                                });
                                        });
                                });
                        });
                });
        },
        show: function (dialog) {
                $('#angebot6-container .angebot-send').click(function (e) {
                        e.preventDefault();
                        // validate form
                        if (angebot6.validate()) {
                                $('#angebot6-container .angebot6-message').fadeOut(function () {
                                        $('#angebot6-container .angebot6-message').removeClass('angebot-error').empty();
                                });
                                $('#angebot6-container .angebot-title').html('Sende Anfrage...');
                                $('#angebot6-container form').fadeOut(200);
                                $('#angebot6-container .angebot6-content').animate({
                                        height: '80px'
                                }, function () {
                                        $('#angebot6-container .angebot6-loading').fadeIn(200, function () {
                                                $.ajax({
                                                        url: 'data/angebot.php?id=1',
                                                        data: $('#angebot6-container form').serialize() + '&action=send',
                                                        type: 'post',
                                                        cache: false,
                                                        dataType: 'html',
                                                        complete: function (xhr) {
                                                                $('#angebot6-container .angebot6-loading').fadeOut(200, function () {
                                                                        $('#angebot6-container .angebot-title').html('Vielen Dank!');
                                                                        $('#angebot6-container .angebot6-message').html(xhr.responseText).fadeIn(200);
                                                                });
                                                        },
                                                        error: angebot6.error
                                                });
                                        });
                                });
                        }
                        else {
                                if ($('#angebot6-container .angebot-message:visible').length > 0) {
                                        var msg = $('#angebot6-container .angebot6-message div');
                                        msg.fadeOut(200, function () {
                                                msg.empty();
                                                angebot6.showError();
                                                msg.fadeIn(200);
                                        });
                                }
                                else {
                                        $('#angebot6-container .angebot6-message').animate({
                                                height: '30px'
                                        }, angebot6.showError);
                                }

                        }
                });
        },
        close: function (dialog) {
                $('#angebot6-container .angebot6-message').fadeOut();
                $('#angebot6-container .angebot-title').html('Auf Wiedersehen...');
                $('#angebot6-container form').fadeOut(200);
                $('#angebot6-container .angebot6-content').animate({
                        height: 40
                }, function () {
                        dialog.data.fadeOut(200, function () {
                                dialog.container.fadeOut(200, function () {
                                        dialog.overlay.fadeOut(200, function () {
                                                $.modal.close();
                                        });
                                });
                        });
                });
        },
        error: function (xhr) {
                alert(xhr.statusText);
        },
        validate: function () {
                angebot6.message = '';
                if (!$('#angebot6-container #angebot-name').val()) {
                        angebot6.message += 'Bitte Ihren Namen angeben. ';
                }

                if (!$('#angebot6-container #angebot-phone').val()) {
                        angebot6.message += 'Bitte Ihre Telefonnummer angeben.';
                }

                if (angebot6.message.length > 0) {
                        return false;
                }
                else {
                        return true;
                }
        },
        showError: function () {
                $('#angebot6-container .angebot6-message')
                        .html($('<div class="angebot-error">').append(angebot6.message))
                        .fadeIn(200);
        }
};
