displayDetailPrice = 0;
actualParzellen = new Array();
loadMap = 0;
request = false;
var address = 1;
var reqok;
var mwst = 1.076;
var global_count_gemeinde = 1;


var min, max, selection_fileformat, format, selection_formatierung, selection_gemeinde, selection_format, selection_scale, selection_planart, selection_anzahl, selection_polygon, selection_formatorientation, scale, newX, newY, newT;

function awaitRequest() {
    if (request == true) {
        $('#tx_mailform_2001').submit();
    } else {
        setTimeout(awaitRequest, 10);
    }
}
/**
 * Seitennavigation
 */
 $(document).ready(function(){
 
 
$('.nextp').click( function(){

//console.log(checkRequiredFields(($('.tx_mailform_nextpage input:nth-child(2)').val()-1)));

if(checkRequiredFields(($('.tx_mailform_nextpage input:nth-child(2)').val()-1))!=false){
$('.tx_mailform_navi_nextpage').click();
}
});
$('.prevp').click( function(){
$('.tx_mailform_navi_previouspage').click();
});
});
/**
 * Definition of which fields to check on each page
 */

function checkRequiredFields(pageId) {


    switch (pageId) {

    case 1:
        if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 0) {
            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
            $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');

            return false;
        }
        /**
         * Wenn DXF pro Gemeinde ausgewählt ist müssen die folgenden Felder ausgewählt sein
         */
        if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_pro_gemeinde') {
            if ($('#tx_mailform_input-item-2001-FFN021HSN').val() != 0 && $('#tx_mailform_input-item-2001-FOZ851MPD').val() != 0 && $('#tx_mailform_input-item-2001-FCS404LMV').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FRY074JNW').val() != 0) {

                return true;
            } else {
                //alert("JEAH");
                //$("#buttonerrorbox").replaceWith('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');

                return false;
            }
        } else {
            /**
             * Wenn DXF mit Rahmen ausgewählt ist müssen die folgenden Felder ausgewählt sein tx_mailform_input-item-2001-FCS404LMV
             */
            if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_rahmen') {
                /**
                 * Adresse
                 */
                if ($('#tx_mailform_div-item-2001-FJU125UTG-0:checked').val() == 'mopt-0') {
                    if ($('#tx_mailform_input-item-2001-FLV387PCZ').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FLV387PCZ').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FRY074JNW').val() != 0 && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 0 && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 0 && $('#tx_mailform_input-item-2001-FCS404LMV').val() != 'bitte wählen...') {

                    } else {
                        $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                        $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                        return false;

                    }
                    /**
                     * Parzelle
                     */
                } else {
                    if ($('#tx_mailform_input-item-2001-FLV387PCZ').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FLV387PCZ').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FRY074JNW').val() != 0 && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 0 && $('#tx_mailform_input-item-2001-FIX028KYN').val() != '' && $('#tx_mailform_input-item-2001-FCS404LMV').val() != 'bitte wählen...') {

                    } else {
                        $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                        $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                        return false;
                    }
                }

            }
            /**
             * Wenn Situationsplan beglaubigt ausgewählt ist müssen die folgenden Felder ausgewählt sein
             */
            if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'sit_bg') {
                /**
                 * Allgemein
                 */
                if ($('#tx_mailform_input-item-2001-FRY074JNW').val() != 0 && $('#tx_mailform_input-item-2001-FLY308FJE').val() != 'bitte wählen...' && $('#tx_mailform_input-item-2001-FUJ580XLD').val() != 'bitte wählen...') {
                    /**
                     * Bei Adresse
                     */
                    if ($('#tx_mailform_div-item-2001-FJU125UTG-0:checked').val() == 'mopt-0') {

                        if ($('#tx_mailform_input-item-2001-FFT801RXI').val() != 0 && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 'bitte wählen...') {} else {
                            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                            $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                            return false;
                        }
                    } else {
                        /**
                         * Bei Parzelle
                         */
                        if ($('#tx_mailform_input-item-2001-FIX028KYN').val() != '') {} else {
                            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                            $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                            return false;
                        }
                    }
                } else {
                    $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                    $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                    return false;
                }
            }
            /**
             * Wenn Situationsplan unbeglaubigt ausgewählt ist müssen die folgenden Felder ausgewählt sein
             */
            if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'sitshop') {
                /**
                 * Allgemein
                 */
                if ($('#tx_mailform_input-item-2001-FRY074JNW').val() != 0) {
                    /**
                     * Bei Adresse
                     */
                    if ($('#tx_mailform_div-item-2001-FJU125UTG-0:checked').val() == 'mopt-0') {
                        if ($('#tx_mailform_input-item-2001-FFT801RXI').val() != 0 && $('#tx_mailform_input-item-2001-FFT801RXI').val() != 'bitte wählen...') {} else {
                            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                            $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                            return false;
                        }
                    } else {
                        /**
                         * Bei Parzelle
                         */
                        if ($('#tx_mailform_input-item-2001-FIX028KYN').val() != '') {} else {
                            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                            $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                            return false;
                        }
                    }
                } else {
                    $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                    $('#tx_mailform_div-item-2001-FKK250TON').css('display','block !important');
                    return false;
                }
            }
            /**
             * Old Check Part from Ben Graedel
             *
             */
            if ($('#tx_mailform_div-item-2001-FJU125UTG-0').attr('checked')) {

                if (($('#tx_mailform_input-item-2001-FOZ851MPD').val() != 0) && ($('#tx_mailform_input-item-2001-FFT801RXI').val() != null) && ($('#tx_mailform_input-item-2001-FFT801RXI').val() != '0')) {

                    //alert($('#tx_mailform_input-item-2001-FFT801RXI').find('option').filter(':selected').val());
                } else {

                    //$('#errorbox').replaceWith('<div id="errorbox"><p class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!</p></div>');
                    $("#buttonerrorbox").replaceWith('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
                    return false;

                }
            } else {

                if (($('#tx_mailform_input-item-2001-FOZ851MPD').val() != 0) && ($('#tx_mailform_input-item-2001-FIX028KYN').val() != '') && ($('#tx_mailform_input-item-2001-FIX028KYN').val() != 'bitte manuell eingeben') && ($('#tx_mailform_input-item-2001-FRY074JNW').val() != '0') && ($('#statusParzelle').val() == '1')) {

                } else {

                    //			    $('#errorbox').replaceWith('<div id="errorbox"><p class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausf&uuml;llen!</p></div>');
                    $("#buttonerrorbox").replaceWith('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');

                    return false;
                }

            }
        }
        break;
    case 2:
        if (reqok == 1) {} else {
            $("#txtfile").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1"><br /><br /><br /><br />Bitte Preis neu berechnen.<br /><br /><br /><br /><br /></span>');


            return false;
        }
        break;
    case 4:

        //Formularfelder auf Inhalt prüfen
        error = false;

        if ($('#tx_mailform_input-item-2001-FZH836ZTI').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FIH099JBO').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FGC096JGJ').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FKI280VKB').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FXF828ZID').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FTR199RJT').val() == '') {
            error = true;
        }
        if ($('#tx_mailform_input-item-2001-FBK056WDO').val() == '') {
            error = true;
        }

        // Feld Verwendung
        if ($('#tx_mailform_div-item-2001-FQK354EMR').is(':visible') && $('#tx_mailform_input-item-2001-FQK354EMR').val() == '') {
            error = true;
        }

        if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_rahmen' || $('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_rahmen') {
            if ($('#tx_mailform_input-item-2001-FDJ154ZLY').val() == '') {
                error = true;
            }
        }

        if ($('#hasGebuehren').val() == "TRUE") {
            if ($('#tx_mailform_input-item-2001-FOF729MJH').val() == '') {
                error = true;
            }
            if ($('#tx_mailform_input-item-2001-FOF729MJH').val() == "f1" && $('#tx_mailform_input-item-2001-FFF178KSL').val() == '') {
                error = true;
            }
            if ($('#tx_mailform_input-item-2001-FOF729MJH').val() == "f2" && $('#tx_mailform_input-item-2001-FUB275EWT').val() == '') {
                error = true;
            }
            if ($('#tx_mailform_input-item-2001-FOF729MJH').val() == "f3" && ($('#tx_mailform_input-item-2001-FOF803YUC').val() == '' || $('#tx_mailform_input-item-2001-FQL631HST').val() == '')) {
                error = true;
            }
            if ($('#tx_mailform_input-item-2001-FOF729MJH').val() == "f4" && $('#tx_mailform_input-item-2001-FNJ119JOC').val() == 'Bitte auswählen') {
                error = true;
            }
        }


        if (error == true) {

            //	$('#errorbox').replaceWith('<div id="errorbox"><p class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!</p></div>');
            //   $('#errorbox').replaceWith('<div id="errorbox"><p class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausf&uuml;llen!</p></div>');
            $("#errorbox").html('<span id="buttonerrorbox" style="margin-bottom: 10px;" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausf&uuml;llen!<br /></span>');

            //$("#tx_mailform_input-item-2001-FXS920ZDP").before('<span style="width: 200px;" id="errorbox" class="tx_mailform_div_err_msg_1">Bitte alle notwendigen Felder ausw&auml;hlen!<br /></span>');
            return false;

        }

        break;

    case 5:
        //alert($('#tx_mailform_div-item-2001-FOF379DUC-0').attr('checked'));
        if ($('#tx_mailform_div-item-2001-FSO687NHF-0').attr('checked') == true || $('#hasGebuehren').val() != "TRUE") {
            //return true;
        } else {
            $("#geb_error").html('<span id="errorboxbutton_geb" class="tx_mailform_div_err_msg_1">Sie m&uuml;ssen die Gebührenmeldung akzeptieren<br/></span>')
            if ($('#tx_mailform_div-item-2001-FOF379DUC-0').attr('checked') == true) {
                return false;
                //return true;
            } else {
                $("#errorboxbutton").replaceWith('<span id="errorboxbutton" class="tx_mailform_div_err_msg_1">Sie m&uuml;ssen die AGB akzeptieren<br/></span>')
                return false;
            }
        }
        //aus/auslert($('#tx_mailform_div-item-2001-FOF379DUC-0').attr('checked'));
        if ($('#tx_mailform_div-item-2001-FOF379DUC-0').attr('checked') == true) {
            //return true;
        } else {
            $("#errorboxbutton").replaceWith('<span id="errorboxbutton" class="tx_mailform_div_err_msg_1">Sie m&uuml;ssen die AGB akzeptieren<br/></span>')
            return false;
        }
        //return true;
        break;
    }
}

