/* Toggle Lieferadresse */
function toggle_lieferadresse() {
	if ($("input[@name='lieferung_an_bildungseinrichtung']:checked").val() >> 0) {
		$("#wako_form_lieferadresse").show();
		$("#wako_form_rechnungsadresse").hide();
	} else {
		$("#wako_form_lieferadresse").hide();
		$("#wako_form_rechnungsadresse").show();
	}
}
function toggle_nachlassanspruch() {
	if ($("input[@name='wako_nachlassanspruch']:checked").val() == 1) {
		$("#nachlassanspruch_text").show();
	} else {
		$("#nachlassanspruch_text").hide();
	}
}
/* Toggle Lastschrift */
function toggle_lastschrift() {
	$("#wako_form_lastschrift").hide();
	$("#wako_form_kreditkarte").hide();
	$("#wako_form_paypal").hide();

	if ($("input[@name='wako_bezahltyp']:checked").val() == '3') {
		$("#wako_form_lastschrift").show();
	}
	if ($("input[@name='wako_bezahltyp']:checked").val() == '2') {
		$("#wako_form_kreditkarte").show();
	}
	if ($("input[@name='wako_bezahltyp']:checked").val() == '4') {
		$("#wako_form_paypal").show();
	}
}

function reload_adressen(type) {
	$('#adressen').html($('#wako_ajax_loader').html());
	$("#cboxClose").click();
	/*address_id = $('input[name=_address_id]:checked:first').val();*/
	$.ajax ({
			type: 'GET',
			url: '/warenkorb-1-1/ajax_adressen.html',
			data: 'sub_step=' + type,
			cache: false,
			success: function (html) {
					$('#adressen').html (html);
					/* Rebind Colorbox f�r Adressen */
					$(".colorbox_adressen").colorbox({width:"580", height:"500", iframe:true, overlayClose:false, close:""});
			}
	});
}

$(document).ready(function(){
	/* Colorbox f�r Bestelllinks */
	$(".colorbox_bestellen").colorbox({width:"400", height:"180", iframe:true, title:" ", overlayClose:false, close:""});
	/* Colorbox f�r Detail Popup */
	$(".colorbox_detail").colorbox({width:"580", height:"450", iframe:true, title:" ", overlayClose:false, close:""});
	/* Colorbox f�r Ausloggen */
	$(".colorbox_logout").colorbox({width:"400", height:"200", iframe:true, title:" ", overlayClose:false, close:""});
	/* Colorbox f�r AGB */
	$(".colorbox_agb").colorbox({width:"600", height:"450", iframe:true, title:" ", overlayClose:false, close:""});
	/* Colorbox f�r Adressen */
	$(".colorbox_adressen").colorbox({width:"580", height:"500", iframe:true, title:" ", overlayClose:false, close:""});
	/* Wakoartikel entfernen */
	$("a.wako_del").click(function (){
		var id = $(this).attr("id").replace("wako_del_","");
		$("input[name=wako_anzahl_" + id +"]").val("0");
		$("input[name=wako_btn_submit_recalculate]").click();
	});
	/* Bestellung Details anzeigen */
	$("a.bestellungen_detail").click(function (){
		var id = $(this).attr("id").replace("bestellungen_detail_","").replace("_link","");

		if ($("#wako_bestellungen_artikel_" + id).html() == '<hr>' || $("#wako_bestellungen_artikel_" + id).html() == '<HR>') {
			$("#wako_bestellungen_artikel_" + id).html('<div style="text-align:center;"><img src="/_images/wako_load.gif" alt="Bitte warten"/></div>');
			$.ajax ({
				type: 'GET',
				url: '/warenkorb-1-1/ajax_bestellungen_details.html',
				data: 'bestellung_id=' + id,
				cache: false,
				success: function (html) {
					$("#wako_bestellungen_artikel_" + id).html(html);
				}
			});
		} else {
			$("#wako_bestellungen_artikel_" + id).html("<hr />");
		}
	});

	//Verstecke Zahlart
	toggle_lastschrift();
	//	Bildungseinrichtungssuche
	$('.adress_suche').change(function() {
		var id = $(this).val();
		var target = "#wako_bildungseinrichtung_adresse_" + id;
		$("#bildungseinrichtungen").children().hide();
		$(target).toggle();
	});
	toggle_lieferadresse();
	toggle_nachlassanspruch()
});
