/********************************************
  FUNZIONI DI CONVENIENZA
********************************************/
function Is_Number(sDato,MinDim,MaxDim)
{
	if ((MinDim != 0) && (MaxDim != 0))
	{
		if (sDato.length < MinDim)
			return("deve contenere almeno " + MinDim + " caratteri.");
		if (sDato.length > MaxDim)
			return("deve contenere al più " + MaxDim + " caratteri.");
	}
	for (i = 0;  i < sDato.length;  i++)
	{
		CodeChr = sDato.charAt(i);
		if ((CodeChr<'0') || (CodeChr>'9'))
			return("deve contenere esclusivamente cifre numeriche.");
	}
	return("");
}

function Is_String(sDato,MinDim,MaxDim)
{
	if (MinDim !=0){
		if (sDato.length < MinDim)
			return("deve contenere almeno " + MinDim + " caratteri.");
        }
        if (MaxDim != 0) {
		if (sDato.length > MaxDim)
			return("deve contenere al più " + MaxDim + " caratteri.");
	}
    return("");
}

function Is_Alfa(sDato)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ \t\r\n\f";
        var checkStr = sDato;
        var allValid = true;
        for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
    return ("deve contenere esclusivamente caratteri");
  return ("");
}

function Is_Date(theElement) {
  var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
  var thisYear = null;
  var thisMon = null;
  var thisDay = null;
  var today = null;
  inpDate = theElement;
  if (inpDate.length == 0 ) return true;
  thisDay = inpDate.substr(0,2);
  thisMonth = inpDate.substr(3,2);
  thisYear = inpDate.substr(6,4);
  var filter=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
  if (! filter.test(inpDate))
    return ("deve essere inserito con il formato GG/MM/AAAA");
  var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
  if (! filter.test(thisMonth))
    return ("deve essere specificato con un mese corretto");
  N=Number(thisYear);
  if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
    DayArray[1]=29;
  for(var ctr=0; ctr<=11; ctr++){
    if (MonthArray[ctr]==thisMonth){
      if (thisDay<= DayArray[ctr] && thisDay >0 )
        return("");
      else
        return ("deve essere specificato con un giorno valido");
    }
  }
}

function Is_Cap(sDato)
{
	if (Is_Number(sDato,5,5)!= "")
		return("contiene un CAP errato");
	return("");
}

function Is_PIVA (sDato)
{
	if (Is_Number(sDato,11,11)!='')
		return ("contiene una partita IVA non valida.");

	SOMMADISPARI=0;
	SOMMAPARI=0;

	for (i=0;i<9;i+=2)
	{
	    SOMMADISPARI+=sDato.substr(i,1)-'0';
		DIVQ=parseInt((2*(sDato.substr(i+1,1))-'0')/10,10);
		DIVR=(2*(sDato.substr(i+1,1)-'0') % 10);
		SOMMAPARI+= (DIVQ + DIVR);
	}
	SOMMACTR=SOMMADISPARI+SOMMAPARI;
	DIVI= ((10-(SOMMACTR % 10)) % 10);
	if ((sDato.substr(10,1)-'0')==DIVI)
	  return ("");
	else
	  return ("contiene una partita IVA non valida.");
}

function Is_FiscalCode(sDato)
{

	if (sDato.length !=16)
		return("contiene un codice fiscale non valido.");
	sDato=sDato.toUpperCase();
	iChecksum=0;
	iPos=-1;
	iSum=0;
	bPari=true;
	sCaratteri = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	sCodiciPari= "000102030405060708091011121314151617181920212223242500010203040506070809";
	sCodiciDispari="010005070913151719210204182011030608121416102225242301000507091315171921";
	for (iloop=0; iloop<16; iloop++)
	{
	  sCheck=sDato.substr(iloop,1);
	  iPos=((sCaratteri.indexOf(sCheck)+1)*2)-1;
 	  if ( (iloop%2) != 0)
 	  {
	  	iSum = parseInt(sCodiciPari.substr(iPos-1,2),10);
 		//alert(iPos + ' ' + iSum);
	  }
	  else
	  {
		iSum = parseInt(sCodiciDispari.substr(iPos-1,2),10);
 		//alert(iPos + ' ' + iSum);
 	  }
	  if (iloop != 15)
		iChecksum = iChecksum +	iSum;
	}
	//alert(iSum + ' ' + (iChecksum % 26));
	if ((iChecksum % 26) !=	iSum)
		return ("contiene un codice fiscale non valido.");
	else
		return("");
}