function disableFields(itemid) {
    fields = itemid.split('|');
    for (i in fields) {
        $(fields[i]).attr('disabled', true);
    }

    //alert('disable');
}

function enableFields(itemid) {
    fields = itemid.split('|');
    for (i in fields) {
        $(fields[i]).attr('disabled', false);
    }

    //alert('enable');
}

$(document).ready(function () {
    /**
     * Abstände korrigieren bei leeren Boxen oben
     */
    $('.tx_mailform_field_select_special:has(.tx_mailform_div_output_select_width)').each(function () {

        if ($(this + " > .tx_mailform_div_output_select_width").html() != '') {

            $(this).css('display', 'block');
            //alert($(this).html());
        }
    });

/*$('#position').hover( function() {
	alert('tooltip');
}, 0); */

    $("#position").tooltip({
        cssClass: "tooltip-red"
    });
    $(".tx_mailform_navi_nextpage input[type='submit']").before('<span id="buttonerrorbox"></span>');
    $(".tx_mailform_reset input[type='submit']").val("Auswahl zurücksetzen");

    //Verwendungsfeld managen
    //if ($('#tx_mailform_input-item-2001-FQV503UMN').val() == 'sitshop') {

      //  $('#tx_mailform_div-item-2001-FQK354EMR').hide();
        //$('#tx_mailform_input-item-2001-FJT387MQR').val('');

    //} else {

        $('#tx_mailform_div-item-2001-FJT387MQR').hide();
        $('#tx_mailform_input-item-2001-FJT387MQR').val('0');
    //}

    //$(".position").tooltip({cssClass:"tooltip-red"});


    function hideFormparts(id) {
/*  $(id + ' label').hide();
        $(id + ' select').hide();
        $(id + ' input').hide();*/
    }

    function hideFormparts_new(id) {
        $(id + ' label').hide();
        $(id + ' select').hide();
        $(id + ' input').hide();
    }

    function fadeOutFormparts(id) {
/* $(id + ' label').fadeOut("fast");
        $(id + ' select').fadeOut("fast");
        $(id + ' input').fadeOut("fast");
        $(id + ' select').removeAttr("disabled");
        $(id + ' p#validateParzelle').fadeOut("fast");*/
    }
    $('#details_gebuehren').click(function () {
        $('#txtfile').slideToggle();
    });

    function fadeOutFormparts_new(id) {
        $(id + ' label').fadeOut("fast");
        $(id + ' select').fadeOut("fast");
        $(id + ' input').fadeOut("fast");
        $(id + ' select').removeAttr("disabled");
        $(id + ' p#validateParzelle').fadeOut("fast");
    }

    function fadeInFormparts(id) {
        $(id + ' label').fadeIn("fast");
        $(id + ' select').fadeIn("fast");
        $(id + ' input').fadeIn("fast");
        $(id + ' p#validateParzelle').fadeIn("fast");
    }

    function fadeInFormparts_new(id) {
        $(id + ' label').fadeIn("fast");
        $(id + ' select').fadeIn("fast");
        $(id + ' input').fadeIn("fast");
        $(id + ' p#validateParzelle').fadeIn("fast");
    }
    //Benutzerdaten abfragen

    function clearUserData() {

        $('#tx_mailform_input-item-2001-FZH836ZTI').val('');
        $('#tx_mailform_input-item-2001-FIH099JBO').val('');
        $('#tx_mailform_input-item-2001-FGC096JGJ').val('');
        $('#tx_mailform_input-item-2001-FRY100YVT').val('');
        $('#tx_mailform_input-item-2001-FXF828ZID').val('');
        $('#tx_mailform_input-item-2001-FTR199RJT').val('');
        $('#tx_mailform_input-item-2001-FBK056WDO').val('');
        $('#tx_mailform_input-item-2001-FPO534TKG').val('');
        $('#tx_mailform_input-item-2001-FKI280VKB').val('');

        if ($('#tx_mailform_input-item-2001-FQV503UMN').val() == 'sitshop') {

            //alert(json[0].verwendung);
            $('#tx_mailform_input-item-2001-FJT387MQR').val('');
        } else {
            $('#tx_mailform_input-item-2001-FQK354EMR').val('0');
        }

    }

    function fillUserData(username) {

        if (username != '') {

            $.ajax({
                url: ('geodaten.html'),
                data: 'tx_t3mgeodata_pi1[get]=user&tx_t3mgeodata_pi1[fileid]=' + username,
                type: 'GET',
                timeout: 20000,
                dataType: 'json',
                error: function () {
                    //alert('Error loading json data!');
                },
                success: function (json) {

                    var plzort = json[0].zip + ' ' + json[0].city;

/* loadedName1 = json[0].name1;
					    loadedName2 = json[0].name2;
					    loadedAdr1 = json[0].adr1;
					    loadedAdr2 = json[0].adr2;
					    loadedCountry = json[0].country;
					    loadedEmail = json[0].email;
					    loadedTel = json[0].tel;
					    loadedFax = json[0].fax;
					    loadedPlzort = json[0].plzort;
					    loadedVerwendung = json[0].verwendung; */

                    //for (p in json) {
                    $('#tx_mailform_input-item-2001-FZH836ZTI').val(json[0].name1);
                    $('#tx_mailform_input-item-2001-FIH099JBO').val(json[0].name2);
                    $('#tx_mailform_input-item-2001-FGC096JGJ').val(json[0].adr1);
                    $('#tx_mailform_input-item-2001-FRY100YVT').val(json[0].adr2);
                    $('#tx_mailform_input-item-2001-FXF828ZID').val(json[0].country);
                    $('#tx_mailform_input-item-2001-FTR199RJT').val(json[0].email);
                    $('#tx_mailform_input-item-2001-FBK056WDO').val(json[0].tel);
                    $('#tx_mailform_input-item-2001-FPO534TKG').val(json[0].fax);
                    $('#tx_mailform_input-item-2001-FKI280VKB').val(plzort);

                    if ($('#tx_mailform_input-item-2001-FQV503UMN').val() == 'sitshop') {

                        //alert(json[0].verwendung);
                        $('#tx_mailform_input-item-2001-FJT387MQR').val(json[0].verwendung);
                    } else {
                        $('#tx_mailform_input-item-2001-FQK354EMR').val(json[0].verwendung);
                    }

                    //}
                }
            });
        }

    }

    function getUserData(username, password) {

        var verificaton = '';

        //Benutzerdaten prüfen
        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=verify&tx_t3mgeodata_pi1[fileid]=' + username + '&tx_t3mgeodata_pi1[fileid2]=' + password,
            type: 'GET',
            timeout: 80000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data!');
            },
            success: function (json) {

                if (json[1].verification == true) {
                    fillUserData(username);
                }

            }
        });

    }

    //Wechsel der Radiobox Adresse/Parzelle


    function switchedRadio(selection) {
        tempFile2 = showLoadingText('#tx_mailform_input-item-2001-FRY074JNW');
        //alert('switch funktion aufgerufen');
        //Felder deaktivieren für Übergang FRY074JNW
        disableFields('#tx_mailform_div-item-2001-FRY074JNW|#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW|#tx_mailform_input-item-2001-FFT801RXI|#tx_mailform_input-item-2001-FZG018JZI|#tx_mailform_input-item-2001-FIX028KYN');
        loadGemeinde(selection);
        if (selection) {
            //alert('parzelle');
            //Felder die beim Wechsel ein-/ausgeblendet werden
            hideFields = new Array('#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FZG018JZI');
            for (i in hideFields) {
                hideFormparts(hideFields[i]);
            }
            //Prüfen ob Gemeinde schon ausgewählt wurde
            if ($('#tx_mailform_input-item-2001-FRY074JNW').val() != '0') {

                showFields = new Array('#tx_mailform_div-item-2001-FIX028KYN');
                for (j in showFields) {
                    fadeInFormparts(showFields[j]);
                }
/*	//Prüfen ob Parzelle schon gewählt wurde
            if($('#tx_mailform_input-item-2001-FIX028KYN').val()!='0') {

                if($('#tx_mailform_input-item-2001-FIX028KYN').val()=='') {
                	loadParzellen($('#tx_mailform_input-item-2001-FRY074JNW').val());
                } else {
					showFields = new Array(
						'#tx_mailform_div-item-2001-FIX028KYN'
					)
				}
			} else {
				showFields = new Array(
					'#tx_mailform_div-item-2001-FIX028KYN'
				)
			} */
            } else {
                showFields = new Array();
            }

/*		showFields = new Array(
			'#tx_mailform_div-item-2001-FIX028KYN'
		); */

        } else {

            //Felder die beim Wechsel ein-/ausgeblendet werden
            hideFields = new Array('#tx_mailform_div-item-2001-FIX028KYN');
            for (i in hideFields) {
                fadeOutFormparts(hideFields[i]);
            }
            //Prüfen ob Gemeinde schon ausgewählt wurde
            if ($('#tx_mailform_input-item-2001-FRY074JNW').val() != '0') {

                //alert('gemeinde geladen');
                //Prfen ob Strasse schon ausgewählt wurde oder nicht
                if ($('#tx_mailform_input-item-2001-FFT801RXI').val() != '0') {

                    //alert($('#tx_mailform_input-item-2001-FFT801RXI').val());
                    if ($('#tx_mailform_input-item-2001-FFT801RXI').val() == null) {
                        loadStrassen($('#tx_mailform_input-item-2001-FRY074JNW').val());

                        showFields = new Array();

                        //alert('im null');
                        //alert('strassen geladen');
                    } else {
                        //alert('strassen und nummer einblenden');
                        showFields = new Array('#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FZG018JZI');
                        //alert('strasse schon ungleich "0" und ungleich ""');
                        for (j in showFields) {
                            fadeInFormparts(showFields[j]);
                        }
                    }
                } else {
                    //alert('nur strassen einblenden');
                    showFields = new Array('#tx_mailform_div-item-2001-FFT801RXI');
                    for (j in showFields) {
                        fadeInFormparts(showFields[j]);
                    }
                }
            } else {
                showFields = new Array();
            }

        }

/*     for (j in showFields) {
            fadeInFormparts(showFields[j]);
        }

        //Entsprechende Felder ein/ausblenden
        for (i in hideFields) {
            fadeOutFormparts(hideFields[i]);
        }*/

        //Felder wieder aktivieren
        enableFields('#tx_mailform_div-item-2001-FRY074JNW|#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW|#tx_mailform_input-item-2001-FFT801RXI|#tx_mailform_input-item-2001-FZG018JZI|#tx_mailform_input-item-2001-FIX028KYN');

        hideLoadingText(tempFile2);
        setTimeout("displayForm()", 900);
    }

