function urldecode (str) {
    return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

var aivao_mobile = false;
//alert($.os['name']);
if($.os['name'] == 'ipod' || $.os['name'] == 'ipad' || $.os['name'] == 'iphone') { 
	aivao_mobile = true;
}


function aivao_alertpp(options){
	if(!aivao_isloading){
		aivao_isloading = true;
		$.prompt('<img src="/cms/front/pix/loading.gif" />',{
			opacity: 0.8,
			top:'44%',
			persistent:false,
			prefix:'ldng'
		});
	}
}


function aivao_alertinfo(options){
	if (options['duration'] === undefined) {
		options['duration'] = 2000;
	}
	$.prompt(options['html'],{
		opacity: 0.8,
		top:'33%',
		persistent:true,
		timeout:options['duration'],
		prefix:'flsh'
	});
}


function aivao_alert_close(options){
	$.prompt.close();
}

function aivao_alert(options){
	
	$.prompt(options['html'],{
		opacity: 0.8,
		top:'20%',
		persistent:true
	});
}
function aivao_alert_close(options){
	$.prompt.close();
}

var aivao_isloading = false;
function aivao_loading(options){
	if(!aivao_isloading){
		aivao_isloading = true;
		$.prompt('<img src="/cms/front/pix/loading.gif" />',{
			opacity: 0.8,
			top:'44%',
			persistent:false,
			prefix:'ldng'
		});
	}
}
function aivao_loading_close(options){
	$.prompt.close();
	aivao_isloading = false;
}


function aivao_infoslide(options){
	$('.info').find('.bottom').find('a').removeClass('on');
	$('.infobottom_'+options['mode']).addClass('on');
	$('.info_slide').hide();
	if(options['mode'] != 'info'){
		$('.info_'+options['mode']).show();
	}
}

function aivao_infoshipcost(options) {
	aivao_loading({});
	options['country_id'] = $('select[name=info_country]').val();
	
	$.post('/cms/front/ajax/infoshipcost.php', options, function(data) {
		$('.info_shipcost').find('.inner').html(data['html']);
		
		aivao_loading_close({});
	}, 'json');
}

function aivao_logout(options) {
	$.post('/cms/front/ajax/logout.php', {}, function(data) {
		window.location.reload(true);
	}, 'json');
}


$(function() {	
	
	var g = {
		'maxvis' : 20,
		'opened' : 20,
		'batch' : 0,
		'bio_only' : false,
		'best_only' : false,
		'showingbatch' : false
	};

	
	$(window).scroll(function() {
		
		if($('#showbatch').is(':visible')){
			var offset = $('#showbatch').offset();
			var morepos = offset.top;
			var winpos = $(window).scrollTop();
			var winheight = $(window).height();
			var bottom = winpos+winheight-150;
			//alert(g['maxvis']);
			if(bottom >= morepos && !g['showingbatch'] && $('#showbatch').is(':visible')){
				g['showingbatch'] = true;
				setTimeout(function(){
					g['batch']++;
					var options = {
						'batch' : g['batch']
					};
					$.post('/cms/front/ajax/nextbatch.php', options, function(data) {
						//alert(data['producthtml']);
						$('#productlist').append(data['producthtml']);
						if(data['shown'] >= data['totalnum_int']){
							$('#showbatch').hide();
						}
						g['showingbatch'] = false;
						
					}, 'json');
				}, 1000);
			}
		}
		
	});
	
	$('.form_filter select').change(function(e){
		var val = $(this).val();
		if(val != 'suche...'){
			$('.form_search input').val('');
			$('.bestbio').show();
			var name = $(this).attr('name');
			var posi = $(this).attr('alt');
			
			//alert(name);
			g['batch'] = 0;
			var options = {
				'name' : name,
				'val' : val,
				'posi' : posi
			};
			$('.navi_u label').html('Ergebnisse sortieren nach:');
			$('.navi_u .ordernavi').show();
			$('.form_filter select').html('<option>suche...</option>');
			$('#showbatch').hide();
			$('#productlist').html('<div class="loading">Lädt...</div>');
			$.post('/cms/front/ajax/change_selects.php', options, function(data) {
				
				//alert(data['totalnum_int']);
				$('input[name=bio_only]').removeAttr('checked');
				$('input[name=best_only]').removeAttr('checked');
				g['bio_only'] = false;
				g['best_only'] = false;
				$('#productlist').html(data['producthtml']);
				
				if(data['totalnum_int'] > g['maxvis'] && data['shown'] < data['totalnum_int']){
					$('#showbatch').show();
				}
				
				$('input[name=quantity]').numeric({ decimal: false, negative: false });
				$('.total span').html(data['totalnum']);
				$('.biodiv span').html(data['bionum']);
				$('.biodiv').removeClass('disable');
				if(data['bionum'] == 0){
					$('.biodiv').addClass('disable');
				}
				$('.bestdiv span').html(data['bestnum']);
				$('.bestdiv').removeClass('disable');
				if(data['bestnum'] == 0){
					$('.bestdiv').addClass('disable');
				}
				bubble();
				for(key in data['optionhtml']) {
					if($.inArray(key, data['hide']) == -1){
						$('.form_filter select[name="'+key+'"]').show();
					}
					else{
						$('.form_filter select[name="'+key+'"]').hide();
					}
					
					if($.inArray(key, data['disable']) == -1){
						$('.form_filter select[name="'+key+'"]').removeClass('disable');
						$('.form_filter select[name="'+key+'"]').attr('disabled', false);
					}
					else{
						$('.form_filter select[name="'+key+'"]').addClass('disable');
						$('.form_filter select[name="'+key+'"]').attr('disabled', true);
					}
					
					$('.form_filter select[name="'+key+'"]').html(data['optionhtml'][key]);
				}
			
			}, 'json');
		}
	});
	
	$('.allwines').click(function(e){
		$('.form_search input').val('');
		$('.bestbio').show();
		g['batch'] = 0;
		var options = {};
		$('.navi_u label').html('Ergebnisse sortieren nach:');
		$('.navi_u .ordernavi').show();
		$('.form_filter select').html('<option>suche...</option>');
		$('#showbatch').hide();
		$('#productlist').html('<div class="loading">Lädt...</div>');
		$.post('/cms/front/ajax/allwines.php', options, function(data) {
			//alert(1);
			$('input[name=bio_only]').removeAttr('checked');
			$('input[name=best_only]').removeAttr('checked');
			g['bio_only'] = false;
			g['best_only'] = false;
			$('#productlist').html(data['producthtml']);
			if(data['totalnum_int'] > g['maxvis'] && data['shown'] < data['totalnum_int']){
				$('#showbatch').show();
			}
			$('input[name=quantity]').numeric({ decimal: false, negative: false });
			$('.total span').html(data['totalnum']);
			$('.biodiv span').html(data['bionum']);
			$('.biodiv').removeClass('disable');
			if(data['bionum'] == 0){
				$('.biodiv').addClass('disable');
			}
			$('.bestdiv span').html(data['bestnum']);
			$('.bestdiv').removeClass('disable');
			if(data['bestnum'] == 0){
				$('.bestdiv').addClass('disable');
			}
			bubble();
			for(key in data['optionhtml']) {
				if($.inArray(key, data['hide']) == -1){
					$('.form_filter select[name="'+key+'"]').show();
				}
				else{
					$('.form_filter select[name="'+key+'"]').hide();
				}
				
				if($.inArray(key, data['disable']) == -1){
					$('.form_filter select[name="'+key+'"]').removeClass('disable');
					$('.form_filter select[name="'+key+'"]').attr('disabled', false);
				}
				else{
					$('.form_filter select[name="'+key+'"]').addClass('disable');
					$('.form_filter select[name="'+key+'"]').attr('disabled', true);
				}
				
		  		$('.form_filter select[name="'+key+'"]').html(data['optionhtml'][key]);
			}
			
		}, 'json');
	});
	
	
	$('input[name=bio_only], input[name=best_only]').live('change', function(e){
		if(!$(this).parent().parent().hasClass('disable')){
			var arr = $(this).attr('name').split('_');
			var bestbio = arr[0];
			var other = 'best';
			if(bestbio == 'best'){
				other = 'bio';
			}
			//alert(bestbio);
			
			$('input[name='+other+'_only]').removeAttr('checked');
			g[other+'_only'] = false; 
			g[bestbio+'_only'] = false;
			g['batch'] = 0;
			var options = {
				bestbio:bestbio,
				other:other,
				val:0
			}
			if($(this).is(':checked')){
				g[bestbio+'_only'] = true; 
				options['val'] = 1;
			}
			
			
			$('#showbatch').hide();
			$('#productlist').html('<div class="loading">Lädt...</div>');
			$.post('/cms/front/ajax/change_bestbio.php', options, function(data) {
				//alert(1);
				
				$('#productlist').html(data['producthtml']);
				if(data['totalnum_int'] > g['maxvis'] && data['shown'] < data['totalnum_int']){
					$('#showbatch').show();
				}
				$('input[name=quantity]').numeric({ decimal: false, negative: false });
				$('.total span').html(data['totalnum']);
				
				bubble();
				
				
			}, 'json');
			
		}
	});
	
	
	$('.ordernavi a').click(function(e){
		g['batch'] = 0;
		var orderby = $(this).attr('alt');
		var direct = 'asc';
		if($(this).hasClass('asc')){
			direct = 'desc';
		}
		$('.ordernavi a').removeClass('asc desc');
		$(this).addClass(direct);
		//alert(name);
		var options = {
			'orderby' : orderby,
			'direct' : direct
		};
		$('#showbatch').hide();
		$('#productlist').html('<div class="loading">Lädt...</div>');
		$.post('/cms/front/ajax/change_order.php', options, function(data) {
			//alert(data['test']);
			$('#productlist').html(data['producthtml']);
			if(data['totalnum_int'] > g['maxvis'] && data['shown'] < data['totalnum_int']){
				$('#showbatch').show();
			}
			bubble();
			
		}, 'json');
	});
	
	
	
	function submit_search() {
		var val = $('.form_search input').val();
		//alert(name);
		if($.trim(val) != '' && $.trim(val) != 'z.B. Name, Weingut, Anbaugebiet usw.'){
			$('.bestbio').hide();
			g['batch'] = 0;
			var options = {
				'val' : val
			};
			$('.navi_u label').html('Suchergebnisse, sortiert nach Relevanz:');
			$('.navi_u .ordernavi').hide();
			//$('.form_filter select').html('<option>suche...</option>');
			$('#showbatch').hide();
			$('#productlist').html('<div class="loading">Lädt...</div>');
			$.post('/cms/front/ajax/search.php', options, function(data) {
				//alert(data['test']);
				$('input[name=bio_only]').removeAttr('checked');
				$('input[name=best_only]').removeAttr('checked');
				g['bio_only'] = false;
				g['best_only'] = false;
				$('#productlist').html(data['producthtml']);
				$('input[name=quantity]').numeric({ decimal: false, negative: false });
				$('.total span').html(data['totalnum']);
				$('.biodiv span').html(data['bionum']);
				$('.biodiv').removeClass('disable');
				if(data['bionum'] == 0){
					$('.biodiv').addClass('disable');
				}
				$('.bestdiv span').html(data['bestnum']);
				$('.bestdiv').removeClass('disable');
				if(data['bestnum'] == 0){
					$('.bestdiv').addClass('disable');
				}
				if(data['totalnum_int'] > g['maxvis'] && data['shown'] < data['totalnum_int']){
					$('#showbatch').show();
				}
				bubble();
				for(key in data['optionhtml']) {
					if($.inArray(key, data['hide']) == -1){
						$('.form_filter select[name="'+key+'"]').show();
					}
					else{
						$('.form_filter select[name="'+key+'"]').hide();
					}
				
					if($.inArray(key, data['disable']) == -1){
						$('.form_filter select[name="'+key+'"]').removeClass('disable');
						$('.form_filter select[name="'+key+'"]').attr('disabled', false);
					}
					else{
						$('.form_filter select[name="'+key+'"]').addClass('disable');
						$('.form_filter select[name="'+key+'"]').attr('disabled', true);
					}
					
					$('.form_filter select[name="'+key+'"]').html(data['optionhtml'][key]);
				}
				
			}, 'json');
		}
	}
	

	function bubble() {
		$('.bubblelink').each(function(i){
			var desc = $(this).attr('alt');
			$(this).CreateBubblePopup({
			themePath : '/cms/js/jquery/bubblepopup/jquerybubblepopup-theme',
			themeName : 'all-grey',
			align : 'left',
			tail : {align:'left' },
			innerHtml: desc,
			selectable: false,
			closingDelay: 400
			});
		});
	}
	 bubble();

	$('a').live('click', function(e){
		if($.trim($(this).attr('href')) == '#'){
		 	e.preventDefault();
		}
	});
	
	$('input, textarea').focus(function() {
		if($(this).parent().hasClass('disable')){
			//$(this).blur();
		}
		else{
			$(this).removeClass('highlight');
		}
	});
	
	$('select').live('click', function(e) {
		if($(this).hasClass('disable')){
			return false;
			$(this).blur();
			e.preventDefault();
		}
	});
	
	$('input.date').datepicker({ 
		dateFormat: 'dd.mm.yy',
		monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
		monthNamesShort: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
		dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
		maxDate: '-16y',
		changeMonth: true,
		changeYear: true,
		yearRange: '-99:-15'
	});
	
	$('#products .more a, #products h1, #products .mini, #products .thumb').live('click', function(e){
		var id = $(this).attr('alt');
		var lesstxt = 'Weniger Infos';
		var moretxt = 'Weitere Infos';
		if($('#tr_'+id+' div').hasClass('wrapper')){
			if($('#tr_'+id+' .wrapper').hasClass('smallwrapper')){
				lesstxt = 'Einklappen';
				moretxt = 'Lesen';
			}
			if(!$('#tr_'+id+' .wrapper').hasClass('unwrap')){
				$('#tr_'+id+' .wrapper').addClass('unwrap');
				$('#tr_'+id).find('.details, .producer, .region, .thumb, .linkdetail').show();
				$('#tr_'+id).addClass('detail');
				$('#tr_'+id).find('.mini').hide();
				$('#more_'+id).addClass('detail less');
				$('#more_'+id+' a').find('span').html(lesstxt);
			}
			else{
				$('#tr_'+id+' .wrapper').removeClass('unwrap');
				$('#tr_'+id).find('.details, .producer, .region, .thumb, .linkdetail').hide();
				$('#tr_'+id).removeClass('detail');
				$('#tr_'+id).find('.mini').show();
				$('#more_'+id).removeClass('detail less');
				$('#more_'+id+' a').find('span').html(moretxt);
			}
		}
	});
	
	
	
	
	$('.form_search .submit').click(function(e){
		submit_search();
	});
	$('.form_search input').keyup(function(e) {
		//alert(e.keyCode);
		if(e.keyCode == 13) {
			e.preventDefault();
			submit_search();
		}
    });
	
	
	
	
	$('input[name=bio_only]').live('click', function(e){
		if($(this).parent().parent().hasClass('disable')){
			e.preventDefault();
			return false;
		}
	});
	$('input[name=best_only]').live('click', function(e){
		if($(this).parent().parent().hasClass('disable')){
			e.preventDefault();
			return false;
		}
	});
	
	$('.buy .submit').live('click', function(e){
		
		var id = $(this).attr('alt');
		var quantity = parseInt($('#buy_'+id).find('input').val());
		var title = $('#title_'+id).html();
		if(quantity > 0){
			$('.minicart .buttons').show();
			var options = {
				'id' : id,
				'quantity' : quantity
			};
			var html = quantity;
			if(!$(this).hasClass('simplesubmit')){
				html += ' Flasche';
				if(quantity != 1){
					html += 'n';
				}
			}
			else{
				html += 'x';
			}
			html += ' '+title+' wurde';
			if(!$(this).hasClass('simplesubmit')){
				if(quantity != 1){
					html += 'n';
				}
			}
			html += ' in den Warenkorb gelegt.';
			aivao_alertinfo({html:html});
			$('.grapes').hide();
			$.post('/cms/front/ajax/addtocart.php', options, function(data) {
				$('#message_empty').hide();
				$('#message_filled').show();
				$('.minicart .num').html(data['newnum']);
				$('.minicart .total').html(data['newtotal']);
				bubble();
			}, 'json');
		}
	});
	
	
	

	
	$('input[name=quantity]').numeric({ decimal: false, negative: false });
	
	$('input[name=quantity]').live('click', function(e){
		this.select();
	});
	
	$('.carttable input[name=quantity]').live('keyup', function(e){
		if(e.keyCode > 47 && e.keyCode < 58) {
			var quantity = $(this).val();
			var id = $(this).attr('alt');
			var options = {
				'id' : id,
				'quantity' : quantity
			};
			$('#tr_'+id+' .sumprice h1').html('Lädt...');
			$('.shipcost_num h1').html('Lädt...');
			$('.total_num h1').html('Lädt...');
			//$('#tr_'+id).find('.sumprice h1').append(e.keyCode+',');
			$.post('/cms/front/ajax/cart_quantity.php', options, function(data) {
				$('#tr_'+id+' .sumprice h1').html(data['sumprice']);
				$('.shipcost_num h1').html(data['shipcost']);
				$('.total_num h1').html(data['total']);
				bubble();
			}, 'json');
		}
	});
	
	$('.carttable .delprod a').live('click', function(e){
	
		var id = $(this).attr('alt');
		var options = {
			'id' : id
		};
		$('#tr_'+id).remove();
		$('.divid_'+id).remove();
		$('.shipcost_num h1').html('Lädt...');
		$('.total_num h1').html('Lädt...');
		$.post('/cms/front/ajax/cart_remove.php', options, function(data) {
			if(data['total'] == '€ 0,00'){
				$('.tablewrap').html('<h1>Ihr Warenkorb ist leer.</h1>');
			}
			else{
				$('.shipcost_num h1').html(data['shipcost']);
				$('.total_num h1').html(data['total']);
			}
			bubble();
		}, 'json');
		
	});
	
	$('.carttable select[name=country]').change(function(e){
	
		var id = $(this).val();
		var options = {
			'id' : id
		};
		$('.shipcost_num h1').html('Lädt...');
		$('.total_num h1').html('Lädt...');
		$.post('/cms/front/ajax/cart_country.php', options, function(data) {
			$('.shipcost_num h1').html(data['shipcost']);
			$('.total_num h1').html(data['total']);
			bubble();
		}, 'json');
		
	});
	
	$('select[name="probier[kind]"]').change(function(e){
	
		var val = $(this).val();
		$('.simpletable tr').hide();
		if(val == 0){
			$('.simpletable tr').show();
		}
		else{
			$('.simpletable .trkind_'+val).show();
		}
	});
	
	function change_checkout_country(val) {
		var oldshipcost = $('.shipcost_num h1').html();
		var options = {
			'id' : val,
			'oldshipcost' : oldshipcost
		};
		
		$('.shipcost_num h1').html('Lädt...');
		$('.total_num h1').html('Lädt...');
		$.post('/cms/front/ajax/checkout_country.php', options, function(data) {
			
			$('.shipcost_num h1').html(data['shipcost']);
			$('.total_num h1').html(data['total']);
			if(data['changed']){
				aivao_alertinfo({html:'Die Versandkosten und die Gesamtsumme haben sich geändert.'});
			}
			bubble();
		}, 'json');
	}
	
	$('.invoicetable select[name="shipaddress[country]"]').change(function(e){
		var val = $(this).val();
		change_checkout_country(val);
	});
	$('.invoicetable select[name="address[country]"]').change(function(e){
		if($('input[name=sameaddress]').is(':checked')){
			var val = $(this).val();
			$('.invoicetable select[name="shipaddress[country]"]').val(val);
			change_checkout_country(val);
		}
	});
	
	$('.invoicetable select[name="address[salutation]"]').change(function(e){
		if($('input[name=sameaddress]').is(':checked')){
			var val = $(this).val();
			$('.invoicetable select[name="shipaddress[salutation]"]').val(val);
		}
	});
	
	$('.invoicetable .invoice input').keyup(function(e){
		if($('input[name=sameaddress]').is(':checked')){
			
			var name = $(this).attr('name');
			var val = $(this).val();
			//alert(name);
			$('.invoicetable .ship input[name="ship'+name+'"]').val(val);
		}
	});
	
	$('.invoicetable select').keydown(function(e){
		if(e.keyCode == 9){
			e.preventDefault();
			var name = $(this).attr('name');
			if(name == 'address[salutation]'){
				$('.invoicetable input[name="address[firstname]"]').select();
			}
			if(name == 'shipaddress[salutation]'){
				$('.invoicetable input[name="shipaddress[firstname]"]').select();
			}
			if(name == 'address[country]'){
				$('.invoicetable input[name="address[email]"]').select();
			}
			if(name == 'shipaddress[country]'){
				$('.invoicetable input[name="shipaddress[email]"]').select();
			}
		}
	});
	
	$('.invoicetable input').keydown(function(e){
		if(e.keyCode == 9){
			
			var name = $(this).attr('name');
			$('.invoicetable input').each(function(i){
				if($(this).attr('name') == name){
					//alert(i);
					$('.invoicetable input').eq(i+1).focus();
				}
			});
		}
	});
	
	
	
	
	$('input[name=sameaddress]').change(function(e){
		var sameaddress = 0;
		if($(this).is(':checked')){
			sameaddress = 1;
			$('.addresstable .ship .inputdiv').addClass('disable');
			$('.addresstable .invoice input').each(function(i){
				var name = $(this).attr('name');
				var val = $(this).val();
				$('.addresstable .ship input[name="ship'+name+'"]').val(val);
				var options = {
					'name' : 'ship'+name,
					'val' : val,
					'sameaddress' : 0
				};
				$.post('/cms/front/ajax/checkout_change.php', options, function(data) {
				
					//alert(data['test']);
				}, 'json');
			});
		}
		else{
			$('.addresstable .ship .inputdiv').removeClass('disable');
			$('.addresstable .ship input').val('');
		}
		$.post('/cms/front/ajax/checkout_sameaddress.php', {sameaddress:sameaddress}, function(data) {
		
			//alert(data['test']);
		}, 'json');
	});
	
	
	$('.invoicetable input').keyup(function(e){
		var name = $(this).attr('name');
		var val = $(this).val();
		var sameaddress = 0;
		if($('input[name=sameaddress]').is(':checked')){
			sameaddress = 1;
		}
		if(name != 'sameaddress' && name != 'country'){
			var options = {
				'name' : name,
				'val' : val,
				'sameaddress' : sameaddress
			};
			$.post('/cms/front/ajax/checkout_change.php', options, function(data) {
			
				//alert(data['test']);
			}, 'json');
		}
	});
	
	$('.invoicetable select').change(function(e){
		var name = $(this).attr('name');
		var val = $(this).val();
		var sameaddress = 0;
		if($('input[name=sameaddress]').is(':checked')){
			sameaddress = 1;
		}
		if(name != 'sameaddress' && name != 'country'){
			var options = {
				'name' : name,
				'val' : val,
				'sameaddress' : sameaddress
			};
			$.post('/cms/front/ajax/checkout_change.php', options, function(data) {
			
				//alert(data['test']);
			}, 'json');
		}
	});
	
	
	$('#checkoutform a.checkout').click(function(e){
		var grant = true;
		$('.required input').each(function () {
			if(!$(this).parent().hasClass('disable')){
				if($.trim($(this).val()) == ''){
					grant = false;
					$(this).addClass('highlight');
				}
			}
		});
		if(!grant){
			var html = 'Bitte füllen Sie die hervorgehobenen Felder aus.';
			aivao_alert({html:html});
			
		}
		else{
			if(!$('input[name=acceptterms]').is(':checked')){
				grant = false;
				$('input[name=acceptterms]').addClass('highlight');
				var html = 'Bitte akzeptieren Sie die Allgemeinen Lieferbedingungen und die Datenschutzerklärung.';
				aivao_alert({html:html});
			}
			else{
				aivao_loading({});
				var options = {};
				/*
				$('input, select, textarea').each(function () {
					$(this).change();
				});
				*/
				$('#checkoutform').ajaxSubmit({ 
					dataType:  'json', 
					success:   function (data) {
						aivao_loading_close({});
						//alert(data['test']);
						if(!data['grant']){
							var html = '';
							if(data['error'] == 'email'){
								html = 'Bitte geben Sie eine korrekte E-mail-Adresse an.';
								$('input[name="address[email]"]').addClass('highlight');
							}
							else if(data['error'] == 'cartemtpy'){
								html = 'Der Warenkorb konnte nicht gelesen werden.';
							}
							aivao_alert({html:html});
						}
						else{
							$('.navi_o_cart h1').html('Vielen Dank für Ihre Bestellung.<br /><br />Wir werden uns so bald wie möglich bei Ihnen melden.');
							$('.tablewrap').html('<a href="/" class="submit">Zurück zum Shop</a>');
						}
						bubble();
					}
				}); 
				
			}
		}
	});
	
	$('#contactform a.submit').click(function(e){
		var grant = true;
		$('.required input, .required textarea').each(function () {
			if(!$(this).parent().hasClass('disable')){
				if($.trim($(this).val()) == ''){
					grant = false;
					$(this).addClass('highlight');
				}
			}
		});
		if(!grant){
			var html = 'Bitte füllen Sie die hervorgehobenen Felder aus.';
			aivao_alert({html:html});
			
		}
		else{
			aivao_loading({});
			$('#contactform').ajaxSubmit({ 
				dataType:  'json', 
				success:   function (data) {
					aivao_loading_close({});
					//alert(data['test']);
					if(!data['grant']){
						var html = 'Bitte geben Sie eine korrekte E-mail-Adresse an.';
						$('input[name=email]').addClass('highlight');
						aivao_alert({html:html});
					}
					else{
						$('.text').html('<p><b>Vielen Dank für Ihre Nachricht.<br /><br />Wir werden uns so bald wie möglich bei Ihnen melden.</b></p>');
					}
					bubble();
				}
			}); 
		}
	});
	
	
	
	$('input.input_search').live('focus', function() {
		//alert(1);
		if($(this).val() == $(this).attr('placeholder')) {
			$(this).val('');
			$(this).removeClass('placeholder');
		}
	}).live('blur', function() {
	  if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) {
		$(this).addClass('placeholder');
		$(this).val($(this).attr('placeholder'));
	  }
	}).blur();
	
	
	if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
		$(window).load(function(){
			
			$('input:-webkit-autofill').each(function(){
				
				var text = $(this).val();
				var name = $(this).attr('name');
				$(this).after(this.outerHTML).remove();
				$('input[name=' + name + ']').val(text);
			});
		});
	}

	
});



