
Event.observe(window, 'load',restrict);
var selectionBackup = new Array();
var selectionBackupValue = new Array();

function restrict() {

	
	if ($("productSelection_31") || $("productSelection_26")) {

		backupSelection_doit ($("productSelection_29"));
		backupSelection_doit ($("productSelection_26"));

		$("productSelection_31").observe("change", updateRestriction_broschuere);
		preproceecing["productSelection_31"] = true;
	 	$("productSelection_26").observe("change", updateRestriction_broschuere);
		preproceecing["productSelection_26"] = true;
		
		$("productSelection_29").observe("change", updateRestriction_broschuere);
		preproceecing["productSelection_29"] = true;
		
		updateRestriction_broschuere();


	}


	
	if ($("productSelection_39")) {
	
		backupSelection_doit ($("productSelection_40"));
		
	
		preproceecing["productSelection_39"] = true;
		$("productSelection_39").observe("change", updateRestriction_folder_einfach);
		preproceecing["productSelection_38"] = true;
		$("productSelection_38").observe("change", updateRestriction_folder_einfach);
		updateRestriction_folder_einfach();
		
	
	
	}

	if ($("productSelection_163")) {
	
		backupSelection_doit ($("productSelection_165"));
	
		preproceecing["productSelection_163"] = true;
		$("productSelection_163").observe("change", updateRestriction_folder_wickel);
		preproceecing["productSelection_164"] = true;
		$("productSelection_164").observe("change", updateRestriction_folder_wickel);
		updateRestriction_folder_wickel();
		
	
	
	}

	

}

function updateRestriction_folder_einfach() {

		if ($("productSelection_39").value == 100 || $("productSelection_39").value == 103 || $("productSelection_38").value == 98) {
		
			
			$("productSelection_40").options[0].selected = true;
			$("productSelection_40").options[1].selected = false;
			$("productSelection_40").options[2].selected = false;	
			$("productSelection_40").disabled = true;
			
		} else {
			$("productSelection_40").disabled = false;
		}
		reload(this);
}
function updateRestriction_folder_wickel() {

		if ($("productSelection_164").value == 397 || $("productSelection_164").value == 398 || $("productSelection_163").value == 395) {
		
			
			$("productSelection_165").options[0].selected = true;
			$("productSelection_165").options[1].selected = false;
			$("productSelection_165").options[2].selected = false;	
			$("productSelection_165").disabled = true;
			
		} else {
			$("productSelection_165").disabled = false;
		}
		reload(this);
}
function updateRestriction_broschuere() {

	var value = $("productSelection_31").value;
	
	/*
	hideOption($("productSelection_26"),65); //115g
	hideOption($("productSelection_26"),68); //115g
	hideOption($("productSelection_26"),66);  //135g
	hideOption($("productSelection_26"),69);  //135g	
	hideOption($("productSelection_26"),67);  //170g
	hideOption($("productSelection_26"),70);  //170g		
	hideOption($("productSelection_26"),185);  //200g	
	hideOption($("productSelection_26"),186);  //200g	
	*/

	showOption($("productSelection_26"),67);  //170g
	showOption($("productSelection_26"),70);  //170g
	
	hideOption($("productSelection_29"),413); //115g
	hideOption($("productSelection_29"),414); //115g
	hideOption($("productSelection_29"),76);  //135g
	hideOption($("productSelection_29"),79);  //135g	
	hideOption($("productSelection_29"),77);  //170g
	hideOption($("productSelection_29"),80);  //170g		
	hideOption($("productSelection_29"),417);  //200g	
	hideOption($("productSelection_29"),418);  //200g	
	hideOption($("productSelection_29"),78);  //250g	
	hideOption($("productSelection_29"),81);  //250g	
	hideOption($("productSelection_29"),187); //300g	
	hideOption($("productSelection_29"),188); //300g	
	
	
	
	
	if (value == 8) {
		/*
		bei 115g Inhalt 115g Umschlag
		bei 135g Inhalt 135g Umschlag
		bei 170g Inhalt 170g Umschlag
		bei 200g Inhalt 200g Umschlag
		*/
		if ($("productSelection_26").value == 65 || $("productSelection_26").value == 68) {
			showOption($("productSelection_29"), 413, false);
			showOption($("productSelection_29"), 414, false);
		
		}

		if ($("productSelection_26").value == 66 || $("productSelection_26").value == 69) {
			showOption($("productSelection_29"), 76, false);
			showOption($("productSelection_29"), 79, false);
		}
		if ($("productSelection_26").value == 67 || $("productSelection_26").value == 70) {
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
		}
		if ($("productSelection_26").value == 185 || $("productSelection_26").value == 186) {
			showOption($("productSelection_29"), 417, false);
			showOption($("productSelection_29"), 418, false);
		}


	} else if (value >= 12 && value <= 48) {
		/*
		bei 115g Inhalt 115g Umschlag
		170g Umschlag
		bei 135g Inhalt 135 bei 170g Inhalt 170g Umschlag
		250g Umschlag
		bei 200g Inhalt 200g Umschlag
		300g Umschlag
		*/
		
		if ($("productSelection_26").value == 65 || $("productSelection_26").value == 68) {
			showOption($("productSelection_29"), 413, false);
			showOption($("productSelection_29"), 414, false);
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
		}

		if ($("productSelection_26").value == 66 || $("productSelection_26").value == 69) {
			showOption($("productSelection_29"), 76, false);
			showOption($("productSelection_29"), 79, false);	
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
			
		}
		
		if ($("productSelection_26").value == 67 || $("productSelection_26").value == 70) {

			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
			showOption($("productSelection_29"), 78, false);
			showOption($("productSelection_29"), 81, false);	
		}

		if ($("productSelection_26").value == 185 || $("productSelection_26").value == 186) {

			showOption($("productSelection_29"), 187, false);
			showOption($("productSelection_29"), 188, false);
			showOption($("productSelection_29"), 417, false);
			showOption($("productSelection_29"), 418, false);			
		}
		
		
	} else  if (value >= 52 && value <= 64) {
		/*
		115g Inhalt => 115g Umschlag, 170g Umschlag
		135g Inhalt => 135g Umschlag, 170g Umschlag
		170g Inhalt => 170g Umschlag, 250g Umschlagg Umschlag
		*/
		
		if ($("productSelection_26").value == 65 || $("productSelection_26").value == 68) {
			showOption($("productSelection_29"), 413, false);
			showOption($("productSelection_29"), 414, false);
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
		}

		if ($("productSelection_26").value == 66 || $("productSelection_26").value == 69) {
			showOption($("productSelection_29"), 76, false);
			showOption($("productSelection_29"), 79, false);	
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
			
		}
		if ($("productSelection_26").value == 67 || $("productSelection_26").value == 70) {

			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
			showOption($("productSelection_29"), 78, false);
			showOption($("productSelection_29"), 81, false);		
		}	
		hideOption($("productSelection_26"),185);  //200g	
		hideOption($("productSelection_26"),186);  //200g		

	} else  if (value >= 68 && value <= 80) {
		/*
		Grammaturen wählbar sein:
		bei 115g Inhalt  115g Umschlag
		170g Umschlag
		bei 135g Inhalt 135g Umschlag
		170g Umschlag

		*/
		
		if ($("productSelection_26").value == 65 || $("productSelection_26").value == 68) {
			showOption($("productSelection_29"), 413, false);
			showOption($("productSelection_29"), 414, false);
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
		}

		if ($("productSelection_26").value == 66 || $("productSelection_26").value == 69) {
			showOption($("productSelection_29"), 76, false);
			showOption($("productSelection_29"), 79, false);	
			showOption($("productSelection_29"), 77, false);
			showOption($("productSelection_29"), 80, false);
			
		}
		
		hideOption($("productSelection_26"),185);  //200g	
		hideOption($("productSelection_26"),186);  //200g	
		hideOption($("productSelection_26"),67);  //170g
		hideOption($("productSelection_26"),70);  //170g		

	}
	
	hideOption($("productSelection_26"),185);  //200g	
	hideOption($("productSelection_26"),186);  //200g			
	
	
	$("productSelection_26").disabled =$("productSelection_31").value == "";
	$("productSelection_29").disabled =$("productSelection_31").value == "" ||  $("productSelection_26").value == "";
	
	
	refreshSelection($("productSelection_26"));
	refreshSelection($("productSelection_29"));	
	reload(this);
	
}


