var http_req = null; // il problema con IE sta qui ;) 
var http_req_lez = null; // il problema con IE sta qui ;)

var $phpsessid_temp = null;
//var $root = "http://localhost:8888/www.iomulo.com";
//var $root = "http://lnx.calim74.com/testiomulo";
var $root = "http://www.iomulo.com";




//$root = "http://localhost:8888/iomulo.com/testiomulo";
//$root = "http://localhost:8888/iomulo.com/testiomulo";

/* *********************************************************** /*
Nome: 		crea_http_req()
Funzionalitą: 	crea l'oggetto per la comunicazione col server;
				
Ingressi: 		nessuno
Uscite:		req = oggetto per la comunicazione
Note:		Nessuna
Modifica:		09/08/2008 - Michele Moroni
/* *********************************************************** */

function crea_http_req() {   
    var req = false;   
    if (typeof XMLHttpRequest != "undefined")  
        {req = new XMLHttpRequest(); 												//Oggetto per tutti i tipi di prowser diversi da internet explorer
		if (req) {if (req.overrideMimeType) req.overrideMimeType("text/xml");}
		}
		
		
    else if (typeof ActiveXObject != "undefined") {   								 // Diversi tipi di oggetti per internet explorer 
        try {   
            req=new ActiveXObject("Msxml2.XMLHTTP");   
        } catch (e1) {   
            try {   
                req=new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e2) {   
                try {   
                    req=new ActiveXObject("Msxml2.XMLHTTP.4.0");   
                } catch (e3) {   
                    req=null;   
                }   
            }   
        }   
    }   
  
    if(!req && window.createRequest)   
        req = window.createRequest();													// creazione dell'oggetto
    
    if (!req) alert("Il browser non supporta AJAX");   
  
    return req;   
} 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/* *********************************************************** /*
Nome: 			gestisci_conferma_lezione
Funzionalitą:   Gstisce la risposta dell'ajax richiamato quando si preme il pulsante "conferma".
				
Ingressi: 		$code = codice identificativo della lezione confermata
Uscite:			Nessuna
Note:			

Modifica:		25/08/2008 - Michele Moroni
/* *********************************************************** */


function gestisci_conferma_lezione($code)
{
	if (http_req.readyState==4 || http_req.readyState == "complete")
		{
			
			var xmlDoc= http_req.responseXML.documentElement;
			$result = xmlDoc.getElementsByTagName("accettato").item(0).firstChild.data;
			//$prof = xmlDoc.getElementsByTagName("prof").item(0).firstChild.data;
			//$lez = xmlDoc.getElementsByTagName("lez").item(0).firstChild.data;
						
			$codicewaiting = "stato"+$code;
			$stato = document.getElementById($codicewaiting);
			
			if ($result == "YES") {$stato.innerHTML = '<table width=\"155\" border=\"0\"><tr><td width=\"40\" style=\"font-size:12px; font-weight:bold; padding-left:4px\">Stato: </td><td><span style="color:green; font-weight:bold">Accettata</span></td></tr></table>';}
			if ($result != "YES") {$stato.innerHTML = '<table width=\"155\" border=\"0\"><tr><td width=\"40\" style=\"font-size:12px; font-weight:bold; padding-left:4px\">Stato: </td><td>Errore (Causa Probabile: Sessione Scaduta)</td></tr></table>';}
		}
		
	else 
		{
			//alert("ciao");
			$codicewaiting = "stato"+$code;
			$stato = document.getElementById($codicewaiting);
			$stato.innerHTML = '<table width=\"155\" border=\"0\"><tr><td width=\"40\" style=\"font-size:12px; font-weight:bold; padding-left:4px\">Stato:  </td><td>Richiesta Inoltrata ...</td></tr></table>';
		}
}



/* *********************************************************** /*
Nome: 			AcceptLesson
Funzionalitą:   Gestisce il click del pulsante "accetta" per le lezioni in attesa
				
Ingressi: 		$sessionid = identificativo di sessione
Uscite:			Nessuna
Note:			Funzione Ajax

Modifica:		25/08/2008 - Michele Moroni
/* *********************************************************** */

function AcceptLesson($sessionid, $code, $idprof)
{
	
	http_req = crea_http_req();
	var $toopen = $root+"/ajax/ajaxconfirmlesson.php?PHPSESSID="+$sessionid+"&codicelezione="+$code+"&idprof="+$idprof+"&sid"+Math.random();
	http_req.open( "GET", $toopen);
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = function () {gestisci_conferma_lezione($code);};
	http_req.send(null);
	
}


/* *********************************************************** /*
Nome: 			gestisci_conferma_lezione
Funzionalitą:   Gstisce la risposta dell'ajax richiamato quando si preme il pulsante "conferma".
				
Ingressi: 		$code = codice identificativo della lezione confermata
Uscite:			Nessuna
Note:			

Modifica:		25/08/2008 - Michele Moroni
/* *********************************************************** */


function gestisci_rifiuto_lezione($code)
{
	if (http_req.readyState==4 || http_req.readyState == "complete")
		{
			var xmlDoc= http_req.responseXML.documentElement;
			$result = xmlDoc.getElementsByTagName("rifiutato").item(0).firstChild.data;
			$codicewaiting = "stato"+$code;
			$stato = document.getElementById($codicewaiting);
			if ($result == "YES") {$stato.innerHTML = '<tr><td width=\"60\" style=\"font-size:12px; color:red; font-weight:bold; padding-left:4px\">Stato: </td><td><span style="color:red; font-weight:bold">Rifiutata</span></td></tr>';}
			if ($result != "YES") {$stato.innerHTML = '<tr><td width=\"60\" style=\"font-size:12px; font-weight:bold; padding-left:4px\">Stato: </td><td>Errore (Causa Probabile: Sessione Scaduta)</td></tr>';}
		}
		
	else 
		{
			$codicewaiting = "stato"+$code;
			$stato = document.getElementById($codicewaiting);
			$stato.innerHTML = '<td width=\"40\" style=\"font-size:12px; font-weight:bold; padding-left:4px\">Stato:  </td><td>Richiesta Inoltrata ...</td></tr>';
		}
}


/* *********************************************************** /*
Nome: 			RejectLesson
Funzionalitą:   Gestisce il click del pulsante "rifiuta" per le lezioni in attesa
				
Ingressi: 		$sessionid = identificativo di sessione
Uscite:			Nessuna
Note:			Funzione Ajax

Modifica:		25/08/2008 - Michele Moroni
/* *********************************************************** */

