function showarticles() {
	var args = '';
	if (arguments.length == 1) {
		args += '&categoryid='+arguments[0];
	}
	$.ajax({
		data	: "act=showarticles"+args,
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#products").css("height",thedata.elh+'px');
				$("#content").css("height", (thedata.elh)+'px');
				$("#products").html('<img id="aanbiedingen" src="/images/aanbiedingen.jpg">' + thedata.dat);
				$("a[rel^='prettyPhoto']").prettyPhoto({showTitle: false, allowresize: false, theme: 'dark_rounded'});
				var homeleftOH = $("#homeleft").attr("offsetHeight");
				if (homeleftOH) {
					hpalign(homeleftOH)
				}
			}
		}
	});
}
function hpalign (homeleftOH) {
	var homeleftOH = $("#homeleft").attr("offsetHeight") || 0;
	var basketOH = ($("#basket").attr("offsetHeight")) || 0;
	// at the homepage, we need to make the three divs the higher of the three...
	var productsheight = parseInt($("#products").css("height")) || 0;
	var registrationformholderheight = parseInt($("#registrationformholder").css("height")) || 0;
	var confirmationandpaymentformholderheight = parseInt($("#confirmationandpaymentformholder").css("height") +15) || 0;

	var maxheight = Math.max(Math.max(Math.max(basketOH, Math.max(homeleftOH, productsheight)),registrationformholderheight),confirmationandpaymentformholderheight);
	if (basketOH == maxheight) {
		// if the basket is the longest
		//$("#basket").css("height", maxheight +'px');
		$("#content").css("height", maxheight +'px');
	}
	else if (homeleftOH == maxheight) {
		$("#content").css("height", 20+maxheight +'px');
	}
	else if (productsheight == maxheight) {
		$("#content").css("height", 40+maxheight +'px');
	}
	else {
		$("#content").css("height", maxheight +'px');
	}
}
function showbasket() {
	$.ajax({
		data	: "act=showbasket",
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#basket").html(thedata.dat);
				setTimeout("void(0)", 100);
				// if the basked is higher than the products, the latter is 
				// increased
				var basketOH = $("#basket").attr("offsetHeight");
				var homeleftOH = $("#homeleft").attr("offsetHeight") || 0;
				if (homeleftOH) {
					hpalign()
				}
				else if (basketOH > parseInt($("#products").css("height"))) {
					var productsheight = parseInt($("#products").css("height")) || 0;
					var maxheight = Math.max(basketOH, Math.max(homeleftOH, productsheight));
					$("#basket").css("height", maxheight +'px');
					$("#products").css("height", maxheight+'px');
					$("#content").css("height", 5+maxheight +'px');
				}
			}
		}
	});
}
function showbasketregistration() {
	$.ajax({
		data	: "act=showbasket",
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#basket").html(thedata.dat);
				$("#orderbuttonholder").css("display", 'none');
				hpalign();
			}
		}
	});
}
function addtobasket(id) {
	$.ajax({
		data	: "act=addtobasket&id="+id,
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#basket").html(thedata.dat);
				hpalign();
			}
		}
	});
}
function removefrombasket(id) {
	$.ajax({
		data	: "act=removefrombasket&id="+id,
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#basket").html(thedata.dat);
				hpalign();
			}
		}
	});
}
function showregistrationform() {
	$.ajax({
		data	: "act=showregistrationform",
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#registrationformholder").html(thedata.dat);
				$("#orderbuttonholder").css("display", 'none');
			}
		}
	});
}
function saveregistrationform() {
	if (! validateregistrationform()) {
		return false;
	}
	var str = $("#registrationform").serialize();
	$.ajax({
		data	: "act=saveregistrationform&" + str,
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				if (document.getElementById("registrationform")['f[countrycode]'].value == 'be') {
					showbasketregistration();
				}
				location.href = "bevestigenbetaal.php";
			}
		}
	});
}
function validateregistrationform(theform) {
	var theform = document.getElementById("registrationform");
	var errmsg = '';
	var warning = '';
	
	if (! getCheckedRadioValue(theform['f[gender]'])) {
		errmsg += "Er is nog geen geslacht aangegeven.\n";
	}
	if (theform['f[firstname]'].value.trim() == '') {
		errmsg += "Er is nog geen voornaam ingevoerd.\n";
	}
	if (theform['f[lastname]'].value.trim() == '') {
		errmsg += "Er is nog geen achternaam ingevoerd.\n";
	}
	if (theform['f[street]'].value.trim() == '') {
		errmsg += "Er is nog geen adres ingevoerd.\n";
	}
	if (! theform['f[street]'].value.trim().match(/\d/)) {
		warning += "Er lijkt nog geen huisnummer bij het adres te zijn vermeld.\n";
	}
	if (theform['f[postcode]'].value.trim() == '') {
		errmsg += "Er is nog geen postcode ingevoerd.\n";
	}
	if (theform['f[city]'].value.trim() == '') {
		errmsg += "Er is nog geen plaats ingevoerd.\n";
	}
	if (theform['f[countrycode]'].value == '') {
		errmsg += "Er is nog geen land geselecteerd.\n";
	}
	if (theform['f[phonenr]'].value.trim() == '') {
		errmsg += "Er is nog geen telefoonnummer ingevoerd.\n";
	}
	if (theform['f[email]'].value.trim() == '') {
		errmsg += "Er is nog geen e-mail-adres ingevoerd.\n";
	}
	if (errmsg != '') {
		alert(errmsg + warning);
		return false;
	}
	if (warning != '') {
		warning += "Druk op opheffen/cancel om correcties door te voeren, of op OK om de ingevoerde gegevens te bevestigen.\n";
		if (!confirm(warning)) {
			return false;
		}
	}
	return true;
}
function getCheckedRadioValue(radio) {
	for (var i=0; i < radio.length; i++) {
		if (radio[i].checked) return radio[i].value
	}
	return false
}
function showconfirmationandpaymentform() {
	$.ajax({
		data	: "act=showconfirmationandpaymentform",
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				$("#confirmationandpaymentformholder").html(thedata.dat);
			}
		}
	});
}
String.prototype.trim = function () {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function dopaymanual() {
	$.ajax({
		data	: "act=invoicepdf",
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				location.href = "fsuccess.php";
			}
		}
	});
}
function doideal(theform) {
	$.ajax({
		data	: "act=preidealcheck&int1=" + theform.int1.value + "&int2=" + theform.int2.value,
		success	: function(thedata) {
			if (thedata.err)	alert(thedata.err);
			else {
				theform.purchaseID.value = thedata.dat1;
				theform.hash.value = thedata.dat2;
				theform.submit();
			}
		}
	});
	// 
}