function hideOption (selection, id) {

	for (i=0;i<selectionBackup[selection.id].length;i++) {
		if (selectionBackup[selection.id][i].value == id) {
			selectionBackup[selection.id][i].disabled = true;
			return;
		}
	}
	
}
function showOption (selection, id, selected) {

	for (i=0;i<selectionBackup[selection.id].length;i++) {
		if (selectionBackup[selection.id][i].value == id) {
			selectionBackup[selection.id][i].disabled = false;
			return;
		}
	}
	/*
	for (i =0 ;i<selection.options.length;i++) {
		if (id == selection.options[i].value) {
			selection.options[i].style.display = "block";
			if (selected) selection.options[i].selected  = selected;
			break;
		}
	}*/

}

function backupSelection_doit (selection) {
	
	
	selectionBackup[selection.id] = new Array();
	
	for (i =0 ;i < selection.options.length;i++) {

		selectionBackup[selection.id][i] = new Object();
	
		selectionBackup[selection.id][i].text =  selection.options[i].text;
		selectionBackup[selection.id][i].value =  selection.options[i].value;	
		
	}	


}

function refreshSelection (selection, id) {
	var selected=false;
	var isSelected = false;
	for (i = selection.options.length-1 ;i>=0; i--) {
		if (selection.options[i].selected && !selected) {
		 	selected = selection.options[i].value;
			
		}
		selection.options[i] = null;
		
	}
	
	
	for (i=0;i<selectionBackup[selection.id].length;i++) {
		if (!selectionBackup[selection.id][i].disabled && (selectionBackup[selection.id][i].text != "--Bitte wählen--" || !selectionBackupValue[selection.id]))  {
			if (selected==selectionBackup[selection.id][i].value) {
				
					isSelected = true;	
					break;
			}
		}	
	
	}
	
	if (!isSelected)  {

		attributesSelected--;	
		selectionBackupValue[selection.id] = 0;
	}


	for (i=0;i<selectionBackup[selection.id].length;i++) {

		if (!selectionBackup[selection.id][i].disabled && (selectionBackup[selection.id][i].text != "--Bitte wählen--" || !selectionBackupValue[selection.id]))  {

			selection.options[selection.length] = new Option(selectionBackup[selection.id][i].text,selectionBackup[selection.id][i].value);
			if (selected==selectionBackup[selection.id][i].value) {
				selection.options[selection.length-1].selected = true;
				selectionBackupValue[selection.id] = selectionBackup[selection.id][i].value;
				isSelected = true;	
			}
		
		} 
								
	}	
}

