function validateSearch(frm){
	if( frm.word.value == '' || frm.word.value == 'cerca nel sito' ){
		alert('Inserire almeno una parola per effettuare una ricerca!');
		frm.word.focus();
		return false;
	}
	if( frm.word.value.length < 3 ){
		alert('Il termine di ricerca deve contenere almeno 3 caratteri!');
		frm.word.focus();
		return false;
	}
	return true;
}

function validateTesi(frm){
	if( frm.pagamento.value == '' ){
		alert('Modalità di pagamento è un campo obbligatorio!');
		frm.pagamento.focus();
		return false;
	}		
	if( returnSelection(frm.condizioni) == 0 ){
		alert("E' necessario accettare le condizioni del servizio!");
		return false;
	}
	return true;
}

function validateOrdine(frm){
	if( frm.email.value == '' ){
		alert('E-mail è un campo obbligatorio!');
		frm.email.focus();
		return false;
	}		
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(frm.email.value)){
		 alert("Formato indirizzo e-mail non valido!");
		 frm.email.focus();
		 return false;
	}
	if( frm.quantita.value == '' || frm.quantita.value == 0 ){
		alert('Quantità richiesta è un campo obbligatorio!');
		frm.quantita.focus();
		return false;
	}
	if( returnSelection(frm.condizioni) == 0 ){
		alert("E' necessario accettare il consenso di acquisto!");
		return false;
	}
	return true;
}

function validateContatto(frm){
	if( frm.email.value == '' ){
		alert('E-mail è un campo obbligatorio!');
		frm.email.focus();
		return false;
	}		
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(frm.email.value)){
		 alert("Formato indirizzo e-mail non valido!");
		 frm.email.focus();
		 return false;
	}
	if( frm.oggetto.value == '' ){
		alert('Oggetto è un campo obbligatorio!');
		frm.oggetto.focus();
		return false;
	}
	if( frm.corpo.value == '' ){
		alert('Messaggio è un campo obbligatorio!');
		frm.corpo.focus();
		return false;
	}		
	if( frm.id_contatto.value == '' ){
		alert('Scrivi a è un campo obbligatorio!');
		frm.id_contatto.focus();
		return false;
	}		
	if( returnSelection(frm.privacy) == 0 ){
		alert("E' necessario accettare il consenso al trattamento dei dati personali ai sensi della Legge 196/2003");
		return false;
	}
	return true;
}

function validateCandidatura(frm){
	if( frm.cognome.value == '' ){
		alert('Cognome è un campo obbligatorio!');
		frm.cognome.focus();
		return false;
	}		
	if( frm.nome.value == '' ){
		alert('Nome è un campo obbligatorio!');
		frm.nome.focus();
		return false;
	}		
	if( frm.email.value == '' ){
		alert('E-mail è un campo obbligatorio!');
		frm.email.focus();
		return false;
	}		
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(frm.email.value)){
		 alert("Formato indirizzo e-mail non valido!");
		 frm.email.focus();
		 return false;
	}
	if( returnSelection(frm.privacy) == 0 ){
		alert("E' necessario accettare il consenso al trattamento dei dati personali ai sensi della Legge 196/2003");
		return false;
	}
	return true;
}

function validateSendmail(frm){
	if( frm.email.value == '' ){
		alert('E-mail è un campo obbligatorio!');
		frm.email.focus();
		return false;
	}		
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(frm.email.value)){
		 alert("Formato indirizzo e-mail non valido!");
		 frm.email.focus();
		 return false;
	}
	if( frm.oggetto.value == '' ){
		alert('Oggetto è un campo obbligatorio!');
		frm.oggetto.focus();
		return false;
	}		
	if( frm.messaggio.value == '' ){
		alert('Messaggio è un campo obbligatorio!');
		frm.messaggio.focus();
		return false;
	}		
	return true;
}

function validateInfoPoint(frm){
	if( frm.titolo.value == '' ){
		alert('Domanda è un campo obbligatorio!');
		frm.titolo.focus();
		return false;
	}		
	return true;
}

function validateLavoro(frm){
	if( frm.titolo.value == '' ){
		alert('Titolo è un campo obbligatorio!');
		frm.titolo.focus();
		return false;
	}		
	return true;
}

function validateComunicato(frm){
	if( frm.titolo.value == '' ){
		alert('Titolo è un campo obbligatorio!');
		frm.titolo.focus();
		return false;
	}		
	return true;
}

