function CheckCampiProfiloUser()
{
	var nome    	= trim(document.formModUser.nome.value);
	var cognome   = trim(document.formModUser.cognome.value);
	var indirizzo = trim(document.formModUser.indirizzo.value);
	var cap 			= trim(document.formModUser.cap.value);
	var citta 		= trim(document.formModUser.citta.value);
	var telefono 	= trim(document.formModUser.telefono.value);
	var fax 			= trim(document.formModUser.fax.value);
	var cellulare = trim(document.formModUser.cellulare.value);
	var email 		= trim(document.formModUser.email.value);
	var cv 				= trim(document.formModUser.cv.value);
	var passwd 		= trim(document.formModUser.password.value);
	var retpasswd = trim(document.formModUser.retpassword.value);
	
	if ((nome == "") || (nome == "undefined"))
  {
  	alert("Il campo Nome e\' obbligatorio.");
    document.formModUser.nome.focus();
    return false;
  }
  
  if ((cognome == "") || (cognome == "undefined"))
  {
  	alert("Il campo Cognome e\' obbligatorio.");
    document.formModUser.cognome.focus();
    return false;
  }
  
  if ((indirizzo == "") || (indirizzo == "undefined"))
  {
  	alert("Il campo Indirizzo e\' obbligatorio.");
    document.formModUser.indirizzo.focus();
    return false;
  }
  
  if ((citta == "") || (citta == "undefined"))
  {
  	alert("Il campo Citta\' e\' obbligatorio.");
    document.formModUser.citta.focus();
    return false;
  }
  
  if (((telefono == "") || (telefono == "undefined"))&&
     ((cellulare == "") || (cellulare == "undefined")))
  {
  	alert("Un campo tra Telefono e Cellulare e\' obbligatorio.");
    document.formModUser.telefono.focus();
    return false;
  }

  if ((email == "") || (email == "undefined"))
  {
  	alert("Il campo Email e\' obbligatorio.");
    document.formModUser.email.focus();
    return false;
  }

	if (!isEmail(email))
	{
		alert("Il formato del campo Email non e\' corretto");
		document.formModUser.email.focus();
    return false;
	}
	
	if (checkExtension(cv)==false)
  {
  	alert("L\'estensione del file "+cv+" non e\' consentita (PDF/DOC/RTF/DOCX)");
  	return false;
  }   
  
  if ((passwd != "") && (passwd != "undefined"))
  {
		if(passwd!=retpasswd)
  	{
  		alert("Attenzione le 2 password inserite devono coincidere.");
  		document.formModUser.password.focus();
  		return false;
  	}
  }
  
  return true;
}

function CheckCampiNewUser()
{
	var nome    	= trim(document.formNewUser.nome.value);
	var cognome   = trim(document.formNewUser.cognome.value);
	var indirizzo = trim(document.formNewUser.indirizzo.value);
	var cap 			= trim(document.formNewUser.cap.value);
	var citta 		= trim(document.formNewUser.citta.value);
	var telefono 	= trim(document.formNewUser.telefono.value);
	var fax 			= trim(document.formNewUser.fax.value);
	var cellulare = trim(document.formNewUser.cellulare.value);
	var email 		= trim(document.formNewUser.email.value);
	var cv 				= trim(document.formNewUser.cv.value);
	var passwd 		= trim(document.formNewUser.password.value);
	var retpasswd = trim(document.formNewUser.retpassword.value);
	
	if ((nome == "") || (nome == "undefined"))
  {
  	alert("Il campo Nome e\' obbligatorio.");
    document.formNewUser.nome.focus();
    return false;
  }
  
  if ((cognome == "") || (cognome == "undefined"))
  {
  	alert("Il campo Cognome e\' obbligatorio.");
    document.formNewUser.cognome.focus();
    return false;
  }
  
  if ((indirizzo == "") || (indirizzo == "undefined"))
  {
  	alert("Il campo Indirizzo e\' obbligatorio.");
    document.formNewUser.indirizzo.focus();
    return false;
  }
  
  if ((citta == "") || (citta == "undefined"))
  {
  	alert("Il campo Citta\' e\' obbligatorio.");
    document.formNewUser.citta.focus();
    return false;
  }
  
  if (((telefono == "") || (telefono == "undefined"))&&
     ((cellulare == "") || (cellulare == "undefined")))
  {
  	alert("Un campo tra Telefono e Cellulare e\' obbligatorio.");
    document.formNewUser.telefono.focus();
    return false;
  }

  if ((email == "") || (email == "undefined"))
  {
  	alert("Il campo Email e\' obbligatorio.");
    document.formNewUser.email.focus();
    return false;
  }

	if (!isEmail(email))
	{
		alert("Il formato del campo Email non e\' corretto");
		document.formNewUser.email.focus();
    return false;
	}
	
	if (checkExtension(cv)==false)
  {
  	alert("L\'estensione del file "+cv+" non e\' consentita (PDF/DOC/RTF/DOCX)");
  	return false;
  }
  
  if ((passwd == "") || (passwd == "undefined"))
  {
  	alert("Il campo Password non puo\' essere vuoto.");
    document.formNewUser.password.focus();
    return false;
  }
  
  if ((retpasswd == "") || (retpasswd == "undefined"))
  {
  	alert("Il campo Ridigita Password non puo\' essere vuoto.");
    document.formNewUser.password.focus();
    return false;
  }
  
	if(passwd!=retpasswd)
  {
  	alert("Attenzione le 2 password inserite devono coincidere.");
  	document.formNewUser.password.focus();
  	return false;
  } 
  
  return true;
}