function Is_Email(sDato)
{
 if (sDato != "")
 {
  var s = sDato;
  var localPartfilter1 = /^[^<>()\[\]\x5C.,;:@" ]+(\.[^<>()\[\]\x5C.,;:@" ]+)*@$/;
  var localPartfilter2 = /^"[^\r\n]+"@$/;
  var domainfilter = /^([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9])(\.([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9]))(\.([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]|[a-zA-Z0-9]))*$/;
  var sepPos = 0;
  var localPart;
  var domain;
  var localPartOk = false;
  var domainOk    = false;
  sepPos = s.lastIndexOf("@");
  localPart = s.substring(0,sepPos+1);
  domain    = s.substring(sepPos+1,s.length);
  if  (localPartfilter1.test(localPart))
    localPartOk = true;
  else if (localPartfilter2.test(localPart))
    localPartOk = true;
  else
    localPartOk = false;
  if (domainfilter.test(domain))
    domainOk = true;
  else
    domainOk = false;
  if (localPartOk != true || domainOk != true)
    return ("non è un indirizzo valido");
  return("");
 }
}

function Is_Select(theSel){
  if(theSel.options[theSel.selectedIndex].value == "")
    return ("deve essere specificato")
  return ("");
}


function Check(Controllo,NomeCampo,Tipo,Obbligo,MinDim,MaxDim,sDatoApp)
{ res= "";
  value = Controllo;

        if ((Obbligo=='Y'||Obbligo=='S')&&value=="")
          return "ATTENZIONE: Il campo " + NomeCampo +" è obbligatorio. Inserire un valore.";

	if (value!="")
	{
		if (Tipo== "Number")      res= Is_Number(value,MinDim,MaxDim);
		if (Tipo== "String")      res= Is_String(value,MinDim,MaxDim);
		if (Tipo== "Alfa")        res= Is_Alfa(value);
		if (Tipo== "Date")        res= Is_Date(value);
		if (Tipo== "Cap")         res= Is_Cap(value);
		//if (Tipo== "FiscalCode")  res= Is_FiscalCode(value);
		//if (Tipo== "PIVA")        res= Is_PIVA(value);
		if (Tipo== "Email")       res= Is_Email(value);
		if (Tipo== "Select")      res= Is_Select(value);
	}

	if (res!="") return "Il campo " + NomeCampo + " " + res;

 return "";
}

function controlla(piva,cod_fisc){
  if((piva.value == "")&&(cod_fisc.value == "")){
    alert("Specificare Partita IVA o Codice Fiscale");
    return false;
  }else{
    if(piva.value != "")
      alertField(Check(piva.value,"Partita IVA","PIVA","Y",0,0,""));
    else
      return alertField(Check(cod_fisc.value,"Codice Fiscale","FiscalCode","Y",0,0,""));
  }
}

function altro(theSel,theSpec){
  if(theSel.options[theSel.selectedIndex].text == "Altro")
    return alertField(Check(theSpec.value,"Specifica","Alfa","Y",0,0,""));
  else
    return alertField(Check(theSpec.value,"Specifica","Alfa","N",0,0,""));
}

function alertField(message)
{
   ok = true;
   if (message!= '')
   {
    ok = false;
    alert(message);
   }

  return ok;
}

