function CheckInput (warnung) {
    if (document.getElementsByName("suche")[0].value.length < 3) {
      alert(warnung);
      document.getElementsByName("suche")[0].focus();
      return false;
    }
  return true;
}

function suche(warnung){
	if (document.getElementsByName("suche")[0].value == "Suche") {
		document.getElementsByName("suche")[0].value="";
	} 
  if (CheckInput (warnung)){
	this.document.form_suche.submit()
  }
}

function change(){
	this.document.formular.update.value=2;
	this.document.formular.submit();
}


function reload(){
	this.document.formular.update.value=2;
	this.document.formular.action += "#formular";
	this.document.formular.submit();
}

var fancy_changed=false;
function closeFancy(){
	if(fancy_changed){
		//$(".box_content_content_content").html("<div style='width:100%; padding:50px 0px 50px 0px; text-align:center'><img src='images/loader.gif' border=0></div>");
		var session_id = $("#session_id").val();
		location.href="index.php?content=bestellung";
		//$(".box_content_content_content").load("content_bestellung.php?session_id="+session_id, activateButtons);
		fancy_changed=false;
	}
}

function activateButtons(){
	
		$(".deleteArticle").click(function(){
			 var id_order = $(this).children("input").val();
			 var session_id = $("#session_id").val();
			 $.ajax({
			   type: "POST",
			   url: "/lib/js_functions.php",
			   async: false,
			   data: "function=deleteArticle&session_id="+session_id+"&id_order="+id_order,
			   success: function(data_str){
			   	 var data = eval('('+data_str+')');
			   	 
			   	 $(".box_content_content_content").load("content_bestellung.php?session_id="+session_id, activateButtons);
			   	 //location.href="index.php?content=bestellung";
			   }
			 });	
			return false;
		});
	
		 $("a.fancy_bestellung").fancybox({
			 	'zoomSpeedIn': 300,
			 	'zoomSpeedOut': 500,
			 	'frameWidth': 598,
			 	'frameHeight' : 450,
			 	'padding' : 0,
			 	'overlayShow': true,
			 	'easingIn' : 'easeInOutCubic',
			 	'easingOut' : 'easeInBack',
			 	'hideOnContentClick' : false,
			 	'callbackOnShow' : activateButtons,
			 	'callbackOnClose' : closeFancy
		 	});	
	 		$("#addArticle").click(function(){
				//$(".box_content_content_content").html("<div style='width:100%; padding:50px 0px 50px 0px; text-align:center'><img src='images/loader.gif' border=0></div>");
				var session_id = $("#session_id").val();
				location.href="index.php?content=speisekarte";
				//$(".box_content_content_content").load("content_speisekarte.php?content=speisekarte&session_id="+session_id, activateButtons);
			});
	
				$("#area_bemerkung").append("<textarea name='bemerkung' class='form_bemerkung' id='bemerkung' cols='50' rows='10'></textarea>");
	
			$("#button_artikel_ok").click(function(){
			 var inhalte = $(".zutaten_checkbox").serialize();
			 var id_artikel = $("#id_artikel").val();
			 var bemerkung = $("#bemerkung").val();
			 var session_id = $("#session_id").val();
			 $.ajax({
			   type: "POST",
			   url: "/lib/js_functions.php",
			   async: false,
			   data: "function=addArticle&session_id="+session_id+"&id_artikel="+id_artikel+"&bemerkung="+bemerkung+"&"+inhalte,
			   success: function(data_str){
			   	 var data = eval('('+data_str+')');
			   	 fancy_changed=true;
			   	 $.fn.fancybox.close();
			   }
			 });	
	 		return false;
	 	});
}

$(document).ready(function() {
	var imgloader = new Image();
  imgloader.src= "/images/loader.gif";	
		activateButtons();
		$(".lightbox").fancybox();
	}); 

function reload_kontakt(){
	document.all.kontakt_form.update.value=2; 
	document.all.kontakt_form.submit();
}