function trim(str)
{
	return str.replace(/^\s+|\s+$/g, '');
}

function isnumber(data)
{
	var numstr="0123456789";
	var thischar;
	var counter=0;
		
	for(var i=0;i<data.length;i++)
	{
		thischar=data.substring(i,i+1)
		if(numstr.indexOf(thischar) != -1)
		{
			counter++;
		}
	}		
	if(counter==data.length)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function checkExtension(nomefile)
{	
	if ((nomefile!="") && (nomefile!="undefined"))
	{						
		if((get_estensione(nomefile)!="PDF")&&
			 (get_estensione(nomefile)!="DOC")&& 
			 (get_estensione(nomefile)!="RTF")&&
			 (get_estensione(nomefile)!="DOCX"))
		{			
			return false;
		}
	}	
	return true;		
}

function get_estensione(path)
{
  posizione_punto=path.lastIndexOf(".");
	lunghezza_stringa=path.length;
	estensione=path.substring(posizione_punto+1,lunghezza_stringa);	
	return estensione.toUpperCase();
}

function CheckCampiModUser()
{
	var password    	 = document.formModUser.Passwd.value;
	var newPassword    = document.formModUser.NewPasswd.value;
	var retNewPassword = document.formModUser.RetypeNewPasswd.value;
	
	if ((password == "") || (password == "undefined"))
  {
  	alert("Il campo Password e\' obbligatorio.");
    document.formModUser.Passwd.focus();
    return false;
  }
  
  if ((newPassword == "") || (newPassword == "undefined"))
  {
  	alert("Il campo nuova password e\' obbligatorio.");
    document.formModUser.NewPasswd.focus();
    return false;
  }
  
	if(newPassword!=retNewPassword)
  {
  	alert("Attenzione le 2 password inserite devono coincidere");
  	document.formModUser.NewPasswd.focus();
  	return false;
  }
  return true;
}

function isEmail(email)
{
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
	{
		return true;
	}
	return false;
}

function validateFloat(obj, nLength, nPrecision)
{
	var strVal = new String(obj.value);
  var nIndexOfDot = strVal.indexOf('.');
  var nValidLength = nIndexOfDot==-1?strVal.length:strVal.length+1
  
  if(strVal.length==0)
 	{
  	return true;
  }
  
  if(strVal.charAt(strVal.length-1)!='.' || nIndexOfDot!=(strVal.length-1))
 	{
  	if(isNaN(parseFloat(strVal)))
 		{
    	strVal='0';
    }
    obj.value=parseFloat(strVal);
   }
   
  if(-1!=nIndexOfDot && strVal.substring(nIndexOfDot+1).length>nPrecision)
  {
  	strVal=strVal.substring(0, strVal.length-1);
    obj.value=strVal;
  }
}

function verificaNotificaLettura(notificaFlag)
{
	if(notificaFlag==1)
	{
		valueNotificaLettura=confirm("Il mittente ha richiesto la notifica di lettura\nInviarla?");
		document.form.notificaLettura.value=valueNotificaLettura;
	}
	else
	{
		document.form.notificaLettura.value=false;		
	}
}