/********************************************************************************
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts.
This may be used freely as long as this msg is intact!
(I always appriciate links to my page)
********************************************************************************/
function hide(id,nest){
  if(document.layers){
    if(nest) document.layers[nest].document.layers[id].visibility="hidden"
    else document.layers[id].visibility="hidden"
  }else if(document.all) document.all[id].style.visibility="hidden"
}

function show(id,nest){
  if(document.layers){
    if(nest) document.layers[nest].document.layers[id].visibility="visible"
    else document.layers[id].visibility="visible"
  }else if(document.all) document.all[id].style.visibility="visible"
}

/*******************************************************************************/

function doSelect(theSel,theName){
  val = theSel.options[theSel.selectedIndex].text;
  if(val == "Altro")
    show(theName)
  else
    hide(theName)
}

/*************************************
  Funzione che restituisce la differenza in millisecondi
  fra una data in formato stringa ed un'altra data
*************************************/
function compareSD(dateString,theDate){
  var aDate = new Date(theDate.getYear(),theDate.getMonth(),theDate.getDate());
  var bDate = new Date(dateString.substring(6,10),
                       dateString.substring(3,5)-1,
                       dateString.substring(0,2));
  return (bDate.getTime() - aDate.getTime());
}

/**********************************
    Validazione Form Utilizzati
***********************************/

function validaGfrReg(theForm){
  ok = true;
  ok = alertField(Check(theForm.nome.value,"Nome","Alfa","Y",0,0,""));
  if(ok){
    ok = alertField(Check(theForm.cognome.value,"Cognome","Alfa","Y",0,0,""));
    if(ok){
      ok = alertField(Check(theForm.data_nasc.value,"Data di nascita","Date","N",0,0,""));
      if(ok){
      	ok = alertField(Check(theForm.professione,"Professione","Select","N",0,0,""));
      	if(ok){
      	  ok = altro(theForm.professione,theForm.prof_altro);
      	  if(ok){
      	    ok = altro(theForm.albo,theForm.albo_altro);
      	    if(ok){
              ok = alertField(Check(theForm.citta_albo.value,"Città di riferimento","Alfa","N",0,0,""));
              if(ok){
                ok = alertField(Check(theForm.tel_uff.value,"Telefono ufficio","String","Y",0,0,""));
                if(ok){
                  ok = alertField(Check(theForm.email.value,"E-mail","Email","Y",0,0,""));
                  if(ok){
              	    ok = alertField(Check(theForm.indirizzo.value,"Indirizzo","String","Y",0,0,""));
              	    if(ok){
              	      ok = alertField(Check(theForm.comune.value,"Comune","String","Y",0,0,""));
              	      if(ok){
              	        ok = alertField(Check(theForm.cap.value,"CAP","Cap","Y",0,0,""));
              	        if(ok){
              	          ok = alertField(Check(theForm.piva.value,"Partita IVA","PIVA","N",0,0,""));
              	          if(ok){
              	      	   // ok = alertField(Check(theForm.cod_fisc.value,"Codice Fiscale","FiscalCode","Y",0,0,""));
              	      	    if(ok){
                              ok = alertField(Check(theForm.username.value,"Username","String","Y",8,0,""));
                              if(ok){
                                ok = alertField(Check(theForm.password.value,"Password","String","Y",5,0,""));
                                if(ok){
                                  ok = alertField(Check(theForm.conf_pwd.value,"Conferma password","String","Y",5,0,""));
                                  if(ok){
                                    if(theForm.password.value != theForm.conf_pwd.value){
                                      alert("Le password immesse devono coincidere!");
                                      ok = false;
                                      theForm.password.focus();
                                    }
                                  }else theForm.conf_pwd.focus();
                                }else theForm.password.focus();
                              }else theForm.username.focus();
              	      	    }else theForm.cod_fisc.focus();
              	      	  }else theForm.piva.focus();
              	        }else theForm.cap.focus();
              	      }else theForm.comune.focus();
                    }else theForm.indirizzo.focus();
                  }else theForm.email.focus();
                }else theForm.tel_uff.focus();
              }else theForm.citta_albo.focus();
            }else theForm.albo_altro.focus();
          }else theForm.prof_altro.focus();
        }else theForm.professione.focus();
      }else theForm.data_nasc.focus();
    }else theForm.cognome.focus();
  }else theForm.nome.focus();
  if(ok){ // Pulisco gli hidden input text
    if(theForm.professione.options[theForm.professione.selectedIndex].text != "Altro")
      theForm.prof_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].text != "Altro")
      theForm.albo_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].value == "")
      theForm.citta_albo.value = "";
  }
  return ok;
}

