window.onload=function() {
	
	document.getElementById("sendEmail").onclick=validateEmailSubscription;
	
	document.getElementById("submit").onclick=validateComment;

}

// Validate email
function validateEmailSubscription() {
	
	var email = document.forms["newsletterSubscribe"]["id_email"].value;
	
	var atpos = email.indexOf("@");
	
	var dotpos = email.lastIndexOf(".");
	
	if (atpos<1 || dotpos < atpos+2 || dotpos + 2 >= email.length) {
		
		alert("Du måste ange en giltig e-postadress!");
		
		return false;
		
	}
	else {
			
		alert("Välkommen som ny prenumerant!");	
	
	}
		
}

// Validate comment
function validateComment() {
	
	var commentEmail = document.forms["commentform"]["email"].value;
	
	var commentAuthor = document.forms["commentform"]["author"].value;
	
	var commentText = document.forms["commentform"]["comment"].value;
	
	var atpos = commentEmail.indexOf("@");
	
	var dotpos = commentEmail.lastIndexOf(".");
	
	if (atpos<1 || dotpos < atpos+2 || dotpos + 2 >= commentEmail.length) {
		
		alert("Du måste ange en giltig e-postadress!");
		
		return false;
		
	} else if(commentAuthor == "") {
		
		alert("Du måste fylla i ett namn!");
		
		return false;
	}
	else if(commentText == "") {
		
		alert("Du måste fylla i en kommentar!");
		
		return false;
	}
	else {
			
		alert("Tack för din kommentar!\nDen publiceras efter granskning.");	
	
	}
		
}
