// JavaScript Document



// data una stringa controlla che sia un valido indirizzo email 
function indirizzoEmailValido(str) {
	if (window.RegExp) {
    	var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    	var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    	var regnv = new RegExp(nonvalido);
    	var regv = new RegExp(valido);
    	if (!regnv.test(str) && regv.test(str))
      		return true;
    	return false;
	} else {
    	if(str.indexOf("@") >= 0)
      		return true;
    	return false;
  	}
}


// data una stringa controlla che sia un numero
function is_numero(str){
	var nr="1234567890.";
	
	// se la stringa è vuota va bene
	if (str=="")
		return true;
		
	for (i=0; i<=(str.length-1); i++)
		if (nr.indexOf(str.charAt(i))==(-1))
			return false;

	return true;		
}



// validazione form contatti
function fn_check_contatti() {
	
	if (document.frmContatti.nome.value==''){
		alert("Il campo 'NOME' e' obbligatorio.");
		return false;
	}
	if (document.frmContatti.cognome.value==''){
		alert("Il campo 'COGNOME' e' obbligatorio.");
		return false;
	}
/*	if ((document.frmContatti.cap.value!='')&&(!is_numero(document.frmContatti.cap.value))){
		alert("Il campo 'CAP' non e' corretto.");
		return false;
	}
	
	if ((document.frmContatti.cap.value!='')&&(!is_numero(document.frmContatti.tel.value))){
		alert("Il campo 'TELEFONO' non e' corretto.");
		return false;
	}
	if ((document.frmContatti.cap.value!='')&&(!is_numero(document.frmContatti.cel.value))){
		alert("Il campo 'CELLULARE' non e' corretto.");
		return false;
	}
	*/
	if (document.frmContatti.email.value==''){
		alert("Il campo 'EMAIL' e' obbligatorio.");
		return false;
	}
	if (!indirizzoEmailValido(document.frmContatti.email.value)) {
		alert("Il campo 'EMAIL' non e' corretto.");
		return false;
	}
	if (document.frmContatti.note.value==''){
		alert("Il campo 'NOTE' e' obbligatorio.");
		return false;
	}
	
	
	if (!document.frmContatti.chkPrivacy.checked){
		alert("Il consenso alla 'PRIVACY' e' obbligatorio.");
		return false;
	}
	return true;
}