function validaGfrAcc(theForm){
  ok = true;
  ok = alertField(Check(theForm.nome.value,"Nome","Alfa","Y",0,0,""));
  if(ok){
    ok = alertField(Check(theForm.cognome.value,"Cognome","Alfa","Y",0,0,""));
    if(ok){
      ok = alertField(Check(theForm.data_nasc.value,"Data di nascita","Date","N",0,0,""));
      if(ok){
      	ok = alertField(Check(theForm.professione,"Professione","Select","N",0,0,""));
      	if(ok){
      	  ok = altro(theForm.professione,theForm.prof_altro);
      	  if(ok){
      	    ok = altro(theForm.albo,theForm.albo_altro);
      	    if(ok){
              ok = alertField(Check(theForm.citta_albo.value,"Città di riferimento","Alfa","N",0,0,""));
              if(ok){
                ok = alertField(Check(theForm.tel_uff.value,"Telefono ufficio","String","Y",0,0,""));
                if(ok){
                  ok = alertField(Check(theForm.email.value,"E-mail","Email","Y",0,0,""));
                  if(ok){
              	    ok = alertField(Check(theForm.indirizzo.value,"Indirizzo","String","Y",0,0,""));
              	    if(ok){
              	      ok = alertField(Check(theForm.comune.value,"Comune","String","Y",0,0,""));
              	      if(ok){
              	        ok = alertField(Check(theForm.cap.value,"CAP","Cap","Y",0,0,""));
              	        if(ok){
              	          ok = alertField(Check(theForm.piva.value,"Partita IVA","PIVA","N",0,0,""));
              	          if(!ok) theForm.piva.focus();
              	        }else theForm.cap.focus();
              	      }else theForm.comune.focus();
                    }else theForm.indirizzo.focus();
                  }else theForm.email.focus();
                }else theForm.tel_uff.focus();
              }else theForm.citta_albo.focus();
            }else theForm.albo_altro.focus();
          }else theForm.prof_altro.focus();
        }else theForm.professione.focus();
      }else theForm.data_nasc.focus();
    }else theForm.cognome.focus();
  }else theForm.nome.focus();
  if(ok){ // Pulisco gli hidden input text
    if(theForm.professione.options[theForm.professione.selectedIndex].text != "Altro")
      theForm.prof_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].text != "Altro")
      theForm.albo_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].value == "")
      theForm.citta_albo.value = "";
  }
  return ok;
}

