/* 
 * Developed by AMAI bvba (http://amai.be)
 * author: Bram Joris <bram at amai.be)
 */

var EventItemsLoaded = "EventItemsLoaded";
var EventLineLoaded = "EventLineLoaded";
var EventLineCountUpdated = "EventLineCountUpdated";
var EventLineProductAdded = "EventLineProductAdded";
var EventLineProductRemoved = "EventLineProductRemoved";

function RemotingProxy(){
	this.name ="RemotingProxy";
} 

RemotingProxy.prototype.getProducts = function(){
	var self = this;
	$.ajax({
	dataType: 'jsonp',
	type: 'POST',
	url: base_url+'ajax/GetProducts',
	success: function(data) {
		$(self).trigger(EventItemsLoaded,[data]);
	  }
	});
};

RemotingProxy.prototype.addToLine = function( id ){
	var self = this;
	$.ajax({
	dataType: 'jsonp',
	type: 'POST',
	data: { id: id },
	url: base_url+'ajax/addToLine',
	success: function(data) {
		$(self).trigger(EventLineCountUpdated,[data]);
		$(self).trigger(EventLineProductAdded,[data]);
	  }
	});
};

RemotingProxy.prototype.removeFromLine = function( id ){
	var self = this;
	$.ajax({
	dataType: 'jsonp',
	type: 'POST',
	data: { id: id },
	url: base_url+'ajax/removeFromLine',
	success: function(data) {
		$(self).trigger(EventLineCountUpdated,[data]);
		$(self).trigger(EventLineProductRemoved,[data]);
	  }
	});
};

RemotingProxy.prototype.getProductsByParam = function( param ){
	var self = this;
	$.ajax({
	dataType: 'jsonp',
	data: param,
	type: 'POST',
	url: base_url+'ajax/GetProductsByParam',
	success: function(data) {
		$(self).trigger(EventItemsLoaded,[data]);
	  }
	});
};

RemotingProxy.prototype.getProductsFromCategory = function(id){
	var self = this;
	$.ajax({
	dataType: 'jsonp',
	type: 'POST',
	url: base_url+'ajax/GetProductsFromSubcategory/'+id,
	success: function(data) {
		$(self).trigger(EventItemsLoaded,[data]);
	  }
	});
};


RemotingProxy.prototype.getLine = function(){

	var self = this;
	$.ajax({
	dataType: 'jsonp',
	type: 'POST',
	url: base_url+'ajax/getProductsInLine',
	success: function(data) {
		$(self).trigger(EventLineLoaded,[data]);
		
	  }
	});
};

