// Convalida campi non vuoti
    function nor(campo1,campo2) 
    {
        if(campo1.value == "" || campo2.value == "")

	{
	    alert("I campi "+campo1.name+" e "+campo2.name+" non possono essere entrambi vuoti");
            campo1.focus();
	    campo2.focus();
            return false;}
        else
            return true;
    }






    // Convalida campo non vuoto
    function nonvuoto(campo) 
    {
        if(campo.value == ""){
	    alert("Il campo "+campo.name+" non puo' essere vuoto");
            campo.focus();
            return false;}
        else
            return true;
    }

    // Convalida dell'email, guarda se c'è "@"
    function validaemail(campo) 
    {
		var primo=campo.value.indexOf('@',0);
		var ultimo=campo.value.length;
		if (primo==-1){
			alert("Email non valida");
          		campo.focus();
			return false;}
		if(campo.value.lastIndexOf('@')>primo){
			alert("Email non valida");
          		campo.focus();
			return false;}
		if(campo.value.indexOf(',',0) != -1){
			alert("Email non valida");
          		campo.focus();
			return false;}
		if(campo.value.indexOf(' ',0) != -1){
			alert("Email non valida");
          		campo.focus();
			return false;}
		if(campo.value.substring(ultimo-1,ultimo)=="."){
			alert("Email non valida");
          		campo.focus();
			return false;}
		return true;
    }

    // Convalida di un numero positivo
    function numeropos(campo) 
    {
        inStr = campo.value;
        inLen = inStr.length;
        for(var i=0; i<inLen; i++) 
	  {
                var ch = inStr.substring(i,i+1)
                if (ch < "0" || "9" < ch){
		    alert("Inserire solo numeri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          }
	  return true;
    }

    // Convalida di un numero positivo di tipo byte
    function byte(campo) 
    {
        inStr = campo.value;
        inLen = inStr.length;
        for(var i=0; i<inLen; i++) 
	  {
                var ch = inStr.substring(i,i+1)
                if (ch < "0" || "9" < ch){
		    alert("Inserire solo numeri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          }
	 if (parseInt(inStr) > 256){
                    alert("Inserire solo numeri minori di 256 nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }	

    // Convalida di un numero positivo di tipo int
    function int(campo) 
    {
        inStr = campo.value;
        inLen = inStr.length;
        for(var i=0; i<inLen; i++) 
	  {
                var ch = inStr.substring(i,i+1)
                if (ch < "0" || "9" < ch){
		    alert("Inserire solo numeri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          }
	 if (parseInt(inStr) > 65536){
                    alert("Inserire solo numeri minori di 65536 nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }	

    // Convalida di un numero positivo di tipo long
    function long(campo) 
    {
        inStr = campo.value;
        inLen = inStr.length;
        for(var i=0; i<inLen; i++) 
	  {
                var ch = inStr.substring(i,i+1)
                if (ch < "0" || "9" < ch){
		    alert("Inserire solo numeri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          }
	 if (parseInt(inStr) > 4294967296){
                    alert("Inserire solo numeri minori di 4294967296 nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }	

    // Convalida la lunghezza max di un campo
    function maxlung(campo, lung) 
    {
        inStr = campo.value;
        inLen = inStr.length;
	lunghezza = parseInt(lung)
	 if (inLen > lung){
                    alert("Inserire solo "+lung+ " caratteri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }

    // Convalida la lunghezza min di un campo
    function minlung(campo, lung) 
    {
        inStr = campo.value;
        inLen = inStr.length;
	lunghezza = parseInt(lung)
	 if (inLen < lung){
                    alert("Inserire almeno "+lung+ " caratteri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }

    // Convalida la lunghezza fissa di un campo
    function fissalung(campo, lung) 
    {
        inStr = campo.value;
        inLen = inStr.length;
	lunghezza = parseInt(lung)
	 if (inLen != lung){
                    alert("Inserire "+lung+ " caratteri nel campo "+campo.name);
                    campo.focus();
                    return false;}
          	
	  return true;
    }