function validaGfrRegOL(theForm){
  ok = true;
  ok = alertField(Check(theForm.nome.value,"Nome","Alfa","Y",0,0,""));
  if(ok){
    ok = alertField(Check(theForm.cognome.value,"Cognome","Alfa","Y",0,0,""));
    if(ok){
      ok = alertField(Check(theForm.data_nasc.value,"Data di nascita","Date","N",0,0,""));
      if(ok){
      	ok = alertField(Check(theForm.professione,"Professione","Select","N",0,0,""));
      	if(ok){
      	  ok = altro(theForm.professione,theForm.prof_altro);
      	  if(ok){
      	    ok = altro(theForm.albo,theForm.albo_altro);
      	    if(ok){
              ok = alertField(Check(theForm.citta_albo.value,"Città di riferimento","Alfa","N",0,0,""));
              if(ok){
                ok = alertField(Check(theForm.tel_uff.value,"Telefono ufficio","String","Y",0,0,""));
                if(ok){
                  ok = alertField(Check(theForm.email.value,"E-mail","Email","Y",0,0,""));
                  if(ok){
              	    ok = alertField(Check(theForm.indirizzo.value,"Indirizzo","String","Y",0,0,""));
              	    if(ok){
              	      ok = alertField(Check(theForm.comune.value,"Comune","String","Y",0,0,""));
              	      if(ok){
              	        ok = alertField(Check(theForm.cap.value,"CAP","Cap","Y",0,0,""));
              	        if(ok){
              	          //ok = alertField(Check(theForm.piva.value,"Partita IVA","PIVA","N",0,0,""));
              	          if(ok){
              	      	    //ok = alertField(Check(theForm.cod_fisc.value,"Codice Fiscale","FiscalCode","Y",0,0,""));
              	      	    if(ok){
                              ok = alertField(Check(theForm.username.value,"Username","String","Y",8,0,""));
                              if(ok){
                                ok = alertField(Check(theForm.password.value,"Password","String","Y",5,0,""));
                                if(ok){
                                  ok = alertField(Check(theForm.conf_pwd.value,"Conferma password","String","Y",5,0,""));
                                  if(ok){
                                    if(theForm.password.value != theForm.conf_pwd.value){
                                      alert("Le password immesse devono coincidere!");
                                      ok = false;
                                      theForm.password.focus();
                                    }
                                  }else theForm.conf_pwd.focus();
                                }else theForm.password.focus();
                              }else theForm.username.focus();
              	      	    }else theForm.cod_fisc.focus();
              	      	  }else theForm.piva.focus();
              	        }else theForm.cap.focus();
              	      }else theForm.comune.focus();
                    }else theForm.indirizzo.focus();
                  }else theForm.email.focus();
                }else theForm.tel_uff.focus();
              }else theForm.citta_albo.focus();
            }else theForm.albo_altro.focus();
          }else theForm.prof_altro.focus();
        }else theForm.professione.focus();
      }else theForm.data_nasc.focus();
    }else theForm.cognome.focus();
  }else theForm.nome.focus();
  if(ok){ // Pulisco gli hidden input text
    if(theForm.professione.options[theForm.professione.selectedIndex].text != "Altro")
      theForm.prof_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].text != "Altro")
      theForm.albo_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].value == "")
      theForm.citta_albo.value = "";
  }
  return ok;
}

function validaGfrChgPwd(theForm){
 if((theForm.new_pwd.value == "")||(theForm.conf_pwd.value == "")){
   alert("Completare l'inserimento dei campi del form!");
   return false;
 }
 if(theForm.new_pwd.value != theForm.conf_pwd.value){
   alert("Le password immesse devono coincidere!");
   return false;
 }
 if(theForm.new_pwd.value.length < 5){
   alert("Le password devono essere lunghe almeno 5 caratteri!");
   return false;
 }	
 return true;
}

function validaGfrModScad(theForm){
  dateString = theForm.scadenza.value;

  ok = alertField(Check(dateString,"Nuova scadenza","Date","Y",0,0,""));
  if(!ok) return false;

  var now = new Date();
  diff = compareSD(dateString,now);
  if(diff < 0){
    alert("Inserire una Scadenza futura!");
    return false;
  }

  var year = new Date(now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000));
  year = new Date(year.getYear(),year.getMonth(),year.getDate());
  diff = compareSD(dateString,year);
  if(diff > 0){
    alert("Inserire una Scadenza inferiore ad un anno!");
    return false;
  }

  return true;
}

