    $(document).ready(function() {
		changeclient = function(){
			id_client=$('#selected_client').val();
			$.ajax({
			url: "../inc/json.php",
			dataType: "json",
				data: {
					tip: "client",
					id: id_client
				},
				success: function( data ) {
					var client=data.clients[0];
						$('#client_name').val(client.name);
						$('#client_email').val(client.email);
						$('#client_phone').val(client.phone);
						$('#client_address').val(client.address);
						$('#client_location').val(client.location);
				},
				  error: function (xhr, ajaxOptions, thrownError) {
					alert(xhr.status);
					alert(thrownError);
				  }
			});
		}		
		
		changeprod = function(){
			id_prod=$('#selected_prod').val();
			$.ajax({
			url: "../inc/json.php",
			dataType: "json",
				data: {
					tip: "products",
					id: id_prod
				},
				success: function( data ) {
					var prod=data.products[0];
						$('#product_name').val(prod.title);
						$('#product_description').val(prod.description);
						$('#product_price').val(prod.price);
				},
				  error: function (xhr, ajaxOptions, thrownError) {
					alert(xhr.status);
					alert(thrownError);
				  }
			});
		}
		
		
addproduct =function(){
	$('.req').removeClass('error');
	if($('#product_name').val()==''){
		$('#product_name').addClass('error');
	}	
	if($('#product_price').val()==''){
		$('#product_price').addClass('error');
	}	
	if($('#product_qty').val()==''){
		$('#product_qty').addClass('error');
	}	
		if($('.req').hasClass('error')){
			alert('ai eroare!');
		}else{
			$('.ui-popup').popup("close");		
			$.ajax({
			   type: "POST",
			   url: "inc/addprod.php",
			   data: "action=add&"+$('#formaddprod').serialize(),
			   success: function(msg){
					$('#product_qty').val(1);$('#product_price').val('');$('#product_name').val('');$('#product_description').val('');
					$('#ajaxreturn').html(msg);
			   }
			 });
		}
	return false;
}


refresh_prods =function(){
			$.ajax({
			   type: "POST",
			   url: "inc/addprod.php",
			   data: "action=refresh",
			   success: function(msg){
					$('#ajaxreturn').html(msg);
			   }
			 });
}

deleteprod =function(id){
			$.ajax({
			   type: "POST",
			   url: "inc/addprod.php",
			   data: "action=delete&id="+id,
			   success: function(msg){
					$('#ajaxreturn').html(msg);
			   }
			 });
			 return false;
}

update_prod =function(id,rule){
			$.ajax({
			   type: "POST",
			   url: "inc/addprod.php",
			   data: "action=update&rule="+rule+"&id="+id,
			   success: function(msg){
					$('#ajaxreturn').html(msg);
			   }
			 });
			 return false;
}	
		
	});