var leer = '---------';
var sonstige = 'Sonstige';

function isInComboBox(wert, cBox) {
        var test = false;
        for (var j = 1; j<= cBox.length-1; j++) {       // Achtung: Ich beginne hier von 1 anstatt von 0 zu zaehlen, weil der erste Eintrag bei mir der leere '---' Eintrag ist
                if (cBox.options[j].value == wert) {
                        test = true;
                        break;
                }
        }
        return test;
}

var msgSonstigeDF = 'Bitte tragen Sie zusaetzliche Informationen\nzu Ihrem Dachfenster in die Hinweisbox ein!\n(Hersteller, Produkt, Typ, ...)';

function setzeMasse(opt_changed, override) {
// opt_change: was wurde geaendert? 0: Init - 1: Hersteller - 2: Produkt - 3: Typ
// override: gibt an, ob andere Daten ueberschrieben werden sollen - zum Beispiel beim Initialisieren der Seite, wenn diese mit Parametern geladen wurde

		var modell = document.getElementById('konfigurator').modell[radioSelectedIndex(document.getElementById('konfigurator').modell)].value;
		var dachmodell = document.getElementById('konfigurator').dachmodell[radioSelectedIndex(document.getElementById('konfigurator').dachmodell)].value;


		if (opt_changed >= 1) {
				d_hersteller = document.getElementById('konfigurator').d_hersteller.options[document.getElementById('konfigurator').d_hersteller.selectedIndex].value;
		}
		if (opt_changed >= 2) {
				d_produkt = document.getElementById('konfigurator').d_produkt.options[document.getElementById('konfigurator').d_produkt.selectedIndex].value;
		}
		if (opt_changed >= 3) {
				d_typ = document.getElementById('konfigurator').d_typ.options[document.getElementById('konfigurator').d_typ.selectedIndex].value;
		}

		if (opt_changed == 3 && d_typ != sonstige && d_typ != '') {
				document.getElementById('dach_mass_1').style.display = 'none';
				document.getElementById('dach_mass_2').style.display = 'none';
				document.getElementById('dach_mass_3').style.display = 'none';
				document.getElementById('auswahl_falz').style.display = 'none';

				document.getElementById('hinweis_grossesorgfalt').style.display = 'none';
				document.getElementById('hinweis_bestellmasse_dachfensterdaten').style.display = 'block';
				document.getElementById('hinweis_bestellmasse_dachfensterdaten').innerHTML = 'Rollo für Dachfenster<br><b>' + d_hersteller + ' ' + d_produkt + ' ' + d_typ + '</b>';
				document.getElementById('btn_messen').style.display = 'none';
				document.getElementById('btn_dftypbestimmung').style.display = 'none';
		} else {
				document.getElementById('dach_mass_1').style.display = 'block';
				document.getElementById('dach_mass_2').style.display = 'block';
				document.getElementById('dach_mass_3').style.display = 'block';
				document.getElementById('auswahl_falz').style.display = 'block';
				document.getElementById('hinweis_grossesorgfalt').style.display = 'block';
				document.getElementById('hinweis_bestellmasse_dachfensterdaten').style.display = 'none';
				document.getElementById('btn_messen').style.display = 'block';
				document.getElementById('btn_dftypbestimmung').style.display = 'block';
		}

        if (opt_changed == 0) {
                document.getElementById('konfigurator').d_hersteller.length = 0;
                document.getElementById('konfigurator').d_hersteller.options[0] = new Option(leer, '');
                document.getElementById('konfigurator').d_produkt.length = 0;
                document.getElementById('konfigurator').d_produkt.options[0] = new Option(leer, '');
				document.getElementById('konfigurator').d_produkt.disabled = true;
                document.getElementById('konfigurator').d_typ.length = 0;
                document.getElementById('konfigurator').d_typ.options[0] = new Option(leer, '');
				document.getElementById('konfigurator').d_typ.disabled = true;
				ajax_request_dachfensterdaten(modell, dachmodell, opt_changed, '', '', '');

        }

        if (opt_changed == 1) {
				d_hersteller = document.getElementById('konfigurator').d_hersteller.options[document.getElementById('konfigurator').d_hersteller.selectedIndex].value;

				if (override == false) {
						d_produkt = '';
						d_typ = '';
				}

				document.getElementById('konfigurator').d_produkt.length = 0;
				document.getElementById('konfigurator').d_produkt.options[0] = new Option(leer, '');
				
				document.getElementById('konfigurator').d_typ.length = 0;
				document.getElementById('konfigurator').d_typ.options[0] = new Option(leer, '');

				document.getElementById('konfigurator').d_typ.disabled = true;
				
				hideHint('fluegeltyp_ab');
				hideHint('fluegeltyp_aby');

				if (d_hersteller == '') {
						document.getElementById('konfigurator').d_produkt.disabled = true;
                } else if (d_hersteller == sonstige) {
						document.getElementById('konfigurator').d_produkt.disabled = true;
						if (override == false) {
								alert(msgSonstigeDF);
						}
                } else {
						document.getElementById('konfigurator').d_produkt.disabled = false;
						ajax_request_dachfensterdaten(modell, dachmodell, opt_changed, d_hersteller, d_produkt, d_typ);
 				}

        }

        if (opt_changed == 2) {
				d_produkt = document.getElementById('konfigurator').d_produkt.options[document.getElementById('konfigurator').d_produkt.selectedIndex].value;
                document.getElementById('konfigurator').d_typ.length = 0;
                document.getElementById('konfigurator').d_typ.options[document.getElementById('konfigurator').d_typ.length] = new Option(leer, '');
				
				if (override == false) {
						d_typ = '';
				};

				if (d_produkt == '') {
						hideHints();
						document.getElementById('konfigurator').d_typ.disabled = true;
				} else if (d_produkt == sonstige) {
						hideHints();
						document.getElementById('konfigurator').d_typ.disabled = true;
						if (override == false) {
								alert(msgSonstigeDF);
						}
				} else {
						updateHintFluegelTyp();
						document.getElementById('konfigurator').d_typ.disabled = false;
						ajax_request_dachfensterdaten(modell, dachmodell, opt_changed, d_hersteller, d_produkt, d_typ);
				}

        }

        if (opt_changed == 3) {
				d_typ = document.getElementById('konfigurator').d_typ.options[document.getElementById('konfigurator').d_typ.selectedIndex].value;
				if (d_typ == sonstige) {
						if (override == false) {
								alert(msgSonstigeDF);
						}

				} else if (d_typ != '') {
				
						if ( (document.getElementById('konfigurator').dachmodell[radioSelectedIndex(document.getElementById('konfigurator').dachmodell)].value * 1 == EXCLUSIV) && (d_hersteller == 'Velux' || d_hersteller == 'Velux®') && (d_typ == '102' || d_typ == '104' || d_typ == '204' || d_typ == '206') ) {

								alert('Das Rollomodell \'Exklusiv\' passt nicht auf \'alte\' Velux-Dachfenster Nr. 102, 104, 204 und 206!');
								document.getElementById('konfigurator').d_typ[radioIndexByValue(document.getElementById('konfigurator').d_typ, leer)].selected = true;

								d_typ = leer;
						
						} else {
				
								ajax_request_dachfensterdaten(modell, dachmodell, opt_changed, d_hersteller, d_produkt, d_typ);
						
						}
                }
        }


}

