window.onerror = function () {return true;};

var redirect = '';
var i, f;

function doPost(obj) {
	window.onerror = null;
	f = document.createElement('FORM');
	try {
		i = document.createElement('<IFRAME name="guestbook_iframe" onload=doAfterPost();>');
	} catch (e) {
		i = document.createElement('IFRAME');
		i.name = "guestbook_iframe";
		i.onload = doAfterPost;
	}

	redirect = obj.redirect.value;
	
	f.style.height = f.style.width = 0;
	i.style.height = i.style.width = 0;

	f.action = "http://guestbook.cmsbasic.nl/action.asp?r=" + escape("http://" + window.location.host + "/dummy.html");
	f.method = "POST";
	f.target = "guestbook_iframe";

	var node;
	for (var x=0; x<obj.elements.length; x++) {
		node = f.appendChild(obj.elements[x].cloneNode(true));
		node.value = obj.elements[x].value;
	}
	document.body.appendChild(f);
	document.body.appendChild(i);
	
	f.submit();
}

function doAfterPost() {
	var code = parseInt(i.contentWindow.document.location.search.substring(6));
	document.body.removeChild(f);
	document.body.removeChild(i);
	var msg = '';
	if ((code & 8) == 8) { msg += 'Naam is een verplicht veld.\n\r'}
	if ((code & 4) == 4) { msg += 'E-mail is een verplicht veld.\n\r'}
	if ((code & 2) == 2) { msg += 'Plaats is een verplicht veld.\n\r'}
	if ((code & 1) == 1) { msg += 'Bericht is een verplicht veld.\n\r'}
	
	if (msg != '') {
		alert(msg);
	} else {
		window.location.href = redirect + "?" + Math.ceil(Math.random()*99999);
	}
}

