
	function openSplitBon(){			

		if( $("#bonSplitModal").css("display")=="none"){		
			
			$("#bonSplitModal").css({ "display":"block" });
			if($(".ziffernblock").css("display") == 'none'){
				$(".ziffernblock").css({ "display":"block" });
				$("#numPadStatus").val('nonDisplay');
			}
			else $("#numPadStatus").val('');
			loadBonForSplit();
			$('#error_message').html('Split Bon aktiv.');
			
				xmlhttp=GetXmlHttpObject();
				xmlhttp.open("POST", "include/ajax_functions_gastro.php", false);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
				sendCont="functionKey=printGastroSupply";	
				xmlhttp.send(sendCont);				
				resp=xmlhttp.responseText;
		}
		else {
			$(".split_but_down").attr("disabled", false).removeClass('gGray').addClass('orange');
			$("#bonSplitModal").css({ "display":"none" });
			$("#splitLastSelectLine").val('');
			if($("#numPadStatus").val()=='nonDisplay') $(".ziffernblock").css({ "display":"none" });
			xmlhttp=GetXmlHttpObject();
			xmlhttp.open("POST", "include/ajax_functions_splitbon.php", true);
			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
			sendCont="functionKey=clearSplitBon";	

			xmlhttp.send(sendCont);
			
			resp=xmlhttp.responseText;
			$('#error_message').html(resp);
			$("#customerOnBonModalField").css({ "display":"block"		});   // das kunden search Feld wird im Bezahkl Modal wenn splitten aktiv ausgeblendet, und hier wieder angezeigt
			bon_anzeigen();
		}
		
	}
	
	
	function moveTotalTable(currentTableId, targetTableId){
		
		$.ajax({
					type: "POST",
					url: "include/ajax_functions_gastro.php",
					dataType : "html",
					data: { functionKey:'moveTotalTable', currentTableId:currentTableId, targetTableId:targetTableId 	} ,
					async: true,
					success:function(response){	
						if (response.toLowerCase().indexOf('success') !== -1){
							$("#setTargetHiddenField").val("");
							$(".setTableToMoveTxt").html("");
							
							console.log(response);
							tische_anzeigen(false);			// wenn false gesetzt wird der erste raum (reihenfolge) angezeigt
						}
									
					}
		});	
	}
	

	
	function addToMoveBon(direction){
	
		if(direction=='down'){
			
			if($("#moveBonOriginContent > [id^='move_line']").hasClass("line_unselected")==false){
				ids=[];
				$("#moveBonOriginContent > [id^='move_line']").each(function(){
					var idNo=$(this).attr('id').replace(/\D/g, '');
					var lineQty=$("#move_bon_stk"+idNo).html().replace(',', '.');
					var price=$("#move_bon_einzelpreis"+idNo).html();
					var nName=$("#move_bon_name"+idNo).html();
					var mArray=new Array($(this).attr('id'), lineQty, price, nName );
					ids.push(mArray);
				})
			}
			else{
				$("#moveBonOriginContent").each(function() {
					originBonLineId = $(this).find('.line_selected').attr('id');				
					if(!originBonLineId){ alert("nix selected");    return "no selected line";		}
				})
				var moveQty=0;
				moveQty=$("#movebon_stueck").val();
				if(moveQty==false || moveQty==0)moveQty=1;
				$("#movebon_stueck").val('');
				
			//	alert("selected id: "+originBonLineId);
			}
			
		}
		

		$.ajax({
					type: "POST",
					url: "include/ajax_functions_gastro.php",
					dataType : "html",
					data: {functionKey:'addToMoveArray' , moveIdArray:ids },
					async: false,
					success:function(response){
						if( response.toLowerCase().indexOf('success') !== -1){ 
							content=response.split('-|-');
							targetTable=$("#moveTargetTable").val();
							loadBonForMove(content[1], targetTable);
							
						//	alert(response);
						}
					//	$("#error_message").html(html);
					}
			})
		
		
		
		
	}
	
	function addToSplitBon(direction){
		if(direction=='down'){
			$("#splitBonOriginContent").each(function() {
				originBonLineId = $(this).find('.line_selected').attr('id');				
				$("#splitLastSelectLine").val(originBonLineId);
			})
			if(!originBonLineId){ 
				$("#splitbonMessageDiv").html("Kein Artikel ausgewählt."); 
				setTimeout(function(){	$("#splitbonMessageDiv").html("");},1500); 
				return "no selected line";		
			}
		}
		else if(direction=='up'){
			$("#splitBonContent").each(function() {
				bonLineId = $(this).find('.line_selected').attr('id');
					// welche zeile aus dem origin container ist relevant
				if(bonLineId)originBonLineId=bonLineId.replace("splittedLine", "split_line");
			})
			$("#splitLastSelectLine").val(bonLineId);

			if(!bonLineId){ 
				$("#splitbonMessageDiv").html("Kein Artikel ausgewählt."); 
				setTimeout(function(){	$("#splitbonMessageDiv").html("");},1500);
				return "no selected line";		
			}
		}
		
		var splitQty=0;
		splitQty=$("#splitbon_stueck").val();
		if(splitQty==false || splitQty==0)splitQty=1;
		$("#splitbon_stueck").val('');
		
		$.ajax({
					type: "POST",
					url: "include/ajax_functions_splitbon.php",
					dataType : "html",
					data: {functionKey:'addToSplittbonArray' , originBonLineId:originBonLineId, splitQty:splitQty, functionDirection:direction  },					
					async: true,
					success:function(response){
					loadBonForSplit();
					
					}
		})	
		

	}
	
	function loadBonForSplit(){
		aktueller_bon=document.getElementById("aktueller_bon").value;
		currentBonId=$("#aktueller_bon").val();
		
		xmlhttp=GetXmlHttpObject();
		xmlhttp.open("POST", "ajax_funktionen.php", false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		sendCont="funktion=bon_anzeigen&id="+currentBonId+"&callFrom=splitBon";		

		xmlhttp.send(sendCont);
		ajaxResponse=xmlhttp.responseText;

		if(checkJson(ajaxResponse) == true) {
			respArray=JSON.parse(ajaxResponse);
			content=respArray[0].split('-|-');			
		}
		else{
			$("#splitBonOriginContent").html("Fehler beim laden vom Splitbon Inhalt<br />".ajaxResponse);
			return false;
		}
		
		$("#splitBonOriginContent").html(content[0]);
		$("#splitBonContent").html(content[1]);
		$("#split_bon_origin_sum_field").val($("#hiddenOriginBonSum").val() );
		$("#split_bon_sum_field").val($("#hiddenSplitBonSum").val() );
		
		if($("#splitLastSelectLine").val().indexOf('split_line') !== -1){
			lineToSelect=$("#splitLastSelectLine").val();
			$("#"+lineToSelect).removeClass("line_unselected").addClass("line_selected");
			
		//	$('#'+bon_id ).removeClass("line_unselected");
		//	$('#'+bon_id ).addClass("line_selected");
		}
		
		else if($("#splitLastSelectLine").val().indexOf('splittedLine') !== -1){
			lineToSelect=$("#splitLastSelectLine").val();
			$("#"+lineToSelect).removeClass("line_unselected").addClass("line_selected");
		}
		
		
	
	
	}
	
	
	
	function verrechnenSplitBon(){
		xmlhttp=GetXmlHttpObject();
		xmlhttp.open("POST", "include/ajax_functions_splitbon.php", false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		sendCont="functionKey=splittBonBill";	

		xmlhttp.send(sendCont);
		resp=xmlhttp.responseText;
		
		resp=resp.split('-|-');
		
		if (resp[0].toLowerCase().indexOf('success') !== -1){
			newOpenBonId=resp[0];
			
			
			$("#kassieren_id").css({ "display":"block"	});
			$("#aktueller_bon").val(resp[1]);
			curBon=$("#aktueller_bon").val();
			$("#modalTestOp").html(curBon);
			loadBonForSplit();
			
		}
		else console.log('Offener Bon aus Splitbon konnte nicht geblildet werden.');
	}
	
	
	function loadBonForMove(currentBonId, toMoveTableId){				// aufgerufen from kassieren.php, nach menu Anzeigen
	
		console.log("split bon to js: id-> "+" / "+toMoveTableId);
		
		xmlhttp=GetXmlHttpObject();
		xmlhttp.open("POST", "ajax_funktionen.php", false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		sendCont="funktion=bon_anzeigen&id="+currentBonId+"&callFrom=moveTotable&toMoveTableId="+toMoveTableId;		

		xmlhttp.send(sendCont);
		resp=xmlhttp.responseText;
		
		console.log(resp);
		content=resp.split('-|-');
		
		$("#moveBonOriginContent").html(content[0]);
		$("#moveBonContent").html(content[1]);
		
		
	
	
	}
	
	function closeMoveBonModal(){
		$("#moveTableIndicator").val("x");
		$(".move_bon_modal").css({ "display":"none"			});
	
	}
	
		

	function getOpenSplittBonId(){
	
		xmlhttp=GetXmlHttpObject();
		xmlhttp.open("POST", "include/ajax_functions_splitbon.php", false);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		sendCont="functionKey=setOpenSplittBonId";
		
		xmlhttp.send(sendCont);
		resp=xmlhttp.responseText;
	
		if( resp.toLowerCase().indexOf('success') !== -1){
			$('#error_message').html("Split Bon gesetzt.");
		}
		else if(resp.toLowerCase().indexOf('error') !== -1){
			$('#error_message').html("Fehler aufgetreten.");
		}
	
	}

	function moveToTableDetail(){
		if($("#splitBonContent > [id^=splittedLine]").length <= 0){
			$("#splitBonContent").html("<p class='splitBonContMsgP'>Split Container ist leer.</p>");
			setTimeout(function(){	$("#splitBonContent").html("");},1000); 
		
			return false;
		}
		
		$("#moveTableIndicator").val("setByMoveTableDetail");
		$("#moveTableSetTargetForm").submit();
	
	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	