
function order_finalstep(){
	
	var missingtext = '';
	if($("input[name='vorname']").val()==''){
		missingtext += '- Anschrift: Vorname fehlt\n';
	}
	if($("input[name='name1']").val()==''){
		missingtext += '- Anschrift: Name fehlt\n';
	}
	
	if($("input[name='strasse']").val()==''){
		missingtext += '- Anschrift: Strasse fehlt\n';
	}
	
	if($("input[name='plz']").val()==''){
		missingtext += '- Anschrift: Plz fehlt\n';
	}
	if($("input[name='ort']").val()==''){
		missingtext += '- Anschrift: Ort fehlt\n';
	}
	if($("input[name='land']").val()==''){
		missingtext += '- Anschrift: Land fehlt\n';
	}
	if($("input[name='telefon']").val()==''){
		missingtext += '- Anschrift: Telefon Nr fehlt\n';
	}
	if($("input[name='email']").val()==''){
		missingtext += '- Anschrift: Email fehlt\n';
	}
	if($("input[name='land']").val()==''){
		missingtext += '- Anschrift: Land fehlt\n';
	}
	
	if($("input[name='versandoption']:checked").val()=='spedition'  &&  $("input[name='zweise_spedition']:checked").val()=='abbuchung' ) {
		if( ($("input[name='kontonr']").val()=='') || ($("input[name='bank']").val()=='') || ($("input[name='kontoinhaber']").val()=='') || ($("input[name='blz']").val()=='')){
				missingtext += unescape('- Abbuchung bei Versand per Spedition: Bankverbindung unvollst%E4ndig')+' \n';
		}
	}
	
	if(missingtext!=''){		
		missingtext = unescape('Bitte f%FCllen Sie das Formular vollst%E4ndig aus')+'\n\n'+missingtext
	}
	
	
	if(missingtext!=''){
	//if(false){
		alert(missingtext);
	}
	else{
			var d=new Date();
			$.post('shop_AX_bestellung_finalStep.a4d?d='+d.getTime(), $("#bestell_formular").serialize(),function(data) {
			   	//alert("Data Loaded: " + data);
				$('#Bestellung_Step4').html(data);
				$('.form_Bestellung').hide();
				$('#Bestellung_Step4').show();
				$('.bestellmenu_step_active').removeClass('bestellmenu_step_active');
				$('#bestellung_m_step1').addClass('bestellmenu_step');
				$('.bestellmenu_step_active').addClass('bestellmenu_step');
				$('.bestellmenu_step').addClass('bestellmenu_step');
				$('#bestellung_m_step4').addClass('bestellmenu_step_active');
			 });
	}
		
	
	
}

function do_order(){
	var agb_ok = $("input[name='AGB']:checked").val();
	if(agb_ok==null){
			alert(unescape('Bitte best%E4tigen Sie die Kenntnisnahme der Lieferbedingungen'));
	}
	else{
			//alert('doorder');
			var d=new Date();
			$.post('shop_AX_bestellung_DoOrder.a4d?d='+d.getTime(),$("#bestell_formular").serialize(),function(data) {
				//alert('data:'+data);
				$('#Bestellung_Step5').html(data);
				$('.form_Bestellung').hide();
				$('#Bestellung_Step5').show();
				$('.bestellmenu_step_active').removeClass('bestellmenu_step_active');
				$('#bestellung_m_step1').addClass('bestellmenu_step');
				$('.bestellmenu_step_active').addClass('bestellmenu_step');
				$('.bestellmenu_step').addClass('bestellmenu_step');
				$('#bestellung_m_step5').addClass('bestellmenu_step_active');
			});
	}

}

