function motore(url,div) 
{
 if (document.getElementById('attesa').value=='0') 
	{
	  setTimeout(function () {motore(url,div);},30);
	}
	else
	{
		document.getElementById('attesa').value='0';
		document.getElementById(div).style.display='block';
		var http_request = false;
		
		if (window.XMLHttpRequest)   // Mozilla, Safari,...
		{ 
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) 
			{
				http_request.overrideMimeType('text/xml');    // Vedi note sotto
			}
		} 
		else if (window.ActiveXObject)	// IE
		{ 
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) 
			{
				try 
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e) {}
			}
		}
		
		if (!http_request) 
		{
			alert('Giving up :( Non riesco a creare una istanza XMLHTTP');
			return false;
		}
		
		http_request.onreadystatechange = function() { alertContents(http_request,div); };
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}


function motorepost(url,div,parametri) 
{
   if (document.getElementById('attesa').value=='0') 
   {
	  setTimeout(function () {motorepost(url,div,parametri);},30);
   }
   else
   {  
     var http_request = false;

     if (window.XMLHttpRequest)   // Mozilla, Safari,...
	 { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');   // Vedi note sotto
        }
     } 
	 else if (window.ActiveXObject) 	// IE
	 { 
        try 
		{
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch (e) 
		{
           try 
		   {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } 
			catch (e) {}
         }
      }

	  if (!http_request) 
	  {
		alert('Giving up : Non riesco a creare una istanza XMLHTTP');
		return false;
	  }
      
	  http_request.onreadystatechange = function() { alertContents(http_request,div); };
      http_request.open('POST', url, true);
	  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parametri.length);
      http_request.send(parametri);
   }
}
    
	
function alertContents(http_request,div) 
{
   if (http_request.readyState == 4) 
   {
       if (http_request.status == 200) 
	   {
          resp=http_request.responseText;
		  creaDIV (div, resp);
       } 
	   else 
	   {
          alert('Si è verificato un problema con la richiesta');
       }
    }
}
	
	
	
function creaDIV (target, html)
{
   if (document.body.innerHTML)
   {
	  var tipo = html.split('[comando]');
	  if (tipo[0]=='errore')
	  {
	     alert(tipo[1]);
	  }
	  else
      {
		  document.getElementById(target).innerHTML =tipo[0];
	  }
      document.getElementById('attesa').value='1';
   }
   else if (document.getElementById)
   {
	  var element = document.getElementById(target);
	  var range = document.createRange();

	  range.selectNodeContents(element);
	  range.deleteContents();
	  element.appendChild(range.createContextualFragment(html));
	  document.getElementById('attesa').value='1';
   }
}

function form( file, formName, target ) 
{
	var the_form = document.getElementById(formName);
	var num = the_form.elements.length;
	var url = "";
	var radio_buttons = new Array();
	var nome_buttons = new Array();
	var check_buttons = new Array();
	var nome_buttons = new Array();

	// submit radio values
	var j = 0;
	var a = 0;
	for(var i=0; i< the_form.length; i++)
	{
		var temp = the_form.elements[i].type;
		if ( (temp == "radio") && ( the_form.elements[i].checked) ) 
		{ 
			nome_buttons[a] = the_form.elements[i].name;
			radio_buttons[j] = the_form.elements[i].value; 
			j++; 
			a++;
		}
	}
	for(var k = 0; k < radio_buttons.length; k++) 
	{
		url += nome_buttons[k] + "=" + radio_buttons[k] + "&";
	}

	// submit checkbox values
	var j = 0;
	var a = 0;
	for(var i=0; i< the_form.length; i++)
	{
		var temp = the_form.elements[i].type;
		if ( (temp == "checkbox") && ( the_form.elements[i].checked) ) 
		{ 
			nome_buttons[a] = the_form.elements[i].name;
			check_buttons[j] = the_form.elements[i].value; 
			j++; 
			a++;
		}
	}
	for(var k = 0; k < check_buttons.length; k++) 
	{
		url += nome_buttons[k] + "=" + check_buttons[k] + "&";
	}

	// submit all kind of input		
	for (var i = 0; i < num; i++)
	{	
		var chiave = the_form.elements[i].name;
		var valore = the_form.elements[i].value;
		var tipo = the_form.elements[i].type;

		if ( (tipo == "submit") || (tipo == "radio") || (tipo == "checkbox") ){}  //non fare nulla
		else 
		{
			url += chiave + "=" + valore + "&";
		}
	}

	var parameters = url;
	motorepost(file,target,parameters);
}