function validateLogin(frm){
	if( frm.uid.value == '' ){
		alert('Nome utente è un campo obbligatorio!');
		frm.uid.focus();
		return false;
	}
	if( frm.pwd.value == '' ){
		alert('Password è un campo obbligatorio!');
		frm.pwd.focus();
		return false;
	}
	getId('form').style.display='none';
		
	return true;
}

function validateRePassword(frm){
	if( frm.uid.value == '' ){
		alert('Nome utente è un campo obbligatorio!');
		frm.uid.focus();
		return false;
	}
	return true;
}

function validatePassword(frm){
	if( frm.old.value == '' ){
		alert('Vecchia password è un campo obbligatorio!');
		frm.old.focus();
		return false;
	}
	if( frm.pwd.value == '' ){
		alert('Nuova password è un campo obbligatorio!');
		frm.pwd.focus();
		return false;
	}
	var reg_exp = /^([a-zA-Z0-9_\.\-\@])+$/;
	if ( frm.pwd.value != '' && !reg_exp.test(frm.pwd.value)){
		alert('Formato password non valido!');
		 frm.pwd.focus();
		 return false;
	}
	if( frm.pwd.value != '' && frm.re_pwd.value == '' ){
		alert('Ripeti password è un campo obbligatorio!');
		frm.re_pwd.focus();
		return false;
	}
	if( frm.re_pwd.value != '' && frm.pwd.value != frm.re_pwd.value ){
		 alert("La password ripetuta non è corretta!");
		frm.re_pwd.focus();
		return false;
	}
	return true;
}

function validateUtente(frm, ruolo){
	if( ruolo == 1 ){
		if( frm.cognome.value == '' ){
			alert('Cognome è un campo obbligatorio!');
			frm.cognome.focus();
			return false;
		}
		if( frm.nome.value == '' ){
			alert('Nome è un campo obbligatorio!');
			frm.nome.focus();
			return false;
		}
	}else if( ruolo == 4 ){
		if( frm.nome.value == '' ){
			alert('Nome è un campo obbligatorio!');
			frm.nome.focus();
			return false;
		}
		if( frm.provincia.value == '' ){
			alert('Provincia è un campo obbligatorio!');
			frm.provincia.focus();
			return false;
		}
	}else{
		if( frm.nome.value == '' ){
			alert('Ragione sociale è un campo obbligatorio!');
			frm.nome.focus();
			return false;
		}
		if( getId('settori').style.display == '' ){
			var risp = 0;
			for( i=0; i<frm.elements.length; i++ ){
				 if( frm.elements[i].name == 'settore[]' && frm.elements[i].checked == true )
					 risp++;
			}
			if( risp == 0 || risp > 3 ){
				alert('Devi selezionare almeno uno e al massimo 3 settori di appartenenza!');
				frm.submit.focus();
				return false;
			}
		}
	}
	if( frm.email.value == '' ){
		alert('Indirizzo e-mail è un campo obbligatorio!');
		frm.email.focus();
		return false;
	}
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!email_reg_exp.test(frm.email.value)){
		 alert("Formato indirizzo e-mail non valido!");
		 frm.email.focus();
		 return false;
	}
	if( frm.username.value == '' ){
		alert('Nome utente è un campo obbligatorio!');
		frm.username.focus();
		return false;
	}
	if( frm.password.value == '' ){
		alert('Password è un campo obbligatorio!');
		frm.password.focus();
		return false;
	}
	if( frm.re_pwd.value == '' ){
		alert('Ripeti password è un campo obbligatorio!');
		frm.re_pwd.focus();
		return false;
	}
	if( frm.password.value != frm.re_pwd.value ){
		alert('La password ripetuta non è corretta!');
		frm.re_pwd.focus();
		return false;
	}
	if( returnSelection(frm.privacy) == 0 ){
		alert("E' necessario accettare il consenso al trattamento dei dati personali ai sensi della Legge 196/2003");
		return false;
	}
	
	if( !getId('settori') ){
		getId('form').style.display='none';
		getId('cmd').style.display='none';
	}else if( getId('settori').style.display == '' ){
		getId('settori').style.display='none';
		getId('form').style.display='none';
		getId('cmd').style.display='none';
	}
		
	return true;
}