/*function ajaxLoading() {

	$("body").append('<div id="divloader">lade daten...</div>');
			$('#divloader').hide();

	//i=0;
	//for (i in displayLoading) {
		$(this).ajaxStart(function() {
			$('#divloader').fadeIn("fast");
			$('#tx_mailform_2001').fadeTo("fast", 0.2);

		});
		$(this).ajaxStop(function() {
			$('#tx_mailform_2001').fadeTo("fast", 1);
			$('#divloader').fadeOut("fast");
		});
	//}

} */

    function showLoadingText(itemid) {

        splitResult = itemid.split("2001-");
        $(itemid).hide()
        $(itemid).before('<div id="tx_mailform_loader-item-2001-' + splitResult[1] + '" class="div-loader">laden...</div>');
        return ('#tx_mailform_loader-item-2001-' + splitResult[1] + '|' + itemid);

    }

    function hideLoadingText(itemid) {

        items = itemid.split('|');
        //	$('body').append(items[0]);
        $(items[0]).remove();
        $(items[1]).show();

    }

    function validateParzelle() {

        $('#validateParzelle').remove();

        //alert(actualParzellen.length);
        //alert('Parzellenfeld: ' + $('#tx_mailform_input-item-2001-FIX028KYN').val());
        if (isInArray($('#tx_mailform_input-item-2001-FIX028KYN').val(), actualParzellen)) {

            $('#tx_mailform_input-item-2001-FIX028KYN').after('<p id="validateParzelle" style="color: #000000; font-weight: bold;">Parzelle gefunden!</p>');
            $('#statusParzelle').val('1');
        } else {
            $('#tx_mailform_input-item-2001-FIX028KYN').after('<p id="validateParzelle" style="color: #ff0000; font-weight: bold;">Parzelle ung&uuml;ltig!</p>');
            $('#statusParzelle').val('0');
        }
    }

    function firstCallCheckboxes() {
        $('#tx_mailform_div-item-2001-FJU125UTG-' + $('#firstCall').val()).attr('checked', 'checked');
    }

    function getMapSource(addX, addY, startX, startY, addT) {

        reqok = 0;
        if (loadMap != 1) {

            loadMap = 1;

            //alert($('#tx_mailform_input-item-2001-FYH842QDU').val());
            addedX = parseInt($('#tx_mailform_input-item-2001-FYH842QDU').val());
            addedY = parseInt($('#tx_mailform_input-item-2001-FLK424SVF').val());
            addedT = parseFloat($('#tx_mailform_input-item-2001-FSO743EST').val());
            product = $('#product').val();
            addedX = addedX + parseInt(addX);
            addedY = addedY + parseInt(addY);
            addedT = addedT + parseFloat(addT);

            $('#tx_mailform_input-item-2001-FYH842QDU').val(addedX);
            $('#tx_mailform_input-item-2001-FLK424SVF').val(addedY);
            $('#tx_mailform_input-item-2001-FSO743EST').val(addedT);
            if (product == "dxf_pro_gemeinde") {
                $('#up-slow').css("display", "none");
                $('#down-slow').css("display", "none");
                $('#left-slow').css("display", "none");
                $('#right-slow').css("display", "none");
                $('#map_turn_span').css("display", "none");
                newX = startX;
            } else {
                newX = parseFloat(startX) + parseInt(addedX);
            }
            newY = parseFloat(startY) + parseInt(addedY);

            $('#map-loader').show();

            //scale = $('#tx_mailform_input-item-2001-FVQ366PBB').val();
            scale = $('#scale').val();
            scaleParts = scale.split(':');

            //scale für die berechnung
            scale = scaleParts[1];

            format = $('#format').val();

            if (format == 'A4') {

                scales = new Array();
                scales['200'] = '1000';
                scales['250'] = '1000';
                scales['500'] = '2000';
                scales['1000'] = '4000';

            } else {

                scales = new Array();
                scales['200'] = '1500';
                scales['250'] = '1500';
                scales['500'] = '3000';
                scales['1000'] = '6000';

            }

            //recenter scale
            scale2 = scales[scaleParts[1]];
            selection_formatierung = format;
            startX = newX;
            startY = newY;
            newT = addT;
            $.ajax({

                url: ('geodaten.html'),
                data: 'tx_t3mgeodata_pi1[get]=poly&tx_t3mgeodata_pi1[startX]=' + newX + '&tx_t3mgeodata_pi1[startY]=' + newY + '&tx_t3mgeodata_pi1[scale]=' + scale + '&tx_t3mgeodata_pi1[scale2]=' + scale2 + '&tx_t3mgeodata_pi1[addT]=' + addedT + '&tx_t3mgeodata_pi1[format]=' + format + '&tx_t3mgeodata_pi1[product]=' + product,
                type: 'GET',
                timeout: 90000,
                dataType: 'json',
                error: function () {
                    //alert('Error loading json data! mapsource');
                },
                success: function (json) {

                    geoMap = new Image()

                    $(geoMap).load(function () {

                        $('#dynamic-map').replaceWith(geoMap);
                        $('#map-loader').hide();
                        loadMap = 0;

                    }).error(function () {

                        //alert('Error loading image! mapsource');
                    }).attr({

                        src: json[0].source,
                        id: 'dynamic-map',
                        style: 'background: #ffffff; border: 1px solid #000000; margin: 4px;'

                    });

                    //File Url in Textfeld schreiben für letzte Seite...
                    overviewSource = json[0].source.replace('recenter_scale=' + scale2, 'recenter_scale=' + scale2 * 1.333);

                    $('#tx_mailform_input-item-2001-FMB327HTW').val(overviewSource);

                    //CartoWeb Link - URL hinzufügen
                    $('#cartoweblink').attr('href', json[0].cartoweblink);

                    //DAPRgetPrice($('#product').val(), $('#format').val());
                }
            });

        }

    }

    function switchDetailPrice() {

        if (displayDetailPrice == 0) {
            displayDetailPrice = 1;
            $('#detailPrice').fadeIn("fast");

        } else {
            $('#detailPrice').fadeOut("fast");
            displayDetailPrice = 0;
        }

        return true;
    }

    function isInArray(item, arr) {
        for (p = 0; p < arr.length; p++) {
            if (item == arr[p].name) {
                return true;
            }
        }

    }

    function getPrice(product, format) {
        if ($('#hasAbo').val() == 'undefined') {
            hasAbo = 0;
        } else {
            hasAbo = $('#hasAbo').val();
        }
        alert('ajax: http://www.geoshopper.ch/geodaten.html?tx_t3mgeodata_pi1[get]=price&tx_t3mgeodata_pi1[type]=' + product + '&tx_t3mgeodata_pi1[abo]=' + hasAbo + '&tx_t3mgeodata_pi1[format]=' + format);
        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=price&tx_t3mgeodata_pi1[type]=' + product + '&tx_t3mgeodata_pi1[abo]=' + hasAbo + '&tx_t3mgeodata_pi1[format]=' + format,
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {
                alert('err');
                //alert('Error loading json data! price');
                //alert('tx_t3mgeodata_pi1[get]=price&tx_t3mgeodata_pi1[type]=' + product + '&tx_t3mgeodata_pi1[abo]=1&tx_t3mgeodata_pi1[format]=' + format);
            },
            success: function (json) {
                alert('get');
                //alert('price'+json[0].shortPrice);
                if (json[0].shortPrice == 0) {

                    $('#displayPrice').replaceWith('<span id="displayPrice">Das gew&auml;hlte Produkt ist kostenlos.</span>');
                } else {
                    $('#displayPrice').replaceWith('<span id="displayPrice">Das gew&auml;hlte Produkt kostet ' + json[0].shortPrice + ' sFr. exkl MwSt.</span>');
                }

                $('#detailContent').replaceWith('<div id="detailContent">' + json[0].detailPrice + '</div>');

            }
        });
    }

    function loadParzellen(fileid) {

        //	tempFile = showLoadingText('#tx_mailform_input-item-2001-FIX028KYN');
        //fadeOutFormparts('#tx_mailform_div-item-2001-FZG018JZI');
        //disableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');
        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=parzellen&tx_t3mgeodata_pi1[fileid]=' + fileid,
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! parzellen');
                //enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');
            },
            success: function (json) {
                var output = '<option value="0">bitte w&auml;hlen...</option>\n';
/*	for (p in json) {
						output += '<option value=\"' + json[p].fileid + '\">' + json[p].name + '</option>\n'; */

                actualParzellen = json;

                //Parzelle checken falls ausgefüllt
                if (($('#tx_mailform_input-item-2001-FIX028KYN').val() != '') && ($('#tx_mailform_input-item-2001-FIX028KYN').val() != 'bitte manuell eingeben')) {
                    if (!$('#tx_mailform_div-item-2001-FJU125UTG-0').is(":checked")) {
                        validateParzelle();
                    }

                }

            }

            //hideLoadingText(tempFile);
            //enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');
            //$('#tx_mailform_input-item-2001-FIX028KYN').html(output);
            //	alert(actualParzellen);
        });
    }

    function loadStrassen(fileid) {

        tempFile = showLoadingText('#tx_mailform_input-item-2001-FFT801RXI');
        fadeOutFormparts('#tx_mailform_div-item-2001-FZG018JZI');
        disableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');

        strassen = $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=strassen&tx_t3mgeodata_pi1[fileid]=' + fileid,
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! strassen');
                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');

            },
            success: function (json) {
                var output = '<option value="0">bitte w&auml;hlen...</option>\n';
                for (p in json) {
                    output += '<option id="' + json[p].fileid + '" value="' + json[p].fileid + '">' + json[p].name + '</option>\n';
                }

                hideLoadingText(tempFile);

                $('#tx_mailform_input-item-2001-FFT801RXI').html(output);

                if ($('#firstCall').val() != '1') {

                    //Läuft nicht im IE6
                    //$('#tx_mailform_input-item-2001-FFT801RXI').val($('#firstStrasse').val());
                    //---->FIX
                    $("#tx_mailform_input-item-2001-FFT801RXI option").each(function () {

                        if ($(this).attr("id") == $('#firstStrasse').val()) {
                            var X = $(this);
                            //setTimeout(function () {
                            X.attr("selected", "selected");
                            if ($('#tx_mailform_input-item-2001-FFT801RXI').val() != '0') {
                                loadHausnummer();
                                //alert($('#tx_mailform_input-item-2001-FFT801RXI').val());
                            }

/*},
				  10);*/
                        }

                    }); //end each
                    //loadParzellen($('#tx_mailform_input-item-2001-FZN923HJY').val());
                }

                fadeInFormparts('#tx_mailform_div-item-2001-FFT801RXI');
                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW|#tx_mailform_input-item-2001-FFT801RXI|#tx_mailform_input-item-2001-FZG018JZI');
                //alert($("#tx_mailform_input-item-2001-FFT801RXI").val());
            }
        })
    }

    //Produkte laden


    function loadProdukte() {

        tempFile2 = showLoadingText('#tx_mailform_input-item-2001-FZN923HJY');

        /*produkte = $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=produkte',
            type: 'GET',
            timeout: 81000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! produkte');
            },
            success: function (json) {*/

                //loadFormate($('#tx_mailform_input-item-2001-FZN923HJY').val());
                
                /**
                 * VARIANTE DB
                 */
                /*var output = '<option value="0">bitte w&auml;hlen...</option>\n';
                for (p in json) {
                    output += '<option id="' + json[p].fileid + '" value="' + json[p].fileid + '">' + json[p].name + '</option>\n';

                }*/
                /**
                 * VARIANTE FIX
                 */
                var output = '<option value="0">bitte w&auml;hlen...</option>\n<option value="dxf_pro_gemeinde" id="dxf_pro_gemeinde" class="tx_mailform_option">DXF/DWG pro Gemeinde</option>\n<option value="dxf_rahmen" id="dxf_rahmen" class="tx_mailform_option">DXF/DWG mit Rahmen</option>\n<option value="sit_bg" id="sit_bg" class="tx_mailform_option">Situationsplan beglaubigt PDF</option>\n<option value="sitshop" id="sitshop" class="tx_mailform_option">Situationsplan unbeglaubigt PDF</option>\n';

                $('#tx_mailform_input-item-2001-FZN923HJY').html(output);

                $('#tx_mailform_input-item-2001-FZN923HJY').change(function () {

                    $('#tx_mailform_input-item-2001-FRF916ZFX').val($('#tx_mailform_input-item-2001-FZN923HJY').find('option').filter(':selected').text());
                });

/*	if ($('#firstCall').val()!='1') {
					$('#tx_mailform_input-item-2001-FZN923HJY').val($('#firstProduct').val());
					loadFormate($('#tx_mailform_input-item-2001-FZN923HJY').val());
				} */

                if ($('#firstCall').val() != '1') {
                    $("#tx_mailform_input-item-2001-FZN923HJY option").each(function () {

                        if ($(this).attr("id") == $('#firstProduct').val()) {

                            var X = $(this);
                            setTimeout(function () {
                                X.attr("selected", "selected");
                                loadRightCol();
                                loadFormate($('#tx_mailform_input-item-2001-FZN923HJY').val());
                            }, 10);
                        }

                    });

                    //$('#tx_mailform_input-item-2001-FFN021HSN').val($('#firstFormat').val());
                }


            //}

        //});
        $('#tx_mailform_div-item-2001-FCK142FBP').show();
        showFields2 = new Array('#tx_mailform_div-item-2001-FJU125UTG', '#tx_mailform_div-item-2001-FSD137SXH');
        for (j in showFields2) {
            fadeInFormparts(showFields2[j]);
        } /* DW EDIT */
        //Felder deaktivieren für Übergang
        //disableFields('#tx_mailform_div-item-2001-FCS404LMV|#tx_mailform_div-item-2001-FLV387PCZ|#tx_mailform_div-item-2001-FLY308FJE|#tx_mailform_input-item-2001-FUJ580XLD');
        hideFields = new Array('#tx_mailform_div-item-2001-FCS404LMV', '#tx_mailform_div-item-2001-FLV387PCZ', '#tx_mailform_div-item-2001-FLY308FJE', '#tx_mailform_div-item-2001-');
        //Felder ausblenden
        for (i in hideFields) {
            fadeOutFormparts(hideFields[i]);
        }

        if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_pro_gemeinde') {
            showFields = new Array('#tx_mailform_div-item-2001-FCS404LMV');
            hideDivs = new Array('#tx_mailform_div-item-2001-FZG018JZI', '#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FIX028KYN', '#tx_mailform_div-item-2001-FCK142FBP', '#tx_mailform_div-item-2001-FJU125UTG');
            //Felder ausblenden
            for (i in hideDivs) {
                hideDiv(hideDivs[i]);
            }

        }
        hideLoadingText(tempFile2);
    }

    //Formate laden


    function loadRightCol() {
        if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_pro_gemeinde') {
            showDivs = new Array('#tx_mailform_div-item-2001-FCS404LMV');
            hideDivs = new Array('#tx_mailform_div-item-2001-FZG018JZI', '#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FIX028KYN', '#tx_mailform_div-item-2001-FCK142FBP', '#tx_mailform_div-item-2001-FJU125UTG');
            //Felder ausblenden
            for (i in showDivs) {
                showDiv(showDivs[i]);
                fadeInFormparts(showDivs[i]);
            }
            showDiv('#tx_mailform_div-item-2001-FCS404LMV');
            for (i in hideDivs) {
                hideDiv(hideDivs[i]);
            }

        } else if ($('#tx_mailform_input-item-2001-FZN923HJY').val() == 'dxf_rahmen') {
            //alert("dxf_rahmen");
            showDivs = new Array('#tx_mailform_div-item-2001-FZG018JZI', '#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FIX028KYN', '#tx_mailform_div-item-2001-FCK142FBP', '#tx_mailform_div-item-2001-FJU125UTG');
            for (i in showDivs) {
                showDiv(showDivs[i]);
            }
        }
    }

    function loadFormate(fileid) {

        tempFile3 = showLoadingText('#tx_mailform_input-item-2001-FFN021HSN');
        disableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FOZ851MPD');

        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=formate&tx_t3mgeodata_pi1[fileid]=' + fileid,
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {

                enableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FOZ851MPD|#tx_mailform_input-item-2001-FFN021HSN');
                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');
                //alert('Error loading json data! formate');
            },
            success: function (json) {
                var output = '';
                var displayName = '';
                for (p in json) {

                    if (json[p].name == 'A4') {
                        displayName = 'A4 (empfohlen)';
                    } else {
                        displayName = json[p].name;
                    }

                    output += '<option id="' + json[p].name + '" value="' + json[p].name + '">' + displayName + '</option>\n';
                }

                hideLoadingText(tempFile3);

                $('#tx_mailform_input-item-2001-FFN021HSN').html(output);

                if ($('#firstCall').val() != '1') {

                    $("#tx_mailform_input-item-2001-FFN021HSN option").each(function () {

                        if ($(this).attr("id") == $('#firstFormat').val()) {

                            var X = $(this);
                            setTimeout(function () {
                                X.attr("selected", "selected");
                            }, 10);
                        }

                    });

                    //$('#tx_mailform_input-item-2001-FFN021HSN').val($('#firstFormat').val());
                }

                enableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FOZ851MPD|#tx_mailform_input-item-2001-FFN021HSN');

                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');

                loadMassstab($('#tx_mailform_input-item-2001-FZN923HJY').val(), $('#tx_mailform_input-item-2001-FFN021HSN').val());

            }
        });
    }

    //Masstaebe laden


    function loadMassstab(fileid, fileid2) {

        tempFile4 = showLoadingText('#tx_mailform_input-item-2001-FOZ851MPD');
        disableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FFN021HSN');

        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=massstab&tx_t3mgeodata_pi1[fileid]=' + fileid + '&tx_t3mgeodata_pi1[fileid2]=' + fileid2,
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! massstab');
                enableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FFN021HSN');
                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');

            },
            success: function (json) {
                var output = '';
                var displayName = '';

                for (p in json) {

                    if (json[p].name == '1:200') {
                        displayName = '1:200 (empfohlen)';
                    } else {
                        displayName = json[p].name;
                    }

                    output += '<option id="' + json[p].name + '" value="' + json[p].name + '">' + displayName + '</option>\n';
                }

                hideLoadingText(tempFile4);

                $('#tx_mailform_input-item-2001-FOZ851MPD').html(output);

                //Funktioniert nicht im IE6 - WIESO?
                //$('#tx_mailform_input-item-2001-FOZ851MPD').val('1:500');
                // --->FIX
                //$('#tx_mailform_input-item-2001-FOZ851MPD').selectOptions($('1:500', true));
                enableFields('#tx_mailform_input-item-2001-FZN923HJY|#tx_mailform_input-item-2001-FOZ851MPD|#tx_mailform_input-item-2001-FFN021HSN');
                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');

                if ($('#firstCall').val() != '1') {

                    //$('#tx_mailform_input-item-2001-FOZ851MPD').val($('#firstMassstab').val());
                    $("#tx_mailform_input-item-2001-FOZ851MPD option").each(function () {

                        if ($(this).attr("id") == $('#firstMassstab').val()) {

                            var X = $(this);
                            setTimeout(function () {
                                X.attr("selected", "selected");

                            }, 10);
                        }
                    });

                } else {

                    $("#tx_mailform_input-item-2001-FOZ851MPD option").each(function () {

                        if ($(this).attr("id") == '1:200') {
                            var X = $(this);
                            setTimeout(function () {
                                X.attr("selected", "selected");
                            }, 10);
                        }

                    });

                }

                //)enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FRY074JNW');
            }
        });
    }

    function loadGemeinde(selection) {
        //	alert('loadGemeinde'+selection);
/*       tempFile = showLoadingText('#tx_mailform_input-item-2001-FRY074JNW');
	disableFields('#tx_mailform_input-item-2001-FRY074JNW');
*/

        //	alert('http://geoshopper.typo3-agentur.ch/geodaten.html?tx_t3mgeodata_pi1[get]=gemeinden&tx_t3mgeodata_pi1[selection]=' + selection);
        //Gemeinden auslesen
        gemeinden = $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=gemeinden&tx_t3mgeodata_pi1[selection]=' + selection,
            type: 'GET',
            timeout: 11000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! Gemeinden');
            },
            success: function (json) {
                var output = '<option value="0">bitte w&auml;hlen...</option>\n';
                for (p in json) {

                    if ((json[p].name != '') && (json[p].name != null)) {
                        output += '<option id="' + json[p].fileid + '" value="' + json[p].fileid + '\">' + json[p].name + '</option>\n';
                    }

                }

                hideLoadingText(tempFile);

                $('#tx_mailform_input-item-2001-FRY074JNW').html(output);

                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1');

                if ($('#firstCall').val() != '1') {

                    $("#tx_mailform_input-item-2001-FRY074JNW option").each(function () {

                        // aktuelle Gemeinde selektieren
                        if ($(this).attr("id") == $('#firstGemeinde').val()) {
                            var X = $(this); /* */
                            //setTimeout(function () {
                            X.attr("selected", "selected");

                            firstRadio = $('#firstRadio').val();
                            firstRadio = parseInt(firstRadio);
                            hideLoadingText(tempFile);
/*				if ( $global_count_gemeinde > 0 ) {
				    $global_count_gemeinde--;
				    switchedRadio(firstRadio);
				    }*/
                            //alert('call');
                            if ($('#tx_mailform_div-item-2001-FJU125UTG-0').is(":checked")) loadStrassen($('#firstGemeinde').val());
                            else loadParzellen($('#tx_mailform_input-item-2001-FRY074JNW').val());

/* },
				   10);*/
                        }

                    });

                }

            }
        });
    }

    function loadHausnummer() {

var dontShow =false;
        tempFile = showLoadingText('#tx_mailform_input-item-2001-FZG018JZI');
        disableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FFT801RXI|#tx_mailform_input-item-2001-FRY074JNW');

        //alert('tx_t3mgeodata_pi1[get]=hausnummern&tx_t3mgeodata_pi1[fileid]=' + $('#tx_mailform_input-item-2001-FRY074JNW').val() + '&tx_t3mgeodata_pi1[benannte]=' + $(this).val());
        $.ajax({
            url: ('geodaten.html'),
            data: 'tx_t3mgeodata_pi1[get]=hausnummern&tx_t3mgeodata_pi1[fileid]=' + $('#tx_mailform_input-item-2001-FRY074JNW').val() + '&tx_t3mgeodata_pi1[benannte]=' + $('#tx_mailform_input-item-2001-FFT801RXI').val(),
            type: 'GET',
            timeout: 9000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! strassen');
            },
            success: function (json) {
                var output = '<option value="0">bitte w&auml;hlen...</option>\n';
                for (p in json) {
                    output += '<option id="' + json[p].fileid + '\" value="' + json[p].fileid + '\">' + json[p].name + '</option>\n';
                }
                hideLoadingText(tempFile);
                if (json.length == 0) {
                    output = '<option value="0">keine vorhanden...</option>\n';
                    $('#tx_mailform_input-item-2001-FZG018JZI').attr('disabled', 'disabled');
			dontShow = true;

                }
                $('#tx_mailform_input-item-2001-FZG018JZI').html(output);
if(dontShow)
{
$('#tx_mailform_div-item-2001-FZG018JZI').css('display','none');
} 
else 
{
$('#tx_mailform_div-item-2001-FZG018JZI').show('display','block');
}
                fadeInFormparts('#tx_mailform_div-item-2001-FZG018JZI');

                if ($('#firstCall').val() != '1') {

                    //Läuft nicht im IE6
                    //$('#tx_mailform_input-item-2001-FFT801RXI').val($('#firstStrasse').val());
                    //---->FIX
                    //alert($('#firstHausnummer').val());
                    $("#tx_mailform_input-item-2001-FZG018JZI option").each(function () {

                        if ($(this).attr("id") == $('#firstHausnummer').val()) {

                            var X = $(this);
                            setTimeout(function () {
                                X.attr("selected", "selected");
                            }, 10);
                        }

                    });

                }

                enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FFT801RXI|#tx_mailform_input-item-2001-FRY074JNW|#tx_mailform_input-item-2001-FZG018JZI');

            }
        });
    }

    //Start
    //$(window).load(function() {
    $(document).ready(function () {
    $('.mailform-table-outer').css('display','table');
        $("input:text:first:visible").focus();

        if ($('#pagenr').val() == '4') {
            showGeb = new Array('#div-outer-id-3-0-6', '#div-outer-id-3-0-7', '#div-outer-id-3-1-7', '#div-outer-id-3-0-8', '#div-outer-id-3-1-8', '#div-outer-id-3-1-9', '#div-outer-id-3-0-9', '#geb_kom');
            if ($('#hasGebuehren').val() == "TRUE") {

                for (i in showGeb) {
                    showDiv(showGeb[i]);
                    $(showGeb[i]).css("display", "block");
                }
            } else {
                for (i in showGeb) {
                    hideDiv(showGeb[i]);
                    $(showGeb[i]).css("display", "none");
                }
            }

            //getUserData($('#tx_mailform_input-item-2001-FES861MED').val(), $('#tx_mailform_input-item-2001-FGG955MKM').val());
            if ($('#loginStatus').val() == '1') {
                fillUserData($('#tx_mailform_input-item-2001-FES861MED').val());
            } else {

                if ($('#tx_mailform_input-item-2001-FUY383LSR').val() == '3') {
                    clearUserData();
                }
            }

            if ($('#tx_mailform_input-item-2001-FES861MED').val() == '') {
                $('#tx_mailform_div-item-2001-FSR818CKB-0').attr('checked', 'checked');
            } else {
                $('#tx_mailform_div-item-2001-FSR818CKB').hide();
            }

            $(".tx_mailform_navi_nextpage").click(function () {
                previous = true;
            });

            $(".tx_mailform_navi_previouspage").click(function () {
                previous = false;
            });

            $('#tx_mailform_2001').submit(function () {
                if (previous == true) {
                    if (request == false) {
                        return checkRequiredFields(4);
                    } else {
                        return true;
                    }
                }
            });

            //$('#tx_mailform_2001').attr('onsubmit', 'return checkRequiredFields(4);' );
        }

        if ($('#pagenr').val() == '5') {

            showGeb = new Array('#tx_mailform_div-item-2001-FSO687NHF');
            if ($('#hasGebuehren').val() == "TRUE") {

                for (i in showGeb) {
                    showDiv(showGeb[i]);
                    $(showGeb[i]).css("display", "block");
                }
            } else {
                for (i in showGeb) {
                    hideDiv(showGeb[i]);
                    $(showGeb[i]).css("display", "none");
                }
            }

            $('#tx_mailform_div-item-2001-FOF379DUC-0').before('<span id="errorboxbutton"></span>')

            //DAPRgetPrice($('#tx_mailform_input-item-2001-FGG688DNP').val(), $('#tx_mailform_input-item-2001-FZU836DOZ').val());
            //Preisdetails Seite 5
            //DA $('#detailPrice').hide();
/*DA$('#showDetailPrice').click(function () {
                switchDetailPrice();
            });

            $('#showDetailPriceAbo').click(function () {
                switchDetailPrice();
            });

            $('#detailClose a').click(function () {
                switchDetailPrice();
            });*/

            $("#tx_mailform_input-item-2001-FXS920ZDP").click(function () {
                previous = true;

            });

            $(".tx_mailform_navi_previouspage").click(function () {
                previous = false;
            });

            $('#tx_mailform_2001').submit(function () {
                if (previous == true) {
                    //if (request==false) {
                    return checkRequiredFields(5);
                }
            });

        }

        if ($('#pagenr').val() == '2') {
            $(".tx_mailform_navi_nextpage").click(function () {
                previous = true;
            });

            $(".tx_mailform_navi_previouspage").click(function () {
                previous = false;
            });
            $('#tx_mailform_2001').submit(function () {
                if (previous == true) {
                    //if (request==false) {
                    return checkRequiredFields(2);
                }
            });
            if ($('#tx_mailform_input-item-2001-FYH842QDU').val() == '') {
                $('#tx_mailform_input-item-2001-FYH842QDU').val('0');
            }
            if ($('#tx_mailform_input-item-2001-FLK424SVF').val() == '') {
                $('#tx_mailform_input-item-2001-FLK424SVF').val('0');
            }
            if ($('#tx_mailform_input-item-2001-FSO743EST').val() == '') {
                $('#tx_mailform_input-item-2001-FSO743EST').val('0');
            }

            //Preisdetails Seite 2
            $('#showDetailPrice').hover(function () {
                $(this).attr('class', 'linkStyle');
            }, function () {
                $(this).attr('class', '');
            });

            $('#detailPrice').hide();
            $('#showDetailPrice').click(function () {
                switchDetailPrice();
            });

            $('#detailClose a').click(function () {
                switchDetailPrice();
            });

            xPos = $('#xPos').val();
            yPos = $('#yPos').val();

            getMapSource(0, 0, xPos, yPos, 0);

            $('#right-fast').click(function () {
                getMapSource(150, 0, xPos, yPos, 0);
            });
            $('#right-slow').click(function () {
                getMapSource(15, 0, xPos, yPos, 0);
            });
            $('#left-fast').click(function () {
                getMapSource(-150, 0, xPos, yPos, 0);
            });
            $('#left-slow').click(function () {
                getMapSource(-15, 0, xPos, yPos, 0);
            });
            $('#up-fast').click(function () {
                getMapSource(0, 150, xPos, yPos, 0);
            });

            $('#up-slow').click(function () {
                getMapSource(0, 15, xPos, yPos, 0);
            });

            $('#down-fast').click(function () {
                getMapSource(0, -150, xPos, yPos, 0);
            });

            $('#down-slow').click(function () {
                getMapSource(0, -15, xPos, yPos, 0);
            });

            $('#turnleft').click(function () {
                getMapSource(0, 0, xPos, yPos, 0.087266462599716);
            });

            $('#turnright').click(function () {
                getMapSource(0, 0, xPos, yPos, -0.087266462599716);
            });

            $('.mapbutton').click(function () {
                //loadMap = 1;
            });

        }

        tempFile = showLoadingText('#tx_mailform_input-item-2001-FRY074JNW');
        disableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1|#tx_mailform_input-item-2001-FOZ851MPD|#tx_mailform_input-item-2001-FFN021HSN');

        //Massstab/Format Felder
        $('#tx_mailform_input-item-2001-FOZ851MPD').html('<option value="0">nicht verfügbar</option>');
        $('#tx_mailform_input-item-2001-FFN021HSN').html('<option value="0">nicht verfügbar</option>');

        if ($('#pagenr').val() == '1') {
            hideDivs = new Array('#tx_mailform_div-item-2001-FCS404LMV', '#tx_mailform_div-item-2001-FLV387PCZ', '#tx_mailform_div-item-2001-FLY308FJE', '#tx_mailform_div-item-2001-FUJ580XLD');
            //Felder ausblenden
            for (i in hideDivs) {
                hideDiv(hideDivs[i]);
            }

            //Formular prüfen nach Änderung eines Inputs
/*		$('input').keyup( function() {

			if (checkRequiredFields(1)!=false) {

				$('.tx_mailform_navi_nextpage input').attr('style', 'color: #000; background: #D4D0C8;');
				$('.tx_mailform_navi_nextpage input').attr('disabled', false);

			}

		}); */

            //Formular prüfen nach Änderung eines Selects
/*	$('select').change( function() {

			if (checkRequiredFields(1)!=false) {

				$('.tx_mailform_navi_nextpage input').attr('style', 'color: #000; background: #D4D0C8;');
				$('.tx_mailform_navi_nextpage input').attr('disabled', false);
			}

		}); */

            //$('.tx_mailform_navi_nextpage input').attr('disabled', 'true');
            //$('.tx_mailform_navi_nextpage input').attr('style', 'color: #aaaaaa;');
            $('#tx_mailform_input-item-2001-FIX028KYN').focus(function () {
                if ($(this).val() == 'bitte manuell eingeben') {
                    $(this).val('');
                }
            });

            $('#tx_mailform_input-item-2001-FIX028KYN').keyup(function () {
                validateParzelle();
            });

            //Function für RequiredFields laden
            $(".tx_mailform_reset input[type='submit']").click(function () {
                previous = true;

            });

            $(".tx_mailform_navi_nextpage").click(function () {
                previous = false;
            });

            $('#tx_mailform_2001').submit(function () {
                if (previous == false) {
                    //if (request==false) {
                    return checkRequiredFields(1);
                }
            });

            //Gemeinden auslesen
            //enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1');
            if ($('#tx_mailform_div-item-2001-FJU125UTG-0').is(":checked")) loadGemeinde(0);
            else loadGemeinde(1);
            //switchedRadio(firstRadio);
            ///*
            //alert('gemeinden sosnt');
/*
            gemeinden = $.ajax({
                url: ('geodaten.html'),
                data: 'tx_t3mgeodata_pi1[get]=gemeinden',
                type: 'GET',
                timeout: 11000,
                dataType: 'json',
                error: function () {
                    //alert('Error loading json data! Gemeinden');
                },
                success: function (json) {

                    var output = '<option value="0">bitte w&auml;hlen...</option>\n';
                    for (p in json) {

                        if ((json[p].name != '') && (json[p].name != null)) {
                            output += '<option id="' + json[p].fileid + '" value="' + json[p].fileid + '\">' + json[p].name + '</option>\n';
                        }

                    }

                    hideLoadingText(tempFile);

                    $('#tx_mailform_input-item-2001-FRY074JNW').html(output);

                    enableFields('#tx_mailform_div-item-2001-FJU125UTG-0|#tx_mailform_div-item-2001-FJU125UTG-1');

                    if ($('#firstCall').val() != '1') {

                        //Funktioniert nicht im IE6
                        //$('#tx_mailform_input-item-2001-FRY074JNW').val($('#firstGemeinde').val());
                        // --->FIX
                        //setTimeout($('#tx_mailform_input-item-2001-FRY074JNW option[value='+ $('#firstGemeinde').val() +']').attr('selected',true),1);
                        //$('#tx_mailform_input-item-2001-FRY074JNW > option').attr({'selected':''}).filter('option[value=15]').attr({'selected':true });
                        $("#tx_mailform_input-item-2001-FRY074JNW option").each(function () {

                            if ($(this).attr("id") == $('#firstGemeinde').val()) {
                                var X = $(this);
                                setTimeout(function () {
                                    X.attr("selected", "selected")

                                    firstRadio = $('#firstRadio').val();
                                    firstRadio = parseInt(firstRadio);

                                    switchedRadio(firstRadio);
                                    loadParzellen($('#tx_mailform_input-item-2001-FRY074JNW').val());

                                },
                                10);
                            }

                        });
setTimeout("displayForm()",5000);
                        //loadStrassen($('#tx_mailform_input-item-2001-FRY074JNW').val());
                    }

                }
		});//*/
            $('#tx_mailform_input-item-2001-FRY074JNW').change(function () {
                loadParzellen($('#tx_mailform_input-item-2001-FRY074JNW').val());
            })

            displayForm();
            setTimeout("displayForm()", 500);

        }

        //Felder die beim Start ausgeblendet werden sollen
        hideFields = new Array('#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FZG018JZI', '#tx_mailform_div-item-2001-FIX028KYN');

        //Felder ausblenden
        for (i in hideFields) {
            hideFormparts(hideFields[i]);
        }

        if ($('#pagenr').val() == '1') {
            loadProdukte();
            displayForm();
        }

    });

    //Switch Parzelle/Adresse
    $(function () {
        $('#tx_mailform_div-item-2001-FJU125UTG-0').click(function () {
            address = 1;
            showDiv('#tx_mailform_div-item-2001-FFT801RXI');
            fadeInFormparts('#tx_mailform_div-item-2001-FFT801RXI');
            switchedRadio(0);
            displayForm();
        });

        $('#tx_mailform_div-item-2001-FJU125UTG-1').click(function () {
            address = 0;
            switchedRadio(1);
            hideFields = new Array('#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FZG018JZI');
            for (i in hideFields) {
                hideFormparts(hideFields[i]);
            }
            hideDiv('#tx_mailform_div-item-2001-FFT801RXI');

            displayForm();
        });

    });

    //Bei Gemeindeauswahl
    $(function () {
        $('#tx_mailform_input-item-2001-FRY074JNW').change(function () {
            if ($('#tx_mailform_input-item-2001-FZN923HJY').val() != 'dxf_pro_gemeinde') {

                if ($('#tx_mailform_div-item-2001-FJU125UTG-0').is(":checked")) {
                    //Strassen laden
                    loadStrassen($(this).val());
                } else {
                    //Parzellen laden
                    //loadParzellen($(this).val());
                    fadeInFormparts('#tx_mailform_div-item-2001-FIX028KYN');
                    showDiv('#tx_mailform_div-item-2001-FIX028KYN');
                    fadeOutFormparts('#tx_mailform_div-item-2001-FZG018JZI');
                    fadeOutFormparts('#tx_mailform_div-item-2001-FFT801RXI');
                }
            }
            displayForm();
        });

    });

    //Bei Strassenauswahl
    $(function () {
        $('#tx_mailform_input-item-2001-FFT801RXI').change(function () {

            loadHausnummer();
            displayForm();
        });

    });

    //Bei Produkteauswahl
    $(function () {

        $('#tx_mailform_input-item-2001-FZN923HJY').change(function () {
            switchedRadio(0);
            //Felder wieder aktivieren
            enableFields('#tx_mailform_div-item-2001-FCS404LMV|#tx_mailform_div-item-2001-FLV387PCZ|#tx_mailform_div-item-2001-FLY308FJE|#tx_mailform_input-item-2001-FUJ580XLD');

            /* DW EDIT */
            if ($(this).val() != '0') {
                loadFormate($('#tx_mailform_input-item-2001-FZN923HJY').val());
            } else {
                disableFields('#tx_mailform_input-item-2001-FOZ851MPD|#tx_mailform_input-item-2001-FFN021HSN');
                $('#tx_mailform_input-item-2001-FOZ851MPD').html('<option value="0">nicht verfügbar</option>');
                $('#tx_mailform_input-item-2001-FFN021HSN').html('<option value="0">nicht verfügbar</option>');
            }
            loadRightCol();
            displayForm();
        });

    });

    //Bei Format
    $(function () {
        $('#tx_mailform_input-item-2001-FFN021HSN').change(function () {
            if ($(this).val() != '0') {
                loadMassstab($('#tx_mailform_input-item-2001-FZN923HJY').val(), $('#tx_mailform_input-item-2001-FFN021HSN').val());
            }
            displayForm();
        });
    });

    //Lieferadresse
    $(function () {

        if (($('#tx_mailform_input-item-2001-FYQ099NLE').val() != '1') && ($('#tx_mailform_input-item-2001-FYQ099NLE').val() != '0')) {
            $('#tx_mailform_input-item-2001-FYQ099NLE').val('0');
        }

/* if ($('#tx_mailform_input-item-2001-FYQ099NLE').val() == '0') {
            //alert($('#tx_mailform_input-item-2001-FYQ099NLE').val());
            hideFormparts_new('#div-outer-id-3-0-4');
            hideFormparts_new('#div-outer-id-3-1-4');
        }*/
        //
        $('#tx_mailform_div-item-2001-FCB326WDN-0').click(function () {
            if ($('#tx_mailform_div-item-2001-FCB326WDN-0').is(":checked")) {

                $('#tx_mailform_input-item-2001-FYQ099NLE').val('0');

            } else {

                $('#tx_mailform_input-item-2001-FYQ099NLE').val('1');
            }
        });

        $('#agb-checkbox').change(function () {

            if ($('#agb-checkbox').is(":checked")) {
                enableFields('#tx_mailform_input-item-2001-FXS920ZDP');
            } else {
                //	disableFields('#tx_mailform_input-item-2001-FXS920ZDP');
            }
        });
    });

});
$(document).ready(function () {
    if ($('#pagenr').val() == '2') {
        /***
         *
         *Preis berechnen
         */
        reqok = 1;

        selection_formatierung = $("#selection_formatierung").val();
        selection_planart = $("#selection_planart").val();
        selection_anzahl = $('#ncopies').html();
        if (product == 'dxf_pro_gemeinde' || product == 'dxf_rahmen') {

            selection_format = 'dxf';
            format = 'dxf';
            selection_fileformat = 'DXF';
            selection_gemeinde = $('#yPos').val();
            $('#tx_mailform_input-item-2001-FLB301WJT').val($('#yPos').val());
        } else {
            selection_format = format;
            selection_fileformat = format;
        }
        username = $('#usrname').html();
        selection_scale = scale;

        //get prices
        $("#txtfile").html("<br /><br /><br /><br />Preis wird berechnet..<br /><br /><br /><br /><br />");
        price = $.ajax({
            url: 'fileadmin/scripts/prices.php',
            data: 'product=' + product + '&min=' + min + '&max=' + max + '&selection_fileformat=' + selection_fileformat + '&format=' + format + '&selection_formatierung=' + selection_formatierung + '&selection_gemeinde=' + selection_gemeinde + '&selection_format=' + selection_format + '&selection_scale=' + selection_scale + '&selection_planart=' + selection_planart + '&selection_anzahl=' + selection_anzahl + '&selection_polygon=' + selection_polygon + '&selection_formatorientation=' + selection_formatorientation + '&scale=' + scale + '&startX=' + newX + '&startY=' + newY + '&addT=' + newT + '&usrname=' + username,
            type: 'GET',
            timeout: 81000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! Preis');
            },
            success: function (json) {
                for (p in json) {
                    $("#npreis").html(json[p].price + " " + json[p].currency);
                    price = Math.round(json[p].price * mwst * 20) / 20;
                    price_string = price + (parseInt(price / 10) * 10 == price ? '0' : '');

                    $('#tx_mailform_input-item-2001-preis').val("CHF " + price_string);
                    $('#tx_mailform_input-item-2001-FMZ880BBC').val(json[p].gebuehrenoutput);
                    $("#txtfile").html(nl2br(json[p].msg));

                    $('#tx_mailform_input-item-2001-FMG674XTW').val(json[p].msg);
                }
            }
        });
        /**
         * Preis berechnen ende
         */
    }
});