function ControlloCampiREG2(url,div,parametri)
{	
	var errore = false;
	
	var user = document.getElementById('user').value;
	if (user == "" || user.length < 5) {
		alert("il campo username non puo'\n essere vuoto o inferiore\n a 5 caratteri");
		document.getElementById('user').focus();
		document.getElementById('user').select();
		errore = true;
	}
	
	var cognome = document.getElementById('cognome').value;
	if (cognome == "") {
		alert("il campo cognome non puo' essere vuoto");
		document.getElementById('cognome').focus();
		document.getElementById('cognome').select();
		errore = true;
	}
	
	var nome = document.getElementById('nome').value;
	if (nome == "") {
		alert("il campo nome non puo' essere vuoto");
		document.getElementById('nome').focus();
		document.getElementById('nome').select();
		errore = true;
	}
	
	var pass = document.getElementById('pass').value;
	if (pass == "") {
		alert("il campo password non puo' essere vuoto");
		document.getElementById('pass').focus();
		document.getElementById('pass').select();
		errore = true;
	}
	
	var REPpass = document.getElementById('REPpass').value;
	if (REPpass == "") {
		alert("Prego ripetere la password per conferma");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	if (REPpass != pass)
	{
		alert("Attenzione! I campi password e conferma password devono contenere la stessa stringa");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	var cf = document.getElementById('cf').value;
	if (cf == "") 
	{
		alert("il campo Codice Fiscale non puo' essere vuoto");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}
	if (cf.length < 16) {
		alert("Attenzione! Codice Fiscale immesso non valido");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}	
	if( cf.length == 16 ) {
		err = ControllaCF(cf);
		if( err > '' )
		{
			alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
			errore = true;
		}
	}
	
	var datan = document.getElementById('datanascita').value;
	if (datan == "inserisci la data di nascita") {
		alert("immettere la data di nascita");
		document.getElementById('datanascita').focus();
		document.getElementById('datanascita').select();
		errore = true;
	}
	
	var professione = document.getElementById('professione').value;
	if (professione == 0) {
		alert("immettere la professione");
		document.getElementById('professione').focus();
		document.getElementById('professione').select();
		errore = true;
	}
	

	/*var provincia = document.getElementById('provincia').value;
	if (provincia == 0) 
	{
		alert("seleziona una provincia");
		document.getElementById('provincia').focus();
		document.getElementById('provincia').select();
		errore = true;
	}

	var citta = document.getElementById('citta').value;
	if (citta == "") {
		alert("il campo citta non puo' essere vuoto");
		document.getElementById('citta').focus();
		document.getElementById('citta').select();
		errore = true;
	}
	
	var indirizzo = document.getElementById('indirizzo').value;
	if (indirizzo == "") {
		alert("il campo indirizzo non puo' essere vuoto");
		document.getElementById('indirizzo').focus();
		document.getElementById('indirizzo').select();
		errore = true;
	}
	
	var cap = document.getElementById('cap').value;
	if (cap == "") {
		alert("il campo C.A.P. non puo' essere vuoto");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	

	if (cap.length != 5) {
		alert("Dimensione del dato C.A.P. errata");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	
	
	
	/*var telefono = document.getElementById('telefono').value;
	if (telefono == "") {
		alert("il campo telefono non puo' essere vuoto");
		document.getElementById('telefono').focus();
		document.getElementById('telefono').select();
		errore = true;
	}

	
	var cellulare = document.getElementById('cellulare').value;
	if (cellulare == "") {
		alert("il campo cellulare non puo' essere vuoto");
		document.getElementById('cellulare').focus();
		document.getElementById('cellulare').select();
		errore = true;
	} */ 
	
	// restituisce true in caso di errore
	erroremail = controllomail(document.getElementById('email').value);	
	
	if(erroremail)
	{
		errore = erroremail;
	}
	
	if(errore == false)
	{	
		motorepost(url,div,parametri);	
	}
	
}




function ControlloCampiREG(url,div,parametri)
{	
	var errore = false;
	
	var user = document.getElementById('user').value;
	if (user == "" || user.length < 5) {
		alert("il campo username non puo'\n essere vuoto o inferiore\n a 5 caratteri");
		document.getElementById('user').focus();
		document.getElementById('user').select();
		errore = true;
	}
	
	var cognome = document.getElementById('cognome').value;
	if (cognome == "") {
		alert("il campo cognome non puo' essere vuoto");
		document.getElementById('cognome').focus();
		document.getElementById('cognome').select();
		errore = true;
	}
	
	var nome = document.getElementById('nome').value;
	if (nome == "") {
		alert("il campo nome non puo' essere vuoto");
		document.getElementById('nome').focus();
		document.getElementById('nome').select();
		errore = true;
	}
	
	var pass = document.getElementById('pass').value;
	if (pass == "") {
		alert("il campo password non puo' essere vuoto");
		document.getElementById('pass').focus();
		document.getElementById('pass').select();
		errore = true;
	}
	
	var REPpass = document.getElementById('REPpass').value;
	if (REPpass == "") {
		alert("Prego ripetere la password per conferma");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	if (REPpass != pass)
	{
		alert("Attenzione! I campi password e conferma password devono contenere la stessa stringa");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	var cf = document.getElementById('cf').value;
	if (cf == "") 
	{
		alert("il campo Codice Fiscale non puo' essere vuoto");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}
	if (cf.length < 16) {
		alert("Attenzione! Codice Fiscale immesso non valido");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}	
	if( cf.length == 16 ) {
		err = ControllaCF(cf);
		if( err > '' )
		{
			alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
			errore = true;
		}
	}
	
	var datan = document.getElementById('datanascita').value;
	if (datan == "inserisci la data di nascita") {
		alert("immettere la data di nascita");
		document.getElementById('datanascita').focus();
		document.getElementById('datanascita').select();
		errore = true;
	}
	
	var professione = document.getElementById('professione').value;
	if (professione == 0) {
		alert("immettere la professione");
		document.getElementById('professione').focus();
		document.getElementById('professione').select();
		errore = true;
	}
	
	  	if( document.getElementById('ord').value == '' && document.getElementById('ord').value == -1 )
    	{
        	var abb1 = document.getElementById('OP5: abbonamento singolo').checked;
        	//var abb2 = document.getElementById('OP6: abbonamento multiplo').checked;  //if ( abb1 == false && abb2 == false)
        	if ( abb1 == false ) {  
        		alert("selezionare uno tra gli abbonamenti disponibili");
        		errore = true;
        	}
      }  
  	
	/*var provincia = document.getElementById('provincia').value;
	if (provincia == 0) 
	{
		alert("seleziona una provincia");
		document.getElementById('provincia').focus();
		document.getElementById('provincia').select();
		errore = true;
	}

	var citta = document.getElementById('citta').value;
	if (citta == "") {
		alert("il campo citta non puo' essere vuoto");
		document.getElementById('citta').focus();
		document.getElementById('citta').select();
		errore = true;
	}
	
	var indirizzo = document.getElementById('indirizzo').value;
	if (indirizzo == "") {
		alert("il campo indirizzo non puo' essere vuoto");
		document.getElementById('indirizzo').focus();
		document.getElementById('indirizzo').select();
		errore = true;
	}
	
	var cap = document.getElementById('cap').value;
	if (cap == "") {
		alert("il campo C.A.P. non puo' essere vuoto");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	

	if (cap.length != 5) {
		alert("Dimensione del dato C.A.P. errata");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	
	
	
	/*var telefono = document.getElementById('telefono').value;
	if (telefono == "") {
		alert("il campo telefono non puo' essere vuoto");
		document.getElementById('telefono').focus();
		document.getElementById('telefono').select();
		errore = true;
	}

	
	var cellulare = document.getElementById('cellulare').value;
	if (cellulare == "") {
		alert("il campo cellulare non puo' essere vuoto");
		document.getElementById('cellulare').focus();
		document.getElementById('cellulare').select();
		errore = true;
	} */ 
	
	// restituisce true in caso di errore
	erroremail = controllomail(document.getElementById('email').value);	
	
	if(erroremail)
	{
		errore = erroremail;
	}
	
	if(errore == false)
	{	
		motorepost(url,div,parametri);	
	}
	
}



function ControlloCampi(url,div,parametri)
{	
	var errore = false;
	
	var user = document.getElementById('user').value;
	if (user == "" || user.length < 5) {
		alert("il campo username non puo'\n essere vuoto o inferiore\n a 5 caratteri");
		document.getElementById('user').focus();
		document.getElementById('user').select();
		errore = true;
	}
	
	var cognome = document.getElementById('cognome').value;
	if (cognome == "") {
		alert("il campo cognome non puo' essere vuoto");
		document.getElementById('cognome').focus();
		document.getElementById('cognome').select();
		errore = true;
	}
	
	var nome = document.getElementById('nome').value;
	if (nome == "") {
		alert("il campo nome non puo' essere vuoto");
		document.getElementById('nome').focus();
		document.getElementById('nome').select();
		errore = true;
	}
	
	var pass = document.getElementById('pass').value;
	if (pass == "") {
		alert("il campo password non puo' essere vuoto");
		document.getElementById('pass').focus();
		document.getElementById('pass').select();
		errore = true;
	}
	
	var REPpass = document.getElementById('REPpass').value;
	if (REPpass == "") {
		alert("Prego ripetere la password per conferma");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	if (REPpass != pass)
	{
		alert("Attenzione! I campi password e conferma password devono contenere la stessa stringa");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	var cf = document.getElementById('cf').value;
	if (cf == "") 
	{
		alert("il campo Codice Fiscale non puo' essere vuoto");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}
	if (cf.length < 16) {
		alert("Attenzione! Codice Fiscale immesso non valido");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}	
	if( cf.length == 16 ) {
		err = ControllaCF(cf);
		if( err > '' )
		{
			alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
			errore = true;
		}
	}
	
	var datan = document.getElementById('datanascita').value;
	if (datan == "inserisci la data di nascita") {
		alert("immettere la data di nascita");
		document.getElementById('datanascita').focus();
		document.getElementById('datanascita').select();
		errore = true;
	}
	
	/*var regione = document.getElementById('id_regione').value;
	if (regione == 0) {
		alert("seleziona una regione");
		document.getElementById('id_regione').focus();
		document.getElementById('id_regione').select();
		errore = true;
	}
	
	var provincia = document.getElementById('provincia').value;
	if (provincia == 0) 
	{
		alert("seleziona una provincia");
		document.getElementById('provincia').focus();
		document.getElementById('provincia').select();
		errore = true;
	}

	var citta = document.getElementById('citta').value;
	if (citta == "") {
		alert("il campo citta non puo' essere vuoto");
		document.getElementById('citta').focus();
		document.getElementById('citta').select();
		errore = true;
	}
	
	var indirizzo = document.getElementById('indirizzo').value;
	if (indirizzo == "") {
		alert("il campo indirizzo non puo' essere vuoto");
		document.getElementById('indirizzo').focus();
		document.getElementById('indirizzo').select();
		errore = true;
	}
	
	var cap = document.getElementById('cap').value;
	if (cap == "") {
		alert("il campo C.A.P. non puo' essere vuoto");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	

	if (cap.length != 5) {
		alert("Dimensione del dato C.A.P. errata");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	
	
	
	/*var telefono = document.getElementById('telefono').value;
	if (telefono == "") {
		alert("il campo telefono non puo' essere vuoto");
		document.getElementById('telefono').focus();
		document.getElementById('telefono').select();
		errore = true;
	}

	
	var cellulare = document.getElementById('cellulare').value;
	if (cellulare == "") {
		alert("il campo cellulare non puo' essere vuoto");
		document.getElementById('cellulare').focus();
		document.getElementById('cellulare').select();
		errore = true;
	} */ 
	
	// restituisce true in caso di errore
	erroremail = controllomail(document.getElementById('email').value);	
	
	if(erroremail)
	{
		errore = erroremail;
	}
	
	if(errore == false)
	{	
		motorepost(url,div,parametri);	
	}
	
}

function controllomail(mail)
{
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail))
	{
		var erroreMAIL = false;
	    alert("La mail inserita non e' valida!");
		erroreMAIL = true;	
	}

	return erroreMAIL;
}

 //CONTROLLA CHE IL TASTO PREMUTO CORRISPONDA AD UN NUMERO
 function caratteriok(e, goods)
 {
    var key, keychar;
    key = getkey(e);

    if (key == null)
	{
		return true;
	}
	
    // get character
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();

	// check goodkeys
	if (goods.indexOf(keychar) != -1)
	{
		return true;
	}

	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	{
		return true;
	}

	return false;
}    


//CONTROLLO L'EVENTO DI INSERIMENTO DEL DATO
 function getkey(e)
 {
    if (window.event)
       return window.event.keyCode;
    else if (e)
       return e.which;
    else
       return null;
 }
 
 
 
 
 function ControlloCampiconv(url,div,parametri)
 {	
	var errore = false;
	
	var user = document.getElementById('user').value;
	if (user == "" || user.length < 5) {
		alert("il campo username non puo'\n essere vuoto o inferiore\n a 5 caratteri");
		document.getElementById('user').focus();
		document.getElementById('user').select();
		errore = true;
	}
	
	var cognome = document.getElementById('cognome').value;
	if (cognome == "") {
		alert("il campo cognome non puo' essere vuoto");
		document.getElementById('cognome').focus();
		document.getElementById('cognome').select();
		errore = true;
	}
	
	var nome = document.getElementById('nome').value;
	if (nome == "") {
		alert("il campo nome non puo' essere vuoto");
		document.getElementById('nome').focus();
		document.getElementById('nome').select();
		errore = true;
	}
	
	var pass = document.getElementById('pass').value;
	if (pass == "") {
		alert("il campo password non puo' essere vuoto");
		document.getElementById('pass').focus();
		document.getElementById('pass').select();
		errore = true;
	}
	
	var REPpass = document.getElementById('REPpass').value;
	if (REPpass == "") {
		alert("Prego ripetere la password per conferma");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	if (REPpass != pass)
	{
		alert("Attenzione! I campi password e conferma password devono contenere la stessa stringa");
		document.getElementById('REPpass').focus();
		document.getElementById('REPpass').select();
		errore = true;
	}
	
	var cf = document.getElementById('cf').value;
	if (cf == "") 
	{
		alert("il campo Codice Fiscale non puo' essere vuoto");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}
	if (cf.length < 16) {
		alert("Attenzione! Codice Fiscale immesso non valido");
		document.getElementById('cf').focus();
		document.getElementById('cf').select();
		errore = true;
	}	
	if( cf.length == 16 ) {
		err = ControllaCF(cf);
		if( err > '' )
		{
			alert("VALORE ERRATO\n\n" + err + "\nCorreggi e riprova!");
			errore = true;
		}
	}
	
	
	var datan = document.getElementById('datanascita').value;
	if (datan == "inserisci la data di nascita") {
		alert("immettere la data di nascita");
		document.getElementById('datanascita').focus();
		document.getElementById('datanascita').select();
		errore = true;
	}
	
	/*var regione = document.getElementById('id_regione').value;
	if (regione == 0) {
		alert("seleziona una regione");
		document.getElementById('id_regione').focus();
		document.getElementById('id_regione').select();
		errore = true;
	}
	
	var provincia = document.getElementById('provincia').value;
	if (provincia == 0) 
	{
		alert("seleziona una provincia");
		document.getElementById('provincia').focus();
		document.getElementById('provincia').select();
		errore = true;
	}

	var citta = document.getElementById('citta').value;
	if (citta == "") {
		alert("il campo citta non puo' essere vuoto");
		document.getElementById('citta').focus();
		document.getElementById('citta').select();
		errore = true;
	}
	
	var indirizzo = document.getElementById('indirizzo').value;
	if (indirizzo == "") {
		alert("il campo indirizzo non puo' essere vuoto");
		document.getElementById('indirizzo').focus();
		document.getElementById('indirizzo').select();
		errore = true;
	}
	
	var cap = document.getElementById('cap').value;
	if (cap == "") {
		alert("il campo C.A.P. non puo' essere vuoto");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	

	if (cap.length != 5) {
		alert("Dimensione del dato C.A.P. errata");
		document.getElementById('cap').focus();
		document.getElementById('cap').select();
		errore = true;
	}	
	
	
	/* var telefono = document.getElementById('telefono').value;
	if (telefono == "") {
		alert("il campo telefono non puo' essere vuoto");
		document.getElementById('telefono').focus();
		document.getElementById('telefono').select();
		errore = true;
	}

	
	var cellulare = document.getElementById('cellulare').value;
	if (cellulare == "") {
		alert("il campo cellulare non puo' essere vuoto");
		document.getElementById('cellulare').focus();
		document.getElementById('cellulare').select();
		errore = true;
	} */
	
	var albo = document.getElementById('albo').value;
	if (albo == "") {
		alert("il campo albo non puo' essere vuoto");
		document.getElementById('albo').focus();
		document.getElementById('albo').select();
		errore = true;
	}
	
	var iscrizione = document.getElementById('iscrizione').value;
	if (iscrizione == "") {
		alert("il campo iscrizione non puo' essere vuoto");
		document.getElementById('iscrizione').focus();
		document.getElementById('iscrizione').select();
		errore = true;
	}
	
	var sezione = document.getElementById('sezione').value;
	if (sezione == "") {
		alert("il campo sezione non puo' essere vuoto");
		document.getElementById('sezione').focus();
		document.getElementById('sezione').select();
		errore = true;
	}
	
	var titolostudio = document.getElementById('titolostudio').value;
	if (titolostudio == "") {
		alert("il campo titolostudio non puo' essere vuoto");
		document.getElementById('titolostudio').focus();
		document.getElementById('titolostudio').select();
		errore = true;
	}
	
	// restituisce true in caso di errore
	erroremail = controllomail(document.getElementById('email').value);	
	
	if(erroremail)
	{
		errore = erroremail;
	}
	
	if(errore == false)
	{	
		motorepost(url,div,parametri);	
	}
	
}
 
 
 
 
 
 
 function controllodelete(url,div,parametri)
 {	
	if(confirm("Siete sicuri di volervi cancellare dal servizio?\n\nCancellandosi dal servizio andranno persi tutti i diritti di abbonamento!"))
	{		
		//alert('hai confermato');
		motorepost(url,div,parametri);
	}
 }
 
 
 
 
 
 function contlostpass(url,div,parametri)
{	
	var errore = false;
	
	var cognome = document.getElementById('cognome').value;
	if (cognome == "") {
		alert("il campo cognome non puo' essere vuoto");
		document.getElementById('cognome').focus();
		document.getElementById('cognome').select();
		errore = true;
	}
	
	var nome = document.getElementById('nome').value;
	if (nome == "") {
		alert("il campo nome non puo' essere vuoto");
		document.getElementById('nome').focus();
		document.getElementById('nome').select();
		errore = true;
	}
	
	
	// restituisce true in caso di errore
	erroremail = controllomail(document.getElementById('email').value);	
	
	if(erroremail)
	{
		errore = erroremail;
	}
	
	if(errore == false)
	{	
		motorepost(url,div,parametri);	
	}
	
}




function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Il codice fiscale non e' corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}


function ControllaPIVA(pi)
{
	if( pi == '' )  return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non è\n" +
			"corretta: la partita IVA dovrebbe essere lunga\n" +
			"esattamente 11 caratteri.\n";
	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
			return "La partita IVA contiene un carattere non valido `" +
				pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
		return "La partita IVA non è valida:\n" +
			"il codice di controllo non corrisponde.\n";
	return '';
}





 //CONTROLLA CHE IL TASTO PREMUTO SIA VALIDO PER USERNAME E PASSWORD
 function caratteriok2(e)
 {
    var key, keychar;
    key = getkey(e);

	
    // get character
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();

	
	// control keys
	if ( key==232 || key==233 || key==242 || key==224 || key==249 || key==94 || key==236 || key==176 || key==38 || key==36 || key==37 || key==47 || key==34 || key==39 || key==92 || key==124 || key==33 || key==63 || key==231 || key==46 || key==44 || key==59 || key==167 || key==163 || key==32)
	{
		alert('Carattere immesso non valido:\n\nUsername e Password non possono contenere i seguenti caratteri:\n\n'
			  +String.fromCharCode(232)+'\t'+String.fromCharCode(233)+'\t'+String.fromCharCode(242)+'\t'+String.fromCharCode(224)+'\t'+String.fromCharCode(249)+'\t'+String.fromCharCode(94)+'\t'+String.fromCharCode(236)+'\t'+String.fromCharCode(176)+'\t'+String.fromCharCode(38)+'\t'+String.fromCharCode(36)+'\t'+String.fromCharCode(37)+'\t'+String.fromCharCode(47)+'\t'+String.fromCharCode(34)+'\t'+String.fromCharCode(39)+'\t'+String.fromCharCode(92)+'\t'+String.fromCharCode(124)+'\t'+String.fromCharCode(33)+'\t'+String.fromCharCode(63)+'\t'+String.fromCharCode(231)+'\t'+String.fromCharCode(46)+'\t'+String.fromCharCode(44)+'\t'+String.fromCharCode(59)+'\t'+String.fromCharCode(167)+'\t'+String.fromCharCode(163)+'\t'+String.fromCharCode(32)+'\t');
		return false;
		
	}
	else
	{
		return true;
	}
}    