function order_nextstep(step,backw_or_forw){
	//alert('nextstep');
	var versandoption = $("input[name='versandoption']:checked").val();
	//alert(versandoption);
	var nextstep = true;
	
	if((step=='2') && (backw_or_forw=='forw')){
		if(versandoption==null){
			nextstep= false;
			alert(unescape('Bitte eine Versandoption w%E4hlen'));
		}
	}
	
	if((step=='3') && (backw_or_forw=='forw')){
		var ausgew_haendler = $("input[name='Haendler_auswahl']:checked").val();
		if(ausgew_haendler==null){
			nextstep= false;
			alert(unescape('Bitte einen Utopia-Vertragsh%E4ndler w%E4hlen'));
		}
	}
	
	if($("input[name='versandoption']:checked").val()=='haendler' || $("input[name='versandoption']:checked").val()=='abWerk') {
		$('#Bankverbindung').hide();
		$('#div_abweichendeLAnschrift').hide();
		
	}
	else{
		//alert('showL');
		$('#Bankverbindung').show();	
		$('#div_abweichendeLAnschrift').show();	
	}
		

	
	
	if(nextstep){
		$('.zweise').hide();
		$('#zweise_'+versandoption).show();
		//alert('#zweise_'+versandoption);
	
		if((step=='2') && (versandoption!='haendler')){
			if(backw_or_forw=='forw'){
				step='3';
			}
			else{
				step='1';
			}
		}
		//alert(step);
		$('.form_Bestellung').hide();
		$('#Bestellung_Step'+step).show();
		$('.bestellmenu_step_active').removeClass('bestellmenu_step_active');
		$('#bestellung_m_step1').addClass('bestellmenu_step');
		$('.bestellmenu_step_active').addClass('bestellmenu_step');
		$('.bestellmenu_step').addClass('bestellmenu_step');
		$('#bestellung_m_step'+step).addClass('bestellmenu_step_active');	
	}
	
	
	
}


function AxSy(url,TargetDiv){
		//alert(url);
		//alert(TargetDiv);
		$.ajax({
			async : false,
		  	url: url,
		    success: function(data) {
		    $(TargetDiv).html(data);
		  }
		});
}

function AxQ(url,TargetDiv){
		//alert('targetdiv:'+TargetDiv);
		//alert('url:'+url);
	$.ajaxq ("thequeue", {
	    url: url,
	    cache: false,
	    success: function(html)
	    {
			//alert('success'+url);
	        $(TargetDiv).html(html);	
	    }
	});
}

function sendFormvalues() {  
  $.post("shop_AX_MeinFahrrad.a4d", $("form").serialize(), function(data){
	$('#MeinFahrrad_Zusammenfassung').html(data);
   });
}

function SelectSchaltung(modellkey){
		//alert(modellkey);
		//$.ajaxq ("thequeue");	
		$('#rahmen_content').load('shop_AX_box_Rahmen.a4d?ModellKey='+modellkey);
		$('#farbe_content').load('shop_AX_box_Farbe.a4d?ModellKey='+modellkey);
		$('#uebersetzung_content').load('shop_AX_box_Uebersetzung.a4d?ModellKey='+modellkey);
		$('#zusatzartikel_content').load('shop_AX_box_Zusatz.a4d?action=clear');
		$('#aenderungen_content').load('shop_AX_box_Aenderungen.a4d?action=clear');	
		$('#esupport_content').load('shop_AX_box_Antrieb.a4d?action=clear');	
		$('#MeinFahrrad_Zusammenfassung').load('shop_AX_MeinFahrrad.a4d?action=clear');
}

function SelectGrundausstattung(bereich,id){
		//alert('selected');
		//alert(bereich+'   '+id);
		
		AxQ('shop_AX_box_Aenderungen.a4d?bereich='+escape(bereich)+'&id='+escape(id),'#aenderungen_content');
		AxQ('shop_AX_box_Antrieb.a4d?bereich='+escape(bereich)+'&id='+escape(id),'#esupport_content');
		AxQ('shop_AX_box_Zusatz.a4d?bereich='+escape(bereich)+'&id='+escape(id),'#zusatzartikel_content');
		AxQ('shop_AX_MeinFahrrad.a4d','#MeinFahrrad_Zusammenfassung');
		
}

