var leer = '---------';
var sonstige = 'Sonstige';
var aHersteller, aProdukt, aTyp;

/*
function isMglDHersteller(hersteller) {
		var ismgl = false;
		if (hersteller == leer || hersteller == sonstige) {
				ismgl = true;
		} else {
				for (var i = 0; i <= aHersteller.length - 1; i++) {		// geht alle Dachfensterhersteller durch
						if (aHersteller[i][0] == hersteller && aHersteller[i][1] > 0) {		// und sagt, ob fuer den gegebenen Hersteller die Produktion moeglich ist (ob ca_cu_no und ca_cs_no passt)
								ismgl = true;
								break;
						}
				}
		}
		return ismgl;
}

function isMglDProdukt(produkt) {
		var ismgl = false;
		if (produkt == leer || produkt == sonstige) {
				ismgl = true
		} else {
				for (var i = 0; i <= aProdukt.length - 1; i++) {
						if (aProdukt[i][0] == produkt && aProdukt[i][1] > 0) {
								ismgl = true;
								break;
						}
				}
		}
		return ismgl;
}

function isMglDTyp(typ) {
		var ismgl = false;
		if (typ == leer || typ == sonstige) {
				ismgl = true
		} else {
				for (var i = 0; i <= aTyp.length - 1; i++) {
						if (aTyp[i][0] == typ && aTyp[i][1] > 0) {
								ismgl = true;
								break;
						}
				}
		}
		return ismgl;
}

function nichtmoeglich_dachfenster(modell, opt, df) {

		document.getElementById('na_df').style.display = 'block'; // fuer den IE 6/quirks Bug
																	document.getElementById('table_bug_ie').style.position = 'static';

		var btn = '';
		var stoffe = '';

		var ok_cu_no = 1;
		var ok_cs_no = 1;
		
		if (opt == 1) {
				for (var i = 0; i <= aHersteller.length - 1; i++) {
						if (aHersteller[i][0] == df) {
								ok_cu_no = aHersteller[i][2];
								ok_cs_no = aHersteller[i][3];
								break;
						}
				}
		} else if (opt == 2) {
				for (var i = 0; i <= aProdukt.length - 1; i++) {
						if (aProdukt[i][0] == df) {
								ok_cu_no = aProdukt[i][2];
								ok_cs_no = aProdukt[i][3];
								break;
						}
				}
		} else if (opt == 3) {
				for (var i = 0; i <= aTyp.length - 1; i++) {
						if (aTyp[i][0] == df) {
								ok_cu_no = aTyp[i][2];
								ok_cs_no = aTyp[i][3];
								break;
						}
				}
		}
		
		if (ok_cu_no == 1 && ok_cs_no == 1) {		// falls beides fuer sich, aber nicht in kombination, in ordnung ist
				ok_cu_no = 0;
				ok_cs_no = 0;
		}
		
		if (ok_cu_no == 0) {
				btn = btn + '<div style="text-align: center; margin: 14px;">Wählen Sie ein anderes <b>passendes Plissee-Modell</b>:</div>';
				if (modell == DACH_EINFACH || modell == DACH_FREI || modell == DACH_DOPPEL) {

				} else {

				};
		}

		if (ok_cs_no == 0) {
				stoffe = stoffe + '<div style="text-align: center; margin: 14px;">Wählen Sie einen anderen <b>passenden Stoff</b>:</div>';
				stoffe = stoffe + '<div id="wahl2_stoff" class="wahl2_stoff" style="margin-top: 8px;">';
				stoffe = stoffe + '		...';
				stoffe = stoffe + '</div>';
				ajax_request_stoffex(getHersteller(document.forms.daten.pl_no));		// setzt innerHTML von id="wahl2_stoff"
		}

		var wahl = '';
		if (ok_cu_no == 0) {
				wahl = wahl + btn;
		}
		if (ok_cs_no == 0) {
				if (ok_cu_no == 0) {
						wahl = wahl + '<div style="margin-top: 16px; margin-bottom: 16px; font-weight: bold; text-align: center; font-size: 160%;">oder</div>';
				}
				wahl = wahl + stoffe;
		}
		
		document.getElementById('wahl2').innerHTML = wahl;

}
*/
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 * 1;
		// var cs_no = // System (Hersteller) Nummer

		var d_hersteller = leer;
		var d_produkt = leer;
		var d_typ = leer;

		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 != leer) {
				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('wahl_dachfenster_material').style.display = 'none';
				document.getElementById('hinweis_bestellmasse_fenstermasse').style.display = 'none';
				document.getElementById('hinweis_bestellmasse_dachfenstertyp').style.display = 'block';
				document.getElementById('hinweis_bestellmasse_dachfenstertyp').innerHTML = 'Jalousie für Dachfenster<br><b>' + d_hersteller + ' ' + d_produkt + ' ' + d_typ + '</b>';
				document.getElementById('btn_messen').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('wahl_dachfenster_material').style.display = 'block';
				document.getElementById('hinweis_bestellmasse_fenstermasse').style.display = 'block';
				document.getElementById('hinweis_bestellmasse_dachfenstertyp').style.display = 'none';
				document.getElementById('btn_messen').style.display = 'block';
		}

        if (opt_changed == 0) {
				
                document.getElementById('konfigurator').d_hersteller.length = 0;
                document.getElementById('konfigurator').d_hersteller.options[0] = new Option(leer, leer);
				document.getElementById('konfigurator').d_hersteller.disabled = false;
                document.getElementById('konfigurator').d_produkt.length = 0;
                document.getElementById('konfigurator').d_produkt.options[0] = new Option(leer, 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, leer);
				document.getElementById('konfigurator').d_typ.disabled = true;
				ajax_request_dachfensterdaten(opt_changed, d_hersteller, d_produkt, d_typ);
		}

        if (opt_changed == 1) {

                document.getElementById('konfigurator').d_produkt.length = 0;
                document.getElementById('konfigurator').d_produkt.options[0] = new Option(leer, leer);
                document.getElementById('konfigurator').d_typ.length = 0;
                document.getElementById('konfigurator').d_typ.options[0] = new Option(leer, leer);

				hideHint('fluegeltyp_ab');
				hideHint('fluegeltyp_aby');

				//if (isMglDHersteller(d_hersteller) == false) {
				//		document.getElementById('konfigurator').produkt.disabled = true;
				//		nichtmoeglich_dachfenster(modell, opt_changed, d_hersteller);
				//} else
				if (d_hersteller == leer) {
						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(opt_changed, d_hersteller, d_produkt, d_typ);
				}

				document.getElementById('konfigurator').d_typ.disabled = true;
        }

        if (opt_changed == 2) {

                document.getElementById('konfigurator').d_typ.length = 0;
                document.getElementById('konfigurator').d_typ.options[document.getElementById('konfigurator').d_typ.length] = new Option(leer, leer);

				//if (isMglDProdukt(d_produkt) == false) {
				//		hideHints();
				//		document.getElementById('konfigurator').typ.disabled = true;
				//		nichtmoeglich_dachfenster(modell, opt_changed, d_produkt);
				//} else
				if (d_produkt == leer) {
						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(opt_changed, d_hersteller, d_produkt, d_typ);
				}

        }

        if (opt_changed == 3) {
				// if (isMglDTyp(d_typ) == false) {
				//		nichtmoeglich_dachfenster(modell, opt_changed, d_typ);
				//} else
				if (d_typ == sonstige) {
						if (override == false) {
								alert(msgSonstigeDF);
						}
				} else if (d_typ != leer) {
                        ajax_request_dachfensterdaten(opt_changed, d_hersteller, d_produkt, d_typ);
                }
        }

}

