// Controlla se l'indirizzo mail ่ corretto
function isValidEMail(ind){
	
   	var l=ind.length;
   	
   	if (l<6)
   	   	return false;

	var k = ind.indexOf('@');
	if (k == -1)
        return false;
   	
   	if ((ind.charAt(l-3)!='.') && (ind.charAt(l-4)!='.') && (ind.charAt(l-5)!='.'))
   		return false;
   	
   	return true;
}

// ritorna true se una stringa รจ vuota
function isEmpty(str){
	if ((str==null) || (str==""))
		return true;
	return false;
} 
// ritorna false se una stringa รจ vuota
function isNotEmpty(str){
	return !isEmpty(str);
}

// Validator per il form dei commenti
function validateComment(){
	tinyMCE.triggerSave();
	var nome = document.getElementById('nome');
	var e_mail = document.getElementById('e_mail');
	var testo = document.getElementById('testo');
	
	if (isEmpty(nome.value)){
		alert('Il campo \"Nome\" e\' richiesto!')
		nome.focus();
		return false;
	}
	if (!isValidEMail(e_mail.value)){
		alert('Il campo \"E-mail\" deve contenere un indirizzo mail valido!');
		e_mail.focus();
		return false;
	}
	if (isEmpty(testo.value)){
		alert('Il commento non puo\' essere vuoto!');
		testo.focus();
		return false;
	}

	return true;
}

// Validator per il form Contattaci
function validateContattaci(){
	var nome = document.getElementById('from');
	var e_mail = document.getElementById('fromMail');
	var oggetto = document.getElementById('subject');
	
	if (isEmpty(nome.value)){
		alert('Il campo \"Nome\" e\' richiesto!')
		nome.focus();
		return false;
	}
	
	if (!isValidEMail(e_mail.value)){
		alert('Il campo \"E-mail\" deve contenere un indirizzo mail valido!');
		e_mail.focus();
		return false;
	}
	
	if (isEmpty(oggetto.value)){
		alert('Il campo \"Oggetto\" e\' richiesto!')
		oggetto.focus();
		return false;
	}

	return true;
}
