function attiva()
{
  document.getElementById('pwd').disabled=false;
}
function checkFile(file)
{  
  // controllo il tipo di file  
  ext = file.substr(file.lastIndexOf("."))+".";  
  perm = ".gif.jpg.jpeg.png.";
  
  if(perm.indexOf(ext.toLowerCase())<0)  
  {		
    alert("Estensione file non consentita\n\nEstensioni consentite: gif jpg jpeg bmp png");
    
    document.getElementById('foto').value='';  
  }   
  else  {}
}
function checkTutti(stato)
{
  with (document.modulo)
  {
    for (var i=0; i < elements.length; i++) 
    {
        if (elements[i].type == 'checkbox')
          elements[i].checked = stato.checked;
    }
  }
}
function checkForm(file)
{
  if (document.getElementById(file).value!="")
  {
    document.getElementById("load").style.display="block";
    return true;
  }
}
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 is_integer(arg)
{
  var len = arg.length;
  var count=0;
  var Number=true;
        
  /* ciclo su tutti i caratteri e verifico */
  for( count=0; count<len; count++ )
  {
    /* leggo il carattere */
    if( arg.charAt( count ) < '0' || arg.charAt( count ) > '9' )
    {
      /* non e' un numero */
      Number=false;
      break;
    }
  }
  return Number
}
function check_mail(indirizzo) 
{
  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(indirizzo) && regv.test(indirizzo))
      return true;
    return false;
  }
  else 
  {
    if(indirizzo.indexOf("@") >= 0 && indirizzo.indexOf(".") > indirizzo.indexOf("@"))
      return true;
    return false;
  }
}
function check_username(user)
{
  var pattern = /\W/i;
  var result = user.search(pattern);
        
  return result;
}
function check_data(data)
{
  var myRegex = /^\d{4}-\d{2}-\d{2}/;
 
  var result = myRegex.test(data);
  return result;
}
function checkModuloContatti(lang)
{
	var nome_cognome=document.getElementById("nome_cognome");
	var citta=document.getElementById("citta");
	var email=document.getElementById("email");
	var ripeti_email=document.getElementById("ripeti_email");
	var motivo_contatto=document.getElementById("motivo_contatto");
	var code=document.getElementById("code");
  
	if (trim(nome_cognome.value)=="")
	{
    if (lang=="it")
      alert("Campo Nome e cognome richiesto");
    else alert("Campo Nome e cognome richiesto");
		
    nome_cognome.focus();
		return false;
	}
	else if (trim(citta.value)=="")
	{
    if (lang=="it")
      alert("Campo citt\340 richiesto");
    else alert("Campo citt\340 richiesto");
    
		citta.focus();
		return false;
	}
	else if (trim(email.value)=="")
	{
    if (lang=="it")
      alert("Campo indirizzo email richiesto");
    else alert("Campo indirizzo email richiesto");
    
		email.focus();
		return false;
	}
	else if (!check_mail(email.value))
	{
    if (lang=="it")
      alert("Formato indirizzo email errato");
    else alert("Formato indirizzo email errato");
    
		email.focus();
		return false;
	}
	else if (trim(ripeti_email.value)=="")
  {
    if (lang=="it")
      alert("Inserisci nuovamente l'indirizzo email");
    else alert("Inserisci nuovamente l'indirizzo email");
    
    ripeti_email.focus();
    return false;
  }
	else if (trim(ripeti_email.value)!=trim(email.value))
  {
    if (lang=="it")
      alert("I campi indirizzo email e ripeti indirizzo email non coincidono");
    else alert("I campi indirizzo email e ripeti indirizzo email non coincidono");
    
    ripeti_email.focus();
    return false;
  }
	else if (trim(motivo_contatto.value)=="")
	{
    if (lang=="it")
      alert("Campo motivo del contatto richiesto");
		else alert("Campo motivo del contatto richiesto");
		
    motivo_contatto.focus();
		return false;
	}
	else if (trim(code.value)=="")
	{
    if (lang=="it")
      alert("Devi ricopiare il codice che vedi nell'immagine");
    else alert("Devi ricopiare il codice che vedi nell'immagine");
    
		code.focus();
		return false;
	}
	else if (document.getElementById('accept').checked==false)
	{
    if (lang=="it")
      alert("Per continuare devi accettare la privacy spuntando la casella di controllo");
    else alert("Per continuare devi accettare la privacy spuntando la casella di controllo");
		
    document.getElementById('accept').focus();
		return false;
	}
	else return true;	
}
function checkFormFeedback(lang)
{
	var nome=document.getElementById("nome");
	var citta=document.getElementById("citta");
	var feedback=document.getElementById("feedback");
  
	if (trim(nome.value)=="")
	{
    if (lang=="it")
      alert("Campo nome richiesto");
    else alert("Campo nome richiesto");
		
    nome.focus();
		return false;
	}
	else if (trim(citta.value)=="")
	{
    if (lang=="it")
      alert("Campo citt\340 richiesto");
    else alert("Campo citt\340 richiesto");
    
		citta.focus();
		return false;
	}
	else if (trim(feedback.value)=="")
	{
    if (lang=="it")
      alert("Campo feedback richiesto");
		else alert("Campo feedback del contatto richiesto");
		
    feedback.focus();
		return false;
	}
	else return true;	
}
function codifica()
{
  if (document.getElementById('pwd').value!='')
    document.getElementById('pwd').value=SHA1(document.getElementById('pwd').value);
}
function checkFormProdotti()
{
  var categoria_it=document.getElementById("categoria_it");
  var nome_it=document.getElementById("nome_it");
  var unita=document.getElementById("unita");
  var qta_min=document.getElementById("qta_min");
  var peso_lordo=document.getElementById("peso_lordo");
  var prezzo=document.getElementById("prezzo");
  var costo_spedizione=document.getElementById("costo_spedizione");
  
  if (trim(categoria_it.value)=="")
  {
    alert("Campo categoria (it) richiesto");
    categoria_it.focus();
    return false;
  }
  else if (trim(nome_it.value)=="")
  {
    alert("Campo nome (it) richiesto");
    nome_it.focus();
    return false;
  }
  else if (trim(unita.value)=="")
  {
    alert("Campo unit\364 di misura richiesto");
    unita.focus();
    return false;
  }
  else if (trim(qta_min.value)=="")
  {
    alert("Campo quantit\364 minima ordinabile richiesto");
    qta_min.focus();
    return false;
  }
  else if (!is_integer(qta_min.value))
  {
    alert("Il campo quantit\364 minima ordinabile deve essere un numero intero");
    qta_min.focus();
    return false;
  }
  else if (trim(peso_lordo.value)=="")
  {
    alert("Campo peso lordo richiesto");
    peso_lordo.focus();
    return false;
  }
  else if (trim(prezzo.value)=="")
  {
    alert("Campo prezzo richiesto");
    prezzo.focus();
    return false;
  }
  else if (trim(costo_spedizione.value)=="")
  {
    alert("Campo costo spedizione richiesto");
    costo_spedizione.focus();
    return false;
  }
  else if (!document.modulo.disponibilita[0].checked && !document.modulo.disponibilita[1].checked)
  {
	alert("Scegli se il prodotto è disponibile oppure no");
    return false;
  }
  else
  {
	if (document.getElementById("foto").value!="")
		document.getElementById("load").style.display="block";
	return true;
  }
}
