function webshop()
{

	this.updateShoppingCart = function()
	{
		req = 'f=updateShoppingCart';
		this.request(req, 'shoppingcart');
	}


	this.addProduct = function(id)
	{
		$.noticeAdd({
			text: 'Item toegevoegd aan winkelwagen',
			stayTime: 1000,
			type: 'notice',
			stay: false
		});
	
		req = 'f=addProduct&id=' + id;
		this.request(req, 'shoppingcart');
	}
	
	
	this.removeProduct = function(id)
	{
		req = 'f=removeProduct&id=' + id;
		this.request(req, 'main');
		this.updateShoppingCart();
	}
	
	
	this.setProductAmount = function(id)
	{
		if($('#' + id).val() > 0)
		{
			req = 'f=setProductAmount&id=' + id + '&amount=' + $('#' + id).val();
			this.request(req, 'main');
			this.updateShoppingCart();
		}
	}
	
	
	this.incProductAmount = function(id)
	{
		req = 'f=incProductAmount&id=' + id;
		this.request(req, 'main');
	}
	
	
	this.decProductAmount = function(id)
	{
		req = 'f=decProductAmount&id=' + id;
		this.request(req, 'main');
	}
	
	
	this.validateForm = function()
	{
		// validate signup form on keyup and submit
		$("#gegevens_form").validate({
		submitHandler: function(form) {
   		var results = $('#gegevens_form').serialize();
    	$.post('/engine/ajax/webshop_ajax.php', results, function(data) {
    		window.location = '/winkelwagen/betalingswijze/';
    	});
   	},
		rules: {
			voorletters: "required",
			geslacht: "required",
			achternaam: "required",
			adres: "required",
			postcode: "required",
			woonplaats: "required",
			telefoon: {
				required: true,
				minlength: 10,
				digits: true
			},
			mail: {
				required: true,
				email: true
			}
		},
		messages: {
			voorletters: "<br />Voer uw voorletters in",
			geslacht: "<br />Voer uw aanhef in",
			achternaam: "<br />Voer uw achternaam in",
			adres: "<br />Voer uw adres in",
			postcode: "<br />Voer uw postcode in",
			woonplaats: "<br />Voer uw woonplaats in",
			telefoon: {
				required: "<br />Voer uw telefoonnummer in",
				minlength: "<br />Voer minimaal 10 cijfers in",
				digits: "<br />U kunt alleen maar cijfers gebruiken in dit veld"
			},
			mail: "<br />Voer een valide e-mail adres in"
		}
		});
	}
	
	
	this.acceptPayment = function()
	{
		var results = $('#betalingswijze_form').serialize();
    $.post('/engine/ajax/webshop_ajax.php', results, function(data) {
    	window.location = '/winkelwagen/overzicht/';
    });
	}
	
	
	this.order = function()
	{	
		$.noticeAdd({
			text: 'Uw bestelling wordt verzonden...',
			stayTime: 1000,
			type: 'notice',
			stay: true
		});
	
		$.ajax({
			url: '/engine/ajax/webshop_ajax.php',
			type: 'POST',
			cache: false,
			data: 'f=order',
			success: function(data)
			{
				if(payment == 'ideal') $('#form').submit();
				else $('#main').html(data);
			}
		});
	}
	
	
	this.request = function(req, target)
	{
		$.ajax({
			url: '/engine/ajax/webshop_ajax.php',
			type: 'POST',
			cache: false,
			data: req,
			success: function(data)
			{
				$('#' + target).html(data);
			}
		});
	}

}


$(document).ready(function() {
	webshop = new webshop();
	webshop.validateForm();
});