function RejectLesson($sessionid, $code, $idprof)
{
	http_req = crea_http_req();
	var $toopen = $root+"/ajax/ajaxrejectlesson.php?PHPSESSID="+$sessionid+"&codicelezione="+$code+"&idprof="+$idprof+"&sid"+Math.random();
	http_req.open( "GET", $toopen);
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = function () {gestisci_rifiuto_lezione($code);};
	http_req.send(null);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



function gestisci_dati_personali()
{
	if (http_req_dati.readyState==4 || http_req_dati.readyState == "complete")
		{
			var xmlDoc= http_req_dati.responseXML.documentElement;
			$categoria = xmlDoc.getElementsByTagName("categoria").item(0).firstChild.data;
				
			$nome = xmlDoc.getElementsByTagName("nome").item(0).firstChild.data;
			$nome = $nome.replace(/@ecommerciale@/g, "&");
			
			$cognome = xmlDoc.getElementsByTagName("cognome").item(0).firstChild.data;
			$genere = xmlDoc.getElementsByTagName("genere").item(0).firstChild.data;
			$telefono = xmlDoc.getElementsByTagName("telefono").item(0).firstChild.data;
			$citta = xmlDoc.getElementsByTagName("citta").item(0).firstChild.data;
			$provincia = xmlDoc.getElementsByTagName("provincia").item(0).firstChild.data;
			$datanascita = xmlDoc.getElementsByTagName("datanascita").item(0).firstChild.data;
			$professione = xmlDoc.getElementsByTagName("professione").item(0).firstChild.data;
			$titolo = xmlDoc.getElementsByTagName("titolo").item(0).firstChild.data;
			$tipologia1 = xmlDoc.getElementsByTagName("tipologia1").item(0).firstChild.data;
			$descrizione = xmlDoc.getElementsByTagName("descrizione").item(0).firstChild.data;
			
			$email = xmlDoc.getElementsByTagName("email").item(0).firstChild.data;
			$password = xmlDoc.getElementsByTagName("password").item(0).firstChild.data;
			$nazione = xmlDoc.getElementsByTagName("nazione").item(0).firstChild.data;
			
			
			if ($telefono == "ND") $telefono = "";
			if ($professione == "ND") $professione = "";
			if ($citta == "ND") $citta = "";
			if ($provincia == "ND") $provincia = "";

			
    
			if ($categoria == "PRF")
			
			{
			
			
			
			if ($datanascita == "ND")
			    {
				$datanascita="";
				document.getElementById('annonascita').disabled="";
			    }
			
			
			document.getElementById('nome').value = $nome;
			document.getElementById('cognome').value = $cognome;
			document.getElementById('genere').value = $genere;
			document.getElementById('telefono').value = $telefono;
			document.getElementById('domicilio').value = $citta;
			//document.getElementById('provincia').value = $provincia;
			document.getElementById('annonascita').value = $datanascita;
			document.getElementById('professione').value = $professione;
			document.getElementById('password').value = $password;
			
			document.getElementById($nazione).selected="selected";
			
			
			
			
			if ($titolo == "ND") document.getElementById('titolo_0').selected="selected";
			if ($titolo == "Scuola Media Inf.") document.getElementById('titolo_1').selected="selected";
			if ($titolo == "Scuola Media Sup.") document.getElementById('titolo_2').selected="selected";
			if ($titolo == "Laurea 1° livello") document.getElementById('titolo_3').selected="selected";
			if ($titolo == "Laurea 2° livello") document.getElementById('titolo_4').selected="selected";
			if ($titolo == "Dottorato di Ricerca") document.getElementById('titolo_5').selected="selected";
			
			document.getElementById('email').value = $email;
			document.getElementById('password').value = $password;
			document.getElementById('ctrpassword').value = $password;
				
			}
		
			if ($categoria == "STD")
			
			{
			
			
			if ($datanascita == "ND")
			    {
				$datanascita="";
				document.getElementById('annonascita').disabled="";
			    }
			
			
			document.getElementById('nome').value = $nome;
			document.getElementById('cognome').value = $cognome;
			// document.getElementById('genere').value = $genere;
			
			try {document.getElementById('telefono').value = $telefono;} catch (e4) {};
			try {document.getElementById('provincia').value = $provincia;} catch (e5) {};
			try {document.getElementById('annonascita').value = $datanascita;} catch (e6) {};
			
			document.getElementById('domicilio').value = $citta;

			try {document.getElementById('email').value = $email;} catch (e1) {};
			try {document.getElementById('password').value = $password;} catch (e2) {};
			try {document.getElementById('ctrpassword').value = $password; } catch (e3) {};
			
			
			document.getElementById('pbt_ok').disabled="";
			
			}
			
			if ($categoria == "AZD")
			
			{
			
			if ($datanascita == "ND")
			    {
				$datanascita="";
				document.getElementById('annofondazione').disabled="";
			    }
			
			
			document.getElementById('nome').value = $nome;
			document.getElementById('telefono').value = $telefono;
			document.getElementById('domicilio').value = $citta;
			document.getElementById('provincia').value = $provincia;
			document.getElementById('annofondazione').value = $datanascita;
			
			if ($tipologia1 == "ND") document.getElementById('tipologia_0').selected="selected";
			if ($tipologia1  == "Istruzione") document.getElementById('tipologia_1').selected="selected";
			if ($tipologia1  == "Sport") document.getElementById('tipologia_2').selected="selected";
			if ($tipologia1  == "Tempo Libero") document.getElementById('tipologia_3').selected="selected";
			if ($tipologia1  == "Lingue") document.getElementById('tipologia_4').selected="selected";
			
			document.getElementById('email').value = $email;
			document.getElementById('password').value = $password;
			document.getElementById('ctrpassword').value = $password;
			document.getElementById('textbox_descrizione').value = $descrizione;
			
			document.getElementById('pbt_ok').disabled="";
			
			}
			
		
		
		}
		
	else 
		{
			// Do nothing
		}

}


/* *********************************************************** /*
Nome: 			AjaxGetDatiPersonali
Funzionalitą:   Gestisce il recupero dei dati personali nella pagina dati/disponibilita
				
Ingressi: 		$sessionid = identificativo di sessione
Uscite:			Nessuna
Note:			Funzione Ajax

Modifica:		12/10/2008 - Michele Moroni
/* *********************************************************** */


function AjaxGetDatiPersonali($sessionid)
{
		
	http_req_dati = crea_http_req();
	http_req_dati.open( "GET", $root+"/ajax/ajaxgetdatipersonali.php?PHPSESSID="+$sessionid+"&sid=" + Math.random());
	http_req_dati.setRequestHeader("Content-Type", "text/xml");
	http_req_dati.onreadystatechange = gestisci_dati_personali;
	http_req_dati.send(null);
	
	// Aggiornamento Lista Regioni
	GetListaRegioniForDati($sessionid);
	
}

function AjaxGetDatiPersonaliAzdPrf($sessionid, $idprof)
{

	http_req_dati = crea_http_req();
	http_req_dati.open( "GET", $root+"/ajax/ajaxgetdatipersonali.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&sid=" + Math.random());
	http_req_dati.setRequestHeader("Content-Type", "text/xml");
	http_req_dati.onreadystatechange = gestisci_dati_personali;
	http_req_dati.send(null);

	
}





function get_corsi()
{
	if (http_req_corsi.readyState==4 || http_req_corsi.readyState == "complete")
		{
			var xmlDoc= http_req_corsi.responseXML.documentElement;
			
			$sessid =  xmlDoc.getElementsByTagName("sessid").item(0).firstChild.data;
			
			$materia1 = xmlDoc.getElementsByTagName("materia1").item(0).firstChild.data;
			$materia1 = urldecode($materia1);
			$materia2 = xmlDoc.getElementsByTagName("materia2").item(0).firstChild.data;
			$materia2 = urldecode($materia2);
			$materia3 = xmlDoc.getElementsByTagName("materia3").item(0).firstChild.data;
			$materia3 = urldecode($materia3);
			$materia4 = xmlDoc.getElementsByTagName("materia4").item(0).firstChild.data;
			$materia4 = urldecode($materia4);
			
			if ($materia1 != "ND") 
			{
			
				$tariffa1 = xmlDoc.getElementsByTagName("tariffa1").item(0).firstChild.data;
				$livello1 = xmlDoc.getElementsByTagName("livello1").item(0).firstChild.data;
				$indirizzo1 = xmlDoc.getElementsByTagName("indirizzo1").item(0).firstChild.data;
				$indirizzo1 = urldecode($indirizzo1);
				$tipologia1 = xmlDoc.getElementsByTagName("tipologia1").item(0).firstChild.data;
				$descrizione1 = xmlDoc.getElementsByTagName("descriz1").item(0).firstChild.data;
			
				
				//$descrizione1 = "ciao";
				
				document.getElementById('bookmark_c1').src= $root+"/immagini/bookmark.gif";
			
				document.getElementById('corso_1').value = $materia1;
				if ($tariffa1!="ND") document.getElementById('tariffa').value = $tariffa1;
				document.getElementById('indirizzo').value = $indirizzo1;
				if ($descrizione1 != "ND") {document.getElementById('descrizione_mat').innerHTML = $descrizione1;}
				
				
				if ($tipologia1 == "ND") { //do nothing --> condizione di errore perche' il dato e' obbligatorio
										 }
				
				if ($tipologia1 == "Istruzione") document.getElementById('gruppo_1').selected="selected";
				if ($tipologia1 == "Sport") document.getElementById('gruppo_2').selected="selected";
				if ($tipologia1 == "Tempo Libero") document.getElementById('gruppo_3').selected="selected";
				if ($tipologia1 == "Lingue") document.getElementById('gruppo_4').selected="selected";		
						
				if ($livello1 == "Elementare") document.getElementById('livello_1').selected="selected";
				if ($livello1 == "Medio") {document.getElementById('livello_2').selected="selected";}
				if ($livello1 == "Alto") document.getElementById('livello_3').selected="selected";
				if ($livello1 == "Avanzato") document.getElementById('livello_4').selected="selected";
				if ($livello1 == "Tutti") document.getElementById('livello_5').selected="selected";
				
				
			}
			
			else document.getElementById('corso_1').innerHTML = "AGGIUNGI";
			
			
			if ($materia2 != "ND") {document.getElementById('corso_2').innerHTML = $materia2;}
			else document.getElementById('corso_2').innerHTML = "<p style=\"cursor:pointer; margin:0px; font-weight:14px;\" onclick=\"Aggiungi($sessid,'2')\">AGGIUNGI</p>";
			
			if ($materia3 != "ND") {document.getElementById('corso_3').innerHTML = $materia3;}
			else document.getElementById('corso_3').innerHTML = "<p style=\"cursor:pointer; margin:0px; font-weight:14px;\" onclick=\"Aggiungi($sessid,'3')\">AGGIUNGI</p>";
			
			if ($materia4 != "ND") {document.getElementById('corso_4').innerHTML = $materia4;}
			else document.getElementById('corso_4').innerHTML = "<p style=\"cursor:pointer; margin:0px; font-weight:14px;\" onclick=\"Aggiungi($sessid,'4')\">AGGIUNGI</p>";
			
			
			for ($a = 1; $a<8; $a++)
			{
			
			$cal1 = "1_"+$a;
			$cal2 = "2_"+$a;
			$cal3 = "3_"+$a;
			$cal4 = "4_"+$a;
			
			$numday = "day"+$a;
			
			
			
			$dalle1 = xmlDoc.getElementsByTagName("dispon1")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle1").item(0).firstChild.data;
			if ($dalle1 != "ND") {document.getElementById($cal1).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle1+":00</p>";}
			
			$alle1 = xmlDoc.getElementsByTagName("dispon1")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle1").item(0).firstChild.data;
			if ($alle1 != "ND") {document.getElementById($cal2).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle1+":00</p>";}
			
			$dalle2 = xmlDoc.getElementsByTagName("dispon1")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle2").item(0).firstChild.data;
			if ($dalle2 != "ND") {document.getElementById($cal3).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle2+":00</p>";}
			
			$alle2 = xmlDoc.getElementsByTagName("dispon1")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle2").item(0).firstChild.data;
			if ($alle2 != "ND"){ document.getElementById($cal4).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle2+":00</p>";}
			
			}
		
		document.getElementById('pbt_ok').disabled="";
		document.getElementById('gruppo').options[0]=null; // Questo serve per evitare che, prima del caricamento di ajax, si veda il primo elemento della select. L'elemento 0 e' stato precedentemento posto a zero
		
		}
		
	else 
		{
			// Do nothing
		}

}


function AjaxGetCorsi($sessionid)
{
	
	http_req_corsi = crea_http_req();
	http_req_corsi.open( "GET", $root+"/ajax/ajaxgetdaticorsi.php?PHPSESSID="+$sessionid+"&sid=" + Math.random());
	http_req_corsi.setRequestHeader("Content-Type", "text/xml");
	http_req_corsi.onreadystatechange = get_corsi;
	http_req_corsi.send(null);
	
}


/* *********************************************************** /*
Nome: 			get_corsi_small
Funzionalitą: 	All'interno della pagina dati recupera i titoli dei corsi e materie configurati, li scrive nei campi e inserisce i bottoni
                Aggiungi, Modifica, Elimina.
				
Ingressi: 		Nessuno
Uscite:			Nessuna
Note:			Nessuna
Modifica:		09/02/2009 - Michele Moroni
/* *********************************************************** */

function get_corsi_small()
{
	if (http_req_corsi.readyState==4 || http_req_corsi.readyState == "complete")
		{
			var xmlDoc= http_req_corsi.responseXML.documentElement;
			
			
			$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
			$sessid =  xmlDoc.getElementsByTagName("sessid").item(0).firstChild.data;
			$idprof = xmlDoc.getElementsByTagName("idprof").item(0).firstChild.data;
			$azdprf = xmlDoc.getElementsByTagName("azdprf").item(0).firstChild.data;
		    
			$materia1 = xmlDoc.getElementsByTagName("materia1").item(0).firstChild.data;
			$materia1 = urldecode($materia1);
			$materia2 = xmlDoc.getElementsByTagName("materia2").item(0).firstChild.data;
			$materia2 = urldecode($materia2);
			$materia3 = xmlDoc.getElementsByTagName("materia3").item(0).firstChild.data;
			$materia3 = urldecode($materia3);
			$materia4 = xmlDoc.getElementsByTagName("materia4").item(0).firstChild.data;
			$materia4 = urldecode($materia4);
                        
                        $deletingenabled1 = xmlDoc.getElementsByTagName("deleting1").item(0).firstChild.data;
                        $deletingenabled2 = xmlDoc.getElementsByTagName("deleting2").item(0).firstChild.data;
                        $deletingenabled3 = xmlDoc.getElementsByTagName("deleting3").item(0).firstChild.data;
                        $deletingenabled4 = xmlDoc.getElementsByTagName("deleting4").item(0).firstChild.data;
			
			var $numero_materie = 0;
			
			if ($materia1 != "ND") {$numero_materie = $numero_materie+1; document.getElementById('corso_1').disabled="disabled";}
			if ($materia2 != "ND") {$numero_materie = $numero_materie+1; document.getElementById('corso_2').disabled="disabled";}
			if ($materia3 != "ND") {$numero_materie = $numero_materie+1; document.getElementById('corso_3').disabled="disabled";}
			if ($materia4 != "ND") {$numero_materie = $numero_materie+1; document.getElementById('corso_4').disabled="disabled";}
			
			/////// MATERIA 1 ///////
			if ($materia1 != "ND") 
			 {
				document.getElementById('corso_1').value = $materia1;
				if ($deletingenabled1=="YES") 
				{  
                                    if ($azdprf=="YES") {document.getElementById('action1').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'1')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;;\" onclick=\"CancellaMateriaAzdPrf($sessid,$idprof,'1')\">X</button>";}
				    else {document.getElementById('action1').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'1')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateria($sessid,'1')\">X</button>";}
				}
				
				else  			  
				{ 
				     if ($azdprf=="YES") {document.getElementById('action1').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'1')\">+</button>"; }
				    else {document.getElementById('action1').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px;background-color:green;\" onclick=\"ModificaLezione($sessid,'1')\">+</button>"; }
				}
			 }
			
			else 
			 {
				 if ($azdprf=="YES")  {document.getElementById('action1').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"AggiungiAzdPrf($sessid, $idprof, '1')\">+</button>";}
				else {document.getElementById('action1').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"Aggiungi($sessid,'1')\">+</button>";}
			 }
			
			/////// MATERIA 2 ///////
			if ($materia2 != "ND") 
			 {
				document.getElementById('corso_2').value = $materia2;
				if ($deletingenabled2=="YES") 
				{  
                                    if ($azdprf=="YES") {document.getElementById('action2').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'2')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateriaAzdPrf($sessid,$idprof,'2')\">X</button>";}
				    else {document.getElementById('action2').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'2')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateria($sessid,'2')\">X</button>";}
				}
				
				else  			  
				{ 
				     if ($azdprf=="YES") {document.getElementById('action2').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'2')\">+</button>"; }
				    else {document.getElementById('action2').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px;\" onclick=\"ModificaLezione($sessid,'2')\">+</button>"; }
				}
			 }
			
			else 
			 {
				 if ($azdprf=="YES")  {document.getElementById('action2').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"AggiungiAzdPrf($sessid, $idprof, '2')\">+</button>";}
				else {document.getElementById('action2').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"Aggiungi($sessid,'2')\">+</button>";}
			 }			
			/////// MATERIA 3 ///////
			
			if ($materia3 != "ND") 
			 {
				document.getElementById('corso_3').value = $materia3;
				if ($deletingenabled3=="YES") 
				{  
                                    if ($azdprf=="YES") {document.getElementById('action3').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'3')\">+</button><button style=\"padding-top:0px; width:60px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateriaAzdPrf($sessid,$idprof,'3')\">X</button>";}
				    else {document.getElementById('action3').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'3')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateria($sessid,'3')\">X</button>";}
				}
				
				else  			  
				{ 
				     if ($azdprf=="YES") {document.getElementById('action3').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'3')\">+</button>"; }
				    else {document.getElementById('action3').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'3')\">+</button>"; }
				}
			 }
			
			else 
			 {
				 if ($azdprf=="YES")  {document.getElementById('action3').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"AggiungiAzdPrf($sessid, $idprof, '3')\">+</button>";}
				else {document.getElementById('action3').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"Aggiungi($sessid,'3')\">+</button>";}
				
			 }
			 
			 
			 /////// MATERIA 4 ///////
			
                        if ($materia4 != "ND") 
			 {
				document.getElementById('corso_4').value = $materia4;
				if ($deletingenabled4=="YES") 
				{  
                                    if ($azdprf=="YES") {document.getElementById('action4').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'4')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:red;\" onclick=\"CancellaMateriaAzdPrf($sessid,$idprof,'4')\">X</button>";}
				    else {document.getElementById('action4').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'4')\">+</button><button style=\"padding-top:0px; width:22px; height:22px; font-size:12px;background-color:red;\" onclick=\"CancellaMateria($sessid,'4')\">X</button>";}
				}
				
				else  			  
				{ 
				     if ($azdprf=="YES") {document.getElementById('action4').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezioneAzdPrf($sessid,$idprof,'4')\">+</button>"; }
				    else {document.getElementById('action4').innerHTML = "<button style=\"padding-top:0px; width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"ModificaLezione($sessid,'4')\">+</button>"; }
				}
			 }
			
			else 
			 {
				 if ($azdprf=="YES")  {document.getElementById('action4').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"AggiungiAzdPrf($sessid, $idprof, '4')\">+</button>";}
				else {document.getElementById('action4').innerHTML = "<button style=\"width:22px; height:22px; font-size:12px; background-color:green;\" onclick=\"Aggiungi($sessid,'4')\">+</button>";}
			 }
			   
		}
}


