
function trimAll(sString) {
	if(sString == undefined)
		return "";

	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function checkPostingForm(form) {

	var author = trimAll(form.author.value);
	var email = trimAll(form.email.value);
	var message = trimAll(form.message.value);
	if(form.email2)
		var email2 = trimAll(form.email2.value);
	else
		var email2 = "";
	var hasErrors = false;
	var errorMessage = "";

	if (form.action_url.value == "") {
		form.action_url.value = form.action;
	}

	if(email2.length > 0) {
		hasErrors = true;
		errorMessage += "Roskapostittajilta pääsy kielletty!\n";
	}

	if (author.length < 1)	{
		hasErrors = true;
		errorMessage += "Nimimerkki on pakollinen tieto!\n";
	}

	if (email.length < 1)	{
		hasErrors = true;
		errorMessage += "Sähköposti on pakollinen tieto!\n";
	}

	if (message.length < 1) {
		hasErrors = true;
		errorMessage += "Viesti on pakollinen tieto!\n";
	}

	if (hasErrors){
		alert(errorMessage);
		return false;
	}

	form.action = form.action_url.value;
	return true;
}
