var btnWhichButton;

function checkLogin()
{
	var username    = document.formLogin.username.value;
	var passwd    = document.formLogin.password.value;	
	
	if ((username == "undefined") || (trim(username) == ""))
  {
  	alert("Il campo username e\' obbligatorio.");
    document.formLogin.username.focus();
    return false;
  }
  
  if ((passwd == "undefined") || (trim(passwd) == ""))
  {
  	alert("Il campo password e\' obbligatorio.");
    document.formLogin.password.focus();
    return false;
  }  
  return true;
}


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 checkUploadFile(data)
{	
	if(btnWhichButton.value == 'Annulla') return true;
	
	var i=1;
	var nomefile;
	var nome;
	var errore ="";
	for (i=1;i<=data;i++)
	{
		nome = "foto_"+i;
		nomefile = document.formUpload[nome].value;
		if ((nomefile=="undefined") || (trim(nomefile)==""))
		{
			continue;
		}
		else if((get_estensione(nomefile)!="JPG") &&
					  (get_estensione(nomefile)!="JPEG")&& 
					  (get_estensione(nomefile)!="GIF") &&
					  (get_estensione(nomefile)!="PNG"))
		{
			errore = errore+"L\'estensione del file "+nomefile+" non e\' consentita (jpg/jpeg/gif/png)\n";
		}	
	}
	
	if(errore!="")
	{
		alert(errore);
		return false;
	}
	else
	{
		return true;
	}
}

function checkExtensionAllegato()
{	
	var nomefile;
	var nome;
	var errore ="";

	if(btnWhichButton.value == 'Annulla') return true;
	
	nome = "allegato";
	nomefile = document.formUpload[nome].value;	

	if ((nomefile!="undefined") && (trim(nomefile)!=""))
	{
		if((get_estensione(nomefile)!="DOC")&&			  
			 (get_estensione(nomefile)!="PDF"))
		{
			errore = errore+"L\'estensione del file "+nomefile+" non e\' consentita (doc/pdf)\n";
		}		
	}
	else
	{
		errore = errore + "Attenzione nessun file selezionato per l'upload\n";		
	}

	if(errore!="")
	{
		alert(errore);
		return false;
	}
	return true;
}