/* *********************************************************** /*
Nome: 			AjaxGetCorsiSmall
Funzionalitą: 	recupera i dati che verranno utilizzati per la funzione get_corsi_small (titoli dei corsi e materie configurati).
                Aggiungi, Modifica, Elimina.
				
Ingressi: 		Nessuno
Uscite:			Nessuna
Note:			Nessuna
Modifica:		09/02/2009 - Michele Moroni
/* *********************************************************** */

function AjaxGetCorsiSmall($sessionid)
{
	
	http_req_corsi = crea_http_req();
	http_req_corsi.open( "GET", $root+"/ajax/ajaxgetdaticorsi.php?PHPSESSID="+$sessionid+"&sid=" + Math.random());
	http_req_corsi.setRequestHeader("Content-Type", "text/xml");
	http_req_corsi.onreadystatechange = get_corsi_small;
	http_req_corsi.send(null);
	
}

/* *********************************************************** /*
Nome: 			AjaxGetCorsiSmall
Funzionalitą: 	recupera i dati che verranno utilizzati per la funzione get_corsi_small (titoli dei corsi e materie configurati).
                Aggiungi, Modifica, Elimina.
				
Ingressi: 		Nessuno
Uscite:			Nessuna
Note:			Nessuna
Modifica:		09/02/2009 - Michele Moroni
/* *********************************************************** */

function AjaxGetCorsiSmallAzdPrf($sessionid, $idprof)
{
		
	http_req_corsi = crea_http_req();
	http_req_corsi.open( "GET", $root+"/ajax/ajaxgetdaticorsi.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&sid=" + Math.random());
	http_req_corsi.setRequestHeader("Content-Type", "text/xml");
	http_req_corsi.onreadystatechange = get_corsi_small;
	http_req_corsi.send(null);
	
}

function gestisci_update_dati()
{


if (http_req_update.readyState==4 || http_req_update.readyState == "complete")
		{
			var xmlDoc= http_req_update.responseXML.documentElement;
			$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;	

			if ($errore == "YES")
			{
			
            
            
			$errore_email = xmlDoc.getElementsByTagName("errore_email").item(0).firstChild.data;	
			if ($errore_email == "YES") {document.getElementById('ErroreEmail').innerHTML = "<p style=\"font-size:10px; color:red; margin:0px; \">Email gi&agrave; registrata</p>";
										 document.getElementById('label_email').style.background="red";
										
										}
                        else {
                        
                            document.getElementById('ErroreEmail').innerHTML = "";
                        
                             }
		
			$errore_prov = xmlDoc.getElementsByTagName("errore_prov").item(0).firstChild.data;	
			if ($errore_prov == "YES")  {
										 document.getElementById('label_provincia').style.background="red";
										}
			
			
			document.getElementById('result').style.color = "red";
			document.getElementById('result').innerHTML = "ERRORE";
                        
			
			}
			
			else
			
			{
			
			document.getElementById('ErroreEmail').innerHTML = "";
			document.getElementById('label_email').style.background="";
										
			document.getElementById('result').style.color = "green";
			document.getElementById('result').innerHTML = "AGGIORNATO";
			}
		}
		
	else 
		{
			document.getElementById('result').style.color = "green";
			document.getElementById('result').innerHTML = "IN CORSO...";
			
		}
}


function gestisci_set_vacanze()
{


		if ((http_req_vac.readyState==4) || (http_req_vac.readyState == "complete"))
		{
			var xmlDoc= http_req_vac.responseXML.documentElement;
			$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
	
			
			
		    
			if ($errore == "NO") {
									document.getElementById('messaggi').innerHTML =  "Operazione eseguita";	
									
									$giorno1 = "";
									$giorno2 = "";
								 }
		}
		
	else 
		{
			 document.getElementById('messaggi').innerHTML = "richiesta in corso...";
		}

}


function gestisci_res_vacanze()
{


		if ((http_req_res.readyState==4) || (http_req_res.readyState == "complete"))
		{
			var xmlDoc= http_req_res.responseXML.documentElement;
			$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
			$sessionid = xmlDoc.getElementsByTagName("sessionid").item(0).firstChild.data;
			try {$idprof =  xmlDoc.getElementsByTagName("idprof").item(0).firstChild.data; } catch (e1) {$idprof=""};

			document.getElementById('messaggi').innerHTML = "OK... reloading page";	
			
			if ($errore=="NO") {//alert($sessionid);
								
								if ($idprof) {$location = "index.php?page=vacanze&idprof="+$idprof+"&PHPSESSID="+$sessionid;}
								else $location = "index.php?page=vacanze&PHPSESSID="+$sessionid;
								
								window.location= $location;
								}
	
		
		}
		
	    else 
		{
			 document.getElementById('messaggi').innerHTML = "richiesta in corso...";
		}

}

function gestisci_privacy()
{

if ((http_req_mess.readyState==4) || (http_req_mess.readyState == "complete"))
		{
			var output_privacy= http_req_mess.responseText;
			document.getElementById('AreaPrivacy').innerHTML = output_privacy;
			
		}
		
	    else 
		{
			 document.getElementById('AreaPrivacy').innerHTML = "Loading...";
		}


}


function GetPrivacyText()
{

	http_req_mess = crea_http_req();
	http_req_mess.open( "GET", $root+"/help/AjaxPrivacy.php");
	http_req_mess.setRequestHeader("Content-Type", "text/xml");
    http_req_mess.onreadystatechange = gestisci_privacy;
    http_req_mess.send(null);


}

// Utilizzato quando premo il tasto Aggiungi nella pagina dati prof



function gestisci_aggiunta_corso_1()
{

if ((http_req_aggiungi_1.readyState==4) || (http_req_aggiungi_1.readyState == "complete"))
		{
			var output = http_req_aggiungi_1.responseText;
			document.getElementById('SezioneInferiore').innerHTML = output;
			
		}
		
	    else 
		{
			 document.getElementById('SezioneInferiore').innerHTML = "Loading...";
		}


}



function ModificaLezione($id, $number)
{
window.location = $root+"/index.php?PHPSESSID="+$id+"&page=modifylesson&number="+$number+"";
}


function ModificaLezioneAzdPrf($id, $idprof, $number)
{
window.location = $root+"/index.php?PHPSESSID="+$id+"&idprof="+$idprof+"&page=modifylesson&number="+$number+"";
}




function Aggiungi($id, $number)
{

var $subject;

if ($number == "1") { $subject =  document.getElementById('corso_1').value; }
if ($number == "2") { $subject =  document.getElementById('corso_2').value; }
if ($number == "3") { $subject =  document.getElementById('corso_3').value; }
if ($number == "4") { $subject =  document.getElementById('corso_4').value; }

$subject = removeHTMLTags($subject);

http_req_aggiungi_1 = crea_http_req();
http_req_aggiungi_1.open( "GET", $root+"/ajax/ajaxaggiungidisplay.php?PHPSESSID="+$id+"&add="+$number+"&subject="+$subject+"");
http_req_aggiungi_1.setRequestHeader("Content-Type", "text/xml");
http_req_aggiungi_1.onreadystatechange = gestisci_aggiunta_corso_1;
http_req_aggiungi_1.send(null);

}


function AggiungiAzdPrf($id, $idprof, $number)
{



if ($number == "1") { $subject =  document.getElementById('corso_1').value; }
if ($number == "2") { $subject =  document.getElementById('corso_2').value; }
if ($number == "3") { $subject =  document.getElementById('corso_3').value; }
if ($number == "4") { $subject =  document.getElementById('corso_4').value; }

$subject = removeHTMLTags($subject);

http_req_aggiungi_1 = crea_http_req();
http_req_aggiungi_1.open( "GET", $root+"/ajax/ajaxaggiungidisplay.php?PHPSESSID="+$id+"&idprof="+$idprof+"&add="+$number+"&subject="+$subject+"");
http_req_aggiungi_1.setRequestHeader("Content-Type", "text/xml");
http_req_aggiungi_1.onreadystatechange = gestisci_aggiunta_corso_1;
http_req_aggiungi_1.send(null);

}


function gestisci_get_dati_materia()
{

if ((http_req_materia.readyState==4) || (http_req_materia.readyState == "complete"))
		{
			
		var xmlDoc= http_req_materia.responseXML.documentElement;
		$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
		
		if ($errore == "NO")
			{
			$materia = xmlDoc.getElementsByTagName("materia").item(0).firstChild.data;
			
			if ($materia != "empty") {document.getElementById('materia').value = $materia;}
			
			if ($materia != "empty")
				{
				
				$tariffa = xmlDoc.getElementsByTagName("tariffa").item(0).firstChild.data;
				$livello = xmlDoc.getElementsByTagName("livello").item(0).firstChild.data;
				$tipologia = xmlDoc.getElementsByTagName("tipologia").item(0).firstChild.data;
				$indirizzo = xmlDoc.getElementsByTagName("indirizzo").item(0).firstChild.data;
				$indirizzo = urldecode($indirizzo);
				$descrizione = xmlDoc.getElementsByTagName("descriz").item(0).firstChild.data;
				
				if ($tariffa == "empty") {$tariffa="";}
				document.getElementById('tariffa').value = $tariffa;
				
				document.getElementById('indirizzo').value = $indirizzo;
				
				if ($descrizione == "empty") {$descrizione="";}
				document.getElementById('descrizione_nuova').innerHTML = $descrizione;
				
				
				if ($livello == "Elementare") document.getElementById('livello_1').selected="selected";
				if ($livello == "Medio") {document.getElementById('livello_2').selected="selected";}
				if ($livello == "Alto") document.getElementById('livello_3').selected="selected";
				if ($livello == "Avanzato") document.getElementById('livello_4').selected="selected";
				if ($livello == "Tutti") document.getElementById('livello_5').selected="selected";
				
				if ($tipologia == "Istruzione") document.getElementById('gruppo_1').selected="selected";
				if ($tipologia == "Sport") document.getElementById('gruppo_2').selected="selected";
				if ($tipologia == "Tempo Libero") document.getElementById('gruppo_3').selected="selected";
				if ($tipologia == "Lingue") document.getElementById('gruppo_4').selected="selected";		
				
				for ($a = 1; $a<8; $a++)
					{
										
					$cal1 = "1_"+$a;
					$cal2 = "2_"+$a;
					$cal3 = "3_"+$a;
					$cal4 = "4_"+$a;
					
					$numday = "day"+$a;
					
					$dalle1 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle1").item(0).firstChild.data;
					if ($dalle1 != "ND") {document.getElementById($cal1).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle1+":00</p>";}
					
					$alle1 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle1").item(0).firstChild.data;
					if ($alle1 != "ND") {document.getElementById($cal2).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle1+":00</p>";}
					
					$dalle2 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle2").item(0).firstChild.data;
					if ($dalle2 != "ND") {document.getElementById($cal3).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle2+":00</p>";}
					
					$alle2 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle2").item(0).firstChild.data;
					if ($alle2 != "ND"){ document.getElementById($cal4).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle2+":00</p>";}
										
					}
				
				
				}
			
		    }
		
		}
	    else 
		{
			 //document.getElementById('dati_lower_part').innerHTML = "Loading...";
		}


}