function validaGfrRicerca(theForm){
  ok = true;
  ok = alertField(Check(theForm.deposito_gg.value,"Data di deposito","Number","N",2,2,""));
  if(ok){
    ok = alertField(Check(theForm.deposito_mm.value,"Data di deposito","Number","N",2,2,""));
    if(ok){
      ok = alertField(Check(theForm.deposito_aa.value,"Data di deposito","Number","N",4,4,""));
      if(ok){
        ok = alertField(Check(theForm.numero.value,"Numero","Number","N",0,0,""));
        if(!ok) theForm.numero.focus();
      } theForm.deposito_aa.focus();
    }else theForm.deposito_mm.focus();
  }else theForm.deposito_gg.focus();
  return ok;
}

function validaGfrRicUtenti(theForm){
  ok = true;
  ok = alertField(Check(theForm.scadenza.value,"Data di deposito","Date","Y",0,0,""));
  var now = new Date();
  diff = compareSD(theForm.scadenza.value,now);
  if(diff < 0){
    alert("Inserire una Scadenza futura!");
  ok = false
  }
  return ok;
}

function cambia_num(nuovo_num, old_num, pag, link){
  var documento = old_num*(pag-1);
  var pagina = (documento/nuovo_num) +.5;
  var nuova_pag = Math.round(pagina);
  var cambia = link+"&pag="+nuova_pag+"&num=" + nuovo_num;
  window.location.href=cambia;
}

function validaGfrEsport(theForm){
  var tot = 0;
  for (i=0;i<document.getElementsByName("esport").length;i++){
    if (document.getElementsByName("esport").item(i).checked) tot++;
    }
  if (tot == 0){
    alert("nessun elemento selezionato");
    return false;}
return true;
}

function LS(){
  document.LoginForm.submit();
}

// Controllo per la privacy: se utente seleziona vengono riempiti tutti i campi con valori default

function fill_defvalue()
{
  theForm = document.getElementsByName("GfrMod")[0];

  if(theForm.cod_privacy.checked)  {
    theForm.nome.value = "xxxxx";
    theForm.nome.disabled = true;
    theForm.cognome.value = "xxxxx";
    theForm.cognome.disabled = true;
    theForm.tel_uff.value = "00000";
    theForm.tel_uff.disabled = true;
    theForm.email.value = "xxxxx@xx.xx";
    theForm.email.disabled = true;
    theForm.indirizzo.value = "xxxxx";
    theForm.indirizzo.disabled = true;
    theForm.comune.value = "xxxxx";
    theForm.comune.disabled = true;
    theForm.cap.value = "00000";
    theForm.cap.disabled = true;
    theForm.cod_fisc.value = "xxxxx";
    theForm.cod_fisc.disabled = true;
    theForm.professione.selectedIndex = 4;
    doSelect(theForm.professione,'divprof');
    theForm.prof_altro.value = "xxxxx";
    theForm.professione.disabled = true;
    theForm.prof_altro.disabled = true;
  }
  else
  {
    theForm.nome.value = "";
    theForm.nome.disabled = false;
    theForm.cognome.value = "";
    theForm.cognome.disabled = false;
    theForm.tel_uff.value = "";
    theForm.tel_uff.disabled = false;
    theForm.email.value = "";
    theForm.email.disabled = false;
    theForm.indirizzo.value = "";
    theForm.indirizzo.disabled = false;
    theForm.comune.value = "";
    theForm.comune.disabled = false;
    theForm.cap.value = "";
    theForm.cap.disabled = false;
    theForm.cod_fisc.value = "";
    theForm.cod_fisc.disabled = false;
    theForm.professione.selectedIndex = 0;
    doSelect(theForm.professione,'divprof');
    theForm.prof_altro.value = "";
    theForm.professione.disabled = false;
    theForm.prof_altro.disabled = false;
  }
}