function save_config() {
	//alert('test');
	var data=$('#ID_form_save_config').serialize();
	$.post("shop_AX_OVL_saveConfig.a4d", data, function(data1) {
			//alert(data1);
			//$('#result').html(data1);
			
			if (data1='saved')
						$.fancybox({
								'href'	: 'shop_AX_loadSavedConfigs.a4d',
								'overlayShow'	:	true,
								'type': 'ajax'
						});
			
				//$.fn.colorbox({open: true, opacity: 0.5, href: "shop_AX_loadSavedConfigs.a4d"});

	  		//$('.result').html(data1);
			//$.fn.colorbox.close();
			//$.fn.colorbox({open: true, opacity: 0.5, href: "shop_AX_saveconfig.a4d"});
	});

	
}


$(document).ready(function() {
	
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$('ul.tabs li').live('click', function(event) {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	

	$('#rahmen_content').load('shop_AX_box_Rahmen.a4d?ModellKey=');
	$('#farbe_content').load('shop_AX_box_Farbe.a4d?ModellKey=');
	$('#uebersetzung_content').load('shop_AX_box_Uebersetzung.a4d?ModellKey=');
	$('#zusatzartikel_content').load('shop_AX_box_Zusatz.a4d?action=clear');
	$('#aenderungen_content').load('shop_AX_box_Aenderungen.a4d?action=clear');	
	$('#esupport_content').load('shop_AX_box_Antrieb.a4d?action=clear');	
	$('#MeinFahrrad_Zusammenfassung').load('shop_AX_MeinFahrrad.a4d?action=clear');

	
	
	/*
	$("#window_loadConfig").fancybox({
			'href'	:	'shop_AX_loadSavedConfigs.a4d',
			'overlayShow'	:	true
	});
	*/
	
	$('#cb_abwLieferanschrift').live('click', function(event) {
		if( $(this).attr('checked')){
			$('#div_abweichendeLAnschrift_fields').show();
		}
		else{
			$('#div_abweichendeLAnschrift_fields').hide();	
		}
		
	 });
	
	$('.radio_zweise').live('click', function(event) {
		$('#bankverbindung').hide();
		//alert('this selected: '+$(this).attr('checked'))
		//alert('this attr value: '+$(this).attr('value'))
		
		if( $(this).attr('checked') && $(this).attr('value')== 'abbuchung'){
			$('#bankverbindung').show();
		}

	 });
	
	
	
	$('#window_loadConfig').live('click', function(event) {
		//alert('klick');
		$.fancybox({
				'href'	:	'shop_AX_loadSavedConfigs.a4d',
				'overlayShow'	:	true,
				'type': 'ajax'
		});
		
	  });
	
	$('#OVL_saveConfig').live('click', function(event) {
		//alert('klick');
		$.fancybox({
				'href'	:	'shop_AX_OVL_saveConfig.a4d',
				'overlayShow'	:	true,
				'type': 'ajax'
		});
		
	  });
	
	$('#id_button_save_config').live('click', function(event) {
		save_config();
	  });
	
	
	
	$('#OVL_angebot').live('click', function(event) {
		$.fancybox({
				'href'	:	'shop_AX_Angebot.a4d',
				'overlayShow'	:	true,
				'type': 'ajax'
		});
	  });
	
	$('#OVL_bestellung').live('click', function(event) {
			sendFormvalues();
			$.fancybox({
					'padding': 10,
					'margin': 10,
					'href'	:	'shop_AX_bestellung.a4d',
					'overlayShow'	:	true,
					'type': 'ajax',
					'centerOnScroll' : true,
					'autoDimensions' : true
			});
	  });
	
	
	
	
	

	// -----------------------------------------------------------------------------------------------
	// Box MeinFahrrad fixieren.
	var top = $('#MeinFahrrad').offset().top - parseFloat($('#MeinFahrrad').css('marginTop').replace(/auto/,0));

	 $(window).scroll(function (event) {
		
	    // what the y position of the scroll is
		//alert('scroll');
	    var y = $(this).scrollTop();
		//alert('scroll');
	    // whether that's below the form
		//alert('top: '+top+'y: '+y);
	    if (y >= top) {
	      // if so, ad the fixed class
	      $('#MeinFahrrad').addClass('fixed');
			//alert('set fixed');
	    } else {
	      // otherwise remove it
	      $('#MeinFahrrad').removeClass('fixed');
			//alert('remove fixed');
	    }
	  });

	// -----------------------------------------------------------------------------------------------


	
	// -----------------------------------------------------------------------------------------------
	// Tooltip Konfiguration fixieren.
	$('#init_load_savedconfig').hover(
		function() {
			Tip('Laden Ihrer <BR>frueher gespeicherten <BR>Konfigurationen<BR>',DELAY, 100)
	  },
		function() {
		UnTip('')
	});

	global_Modell_Selected = false;	
	
	
	// -----------------------------------------------------------------------------------------------
	// Infotext zur Warengruppe
	
  $('.Arrow_Text_WG').live('click', function(event) {
	if($(this).attr('src')=='lay\/ArrowUp.gif'){
		$(this).attr('src','lay\/ArrowDown.gif');
	}else{
		$(this).attr('src','lay\/ArrowUp.gif');
	}
	$(this).parent().parent().next().fadeToggle();

  });

	// -----------------------------------------------------------------------------------------------
	// Modellbild Hover


	$('.modelllink').hover(
		function() {
		$(this).children(":first").next().attr('class','modellbild_hover');
	  },
		function() {
		$(this).children(":first").next().attr('class','modellbild');
	});
	
	// -----------------------------------------------------------------------------------------------
	// Modellbild KLick
	
	$('.modelllink').click(
		function() {
			var bildname = $(this).children(":first").next().attr('alt');
			var modell = $(this).children(":first").next().attr('id');
			$('#bild_meinfahrrad').attr('src','lay/MiniaturenShop/'+bildname+'_200.jpg');
			$('#bild_meinfahrrad').show();
			$('#meinFModellBezeichnung').html(modell);
			
			
			//alert(modell);
			AxQ('shop_AX_box_Schaltung.a4d?modell='+modell,'#schaltung_content');
			AxQ('shop_AX_box_Rahmen.a4d?modellkey=','#rahmen_content');
			AxQ('shop_AX_box_Farbe.a4d?modellkey=','#farbe_content');
			AxQ('shop_AX_box_Uebersetzung.a4d?modellkey=','#uebersetzung_content');	
			AxQ('shop_AX_box_Aenderungen.a4d?action=clear','#aenderungen_content');
			AxQ('shop_AX_box_Antrieb.a4d?action=clear','#esupport_content');
			AxQ('shop_AX_box_Zusatz.a4d?action=clear','#zusatzartikel_content');
			
			AxQ('shop_AX_MeinFahrrad.a4d?action=clear&modellname='+modell,'#MeinFahrrad_Zusammenfassung');
			//alert('vor clear queue');
			//$.ajaxq ("thequeue");	
	  })
	
	// -----------------------------------------------------------------------------------------------
	// KLick radiobutton Auswahl Schaltung
	  $('.auswahl_schaltung').live('click', function(event) {
			var param = $(this).attr('id');
			var params_array = param.split('_'); // this is an array containing the items
			//alert(params_array[1]);
			$('#meinFModellBezeichnung').html(params_array[2]);
			SelectSchaltung(params_array[1]);
	  });
	
	// -----------------------------------------------------------------------------------------------
	// KLick radiobutton Auswahl Rahmen, Farbe + Übersetzung
	  $('.GR_radio_auswahl').live('click', function(event) {
		
			var param = $(this).attr('id');
			//alert('param');
			var params_array = param.split('_'); // this is an array containing the items
			SelectGrundausstattung(params_array[0],escape(params_array[1]))
			
	  });
	
	//$('#init_load_savedconfig').colorbox({opacity: 0.5, speed: 200, transition: 'fade', href: "shop_AX_loadSavedConfigs.a4d"});

});
