////////////////////////INIZIO CONTROLLI IS//////////////////////////
function isLetter (c)
{
/////return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c =<= "Z")) )
	return (!isDigit(c))
}

//////////////////////////////////////////////////
function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}


//////////////////////////////////////////////////
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}


//////////////////////////////////////////////////
function isAlfaBetic(value)
{
	for( i=0; i < value.length; i++  )
	{
		   if(!isLetter(value.charAt(i)))
		   {
     	     		return false;
		   }

	}//for

	return true;
}

//////////////////////////////////////////////////
function isNumeric(value)
{
        cap=value.length;
	for( i=0; i < value.length; i++  ) {
		if(!isDigit(value.charAt(i)))
			return false;
	}

	return true;
}

////////////////////////FINE CONTROLLI IS//////////////////////////
//////////////////////////////////////////////////

// VERIFICA CAMPO ALFABETICO

function checkAlfaBetic(value,fieldName)
{
		if (!isAlfaBetic(value))
		{
			alert( 'Il campo ' + fieldName + ' deve essere alfabetico');
			return false;
		}
		return true;
}

///////////////////////////////////////////////////

// VERIFICA CAMPO NUMERICO

function checkNumeric(field, fieldName)
{
	if (!isNumeric(field.value))
	{
		errorAlert(field, 'Il campo ' + fieldName + ' deve essere numerico');
		return false;
	}
	return true;
}

///////////////////////////////////////////////////

// VERIFICA CHE IL CAMPO NON SIA VUOTO

function checkEmpty(field, fieldName)
{
	if (isEmpty(field.value)) {
		errorAlert(field, 'Il campo ' + fieldName + ' non può essere vuoto');
		return false;
	}
	return true;
}

///////////////////////////////////////////////////

// VERIFICA CHE LA COMBO-BOX NON SIA VUOTA

function checkCombo(field, errIndex, fieldName)
{
	if (field.selectedIndex == errIndex) {
		errorAlert(field, 'Il campo ' + fieldName + ' non può essere vuoto');
		return false;
	}
	return true;
}


///////////////////////////////////////////////////

// VERIFICA CHE IL RADIO BUTTON NON SIA VUOTO

function checkRadio(field, fieldName)
{
	for (i=0; i<field.length; i++) {
		if (field[i].checked) {
			return true;
		}
	}
	errorAlert(field, 'Il campo ' + fieldName + ' non può essere vuoto');

	return false;
}

///////////////////////////////////////////////////

// CONTROLLO E VERIFICA C.A.P.

        function checkCAP(field, fieldName)
        {
                cap=(field.value).length;
                capv=field.value;
                boleancap=true;

                if (cap!=5) {
                  errorAlert(field, 'La lunghezza del campo ' + fieldName + ' non è corretta ');
                  boleancap=false;
                  return boleancap;
                }

                if (cap=5) {
                for( i=0; i < cap; i++  ) {
                        if(!isDigit(capv.charAt(i))) {
                                errorAlert(field, 'Il campo ' + fieldName + ' deve essere numerico');
                                boleancap=false;
                                return boleancap;
                        }
                }
                }
                return boleancap;
        }
///////////////////////////////////////////////////

// CONTROLLO E VERIFICA E-MAIL

        function checkEMAIL(field, fieldName) {
                email=(field.value).length;
                emailv=field.value;
                boleanmail=true;

                if (email<7) {
                  errorAlert(field, 'Il campo ' + fieldName + ' non è valido ');
                  boleanmail=false;
                  return boleanmail;
                }

                boleanat=false;
                for( i=0; i < email; i++  ) {
                        if(emailv.charAt(i)=="@") {
                                boleanat=true;
                        }
                }
                if (boleanat!=true) {
                  errorAlert(field, 'Il campo ' + fieldName + ' non è valido ');
                  boleanmail=false;
                  return boleanmail;
                }

                boleanpt=false;
                for( i=0; i < email; i++  ) {
                        if(emailv.charAt(i)==".") {
                                boleanpt=true;
                        }
                }
                if (boleanpt!=true) {
                  errorAlert(field, 'Il campo ' + fieldName + ' non è valido ');
                  boleanmail=false;
                  return boleanmail;
                }

                return boleanmail;
        }

///////////////////////////////////////////////////

// CONTROLLO E VERIFICA DATA

        function checkDATA(field, fieldName)
        {
                data=(field.value).length;
                datav=field.value;
                boleandata=true;

                if (data!=10) {
                  errorAlert(field, 'Il campo ' + fieldName + ' deve avere formato gg/mm/aaaa');
                  boleandata=false;
                  return boleandata;
                }


                if(datav.charAt(2) != "/" || datav.charAt(5) != "/") {
                  errorAlert(field, 'Il campo' + fieldName + ' deve avere formato gg/mm/aaaa');
                  boleandata=false;
                  return boleandata;
                }

                for( i=0; i < 2; i++  ) {
		   if( !isDigit(datav.charAt(i)) ){
                      errorAlert(field, 'Il campo ' + fieldName + ' deve avere formato gg/mm/aaaa');
                      boleandata=false;
                      return boleandata;
		   }
                }
                for( i=3; i < 5; i++  ) {
                   if( !isDigit(datav.charAt(i)) ){
                      errorAlert(field, 'Il campo ' + fieldName + ' deve avere formato gg/mm/aaaa');
                      boleandata=false;
                      return boleandata;
                   }
                }
                for( i=6; i < 10; i++  ) {
                   if( !isDigit(datav.charAt(i)) ){
                      errorAlert(field, 'Il campo ' + fieldName + ' deve avere formato gg/mm/aaaa');
                      boleandata=false;
                      return boleandata;
                   }
                }

                c1=datav.charAt(0);
                c2=datav.charAt(1);
                tk1=c1+c2;
                c3=datav.charAt(3);
                c4=datav.charAt(4);
                tk2=c3+c4;

                if(tk1>31 || tk1<1 || tk2>12 || tk2<1){
                      errorAlert(field, 'Il campo ' + fieldName + ' deve avere formato gg/mm/aaaa');
                      boleandata=false;
                      return boleandata;
		   }


                return boleandata;
        }

///////////////////////////////////////////////////
//////////////////////////////////////////////////

// FUNZIONE DI ERRORE E MESSAGGIO E POSIZIONA IL CURSORE SUL FOCUS
function errorAlert(field, msg)
{
	alert(msg);
	field.focus();
}
