function validateForm(objFrm){
	the_form=objFrm;
	msg='';
	if(the_form.userName.value == '') msg += "ATTENZIONE: USERNAME e' un campo obbligatorio\n";
	if(the_form.pwd.value == '') msg += "ATTENZIONE: PASSWORD e' un campo obbligatorio\n";
	if(the_form.nome.value == '') msg += "ATTENZIONE: NOME e' un campo obbligatorio\n";
	if(the_form.cognome.value == '') msg += "ATTENZIONE: COGNOME e' un campo obbligatorio\n";
	if(the_form.email.value == '') msg += "ATTENZIONE: EMAIL e' un campo obbligatorio\n";
	if(typeof the_form.catcha_code != 'undefined' && the_form.catcha_code.value=='') msg += "ATTENZIONE: devi inserire la scritta riportata nell'immagine\n";

	if(!the_form.cbPrivacy.checked){
		msg += "ATTENZIONE: Senza il consenso alla privacy non è possibile iscriverti.\nCome puoi leggere nell'informativa, il consenso si riferisce esclusivamente alla possibilità di memorizzare nel nostro database i tuoi dati\n";
		the_form.cbPrivacy.checked = true;
	}

	if(msg != ''){
		alert (msg)
		return false;
	} else return checkRight(1);
}

function validateFormLogin(objFrm){
	the_form=objFrm;
	msg='';
	if(the_form.pwd.value == '') msg += "ATTENZIONE: PASSWORD e' un campo obbligatorio\n";
	if(the_form.email.value == '')msg += "ATTENZIONE: EMAIL e' un campo obbligatorio\n";

	if(msg != ''){
		alert (msg)
		return false;
	} else return checkRight(0);
}

function setUN(){
	the_form.userName.value=the_form.email.value;
}

function checkRight( caso ) {
	msg2='';
	if(!checkEmail(the_form.email.value)) msg2 += "ATTENZIONE: EMAIL non valida\n";
	if(checkPWD(the_form.pwd.value)) msg2 += "ATTENZIONE: La password puo' contenere solo lettere e numeri\n";

	if( caso==1 ){
		if(the_form.userName.value != the_form.email.value) msg2+='ATTENZIONE: USERNAME e EMAIL devono essere uguali.\n'
		if(the_form.pwd.value != the_form.pwdConfirm.value) msg2+='ATTENZIONE: Ricontrolla la password, non e\' uguale alla conferma.\n'
		//checkTel();
		//if( typeof(the_form.cap) != 'undefined' && the_form.cap.value != '') checkCAP();
	}

	if (msg2 == ''){
		return true;
	}else{
		alert(msg2);
		return false;
	}
}

function checkCAP() {
	var cap_re = new RegExp("^[0-9]{5}$");
	str = the_form.cap.value
	if(cap_re.test(str) == false) msg2 += "ATTENZIONE: hai inserito un C.A.P. non valido \n";
}
function checkTel() {
	var Tel_re = new RegExp("[0-9\(\)\-/ ]+");
	str = the_form.tel_uff.value
	if(Tel_re.test(str) == false) msg2 += "ATTENZIONE: hai inserito un numero di telefono non valido \n";
}

function checkEmail(strEmail){
	//var email_re = new RegExp(".+@.+\.[a-zA-A]{2,}");
	//var email_re = new RegExp(".+@.+\..+");
	//var email_re = new RegExp(".+@.+\..+");
	//var email_re = new RegExp("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
	var email_re = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$");

	return email_re.test(strEmail);

}

function checkPWD(strUN){

	//var email_re = new RegExp("[a-zA-Z0-9_]","g");
	//return(strUN.match(/[^\w_]/))?0:1;
	var un_re = new RegExp("[^a-zA-Z0-9_]");
	oResult=un_re.test(strUN);
	//alert("alertFun:"+oResult);
	return oResult;

}