
function color_field(obj) {
	if($(obj).val() == '') {
		$(obj).addClass('gms-required-field');
		return false;
	} else {
		$(obj).removeClass('gms-required-field');
		return true;
	}
}

function clear_radios() {
	$('#cashpoint_type1').removeAttr('checked');
	$('#cashpoint_type2').removeAttr('checked');
	$('#cashpoint_type3').removeAttr('checked');
}



$(document).ready(function() {
	$('#tabs').tabs();

	$('#debug-tabs').tabs();
	$('#debug').dialog(
		{
			width: 600,
			height: 400,
			autoOpen: false
		}
	);
	
	$('#slideshow').c2pslider({
	'thumbs_enable': false,
	'animation_step_speed': 6000,
	'animation_speed': 600,
	'autoplay': true,
	'fullsize_fitting_images': false,
	'thumbs_fitting_images': false
	}); 
	
	var encounted_width = 0;
	$('#admin-toolbox .admin-button')
	.mouseover(function() {
		$(this).addClass('ui-state-hover');
	})
	.mouseout(function() {
		$(this).removeClass('ui-state-hover');
	})
	.each(function() {
		encounted_width += $(this).outerWidth(true);
	});
	
	if(encounted_width > 0) {
		$('#admin-toolbox').css('width', encounted_width+'px');
	}
	
	$('#open-debug').click(function() {
		$('#debug').dialog('open');
		return false;
	});
	
	/*if($('.products-header .content-products-header1').length == 1) {
		$('.products-header div[class^="picture-area"]').css('display', 'none');
	}*/
	
	$('#searchfield, input[name="gms_username"], input[name="gms_password"]')
	.focus(function() {
		var fieldval = $(this).val();
		
		if($(this).data('orig_value') == undefined || $(this).data('orig_value') == $(this).val()) {
			$(this).data('orig_value', fieldval);
			$(this).val('');
		} else {
			$(this).select();
		}
	})
	.blur(function() {
		if($(this).val() == '') {
			$(this).val($(this).data('orig_value'));
		}
	});
	

	
	
	// ----------------------- Abwicklung der drei unterschiedlichen Buttons auf der ersten Seite -------------------------------------------
	$('.cashpoint-button1').click(function() {
		clear_radios();
		$('#cashpoint_type1').attr('checked', 'checked');
		$('#shoping-cart form').submit();
	});
	
	$('.cashpoint-type2').change(function() {
		$('#cashpoint_type2').attr('checked', 'checked');
	});
	$('.cashpoint-button2').click(function() {
		clear_radios();
		$('#cashpoint_type2').attr('checked', 'checked');
		$('#shoping-cart form').submit();
	});

	$('.cashpoint-type3').change(function() {
		$('#cashpoint_type3').attr('checked', 'checked');
	});
	
	$('.cashpoint-button3').click(function() {
		clear_radios();
		$('#cashpoint_type3').attr('checked', 'checked');
		$('#shoping-cart form').submit();
	});
	
	// ----------------------- ENDE Abwicklung der drei unterschiedlichen Buttons auf der ersten Seite -------------------------------------------
	
	
	
	
	
	
	
	// Datumsfelder mit Kalenderfunktion ausstatten
	$('.is-date-picker').datepicker({
		dateFormat: 'dd.mm.yy'
	});
	
	
	$('input[name="filter_events"]').click(function(){
		$('input[name="gms_filter"]').val('1');
	});
	
	// Aktiviere des Weiter-Buttons auf der Veranstaltungsliste
	$('#shoping-cart .select-event').click(function() {
		$('#shoping-cart input.step-button').removeAttr('disabled');
	});
	if($('input[name="event_id"]:checked').length == 1) {
		$('#shoping-cart input.step-button').removeAttr('disabled');
	}
	
	
	$('#shoping-cart form input.may-not-empty').blur(function() {
		color_field($(this));
	});
	
	
	

	
	
	
	
	$('#shoping-cart form').submit(function() {
		var check_field = true;
		
		// console.log($('#shoping-cart form input[name="cashpoint_type"]:checked').val());
		// return false;
		
		
		if($('#shoping-cart form input[name="step"]').length > 0) {
			switch(parseInt($('#shoping-cart form input[name="step"]').val())) {
				case 1:
				
					console.log('angehaktes Feld: ' + $('#shoping-cart form input[name="cashpoint_type"]:checked').val());
				
				
					switch(parseInt($('#shoping-cart form input[name="cashpoint_type"]:checked').val())) {
						case 1:
						break;
						
						case 2:
						break;
						
						case 3:
							var send_form = true;
							$('#shoping-cart form input.may-not-empty').each(function(index, obj) {
								check_field = color_field($(obj));
								if(send_form == true && check_field == false) send_form = false;
							});
							return send_form;
						break;
					}
				break;
					
				case 2:
				case 4:
					var send_form = true;
					$('#shoping-cart form input.may-not-empty').each(function(index, obj) {
						check_field = color_field($(obj));
						if(send_form == true && check_field == false) send_form = false;
					});
					return send_form;
				break;
			}
		}
		
	
		if($('#shoping-cart form input[name="gms_register"]').length > 0) {
			var send_form = true;
			$('#shoping-cart form input.may-not-empty').each(function(index, obj) {
				check_field = color_field($(obj));
				if(send_form == true && check_field == false) send_form = false;
			});
			return send_form;
		}
		
	});
});





$(window).load(function() {
	if($('#product-detail #tabs').length == 1) {
		$('#products-wrapper .products-header').css('display', 'none');
		var max_height = 0;
		$('#tabs .ui-tabs-panel').each(function(i, obj) {
			if($(obj).height() > max_height) {
				max_height = $(obj).height();
			}
		});
		$('#tabs .ui-tabs-panel').css('height', max_height + 'px');
	}

});