function checkExtension(data)
{
	var nome;
	var nomefile;
	var i=1;
	var cont=0;
	var errore ="";
	
	if(btnWhichButton.value == 'Annulla') return true;
	
	for (i=1;i<=data;i++)
	{
		nome = "foto_"+i;
		nomefile = document.formUpload[nome].value;
		if ((nomefile!="undefined") && (trim(nomefile)!=""))
		{
			if((get_estensione(nomefile)!="JPG") &&
				 (get_estensione(nomefile)!="JPEG")&& 
				 (get_estensione(nomefile)!="GIF") &&
				 (get_estensione(nomefile)!="PNG"))
			{
				errore = errore+"L\'estensione del file "+nomefile+" non e\' consentita (jpg/jpeg/gif/png)\n";
			}
		}
		else
		{
			cont++;
		}
	}
	if(cont==data)
	{
		alert("Attenzione nessun file selezionato per l'upload");
		return false;
	}
	if(errore!="")
	{
		alert(errore);
		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 checkCampiCambioPassword()
{	
	if(btnWhichButton.value == 'Annulla') return true;
	
	var password    	 = document.frmCambioPasswordUser.Passwd.value;	
	var newPassword    = document.frmCambioPasswordUser.NewPasswd.value;	
	var retNewPassword = document.frmCambioPasswordUser.RetypeNewPasswd.value;

	if ((password == "undefined") || (trim(password) == ""))
  {
  	alert("Il campo Password e\' obbligatorio.");
    document.frmCambioPasswordUser.Passwd.focus();
    return false;
  }

  if ((newPassword == "undefined") || (trim(newPassword) == ""))
  {
  	alert("Il campo nuova password e\' obbligatorio.");
    document.frmCambioPasswordUser.NewPasswd.focus();
    return false;
  }

	if(newPassword!=retNewPassword)
  {
  	alert("Attenzione la nuova password non coincide con quella ridigitata");
  	document.frmCambioPasswordUser.NewPasswd.focus();
  	return false;
  }
  return true;
}

function checkCampiUtenteAssociato(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;

	var selezionePassword      = getCheckedValue(document[nomeForm].selezionepassword);

  var enteUtenteAssociato    = document[nomeForm].EnteUtenteAssociato.value;
	var nomeUtenteAssociato    = document[nomeForm].NomeUtenteAssociato.value;
	var cognomeUtenteAssociato = document[nomeForm].CognomeUtenteAssociato.value;
	var emailUtenteAssociato   = document[nomeForm].IndirizzoEmailUtenteAssociato.value;
	var indirizzoAssociato     = document[nomeForm].IndirizzoAssociato.value;

	var userUtenteAssociato    = document[nomeForm].UsernameUtenteAssociato.value;
	var passwdUtenteAssociato  = document[nomeForm].PasswordUtenteAssociato.value;
	var retPwdUtenteAssociato  = document[nomeForm].RidigitaPasswordUtenteAssociato.value;

  if ((enteUtenteAssociato == "undefined") || (trim(enteUtenteAssociato) == ""))
  {
  	alert("Errore: Il campo Ente Referente e\' obbligatorio.");
   	document[nomeForm].EnteUtenteAssociato.focus();
    return false;
  }
  
	if ((nomeUtenteAssociato == "undefined") || (trim(nomeUtenteAssociato) == ""))
  {
  	alert("Errore: Il campo Nome Referente e\' obbligatorio.");
   	document[nomeForm].NomeUtenteAssociato.focus();
    return false;
  }

  if ((cognomeUtenteAssociato == "undefined") || (trim(cognomeUtenteAssociato) == ""))
  {
  	alert("Errore: Il campo Cognome Referente e\' obbligatorio.");
   	document[nomeForm].CognomeUtenteAssociato.focus();
    return false;
  }

  if ((emailUtenteAssociato == "undefined") || (trim(emailUtenteAssociato) == ""))
  {
  	alert("Errore: Il campo Indirizzo Email Referente e\' obbligatorio.");
   	document[nomeForm].IndirizzoEmailUtenteAssociato.focus();
    return false;
  }

  if(!isEmail(emailUtenteAssociato))
  {
  	alert("Errore: Il formato dell'Indirizzo Email Referente non e\' corretto");
   	document[nomeForm].IndirizzoEmailUtenteAssociato.focus();
    return false;
  }

  if ((indirizzoAssociato == "undefined") || (trim(indirizzoAssociato) == ""))
  {
  	alert("Errore: Il campo Indirizzo Referente e\' obbligatorio.");
   	document[nomeForm].IndirizzoAssociato.focus();
    return false;
  }  

  if ((userUtenteAssociato == "undefined") || (trim(userUtenteAssociato) == ""))
  {
  	alert("Errore: Il campo Username Referente e\' obbligatorio.");
   	document[nomeForm].UsernameUtenteAssociato.focus();
    return false;
  }

  if (selezionePassword!="NessunaModifica")
  {
    if ((passwdUtenteAssociato == "undefined") || (trim(passwdUtenteAssociato) == ""))
    {
  	  alert("Errore: Il campo Password Referente e\' obbligatorio.");
   	  document[nomeForm].PasswordUtenteAssociato.focus();
      return false;
    }

    if (passwdUtenteAssociato != retPwdUtenteAssociato)
    {
  	  alert("Errore: La password del referente inserita e quella ridigitata devono coincidere");
   	  document[nomeForm].PasswordUtenteAssociato.focus();
      return false;
    }
  }

  return true;
}

function checkCampiNews(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloNews = document[nomeForm].TitoloNews.value;
	var testoNews  = tinyMCE.get("TestoNews").getContent();
  var dataNews   = document[nomeForm].DataNews.value;
   
	if ((titoloNews == "undefined") || (trim(titoloNews) == ""))
  {
  	alert("Errore: Il campo Titolo News e\' obbligatorio.");
   	document[nomeForm].TitoloNews.focus();
    return false;
  }

  if ((testoNews == "undefined") || (trim(testoNews) == ""))
  {
  	alert("Errore: Il campo Testo News e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "TestoNews");
    tinyMCE.execCommand("mceFocus", false, "TestoNews");
    return false;
  }

  if ((dataNews == "undefined") || (trim(dataNews) == ""))
  {
  	alert("Errore: Il campo Data News e\' obbligatorio.");
   	document[nomeForm].DataNews.focus();
    return false;
  }
  
  return true;
}

function checkCampiRicerca(nomeForm)
{			
	var criteriRicerca = document[nomeForm].CriteriRicerca.value;
	 
	if ((criteriRicerca == "undefined") || (trim(criteriRicerca) == ""))
  {
  	alert("Errore: Per effettuare la ricerca e\' necessario specificare i criteri desiderati");
   	document[nomeForm].CriteriRicerca.focus();
    return false;
  }
  return true;
}


function checkCampiNewsStampa(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloNews = document[nomeForm].TitoloNews.value;
	var testoNews  = tinyMCE.get("TestoNews").getContent();
  var dataNews   = document[nomeForm].DataNews.value;
  var nomeFoto   = document[nomeForm].fotoNews.value;
  var nomeAllegato = document[nomeForm].allegatoNews.value;

	if ((titoloNews == "undefined") || (trim(titoloNews) == ""))
  {
  	alert("Errore: Il campo Titolo News e\' obbligatorio.");
   	document[nomeForm].TitoloNews.focus();
    return false;
  }

  if ((testoNews == "undefined") || (trim(testoNews) == ""))
  {
  	alert("Errore: Il campo Testo News e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "TestoNews");
    tinyMCE.execCommand("mceFocus", false, "TestoNews");
    return false;
  }

  if ((dataNews == "undefined") || (trim(dataNews) == ""))
  {
  	alert("Errore: Il campo Data News e\' obbligatorio.");
   	document[nomeForm].DataNews.focus();
    return false;
  }
  
  if ((nomeFoto != "undefined") && (trim(nomeFoto) != ""))
  {
    if((get_estensione(nomeFoto)!="JPG") &&
		   (get_estensione(nomeFoto)!="JPEG")&& 
		   (get_estensione(nomeFoto)!="GIF") &&
		   (get_estensione(nomeFoto)!="PNG"))
    {
			alert("L\'estensione del file "+nomeFoto+" non e\' consentita (jpg/jpeg/gif/png)");
			return false;
		}
  }

  if ((nomeAllegato != "undefined") && (trim(nomeAllegato) != ""))
  {
    if(get_estensione(nomeAllegato)!="PDF")
    {
			alert("L\'estensione del file "+nomeAllegato+" non e\' consentita (pdf)");
			return false;
		}
  }

  return true;
}

function checkCampiEventi(nomeForm)
{
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloEvento = document[nomeForm].TitoloEvento.value;
	var testoEvento  = tinyMCE.get("TestoEvento").getContent();
  var dataEvento   = document[nomeForm].DataEvento.value;
  var fotoEvento   = document[nomeForm].fotoEvento.value;

	if ((titoloEvento == "undefined") || (trim(titoloEvento) == ""))
  {
  	alert("Errore: Il campo Titolo Evento e\' obbligatorio.");
   	document[nomeForm].TitoloEvento.focus();
    return false;
  }

  if ((testoEvento == "undefined") || (trim(testoEvento) == ""))
  {
  	alert("Errore: Il campo Testo Evento e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "TestoEvento");
    tinyMCE.execCommand("mceFocus", false, "TestoEvento");
    return false;
  }

  if ((dataEvento == "undefined") || (trim(dataEvento) == ""))
  {
  	alert("Errore: Il campo Data Evento e\' obbligatorio.");
   	document[nomeForm].DataEvento.focus();
    return false;
  }
  
  if ((fotoEvento != "undefined") && (trim(fotoEvento) != ""))
  {
    if((get_estensione(fotoEvento)!="JPG") &&
		   (get_estensione(fotoEvento)!="JPEG")&& 
		   (get_estensione(fotoEvento)!="GIF") &&
		   (get_estensione(fotoEvento)!="PNG"))
    {
			alert("L\'estensione del file "+fotoEvento+" non e\' consentita (jpg/jpeg/gif/png)");
			return false;
		}
  }
  
  return true;
}

function checkCampiVideo(nomeForm)
{
  
	if(btnWhichButton.value == 'Annulla') return true;	

	var nomeVideo  = document[nomeForm].NomeVideo.value;
  var dataVideo  = document[nomeForm].DataInserimentoVideo.value;
  var tipoVideo  = getCheckedValue(document[nomeForm].groupTipoVideo);   
  var linkVideoLocale  = document[nomeForm].LinkVideoLocale.value;
  var linkVideoYoutube = document[nomeForm].LinkVideoYoutube.value;

  var opzioniVideo = getCheckedValue(document[nomeForm].GroupOpzioniVideo);   

  
	if ((nomeVideo == "undefined") || (trim(nomeVideo) == ""))
  {
  	alert("Errore: Il campo Nome Video e\' obbligatorio.");
   	document[nomeForm].NomeVideo.focus();
    return false;
  }
  else if ((dataVideo == "undefined") || (trim(dataVideo) == ""))
  {
  	alert("Errore: Il campo Data Video  e\' obbligatorio.");
   	document[nomeForm].DataInserimentoVideo.focus();
    return false;
  }  
  else if (tipoVideo == "0")
  {     
    if ((linkVideoLocale != "undefined") && (trim(linkVideoLocale) != ""))
    {
      if(get_estensione(linkVideoLocale)!="FLV")
      {
  			alert("L\'estensione del file "+linkVideoLocale+" non e\' consentita (flv)");
  			return false;
  		}
    }
    else
    {
       if (((opzioniVideo == "undefined") || (trim(opzioniVideo) == ""))||(opzioniVideo=="1"))
       {
        alert("Errore: Il campo Link Video Locale e\' obbligatorio.");
        return false;
       }      
    }
  }
  else if (tipoVideo == "1")
  {
    if ((linkVideoYoutube == "undefined") || (trim(linkVideoYoutube) == ""))
    {
        alert("Errore: Il campo Link Video Youtube e\' obbligatorio.");
        document[nomeForm].LinkVideoYoutube.focus();
  			return false;
    } 
  }
  
  return true;
}

function checkCampiLinkUtili(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloLinkUtile = document[nomeForm].TitoloLinkUtile.value;
	var descLinkUtile   = tinyMCE.get("DescrizioneLinkUtile").getContent();
  var urlLinknUtile   = document[nomeForm].UrlLinkUtile.value;
  var idCategoria     = document[nomeForm].IdCategoria.value;

	if ((titoloLinkUtile == "undefined") || (trim(titoloLinkUtile) == ""))
  {
  	alert("Errore: Il campo Nome Link Utile e\' obbligatorio.");
   	document[nomeForm].TitoloLinkUtile.focus();
    return false;
  }

  if ((descLinkUtile == "undefined") || (trim(descLinkUtile) == ""))
  {
  	alert("Errore: Il campo Descrizione Link Utile e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "DescrizioneLinkUtile");
    tinyMCE.execCommand("mceFocus", false, "DescrizioneLinkUtile");
    return false;
  }

  if ((urlLinknUtile == "undefined") || (trim(urlLinknUtile) == ""))
  {
  	alert("Errore: Il campo URL Link Utile e\' obbligatorio.");
   	document[nomeForm].UrlLinkUtile.focus();
    return false;
  }
  
  if ((idCategoria == "undefined") || (trim(idCategoria) == ""))
  {
  	alert("Errore: Il campo Categoria Link Utili e\' obbligatorio.\nSe non esiste nessuna categoria crearla nell\' apposita sezione");
   	document[nomeForm].IdCategoria.focus();
    return false;
  }

  return true;
}

function checkCampiServiziAssociati(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	
  
	var nomeServizio = document[nomeForm].NomeServizioAssociato.value;
	var descServizio = tinyMCE.get("DescServizio").getContent();
	var dataServizio = document[nomeForm].DataServizioAssociato.value;  
  var allegatoServizio = document[nomeForm].allegatoServizioAssociato.value;

  var opzioniAllegatoServizio = getCheckedValue(document[nomeForm].GroupOpzioniAllegato);
  
	if ((nomeServizio == "undefined") || (trim(nomeServizio) == ""))
  {
  	alert("Errore: Il campo Nome Servizio e\' obbligatorio.");
   	document[nomeForm].NomeServizioAssociato.focus();
    return false;
  }
  
  if ((descServizio == "undefined") || (trim(descServizio) == ""))
  {
  	alert("Errore: Il campo Descrizione e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "DescServizio");
    tinyMCE.execCommand("mceFocus", false, "DescServizio");
    return false;
  }
  
  if ((dataServizio == "undefined") || (trim(dataServizio) == ""))
  {
  	alert("Errore: Il campo Data Servizio e\' obbligatorio.");
    document[nomeForm].DataServizioAssociato.focus(); 	
    return false;
  }
  
  if((opzioniAllegatoServizio=="undefined")||(trim(opzioniAllegatoServizio)==""))
  {
    if ((allegatoServizio != "undefined") && (trim(allegatoServizio) != ""))
    {
      if((get_estensione(allegatoServizio)!="PDF") &&
  			 (get_estensione(allegatoServizio)!="DOC") &&
  			 (get_estensione(allegatoServizio)!="DOCX"))
  		{
  		  	alert("L\'estensione del file "+allegatoServizio+" non e\' consentita (pdf/doc)\n");		  	
  		  	return false;
  		}
    }
    else 
    {
   	  alert("Errore: Il campo allegato servizio e\' obbligatorio.");
      return false; 
    }
  }
  else if (opzioniAllegatoServizio=="1")
  {
    if ((allegatoServizio != "undefined") && (trim(allegatoServizio) != ""))
    {
      if((get_estensione(allegatoServizio)!="PDF") &&
  			 (get_estensione(allegatoServizio)!="DOC") &&
  			 (get_estensione(allegatoServizio)!="DOCX"))
  		{
  		  	alert("L\'estensione del file "+allegatoServizio+" non e\' consentita (pdf/doc)\n");		  	
  		  	return false;
  		}
    }
    else 
    {
   	  alert("Errore: Il campo allegato servizio e\' obbligatorio.");
      return false; 
    } 
  }

  return true;
}

function checkCampiPubblicazioni(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	
  
	var nomePubblicazione = document[nomeForm].NomePubblicazione.value;
	var dataPubblicazione = document[nomeForm].DataPubblicazione.value;  
    
	if ((nomePubblicazione == "undefined") || (trim(nomePubblicazione) == ""))
  {
  	alert("Errore: Il campo Nome Pubblicazione e\' obbligatorio.");
   	document[nomeForm].NomePubblicazione.focus();
    return false;
  }
  
  if ((dataPubblicazione == "undefined") || (trim(dataPubblicazione) == ""))
  {
  	alert("Errore: Il campo Data Pubblicazione e\' obbligatorio.");
    document[nomeForm].DataPubblicazione.focus(); 	
    return false;
  }    

  return true;
}

function checkCampiCategorie(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var nomeCategoria = document[nomeForm].NomeCategoria.value;	

	if ((nomeCategoria == "undefined") || (trim(nomeCategoria) == ""))
  {
  	alert("Errore: Il campo Nome Categoria e\' obbligatorio.");
   	document[nomeForm].NomeCategoria.focus();
    return false;
  }

  return true;
}

function checkCampiFaq(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloFaq   = document[nomeForm].TitoloFaq.value;
	var domandaFaq  = tinyMCE.get("DomandaFaq").getContent();
	var rispostaFaq = tinyMCE.get("RispostaFaq").getContent();	  
   
	if ((titoloFaq == "undefined") || (trim(titoloFaq) == ""))
  {
  	alert("Errore: Il campo Titolo Faq e\' obbligatorio.");
   	document[nomeForm].TitoloFaq.focus();
    return false;
  }

  if ((domandaFaq == "undefined") || (trim(domandaFaq) == ""))
  {
  	alert("Errore: Il campo Domanda Faq e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "DomandaFaq");
    tinyMCE.execCommand("mceFocus", false, "DomandaFaq");
    return false;
  }

  if ((rispostaFaq == "undefined") || (trim(rispostaFaq) == ""))
  {
  	alert("Errore: Il campo Risposta Faq e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "RispostaFaq");
    tinyMCE.execCommand("mceFocus", false, "RispostaFaq");
    return false;
  }

  return true;
}

function checkCampiBibliografia(nomeForm)
{	
	if(btnWhichButton.value == 'Annulla') return true;	

	var titoloBibliografia = document[nomeForm].TitoloBibliografia.value;
	var autoreBibliografia = document[nomeForm].AutoreBibliografia.value;
	var testoBibliografia  = tinyMCE.get("TestoBibliografia").getContent();	  
   
	if ((titoloBibliografia == "undefined") || (trim(titoloBibliografia) == ""))
  {
  	alert("Errore: Il campo Titolo e\' obbligatorio.");
   	document[nomeForm].TitoloBibliografia.focus();
    return false;
  }

  if ((autoreBibliografia == "undefined") || (trim(autoreBibliografia) == ""))
  {
  	alert("Errore: Il campo Autore e\' obbligatorio.");
   	document[nomeForm].AutoreBibliografia.focus();
    return false;
  }   

  if ((testoBibliografia == "undefined") || (trim(testoBibliografia) == ""))
  {
  	alert("Errore: Il campo Testo e\' obbligatorio.");
   	tinyMCE.execCommand("mceAddControl", false, "TestoBibliografia");
    tinyMCE.execCommand("mceFocus", false, "TestoBibliografia");
    return false;
  }

  return true;
}

function checkCampiComboItem(nomeform,nomecampoid)
{
	if(btnWhichButton.value == 'Annulla') return true;		

	var indexSelected = document[nomeform][nomecampoid].selectedIndex;
  var valueSelected = document[nomeform][nomecampoid].value;
   
	if ((indexSelected==-1)||(valueSelected=='undefined')||(trim(valueSelected)==""))
	{
		alert("Impossibile effettuare operazioni: Nessun elemento selezionato");
		return false;
	}

	return true;
}

function confirmDel(nomeform,nomecampoid,msg)
{
	if(btnWhichButton.value == 'Annulla') return true;
	
	var indexSelected = document[nomeform][nomecampoid].selectedIndex;
	
	if (indexSelected==-1)
	{
		alert("Impossibile effettuare la cancellazione: Nessun elemento selezionato");
		return false;
	}
	
	var esito=window.confirm(msg);
	return esito;
}

function checkIsChecked(field)
{
	if(btnWhichButton.value == 'Annulla') return true;

	var i=0;
	var result = false;

	for (i = 0; i < field.length; i++)
	{
		if (field[i].checked == true)
		{
			result = true;
		}
	}
	if(field.checked == true)
	{
		result = true;
	}

	if(result == true)
	{
		var esito=window.confirm("Confermi la cancellazione?");
		if(esito)
		{
			result = true;
		}
		else
		{
			result = false;
		}
	}
	else
	{
		alert("Errore: Nessun elemento selezionato");
	}
	return result;
}

function isEmail(email)
{
	if (email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
	{
		return true;
	}
	return false;
}

function trim(stringa)
{
	while (stringa.substring(0,1) == ' ')
	{
  	stringa = stringa.substring(1, stringa.length);
  }
  while (stringa.substring(stringa.length-1, stringa.length) == ' ')
  {
  	stringa = stringa.substring(0,stringa.length-1);
  }
  return stringa;
}

function generaPassword(tipoInserimento,numeroMinimoCaratteri,numeroMassimoCaratteri)
{
	if (tipoInserimento==0)
	{
		 document.frmUtenteAssociato.PasswordUtenteAssociato.value = '';
		 document.frmUtenteAssociato.RidigitaPasswordUtenteAssociato.value = '';
		 return;
	}
	
	var elencoCaratteri = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

	var minimoCaratteri = numeroMinimoCaratteri;
	var massimoCaratteri = numeroMassimoCaratteri;

	var differenzaCaratteri = massimoCaratteri - minimoCaratteri;

	var lunghezza = Math.round((Math.random() * differenzaCaratteri) + minimoCaratteri);

	var incremento = 0;
	var password = "";

	while (incremento < lunghezza)
	{
  	 password += elencoCaratteri.charAt(Math.round(Math.random() * elencoCaratteri.length));
   	 incremento++;
	}
	
	document.frmUtenteAssociato.PasswordUtenteAssociato.value = password;
	document.frmUtenteAssociato.RidigitaPasswordUtenteAssociato.value = password;
	return;	
}

function getCheckedValue(radioObj)
{
  if(!radioObj)
	 return "";
	
  var radioLength = radioObj.length;
	if(radioLength == undefined)
	 if(radioObj.checked)
			return radioObj.value;
	 else
	 	 return "";
	 	 
	for(var i = 0; i < radioLength; i++)
  {
		if(radioObj[i].checked)
    {
			return radioObj[i].value;
		}
	}
	return "";
}

function openclosediv(anno)
{
  var elem = document.getElementById(anno);
  if(elem.style.display == "block")
  {
    elem.style.display = "none";
  }
  else
  {
    elem.style.display = "block";
  }
}

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(nValidLength<strVal.length)
  {
  	alert('Maximum length can be '+nLength);
    strVal = strVal.substring(0,nValidLength);
  }
  
  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 Disab(val,nomeForm)
{
  if(val=="1")
  {
    document[nomeForm].LinkVideoLocale.disabled=false;
    document[nomeForm].LinkVideoYoutube.disabled=true;    
  }
  else if(val=="2")
  {
    document[nomeForm].LinkVideoLocale.disabled=true;
    document[nomeForm].LinkVideoYoutube.disabled=false;  
  }
}