function validaGfrMod(theForm){
if(theForm.privacy.checked){
  ok = alertField("La registrazione non può continuare");
}else if(!theForm.pers.checked){
  ok = alertField("Per continuare la registrazione \ndeve leggere e approvare l'informativa \nsul trattamento dei dati personali");
}else{
  ok = true;

  ok = alertField(Check(theForm.nome.value,"Nome","Alfa","Y",0,0,""));
  if(ok){
    ok = alertField(Check(theForm.cognome.value,"Cognome","Alfa","Y",0,0,""));
    if(ok){
      ok = alertField(Check(theForm.data_nasc.value,"Data di nascita","Date","N",0,0,""));
      if(ok){
      	ok = alertField(Check(theForm.professione,"Professione","Select","N",0,0,""));
      	if(ok){
      	  ok = altro(theForm.professione,theForm.prof_altro);
      	  if(ok){
      	    ok = altro(theForm.albo,theForm.albo_altro);
      	    if(ok){
              ok = alertField(Check(theForm.citta_albo.value,"Città di riferimento","Alfa","N",0,0,""));
              if(ok){
                ok = alertField(Check(theForm.tel_uff.value,"Telefono ufficio","String","Y",0,0,""));
                if(ok){
                  ok = alertField(Check(theForm.email.value,"E-mail","Email","Y",0,0,""));
                  if(ok){
              	    ok = alertField(Check(theForm.indirizzo.value,"Indirizzo","String","Y",0,0,""));
              	    if(ok){
              	      ok = alertField(Check(theForm.comune.value,"Comune","String","Y",0,0,""));
              	      if(ok){
              	        ok = alertField(Check(theForm.cap.value,"CAP","Cap","Y",0,0,""));
              	        if(ok){
              	         // ok = alertField(Check(theForm.piva.value,"Partita IVA","PIVA","N",0,0,""));
              	          if(ok){
              	         // ok = alertField(Check(theForm.cod_fisc.value,"Codice Fiscale","FiscalCode","Y",0,0,""));
              	          }else theForm.piva.focus();
              	        }else theForm.cap.focus();
              	      }else theForm.comune.focus();
                    }else theForm.indirizzo.focus();
                  }else theForm.email.focus();
                }else theForm.tel_uff.focus();
              }else theForm.citta_albo.focus();
            }else theForm.albo_altro.focus();
          }else theForm.prof_altro.focus();
        }else theForm.professione.focus();
      }else theForm.data_nasc.focus();
    }else theForm.cognome.focus();
  }else theForm.nome.focus();
  if(ok){ // Pulisco gli hidden input text
    if(theForm.professione.options[theForm.professione.selectedIndex].text != "Altro")
      theForm.prof_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].text != "Altro")
      theForm.albo_altro.value = "";
    if(theForm.albo.options[theForm.albo.selectedIndex].value == "")
      theForm.citta_albo.value = "";
  }
}
  return ok;
}


//Cintrolla che ci sia almeno un campo non vuoto (requserdata.jsp)

function validaGfrRichiestaUserData(theForm)
{
  var result = false;
  
  
  //theForm = document.getElementsByName("GfrRichiesta")[0];
  if( (theForm.user.value != "") || (theForm.ragsoc.value != "") || 
      (theForm.codclient.value != "") || (theForm.comune.value != "") )
  {
    result = true;
  }  
  else
  {
    result = false;
    alert("Inserire almeno un parametro di ricerca!");
  }
  
  /*if(theForm.agenzia.value == "")
  {
    result = false;
    alert("Agenzia sconosciuta!");
  }*/
  
  return result;

}

function validaGfrMandaUserData(theForm)
{
  var result = true;
  
  
  if(theForm.email.value == "")
  {
    alert("Indirizzo email non presente!");
    return false;
  }
  
  //Controllare email
  result = alertField(Check(theForm.email.value,"E-mail","Email","Y",0,0,""));

  return result;
  
}

function validaGfrModificaEmail(theForm)
{
  var result = true;

  //alert("Check Modifica!");
  result = alertField(Check(theForm.newemail.value,"E-mail","Email","Y",0,0,""));
  
  return result;
}