function gestisci_get_orario()
{

if ((http_req_orario.readyState==4) || (http_req_orario.readyState == "complete"))
		{
			
		var xmlDoc= http_req_orario.responseXML.documentElement;
		$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
		
		if ($errore == "NO")
			{
				for ($a = 1; $a<8; $a++)
					{
										
					$cal1 = "1_"+$a;
					$cal2 = "2_"+$a;
					$cal3 = "3_"+$a;
					$cal4 = "4_"+$a;
					
					$numday = "day"+$a;
					
					
					try {$dalle1 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle1").item(0).firstChild.data;} catch (e1) {$dalle1 = "ND";};
					if ($dalle1 != "ND") {document.getElementById($cal1).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle1+":00</p>";}
					
					try {$alle1 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle1").item(0).firstChild.data;} catch (e2) {$alle1 = "ND";};
					if ($alle1 != "ND") {document.getElementById($cal2).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle1+":00</p>";}
					
					try {$dalle2 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("dalle2").item(0).firstChild.data;} catch (e2) {$dalle2 = "ND";};
					if ($dalle2 != "ND") {document.getElementById($cal3).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$dalle2+":00</p>";}
					
					try {$alle2 = xmlDoc.getElementsByTagName("dispon")[0].getElementsByTagName($numday)[0].getElementsByTagName("alle2").item(0).firstChild.data;} catch (e2) {$alle2 = "ND";};
					if ($alle2 != "ND"){ document.getElementById($cal4).innerHTML = "<p style=\"font-size:12px; margin:0px;\">"+$alle2+":00</p>";}
										
					}
				
			
		    }
		
		}
	    else 
		{
			 //document.getElementById('dati_lower_part').innerHTML = "Loading...";
		}


}


function AjaxGetDatiMateria($sessionid,$iduser, $numeromateria)
{	
    
    
    http_req_materia = crea_http_req();
    http_req_materia.open( "GET", $root+"/ajax/ajaxgetdatimateria.php?PHPSESSID="+$sessionid+"&iduser="+$iduser+"&number="+$numeromateria+"");
    http_req_materia.setRequestHeader("Content-Type", "text/xml");
    http_req_materia.onreadystatechange = gestisci_get_dati_materia;
    http_req_materia.send(null);
}






function AjaxGetOrarioCorso($sessionid, $iduser, $numeromateria)
{
	    
    http_req_orario = crea_http_req();
    http_req_orario.open( "GET", $root+"/ajax/ajaxgetorariocorso.php?PHPSESSID="+$sessionid+"&iduser="+$iduser+"&number="+$numeromateria+"");
    http_req_orario.setRequestHeader("Content-Type", "text/xml");
    http_req_orario.onreadystatechange = gestisci_get_orario;
    http_req_orario.send(null);
}


// Funzione richiamata quando si preme il tasto conferma nella pagina dati/materia" //




function gestisci_update_dati_materia()
{

if ((http_req_addmod_materia.readyState==4) || (http_req_addmod_materia.readyState == "complete"))
		{
			var xmlDoc= http_req_addmod_materia.responseXML.documentElement;
		    $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
		
			if ($errore == "NO") document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">Aggiornato</p>";
			else document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">"+$errore+"</p>";
			
		}
		
	    else 
		{
			 document.getElementById('result').innerHTML = "Loading...";
		}





}


function confermamodificamateria($sessionid, $iduser, $number)
{
	

var $errori = "no";
var $arraycalendario = new Array();
var $arraycontrollocal = new Array();

$materia =  document.getElementById('materia').value;
$descrizione = document.getElementById('descrizione_nuova').value;
$tariffa = document.getElementById('tariffa').value;

$livello_index = document.getElementById('select_livello').selectedIndex;
$livello = document.getElementById('select_livello').options[$livello_index].text;

$gruppo_index = document.getElementById('select_categoria').selectedIndex;
$gruppo = document.getElementById('select_categoria').options[$gruppo_index].text; //returns "Option 3"

$indirizzo = document.getElementById('indirizzo').value;

$arraycalendario = AjaxGenerateArrayCalendario();
$arraycontrollocal = AjaxControlloDatiCalendario($arraycalendario);
	
$notnull = $arraycalendario[0][0];  // Numero di valori non nulli all'interno del calendario
	
if ($notnull == "0") { $errori = "yes"; document.getElementById('label_disponibilita').style.background="red";}
if ($notnull != "0") {  document.getElementById('label_disponibilita').style.background=""; }
	
$errorecalendario = $arraycontrollocal[0][0];

if ($errorecalendario == "KO") { 
	
										for($j=1; $j<5; $j++)   //j = riga, i = colonna;
										
										{
										for ($i=1; $i<8; $i++)
										
											{	
											$id = $id = $j+"_"+$i;
											$errore = $arraycontrollocal[$j][$i];
											if ($errore == "KO") {document.getElementById($id).style.background="red";}
											$errori = "yes";
											}
										}
	
									
									}
	
if ($errorecalendario == "OK") { 
	
										for($j=1; $j<5; $j++)   //j = riga, i = colonna;
										
										{
										for ($i=1; $i<8; $i++)
										
											{	
											$id = $id = $j+"_"+$i;
											document.getElementById($id).style.background="#ffffff";
											
											}
										}
	
									
		}

// CONTROLLI
$descrizione = removeHTMLTags($descrizione);
$materia = removeHTMLTags($materia);

$tariffa = CleanTariffa($tariffa);
$indirizzo = removeHTMLTags($indirizzo);

$calendar_stringed = GetArrayCalendarioStringed();

if (!$indirizzo) { $errori = "yes"; document.getElementById('label_indirizzo').style.background="red";}
if ($indirizzo)  {  document.getElementById('label_indirizzo').style.background=""; }
	
if (!$materia) { $errori = "yes"; document.getElementById('label_materia').style.background="red";}
if ($materia)  {  document.getElementById('label_materia').style.background=""; }

//if (!$gruppo) { $errori = "yes"; document.getElementById('label_gruppo').style.background="red";}
//if ($gruppo)  {  document.getElementById('label_gruppo').style.background=""; }

if ($errori == "no")
{
    
    
        $tosend = $root+"/ajax/ajaxupdatemateria.php?PHPSESSID="+$sessionid+"&iduser="+$iduser+"&cal1="+$calendar_stringed[1]+"&cal2="+$calendar_stringed[2]+"&cal3="+$calendar_stringed[3]+"&cal4="+$calendar_stringed[4]+"&number="+$number+"&materia="+$materia+"&tariffa="+$tariffa+"&livello="+$livello+"&gruppo="+$gruppo+"&indirizzo="+$indirizzo+"&descrizione="+$descrizione+"";
	http_req_addmod_materia = crea_http_req();
	http_req_addmod_materia.open( "GET", $tosend);
	http_req_addmod_materia.setRequestHeader("Content-Type", "text/xml; charset=ISO-8859-1");
	http_req_addmod_materia.onreadystatechange = gestisci_update_dati_materia;
	http_req_addmod_materia.send(null);
}


// CONTROLLI END
}


function gestisci_chksovrapp()
{


if ((http_req_chksovrapp.readyState==4) || (http_req_chksovrapp.readyState == "complete"))
		{
			var xmlDoc= http_req_chksovrapp.responseXML.documentElement;
                        $controllo = xmlDoc.getElementsByTagName("controllo").item(0).firstChild.data;
                        $errore = xmlDoc.getElementsByTagName("error").item(0).firstChild.data;
                        $test = xmlDoc.getElementsByTagName("test").item(0).firstChild.data;
                        
                        
                        
                        if ($errore != "NO")
                        {
                        document.getElementById('result').innerHTML = "FAILED";
                        }
                        
                        else
                        {
                    
                        document.getElementById('result').innerHTML = $controllo;
                        
                        if ($controllo == "SOVRAPPOSIZIONE")
                            {
                            document.getElementById('result').innerHTML = "FALLITO";
                            
                            document.getElementById('label_disponibilita').style.background="red";
                            alert("ATTENZIONE! Uno o piu' impegni precedentemente presi si sovrappongono alle lezioni del corso; la combinazione data/ora proposta non e' acccettabile");
                            }
                           
			else if  ($controllo == "VACANZE")
			    {
                            document.getElementById('result').innerHTML = "FALLITO";
                            
                            document.getElementById('label_disponibilita').style.background="red";
			    document.getElementById('label_datainizio').style.background="red";
			    document.getElementById('label_datafine').style.background="red";
                            
			    alert("ATTENZIONE! Uno o piu' periodi di vacanza precedentemente presi si sovrappongono alle lezioni del corso; le date per il corso non sono acccettabili");
                            }
			    
			    
                            
                        else if ($controllo == "EI")
                            {
                             document.getElementById('result').innerHTML = "ERRORE";

                            }
                            
                        else if ($controllo == "OK")
                            {
               
                            document.getElementById('result').innerHTML = "AGGIORNATO";
                            
                            
                            }
		    
		    
		        else
			
			{
                
			 document.getElementById('result').innerHTML = $controllo;
                        
                        }
                        
			
			
		    }
                    
		
                //document.getElementById('result').innerHTML = $test;
                
                }
		
	    else 
		{
			 document.getElementById('result').innerHTML = "Loading...";
		}





}




function ConfermaModificaCorso($phpsessid, $iduser, $number, $datetoday)
{
       
    var $errori = "no";
    var $arraycalendario = new Array();
    var $arraycontrollocal = new Array();

    document.getElementById('label_disponibilita').style.background="red";
    
    $materia =  document.getElementById('materia').value;
    $descrizione = document.getElementById('descrizione_nuova').value;
    $tariffa = document.getElementById('tariffa').value;
    $numero_stud = document.getElementById('numero_stud').value;

    $livello_index = document.getElementById('select_livello').selectedIndex;
    $livello = document.getElementById('select_livello').options[$livello_index].text;
    
    $categoria_index = document.getElementById('select_categoria').selectedIndex;
    $categoria = document.getElementById('select_categoria').options[$categoria_index].value;
    
    /// ANNOINIZIO //
    
    $giornoinizio_index = document.getElementById('select_giornoinizio').selectedIndex;
    $giornoinizio = document.getElementById('select_giornoinizio').options[$giornoinizio_index].value;
        
    $meseinizio_index = document.getElementById('select_meseinizio').selectedIndex;
    $meseinizio = document.getElementById('select_meseinizio').options[$meseinizio_index].value;
    
    $annoinizio_index = document.getElementById('select_annoinizio').selectedIndex;
    $annoinizio = document.getElementById('select_annoinizio').options[$annoinizio_index].text;

    /// ANNOFINE //
    
    $giornofine_index = document.getElementById('select_giornofine').selectedIndex;
    $giornofine = document.getElementById('select_giornofine').options[$giornofine_index].value;
      
    $mesefine_index = document.getElementById('select_mesefine').selectedIndex;
    $mesefine = document.getElementById('select_mesefine').options[$mesefine_index].value;
    
    $annofine_index = document.getElementById('select_annofine').selectedIndex;
    $annofine = document.getElementById('select_annofine').options[$annofine_index].text;

    ///////////////////
    $livello_index = document.getElementById('select_livello').selectedIndex;
    $livello = document.getElementById('select_livello').options[$livello_index].text;
    
    $categoria_index = document.getElementById('select_categoria').selectedIndex;
    $categoria = document.getElementById('select_categoria').options[$categoria_index].value;
    
    $indirizzo = document.getElementById('indirizzo').value;
    $descrizione = document.getElementById('descrizione_nuova').value;
    
    if (!$materia)
    {
    
        $errori = "yes";
        document.getElementById('label_materia').style.backgroundColor = "#ff0000";
    }
    
    else
    
    {
        document.getElementById('label_materia').style.backgroundColor = "";
    }
    
    
    
    /////
    if ($tariffa)
        {
        var $tariffatomatch = /^[0-9]{1,4}$/;
        $result = $tariffatomatch.test($tariffa);
            
            if ($result == false)
            {
            $errori = "yes";
            document.getElementById('label_tariffa').style.backgroundColor = "#ff0000";
            }
            else
            {
            
            document.getElementById('label_tariffa').style.backgroundColor = "";
            }
        }
    
    else
        {
        document.getElementById('label_tariffa').style.backgroundColor = "";
        }
    /////////////////////////////
    
    if (!$numero_stud)
    {
        $errori = "yes";
        document.getElementById('label_numerostud').style.backgroundColor = "#ff0000";
    }
    
    else
    {
        $result = ConsistenzaNumero($numero_stud)
		if ($result == "passed") document.getElementById('label_numerostud').style.backgroundColor = "";
	    else
		{
			document.getElementById('label_numerostud').style.backgroundColor = "#ff0000";
			$errori = "yes";
		}
    }
    
    ///////////////////////////
    
    if ($meseinizio<10) $meseinizio = "0"+$meseinizio;
    if ($giornoinizio<10) $giornoinizio = "0"+$giornoinizio;
    
    if ($mesefine<10) $mesefine = "0"+$mesefine;
    if ($giornofine<10) $giornofine = "0"+$giornofine;
    
    $datainizio = $annoinizio+$meseinizio+$giornoinizio;
    $datafine = $annofine+$mesefine+$giornofine;
    
    
    
    if ($datainizio>$datafine)
    {
	
        
        $errori = "yes";
	document.getElementById('label_datainizio').style.backgroundColor = "#ff0000";
	document.getElementById('label_datafine').style.backgroundColor = "#ff0000";
    }
        
    else
    {
	if ($datainizio<$datetoday)
	{
	    $errori = "yes";
	    document.getElementById('label_datainizio').style.backgroundColor = "#ff0000";
	}
	
	else
	{
	    document.getElementById('label_datainizio').style.backgroundColor = "";
	}
    
        if ($datafine<$datetoday)
	{
	    $errori = "yes";
	    document.getElementById('label_datafine').style.backgroundColor = "#ff0000";
	}
    
       else
	{
	    document.getElementById('label_datafine').style.backgroundColor = "";
	}
	
	$arraycalendario = AjaxGenerateArrayCalendario();	
	$notnull = $arraycalendario[0][0];  // Numero di valori non nulli all'interno del calendario
	
        if ($notnull == "0") { $errori = "yes"; document.getElementById('label_disponibilita').style.background="red";}
        if ($notnull != "0") {  document.getElementById('label_disponibilita').style.background=""; }
	
	$arraycontrollocal = AjaxControlloDatiCalendario($arraycalendario);
	
	$errorecalendario = $arraycontrollocal[0][0];

	if ($errorecalendario == "KO") { 
	
										for($j=1; $j<5; $j++)   //j = riga, i = colonna;
										
										{
										for ($i=1; $i<8; $i++)
										
											{	
											$id = $j+"_"+$i;
											$errore = $arraycontrollocal[$j][$i];
											if ($errore == "KO") {document.getElementById($id).style.background="red";}
											$errori = "yes";
											}
										}
	
									
									}
	
	    if ($errorecalendario == "OK") { 
	
										for($j=1; $j<5; $j++)   //j = riga, i = colonna;
										
										{
										for ($i=1; $i<8; $i++)
										
											{	
											$id = $j+"_"+$i;
											document.getElementById($id).style.background="#ffffff";
											
											}
										}
	
									
		}
	
        
        $calendario_encoded = js_base64_encode(js_serialize($arraycalendario)); 
	        
        if ($errori == "no")
        {
	http_req_chksovrapp = crea_http_req();
	http_req_chksovrapp.open( "GET", $root+"/ajax/ajaxchksovrapp.php?PHPSESSID="+$phpsessid+"&iduser="+$iduser+"&categoria="+$categoria+"&indirizzo="+$indirizzo+"&livello="+$livello+"&datainizio="+$datainizio+"&nomecorso="+$materia+"&numerostud="+$numero_stud+"&number="+$number+"&datafine="+$datafine+"&calendarioenc="+$calendario_encoded+"&descrizione="+$descrizione+"&tariffa="+$tariffa+"");
	http_req_chksovrapp.setRequestHeader("Content-Type", "text/xml");
	http_req_chksovrapp.onreadystatechange = gestisci_chksovrapp;
	http_req_chksovrapp.send(null);
        }
	
	
	
	
    }
 
 
 if (!$indirizzo)

       {
	    $errori = $errori+1;
	    document.getElementById('label_indirizzo').style.backgroundColor = "#ff0000";
	}
    
       else
	{
	    document.getElementById('label_indirizzo').style.backgroundColor = "";
	}        
}


function CancellaMateria($id, $number)
{
	window.location = $root+"/index.php?PHPSESSID="+$id+"&page=eraselesson&number="+$number+"";
}

function CancellaMateriaAzdPrf($id, $iduser, $number)
{
	window.location = $root+"/index.php?PHPSESSID="+$id+"&page=eraselesson&iduser="+$iduser+"&number="+$number+"";
}


function gestisci_erase_materia()
{


   if ((http_req_canc_materia.readyState==4) || (http_req_canc_materia.readyState == "complete"))
		{
			var xmlDoc= http_req_canc_materia.responseXML.documentElement;
		    $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
			
			if ($errore == "NO") document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">Eliminato</p>";
			else document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\"></p>";
			
		}
		
	    else 
		{
			 document.getElementById('result').innerHTML = "Richiesta...";
		}

}



function execute_cancellamateria($id, $iduser, $number)
{

    http_req_canc_materia = crea_http_req();
    http_req_canc_materia.open( "GET", $root+"/ajax/ajaxerasemateria.php?PHPSESSID="+$id+"&number="+$number+"&iduser="+$iduser+"");
    http_req_canc_materia.setRequestHeader("Content-Type", "text/xml");
    http_req_canc_materia.onreadystatechange = gestisci_erase_materia;
    http_req_canc_materia.send(null);

}



function gestisci_offerta_descrizione()
{

if ((http_req_offerta_materia.readyState==4) || (http_req_offerta_materia.readyState == "complete"))
		{
			$ciccio = http_req_offerta_materia.responseText;
		    document.getElementById('main_research').innerHTML = $ciccio;
				
		}
		
	    else 
		{
			 document.getElementById('main_research').innerHTML = "<p>Loading...</p>";
		}


}

function gestisci_offerta_info()
{

if ((http_req_offerta_info.readyState==4) || (http_req_offerta_info.readyState == "complete"))
		{
			$output = http_req_offerta_info.responseText;
		    document.getElementById('main_research').innerHTML = $output;	
		}
		
	    else 
		{
			 document.getElementById('main_research').innerHTML = "<p>Loading...</p>";
		}

}

function offerta_info($id, $iduser, $campomateria, $materiacercata, $errorelogin, $controlloguest)
{
			
	http_req_offerta_info = crea_http_req();
    http_req_offerta_info.open( "GET", $root+"/ajax/ajaxoffertainfo.php?PHPSESSID="+$id+"&materiacercata="+$materiacercata+"&iduser="+$iduser+"&campomateria="+$campomateria+"&errorelogin="+$errorelogin+"&controlloguest="+$controlloguest+"&sid=" + Math.random());
    http_req_offerta_info.setRequestHeader("Content-Type", "text/xml");
    http_req_offerta_info.onreadystatechange = gestisci_offerta_info;
    http_req_offerta_info.send(null);
	

}

function offerta_descrizione($iduser, $campomateria, $phpsessid)
{

    
    var $selected_year;
	var $selected_month;
	var $mese;
   
    try {   
          $anno = document.getElementById('anniforavailable');
        } catch (e1) 
		
		{
				
		}
		
	try {   
          $mese = document.getElementById('mesiforavailable');
        } catch (e2) 
		
		{
				
		}
		
    if (($anno != null)&&($mese!=null)) { try{$selected_year = $anno.options[$anno.selectedIndex].text; } catch (e3) { }
	                                      try{$selected_month = $mese.options[$mese.selectedIndex].value; } catch (e4) { }
									   } 
	
	document.getElementById('pbt_descrizione').style.backgroundImage="url("+$root+"/immagini/button_green_on.jpg)";
	
    http_req_offerta_materia = crea_http_req();
    http_req_offerta_materia.open( "GET", $root+"/ajax/ajaxoffertadescrizione.php?PHPSESSID="+$phpsessid+"&iduser="+$iduser+"&campomateria="+$campomateria+"&anno="+$selected_year+"&mese="+$selected_month+"");
    http_req_offerta_materia.setRequestHeader("Content-Type", "text/html");
    http_req_offerta_materia.onreadystatechange = gestisci_offerta_descrizione;
    http_req_offerta_materia.send(null);

}


function gestisci_offerta_prenota()
{

if ((http_req_offerta_prenota.readyState==4) || (http_req_offerta_prenota.readyState == "complete"))
		{
			$output = http_req_offerta_prenota.responseText;
		    document.getElementById('main_research').innerHTML = $output;	
		}
		
	    else 
		{
			 document.getElementById('main_research').innerHTML = "<p>Loading...</p>";
		}

}



function offerta_prenota($id, $iduser, $campomateria, $materiacercata, $errorelogin, $controlloguest)
{
    http_req_offerta_prenota = crea_http_req();
    http_req_offerta_prenota.open( "GET", $root+"/ajax/ajaxoffertaprenota.php?PHPSESSID="+$id+"&materiacercata="+$materiacercata+"&iduser="+$iduser+"&campomateria="+$campomateria+"&errorelogin="+$errorelogin+"&controlloguest="+$controlloguest+"&sid=" + Math.random());
    http_req_offerta_prenota.setRequestHeader("Content-Type", "text/xml");
    http_req_offerta_prenota.onreadystatechange = gestisci_offerta_prenota;
    http_req_offerta_prenota.send(null);
}



/* *********************************************************** /*
Nome: 		gestisci_update_cal()
Funzionalitą: 	Gestisce l'output del file ajaxupdatecal, che ridisegna il calendario al variare della select "mese""anno"			
Ingressi: 		Nessuno
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */

function gestisci_update_cal()
{

if ((http_req_update_cal.readyState==4) || (http_req_update_cal.readyState == "complete"))
		{
		    var $output = http_req_update_cal.responseText;
		    document.getElementById('Calendario').innerHTML = $output;		
		}
		
	    else 
		{
			document.getElementById('result').innerHTML="<p style=\"font-size:12px; margin:0px; \">UPDATING...</p>";
		}

}


/* *********************************************************** /*
Nome: 		UpdateCalendario()
Funzionalitą: 	Quando un utente cambia il valore della select "anno" o "mese" richiama il file ajax che  ridisegna il calendario. 			
Ingressi: 		$phpsessid = identificativo di sessione (se presente)
			$iduser = identificativo del professore a cui appartiene la materia per cui si visualizza il calendario
			$campomateria = numero della materia all'interno del database
			$tipocalendario = 1 se e' il calendario per la prenotazione materia, 0 se e' il calendari small
			
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2008  - Michele Moroni
/* *********************************************************** */


function UpdateCalendario($phpsessid, $iduser, $campomateria,$tipocalendario)     //0 = small 1 = prenotazione
{
	
	document.getElementById('result').innerHTML="<p style=\"font-size:12px; margin:0px; \">UPDATING...</p>";
	
	var $selected_year;
	var $selected_month;
	var $mese;
	 
    var $anno_index = document.getElementById("anno_index").value;
    var $mese_index = document.getElementById("mese_index").value;

    
    http_req_update_cal = crea_http_req();
    http_req_update_cal.open( "GET", $root+"/ajax/ajaxupdatecal.php?PHPSESSID="+$phpsessid+"&iduser="+$iduser+"&campomateria="+$campomateria+"&anno="+$anno_index+"&mese="+$mese_index+"&tipo="+$tipocalendario+"");
    http_req_update_cal.setRequestHeader("Content-Type", "text/html");
    http_req_update_cal.onreadystatechange = gestisci_update_cal;
    http_req_update_cal.send(null);


}

/* *********************************************************** /*
Nome: 		gestisci_send_messaggi_tutti
Funzionalitą: 	Gestisce l'output del file ajaxsendmessage.php, usato per inviare un messaggio 1 a 1				
Ingressi: 		Nessuno
Uscite:		Nessuna
Note:		Se la scrittura dei messaggi ha avuto successo  visualizza "INVIATO", in caso contrario visualizza "Fallito"
		          nell'area "result"
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */


function gestisci_send_message()
{

		
   if ((http_req_send_message.readyState==4) || (http_req_send_message.readyState == "complete"))
		{
			var xmlDoc= http_req_send_message.responseXML.documentElement;
		    $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
			
			if ($errore == "NO") document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">INVIATO</p>";
			else document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">"+$errore+"</p>";
			
		}
		
	    else 
		{
			 document.getElementById('result').innerHTML = "<p style=\"font-size:12px; margin:0px; \">In corso...</p>";
		}

}

/* *********************************************************** /*
Nome: 		gestisci_send_messaggi_tutti
Funzionalitą: 	Gestisce l'output del file ajaxsendmessagetutti.php, usato per inviare un messaggio multiplo
			a tutti gli studenti confermati all'interno di un corso
				
Ingressi: 		Nessuno

Uscite:		Nessuna
Note:		Se la scrittura dei messaggi ha avuto successo  visualizza "INVIATO", in caso contrario visualizza "Fallito"
		          nell'area "result"
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */



function gestisci_send_message_tutti()
{

		
   if ((http_req_send_message.readyState==4) || (http_req_send_message.readyState == "complete"))
		{
			var xmlDoc= http_req_send_message.responseXML.documentElement;
		        $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
			
			if ($errore == "NO") document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">INVIATO</p>";
			else document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">Fallito</p>";
			
		}
		
	    else 
		{
			 document.getElementById('result').innerHTML = "<p style=\"font-size:12px; margin:0px; \">In corso...</p>";
		}



}

/* *********************************************************** /*
Nome: 		Invia_messaggio_forinfo
Funzionalitą: 	Chiama il file ajax che gestisce l'invio di un messaggio 1 a 1 (prof to student o student to prof)
				
Ingressi: 		$phpsessid = identificativo di sessione
			$idsender = identificativo di chi stai nviando il messaggio 
			$idreceiver = identificativo di chi deve ricevere il messaggio

Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */



function invia_messaggio_forinfo($phpsessid, $idsender, $idreceiver)
{

$content = document.getElementById("contenutomessaggio").value;
$content_encoded = removeHTMLTags2($content);

    http_req_send_message = crea_http_req();
    http_req_send_message.open( "GET", $root+"/ajax/ajaxsendmessage.php?PHPSESSID="+$phpsessid+"&idsender="+$idsender+"&idreceiver="+$idreceiver+"&message="+$content_encoded+"");
    http_req_send_message.setRequestHeader("Content-Type","text/html; charset=utf-8");
    http_req_send_message.onreadystatechange = gestisci_send_message;
    http_req_send_message.send(null); 

}


/* *********************************************************** /*
Nome: 		Invia_messaggio_tutti
Funzionalitą: 	Chiama il file ajax che gestisce l'invio di un messaggio da un prof a tutti gli studenti iscritti ad un corso
				
Ingressi: 		$phpsessid = identificativo di sessione
			$idsender = identificativo del professore che gestisce il corso
			$codcorso = codice del corso a cui gli allievi sono iscritti

Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */

function invia_messaggio_tutti($phpsessid, $idsender, $codcorso)
{
    
$content = document.getElementById("contenutomessaggio").value;
$content_encoded = removeHTMLTags2($content);

    http_req_send_message = crea_http_req();
    http_req_send_message.open( "GET", $root+"/ajax/ajaxsendmessagetutti.php?PHPSESSID="+$phpsessid+"&idsender="+$idsender+"&codcorso="+$codcorso+"&message="+$content_encoded+"");
    http_req_send_message.setRequestHeader("Content-Type", "text/html");
    http_req_send_message.onreadystatechange = gestisci_send_message_tutti;
    http_req_send_message.send(null); 
    
}


/* *********************************************************** /*
Nome: 		gestisci_visualizzazione_news()
Funzionalitą: 	inserisce nella pagina "news" il file ajax corrispondente alle news, definito nella funzione AjaxNews
							
Ingressi: 		Nessuno			
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */

function gestisci_visualizzazione_news()
{


 if ((http_req_news.readyState==4) || (http_req_news.readyState == "complete"))
		{			
                    var $output = http_req_news.responseText;
		    document.getElementById('News').innerHTML = $output;		           
                }
		
	    else 
		{
			 document.getElementById('News').innerHTML = "<p style=\"font-size:12px; margin:0px; \">Loading News</p>";
		}

}


/* *********************************************************** /*
Nome: 		AjaxNews
Funzionalitą: 	All'interno della pagina "News" viene richiamata automaticamente per inserire il file corrispondente alle news
				
Ingressi: 		Nessuno
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */

function AjaxNews()
{
   http_req_news = crea_http_req();
   http_req_news.open( "GET", $root+"/news/news.html");
   http_req_news.setRequestHeader("Content-Type", "text/html");
   http_req_news.onreadystatechange = gestisci_visualizzazione_news;
   http_req_news.send(null); 
}

/* *********************************************************** /*
Nome: 		gestisci_pp_cliente
Funzionalitą: 	inserisce nella pagina "le nostre aziende" il file ajax corrispondente alla pagina del cliente, definito dalla funzione "javaaziende"
							
Ingressi: 		Nessuno			
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */


function gestisci_pp_cliente()
{

            if ((http_req_mess.readyState==4) || (http_req_mess.readyState == "complete"))
		{
                    var $output = http_req_mess.responseText;
		    document.getElementById('MainNostreAziende').innerHTML = $output;		
                }
		
	    else 
		{
			 document.getElementById('MainNostreAziende').innerHTML = "<p style=\"font-size:12px; margin:0px; \">Loading...</p>";
		}
		
}


/* *********************************************************** /*
Nome: 		JavaAziende
Funzionalitą: 	All'interno della pagina "Le nostre aziende" viene richiamata quando l'utente clicca sul logo.
			Richiama la pagina specifica del cliente a cui corrisponde il logo
				
Ingressi: 		$nomecliente = directory dove sono situati i file relativi al cliente (deve avere corrispondenza nel database)
			
Uscite:		Nessuna
Note:		Nessuna
Modifica:		24/05/2009 - Michele Moroni
/* *********************************************************** */


function JavaAziende($nomecliente, $timestamp, $phpsessid)
{

    
    WriteStatistics("Descrizione Azienda");
    
    http_req_mess = crea_http_req();
    $toopen = $root+"/clienti/"+$nomecliente+"/index.php?&timestamp="+$timestamp+"&phpsessid="+$phpsessid+"&mat="+Math.random();
    http_req_mess.open( "GET", $toopen);
    http_req_mess.setRequestHeader("Content-Type", "text/html");
    http_req_mess.onreadystatechange = gestisci_pp_cliente;
    http_req_mess.send(null); 
}


function gestisci_dettaglio_aziende($phpsessid, $timestamp, $subpage)
{
        
    if ($phpsessid=="undefined") $phpsessid="";

    if ((http_req_dettaglio.readyState==4) || (http_req_dettaglio.readyState == "complete"))
		{
                    var $output = http_req_dettaglio.responseText;
		    document.getElementById('MainNostreAziende').innerHTML = $output;
		    
		    if ($subpage=="1")
			    {
			     GetCorsiAzd($phpsessid, $timestamp); 
			    }
			    
		     if ($subpage=="2")
			    {
			     GetContattiAzd($phpsessid,$timestamp);
			    }
			    
			    
			    
                }
		
	    else 
		{
			 document.getElementById('MainNostreAziende').innerHTML = "<p style=\"font-size:12px; margin:0px; \">Loading...</p>";
		}
}


function JavaAzdGen($phpsessid, $timestamp, $subpage, $position_bar)
{    
    
    var stat;
    
    if ($subpage == 0) stat = "Descrizione Azienda";
    if ($subpage == 1) stat = "Corsi Azienda";
    if ($subpage == 2) stat = "Info Azienda";
    
    WriteStatistics(stat);
    
    http_req_dettaglio = crea_http_req();
    http_req_dettaglio.open( "GET", $root+"/ajax/ajaxgetpagdettaglio.php?phpsessid="+$phpsessid+"&timestamp="+$timestamp+"&subpage="+$subpage+"&position_bar="+$position_bar+"");
    http_req_dettaglio.setRequestHeader("Content-Type", "text/html");
    http_req_dettaglio.onreadystatechange = function () {gestisci_dettaglio_aziende($phpsessid, $timestamp, $subpage);};
    http_req_dettaglio.send(null); 
}
    


function gestisci_servizi()
{

        if ((http_req_serv.readyState==4) || (http_req_serv.readyState == "complete"))
		{
                    var $output = http_req_serv.responseText;
                    document.getElementById('TestoServizi').innerHTML = $output;	
                }
		
	    else 
		{
			  document.getElementById('TestoServizi').innerHTML = "Loading";	
		}
		
}


function servizi($numeropagina)
{
    
    $errore = "NO";
    $pagina = "";
    
    if ($numeropagina == "0") {$pagina = "servizioggi.php";}
    else if ($numeropagina == "1") {$pagina = "servizifuturi.php";}
    else if ($numeropagina == "2") {$pagina = "servizirichiedi.php";}
    
    else {
         $errore = "YES";
         }

    if ($errore == "NO")
        {
        http_req_serv = crea_http_req();
        $toopen = $root+"/servizi/"+$pagina+"?mat="+Math.random();
        
        
        
        http_req_serv.open( "GET", $toopen);
        http_req_serv.setRequestHeader("Content-Type", "text/html");
        http_req_serv.onreadystatechange = gestisci_servizi;
        http_req_serv.send(null);  
        }
}



function gestisci_richiesta_servizi()
{

        if ((http_req_richiedi.readyState==4) || (http_req_richiedi.readyState == "complete"))
		{
                var xmlDoc= http_req_richiedi.responseXML.documentElement;
		        $errore = xmlDoc.getElementsByTagName("error").item(0).firstChild.data;
			
				if ($errore == "OK") document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">MESSAGGIO INVIATO</p>";
				else document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">Fallito</p>";
			
                }
		
	    else 
		{
			  document.getElementById('result').innerHTML = "Loading";	
		}
		
}

function InviaMessageForRichiedi($tiporichiesta)
{
   
   $servizio_index = document.getElementById('select_servizio').selectedIndex;
   $servizio = document.getElementById('select_servizio').options[$servizio_index].text;
   
   $nome = document.getElementById('nome').value;
   $nome = removeHTMLTags($nome)
   
   $email = document.getElementById('email').value;
   $email = removeHTMLTags($email)
   
   $domanda = document.getElementById('domanda').value;
   $domanda = removeHTMLTags($domanda);
      
   
   http_req_richiedi = crea_http_req();
   http_req_richiedi.open( "GET", $root+"/ajax/ajaxrichiedi.php?tiporichiesta="+$tiporichiesta+"&servizio="+$servizio+"&nome="+$nome+"&email="+$email+"&domanda="+$domanda+"");
   http_req_richiedi.setRequestHeader("Content-Type", "text/html");
   http_req_richiedi.onreadystatechange = gestisci_richiesta_servizi;
   http_req_richiedi.send(null);
	
	
}


function gestisci_richiesta_diventaprof()
{

        if ((http_req_diventaprof.readyState==4) || (http_req_diventaprof.readyState == "complete"))
		{
                var xmlDoc= http_req_diventaprof.responseXML.documentElement;
		$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
		$errore_prov = xmlDoc.getElementsByTagName("errore_prov").item(0).firstChild.data;
		$phpsessid = xmlDoc.getElementsByTagName("phpsessid").item(0).firstChild.data;
		//$test = xmlDoc.getElementsByTagName("test").item(0).firstChild.data;
			
	        if ($errore != "NO")
		   {
			document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">FALLITO</p>";
		    }
	        
		else
		
		   {
		       // document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">"+$errore_prov+"</p>";
		        if ($errore_prov == "YES")
			   {
			   $errori=  $errori+1;
			   document.getElementById('label_provincia').style.backgroundColor="#cc0000";
			   document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:red; margin:0px;\">SIGLA PROVINCIA ERRATA</p>";
			   }
			else
			   {
			   document.getElementById('result').innerHTML = "<p style=\"font-size:16px; color:green; margin:0px;\">Richiesta OK</p>";
			   redirect('index.php?page=welcomenewprof', $phpsessid);
			   }
		   }
	
			
                }
		
	    else 
		{
			  document.getElementById('result').innerHTML = "Richiesta in corso...";	
		}
		
}


function ConfirmDiventaProf($PHPSESSID)
{
    
    $errori = 0;

    $citta = document.getElementById('domicilio').value;

    $nazione_index = document.getElementById('select_stato').selectedIndex;
    $nazione = document.getElementById('select_stato').options[$nazione_index].text //returns "Option 3"
	
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;

    $province_index = document.getElementById('lista_province').selectedIndex;
    $provincia = document.getElementById('lista_province').options[$province_index].text;
    
    if ($citta == "") {
				$errori=  $errori+1; document.getElementById('label_domicilio').style.backgroundColor="#cc0000";
			    }
    else
			    {
			        document.getElementById('label_domicilio').style.backgroundColor="";
			    }
			    
    if ($provincia == "") {
					$errori=  $errori+1; document.getElementById('label_provincia').style.backgroundColor="#cc0000";
				    }
    else
    
				    {
					document.getElementById('label_provincia').style.backgroundColor="";
				    }
    
    $genere = document.getElementById('genere').value;
   
    //$telefono = document.getElementById('telefono').value;
    //$telefonocleaned = CleanPhoneNumber($telefono);

    if ($errori == 0)
    
    {
		
	http_req_diventaprof = crea_http_req();
	http_req_diventaprof.open( "GET", $root+"/ajax/ajaxcontrollodiventaprof.php?phpsessid="+$PHPSESSID+"&nazione="+$nazione+"&regione="+$regione+"&citta="+$citta+"&provincia="+$provincia+"&genere="+$genere+"");
	http_req_diventaprof.setRequestHeader("Content-Type", "text/html");
	http_req_diventaprof.onreadystatechange = gestisci_richiesta_diventaprof;
	http_req_diventaprof.send(null);
    }
    
}


function gestisci_richiesta_cancellaimmagine()
{

	if ((http_req_cancellaimmagine.readyState==4) || (http_req_cancellaimmagine.readyState == "complete"))
	{
	
	  var xmlDoc= http_req_cancellaimmagine.responseXML.documentElement;
	  //$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
	  document.getElementById('result').innerHTML = "<p style=\"color:green; font-size:12px\">Foto cancellata</p>";
	  document.getElementById('Foto').innerHTML = "";
	  //alert($errore);
	
	
	}

else
        {
	
	document.getElementById('result').innerHTML = "Richiesta...";
	
	
	}


}

function CancellaImmagine($PHPSESSID,$idprof)
{
    	
	http_req_cancellaimmagine = crea_http_req();
	http_req_cancellaimmagine.open( "GET", $root+"/ajax/ajaxcancellaimmagine.php?PHPSESSID="+$PHPSESSID+"&idprof="+$idprof+"");
	http_req_cancellaimmagine.setRequestHeader("Content-Type", "text/html");
	http_req_cancellaimmagine.onreadystatechange = gestisci_richiesta_cancellaimmagine;
	http_req_cancellaimmagine.send(null);
}

function gestisci_richiesta_cancellalezione()
	{

	    if ((http_req_cancellalezione.readyState==4) || (http_req_cancellalezione.readyState == "complete"))
	    {
	
	  var xmlDoc= http_req_cancellalezione.responseXML.documentElement;
	  $phpsessid = xmlDoc.getElementsByTagName("phpsessid").item(0).firstChild.data;
	  $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
	  if ($errore == "NO") {
				redirect('index.php?page=lezioni', $phpsessid);
			       }

else
        {
	
	//document.getElementById('result').innerHTML = "Richiesta...";
	
	
	}



	}

    }

function CancellaLezioneCorso($PHPSESSID, $codicecorso, $codethislesson)
{

	http_req_cancellalezione = crea_http_req();
	http_req_cancellalezione.open( "GET", $root+"/ajax/ajaxcancellalezione.php?PHPSESSID="+$PHPSESSID+"&codicecorso="+$codicecorso+"&codicelezione="+$codicelezione+"");
	http_req_cancellalezione.setRequestHeader("Content-Type", "text/html");
	http_req_cancellalezione.onreadystatechange = gestisci_richiesta_cancellalezione;
	http_req_cancellalezione.send(null);


}

// Lista province per regione


function gestisci_richiesta_province()
{
    
    if ((http_req_listaprovince.readyState==4) || (http_req_listaprovince.readyState == "complete"))
	{
	
	  var $output = http_req_listaprovince.responseText;
          document.getElementById('DivProvincia').innerHTML=$output;
	  document.getElementById('DivCitta').innerHTML="";
	
	
	}

else
        {
	
	//document.getElementById('result').innerHTML = "Richiesta...";
	
	
	}
    
    
    
}



function gestisci_richiesta_listaaziende()
{
    if ((http_req_listaaziende.readyState==4) || (http_req_listaaziende.readyState == "complete"))
	{
	
	  var $output = http_req_listaaziende.responseText;
          document.getElementById('MainNostreAziende').innerHTML=$output;	
	
	
	}

else
        {
	document.getElementById('MainNostreAziende').innerHTML = "Richiesta...";
	}
}

function gestisci_richiesta_listaregioni()
{
    
    
    
    if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
	{
	  
	 
	  var $output = http_req_listaregioni.responseText;
	  
	  document.getElementById('div_regioni').innerHTML=$output;
	  
	   $nazione_index =  document.getElementById('nazioni').selectedIndex;
	   $nazione = document.getElementById('nazioni').options[$nazione_index].text
	  
	  if ($nazione=="Tutte")
	    {
	     //document.getElementById('Regioni_Tutte').selected = "selected";  
	     document.getElementById('div_regioni').disabled = "disabled";
	     document.getElementById('regioni').disabled = "disabled"; 
	    }
	    
	    if ($nazione!="Tutte")
	   {
	     document.getElementById('div_regioni').disabled = "";
	     document.getElementById('regioni').disabled = ""; 
	   }
	  
	  
	  
	
	}

else
        {
	
	//document.getElementById('MainNostreAziende').innerHTML = "Richiesta...";
	
	}
}
    




function ShowAzienda($phpsessid, $select)
{
       
   
   $stringa_cercata = document.getElementById('stringa_cercata').value
   
   $tipologia_index = document.getElementById('tipologia').selectedIndex;
   $tipologia = document.getElementById('tipologia').options[$tipologia_index].text
   
   $regione_index = document.getElementById('regioni').selectedIndex;
   $regione= document.getElementById('regioni').options[$regione_index].text
    
   $nazione_index =  document.getElementById('nazioni').selectedIndex;
   $nazione = document.getElementById('nazioni').options[$nazione_index].text
      
   http_req_listaaziende = crea_http_req();
   http_req_listaaziende.open( "GET", $root+"/ajax/ajaxgetlistaaziende.php?stringa_cercata="+$stringa_cercata+"&tipologia="+$tipologia+"&nazione="+$nazione+"&regione="+$regione+"&phpsessid="+$phpsessid+"");
   http_req_listaaziende.setRequestHeader("Content-Type", "text/html");
   http_req_listaaziende.onreadystatechange = gestisci_richiesta_listaaziende;
   http_req_listaaziende.send(null);
   
}


//Eseguita quando cambia stato nella pagina ricerca aziende

function ShowAziendaStato($phpsessid, $select_regioni)
{
              
    $stringa_cercata = document.getElementById('stringa_cercata').value
    
    $tipologia_index = document.getElementById('tipologia').selectedIndex;
    $tipologia = document.getElementById('tipologia').options[$tipologia_index].text
    
    $nazione_index =  document.getElementById('nazioni').selectedIndex;
    $nazione = document.getElementById('nazioni').options[$nazione_index].text
    
    if ($nazione=="Tutte")
    {
     //document.getElementById('Regioni_Tutte').selected = "selected";  
     document.getElementById('div_regioni').disabled = "disabled";
     document.getElementById('regioni').disabled = "disabled"; 
    }
    
    if ($nazione!="Tutte")
   {
     document.getElementById('div_regioni').disabled = "";
     document.getElementById('regioni').disabled = ""; 
   }
   
   $regione = "Tutte";
   
   
   http_req_listaaziende = crea_http_req();
   http_req_listaaziende.open( "GET", $root+"/ajax/ajaxgetlistaaziende.php?stringa_cercata="+$stringa_cercata+"&tipologia="+$tipologia+"&nazione="+$nazione+"&regione="+$regione+"&phpsessid="+$phpsessid+"");
   http_req_listaaziende.setRequestHeader("Content-Type", "text/html");
   http_req_listaaziende.onreadystatechange = gestisci_richiesta_listaaziende;
   http_req_listaaziende.send(null);
   
   http_req_listaregioni = crea_http_req();
   http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?stato="+$nazione+"&select="+$select_regioni+"&opt_tutte=On");
   http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
   http_req_listaregioni.onreadystatechange = gestisci_richiesta_listaregioni;
   http_req_listaregioni.send(null);
    
   //$var = $root+"/ajax/ajaxgetlistaregioni.php?stato="+$nazione+"&select="+$select_regioni+"&opt_tutte=On";
   //alert($var);
    
}



function SearchRegione($regione,$phpsessid)
{
       
   if (!$regione)
   {
   $regione_index = document.getElementById('regioni').selectedIndex;
   $regione= document.getElementById('regioni').options[$regione_index].text
   }
   
   else  // Qui vuol dire che abbiamo premuto la chiamata diretta nella lista regioni
   {
    var $indice=0;
    for ($index=0; $index<=20; $index++)
    {
	 
	 $regione_tocompare= document.getElementById('lista_regioni').options[$index].text
	 if ($regione_tocompare==$regione)
	 {  
	    document.getElementById('lista_regioni').selectedIndex = $index;
	 }
	
    }
    
    
   }
      
   $materia = document.getElementById('materia_cercata').value;

   http_req_listaprovince = crea_http_req();
   http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetprovince.php?&phpsessid="+$phpsessid+"&regione="+$regione+"");
   http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
   http_req_listaprovince.onreadystatechange = gestisci_richiesta_province;
   http_req_listaprovince.send(null);
   
   http_req_listaofferta = crea_http_req();
   http_req_listaofferta.open( "GET", $root+"/ajax/ajaxgetlistaofferta.php?&phpsessid="+$phpsessid+"&materia="+$materia+"&regione="+$regione+"");
   http_req_listaofferta.setRequestHeader("Content-Type", "text/html");
   http_req_listaofferta.onreadystatechange = gestisci_richiesta_listaofferta;
   http_req_listaofferta.send(null);
   
   $phpsessid_temp = $phpsessid;  // per recuperare l'identificativo di sessione dall'output ajax, se non passato internamente
    
}



function gestisci_richiesta_citta()
{
    
    if ((http_req_listacitta.readyState==4) || (http_req_listacitta.readyState == "complete"))
	{
	
	  var $output = http_req_listacitta.responseText;
          document.getElementById('DivCitta').innerHTML=$output;	
	
	
	}

else
        {
	
	//document.getElementById('result').innerHTML = "Richiesta...";
	
	
	}
    
    
    
}



function SearchProvincia($phpsessid)
{
    
   $regione_index = document.getElementById('lista_regioni').selectedIndex;
   $regione= document.getElementById('lista_regioni').options[$regione_index].text
   
   $provincia_index = document.getElementById('lista_province').selectedIndex;
   $provincia= document.getElementById('lista_province').options[$provincia_index].text

   $materia = document.getElementById('materia_cercata').value;

   http_req_listaofferta = crea_http_req();
   http_req_listaofferta.open( "GET", $root+"/ajax/ajaxgetlistaofferta.php?&phpsessid="+$phpsessid+"&materia="+$materia+"&regione="+$regione+"&provincia="+$provincia+"");
   http_req_listaofferta.setRequestHeader("Content-Type", "text/html");
   http_req_listaofferta.onreadystatechange = gestisci_richiesta_listaofferta;
   http_req_listaofferta.send(null);
   
   http_req_listacitta = crea_http_req();
   http_req_listacitta.open( "GET", $root+"/ajax/ajaxgetcitta.php?&phpsessid="+$phpsessid+"&provincia="+$provincia+"");
   http_req_listacitta.setRequestHeader("Content-Type", "text/html");
   http_req_listacitta.onreadystatechange = gestisci_richiesta_citta;
   http_req_listacitta.send(null);
   
   $phpsessid_temp = $phpsessid;  // per recuperare l'identificativo di sessione dall'output ajax, se non passato internamente
   
}


function SearchCitta($phpsessid)
{
    
   $regione_index = document.getElementById('regioni').selectedIndex;
   $regione= document.getElementById('regioni').options[$regione_index].text
   
   $provincia_index = document.getElementById('province').selectedIndex;
   $provincia= document.getElementById('province').options[$provincia_index].text
    
   $citta_index = document.getElementById('citta').selectedIndex;
   $localita = document.getElementById('citta').options[$citta_index].text
   
    $materia = document.getElementById('materia_cercata').value;
    
    http_req_listaofferta = crea_http_req();
   http_req_listaofferta.open( "GET", $root+"/ajax/ajaxgetlistaofferta.php?&phpsessid="+$phpsessid+"&materia="+$materia+"&regione="+$regione+"&provincia="+$provincia+"&localita="+$localita+"");
   http_req_listaofferta.setRequestHeader("Content-Type", "text/html");
   http_req_listaofferta.onreadystatechange = gestisci_richiesta_listaofferta;
   http_req_listaofferta.send(null);
    
    $phpsessid_temp = $phpsessid;  // per recuperare l'identificativo di sessione dall'output ajax, se non passato internamente
    
    
    
}



function gestisci_richiesta_listaofferta()
{
    
     if (( http_req_listaofferta.readyState==4) || (http_req_listaofferta.readyState == "complete"))
	{
		  	  
	  	  
	  $regione_index = document.getElementById('lista_regioni').selectedIndex;
	  $regione= document.getElementById('lista_regioni').options[$regione_index].text
   
   
	  document.getElementById('listamaterie').style.border="0px solid black";
	  document.getElementById('listamaterie').style.padding="5px";
	  var $output =  http_req_listaofferta.responseText;
	  
	  if ($regione=='Tutte')
	  {
	  document.getElementById('listamaterie').style.marginTop="40px";
	  document.getElementById('listamaterie').style.height="250px";	    
	  }
	  
	  else
	  {
	  document.getElementById('listamaterie').style.marginTop="-5px";
	  document.getElementById('listamaterie').style.height="300px";
	    
	  }
	  	  
          document.getElementById('listamaterie').innerHTML=$output;
	  
	   if ($output != "")
	   {
	    	    
	       //document.getElementById('headerlista').style.backgroundImage="";
	    
		if ($regione=='Tutte')
	       {
				
		document.getElementById('headerlista').style.backgroundImage="url("+$root+"/immagini/bg_db_02.jpg)";		
		$header = "<table width=\"\" border=\"0\" cellspacing=\"0\" style=\"font-size:14px; width:525px; font-weight:bold; margin-top:5px; color:#7e3905;\" ><tr><td style=\"width:210px\">REGIONE</td><td>NUMERO OFFERTE</td></tr></table>";
		document.getElementById('listamaterie').style.backgroundImage="url("+$root+"/immagini/bg_db_04.jpg)";
		document.getElementById('headerlista').innerHTML=$header;
	        //document.getElementById('materie_down').style.display='none';
	       }
	       else
	       {
		
		document.getElementById('headerlista').style.backgroundImage="";
		document.getElementById('listamaterie').style.backgroundImage="";
		document.getElementById('headerlista').innerHTML="";
		//document.getElementById('materie_down').style.display='block';
		
	        }
	   
	   
	   
	   
	   }
	  
	   else
	   {
	 
	    
	 
	    if ($phpsessid_temp==""||$phpsessid_temp==null)
	    {
		$lista = $root+"/index.php?page=materie";
                $iscrizione = $root+"/index.php?page=ingressoprofessori";   
	    }
	    else
	    {
		$lista = $root+"/index.php?PHPSESSID="+$phpsessid_temp+"&page=materie";
		$iscrizione = $root+"/index.php?PHPSESSID="+$phpsessid_temp+"&page=ingressoprofessori";  
	    }
	    	        
	    document.getElementById('listamaterie').innerHTML="<p style=\"margin:0px; font-size:12px;\">Non sono state trovate offerte compatibili con la materia cercata<br />&nbsp<br /></p><p style=\"margin:0px; font-size:12px;\">Prova con una nuova ricerca oppure <br />guarda la <a href='"+$lista+"' style=\"color:#854405; font-size:12px; text-decoration:underline\">lista completa delle materie disponibili</a><br />&nbsp;<br /></p><p style=\"margin:0px; font-size:12px;\">Vuoi dare lezioni private? Proponi la tua offerta su Iomulo!<br />Vai alla \"<a href='"+$iscrizione+"' style=\"color:#854405; font-size:12px; text-decoration:underline\">pagina iscrizione</a>\"</p>";
	    document.getElementById('headerlista').innerHTML="";
	    document.getElementById('listamaterie').style.backgroundImage="";
	    document.getElementById('headerlista').style.backgroundImage="";
	    
	    document.getElementById('listamaterie').style.border="0px solid black";
	   }
	   
	}

else
        {
	
	 document.getElementById('listamaterie').innerHTML = "Richiesta...";
	}
}


function RefreshListaOfferta($phpsessid, $nazione, $regione, $provincia, $citta)
{
  
       
   if ($phpsessid=="undefined") $phpsessid="";
   
     $corsi = document.getElementById('corsi_si').checked;
     $lezioni = document.getElementById('lezioni_si').checked;
    
   //if (!$nazione)
   // {
    $nazione_index = document.getElementById('select_stato').selectedIndex;
    $nazione= document.getElementById('select_stato').options[$nazione_index].text
   // }
   
   
   if (!$regione)
    {
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione= document.getElementById('lista_regioni').options[$regione_index].text
    }
   
   else
    {
        
    
    
    
    }
    
   
   
   
   if (!$provincia)
    {
	$provincia_index = document.getElementById('lista_province').selectedIndex;
	$provincia = document.getElementById('lista_province').options[$provincia_index].text
       
       try
	 {
	     $provincia_index = document.getElementById('lista_province').selectedIndex;
	     
	 }
	 
	 catch (e1) {$provincia_index="null"};
    }
   
   if (!$citta)
   {
   try
     {
	$citta_index = document.getElementById('lista_citta').selectedIndex;
	$citta = document.getElementById('lista_citta').options[$citta_index].text
       
     }
   
     catch (e2) {$citta_index="null"};   
   }
    
    //if ($provincia_index!="null") {$provincia= document.getElementById('lista_province').options[$provincia_index].text}
    //if ($citta_index!="null") {$localita = document.getElementById('lista_citta').options[$citta_index].text}

   $materia = document.getElementById('materia_cercata').value;
   
   if ($nazione=="Italia")
   {if ($provincia=="Tutte") {$citta=""};}
   
    
    
   http_req_listaofferta = crea_http_req();
   http_req_listaofferta.open( "GET", $root+"/ajax/ajaxgetlistaofferta.php?&phpsessid="+$phpsessid+"&nazione="+$nazione+"&materia="+$materia+"&regione="+$regione+"&provincia="+$provincia+"&localita="+$citta+"&corsi="+$corsi+"&lezioni="+$lezioni+"");
   http_req_listaofferta.setRequestHeader("Content-Type", "text/html");
   http_req_listaofferta.onreadystatechange = gestisci_richiesta_listaofferta;
   http_req_listaofferta.send(null);
      
}


function FirstLoadListaOfferta($phpsessid, $nazione, $materia, $regione, $provincia, $localita)
{

   http_req_listaofferta = crea_http_req();
   http_req_listaofferta.open( "GET", $root+"/ajax/ajaxgetlistaofferta.php?&phpsessid="+$phpsessid+"&nazione="+$nazione+"&materia="+$materia+"&regione="+$regione+"&provincia="+$provincia+"&localita="+$localita+"");
   http_req_listaofferta.setRequestHeader("Content-Type", "text/html");
   http_req_listaofferta.onreadystatechange = gestisci_richiesta_listaofferta;
   http_req_listaofferta.send(null);   
}



function gestisci_listacorsiazd()
{
    
     if ((http_req_getcorsiazd.readyState==4) || (http_req_getcorsiazd.readyState == "complete"))
	{
	
	  var $output = http_req_getcorsiazd.responseText;
          document.getElementById('DivDescrizione').innerHTML=$output;
	  document.getElementById('LiDescrizione').style.color = "green";
	  document.getElementById('LiProf').style.color = "grey";
	  document.getElementById('LiContatti').style.color = "green";
	
	}

else
        {
	
	document.getElementById('DivDescrizione').innerHTML = "Richiesta...";
	
	
	}
    
    
}

function GetCorsiAzd($phpsessid, $idazienda)
{
        
     http_req_getcorsiazd = crea_http_req();
     http_req_getcorsiazd.open( "GET", $root+"/ajax/ajaxgetlistacorsiazd.php?phpsessid="+$phpsessid+"&idazienda="+$idazienda+"");
     http_req_getcorsiazd.setRequestHeader("Content-Type", "text/html");
     http_req_getcorsiazd.onreadystatechange = gestisci_listacorsiazd;
     http_req_getcorsiazd.send(null);   
}


function gestisci_descrizioneazd()
{
    
    if ((http_req_getdescrizioneazd.readyState==4) || (http_req_getdescrizioneazd.readyState == "complete"))
	{
	  var $output = http_req_getdescrizioneazd.responseText;
          document.getElementById('DivDescrizione').innerHTML=$output;
	  document.getElementById('LiDescrizione').style.color = "grey";
	  document.getElementById('LiProf').style.color = "green";
	  document.getElementById('LiContatti').style.color = "green";
	}

else
        {
	document.getElementById('DivDescrizione').innerHTML = "Richiesta...";
	}
    
}




function GetDescrizioneAzd($idazienda)
{
     http_req_getdescrizioneazd = crea_http_req();
     http_req_getdescrizioneazd.open( "GET", $root+"/ajax/ajaxgetdescrizioneazd.php?&idazienda="+$idazienda+"");
     http_req_getdescrizioneazd.setRequestHeader("Content-Type", "text/html");
     http_req_getdescrizioneazd.onreadystatechange = gestisci_descrizioneazd;
     http_req_getdescrizioneazd.send(null);       
}


function gestisci_contattiazd()
{
    
    if ((http_req_getcontattiazd.readyState==4) || (http_req_getcontattiazd.readyState == "complete"))
	{
	  var $output = http_req_getcontattiazd.responseText;
          document.getElementById('DivDescrizione').innerHTML=$output;
	  document.getElementById('LiDescrizione').style.color = "green";
	  document.getElementById('LiProf').style.color = "green";
	  document.getElementById('LiContatti').style.color = "grey";
	}

else
        {
	document.getElementById('DivDescrizione').innerHTML = "Richiesta...";
	}
    
}




function GetContattiAzd($phpsessid,$idazienda)
{
    

     http_req_getcontattiazd = crea_http_req();
     http_req_getcontattiazd.open( "GET", $root+"/ajax/ajaxgetcontattiazd.php?phpsessid="+$phpsessid+"&idazienda="+$idazienda+"");
     http_req_getcontattiazd.setRequestHeader("Content-Type", "text/html");
     http_req_getcontattiazd.onreadystatechange = gestisci_contattiazd;
     http_req_getcontattiazd.send(null);   

}

function gestisci_richiestapagpers()
{
    
    if ((http_req_richiedipagpers.readyState==4) || (http_req_richiedipagpers.readyState == "complete"))
	{
	  var $output = http_req_richiedipagpers.responseText;
          document.getElementById('DivPubblicita').innerHTML=$output;
	}

else
        {
	document.getElementById('DivPubblicita').innerHTML = "Richiesta...";
	}
}




function gestisci_richiestapersonale()
{
    
     if ((http_req_richiedipersonale.readyState==4) || (http_req_richiedipersonale.readyState == "complete"))
	{
	  var $output = http_req_richiedipersonale.responseText;
          document.getElementById('Div_InsPersonale').innerHTML=$output;
	  document.getElementById('ButtonRichPersonale').disabled="disabled";
	}

     else
        {
	document.getElementById('Div_InsPersonale').innerHTML = "Richiesta...";
	}
}



function RichiestaPaginaPersonale($phpsessid)
{
     http_req_richiedipagpers = crea_http_req();
     http_req_richiedipagpers.open( "GET", $root+"/ajax/ajaxgetpagpers.php?phpsessid="+$phpsessid+"");
     http_req_richiedipagpers.setRequestHeader("Content-Type", "text/html");
     http_req_richiedipagpers.onreadystatechange = gestisci_richiestapagpers;
     http_req_richiedipagpers.send(null);   
}


function gestisci_richiestabanner()
{
    
     if ((http_req_richiedibanner.readyState==4) || (http_req_richiedibanner.readyState == "complete"))
	{
	  var $output = http_req_richiedibanner.responseText;
          document.getElementById('Div_InsBanner').innerHTML=$output;
	  document.getElementById('ButtonRichBanner').disabled="disabled";
	}

     else
        {
	document.getElementById('Div_InsBanner').innerHTML = "Richiesta...";
	}
}



function AjaxSendRequestBanner($phpsessid)
{
     
     http_req_richiedibanner = crea_http_req();
     http_req_richiedibanner.open( "GET", $root+"/ajax/ajaxgestiscibanner.php?phpsessid="+$phpsessid+"");
     http_req_richiedibanner.setRequestHeader("Content-Type", "text/html");
     http_req_richiedibanner.onreadystatechange = gestisci_richiestabanner;
     http_req_richiedibanner.send(null);    
}


function AjaxSendRequestPersonale($phpsessid)
{
     http_req_richiedipersonale = crea_http_req();
     http_req_richiedipersonale.open( "GET", $root+"/ajax/ajaxgestiscipersonale.php?phpsessid="+$phpsessid+"");
     http_req_richiedipersonale.setRequestHeader("Content-Type", "text/html");
     http_req_richiedipersonale.onreadystatechange = gestisci_richiestapersonale;
     http_req_richiedipersonale.send(null);    
}

