function CustomerEdit(customer_id)
{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Admin_Customers_Edit&mode=clear&customer_id="+customer_id,
   success: function(msg){
   	$.modal(msg, { containerCss: ({height: "300px", width: "500px" })});
   
   	Attach_ajaxForm();
   }      
 });
} 
 
 
function OrderItemsUpdate()
{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Customer_NewOrder&action=ShowItems&mode=clear",
   success: function(msg){
   	
   	$('#itemscont').html (msg);
   	
   	if (items_count > 0)
   	{
   		$('#send').attr('disabled', 0);
   		$('#cancel').attr('disabled', 0);
   	}   	
   	else
   	{
   		$('#send').attr('disabled', 1);
   		$('#cancel').attr('disabled', 1);
   	}
   }      
 });		
}

function SyncItemQuan(item_code, quan)
{	
//	if (quan > 0)
	{
		$.ajax({
   		type: "POST",
   		url: "/index.php",
   		data: "bo=BO_Customer_NewOrder&action=SyncItemQuan&mode=clear&item_code=" + item_code + '&quan=' + quan,
 		success: function(msg){
 			OrderItemsUpdate();
 		}
 		});
 	}		
}

function CheckQuan(field)
{
	if (field.value <=0 || isNaN (field.value )	)
	{
		field.value = 0;
	}
}

function CancelOrder()
{
	var ask = confirm ('Czy na pewno chcesz wyczyścić zamówienie?')
	
	if (ask)
	{
	
		$.ajax({
	   type: "POST",
	   url: "/index.php",
	   data: "bo=BO_Customer_NewOrder&action=CancelOrder&mode=clear",
	   success: function(msg){   	   	
	   	OrderItemsUpdate();   
	   }      
	 });
	}		
}

function AddNewItem()
{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Customer_NewOrder&action=PriceList&mode=clear",
   success: function(msg){
   	$.modal(msg, { containerCss: ({height: "500px", width: "600px" })});   	
   
   	$("#filter_phrase").keydown(function(e){if(e.keyCode==13) 
	{		
		UpdateGrid();
	}
	});
	
	BuildFlexiGrid();
   	
   }      
 });
}


function CustomerAddItem(item_code)
{
	// pytanie o ilość
	var quan = prompt ('Podaj liczbę sztuk', 0);
	if (quan > 0)
	{
		$.ajax({
	   type: "POST",
	   url: "/index.php",
	   data: "bo=BO_Customer_NewOrder&action=AddItem&mode=clear&item_code=" + item_code + "&quan=" + quan,
	   success: function(msg){
	   	   	
	   	OrderItemsUpdate();
	   	var ask = confirm ('Pozycja została dodana do zamówienia. Czy dodać kolejną?');
	   	if (!ask)
	   	{
	   		$.modal.close();
	   	}	   	
	   }      
	 });		
	}	
}

function CustomerRemoveItem(item_code)
{
		$.ajax({
	   type: "POST",
	   url: "/index.php",
	   data: "bo=BO_Customer_NewOrder&action=RemoveItem&mode=clear&item_code=" + item_code,
	   success: function(msg){	   			   
	   	OrderItemsUpdate();
	   	
	   }      
	 });		
}

function AdminOrderItems (order_id)
{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Admin_Orders&mode=clear&action=OrderItems&order_id="+order_id,
   success: function(msg){
   	$.modal(msg, { containerCss: ({height: "400px", width: "600px" })});   
   }      
 });
}

function CustomerOrderItems (order_id)
{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Customer_OrdersHistory&mode=clear&action=OrderItems&order_id="+order_id,
   success: function(msg){
   	$.modal(msg, { containerCss: ({height: "400px", width: "500px" })});   
   }      
 });	
}

function CustomerDelete (customer_id)
{
	var ask = confirm ('Czy na pewno usunąć tego kontrahenta?');
	
	if (ask)
	{
	$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Admin_Customers_Edit&action=CustomerDeleteProceed&mode=clear&customer_id="+customer_id,
   success: function(msg){
	UpdateGrid();
   }      
 });
		
	}
}


function GetPriceList()
{
		$.ajax({
   type: "POST",
   url: "/index.php",
   data: "bo=BO_Admin_GetPriceList&mode=clear",
   success: function(msg){
   	alert ('Cennik został uaktualniony');
   	$('#getpl').attr('disabled', 0);
   	UpdateGrid();   
   }      
 });		
}

function CustomerOrderSend()
{
	var ask = confirm ('Czy na pewno chcesz wysłać zamówienie?')
	if (ask)
	{
		return true;
	}
	else
	{
		return false;	
	}
}
