// validation form

// If the length of the element's string is 0 then display helper message
function notEmpty(elem, helperMsg){
	
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function submitform(thisform, english)
{
za_form = document.getElementById(thisform);

	var nume = za_form.nume;
	var telefon = za_form.telefon;
	var email = za_form.email;
	var mesaj = za_form.mesaj;
	
	var msgNume = "";
	var msgEmail = "";
	var msgMesaj = "";
	
	if(english == true)
	{
		msgNume = "Please fill in the field 'Name'!";
		msgEmail = "Please fill in the field 'Email'!";
		msgMesaj = "Please fill in the field 'Message'!";
	}
	else
	{
		msgNume = "Va rugam completati campul 'Nume'!";
		msgEmail = "Va rugam completati corect campul 'Email'!";
		msgMesaj = "Va rugam completati corect campul 'Mesaj'!";
	}
	

	if(!notEmpty(nume, msgNume )) {
		return false;
	}
	if(!emailValidator(email, msgEmail )) {
		return false;
	}
	if(!notEmpty(mesaj, msgMesaj )) {
		return false;
	}
	
return true;
}