$(function () {
    /**
     * Liegenschaft anzeigen bei dxf_rahmen und sit_bg
     */
    $('#tx_mailform_div-item-2001-FDJ154ZLY').slideUp('fast');
    if ($('#tx_mailform_input-item-2001-FQV503UMN').val() == 'sit_bg' || $('#tx_mailform_input-item-2001-FQV503UMN').val() == 'dxf_rahmen') {
        $('#tx_mailform_div-item-2001-FDJ154ZLY').slideDown('fast');
    }
    /**
     * Toggler für Gebührenmeldung
     */
    $('#tx_mailform_div-item-2001-FFF178KSL').slideUp("300");
    $('#tx_mailform_div-item-2001-FUB275EWT').slideUp("300"); //2
    $('#tx_mailform_div-item-2001-FOF803YUC').slideUp("300"); //3
    $('#tx_mailform_div-item-2001-FVV374ZCC').slideUp("300"); //3
    $('#tx_mailform_div-item-2001-FQX910TLC').slideUp("300"); //3
    $('#tx_mailform_div-item-2001-FQL631HST').slideUp("300"); //3
    $('#tx_mailform_div-item-2001-FNJ119JOC').slideUp("300"); //4
    $('#tx_mailform_div-item-2001-f4_zweck_andere').slideUp("300"); //4
    $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');
    /**
     * Nr1
     */
    $('#tx_mailform_div-item-2001-FWG713MNV-0').click(function () {
        $('#tx_mailform_div-item-2001-FFF178KSL').slideDown("300"); //1
        $('#tx_mailform_div-item-2001-FUB275EWT').slideUp("300"); //2
        $('#tx_mailform_div-item-2001-FOF803YUC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FVV374ZCC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQX910TLC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQL631HST').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FNJ119JOC').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');

    });
    /**
     * Nr2
     */
    $('#tx_mailform_div-item-2001-FSS917EJY-0').click(function () {
        $('#tx_mailform_div-item-2001-FFF178KSL').slideUp("300");
        $('#tx_mailform_div-item-2001-FUB275EWT').slideDown("300");
        $('#tx_mailform_div-item-2001-FOF803YUC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FVV374ZCC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQX910TLC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQL631HST').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FNJ119JOC').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');
    });

    /**
     * Nr3
     */
    $('#tx_mailform_div-item-2001-FUR553GXC-0').click(function () {
        $('#tx_mailform_div-item-2001-FFF178KSL').slideUp("300"); //1
        $('#tx_mailform_div-item-2001-FUB275EWT').slideUp("300"); //2
        $('#tx_mailform_div-item-2001-FOF803YUC').slideDown("300"); //3
        $('#tx_mailform_div-item-2001-FVV374ZCC').slideDown("300"); //3
        $('#tx_mailform_div-item-2001-FQX910TLC').slideDown("300"); //3
        $('#tx_mailform_div-item-2001-FQL631HST').slideDown("300"); //3
        $('#tx_mailform_div-item-2001-FNJ119JOC').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere').slideUp("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');
    });

    /**
     * Nr4
     */
    $('#tx_mailform_div-item-2001-FPG754LJE-0').click(function () {
        $('#tx_mailform_div-item-2001-FFF178KSL').slideUp("300"); //1
        $('#tx_mailform_div-item-2001-FUB275EWT').slideUp("300"); //2
        $('#tx_mailform_div-item-2001-FOF803YUC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FVV374ZCC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQX910TLC').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FQL631HST').slideUp("300"); //3
        $('#tx_mailform_div-item-2001-FNJ119JOC').slideDown("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere').slideDown("300"); //4
        $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');


    });
    /**
     * zweck_andere gewählt
     */
    $('#tx_mailform_input-item-2001-FNJ119JOC').change(function () {
        if ($('#tx_mailform_input-item-2001-FNJ119JOC').val() == 'andere') {
            $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideDown('fast');
        } else {
            $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');
        }
    });
    /**
     * Toggler for page 4
     */
    /**
     * Wenn Bestelladresse geklickt
     */
    $('#div-outer-id-3-0-4').slideUp("300"); //Rechnungs links
    $('#div-outer-id-3-1-4').slideUp("300"); //Rechnungs rechts
    $('#div-outer-id-3-0-7').slideUp("300"); //Gebühren
    $('#div-outer-id-3-1-7').slideUp("300"); //Gebühren
    $('#div-outer-id-3-0-8').slideUp("300"); //Gebühren
    $('#div-outer-id-3-1-8').slideUp("300"); //Gebühren
    $('#div-outer-id-3-0-9').slideUp("300"); //Gebühren
    $('#div-outer-id-3-1-9').slideUp("300"); //Gebühren
    $('#tx_mailform_div-item-2001-FYB944LLX').click(function () {
        $('#div-outer-id-3-0-2').slideDown("300"); //Liefer links
        $('#div-outer-id-3-1-2').slideDown("300"); //Liefer rechts
        $('#div-outer-id-3-0-4').slideUp("300"); //Rechnungs links
        $('#div-outer-id-3-1-4').slideUp("300"); //Rechnungs rechts
        $('#div-outer-id-3-0-7').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-7').slideUp("300"); //Gebühren
        $('#div-outer-id-3-0-8').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-8').slideUp("300"); //Gebühren
        $('#div-outer-id-3-0-9').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-9').slideUp("300"); //Gebühren
    });
    /**
     * Wenn Rechnungs geklickt
     */

    $('#tx_mailform_div-item-2001-FTB671DKF').click(function () {
        $('#div-outer-id-3-0-4').slideDown("300"); //Rechnungs links
        $('#div-outer-id-3-1-4').slideDown("300"); //Rechnungs rechts
        $('#div-outer-id-3-0-2').slideUp("300"); //Liefer links
        $('#div-outer-id-3-1-2').slideUp("300"); //Liefer rechts
        $('#div-outer-id-3-0-7').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-7').slideUp("300"); //Gebühren
        $('#div-outer-id-3-0-8').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-8').slideUp("300"); //Gebühren
        $('#div-outer-id-3-0-9').slideUp("300"); //Gebühren
        $('#div-outer-id-3-1-9').slideUp("300"); //Gebühren
    });
    /**
     * Wenn Liefer geklickt
     */

    $('#tx_mailform_div-item-2001-FDB605NSB').click(function () {
        $('#div-outer-id-3-0-2').slideUp("300"); //Liefer links
        $('#div-outer-id-3-1-2').slideUp("300"); //Liefer rechts
        $('#div-outer-id-3-0-4').slideUp("300"); //Rechnungs links
        $('#div-outer-id-3-1-4').slideUp("300"); //Rechnungs rechts
        $('#div-outer-id-3-0-7').slideDown("300"); //Gebühren
        $('#div-outer-id-3-1-7').slideDown("300"); //Gebühren
        $('#div-outer-id-3-0-8').slideDown("300"); //Gebühren
        $('#div-outer-id-3-1-8').slideDown("300"); //Gebühren
        $('#div-outer-id-3-0-9').slideDown("300"); //Gebühren
        $('#div-outer-id-3-1-9').slideDown("300"); //Gebühren








        switch ($("#tx_mailform_input-item-2001-FOF729MJH").val()) {
        case 'f1':
            $('#tx_mailform_div-item-2001-FWG713MNV-0').attr('checked', 'checked');

            $('#tx_mailform_div-item-2001-FFF178KSL').css("display", "block"); //1
            $('#tx_mailform_div-item-2001-FUB275EWT').css("display", "none"); //2
            $('#tx_mailform_div-item-2001-FOF803YUC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FVV374ZCC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQX910TLC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQL631HST').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FNJ119JOC').css("display", "none"); //4
            $('#tx_mailform_div-item-2001-f4_zweck_andere').css("display", "none"); //4
            break;
        case 'f2':
            $('#tx_mailform_div-item-2001-FSS917EJY-0').attr('checked', 'checked');
            $('#tx_mailform_div-item-2001-FFF178KSL').css("display", "none");
            $('#tx_mailform_div-item-2001-FUB275EWT').css("display", "block");
            $('#tx_mailform_div-item-2001-FOF803YUC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FVV374ZCC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQX910TLC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQL631HST').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FNJ119JOC').css("display", "none"); //4
            $('#tx_mailform_div-item-2001-f4_zweck_andere').css("display", "none"); //4
            break;
        case 'f3':
            $('#tx_mailform_div-item-2001-FUR553GXC-0').attr('checked', 'checked');
            $('#tx_mailform_div-item-2001-FFF178KSL').css("display", "none"); //1
            $('#tx_mailform_div-item-2001-FUB275EWT').css("display", "none"); //2
            $('#tx_mailform_div-item-2001-FOF803YUC').css("display", "block"); //3
            $('#tx_mailform_div-item-2001-FVV374ZCC').css("display", "block"); //3
            $('#tx_mailform_div-item-2001-FQX910TLC').css("display", "block"); //3
            $('#tx_mailform_div-item-2001-FQL631HST').css("display", "block"); //3
            $('#tx_mailform_div-item-2001-FNJ119JOC').css("display", "none"); //4
            $('#tx_mailform_div-item-2001-f4_zweck_andere').css("display", "none"); //4
            break;
        case 'f4':
            $('#tx_mailform_div-item-2001-FPG754LJE-0').attr('checked', 'checked');
            $('#tx_mailform_div-item-2001-FFF178KSL').css("display", "none"); //1
            $('#tx_mailform_div-item-2001-FUB275EWT').css("display", "none"); //2
            $('#tx_mailform_div-item-2001-FOF803YUC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FVV374ZCC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQX910TLC').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FQL631HST').css("display", "none"); //3
            $('#tx_mailform_div-item-2001-FNJ119JOC').css("display", "block"); //4
            $('#tx_mailform_div-item-2001-f4_zweck_andere').css("display", "block"); //4
            if ($('#tx_mailform_input-item-2001-FNJ119JOC').val() == 'andere') {
                $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideDown('fast');
            } else {
                $('#tx_mailform_div-item-2001-f4_zweck_andere_text').slideUp('fast');
            }
            break;

        }







    });

    /**
     * Preis neu berechnen
     */

    $("#calcPrice").click(function () {
        reqok = 1;
        selection_formatierung = $("#selection_formatierung").val();
        selection_planart = $("#selection_planart").val();
        selection_anzahl = $('#ncopies').html();
        if (product == 'dxf_pro_gemeinde' || product == 'dxf_rahmen') {
            selection_format = 'dxf';
            format = 'dxf';
            selection_fileformat = 'DXF';
            selection_gemeinde = $('#yPos').val();
            $('#tx_mailform_input-item-2001-FLB301WJT').val($('#yPos').val());
        } else {
            selection_format = format;
            selection_fileformat = format;
        }
        username = $('#usrname').html();
        selection_scale = scale;


        //get prices
        $("#txtfile").html("<br /><br /><br /><br />Preis wird berechnet..<br /><br /><br /><br /><br />");
        price = $.ajax({
            url: 'fileadmin/scripts/prices.php',
            data: 'product=' + product + '&min=' + min + '&max=' + max + '&selection_fileformat=' + selection_fileformat + '&format=' + format + '&selection_formatierung=' + selection_formatierung + '&selection_gemeinde=' + selection_gemeinde + '&selection_format=' + selection_format + '&selection_scale=' + selection_scale + '&selection_planart=' + selection_planart + '&selection_anzahl=' + selection_anzahl + '&selection_polygon=' + selection_polygon + '&selection_formatorientation=' + selection_formatorientation + '&scale=' + scale + '&startX=' + newX + '&startY=' + newY + '&addT=' + newT + '&usrname=' + username,
            type: 'GET',
            timeout: 81000,
            dataType: 'json',
            error: function () {
                //alert('Error loading json data! Preis');
            },
            success: function (json) {
                for (p in json) {
                    $("#npreis").html(json[p].price + " " + json[p].currency);
                    price = Math.round(json[p].price * mwst * 20) / 20;
                    price_string = price + (parseInt(price / 10) * 10 == price ? '0' : '');
                    $('#tx_mailform_input-item-2001-preis').val("CHF " + price_string);
                    $('#tx_mailform_input-item-2001-FMZ880BBC').val(json[p].gebuehrenoutput);
                    $("#txtfile").html(nl2br(json[p].msg));

                    $('#tx_mailform_input-item-2001-FMG674XTW').val(json[p].msg);
                }
            }
        });
    });
    /**
     *Hand darstellen bei Hover
     */
    $("#calcPrice").hover(

    function () {
        $(this).css("cursor", "pointer");
    }, function () {
        $(this).css("cursor", "auto");
    });
    $('#tx_mailform_div-item-2001-FWG713MNV-0').click(function () {
        $('#tx_mailform_input-item-2001-FOF729MJH').val("f1");
    });
    $('#tx_mailform_div-item-2001-FSS917EJY-0').click(

    function () {
        $('#tx_mailform_input-item-2001-FOF729MJH').val("f2");
    });
    $('#tx_mailform_div-item-2001-FUR553GXC-0').click(

    function () {
        $('#tx_mailform_input-item-2001-FOF729MJH').val("f3");
    });
    $('#tx_mailform_div-item-2001-FPG754LJE-0').click(

    function () {
        $('#tx_mailform_input-item-2001-FOF729MJH').val("f4");
    });
});
/**
 * This Function displays the correct objects of the form. it uses hideDiv and showDiv to change the (css) display state.
 * Felder:
 * 0. Produkte: tx_mailform_div-item-2001-FZN923HJY
 * 1. Formate: tx_mailform_div-item-2001-FFN021HSN
 * 2. Massstab: tx_mailform_div-item-2001-FOZ851MPD
 * 3. Label Frage: tx_mailform_div-item-2001-FCK142FBP
 * 4. Adresse/Parzelle: tx_mailform_div-item-2001-FJU125UTG
 * 5. Gemeinde: tx_mailform_div-item-2001-FRY074JNW
 * 6. Parzelle: tx_mailform_div-item-2001-FIX028KYN
 * 7. Strasse: tx_mailform_div-item-2001-FFT801RXI
 * 8. Hausnummer: tx_mailform_div-item-2001-FZG018JZI
 * 9.DXF Formatierung: tx_mailform_div-item-2001-FCS404LMV
 * 10.Planart DXF: tx_mailform_div-item-2001-FLV387PCZ
 * 11.Planart Sit: tx_mailform_div-item-2001-FLY308FJE
 * 12.Anzahl Kopien: tx_mailform_div-item-2001-FUJ580XLD
 */

