/* SKYLIMIT CART */
function Skylimit_Cart(cartbox_id, cart_id, checkout_url)
{
	this.cartbox_id = cartbox_id;
	this.cart_id = cart_id;
	this.checkout_url = checkout_url;
}

Skylimit_Cart.prototype.add = function(product_id, callback, callback_cart)
{
	$(this.cartbox_id).load(this.checkout_url+'a/cart_add', {product_id: product_id}, callback);
	$(cart.cart_id).load(cart.checkout_url+'a/cart_table', {}, callback_cart);
}

Skylimit_Cart.prototype.remove = function(key, callback_cartbox, callback_cart)
{
	var cart = this;
	
	$(this.cartbox_id).load(this.checkout_url+'a/cart_remove', {key: key}, function()
	{
		callback_cartbox();
		$(cart.cart_id).load(cart.checkout_url+'a/cart_table', {key: key}, callback_cart);
	});
	
}

Skylimit_Cart.prototype.changeAmount = function(key, amount, callback_cartbox, callback_cart)
{
	var cart = this;

	$(this.cartbox_id).load(this.checkout_url+'a/cart_changeAmount', {key: key, amount: amount}, function()
	{
		callback_cartbox();
		$(cart.cart_id).load(cart.checkout_url+'a/cart_table', {key: key}, callback_cart);
	});
}

Skylimit_Cart.prototype.amountPlusOne = function(key, callback)
{
	$(this.cartbox_id).load(this.checkout_url+'a/cart_amountPlusOne', {key: key}, callback);
}

Skylimit_Cart.prototype.amountMinOne = function(key, callback)
{
	$(this.cartbox_id).load(this.checkout_url+'a/cart_amountMinOne', {key: key}, callback);
}

Skylimit_Cart.prototype.setCountry = function(country, callback_cartbox, callback_cart)
{
	var cart = this;

	$(this.cartbox_id).load(this.checkout_url+'a/cart_setCountry', {country:country}, function()
	{
		callback_cartbox();
		$(cart.cart_id).load(cart.checkout_url+'a/cart_table', {}, callback_cart);
	});
}

Skylimit_Cart.prototype.setPickup = function(pickup, callback_cartbox, callback_cart)
{
	var cart = this;

	$(this.cartbox_id).load(this.checkout_url+'a/cart_setPickup', {pickup:pickup}, function()
	{
		callback_cartbox();
		$(cart.cart_id).load(cart.checkout_url+'a/cart_table', {}, callback_cart);
	});
}


function Skylimit_Usermanagement(usermanagement_url)
{
	this.usermanagement_url = usermanagement_url;
}

Skylimit_Usermanagement.prototype.login = function(login, password)
{
	var login_ok = false;
	
	$.ajax(
	{
		type: 'POST', 
		url: this.usermanagement_url+'a/ajax_login', 
		data: {login: login, password:password}, 
		success: function(data)
		{
			login_ok = (data=='true');
		},
		dataType: 'text',
		async: false
	});
	
	
	return login_ok;
}

Skylimit_Usermanagement.prototype.logout = function()
{
	$.ajax(
	{
		type: 'POST', 
		url: this.usermanagement_url+'a/ajax_logout', 
		dataType: 'text',
		async: false
	});
}