function displayForm() {
    div = new Array('#tx_mailform_div-item-2001-FZN923HJY', '#tx_mailform_div-item-2001-FFN021HSN', '#tx_mailform_div-item-2001-FOZ851MPD', '#tx_mailform_div-item-2001-FCK142FBP', '#tx_mailform_div-item-2001-FJU125UTG', '#tx_mailform_div-item-2001-FRY074JNW', '#tx_mailform_div-item-2001-FIX028KYN', '#tx_mailform_div-item-2001-FFT801RXI', '#tx_mailform_div-item-2001-FZG018JZI', '#tx_mailform_div-item-2001-FCS404LMV', '#tx_mailform_div-item-2001-FLV387PCZ', '#tx_mailform_div-item-2001-FLY308FJE', '#tx_mailform_div-item-2001-FUJ580XLD');
    feld = new Array('#tx_mailform_input-item-2001-FZN923HJY', '#tx_mailform_input-item-2001-FFN021HSN', '#tx_mailform_input-item-2001-FOZ851MPD', '#tx_mailform_input-item-2001-FCK142FBP', '#tx_mailform_input-item-2001-FJU125UTG', '#tx_mailform_input-item-2001-FRY074JNW', '#tx_mailform_input-item-2001-FIX028KYN', '#tx_mailform_input-item-2001-FFT801RXI', '#tx_mailform_input-item-2001-FZG018JZI', '#tx_mailform_input-item-2001-FCS404LMV', '#tx_mailform_input-item-2001-FLV387PCZ', '#tx_mailform_input-item-2001-FLY308FJE', '#tx_mailform_input-item-2001-FUJ580XLD');
    if ($(feld[0]).val() != null) var address = $('input', 'div#tx_mailform_div-item-2001-FJU125UTG')[0].checked;
    hideDivs = new Array();
    showDivs = new Array();
    pausecomp(20);
//alert($(feld[0]).val());
    switch ($(feld[0]).val()) {

    case 'dxf_pro_gemeinde':
        hideDivs = new Array(div[1], div[2], div[3], div[4], div[6], div[7], div[8], div[10], div[11], div[12]);
        showDivs = new Array(div[0], div[5], div[9]);
        break;

    case 'dxf_rahmen':

        if (address == true) { //Nach Adresse
            if ($(feld[5]).val() != 0) { // Gemeinde nicht leer
                if ($(feld[7]).val() != 0 && $(feld[7]).val() != null) { //Strasse nicht leer
                    hideDivs = new Array(div[6], div[11], div[12]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7], div[8], div[9], div[10]);

                } else { // Strasse leer
                    hideDivs = new Array(div[6], div[8], div[11], div[12]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7], div[9], div[10]);
                }
            } else { //Gemeinde leer
                hideDivs = new Array(div[6], div[7], div[8], div[11], div[12]);
                showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[9], div[10]);
            }
        } else { //Parzelle
            hideDivs = new Array(div[7], div[8], div[11], div[12]);
            showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[6], div[9], div[10]);
        }
        break;

    case 'sit_bg':
        if (address == true) { //Nach Adresse
            if ($(feld[5]).val() != 0) { // Gemeinde nicht leer
                if ($(feld[7]).val() != 0 && $(feld[7]).val() != null) { //Strasse nicht leer
                    hideDivs = new Array(div[6], div[9], div[10]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7], div[8], div[11], div[12]);

                } else { // Strasse leer
                    hideDivs = new Array(div[6], div[8], div[9], div[10]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7], div[11], div[12]);
                }
            } else { //Gemeinde leer
                hideDivs = new Array(div[6], div[7], div[8], div[9], div[10]);
                showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[11], div[12]);
            }
        } else { //Parzelle
            hideDivs = new Array(div[7], div[8], div[9], div[10]);
            showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[6], div[11], div[12]);
        }
        break;

    case 'sitshop':
        if (address == true) { //Nach Adresse
            if ($(feld[5]).val() != 0) { // Gemeinde nicht leer
                if ($(feld[7]).val() != 0 && $(feld[7]).val() != null) { //Strasse nicht leer
                    hideDivs = new Array(div[6], div[9], div[10], div[11], div[12]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7], div[8]);

                } else { // Strasse leer
                    hideDivs = new Array(div[6], div[8], div[9], div[10], div[11], div[12]);
                    showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[7]);
                }
            } else { //Gemeinde leer
                hideDivs = new Array(div[6], div[7], div[8], div[9], div[10], div[11], div[12]);
                showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5]);
            }
        } else { //Parzelle
            hideDivs = new Array(div[7], div[8], div[9], div[10], div[11], div[12]);
            showDivs = new Array(div[0], div[1], div[2], div[3], div[4], div[5], div[6]);
        }
        break;
    default:
        hideDivs = new Array(div[6], div[11], div[12], div[1], div[2], div[3], div[4], div[5], div[7], div[8], div[9], div[10]);
        showDivs = new Array(div[0]);
        break;

    }
    /**
     *Ausblenden
     */
    for (i in hideDivs) {
        hideDiv(hideDivs[i]);
    }

    for (i in showDivs) {
        showDiv(showDivs[i]);
        
 }
}

/**
 * Hide the whole div
 */

function hideDiv(id) {
    $(id).hide();
}

function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do {
        curDate = new Date();
    }
    while (curDate - date < millis);
}

function nl2br(str) {
    if (typeof(str) == "string") return str.replace(/(\r\n)|(\n\r)|\r|\n/g, "<BR>");
    else return str;
}
/**
 * Show the whole div
 */

function showDiv(id) {
    $(id).fadeIn("fast");
}

