//  Document


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

var $nom_lezione = "0";

//Variabili per i messaggi
/////////////////////////
var idbookmarkold = "0";
var codebookmark_first = "";
var $codelesson_first = "";
var $codelesson_actual="";
var namesender = "0";
var surnamesender ="0";
var idsender = "0";
var blinkerstatus = "0";
var displaylezioni = "future";
var $codebookmark_old = "";
var $button_old = "future";
var $topoint = "";
var $abilitamessaggi = "yes";
var $id_help_old = "ChiSiamo"; // usato per la navigazione nella pagina help
var $dayclicked="";    //giorno cliccato nella prenotazione
/////////////////////////

var $giorno1 = "";
var $giorno2 = ""; // Queste servono per la pagina vacanze

var $last = "00";  // Siamo in questa condizione se Ë stato cliccata una casella del calendario, il div-ora Ë visibile ma non Ë ancora stata cliccata un'ora
var $coloron = "#ffffff"; // colore della casella su cui ci muoviamo
$towrite = "";  
var $arrayore = new Array();
var $colorlast="#ffffff";
var $position = "";
var httpObject;
var xmlDoc;

var $ora1 = "";
var $ora2 = "";

$arrayore[1] = new Array("","","","","","","","");
$arrayore[2] = new Array("","","","","","","","");
$arrayore[3] = new Array("","","","","","","","");
$arrayore[4] = new Array("","","","","","","","");

/* *********************************************************** /*
Nome: 			PreLoader
Funzionalit: 	carica in memoria una immagine in modo tale che, 
                quando viene richiamata, sia immediatamente disponibile
Ingressi: 		$image = none del file da caricare
Uscite:			nessuna
				 
Note:			
Modifica:		25/12/2008 - Michele Moroni
/* *********************************************************** */

function PreLoader($image1, $image2)
{

			var myImages = new Array;
            myImages[0]=$image1;
            myImages[1]=$image2;
            
			var myPreload = new Array (); 
			for (var i = 0; i < myImages.length; i++ ) 
			{ 
			myPreload[ i ]= new Image(); 
			myPreload[ i ].src = myImages[ i ];
			}
            
            //return myPreload;
            
}



/* *********************************************************** /*
Nome: 			verificaEmail($email)
Funzionalità: 	dato un indirizzo email verifica che questo sia conforme al formato xxx@xxxxxx.xx
Ingressi: 		$email
Uscite:			$status = failed 
				$status = passed 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */

function VerificaEmail($email)
{


var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if ($email.search(emailRegEx) == -1) 
	 {
          $status = "failed";
     }
  
     else 
	 {  
          $status = "passed";
     }
    
return $status;

}


function CleanMateria(input)
{
	//strOutputCode = addslashes(str_replace("\'", " ",strTagStrippedText));
    return input;
}




/* *********************************************************** /*
Nome: 			CleanTitolo
Funzionalità: 	data una stringa la funzione sostitiisce il carattere speciale °
                con la stringa "deg". Utilizzata per passare nel database "stringa di 1° livello".
Ingressi: 		strTagStrippedText = stringa da pulire
Uscite:			strOutputCode
				 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */

function CleanTitolo(strTagStrippedText)
{

	
	strOutputCode = strTagStrippedText.replace(/°/, "deg");
	
	
	//strTagStrippedText = strTagStrippedText.replace(/[s+]/g, "plus");
	return strOutputCode;
}


/* *********************************************************** /*
Nome: 			CleanTariffa
Funzionalit?: 	data una stringa la funzione elimina tutti i caratteri non numerici
                
Ingressi: 		strTagStrippedText = stringa da pulire
Uscite:			strOutputCode
				 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */


function CleanTariffa(strTagStrippedText)
{
strTagStrippedText = strTagStrippedText.replace(/[^0-9]/g, "");
var strOutputCode = strTagStrippedText.replace(/[&]/g, "");
return strOutputCode;
}
	
/* *********************************************************** /*
Nome: 			ConsistenzaPassword
Funzionalit?: 	data una stringa la funzione verifica che al suo interno siano
                contenuti sono caratteri alfanumerici e che sia di lunghezza compresa tra 6 e 30
                (Viene richiesta per la password)
				
Ingressi: 		$password = pasword da verificare
Uscite:			"failed" o "passed" 
				 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */

function ConsistenzaPassword($password)
{

	var $regtomatch = /^[a-zA-Z0-9]{6,30}$/;
	$result = $regtomatch.test($password);
	
	if ($result == false) {$status = "failed"}
	else {$status = "passed";}
	return $status;

}


function ConsistenzaAnno($anno)
{
      
    var $regtomatch = /^[0-9]{4}$/;
	$result = $regtomatch.test($anno);
	
	if ($result == false) {$status = "failed"}
	else {$status = "passed";}
	return $status;
     
}


function ConsistenzaNumero($num)
{
	 var $regtomatch = /^[0-9]+$/;
	 $result = $regtomatch.test($num);
	 if ($result == false) {$status = "failed"}
	 else {$status = "passed";}
	 return $status;
}




/* *********************************************************** /*
Nome: 			CleanPhoneNumber
Funzionalit?: 	data una stringa la funzione rimuove tutti i simboli non numerici tranne il segno "+"
                Inoltre il segno "+" viene sostituito dalla stringa "plus" (per la scrittura nel database)
               
Ingressi: 		strTagStrippedText = numero di telefono da verificare
Uscite:			strOutputCode = numero di telefono pulito
				 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */


function CleanPhoneNumber(strTagStrippedText)
{

	
	strTagStrippedText = strTagStrippedText.replace(/[^0-9 s+]/g, "");
	
	strTagStrippedText = strTagStrippedText.replace(/[s+]/g, "plus");
	var strOutputCode = strTagStrippedText.replace(/[&]/g, "");
	return strOutputCode;
}

/* *********************************************************** /*
Nome: 			removeHTMLTags
Funzionalit?: 	Rimuove i tags HTML da una stringa
               
Ingressi: 		strInputCode = stringa che contiene i tags
Uscite:			strOutputCode = stringa pulita
				 
Note:			
Modifica:		23/11/2008 - Michele Moroni
/* *********************************************************** */

function removeHTMLTags(strInputCode)

{
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		}); 
		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		var strOutputCode = strTagStrippedText.replace(/[&]/g, "");
		return strOutputCode;
		
}

function removeHTMLTags2(strInputCode)

{
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		}); 
		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		var strOutputCode = strTagStrippedText.replace(/[&]/g, "@ecommerciale@");
		return strOutputCode;
		
}	


function RefillArrayHour()
{
		
		for (j=1; j<5; j++)   					
	  	{
			  for (i=1; i<8; i++)
			  { 
			  $name = j+"_"+i;
			  $a = document.getElementById($name).innerHTML;
			  if ($a!="") {$arrayore[j][i] = $a;} 
			  $towrite = $towrite + "<input type=\"hidden\" name=\""+$name+"\" value=\""+$arrayore[j][i]+"\" />";			 
			  }
		}

		document.getElementById("arrayoreform").innerHTML= $towrite;

}


/* *********************************************************** /*
Nome: 			addhourtoform
Funzionalit?: 	scrive l'array alÚ'interno del form da spedire al PHP
				
Ingressi: 		Nessuno
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/12/2008 - Michele Moroni
/* *********************************************************** */


function AddHourToForm() 

	{  
	  
  		for(j=1; j<5; j++)   //j = riga, i = colonna;
		  						
	  	{
			  for (i=1; i<8; i++)
			  {
			  $name = j+"_"+i;
			  $towrite = $towrite + "<input type=\"hidden\" name=\""+$name+"\" value=\""+$arrayore[j][i]+"\" />";
			  }
		}
	  
	  document.getElementById("arrayoreform").innerHTML= $towrite;  // qui scrive materialmente nell'arrayform
	  
	}


/* *********************************************************** /*
Nome: 			onmouseoverforreservation
Funzionalit?: 	Ë la funzione che viene eseguita quando il puntatore si muove su una cella del calendario
				
Ingressi: 		id = identificativo della cella su cui ci muoviamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function onmouseoverforreservation(id)
{
 $coloron = document.getElementById(id).style.background;
if ($coloron != "#ffffff") 
 		{ document.getElementById(id).style.background = "#5ea3e0";   // Se ci muoviamo su una casella del calendario mostrala di questo colore
		  }
 
 if ($coloron == "#ffffff") document.body.style.cursor = 'default';
				  
}

/* *********************************************************** /*
Nome: 			onmouseoverforreservation
Funzionalit?: 	Ë la funzione che viene eseguita quando il puntatore si muove su una cella del calendario
				
Ingressi: 		id = identificativo della cella su cui ci muoviamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function onmouseoutforreservation(id)
{
document.getElementById(id).style.background = $coloron;  // Se ci muoviamo su una casella del calendario mostrala di questo colore
}



/* *********************************************************** /*
Nome: 			onmouseoverhour
Funzionalit?: 	Ë la funzione che viene eseguita quando il puntatore si muove su una cella del calendario
				
Ingressi: 		id = identificativo della cella su cui ci muoviamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */


function onmouseoverhour(id)
{
 $coloron = document.getElementById(id).style.background;
 document.getElementById(id).style.background = "#5ea3e0";   // Se ci muoviamo su una casella del calendario mostrala di questo colore
}



/* *********************************************************** /*
Nome: 			gestisci_getoredisponibili
Funzionalità:  	        Riceve i dati dal file ajaxgetoredisponibili (ore disponibili per una singola lezione) e li inserisce nell'apposito div
				
Ingressi: 		
Uscite:			Nessuna
Note:			Nessuna
Modifica:			10/04/2009 - Michele Moroni
/* *********************************************************** */

function gestisci_getoredisponibili()
{
	
	if ((http_req_oredisponibili.readyState==4) || (http_req_oredisponibili.readyState == "complete"))
		{
			$output = http_req_oredisponibili.responseText;
		        document.getElementById('SceltaOre').innerHTML = $output;	
		}
		
	    else 
		{
			 document.getElementById('SceltaOre').innerHTML = "Loading...";
		}		
}



/* *********************************************************** /*
Nome: 			GetDisplayOreDisponibili
Funzionalità:  	        E' la funzione che viene eseguita quando si clicca su una data disponibile del calendario prenotazioni
				
Ingressi:
				$phpsessid = identificativo di sessione
				$idcella  = identificativo della cella del calendario
				$iduser = identificativo del professore
				$campomateria = posizione della materia nel database (1,2,3,4)
				$anno = $anno in cui viene fornita la lezione
				$mese = $mese in cui viene fornita la lezione
				$giorno = $giorno in cui viene fornita la lezione
				 
Uscite:			Nessuna
Note:			Nessuna
Modifica:			10/04/2009 - Michele Moroni
/* *********************************************************** */


function GetDisplayOreDisponibili($phpsessid, $idcella, $iduser, $campomateria, $anno, $mese, $giorno,$giorno_settimana)
{

//document.submitcalendarday.idcell.value=id;
//document.submitcalendarday.datadelmese.value=counter;

$ora1 = "";
$ora2 = "";

document.getElementById('indicazione').style.visibility = "visible";
try {document.getElementById('visualizzaselezione').style.visibility = "hidden";} catch (e1) {};


http_req_oredisponibili = crea_http_req();
http_req_oredisponibili.open( "GET", $root+"/ajax/ajaxgetoredisponibili.php?PHPSESSID="+$phpsessid+"&idcella="+$idcella+"&iduser="+$iduser+"&campomateria="+$campomateria+"&anno="+$anno+"&mese="+$mese+"&giorno="+$giorno+"&giorno_settimana="+$giorno_settimana+"&id="+Math.random());
http_req_oredisponibili.setRequestHeader("Content-Type", "text/html");
http_req_oredisponibili.onreadystatechange = gestisci_getoredisponibili;
http_req_oredisponibili.send(null);

if ($dayclicked != "") { document.getElementById($dayclicked).style.backgroundColor = "#3e8e08";    }

$coloron = "orange"; 
$dayclicked = $idcella;

document.getElementById($idcella).style.backgroundColor = "orange";
document.getElementById('indicazione').innerHTML = "<p style=\"text-align:center; font-size:14px; color:#ae7c4b\"> Scegli l'<span style=\"font-weight:bold\">orario</span> della tua lezione <br />cliccando sull'area verde</p>";


}


/* *********************************************************** /*
Nome: 			clickonhourforreservation(id)
Funzionalit?: 	SSeleziona una sequenza di ore nel form di selezione ore e attiova il pulsante di go ahead
				
Ingressi: 		id = identificativo della cella su cui ci muoviamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */


function clickonhourforreservation(id, code)
{



$code = code
var stringavail = $code;

var $dispon=stringavail.split("/");

var $color = "#fe771e";  // Arancione 254, 119, 30
var $colorgreen = "#3e8e08";// Verde 62, 142, 8
var $white = "#ffffff"; // Bianco 255, 225, 255
var $code;
$position = id;


// ora1 e ora2 sono variabili globali
//// Questo serve per togliere la selezione nel caso si voglia effettuare una seconda scelta

if($ora2 == $ora1)
			{
			$ora2 == "";
			}


if (($ora1 !== "")&&($ora2 !== ""))   //Clicco una terza volta
	{
	
     var a = $ora1
    var b = $ora2
	
    a = a-1+1;	// COSI' FORZO IL TYPECAST! NON TOGLIERE!!
    b = b-1+1;
	
	if (a<=b) 	
				{
				for(i=a; i<=b; i++) 
					 {
					  $startcolor = document.getElementById(i).style.background;
					  $result = $startcolor.indexOf("255, 255, 255")
					  if (($startcolor != "#ffffff")&&($result == -1)) {document.getElementById(i).style.background =  $colorgreen;}   
					  else {document.getElementById(i).style.background =  "#ffffff"}
					}				
				}
	
	if (b<a)  
				
				{
			    for(i=b; i<=a; i++) 
								{
								$startcolor = document.getElementById(i).style.background;
								$result = $startcolor.indexOf("255, 255, 255")
				   				if (($startcolor != "#ffffff")&&($result == -1)) {document.getElementById(i).style.background =  $colorgreen; }
								else  {document.getElementById(i).style.background =  "#ffffff"}
								}
				}
		
	$ora1 = ""; 
	$ora2 = ""; 
	}
	

// Questo invece Ë per creare la selezione
////////////////////////////////////////////////////////////////////////////////////////////////

if (($ora1 === "")||($ora2 === ""))

	{
		
		//document.getElementById('indicazione').style.visibility = "visible";
        //document.getElementById('visualizzaselezione').style.visibility = "hidden";
		
		document.getElementById('pbt_continua').disabled= true;							// Disabilito il pulsante di invia
		document.getElementById('pbt_continua').style.visibility = "hidden";
		
		//document.getElementById('pbt_continua').style.background = "#FF4444";			// Setto il background del pulsante a rosso
		document.getElementById('DivDisplayOre').innerHTML = "";							// Cancello l'area display
		document.getElementById(id).style.background =  $color;								// Imposto il colore dello sfondo della cella in arancione							
		$coloron = $color;
			
		
		
		if ($ora1 !== "") {$ora2 = id; }  // Se siamo al secondo click
		
		if ($ora1 === $ora2) $ora2 = "";  // questo serve ad evitare che il pulsante si attivi quando clicco 2 volte sulla stessa ora
		
		if ($ora1 === "") {$ora1 = id; }	 // Se siamo al primo click
			
		
		
		if ($ora2 !== "")																			// In questo caso siamo al secondo click
		{			
		
					var a = $ora1					
					var b = $ora2
					
					a = a-1+1;	// COSI' FORZO IL TYPECAST! NON TOGLIERE!!
					b = b-1+1;
				
					if (a<=b) 
							{
									for(i=a; i<=b; i++) // Stiamo scorrendo gli elementi tra le selezioni, in avanti
									{
									$startcolor = document.getElementById(i).style.background;   // Guardo l'elemento di background
									$result = $startcolor.indexOf("255, 255, 255")				 //questo Ë per mozilla
									
									if (($startcolor != "#ffffff")&&($result == -1))  {document.getElementById(i).style.background =  $color;}  //Se il colore non Ë bianco (e quindi Ë verde) lo colora di arancione	
									else {document.getElementById(i).style.background =  $white;}		// Se il colore Ë bianco, lo lascia bianco
									}
						    }
						
				   if (b<a)  		// Se clicchiamo indietro, e non avanti faccio questo
					   
					   		{
					
									for(i=b; i<=a; i++) 
									{
										$startcolor = document.getElementById(i).style.background;
										$result = $startcolor.indexOf("255, 255, 255")
										if (($startcolor != "#ffffff")&&($result == -1)) {document.getElementById(i).style.background =  $color;}
										else  {document.getElementById(i).style.background =  "#ffffff"}
									}
							}

//Questo serve per modificare le ore, disattivando il fine intervallo o inizio intervallo
/////////////////////////////////////////////
			var $a = "";
			var $b = "";
			var $c = "";
			var $d = "";
			var $contatore;  
			var $numeroore = 0;
			var $backcolor;
			var $frontcolor;
			
			if (($ora1 !== "")&&($ora2 !== ""))   //l'assegnazione di ora2 l'abbiamo fatta in questa graffa
			{									  // ORA abbiamo l'ora di inizio e l'Ïora di fine intervallo
							
							for(i=1; i<=24; i++) // ATTENZIONE All'UNO e NON 0 (dopo c'Ë un -1) // Stiamo scorrendo gli elementi
							{
							
							$back = i-1;
							$front = i+1;
							$startcolor = document.getElementById(i).style.background;
							
							$result = $startcolor.indexOf("254, 119, 30")
						
							if (($startcolor == $color)||($result != -1))  //Se il colore Ë arancione
									{
									
									
									$backcolor = document.getElementById($back).style.background;
									$frontcolor = document.getElementById($front).style.background;
									
									// QUESTO SERVE PER MOZILLA
									$backcolorwhite = $backcolor.indexOf("255, 255, 255")  // = 1 se il backcolor NON Ë bianco 
									$frontcolorgreen = $frontcolor.indexOf("62, 142, 8")
									$frontcolorwhite = $frontcolor.indexOf("255, 255, 255")
									$backcolorgreen = $backcolor.indexOf("62, 142, 8")
									$backcolororange = $backcolor.indexOf("254, 119, 30")
									$frontcolororange = $frontcolor.indexOf("254, 119, 30")
									////////////////////////////
						
															
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancio all'inizio dell'intervallo
									if (($backcolor == $white)&&($frontcolor == $colorgreen)) {if (i==$position) {$coloron = $colorgreen;}   
																							  document.getElementById(i).style.background = $colorgreen;}
																							  
									
									
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancio all'inizio dell'intervallo (per mozilla)
									else if (($backcolorwhite != -1)&&($frontcolorgreen != -1))  {if (i==$position) {$coloron = $colorgreen;}
																								 document.getElementById(i).style.background = $colorgreen;}
									
									
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancio all'inizio dell'intervallo definito tramite S
									else if (($dispon[i-1]=="S")&&($frontcolor == $colorgreen)) {if (i==$position) {$coloron = $colorgreen;}   
																							  document.getElementById(i).style.background = $colorgreen;
																							    }
																							  
									
																								 
									
									else if (($dispon[i-1]=="S")&&($frontcolorgreen != -1)) {if (i==$position) {$coloron = $colorgreen;}   
																							  document.getElementById(i).style.background = $colorgreen;
																							    }
									
									
									
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancioalla fine  dell'intervallo
									else if (($frontcolor == $white)&&($backcolor == $colorgreen))  { if (i==$position) {$coloron = $colorgreen;}
																									document.getElementById(i).style.background = $colorgreen;}
									
									
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancioalla fine  dell'intervallo (per mozilla)
									else if (($frontcolorwhite != -1)&&($backcolorgreen != -1)) {if (i==$position) {$coloron = $colorgreen;} 
																								 document.getElementById(i).style.background = $colorgreen;}
									
									// Questo elimina il caso in cui c'Ë un solo quadrato in arancioalla fine  dell'intervallo definito tramite E
									else if (($dispon[i+1]=="E")&&($backcolor == $colorgreen)) {if (i==$position) {$coloron = $colorgreen;}   
																							  document.getElementById(i).style.background = $colorgreen;
																							    }
									
									
									else if (($dispon[i+1]=="E")&&($backcolorgreen != -1)) {if (i==$position) {$coloron = $colorgreen;}   
																							  document.getElementById(i).style.background = $colorgreen;
																							    }
									
									
									
									
									
									
													
									//else {$coloron = $color; $numeroore = $numeroore+1;}
									}  	
							}
			
			
			
			//alert($numeroore-1);	
		    //document.hourcontinuaform.pulsantecontinua. = #00ff00;
						
						//document.getElementById('DivDisplayOre').style.background = "#ffffff";
						
						for(i=0; i<=24; i++) 	// Ripercorriamo l'intervallo
							{

							$back = i-1;
							$front = i+1;
							$startcolor = document.getElementById(i).style.background;
							
							$result = $startcolor.indexOf("254, 119, 30")
							
							if (($startcolor == $color)||($result != -1))  // Se la cella Ë arancione
									{
									
									
									if (i == 0) {$a = 0;}  // Se siamo alla prima cella, questo Ë il valore di partenza
									
									if (i != 0) 
									
										{
									
										$backcolor = document.getElementById($back).style.background;
										$frontcolor = document.getElementById($front).style.background;
										
										// QUESTO SERVE PER MOZILLA
										
										$backcolororange = $backcolor.indexOf("254, 119, 30")
										$frontcolororange = $frontcolor.indexOf("254, 119, 30") //-1 se NON Ë arancione
										////////////////////////////
										
										if ($result == -1)  // Per Internet Explorer
											{
											
											if (($a !== "")&&($b !== "")&&($c !== "")&&($d !== "")) 
											
											
												{
												
												for ($k = i; $k<25; $k++)
													{
													$color = document.getElementById($k).style.background;
													if ($color != "#ffffff") document.getElementById($k).style.background = $colorgreen;
													$coloron = $colorgreen;
													}
												}
																						 
											else 	 
												{
												
												if (($a !== "")&&(($backcolor != $color)||($dispon[i]=="E"))) {$c=i;}
												if (($b !== "")&&(($frontcolor != $color)||($dispon[i]=="S"))) {$d=i;}
												if (($a === "")&&(($backcolor != $color)||($dispon[i]=="E"))) {$a=i;}
												if (($b === "")&&(($frontcolor != $color)||($dispon[i]=="S"))) {$b=i;}
												}
											
											}
										
										
										
										if ($result != -1)	// Per Mozilla
											{
											
											if (($a !== "")&&($b !== "")&&($c !== "")&&($d !== "")) 
											
											
												{
												
												for ($k = i; $k<25; $k++)
													{
													$color = document.getElementById($k).style.background;
													if ($color != "#ffffff") document.getElementById($k).style.background = $colorgreen;
													$coloron = $colorgreen;
													}
												
												}
												
												else 	 
												{
												if (($a !== "")&&(($backcolororange == -1)||($dispon[i]=="E"))) {$c=i;}
												if (($b !== "")&&(($frontcolororange == -1)||($dispon[i]=="S"))) {$d=i;}
												if (($a === "")&&(($backcolororange == -1)||($dispon[i]=="E"))) {$a=i;}
												if (($b === "")&&(($frontcolororange == -1)||($dispon[i]=="S"))) {$b=i;}
												}
												
											}
										
										}
									
									}
							}
						
						
						
						if (($c === "")&&($a !== ""))
						{
							
						document.getElementById('indicazione').style.visibility = "hidden";
						document.getElementById('visualizzaselezione').style.visibility = "visible";
						document.getElementById('pbt_continua').style.visibility = "visible";
						
						document.getElementById('DivDisplayOre').innerHTML = "<p style=\"font-size:12px; margin-top:0px; color:#ae7c4b\">Dalle&nbsp;"+$a+":00 alle "+$b+":00</p>";
						//document.getElementById('pbt_tecontinua').style.background = "#66FF66";
						document.getElementById('pbt_continua').disabled= false;
						document.getElementById('hourdalle1').value= $a;
						document.getElementById('houralle1').value= $b;
						
						
						}
						
						if (($c !== "")&&($a !== ""))
						{
							
						document.getElementById('indicazione').style.visibility = "hidden";
						document.getElementById('visualizzaselezione').style.visibility = "visible";
						document.getElementById('pbt_continua').style.visibility = "visible";
						document.getElementById('DivDisplayOre').innerHTML = "<p style=\"font-size:12px; margin-top:0px; color:#ae7c4b\">Dalle&nbsp;"+$a+":00 alle "+$b+":00 e dalle "+$c+":00 alle "+$d+":00</p>";
						//document.getElementById('pbt_tecontinua').style.background = "#66FF66";
						document.getElementById('pbt_continua').disabled= false;
						document.getElementById('hourdalle1').value= $a;
						document.getElementById('houralle1').value= $b;
						document.getElementById('hourdalle2').value= $c;
						document.getElementById('houralle2').value= $d;
						
						
						}
					
					
		
						
					}
	
		
		
		
	}
	
		
	
  }

}


/* *********************************************************** /*
Nome: 			GetNextMonth($anno, $mese)
Funzionalit?: 	dato un anno e un mese in formato numerico recupera il mese successivo in formato
                0 ->[XXXX]   (anno)
				1 ->[XX]  (mese)

Ingressi: 		$anno = anno in formato XXXX
                $mese = mese in formato XX
Uscite:			$array a 2 valori
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */



function GetNextMonth($anno, $mese) // in uscita anno e mese successivo a quello selezionato;
{
	var $array = Array();

	$anno = $anno-1+1;
	$mese = $mese-1+1;

	if ($mese != 12) {$nextmonth = $mese+1;
					  $year = $anno; }
	
	if ($mese == 12) {$nextmonth = 01;
					  $year = $anno+1; }
					  
	$array[0] = $year;
	$array[1] = $nextmonth;
	
	return $array; 

}

/* *********************************************************** /*
Nome: 			GetLastDay($anno, $mese)
Funzionalit?: 	dato un anno e un mese in formato numerico recupera il numero dell'ultimo giorno di quel mese 
                0 ->[XXXX]   (anno)
				1 ->[XX]  (mese)

Ingressi: 		$anno = anno in formato XXXX
                $mese = mese in formato XX
Uscite:			$lastday (formato XX)
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function GetLastDay($anno, $mese) // numero ultimo giorno del mese
{
	var $lastday;
	var $id; 
	
	$anno = $anno.toString();
		
	for ($t = 28; $t < 32; $t++)
		{
			$s = $t.toString();
			$id = $anno+$mese+$t;
			
			try{ 							 
				$temp = document.getElementById($id).innerHTML;
				} 
										  
				catch(e) 
				{ 
				break;
				}
				
				$lastday = $t;  // Ultimo giorno del mese su cui ho cliccato
									
		}

	//alert($lastday);
	return $lastday;

}




function GetSpread($mese1, $mese2) // calcolo differenza mesi
{

$spread = 0;

$mese1 = $mese1-1+1;
$mese2 = $mese2-1+1;

if ($mese2 < $mese1)
	{
	$mese2 = $mese2+12;
	}

$spread = $mese2-$mese1;

return $spread;
}


function GetFailed($anno1, $mese1, $giorno1, $anno2, $mese2, $giorno2) // vede se l'intervallo e' accettabile;
{

$failed = "";
$idstart = $anno1+$mese1+$giorno1;
$idend = $anno2+$mese2+$giorno2;

	if (($anno1 == $anno2)&&($mese1 == $mese2))
	{
		
								$anno1 = $anno1.toString();
								$mese1 = $mese1.toString();
								$giorno1 = $giorno1.toString();
								
								$anno2 = $anno2.toString();
								$mese2 = $mese2.toString();
								$giorno2 = $giorno2.toString();
								
								//alert($giorno2);
								//if ($mese1<10) $mese1 = "0"+$mese1;
								//if ($mese2<10) $mese2 = "0"+$mese2;
								
								
								var a = $giorno1					
								var b = $giorno2
								
								a = a-1+1;	// COSI' FORZO IL TYPECAST! NON TOGLIERE!!
								b = b-1+1;
								
								for(i=a+1; i<b; i++) // Stiamo scorrendo gli elementi tra le selezioni, in avanti
								{
												
									if (i > 9) {$id = $anno1+$mese1+i}
									else {$id = $anno1+$mese1+"0"+i}
									$startcolor = document.getElementById($id).style.background;   // Guardo l'elemento di background
									$result = $startcolor.indexOf("255, 255, 255")				 //questo Ë per mozilla
												
									if (($startcolor != $coloravailable)&&($result == -1))  {$failed = "<p style=\"font-size:12px; margin:0px; color:red;\">La selezione non &egrave; stata accettata perch&egrave; contiene almeno una lezione richiesta o gi&agrave; approvata, oppure si sovrappone ad un altro periodo di vacanza</p>"; 
																							 document.getElementById('messaggi').innerHTML =  $failed;
																							 //document.getElementById($idstart).style.background ="#ffffff";
																							 //document.getElementById($idend).style.background ="#ffffff";
																										
																							 }  //Se il colore non Ë bianco (e quindi Ë verde) lo colora di arancione	
												
															
												
								
								
								}
	
	
	
	}

return $failed;


}




function PaintElement($anno1, $mese1, $giorno1, $anno2, $mese2, $giorno2, $color)
{

	
	$anno1 = $anno1.toString();
	$mese1 = $mese1.toString();
	$giorno1 = $giorno1.toString();
								
	$anno2 = $anno2.toString();
	$mese2 = $mese2.toString();
	$giorno2 = $giorno2.toString();
		
	if (($anno1 == $anno2)&&($mese1 == $mese2))	
								
								
			{
											
			document.getElementById('Pbt_ConfVacanza').disabled=false;	
											
			var a = $giorno1					
			var b = $giorno2
								
			a = a-1+1;	// COSI' FORZO IL TYPECAST! NON TOGLIERE!!
			b = b-1+1;
											
			for(i=a; i<=b; i++) // Stiamo scorrendo gli elementi tra le selezioni, in avanti
				
				{
														
				if (i > 9) {$id = $anno1+$mese1+i}
				else {$id = $anno1+$mese1+"0"+i}
				
				//alert($id);
				document.getElementById($id).style.background =$color;
														
				}
										
			}


}





function clickfordayvacation($id)
{
	
	$failed = "";
	document.getElementById('messaggi').innerHTML =  ""
	
	$coloravailable="#ffffff";
	$color = "#cc0000";
	$colorback ="#ffffff";
	
	if ($giorno2 == $giorno1)  // Se clicchiamo 2 volte sullo stesso giorno
		{
		
		
		$giorno2 == "";
		
		
		
		}
	
	
	if (($giorno1 !== "")&&($giorno2 !== ""))  // Se siamo al secondo click valido
		
		{
			
			document.getElementById('Pbt_ConfVacanza').disabled= true;			
			
			$anno_giorno1 = $giorno1.substr(0, 4);
			$mese_giorno1 =  $giorno1.substr(4, 2);
			$giorno_giorno1 = $giorno1.substr(6, 2);
							
			$anno_giorno2 = $giorno2.substr(0, 4);
			$mese_giorno2 =  $giorno2.substr(4, 2);
			$giorno_giorno2 = $giorno2.substr(6, 2);
			
			
			if ($mese_giorno1 == $mese_giorno2)	{PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno2, $mese_giorno2, $giorno_giorno2, $colorback);}	
			if ($mese_giorno1 != $mese_giorno2) {	
			
			
			     									var a = $giorno_giorno1;
													var $lastday1 = GetLastDay($anno_giorno1, $mese_giorno1);
													var $spreadmesi = GetSpread($mese_giorno1, $mese_giorno2);
													
													if ($spreadmesi == 1)
													{   
													   PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1,$colorback);
													   PaintElement($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2,$colorback);			
													}
									
													if ($spreadmesi == 2)
													{
								
														var $arraynext = Array();
														
														$arraynext =  GetNextMonth($anno_giorno1, $mese_giorno1)
														$annonext = $arraynext[0];
														$mesenext = $arraynext[1];
														
														if ($mesenext<10) $mesenext = "0"+$mesenext;
														
														$lastdaynext = GetLastDay($annonext, $mesenext)
																												
														PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1, $colorback);
														PaintElement($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2, $colorback);		
														PaintElement($annonext, $mesenext, "01", $annonext, $mesenext, $lastdaynext, $colorback);
														
													
														
													}					
								
												}	
														
		
		
		
		
		$giorno1 = "";
		$giorno2 = "";
		
		}
	
	if (($giorno1 === "")||($giorno2 === "")) // Se solo uno dei due click e' valido
	
		{
		
				document.getElementById($id).style.background =  $color;		
				document.getElementById('Pbt_ConfVacanza').disabled= "";							// Disabilito il pulsante di invia
				//document.getElementById('Pbt_ConfVacanza').style.background = "#FF4444";			    // Setto il background del pulsante a rosso
				//document.getElementById('DivDisplayOre').innerHTML = "";							    // Cancello l'area display
																			
					
				//$coloron = $color;
				
				if ($giorno1 !== "") {$giorno2 = $id; }  // Se siamo al secondo click
				if ($giorno1 === $giorno2) $giorno2 = "";  // questo serve ad evitare che il pulsante si attivi quando clicco 2 volte sulla stessa ora
				if ($giorno1 === "") {$giorno1 = $id; }	 // Se siamo al primo click
					
				if ($giorno2 !== "")																			// In questo caso siamo al secondo click
				{			
				
				       
					   
					   if ($giorno2 < $giorno1)
							{
							
							$temp_g1 = $giorno1;
							$temp_g2 = $giorno2;
							
							$giorno2 = $temp_g1;
							$giorno1 = $temp_g2;
							}	
						
						
						$anno_giorno1 = $giorno1.substr(0, 4);
						$mese_giorno1 =  $giorno1.substr(4, 2);
						$giorno_giorno1 = $giorno1.substr(6, 2);
						
						$anno_giorno2 = $giorno2.substr(0, 4);
						$mese_giorno2 =  $giorno2.substr(4, 2);
						$giorno_giorno2 = $giorno2.substr(6, 2);
						
						if ($mese_giorno1 == $mese_giorno2)
						{
								
							$failed = GetFailed($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno2, $mese_giorno2, $giorno_giorno2);
								
							if ($failed == "")
							{
								PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno2, $mese_giorno2, $giorno_giorno2, $color);	
							}
							
							else 
							{
							
							
							 document.getElementById($giorno1).style.background = $colorback;
							 document.getElementById($giorno2).style.background = $colorback;																 //document.getElementById($idend).style.background =$coloravailable;
							
							 $giorno1 = "";
							 $giorno2 = "";
							
							}
							
						
						}	
						
						
						if ($mese_giorno1 != $mese_giorno2)
							
							{
							
								var a = $giorno_giorno1;
								var $lastday1 = GetLastDay($anno_giorno1, $mese_giorno1);
								var $spreadmesi = GetSpread($mese_giorno1, $mese_giorno2);
								
								//alert($mese_giorno2);
								
								if ($spreadmesi == 1)
								{
								    
									$failed1 = GetFailed($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1);
									$failed2 = GetFailed($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2);
								
									
									if (($failed1 == "")&&($failed2 == ""))
															 
										{
										PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1,$color);
										PaintElement($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2,$color);			
										}
										
									else 
										{
										
										document.getElementById($giorno1).style.background = $colorback;
									    document.getElementById($giorno2).style.background = $colorback;		
										
										$giorno1 = "";
										$giorno2 = "";
										
										}
									
								}
								
								
								if ($spreadmesi == 2)
								{
								
									var $arraynext = Array();
									
									$failed1 = GetFailed($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1);
									$failed2 = GetFailed($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2);
									
									$arraynext =  GetNextMonth($anno_giorno1, $mese_giorno1)
									$annonext = $arraynext[0];
									$mesenext = $arraynext[1];
									
									if ($mesenext<10) $mesenext = "0"+$mesenext;
									$lastdaynext = GetLastDay($annonext, $mesenext)
	
									
									$failed3 = GetFailed($annonext, $mesenext, "01", $annonext, $mesenext, $lastdaynext);
									
									
									if (($failed1 == "")&&($failed2 == "")&&($failed3 == ""))
										{
										
										PaintElement($anno_giorno1, $mese_giorno1, $giorno_giorno1, $anno_giorno1, $mese_giorno1, $lastday1, $color);
										PaintElement($anno_giorno2, $mese_giorno2, "01", $anno_giorno2, $mese_giorno2, $giorno_giorno2, $color);		
										PaintElement($annonext, $mesenext, "01", $annonext, $mesenext, $lastdaynext, $color);
									
										}	
										
									else 
										{
										
										document.getElementById($giorno1).style.background = $colorback;
							            document.getElementById($giorno2).style.background = $colorback;		
										
										$giorno1 = "";
										$giorno2 = "";
										
										}
								    
								}
								
						
						
						}
							
				
				
				}
		}

}
/* *********************************************************** /*
Nome: 			onmouseouthour
Funzionalit?: 	Ë la funzione che viene eseguita quando il puntatore esce da una cella nel calendario
				
Ingressi: 		id = identificativo della cella da cui stiamo uscendo 
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */


function onmouseouthour(id)
{
scritto = document.getElementById(id).innerHTML;					// recupera il contenuto di una cella
var pos = scritto.search('00');										// pos =-1 se all'interno della cella Ën stata scritta un'ora, diverso da -1 altrimenti
var clicked = document.getElementById('divora').style.display       // "block" se la divora Ë visibile, "none" se invisibile.

if (clicked == "block") 

	
	{
		if ($last != "00")  {										//Se la div Ë visibile 
								if ($last == id) {document.getElementById(id).style.background = "#696";}   	// Se ci muoviamo dalla casella a cui la divora si riferisce
								if ($last != id) {document.getElementById(id).style.background = $coloron;}		// Se ci muoviamo da un'altra casella								  			  
							 }
	 	else {return;}									// Se la divora Ë visibile e muoviamo il puntatore dalla casella alla div non fare nulla 
	 

	 }
	 
	 
	

if (clicked != "block") 								       

	{	
		/*if (pos == "-1")
		{document.getElementById(id).style.background = "#fff";}		 // Se la divora Ë invisibile e la casella Ë vuota
		if (pos != "-1")
		{document.getElementById(id).style.background = "#696";}      // Se la divora Ë invisibile e la casella Ë scritta
		*/
		{document.getElementById(id).style.background = $coloron;}
		
	}
}



/* *********************************************************** /*
Nome: 			ClickOnHour
Funzionalit?: 	Ë la funzione che viene eseguita quando il puntatore clicca su una cella del calendario
				
Ingressi: 		id = identificativo della cella in cui siamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function ClickOnHour(colonna, riga, ora)
{


$last = "00";					//resettiamo alla condizione iniziale
$id = riga+"_"+colonna;
if (ora<0) {$ora = ""}  // Se Ë stato passato -1 = spazio bianco
else 
	{
	if (0<=ora<10) {$ora = "0"+ora+":00"};
	if (ora>=10) $ora = ora+":00"; 
	}
	
if ($ora != "") {$insidecell = "<p style=\"font-size:12px; margin:0px;\">"+$ora+"</p>";}
if ($ora == "") {$insidecell = "";}//scriviamo l'ora scelta all'interno della casella selezionata

document.getElementById($id).innerHTML = $insidecell;
if ($ora!="") document.getElementById($id).style.background = "#696";  // backround dell'ora se diverso da &nbsp; non Ë necessario dato che la casella Ë gi? di questo colore ma se vogliamo differenziarli... 
if ($ora=="") document.getElementById($id).style.background = "#ffffff";  // backround dell'ora se la casella Ë vuota

document.getElementById('iframedivora').style.display= "none";
document.getElementById('iframedivora').style.top= 0;
document.getElementById('iframedivora').style.left= 0;


$arrayore[riga][colonna]= $ora;
AddHourToForm(); 
RemoveDivOra();
}


/* *********************************************************** /*
Nome: 			ClickOnHour
Funzionalit?: 	Ë la funzione che disegna la div che contiene la scelta delle ore (divora)
				
Ingressi: 		colonna e riga della cella in cui siamo
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */


function displaydivora(colonna, riga, $dimcolonna, $dimriga) // Disegna la divora
{


if ($last != "00")
	{
	$content = document.getElementById($last).innerHTML;
	if ($content != "")
	document.getElementById($last).style.background = "#696";
	else 
	document.getElementById($last).style.background = "#ffffff";
	}


var hour;
var ni = document.getElementById("divora");
var top = riga*$dimriga+"px";
//var left = colonna*$dimcolonna+$dimcolonna+"px";
var left = colonna*$dimcolonna+"px";
var $id = riga+"_"+colonna;
var clicked = document.getElementById('divora').style.display;


// variabili per il display dell'ora
$bghoursmouseon = "#5ea3e0";  //background con il mouse che ci passa sopra
$bghoursmouseout = "#696";  //background con il mouse fuori dal campo

$displayinside="<span onmouseover=\"this.style.background=$bghoursmouseon\" onmouseout=\"this.style.background=$bghoursmouseout\" onclick=\"ClickOnHour("+colonna+","+riga+",-1)\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";

for (i=0; i<25; i++)

	{
	
	var temp;
	
	if (i<10) {temp = "<br /><span style=\"font-size:12px;\" onmouseover=\"this.style.background=$bghoursmouseon\" onmouseout=\"this.style.background=$bghoursmouseout\"  onclick=\"ClickOnHour("+colonna+","+riga+","+i+")\">"+"0"+i+":00</span>";}    // Genera il display dell'ora 
	if (i>=10) {temp = "<br /><span style=\"font-size:12px;\" onmouseover=\"this.style.background=$bghoursmouseon\" onmouseout=\"this.style.background=$bghoursmouseout\"  onclick=\"ClickOnHour("+colonna+","+riga+","+i+")\">"+i+":00</span>";}
	$displayinside = $displayinside+temp;
	}


			
document.getElementById('divora').style.display='block';
document.getElementById('divora').style.top= top;
document.getElementById('divora').style.left= left;

document.getElementById('iframedivora').style.display= "block";
document.getElementById('iframedivora').style.top= top;
document.getElementById('iframedivora').style.left= left;	

document.getElementById('divora').innerHTML = $displayinside;
document.getElementById($id).style.background = "#696";



$last = $id;


}


/* *********************************************************** /*
Nome: 			RemoveDivOra
Funzionalit?: 	Ë la funzione che rende invisibile la divora quando la cella non Ë cliccata
				
Ingressi: 		nessuno
Uscite:			Nessuna
Note:			Nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function RemoveDivOra()
{
document.getElementById('divora').style.display='none';
}




function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}



function AutoSendForm(nomeform)
{

var $nomeform = nomeform;
window.onload = function() {
			    var frm = document.getElementById($nomeform);
				frm.submit(); }

}





/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//  PARTE JAVASCRIPT PER AJAX
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////






function gestisci_risposta()
{

    	if (http_req.readyState==4 || http_req.readyState == "complete")

		{
    		var xmlDoc= http_req.responseXML.documentElement;
			
			var bodymessage = xmlDoc.getElementsByTagName("body").item(0).firstChild.data;  // Recupero il contenuto del messaggio da XML
			bodymessage = stripslashes(urldecode(bodymessage));
			var idmessage = "ball" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // ricostruisco l'identificativo dell'immagine pallino rosso/verde
			var idbookmark = "bookmark" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // Ricostruisco l'identificativo del segnalibro
			var numread = xmlDoc.getElementsByTagName("numread").item(0).firstChild.data;					// ricostruisco l'identificativo del numero di messaggi letti
			var numwaiting = xmlDoc.getElementsByTagName("numwaiting").item(0).firstChild.data;		// Ricostruisco l'identificativo del numero di messaggi in attesa di lettura
			
			document.getElementById('messaggiotoprint').innerHTML = bodymessage;	//scrivo il contenuto messaggio nella box
			document.getElementById(idmessage).src= $root+"/immagini/ballgreen.gif";		//associo akl messaggio la palla del colore verde, dato che a questo punto e' sicuramente letto )
			document.getElementById('messaggiletti').innerHTML = "Letti:&nbsp;"+numread;  //scrivo il numero di messaggi letti
			document.getElementById('messaggiwaiting').innerHTML = "Da leggere:&nbsp;"+numwaiting;	//scrivo il numero di messaggi da leggere
			document.getElementById(idbookmark).src= $root+"/immagini/bookmark.gif";	// Assegno il bookmark
			
			
			if ((idbookmarkold != 0)&&(idbookmark != idbookmarkold))
			{
			//alert(idbookmarkold);
			document.getElementById(idbookmarkold).src= $root+"/immagini/transparentbookmark.gif";	//cancello il bookmark vecchio
			}
			
			idbookmarkold = idbookmark;
		
		}

 

}

function gestisci_risposta_inviati()
{

    	if (http_req.readyState==4 || http_req.readyState == "complete")

		{
    		var xmlDoc= http_req.responseXML.documentElement;
	
			var date = xmlDoc.getElementsByTagName("date").item(0).firstChild.data; 
			var hour = xmlDoc.getElementsByTagName("hour").item(0).firstChild.data; 
			idsender =  xmlDoc.getElementsByTagName("from").item(0).firstChild.data;	  // global
			
			var state =  xmlDoc.getElementsByTagName("state").item(0).firstChild.data; 
			var bodymessage = xmlDoc.getElementsByTagName("body").item(0).firstChild.data;  // Recupero il contenuto del messaggio da XML
			bodymessage = stripslashes(urldecode(bodymessage));
			var idmessage = "ball" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // ricostruisco l'identificativo dell'immagine pallino rosso/verde
			var idbookmark = "bookmark" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // Ricostruisco l'identificativo del segnalibro
			//var numread = xmlDoc.getElementsByTagName("numread").item(0).firstChild.data;					// ricostruisco l'identificativo del numero di messaggi letti
			//var numwaiting = xmlDoc.getElementsByTagName("numwaiting").item(0).firstChild.data;		// Ricostruisco l'identificativo del numero di messaggi in attesa di lettura
			
			var idmessagecancella = xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; 
			var messaggio = document.getElementById('messaggio_invia');
			var tot = document.getElementById('tot');
			
			document.getElementById('messaggiotoprint').innerHTML = bodymessage;	//scrivo il contenuto messaggio nella box
			document.getElementById(idbookmark).src= $root+"/immagini/bookmark.gif";	// Assegno il bookmark
			
			document.getElementById('messaggi_rispondi_to').innerHTML = "";
			document.getElementById('pulsante_inviamessaggio').disabled = "disabled";
			document.getElementById('textbox_contenutomessaggio').disabled = "disabled";
			document.getElementById('textbox_contenutomessaggio').value = "";
			document.getElementById('numberchar').value = "512";
			document.getElementById('pulsante_eliminamessaggio').disabled = "";
			document.getElementById('idsendercancella').value = idsender;
			document.getElementById('idmessagecancella').value = idmessagecancella;
			
			if (state == "W") document.getElementById('messaggio_status').innerHTML = "<span style=\"font-weight:bold\">Stato:</span> non letto dal destinatario";
			if ((state == "R")||(state == "D")) document.getElementById('messaggio_status').innerHTML = "<span style=\"font-weight:bold\">Stato:</span> letto dal destinatario il "+date+" alle "+hour;
		
			
			if (messaggio != null) {document.getElementById('messaggio_invia').innerHTML= "";}
			
			if ((idbookmarkold != 0)&&(idbookmark != idbookmarkold))
			{
			//alert(idbookmarkold);
			document.getElementById(idbookmarkold).src= $root+"/immagini/transparentbookmark.gif";	//cancello il bookmark vecchio
			}
			
			idbookmarkold = idbookmark;
		
		}

 

}


function gestisci_risposta_long()
{

    	if (http_req.readyState==4 || http_req.readyState == "complete")

		{
    		var xmlDoc= http_req.responseXML.documentElement;
			idsender =  xmlDoc.getElementsByTagName("from").item(0).firstChild.data;	  // global
			namesender = xmlDoc.getElementsByTagName("namesender").item(0).firstChild.data;	  // global
			namesender = namesender.replace(/%40ecommerciale%40/g,"&");
			try {surnamesender =  xmlDoc.getElementsByTagName("surnamesender").item(0).firstChild.data;} catch(e1) {surnamesender="";}
			
			var bodymessage = xmlDoc.getElementsByTagName("body").item(0).firstChild.data;  // Recupero il contenuto del messaggio da XML
			bodymessage = stripslashes(urldecode(bodymessage));
			var idmessage = "ball" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // ricostruisco l'identificativo dell'immagine pallino rosso/verde
			var idbookmark = "bookmark" + xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; // Ricostruisco l'identificativo del segnalibro
			var numread = xmlDoc.getElementsByTagName("numread").item(0).firstChild.data;					// ricostruisco l'identificativo del numero di messaggi letti
			var numwaiting = xmlDoc.getElementsByTagName("numwaiting").item(0).firstChild.data;		// Ricostruisco l'identificativo del numero di messaggi in attesa di lettura
			
			var idmessagecancella = xmlDoc.getElementsByTagName("idmessage").item(0).firstChild.data; 
			
			document.getElementById('messaggiotoprint').innerHTML = bodymessage;	//scrivo il contenuto messaggio nella box
			document.getElementById(idmessage).src= $root+"/immagini/ballgreen.gif";		//associo akl messaggio la palla del colore verde, dato che a questo punto e' sicuramente letto )
			document.getElementById('messaggiletti').innerHTML = "Letti:&nbsp;"+numread;  //scrivo il numero di messaggi letti
			document.getElementById('messaggiwaiting').innerHTML = "Da leggere:&nbsp;"+numwaiting;	//scrivo il numero di messaggi da leggere
			document.getElementById(idbookmark).src= $root+"/immagini/bookmark.gif";	// Assegno il bookmark
			document.getElementById('eliminamessaggio').disabled = "";	// il  pulsante di elminamessaggio e' abilitato
			document.getElementById('rispondimessaggio').disabled = "";	// il pulsante rispondimessaggion e' abilitato
			document.getElementById('idsendercancella').value = idsender;
			document.getElementById('idmessagecancella').value = idmessagecancella;
			document.getElementById('messaggi_rispondi_to').innerHTML = "";
			document.getElementById('pulsante_inviamessaggio').disabled = "disabled";
			document.getElementById('textbox_contenutomessaggio').disabled = "disabled";
			document.getElementById('textbox_contenutomessaggio').value = "";
			document.getElementById('numberchar').value = "512";
			var messaggio = document.getElementById('messaggio_invia');
			
			if (messaggio != null) {document.getElementById('messaggio_invia').innerHTML= "";}
			
			if ((idbookmarkold != 0)&&(idbookmark != idbookmarkold))
			{
			//alert(idbookmarkold);
			document.getElementById(idbookmarkold).src= $root+"/immagini/transparentbookmark.gif";	//cancello il bookmark vecchio
			}
			
			idbookmarkold = idbookmark;
		
		}

 

}



// crea l'oggetto per la comunicazione AJAX con il server   
  
  
// l'oggetto per comunicare con il server   
var http_req = null; // il problema con IE sta qui ;)  

// invia i dati del form al server




/* *********************************************************** /*
Nome: 			AjaxCallRicevuti
Funzionalita': 		Ë la funzione che viene chiamata quando, all'interno della pagina messaggi si clicca sul pulsante "ricevuti"
				Richiama di dati dei messaggi ricevuti dal file getmessaggiricevuti.php e gi associa la funzione gestisci_messaggi_inout per la gestione

				
Ingressi: 		        sessionid=identificativo di sessione
Uscite:			Nessuna
Note:			Nessuna
Modifica:			05/01/2008 - Michele Moroni
/* *********************************************************** */



function gestisci_messaggi_inout()
{

if (http_req.readyState==4 || http_req.readyState == "complete")

		{
    		
			var output_messaggi= http_req.responseText;
			document.getElementById('DivAreaMessaggi').innerHTML = urldecode(output_messaggi);

		
		}
		
else document.getElementById('DivAreaMessaggi').innerHTML = "<div style=\"width:285px; height:150px; margin-left:5px; margin-top:10px; border:1px solid; color:#793905; padding-left:3px\"><p style=\"font-size:12px; color:green; margin-top:50px; margin-left:80px;\">Caricamento Messaggi ....</p></div><div style=\"overflow:auto; position:absolute; left:5px; top:161px; background:#ffffff; width:288px; height:100px; border:1px solid #793905\"></div>";

}

function gestisci_lezioniprenotate()
{

if (http_req.readyState==4 || http_req.readyState == "complete")

		{
			var xmlDoc= http_req.responseXML.documentElement;
				
			$condizioneid =  xmlDoc.getElementsByTagName("condizioneid").item(0).firstChild.data;
			$dalle =  xmlDoc.getElementsByTagName("dalle").item(0).firstChild.data;
			$alle =  xmlDoc.getElementsByTagName("alle").item(0).firstChild.data;
			$data =  xmlDoc.getElementsByTagName("data").item(0).firstChild.data;
			$corrispettivo =  xmlDoc.getElementsByTagName("corrispettivo").item(0).firstChild.data;
			$luogo =  xmlDoc.getElementsByTagName("luogo").item(0).firstChild.data;
			try {$tariffa = xmlDoc.getElementsByTagName("tariffa").item(0).firstChild.data;} catch (e2) {$tariffa = "";}
			try {$tipo = xmlDoc.getElementsByTagName("tipo").item(0).firstChild.data;} catch (e1) {$tipo="";}
			$currency = xmlDoc.getElementsByTagName("currency").item(0).firstChild.data;
			
			$luogo = urldecode($luogo);
			
			$cognomestudente = xmlDoc.getElementsByTagName("cognomestud").item(0).firstChild.data;
			$cognomestudente = urldecode($cognomestudente);
			
			$nomestudente = xmlDoc.getElementsByTagName("nomestud").item(0).firstChild.data;
			$nomestudente = urldecode($nomestudente);
			
			$nomeprof = xmlDoc.getElementsByTagName("nomeprof").item(0).firstChild.data;
			$nomeprof = urldecode($nomeprof);
			
			$cognomeprof = xmlDoc.getElementsByTagName("cognomeprof").item(0).firstChild.data;
			$cognomeprof = urldecode($cognomeprof);
			
			$stringaprof = "<p style=\"font-size:12px; margin:3px;\"><span style=\"font-weight:bold\">Prof: </span>"+$nomeprof+"&nbsp;"+$cognomeprof+"<br />";
			if (($tipo=="")||($tipo=="LEZIONE"))
			{
			$stringastudent = "<p style=\"font-size:12px; margin:3px;\"><span style=\"font-weight:bold\">Studente: </span>"+$nomestudente+"&nbsp;"+$cognomestudente+"<br />";
			}
			
			else
			
			{	
				
				$numerostudenticonf = xmlDoc.getElementsByTagName("iscritti").item(0).firstChild.data;
				$richieste = xmlDoc.getElementsByTagName("richieste").item(0).firstChild.data;
				$stringastudent = "<p style=\"font-size:12px; margin:3px;\"><span style=\"font-weight:bold\">Studenti Confermati: </span>"+$numerostudenticonf+"&nbsp;<span style=\"font-weight:bold\"> Richieste: </span>"+$richieste+"<br />";
			}
			$stringora = $dalle+":00 - "+$alle+":00";
			$corrispettivo = $corrispettivo+" "+$currency+"";
			$stringaluogo = "<span style=\"font-weight:bold\">Dove: </span><input type=\"text\" style=\"width:230px; font-size:10px; height:12px;\" value='"+$luogo+"' /></p>";
			//$stringaluogo = "<span style=\"font-weight:bold\">Dove: </span>"+$luogo+"</p>";
			
			
		
			if ($condizioneid == "Stud")
			{
			document.getElementById('BoxInnerMateria').innerHTML = $stringaprof+$stringaluogo;
			}
			if ($condizioneid == "Prof")
			{
			document.getElementById('BoxInnerMateria').innerHTML = $stringastudent+$stringaluogo;
			}
			
			document.getElementById('BoxData').innerHTML = "<p style=\"font-size:12px; margin:2px\">"+$data+"</p>";
			document.getElementById('BoxOra').innerHTML = "<p style=\"font-size:12px; margin:2px\">"+$stringora+"</p>";
			if ($tipo=="") // Lezione
			{document.getElementById('BoxCosto').innerHTML = "<p style=\"font-size:12px; margin:2px\">"+$corrispettivo+"</p>";}
			
			else
			{document.getElementById('BoxCosto').innerHTML = "<p style=\"font-size:12px; margin:2px\">Tot. Corso: "+$tariffa+"&euro;</p>";}
		
		}
		
}

function gestisci_dettagli_lezioni()
{


if (http_req_lez.readyState==4 || http_req_lez.readyState == "complete")

		{
		
		
		var xmlDoc= http_req_lez.responseXML.documentElement;
		
		$errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
		
		if ($errore != "NO") {
				      try {document.getElementById('linea1').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">"+$errore+"</span>"}
		                      catch(e1) {document.getElementById('AreaDettagli').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">"+$errore+"</span>"}
				      }
		
		else {
		
			
			
			
			try {$type = xmlDoc.getElementsByTagName("type").item(0).firstChild.data;} catch(e1) {$type=""};
			$tipolezione = xmlDoc.getElementsByTagName("tipo").item(0).firstChild.data;
			
			if (($type=="CORSO")&&($tipolezione == "professore"))
			{
				$codicelezione = xmlDoc.getElementsByTagName("codlezione").item(0).firstChild.data;
				$sessionid = xmlDoc.getElementsByTagName("phpsessid").item(0).firstChild.data;
				GetDettagliCorsoSelezionato($codicelezione, $sessionid);
				return;
			}
			
			
			$luogo = xmlDoc.getElementsByTagName("luogo").item(0).firstChild.data;
			$luogo = urldecode($luogo);
			
			$corrispettivo = xmlDoc.getElementsByTagName("corrispettivo").item(0).firstChild.data;
						
			$nome = xmlDoc.getElementsByTagName("nomestudente").item(0).firstChild.data;
			$nome = urldecode($nome);
			$cognome = xmlDoc.getElementsByTagName("cognomestudente").item(0).firstChild.data;
			$cognome = urldecode($cognome);
			$citta = xmlDoc.getElementsByTagName("citta").item(0).firstChild.data;
			$provincia = xmlDoc.getElementsByTagName("provincia").item(0).firstChild.data;
			$telefonostud = xmlDoc.getElementsByTagName("telefonostud").item(0).firstChild.data;
			$idstudente = xmlDoc.getElementsByTagName("idstudente").item(0).firstChild.data;
			$idprofessore = xmlDoc.getElementsByTagName("idprofessore").item(0).firstChild.data;
			$statolezione=xmlDoc.getElementsByTagName("stato").item(0).firstChild.data;
			$currency = xmlDoc.getElementsByTagName("currency").item(0).firstChild.data;
			
			//alert($statolezione);
			
			if ($tipolezione == "professore") $idreceiverinvia = $idstudente;
			if ($tipolezione == "studente") $idreceiverinvia = $idprofessore;
			
			
                         if ($type == "CORSO")
			 {
		        document.getElementById('linea1').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">Dettagli Corso</span>";
			
			if ($corrispettivo=="ND")
			{
			    document.getElementById('linea3').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Costo totale del corso: non dichiarato<span>";  
			}
			else
			{
			document.getElementById('linea3').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Costo totale del corso: "+$corrispettivo+" "+$currency+"<span>"; 
			}
			
			
			 }
			 else
			 {
			document.getElementById('linea1').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">Dettagli Lezione</span>";
			
			if ($corrispettivo=="ND")
			    {
			    document.getElementById('linea3').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Corrispettivo: non dichiarato<span>"; 
			    }
			else
			    {
			      document.getElementById('linea3').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Corrispettivo: "+$corrispettivo+" "+$currency+"<span>";  
			       
			    }
			 
			 
			 }
			
			document.getElementById('linea2').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Luogo:<input type=\"text\" style=\"width:230px; font-size:10px; height:12px;\" value='"+$luogo+"' /><span>";
			document.getElementById('linea11').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold;\">Messaggio Interno<span>"; 
			
			
			if ($tipolezione == "studente")              {  
											document.getElementById('linea5').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">Dati Professore</span>";
											document.getElementById('linea6').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Nome: "+$nome+"</span>";
											document.getElementById('linea7').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Cognome: "+$cognome+"</span>";
											
											if ($statolezione=="C")
											   {
											   document.getElementById('linea8').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Telefono: "+$telefonostud+"</span>";
											   }
											}
											
			if ($tipolezione == "professore")
				{ 	
														
				if (($type=="")||($type=="LEZIONE"))
				
					{
					document.getElementById('linea5').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">Dati Studente</span>";
					document.getElementById('linea6').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Nome: "+$nome+"</span>";
					document.getElementById('linea7').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Cognome: "+$cognome+"</span>";
					
					
					if ($citta=="ND")
					{
					    document.getElementById('linea8').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Residente a: non dichiarato </span>";   
					}
					else
					{
					  document.getElementById('linea8').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Residente a: "+$citta+" ("+$provincia+")</span>";  
					}
					
					if ($telefonostud=="ND")
					{    
					document.getElementById('linea9').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Telefono: non dichiarato</span>";
					}
					else
					{
					document.getElementById('linea9').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; \">Telefono: "+$telefonostud+"</span>";
					}
					
					
					}
				
				else
				
					{
					
					document.getElementById('linea5').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px; border:0px; font-weight:bold\">Studenti:</span>";
					
				
					}
				
				
				}
		
											
		//namesender = $nome;
		//surnamesender = $cognome;
			
		//abilitarispondi(); // Abilita il campo messaggi
		
		//document.getElementById('idreceiverinvia').value =  $idreceiverinvia;  // imposto l'id della persona che deve ricevere il messaggio spedibile tramite area messaggi
			
			}
		
		
		}
		
else    {
		
		//alert("qqq siamo qui"+http_req_lez.readyState);
	        //document.getElementById('AreaDettagli').innerHTML = "Loading";
		
		try {document.getElementById('linea1').innerHTML = "<span style=\"font-size:12px; margin-top:0px; margin-bottom:0px;border:0px;\">Loading</span>";} catch(e1) {};
	        try {document.getElementById('linea2').innerHTML = "";} catch(e2) {};	
		try {document.getElementById('linea3').innerHTML = "";} catch(e3) {};
		try {document.getElementById('linea5').innerHTML = ""; } catch(e4) {};
		try {document.getElementById('linea6').innerHTML = "";	} catch(e5) {};
		try {document.getElementById('linea7').innerHTML = "";} catch(e6) {};
		try {document.getElementById('linea8').innerHTML = "";} catch(e7) {};
		try {document.getElementById('linea9').innerHTML = "";} catch(e8) {};
		try {document.getElementById('linea10').innerHTML = "";} catch(e9) {};
		try {document.getElementById('linea11').innerHTML = "";} catch(e10) {};
		//try {document.getElementById('messaggi_rispondi_to').innerHTML = "";} catch(e11) {};
		 
	}

}


function gestisci_dettagli_corso()
{

if (http_req_corso.readyState==4 || http_req_corso.readyState == "complete")

		{
			var output_lezioni= http_req_corso.responseText;
			document.getElementById('AreaDettagli').innerHTML = output_lezioni;
			
			
		}
		
else document.getElementById('AreaDettagli').innerHTML = "Loading";

}


function gestisci_lezioniprenotate_extended()
{

if (http_req.readyState==4 || http_req.readyState == "complete")

		{
			var output_lezioni= http_req.responseText;
			$codebookmark_old = "";  // questo serve per reinizializzare il bookmark quando cambiamo pagina
			document.getElementById('AreaLezioni').innerHTML = urldecode(output_lezioni);
			
			if (($topoint)&&($topoint!="0"))
			{scrolling($topoint);}
			$lezionetopoint = "0";
			$topoint = "0";
			
			$codelesson_first = document.getElementById('codefirstlesson').value;
			if (!$codelesson_actual) $codelesson_actual = $codelesson_first;
			
                        $numerolezioni = document.getElementById('numtotale').value;
			if ($numerolezioni=="") $numerolezioni = "0";
			document.getElementById('Numero_Lezioni').innerHTML = "<p style=\"margin-top:0px; border:0px; font-size:14px;\">"+$numerolezioni+"</p>";
					
		}
		
else document.getElementById('AreaLezioni').innerHTML = "loading";

}



function AjaxCallText(idsender,idreceiver,timestamp,sessionid, number)
{	
	http_req = crea_http_req();
	
	if ((number == "1")||(number == "2")) {http_req.open( "GET", $root+"/ajax/ajaxmessaggi.php?PHPSESSID="+sessionid+"&idsender="+idsender+"&idreceiver="+idreceiver+"&timestamp="+timestamp+"&sid=" + Math.random());}
	if (number == "3") {http_req.open( "GET", $root+"/ajax/ajaxmessaggisender.php?PHPSESSID="+sessionid+"&idsender="+idsender+"&idreceiver="+idreceiver+"&timestamp="+timestamp+"&sid=" + Math.random());}
	
	http_req.setRequestHeader("Content-Type","text/html; charset=utf-8");
	
	if (number == "1") http_req.onreadystatechange = gestisci_risposta; 
	if (number == "2") http_req.onreadystatechange = gestisci_risposta_long; 
	if (number == "3") http_req.onreadystatechange = gestisci_risposta_inviati; 
	
	http_req.send(null);

}

/* *********************************************************** /*
Nome: 			AjaxCallRicevuti
Funzionalita': 		Ë la funzione che viene chiamata quando, all'interno della pagina messaggi si clicca sul pulsante "ricevuti"
				Richiama di dati dei messaggi ricevuti dal file getmessaggiricevuti.php e gi associa la funzione gestisci_messaggi_inout per la gestione

				
Ingressi: 		        sessionid=identificativo di sessione
Uscite:			Nessuna
Note:			Nessuna
Modifica:			05/01/2008 - Michele Moroni
/* *********************************************************** */



function AjaxCallRicevuti(sessionid, $idprof)
{
	idbookmarkold = "0";
	http_req = crea_http_req();
	http_req.open( "GET", $root+"/ajax/getmessaggiricevuti.php?PHPSESSID="+sessionid+"&idprof="+$idprof+"&sid=" + Math.random());
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = gestisci_messaggi_inout;
	http_req.send(null);
}


/* *********************************************************** /*
Nome: 			AjaxCallInvati
Funzionalita': 		Ë la funzione che viene chiamata quando, all'interno della pagina messaggi si clicca sul pulsante "inviati"
				Richiama di dati dei messaggi inviati dal file getmessaggiinviati.php e gi associa la funzione gestisci_messaggi_inout per la gestione

				
Ingressi: 		        sessionid=identificativo di sessione
Uscite:			Nessuna
Note:			Nessuna
Modifica:			05/01/2008 - Michele Moroni
/* *********************************************************** */



function AjaxCallInviati(sessionid, $idprof)
{
	idbookmarkold = "0";
	http_req = crea_http_req();
	http_req.open( "GET", $root+"/ajax/getmessaggiinviati.php?PHPSESSID="+sessionid+"&idprof="+$idprof+"&sid=" + Math.random());
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = gestisci_messaggi_inout;
	http_req.send(null);
}


function AjaxCallLessonSummary(time, sessionid)
{
	http_req = crea_http_req();
	http_req.open( "GET", $root+"/ajax/ajaxgetlezioni.php?PHPSESSID="+sessionid+"&time="+time+"&sid=" + Math.random());
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = gestisci_lezioniprenotate;
	http_req.send(null);
}


function DisabilitaMessaggiLezioni()
{
$abilitamessaggi = "no";
}

function AbilitaMessaggiLezioni()
{
$abilitamessaggi = "yes";
}



function abilitarispondi()
{
	
	
	document.getElementById('messaggi_rispondi_to').innerHTML = urldecode(namesender+"&nbsp;"+surnamesender);
	
	try {document.getElementById('div_resultsent').style.zIndex = -1;
	    }
	catch (e1) {}
	
	if ($abilitamessaggi == "yes")
	{
	document.getElementById('pulsante_inviamessaggio').disabled = "";
	document.getElementById('textbox_contenutomessaggio').value = "";
	document.getElementById('textbox_contenutomessaggio').style.color = "black";
	}
	
	document.getElementById('textbox_contenutomessaggio').disabled = "";
	document.getElementById('textbox_contenutomessaggio').focus();
	
	document.getElementById('idreceiverinvia').value = idsender;
	AbilitaMessaggiLezioni();
}


/* *********************************************************** /*
Nome: 			LimittextHidden()
Funzionalit?:   Legge il numero di caratteri digitati all'interno della box limitField e li scrive all'interno di 'numberchar';
				Se il numero e' maggiore taglia i caratteri in eccesso in limitfield
				
Ingressi: 		limitField = id del campo di inserimento, limitnum = numero massimo di caratteri
Uscite:			Nessuna
Note:			Nessuna

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

function limitTextHidden(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
		
	
	}   
}


/* *********************************************************** /*
Nome: 			LimittextField()
Funzionalit?:   Legge il numero di caratteri digitati all'interno della box limitField e li scrive all'interno di 'numberchar';
				Se il numero e' maggiore taglia i caratteri in eccesso in limitfield
				
Ingressi: 		limitField = id del campo di inserimento, limitnum = numero massimo di caratteri
Uscite:			Nessuna
Note:			Nessuna

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

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
		
	
	}   
		var $counter = document.getElementById('numberchar');
		$counter.value= limitNum-limitField.value.length;
}



/* *********************************************************** /*
Nome: 			Colorchangerin();
Funzionalit?:   Quando il mouse entra nell'area relativa ad una lezione di oggi cambia il colore corrispondente all'intervallo orario nel calendario
				
Ingressi:		$stato = categoria di utenza (0 = prof, 1 = stud). Attualmente non usato ma lasciato come predisposizione 
				$dalle1 = ora di inizio dell'intervallo da evidenziare
				$alle1 = ora corrispondente alla fine dell'intervallo da evidenziare
Uscite:			nessuna
Note:			

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




function colorchangerin($stato, $dalle1,$alle1)
{
	
	$colorprof = "red"
	$colorstudent = "blue";
	
	var $counter;

	for ($counter = $dalle1; $counter<=$alle1; $counter++)
		{
									var $id = "casella"+$counter;
									if ($stato == '0') document.getElementById($id).style.background= $colorprof;
								   	else document.getElementById($id).style.background=$colorstudent;
		}

}

/* *********************************************************** /*
Nome: 			Colorchangerout();
Funzionalit?:   Ritorna al colore originale del calendario di oggi quando il mouse esce dall'area relativa alla lezione corrispondente
				
Ingressi:		$stato = categoria di utenza (0 = prof, 1 = stud). Attualmente non usato ma lasciato come predisposizione 
				$dalle1 = ora di inizio dell'intervallo da de-evidenziare
				$alle1 = ora corrispondente alla fine dell'intervallo da de-evidenziare
Uscite:			nessuna
Note:			

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


function colorchangerout($stato, $dalle1,$alle1)
{
	
	
	var $counter;

	for ($counter = $dalle1; $counter<=$alle1; $counter++)
		{
									var $id = "casella"+$counter;
									document.getElementById($id).style.background= "orange";
		}

}





/* *********************************************************** /*
Nome: 			DisplayLesson
Funzionalit?:   Visualzza la lista delle lezioni sulla base della selezione effettuata (pulsanti premuti, checkbox e menu' a tendina). 
				
Ingressi: 		$buttonpressed = pulsante premuto (lezioni future o archivio)	
				$sessionid = identificativo di sessione
				$lezionetopoint = lezione da evidenziare tramite bookmark e scrolling (vuoto se non ho cliccato su una lezione della main)
Uscite:			Nessuna
Note:			a lista viene recuperata passando i parametri alla funzione ajax in AjaxGetLezioniExtended

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


function DisplayLesson($ButtonPressed, $sessionid, $lezionetopoint,$tipo)  // Gestisce le lezioni estese
{

	
	
	
	if (($lezionetopoint != "0")&&($lezionetopoint!="")) {
	 $topoint = $lezionetopoint; $bookmarkdisplay="no";
	{
	 $topoint = $lezionetopoint; $bookmarkdisplay="no";
	 
	 if ($tipo == "CORSO")
		{			
			GetDettagliCorsoSelezionato($topoint, $sessionid);
		}
	else
		  {
			GetDettagliLezioneSelezionata($topoint, $sessionid);
		  }
	 
	 
	 
	 }
	
	}
	
	else {$bookmarkdisplay = "yes";}
	
	if ($ButtonPressed == 0) $ButtonPressed = $button_old;  // La condizione di default di $button_old e' "future".
	else $button_old = $ButtonPressed;
	var boxselect = document.getElementById("LessonDisplaySelect").options;
	var tipouser = boxselect[boxselect.selectedIndex].value;		 // valore della select
	
	if ($ButtonPressed == "archivio") displaylezioni = "1";  // Lezioni Passate
	if ($ButtonPressed == "future") displaylezioni = "2";	// lezioni Future
	
	var CheckBoxAttive = document.getElementById("accettate").checked;   // Default fissato nel sincrono [true, true, false].
	var CheckBoxAttesa = document.getElementById("inattesa").checked;
	var CheckBoxRigettate = document.getElementById("rigettate").checked;
	
	//var boxbutton = document.getElementById("DisplayLesson").value;  // BottonePremuto
	
	http_req = crea_http_req();
	var $toopen = $root+"/ajax/ajaxgetlezioniextended.php?PHPSESSID="+$sessionid+"&displaylezioni="+displaylezioni+"&tipouser="+tipouser+"&checkboxattive="+CheckBoxAttive+"&checkboxattesa="+CheckBoxAttesa+"&checkboxrigettate="+CheckBoxRigettate+"&bookmarkdisplay="+$bookmarkdisplay+"&sid="+Math.random();
	http_req.open( "GET", $toopen);
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = gestisci_lezioniprenotate_extended;
	http_req.send(null);
	
}

function DisplayLessonAzd($ButtonPressed, $sessionid, $lezionetopoint,$idprof,$tipo)  // Gestisce le lezioni estese
{

	if (($lezionetopoint != "0")&&($lezionetopoint!=""))
	{
	 $topoint = $lezionetopoint; $bookmarkdisplay="no";
	 
	 if ($tipo == "CORSO")
		{			
			GetDettagliCorsoSelezionatoAzd($topoint, $sessionid, $idprof);
		}
	else
		  {
			GetDettagliLezioneSelezionataAzd($topoint, $sessionid, $idprof);
		  }
	 
	 
	 
	 }
	else {$bookmarkdisplay = "yes";}
	
	if ($ButtonPressed == 0) $ButtonPressed = $button_old;  // La condizione di default di $button_old e' "future".
	else $button_old = $ButtonPressed;
	var boxselect = document.getElementById("LessonDisplaySelect").options;
	var tipouser = boxselect[boxselect.selectedIndex].value;		 // valore della select
	
	if ($ButtonPressed == "archivio") displaylezioni = "1";  // Lezioni Passate
	if ($ButtonPressed == "future") displaylezioni = "2";	// lezioni Future
	
	var CheckBoxAttive = document.getElementById("accettate").checked;   // Default fissato nel sincrono [true, true, false].
	var CheckBoxAttesa = document.getElementById("inattesa").checked;
	var CheckBoxRigettate = document.getElementById("rigettate").checked;
	
	//var boxbutton = document.getElementById("DisplayLesson").value;  // BottonePremuto
	
	http_req = crea_http_req();
	var $toopen = $root+"/ajax/ajaxgetlezioniextended.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&displaylezioni="+displaylezioni+"&tipouser="+tipouser+"&checkboxattive="+CheckBoxAttive+"&checkboxattesa="+CheckBoxAttesa+"&checkboxrigettate="+CheckBoxRigettate+"&bookmarkdisplay="+$bookmarkdisplay+"&sid="+Math.random();
	http_req.open( "GET", $toopen);
	http_req.setRequestHeader("Content-Type", "text/xml");
	http_req.onreadystatechange = gestisci_lezioniprenotate_extended;
	http_req.send(null);
			       
}





/* *********************************************************** /*
Nome: 			scrolling();
Funzionalit?:   Richiamata nella mypage. Quando clicco su una lezione di oggi viene richiamata la pagina "Lezioni". 
				Questa funzione evidenza la lezione cliccata inserendo il bookmark e scrolla l'area di display fino a visualizzare la lezione richiesta
				
Ingressi: 		$code = codice della lezione cliccata;	
Uscite:			nessuna
Note:			

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


function scrolling($code)
{
	
	$bookmark = "bookmark"+$code;                            // Recupero il bookmark della lezione da evidenziare
	$area_bookmark = document.getElementById($bookmark);
	$lezione = document.getElementById($code);
	
	$to_print_inner = "<img src=\""+$root+"/immagini/bookmark.gif\" width=\"15\" height=\"15\" />"; 
	
	if ($area_bookmark != null) $area_bookmark.innerHTML = $to_print_inner;
	$codebookmark_old = $bookmark;

	var $a = $lezione.offsetTop;						// calcolo l'offset dell'area lezioni
	var $b = document.getElementById('AreaLezioni');	// Elemento padre al cui interno faccio lo scrolling
	$b.scrollTop = $a;									// Scrollo fino all'offset calcolato

}

/* *********************************************************** /*
Nome: 			erase_color($code)
Funzionalit?:   Funzione di ottimizzazione. Quando muovo il mouse su una lezione nella pagina "lezioni" una eventuale altra lezione selezionata in ingresso deve essere deselezionata automaticamente.
				questa funzione esegue l'erasing.
				
Ingressi: 		$code = codice della lezione cliccata;	
Uscite:			nessuna
Note:			POTREBBE NON ESSERE PIU' NECESSARIA, DA VERIFICARE!!!

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


function erase_color($code)
{
$lezione = document.getElementById($code);
if ($lezione != null) $lezione.style.background='#ffffff';
}

/* *********************************************************** /*
Nome: 			GetDatiFirst
Funzionalit?:   Nella pagina "lezioni" visualizza i dati della prima lezione visualizzata (quando premo un pulsante o carico la pagina per la prima volta)
				
Ingressi: 		$sessionid = identificativo di sessione
				
Uscite:			Nessuna

Note:			Non viene utilizzata quando clicco su una lezione visualizzata

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

function GetDatiFirst($ButtonPressed, $sessionid)
{
		
	if ($ButtonPressed == 0) $ButtonPressed = $button_old;  					// Se non ho premuto nessun bottone (primo caricamento) la condizione di default di $button_old e' "future".
	else $button_old = $ButtonPressed;											// Altrimenti vedo quale bottone ho premuto
	var boxselect = document.getElementById("LessonDisplaySelect").options;		// Recupero il valore della select (studenti, professori, tutte)
	var tipouser = boxselect[boxselect.selectedIndex].value;		 			// valore della select
	
	if ($ButtonPressed == "archivio") displaylezioni = "1";  					// Lezioni Passate
	if ($ButtonPressed == "future") displaylezioni = "2";						// lezioni Future
	
	var CheckBoxAttive = document.getElementById("accettate").checked;   		// Default fissato nella parte sincrona: valori = [true, true, false].
	var CheckBoxAttesa = document.getElementById("inattesa").checked;
	var CheckBoxRigettate = document.getElementById("rigettate").checked;
	
	/////// Parte Ajax --> Recupero i dettagli della prima lezione selezionata sulla base dei parametri precedenti e li visualizzo nell'area dettagli
	http_req_lez = crea_http_req();
	http_req_lez.open( "GET", $root+"/ajax/ajaxgetdatilezione.php?PHPSESSID="+$sessionid+"&displaylezioni="+displaylezioni+"&tipouser="+tipouser+"&checkboxattive="+CheckBoxAttive+"&checkboxattesa="+CheckBoxAttesa+"&checkboxrigettate="+CheckBoxRigettate+"&codelesson=0&sid=" + Math.random());
	http_req_lez.setRequestHeader("Content-Type", "text/xml");
	http_req_lez.onreadystatechange = gestisci_dettagli_lezioni;
	http_req_lez.send(null);
	
}


function GetDatiFirstAzd($ButtonPressed, $sessionid, $idprof)
{
	
	
		
	if ($ButtonPressed == 0) $ButtonPressed = $button_old;  					// Se non ho premuto nessun bottone (primo caricamento) la condizione di default di $button_old e' "future".
	else $button_old = $ButtonPressed;											// Altrimenti vedo quale bottone ho premuto
	var boxselect = document.getElementById("LessonDisplaySelect").options;		// Recupero il valore della select (studenti, professori, tutte)
	var tipouser = boxselect[boxselect.selectedIndex].value;		 			// valore della select
	
	if ($ButtonPressed == "archivio") displaylezioni = "1";  					// Lezioni Passate
	if ($ButtonPressed == "future") displaylezioni = "2";						// lezioni Future
	
	var CheckBoxAttive = document.getElementById("accettate").checked;   		// Default fissato nella parte sincrona: valori = [true, true, false].
	var CheckBoxAttesa = document.getElementById("inattesa").checked;
	var CheckBoxRigettate = document.getElementById("rigettate").checked;
	
	/////// Parte Ajax --> Recupero i dettagli della prima lezione selezionata sulla base dei parametri precedenti e li visualizzo nell'area dettagli
	http_req_lez = crea_http_req();
	http_req_lez.open( "GET", $root+"/ajax/ajaxgetdatilezione.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&playlezioni="+displaylezioni+"&tipouser="+tipouser+"&checkboxattive="+CheckBoxAttive+"&checkboxattesa="+CheckBoxAttesa+"&checkboxrigettate="+CheckBoxRigettate+"&codelesson=0&sid=" + Math.random());
	http_req_lez.setRequestHeader("Content-Type", "text/xml");
	http_req_lez.onreadystatechange = gestisci_dettagli_lezioni;
	http_req_lez.send(null);
	
}





/* *********************************************************** /*
Nome: 		GetDettagliLezioneSelezionata
Funzionalit?:   Nella pagina "lezioni" recupera i dettagli della lezione che ho selezionato 
			
Ingressi: 	$codelesson = codice identificativo della lezione su cui ho cliccato
		$sessionid = identificativo di sessione
Uscite:		Nessuna
Note:		

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


function GetDettagliLezioneSelezionata($codelesson, $sessionid)
{
	
	// preparazione dell'area dettagli per ricevere l'ajax
	
	$text = "<table width=\"285\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin:0px; padding:0px\">";
	
	
		for ($a=1; $a<15; $a++)
		{
		$variable = "linea"+$a;
		$text = $text+"<tr><td style=\"height:16px; line-height:16px:\" id=\""+$variable+"\">&nbsp;</td></tr>";
		}
	 
	$text=$text+"</table>";
	
	document.getElementById('AreaDettagli').innerHTML = $text;
	
	http_req_lez = crea_http_req();
	http_req_lez.open( "GET", $root+"/ajax/ajaxgetdatilezione.php?PHPSESSID="+$sessionid+"&codelesson="+$codelesson+"&sid=" + Math.random());
	http_req_lez.setRequestHeader("Content-Type", "text/xml");
	http_req_lez.onreadystatechange = gestisci_dettagli_lezioni;
	http_req_lez.send(null);
	
	$codelesson_actual = $codelesson;
	GetAreaMessaggiForLesson($codelesson, $sessionid);
	
	

	
}


function GetDettagliLezioneSelezionataAzd($codelesson, $sessionid, $idprof)
{
	
	// preparazione dell'area dettagli per ricevere l'ajax
	
	$text = "<table width=\"285\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin:0px; padding:0px\">";
	
	
		for ($a=1; $a<15; $a++)
		{
		$variable = "linea"+$a;
		$text = $text+"<tr><td style=\"height:16px; line-height:16px:\" id=\""+$variable+"\">&nbsp;</td></tr>";
		}
	 
	$text=$text+"</table>";
	
	document.getElementById('AreaDettagli').innerHTML = $text;
	
	$var = $root+"/ajax/ajaxgetdatilezione.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&codelesson="+$codelesson+"&sid="+Math.random();
		
	http_req_lez = crea_http_req();
	http_req_lez.open( "GET", $var);
	http_req_lez.setRequestHeader("Content-Type", "text/xml");
	http_req_lez.onreadystatechange = gestisci_dettagli_lezioni;
	http_req_lez.send(null);
	
	$codelesson_actual = $codelesson;
	GetAreaMessaggiForLessonAzd($codelesson, $sessionid, $idprof);
}





function GetDettagliCorsoSelezionato($codelesson, $sessionid)
{
	
	http_req_corso = crea_http_req();
	http_req_corso.open( "GET", $root+"/ajax/ajaxgetdaticorso.php?PHPSESSID="+$sessionid+"&codelesson="+$codelesson+"&sid=" + Math.random());
	http_req_corso.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-15");
	http_req_corso.onreadystatechange = gestisci_dettagli_corso;
	http_req_corso.send(null);
	
	$codelesson_actual = $codelesson;
	GetAreaMessaggiForCorsi($codelesson, $sessionid)
	
	
	
}

function GetDettagliCorsoSelezionatoAzd($codelesson, $sessionid, $idprof)
{
		
	http_req_corso = crea_http_req();
	http_req_corso.open( "GET", $root+"/ajax/ajaxgetdaticorso.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&codelesson="+$codelesson+"&sid=" + Math.random());
	http_req_corso.setRequestHeader("Content-Type", "text/html; charset=ISO-8859-15");
	http_req_corso.onreadystatechange = gestisci_dettagli_corso;
	http_req_corso.send(null);
	
	
	$codelesson_actual = $codelesson;
	GetAreaMessaggiForCorsi($codelesson, $sessionid)
	      
}




/* *********************************************************** /*
Nome: 			ClickLessonExtended
Funzionalit?:   Nella pagina "lezioni" posiziona il bookmark sulla lezione su cui si clicca 
				
Ingressi: 		$codebookmark = codice identificativo della locazione su cui spostare il bookmark
				$codelesson = codice identificativo della lezione su cui ho cliccato
				$bookmarkfirst = condice identificativo del bookmark della prima lezione visualizzata nella pagina
				$sessionid = identificativo di sessione
Uscite:			Nessuna

Note:			

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

function ClickLessonExtended($codebookmark, $bookmarkfirst, $codelesson, $tipo, $condizione_lez, $sessionid, $idprof)
{
		
	$codelesson_actual = $codelesson;

	$codebookmark_first = $bookmarkfirst;
	$area_bookmark = document.getElementById($codebookmark);
	
	
	// Se abbiamo cliccato su una lezione diversa da quella attualmente selezionata
	if (($codebookmark != $codebookmark_old) && ($codebookmark_old != ""))
		{	
		$area_bookmark_old = document.getElementById($codebookmark_old);
		$area_bookmark_old.innerHTML = "";								// Rimuovi il bookmark dalla lezione precedentemente selezionata
		}
	
	// Se abbiamo cliccato su una lezione diversa dalla prima											
	if (($codebookmark != $bookmarkfirst) && ($bookmarkfirst != ""))
		{
		$area_bookmark_first = document.getElementById($bookmarkfirst);	
		$area_bookmark_first.innerHTML = ""; 							// Rimuovi il bookmark dalla prima lezione	
		}
	
	$to_print_inner = "<img src=\""+$root+"/immagini/bookmark.gif\" width=\"15\" height=\"15\" />"; 
	
	// posiziona il bookmark sulla lezione cliccata
	if ($area_bookmark != null) {
					$area_bookmark.innerHTML = $to_print_inner;
				    }
	
	// aggiorna l'identificativo della posizione attuale del bookmark
	$codebookmark_old = $codebookmark;
	
	////////// Visualizzo i dettagli della lezione selezionata nell'area dettagli
	

	if (($tipo == "CORSO")&&($condizione_lez=="prof"))
		{			
			if ($idprof)  GetDettagliCorsoSelezionatoAzd($codelesson, $sessionid, $idprof);
			else GetDettagliCorsoSelezionato($codelesson, $sessionid);
			
		}
	else
	{
			
			if ($idprof) GetDettagliLezioneSelezionataAzd($codelesson, $sessionid, $idprof);
			else GetDettagliLezioneSelezionata($codelesson, $sessionid);
	}
	//////////
	
}





function AjaxGenerateArrayCalendario()

{
	
	var $arraycalendario = new Array();
	$arraycalendario[0] = new Array();
	
	var $id;
	var $j;
	var $i;
	var $CounterNotNull = 0;
	
	for($j=1; $j<5; $j++)   //j = riga, i = colonna;
		  						
	  	{		
			  $arraycalendario[$j] = new Array();
			  
			  for ($i=1; $i<8; $i++)
			  {	
			  
			  
			  
			  $id = $j+"_"+$i;
			  $temporary = document.getElementById($id).innerHTML; 
			  if (($temporary != "")&&($temporary != "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")) // questa roba e' scritta dalla divora
			  	{
					$temporary = removeHTMLTags($temporary);  // Stripping the HTML tags from temporary
					$CounterNotNull = $CounterNotNull+1; 
					$arraycalendario[$j][$i] = $temporary.substr(0,2);}// tagliamo gli ultimi 2 zeri e i due punti
			  else
			  	$arraycalendario[$j][$i] = "";
			  }

		}
	
	$arraycalendario[0][0] = $CounterNotNull;
	return $arraycalendario;

}


function AjaxControlloDatiCalendario($arraytocontrol)
{

		var $calendarioOK = "OK"; 
		var $numerovaloriinseriti = 0;
		var $i;
		var $j;
		var $transit;
		var $temporary = new Array();
		
		
		var $arrayout = new Array();
		var $sottrazione; 
		
		for($j=1; $j<5; $j++)   //j = riga, i = colonna;
		  						
	  	{
			
			  $arrayout[$j] = new Array();
			  $temporary[$j] = new Array();
			
			for ($i=1; $i<8; $i++)
			  {	
			   
			  $arrayout[$j][$i]="OK";					// Inizializzazione a OK
			  
			  if($arraytocontrol[$j][$i]!="")
				  {
				  	$numerovaloriinseriti++;
					$transit = $arraytocontrol[$j][$i];
					$temporary[$j][$i] =  $transit.substr(0,2); // tagliamo gli ultimi 2 zeri e i due punti
				  }
			  
			  else $temporary[$j][$i]="";
			  }
		}
		
		for ($j=2; $j<5; $j=$j+2)
		{ 
			for ($i=1; $i<8; $i++)
			{
				
				
				$var2 = $temporary[$j][$i];
				$var1 = $temporary[$j-1][$i];
				$sottrazione = ($var2-$var1);

								
				if (($temporary[$j][$i]!="")&&($temporary[$j-1][$i]=="")) {$arrayout[$j][$i] = "KO"; $arrayout[$j-1][$i]="KO"; $calendarioOK = "KO";}
				if (($temporary[$j][$i]=="")&&($temporary[$j-1][$i]!="")) {$arrayout[$j][$i] = "KO"; $arrayout[$j-1][$i]="KO"; $calendarioOK = "KO";}
				if (($temporary[$j][$i]!="")&&($temporary[$j-1][$i]!=""))
					{
					if ($sottrazione<=0) {$arrayout[$j][$i] = "KO"; $arrayout[$j-1][$i]="KO"; $calendarioOK = "KO";}
					}
			}
		}
		
		for ($i=1; $i<8; $i++)
			{
				
				if (($arraytocontrol["3"][$i]!="")&&($arraytocontrol["1"][$i]!="")&&($arraytocontrol[2][$i]!="")&&($arraytocontrol[4][$i]!=""))
				{
				     
				     if (($arraytocontrol["3"][$i]>=$arraytocontrol["1"][$i])&&($arraytocontrol["3"][$i]<$arraytocontrol["2"][$i])) {$arrayout["3"][$i] = "KO"; $calendarioOK = "KO";}
				     if (($arraytocontrol["4"][$i]>$arraytocontrol["1"][$i])&&($arraytocontrol["4"][$i]<=$arraytocontrol["2"][$i])) {$arrayout["4"][$i] = "KO"; $calendarioOK = "KO";}
				     if (($arraytocontrol["3"][$i]<$arraytocontrol["1"][$i])&&($arraytocontrol["4"][$i]>$arraytocontrol[2][$i])) {$arrayout["4"][$i] = "KO"; $arrayout["3"][$i]="KO"; $calendarioOK = "KO";}
				
				}
			
			
			
			
			}
		
		if ($numerovaloriinseriti == 0) $calendarioOK = "UN"; // Non Ë stato inserito alcun valore
		$arrayout[0] = new Array();
		$arrayout[0][0] = $calendarioOK;	
		return $arrayout;
}




function JavascriptSubmitDataModifyAzd($sessionid, $iduser)
{

	$errori = "no";
	$consistenza_password = "";
	
	$nome = document.getElementById('nome').value;
	$nome = $nome.replace(/&/g,"@ecommerciale@");
	$telefono = document.getElementById('telefono').value;
	$domicilio = document.getElementById('domicilio').value;
	
	$province_index = document.getElementById('lista_province').selectedIndex;
        $provincia = document.getElementById('lista_province').options[$province_index].text;
	
	$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;
	
	$annofondazione = document.getElementById('annofondazione').value;
	
	$descrizione = document.getElementById('textbox_descrizione').value;
	
	$categoria_index = document.getElementById('select_categoria').selectedIndex;
	$categoria = document.getElementById('select_categoria').options[$categoria_index].text;
	
	$email = document.getElementById('email').value;
	$password = document.getElementById('password').value;
	$ctrpassword = document.getElementById('ctrpassword').value;
	$sito = document.getElementById('sito').value;

	
	$telefono = CleanPhoneNumber($telefono);
	
	$controllo_email = VerificaEmail($email);
	
	if ($controllo_email == "failed") {$errori = "yes"; document.getElementById('label_email').style.background = "red";} 
	if ($controllo_email == "passed") {document.getElementById('label_email').style.background = "";} 
	
	
	
	//if (!$provincia) { $errori = "yes"; document.getElementById('label_provincia').style.background="red";}
	//if ($provincia) {  document.getElementById('label_provincia').style.background=""; }
	
	if (!$domicilio) { $errori = "yes"; document.getElementById('label_domicilio').style.background="red";}
	if ($domicilio) {  document.getElementById('label_domicilio').style.background=""; }
	
	if (!$nome) {$errori = "yes"; document.getElementById('label_nome').style.background = "red";} 
	if ($nome) {document.getElementById('label_nome').style.background = "";}
	
	if (!$password) { $errori = "yes"; document.getElementById('label_password').style.background="red";}
	if ($password) {  $consistenza_password = ConsistenzaPassword($password);
				      if ($consistenza_password == "failed") { $errori = "yes"; document.getElementById('label_password').style.background="red";}
					  else {document.getElementById('label_password').style.background="";} 
					}
	if (!$ctrpassword) { $errori = "yes"; document.getElementById('label_ctrpassword').style.background="red";}
	if ($ctrpassword) {  document.getElementById('label_ctrpassword').style.background=""; 
	                     
						 }
	
	
	if (($password)&&($ctrpassword))  // Controllo di coerenza
		{	
		
		if ($password != $ctrpassword) { 
		
		                                $errori = "yes"; document.getElementById('label_ctrpassword').style.background="yellow";
										if ($consistenza_password != "failed") document.getElementById('label_password').style.background="yellow";
									   }
		
		
		if ($password == $ctrpassword) { 
										
										$consistenza_password = ConsistenzaPassword($password);
										 if ($consistenza_password == "failed") { $errori = "yes"; 
																				  document.getElementById('label_ctrpassword').style.background="red";
																				  document.getElementById('label_password').style.background="red";
																				}
										
										 if ($consistenza_password == "passed") { document.getElementById('label_ctrpassword').style.background="";
																				  document.getElementById('label_password').style.background="";
																				}
									  
									  
									   }
		
		}
		
		
	if ($errori == "yes") 
	{
	document.getElementById('result').style.color = "red";
	document.getElementById('result').innerHTML = "FALLITO";
        document.getElementById('ErroreEmail').innerHTML = "";
	}
	
	else 
	{
	
	//document.getElementById('result').style.color = "green";
	//document.getElementById('result').innerHTML = "PROCEEDING";
	
	http_req_update = crea_http_req();
	http_req_update.open( "GET", $root+"/ajax/ajaxsetupdate.php?PHPSESSID="+$sessionid+"&annofondazione="+$annofondazione+"&nome="+$nome+"&descrizione="+$descrizione+"&categoria="+$categoria+"&iduser="+$iduser+"&email="+$email+"&telefono="+$telefono+"&sito="+$sito+"&password="+$password+"&domicilio="+$domicilio+"&provincia="+$provincia+"&nazione="+$nazione+"&regione="+$regione+"&id="+ Math.random());
	http_req_update.setRequestHeader("Content-Type", "text/xml");
	http_req_update.onreadystatechange = gestisci_update_dati;
	http_req_update.send(null);
	}
	

}




/* *********************************************************** /*
Nome: 			
Funzionalit?:   
				
Ingressi: 		
				
				
				
Uscite:			Nessuna

Note:			

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


function JavascriptSubmitDataModifyStud($sessionid, $iduser)
{
	
	$errori = "no";
	$consistenza_password = "";
	
	//$genere = document.getElementById('genere').value;
	$nome = document.getElementById('nome').value;
	$cognome = document.getElementById('cognome').value;
	$telefono = document.getElementById('telefono').value;
	$domicilio = document.getElementById('domicilio').value;
	$provincia = document.getElementById('provincia').value;
	$annonascita = document.getElementById('annonascita').value;	
	
	$email = document.getElementById('email').value;
	$password = document.getElementById('password').value;
	$ctrpassword = document.getElementById('ctrpassword').value;
	
	$telefono = CleanPhoneNumber($telefono);
	
	$controllo_email = VerificaEmail($email);
	
	if ($controllo_email == "failed") {$errori = "yes"; document.getElementById('label_email').style.background = "red";} 
	if ($controllo_email == "passed") {document.getElementById('label_email').style.background = "";} 
	
	////
	//if (!$domicilio) { $errori = "yes"; document.getElementById('label_domicilio').style.background="red";}
	//if ($domicilio) {  document.getElementById('label_domicilio').style.background=""; }
	////
	
	//if (!$provincia) { $errori = "yes"; document.getElementById('label_provincia').style.background="red";}
	//if ($provincia) {  document.getElementById('label_provincia').style.background=""; }
	
	//if (!$email) { $errori = "yes"; document.getElementById('label_email').style.background="red";}
	//if ($email) {  document.getElementById('label_email').style.background=""; }
	
	if (!$password) { $errori = "yes"; document.getElementById('label_password').style.background="red";}
	if ($password) {  $consistenza_password = ConsistenzaPassword($password);
				      if ($consistenza_password == "failed") { $errori = "yes"; document.getElementById('label_password').style.background="red";}
					  else {document.getElementById('label_password').style.background="";} 
					}
	if (!$ctrpassword) { $errori = "yes"; document.getElementById('label_ctrpassword').style.background="red";}
	if ($ctrpassword) {  document.getElementById('label_ctrpassword').style.background=""; 
	                     
						 }
	
	
	if (($password)&&($ctrpassword))  // Controllo di coerenza
		{	
		
		if ($password != $ctrpassword) { 
		
		                                $errori = "yes"; document.getElementById('label_ctrpassword').style.background="yellow";
										if ($consistenza_password != "failed") document.getElementById('label_password').style.background="yellow";
									   }
		
		
		if ($password == $ctrpassword) { 
										
										$consistenza_password = ConsistenzaPassword($password);
										 if ($consistenza_password == "failed") { $errori = "yes"; 
																				  document.getElementById('label_ctrpassword').style.background="red";
																				  document.getElementById('label_password').style.background="red";
																				}
										
										 if ($consistenza_password == "passed") { document.getElementById('label_ctrpassword').style.background="";
																				  document.getElementById('label_password').style.background="";
																				}
									  
									  
									   }
		
		}
	


	if ($errori == "yes") 
	{
	document.getElementById('result').style.color = "red";
	document.getElementById('result').innerHTML = "FALLITO";
        document.getElementById('ErroreEmail').innerHTML = "";
        
	}
	
	else 
	{
	
	//document.getElementById('result').style.color = "green";
	//document.getElementById('result').innerHTML = "PROCEEDING";
	
	http_req_update = crea_http_req();
	http_req_update.open( "GET", $root+"/ajax/ajaxsetupdate.php?PHPSESSID="+$sessionid+"&annonascita="+$annonascita+"&iduser="+$iduser+"&email="+$email+"&telefono="+$telefono+"&password="+$password+"&domicilio="+$domicilio+"&provincia="+$provincia+"&id="+ Math.random());
	http_req_update.setRequestHeader("Content-Type", "text/xml");
	http_req_update.onreadystatechange = gestisci_update_dati;
	http_req_update.send(null);
	}
	
}



/* *********************************************************** /*
Nome: 			
Funzionalit?:    
				
Ingressi: 		
				
				
				
Uscite:			Nessuna

Note:			

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


function JavascriptSubmitDataModifyProf($sessionid, $iduser)
{

    
	$errori = "no";
	
	$genere = document.getElementById('genere').value;
	$nome = document.getElementById('nome').value;
	$cognome = document.getElementById('cognome').value;
	$telefono = document.getElementById('telefono').value;
	$domicilio = document.getElementById('domicilio').value;
	
	$provincia_index = document.getElementById('lista_province').selectedIndex;
	$provincia = document.getElementById('lista_province').options[$provincia_index].text //returns "Option 3"
	
	$regione_index = document.getElementById('lista_regioni').selectedIndex;
	$regione = document.getElementById('lista_regioni').options[$regione_index].text //returns "Option 3"
	
	$nazione_index = document.getElementById('select_stato').selectedIndex;
	$nazione = document.getElementById('select_stato').options[$nazione_index].text //returns "Option 3"
	
	$annonascita = document.getElementById('annonascita').value;
	$professione = document.getElementById('professione').value;
	$titolo_index = document.getElementById('titolo').selectedIndex;
	$titolo = document.getElementById('titolo').options[$titolo_index].text //returns "Option 3"
	
	$email = document.getElementById('email').value;
	$password = document.getElementById('password').value;
	$ctrpassword = document.getElementById('ctrpassword').value;
	
	/*
	$descrizione1 = document.getElementById('descrizione_mat').value;
	$indirizzo1 = document.getElementById('indirizzo').value;
	
	$livello_index = document.getElementById('livello1').selectedIndex;
	$livello1 = document.getElementById('livello1').options[$livello_index].text; //returns "Option 3"
	
	$gruppo_index = document.getElementById('gruppo').selectedIndex;
	$gruppo1 = document.getElementById('gruppo').options[$gruppo_index].text; //returns "Option 3"
	
	$materia1 = document.getElementById('corso_1').value;
	$tariffa1 = document.getElementById('tariffa').value;
	
	*/
	
	$telefono = CleanPhoneNumber($telefono);
	$professione = removeHTMLTags($professione);
	$titolo = CleanTitolo($titolo); 
	$domicilio = removeHTMLTags($domicilio);
	$provincia = removeHTMLTags($provincia);
	
	//$descrizione = removeHTMLTags($descrizione1);
	//$materia1 = removeHTMLTags($materia1);
	//$tariffa1 = CleanTariffa($tariffa1);
	//$indirizzo1 = removeHTMLTags($indirizzo1);
	
	$controllo_email = VerificaEmail($email);
	
	if ($controllo_email == "failed") {$errori = "yes"; document.getElementById('label_email').style.background = "red";} 
	if ($controllo_email == "passed") {document.getElementById('label_email').style.background = "";} 
	
	////
	if (!$domicilio) { $errori = "yes"; document.getElementById('label_domicilio').style.background="red";}
	if ($domicilio) {  document.getElementById('label_domicilio').style.background=""; }
	////
	
	//if (!$provincia) { $errori = "yes"; document.getElementById('label_provincia').style.background="red";}
	//if ($provincia) {  document.getElementById('label_provincia').style.background=""; }
	
	//if (!$email) { $errori = "yes"; document.getElementById('label_email').style.background="red";}
	//if ($email) {  document.getElementById('label_email').style.background=""; }
	
	if (!$password) { $errori = "yes"; document.getElementById('label_password').style.background="red";}
	if ($password)  {  $consistenza_password = ConsistenzaPassword($password);
				       if ($consistenza_password == "failed") { $errori = "yes"; document.getElementById('label_password').style.background="red";}
					   else {document.getElementById('label_password').style.background="";} 
					}
	
	if (!$ctrpassword) { $errori = "yes"; document.getElementById('label_ctrpassword').style.background="red";}
	if ($ctrpassword) {  document.getElementById('label_ctrpassword').style.background=""; }
	
	//if (!$indirizzo1) { $errori = "yes"; document.getElementById('label_indirizzo').style.background="red";}
	//if ($indirizzo1) {  document.getElementById('label_indirizzo').style.background=""; }
	
	//if (!$materia1) { $errori = "yes"; document.getElementById('corso_1').style.background="red";}
	//if ($materia1) {  document.getElementById('corso_1').style.background="#ffffff"; }
	 
	
	
	
	if (($password)&&($ctrpassword))  // Controllo di coerenza
		{	
		
		if ($password != $ctrpassword) { 
		
		                                $errori = "yes"; document.getElementById('label_ctrpassword').style.background="yellow";
										if ($consistenza_password != "failed") document.getElementById('label_password').style.background="yellow";
									   }
		
		
		if ($password == $ctrpassword) { 
										
										$consistenza_password = ConsistenzaPassword($password);
										 if ($consistenza_password == "failed") { $errori = "yes"; 
																				  document.getElementById('label_ctrpassword').style.background="red";
																				  document.getElementById('label_password').style.background="red";
																				}
										
										 if ($consistenza_password == "passed") { document.getElementById('label_ctrpassword').style.background="";
																				  document.getElementById('label_password').style.background="";
																				}
									  
									  
									   }
		
		}
	

	/*
	var $arraycalendario = new Array();
	var $arraycontrollocal = new Array();
	
	$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";
											
											}
										}
	
									
									}
	*/
	
	if ($errori == "yes") 
	{
	document.getElementById('result').style.color = "red";
	document.getElementById('result').innerHTML = "FALLITO";
        document.getElementById('ErroreEmail').innerHTML = "";
	}
	
	else 
	{
	
	
	//$calendar_stringed = GetArrayCalendarioStringed();
	
	//document.getElementById('result').style.color = "green";
	//document.getElementById('result').innerHTML = "PROCEEDING";
	
			
	http_req_update = crea_http_req();
	
	http_req_update.open( "GET", $root+"/ajax/ajaxsetupdate.php?PHPSESSID="+$sessionid+"&annonascita="+$annonascita+"&iduser="+$iduser+"&professione="+$professione+"&email="+$email+"&telefono="+$telefono+"&titolo="+$titolo+"&password="+$password+"&nazione="+$nazione+"&regione="+$regione+"&domicilio="+$domicilio+"&provincia="+$provincia+"&id="+ Math.random());
	
	http_req_update.setRequestHeader("Content-Type", "text/xml");
	http_req_update.onreadystatechange = gestisci_update_dati;
	http_req_update.send(null);
	
	} 
		
}



function GetArrayCalendarioStringed()
{

	var $calendar = new Array();
	var $calendariostringed = new Array();
	var $k;
	
	for ($j= 1; $j<5; $j++)
	{
		$calendar[$j] = new Array();
		
		for ($i=1; $i<8; $i++)
		{		
		$id = $j+"_"+$i;
		$temp = document.getElementById($id).innerHTML;
		$temp = removeHTMLTags($temp);
		$towrite = $temp.substr(0,2);
		$calendar[$j][$i] = $towrite;
		}
		
		$calendariostringed[$j] = $calendar[$j].toString();
	}
	
	return $calendariostringed;
	
}
	
	//document.location.href='index.php';
	


function ConfirmVacation($sessionid,$idprof)
{
						
	http_req_vac = crea_http_req();
	http_req_vac.open( "GET", $root+"/ajax/ajaxsetvacanze.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&giorno1="+$giorno1+"&giorno2="+$giorno2+"&id="+Math.random());
	http_req_vac.setRequestHeader("Content-Type", "text/xml");
	http_req_vac.onreadystatechange = gestisci_set_vacanze;
	http_req_vac.send(null);

}


function ResetVacation($sessionid, $idprof)
{					
	
	http_req_res = crea_http_req();
	http_req_res.open( "GET", $root+"/ajax/ajaxresvacanze.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&id="+Math.random());
	http_req_res.setRequestHeader("Content-Type", "text/xml");
	http_req_res.onreadystatechange = gestisci_res_vacanze;
	http_req_res.send(null);
}


function gestisci_write_statistics()
{
    
    {


		if ((http_req_wstats.readyState==4) || (http_req_wstats.readyState == "complete"))
		{
			var xmlDoc= http_req_wstats.responseXML.documentElement;
		
		}
		
	    else 
		{
			
		}

}

    
    
}


function WriteStatistics($page)
{
http_req_wstats = crea_http_req();
http_req_wstats.open( "GET", $root+"/ajax/ajaxwritestatistics.php?page="+$page+"");
http_req_wstats.setRequestHeader("Content-Type", "text/xml");
http_req_wstats.onreadystatechange = gestisci_write_statistics;
http_req_wstats.send(null);   
}


function gestisci_help()
{

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


}


function JavaHelp($sub)
{

 $colormenu = "#854405";
 
 WriteStatistics($sub);

 
 http_req_mess = crea_http_req();
 
 
 if ($sub=="ChiSiamo") {
	 				   $toopen = $root+"/help/AjaxChiSiamo.php?mat="+Math.random();
	 				   http_req_mess.open( "GET", $toopen);
                       document.getElementById('ChiSiamo').style.color="#cc0000";
					   if ($id_help_old != "ChiSiamo")
					   		{document.getElementById($id_help_old).style.color= $colormenu;}
				       $id_help_old = "ChiSiamo";
					   }
 if ($sub=="Cosa") {
	 			   
				   $toopen = $root+"/help/AjaxCosa.php?mat="+Math.random();
				    http_req_mess.open( "GET", $toopen);
                   document.getElementById('Cosa').style.color="#cc0000";
				   document.getElementById($id_help_old).style.color= $colormenu;
				   $id_help_old = "Cosa";
				   }
 if ($sub=="Perche") {
	 				 $toopen = $root+"/help/AjaxPerche.php?mat="+Math.random();
	 				 http_req_mess.open( "GET", $toopen);
 					document.getElementById('Perche').style.color="#cc0000";
				    document.getElementById($id_help_old).style.color= $colormenu;
				    $id_help_old = "Perche";
 					}
 if ($sub=="Mappa") {
	 				$toopen = $root+"/help/AjaxMappa.php?mat="+Math.random();
					 http_req_mess.open( "GET", $toopen);
                    document.getElementById('Mappa').style.color="#cc0000";
				    document.getElementById($id_help_old).style.color= $colormenu;
				    $id_help_old = "Mappa";
 					}
 if ($sub=="Privacy") {
	 				   $toopen = $root+"/help/AjaxPrivacy.php?mat="+Math.random();
					    http_req_mess.open( "GET", $toopen);
 					   document.getElementById('Privacy').style.color="#cc0000";
				       document.getElementById($id_help_old).style.color= $colormenu;
				       $id_help_old = "Privacy";
 					  }
					  	  
 if ($sub=="Sicurezza") {
	 					 $toopen = $root+"/help/AjaxSicurezza.php?mat="+Math.random();
						 http_req_mess.open( "GET", $toopen);
 						document.getElementById('Sicurezza').style.color="#cc0000";
				        document.getElementById($id_help_old).style.color= $colormenu;
				        $id_help_old = "Sicurezza";
 						}
 if ($sub=="FAQ") {
	 			   $toopen = $root+"/help/AjaxFAQ.php?mat="+Math.random();
				    http_req_mess.open( "GET", $toopen);
 				   document.getElementById('FAQ').style.color="#cc0000";
				   document.getElementById($id_help_old).style.color= $colormenu;
				   $id_help_old = "FAQ";
 					}
 
 if ($sub=="Contatti") {
	 					 $toopen = $root+"/help/AjaxContatti.php?mat="+Math.random();
						 http_req_mess.open( "GET", $toopen);
 					    document.getElementById('Contatti').style.color="#cc0000";
				   		document.getElementById($id_help_old).style.color= $colormenu;
				   		$id_help_old = "Contatti";
 						}
 
  
 http_req_mess.setRequestHeader("Content-Type", "text/xml");
 http_req_mess.onreadystatechange = gestisci_help;
 http_req_mess.send(null);


}


function display_materia($unic, $PHPSESSID)
{
if(!$PHPSESSID) {window.location = $root+"/index.php?page=searchstrict&search="+$unic;}
if($PHPSESSID) {window.location = $root+"/index.php?PHPSESSID="+$PHPSESSID+"&page=searchstrict&search="+$unic;}
}



function gestisci_listamaterie()
{

if ((http_req_listamaterie.readyState==4) || (http_req_listamaterie.readyState == "complete"))
		{
			var output_lista= http_req_listamaterie.responseText;
			output_lista = urldecode(output_lista);
			document.getElementById('materie_up').innerHTML = output_lista;
		
		}
		
	    else 
		{
			 document.getElementById('materie_up').innerHTML = "<p style=\"margin:15px\">Loading</p>";
		}


}




function showmaterie($phpsessid, $nazione, $regione, $provincia, $citta)
{

if (!$nazione)
    {
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $nazione = document.getElementById('select_stato').options[$stato_index].text;
    }

    if (!$regione)
    {
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;
    }

$gruppo_index = document.getElementById('select_gruppo').selectedIndex;
$gruppo = document.getElementById('select_gruppo').options[$gruppo_index].text;

http_req_listamaterie = crea_http_req();
http_req_listamaterie.open( "GET", $root+"/ajax/ajaxgetlistmaterie.php?&PHPSESSID="+$phpsessid+"&nazione="+$nazione+"&regione="+$regione+"&gruppo="+$gruppo+"&id="+Math.random());
http_req_listamaterie.setRequestHeader("Content-Type", "text/xml");
http_req_listamaterie.onreadystatechange = gestisci_listamaterie;
http_req_listamaterie.send(null);

}

/* *********************************************************** /*
Nome: 			redirect 
Funzionalit?: 	utilizzata per caricare una nuova pagina all'interno della finestra

Ingressi: 		$location = indirizzo della pagina da caricare
                $id = identificativo di sessione
Uscite:			nessuna
Note:			nessuna
Modifica:		05/01/2008 - Michele Moroni
/* *********************************************************** */

function redirect($location, $id)
{
   if ($id == "") {window.location = $location;}  
   if ($id != "") {window.location = $location+"&PHPSESSID="+$id;}
}


function urldecode(encoded)
{
   
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
 
   return plaintext;
}



function stripslashes( str ) {
    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}

/* Questa funzione serve nella pagina "iscrizioni professori", per proseguire verso l'iscrizione di lezioni private (non corsi) */


function gestisci_formlezione()
{

if ((http_req_form.readyState==4) || (http_req_form.readyState == "complete"))
		{
			var output = http_req_form.responseText;
			output_lista = urldecode(output);
			document.getElementById('subprof_divdown').innerHTML = output;
		
		}
		
	    else 
		{
			 document.getElementById('subprof_divdown').innerHTML = "<p style=\"margin:15px\">Loading</p>";
		     document.getElementById('subprof_divdown').style.backgroundImage = "url("+$root+"/immagini/bg_bd_03.)";
		}

}

function gestisci_formlezione_azd()
{

if ((http_req_form.readyState==4) || (http_req_form.readyState == "complete"))
		{
			var output = http_req_form.responseText;
			output_lista = urldecode(output);
			document.getElementById('subprof_divdown').innerHTML = output;
			
			document.getElementById('bottone_ok').innerHTML = "<button style=\"width:80px; height:80px; font-size:21px;\" onclick=\"document.getElementById('form_iscrizioneprof').submit();\">OK</button>";
		
		}
		
	    else 
		{
			 document.getElementById('subprof_divdown').innerHTML = "<p style=\"margin:15px\">Loading</p>";
		     
		}

}


function set_subscribe_lezioni($PHPSESSID)
{

     $stato_index = document.getElementById('select_stato').selectedIndex;
     $nazione = document.getElementById('select_stato').options[$stato_index].text;

     http_req_form = crea_http_req();
     http_req_form.open( "GET", $root+"/ajax/ajaxgetformsubscribeonelesson.php?PHPSESSID="+$PHPSESSID+"&nazione="+$nazione+"&mat="+Math.random());
     http_req_form.setRequestHeader("Content-Type", "text/xml");
     http_req_form.onreadystatechange = gestisci_formlezione;
     http_req_form .send(null);

}

function set_subscribe_lezioni_azd($PHPSESSID)
{

     http_req_form = crea_http_req();
     http_req_form.open( "GET", $root+"/ajax/ajaxgetformsubscribeonelesson_azd.php?PHPSESSID="+$PHPSESSID+"&mat="+Math.random());
     http_req_form.setRequestHeader("Content-Type", "text/xml");
     http_req_form.onreadystatechange = gestisci_formlezione_azd;
     http_req_form .send(null);
     

}


function gestisci_subscribe_lesson_prof()
{

if ((http_req_subscribe.readyState==4) || (http_req_subscribe.readyState == "complete"))
		{
			
		    var xmlDoc= http_req_subscribe.responseXML.documentElement;
			try
			{
			var phpsessid = xmlDoc.getElementsByTagName("phpsessid").item(0).firstChild.data;  // Recupero il contenuto del messaggio da XML
			}
			
			catch(e) 
				{ 
				}
			
			var nome = xmlDoc.getElementsByTagName("nome").item(0).firstChild.data;
			$nome = stripslashes(nome);
			
			var cognome = xmlDoc.getElementsByTagName("cognome").item(0).firstChild.data;
		    $cognome = stripslashes(cognome);
		     
		   //alert(cognome);
		}
		
	    else 
		{
			//alert("loading");
		}






}


function set_subscribe_lezioni_dati($PHPSESSID,$number,$subject, $idprof_azd)
{

if ($idprof_azd)  {window.location = $root+"/index.php?PHPSESSID="+$PHPSESSID+"&page=addlesson&idprof="+$idprof_azd+"&number="+$number+"&nomelezione="+$subject+"";}
else {window.location = $root+"/index.php?PHPSESSID="+$PHPSESSID+"&page=addlesson&number="+$number+"&nomelezione="+$subject+"";}

}

function set_subscribe_corsi_dati($PHPSESSID,$number,$subject, $idprof_azd)
{
if ($idprof_azd)  {window.location = $root+"/index.php?PHPSESSID="+$PHPSESSID+"&page=addcourse&idprof="+$idprof_azd+"&number="+$number+"&nomelezione="+$subject+"";}
else {window.location = $root+"/index.php?PHPSESSID="+$PHPSESSID+"&page=addcourse&number="+$number+"&nomelezione="+$subject+"";}
}




function gestisci_formcorso()
{

if ((http_req_form.readyState==4) || (http_req_form.readyState == "complete"))
		{
			var output = http_req_form.responseText;
			output_lista = urldecode(output);
			document.getElementById('subprof_divdown').innerHTML = output;
		
		}
		
	    else 
		{
			 document.getElementById('subprof_divdown').innerHTML = "<p style=\"margin:15px\">Loading</p>";
		     document.getElementById('subprof_divdown').style.backgroundImage = "url("+$root+"/immagini/bg_bd_03.)";
		}

}

function gestisci_formcorso_azd()
{

if ((http_req_form.readyState==4) || (http_req_form.readyState == "complete"))
		{
			var output = http_req_form.responseText;
			output_lista = urldecode(output);
			document.getElementById('subprof_divdown').innerHTML = output;
			
			document.getElementById('bottone_ok').innerHTML = "<button style=\"width:80px; height:80px; font-size:21px;\" onclick=\"document.getElementById('form_iscrizioneprof').submit();\">OK</button>";
		
		}
		
	    else 
		{
			 document.getElementById('subprof_divdown').innerHTML = "<p style=\"margin:15px\">Loading</p>";
		     
		}

}


function set_subscribe_corsi($PHPSESSID)
{

     
     $stato_index = document.getElementById('select_stato').selectedIndex;
     $nazione = document.getElementById('select_stato').options[$stato_index].text;
     
     http_req_form = crea_http_req();
     http_req_form.open( "GET", $root+"/ajax/ajaxgetformsubscribeonecourse.php?PHPSESSID="+$PHPSESSID+"&nazione="+$nazione+"&mat="+Math.random());
     http_req_form.setRequestHeader("Content-Type", "text/xml");
     http_req_form.onreadystatechange = gestisci_formcorso;
     http_req_form .send(null);

}

function set_subscribe_corsi_azd($PHPSESSID)
{

     http_req_form = crea_http_req();
     http_req_form.open( "GET", $root+"/ajax/ajaxgetformsubscribeonecourse_azd.php?PHPSESSID="+$PHPSESSID+"&mat="+Math.random());
     http_req_form.setRequestHeader("Content-Type", "text/xml");
     http_req_form.onreadystatechange = gestisci_formcorso_azd;
     http_req_form .send(null);

}



function utf8_encode ( string ) {
   
    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}


function js_base64_encode(data) {
   
        
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, enc="", tmp_arr = [];
 
    if (!data) {
        return data;
    }
 
    data = utf8_encode(data+'');
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }
 
    return enc;
}



function js_serialize( mixed_value ) {
   
    var _getType = function( inp ) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {
            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';
            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();
            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];
                    break;
                }
            }
        }
        return type;
    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {
        case "function": 
            val = ""; 
            break;
        case "undefined":
            val = "N";
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");
            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":
            val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":
            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {
                    return;
                }
                objname[1] = serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }
            */
            var count = 0;
            var vals = "";
            var okey;
            var key;
            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }
                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += js_serialize(okey) +
                        js_serialize(mixed_value[key]);
                count++;
            }
            val += ":" + count + ":{" + vals + "}";
            break;
    }
    if (type != "object" && type != "array") {
      val += ";";
  }
    return val;

    
}

function rifiutastudentecorso($idstudente,$codcorso, $PHPSESSID, $idprof)
{
	
	http_req_rifiutastud= crea_http_req();
	http_req_rifiutastud.open( "GET", $root+"/ajax/ajaxrifiutastudentecorso.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&idstudente="+$idstudente+"&codcorso="+$codcorso+"&mat="+Math.random());
	http_req_rifiutastud.setRequestHeader("Content-Type", "text/xml");
	http_req_rifiutastud.onreadystatechange = gestisci_rifiutastudente_corso;
	http_req_rifiutastud.send(null);
	
	
}


function gestisci_rifiutastudente()
{

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

			
			if (error == "NO")
			{
			
			if ($idprof) DisplayLessonAzd('0',$sessionid, $codelesson_actual, $idprof,"LEZIONE");
			else  DisplayLesson('0',$sessionid, $codelesson_actual, "LEZIONE");
			}
		
		}
		
	    else 
		{
			
		}

}

function gestisci_rifiutastudente_corso()
{

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

			
			if (error == "NO")
			{
			
			if ($idprof) DisplayLessonAzd('0',$sessionid, $codelesson_actual, $idprof,"CORSO");
			else  DisplayLesson('0',$sessionid, $codelesson_actual,"CORSO");
			}
		
		}
		
	    else 
		{
			
		}

}


function gestisci_accettastudente()
{

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

			if (error == "NO")
			{
		    
			if ($idprof) DisplayLessonAzd('0',$sessionid, $codelesson_actual, $idprof,"LEZIONE");
			else DisplayLesson('0',$sessionid, $codelesson_actual,"LEZIONE");
			}
		
		}
		
	    else 
		{
			
		}

}

function gestisci_accettastudente_corso()
{

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

			if (error == "NO")
			{
		    
			if ($idprof) DisplayLessonAzd('0',$sessionid, $codelesson_actual, $idprof, "CORSO");
			else DisplayLesson('0',$sessionid, $codelesson_actual,"CORSO");
			}
		
		}
		
	    else 
		{
			
		}

}



function accettastudentecorso($idstudente,$codcorso, $sessiond, $idprof)
{
	
		http_req_confermastud= crea_http_req();
		http_req_confermastud.open( "GET", $root+"/ajax/ajaxconfermastudentecorso.php?PHPSESSID="+$sessionid+"&idprof="+$idprof+"&idstudente="+$idstudente+"&codcorso="+$codcorso+"&mat="+Math.random());
		http_req_confermastud.setRequestHeader("Content-Type", "text/xml");
		http_req_confermastud.onreadystatechange = gestisci_accettastudente_corso;
		http_req_confermastud.send(null);
	
	
}

function Test()
{
//alert("ciao");
}


function gestisci_display_areamessaggi()
{

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

}


function GetAreaMessaggiForLesson($codicelezione, $sessionid)
{

    http_req_messaggi = crea_http_req();
	http_req_messaggi.open( "GET", $root+"/ajax/ajaxdisplayareamessaggilezione.php?PHPSESSID="+$sessionid+"&codicelezione="+$codicelezione+"&id="+Math.random());
	http_req_messaggi.setRequestHeader("Content-Type", "text/html");
	http_req_messaggi.onreadystatechange = gestisci_display_areamessaggi;
	http_req_messaggi.send(null);

}


function GetAreaMessaggiForLessonAzd($codicelezione, $sessionid, $idprof)
{

    http_req_messaggi = crea_http_req();
	http_req_messaggi.open( "GET", $root+"/ajax/ajaxdisplayareamessaggilezione.php?PHPSESSID="+$sessionid+"&codicelezione="+$codicelezione+"&idprof="+$idprof+"&id="+Math.random());
	http_req_messaggi.setRequestHeader("Content-Type", "text/html");
	http_req_messaggi.onreadystatechange = gestisci_display_areamessaggi;
	http_req_messaggi.send(null);

}





function GetAreaMessaggiForCorsi($codicelezione, $sessionid)
{
								
	http_req_messaggi = crea_http_req();
	http_req_messaggi.open( "GET", $root+"/ajax/ajaxdisplayareamessaggicorsi.php?PHPSESSID="+$sessionid+"&codicelezione="+$codicelezione+"&id="+Math.random());
	http_req_messaggi.setRequestHeader("Content-Type", "text/html");
	http_req_messaggi.onreadystatechange = gestisci_display_areamessaggi;
	http_req_messaggi.send(null);
	
	//alert("siamo qui");

}

function InviaMessaggioCorso($phpsessid, $idprofessore, $idstudente, $codcorso)
{
		
				
		$list_index = document.getElementById("mylist").selectedIndex;
                $idstudente = document.getElementById('mylist').options[$list_index].value;
		
		
		if ($idstudente!='allselected')
		{
		invia_messaggio_forinfo($phpsessid, $idprofessore, $idstudente)	;		
		}
		
		if ($idstudente=='allselected')
		{
					
		invia_messaggio_tutti($phpsessid, $idprofessore, $codcorso);
				
		}
		
		
}

function check_icon_az($icon)
{

if ($icon == "0")
	{
	document.getElementById('cbx_aziende_no').checked="";
	document.getElementById('cbx_aziende_si').checked="checked";
	}
if ($icon == "1")
	{
	document.getElementById('cbx_aziende_si').checked="";
	document.getElementById('cbx_aziende_no').checked="checked";
	}


}



function gestisci_controllo_aziende()
{

  if ((http_req_exemail.readyState==4) || (http_req_exemail.readyState == "complete"))
	
	    {		
	    var xmlDoc= http_req_exemail.responseXML.documentElement;
	    var $errore = xmlDoc.getElementsByTagName("errore").item(0).firstChild.data;
            var $esistente = xmlDoc.getElementsByTagName("esistente").item(0).firstChild.data;
            var $email = xmlDoc.getElementsByTagName("email").item(0).firstChild.data;
	    var $controlloprovincia = xmlDoc.getElementsByTagName("controlloprovincia").item(0).firstChild.data;
	    var $controllocitta = xmlDoc.getElementsByTagName("controllocitta").item(0).firstChild.data;
	    

	        if ($controlloprovincia != "OK")  { document.getElementById('label_provincia').style.backgroundColor = 'red';}
		if ($controlloprovincia == "OK")
		
		
		{
		document.getElementById('label_provincia').style.backgroundColor = '';
		
		
		
		}
	
	        
	     
	    }
	    
            
            else
            {
                
		     
            }
	    
        }
	
    

function SwapSuRecuperoDati($position)
{
if ($position == "on") document.getElementById('Recupero_Dati').style.backgroundImage="url('"+$root+"/immagini/recupera_dati_su.jpg')";
if ($position == "off") document.getElementById('Recupero_Dati').style.backgroundImage="url('"+$root+"/immagini/recupera_dati.jpg')";
}




function gestisci_listaregioni()
{

if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
		{		
		var $output = http_req_listaregioni.responseText;
		document.getElementById('div_regioni').innerHTML = ""+$output+"";
		}
		
	    else 
		{
			
		}

}


function UploadListaRegioniForDati($select_regioni)
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&select="+$select_regioni+"&id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni;
    http_req_listaregioni.send(null);
    

    
}



function UploadListaRegioni()
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    if ($stato=="Italia") // QUI CI SONO GLI STATI PER CUI IL CAMPO PROVINCIA E' ABILITATO
    {
    document.getElementById('lista_province').disabled = "";
    document.getElementById('label_provincia').style.color = "black";
    
    http_req_listaprovince = crea_http_req();
    http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetlistaprovince.php?&stato="+$stato+"&regione=FirstRegion&id="+Math.random());
    http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
    http_req_listaprovince.onreadystatechange = gestisci_listaprovince;
    http_req_listaprovince.send(null);
    }
    
    else  // QUI CI SONO GLI STATI PER CUI IL CAMPO PROVINCIA E' DISABILITATO
    {
    document.getElementById('lista_province').innerHTML = "";
    document.getElementById('lista_province').disabled = "disabled";
    document.getElementById('label_provincia').style.color = "grey";  
    } 
     
    
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni;
    http_req_listaregioni.send(null);
    
}

function gestisci_listaprovince()
{

if ((http_req_listaprovince.readyState==4) || (http_req_listaprovince.readyState == "complete"))
		{		
			
		
		
		
		var output = http_req_listaprovince.responseText;
		
		document.getElementById('div_province').disabled="";
		document.getElementById('div_province').innerHTML = output;
    	
	    
		//document.getElementById('div_province').outerHTML = document.getElementById('lista_province').outerHTML;
				
		}
		
	    else 
		{
			
		}

}


function UploadListaProvinceForDati($stato, $regione, $provincia, $select_provincia)
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    if ($stato != "Italia")
    {
	
	document.getElementById('lista_province').innerHTML = "<option></option>";
	document.getElementById('lista_province').disabled = "disabled";
	document.getElementById('label_provincia').style.color = "grey";
	document.getElementById('lista_province').selectedIndex=0;
    
    }
    
    else
    {
	
	if (!$regione) $regione="Abruzzo";
	
	http_req_listaprovince = crea_http_req();
	http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetlistaprovince.php?&stato="+$stato+"&regione="+$regione+"&select="+$select_provincia+"&opt_tutte=OFF&id="+Math.random());
	http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
	http_req_listaprovince.onreadystatechange = gestisci_listaprovince;
	http_req_listaprovince.send(null);
    }
    
    
}


function UploadListaProvinceForOfferta($stato, $regione, $select)
{
    
    
    
    
    if ($regione=="Tutte") document.getElementById('lista_province').disabled="disabled";
    
    if (($regione!="")&&($regione!="Tutte"))
    {
	    
    http_req_listaprovince = crea_http_req();
    http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetlistaprovince.php?&stato="+$stato+"&regione="+$regione+"&select="+$select+"&opt_tutte=On&id="+Math.random());
    http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
    http_req_listaprovince.onreadystatechange = gestisci_listaprovince;
    http_req_listaprovince.send(null);
    }
    
    if (($regione!="")&&($regione!="Tutte"))
    {
    //http_req_listacitta = crea_http_req();
    //http_req_listacitta.open( "GET", $root+"/ajax/ajaxgetlistacitta.php?&stato="+$stato+"&regione="+$regione+"&provincia=FirstProvincia&id="+Math.random());
    //http_req_listacitta.setRequestHeader("Content-Type", "text/html");
    //http_req_listacitta.onreadystatechange = gestisci_listacitta;
    //http_req_listacitta.send(null);
    }
    
    
    
    
    
}







function UploadListaProvince($stato, $regione)
{
    
    if (($regione!="")&&($regione!="Tutte"))
    {
    http_req_listaprovince = crea_http_req();
    http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetlistaprovince.php?&stato="+$stato+"&regione="+$regione+"&id="+Math.random());
    http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
    http_req_listaprovince.onreadystatechange = gestisci_listaprovince;
    http_req_listaprovince.send(null);
    }
    
    if (($regione!="")&&($regione!="Tutte"))
    {
    //http_req_listacitta = crea_http_req();
    //http_req_listacitta.open( "GET", $root+"/ajax/ajaxgetlistacitta.php?&stato="+$stato+"&regione="+$regione+"&provincia=FirstProvincia&id="+Math.random());
    //http_req_listacitta.setRequestHeader("Content-Type", "text/html");
    //http_req_listacitta.onreadystatechange = gestisci_listacitta;
    //http_req_listacitta.send(null);
    }
    
    
    
    
    
}



function gestisci_listacitta()
{
    
    if ((http_req_listacitta.readyState==4) || (http_req_listacitta.readyState == "complete"))
		{		
			
		var output = http_req_listacitta.responseText;
		document.getElementById('div_citta').innerHTML = output;
		
		AttivazioneCittaForOfferta(); 
		
	    
		}
		
	    else 
		{
			
		}
        
}


function UploadListaCittaForOfferta($stato, $regione, $provincia, $select_citta)
{
    		
	if (!$stato) 
	{
	$stato_index = document.getElementById('select_stato').selectedIndex;
	$stato = document.getElementById('select_stato').options[$stato_index].text;
	}
	
	if (!$regione)
	{
	$regione_index = document.getElementById('lista_regioni').selectedIndex;
	$regione = document.getElementById('lista_regioni').options[$regione_index].text;
	}
	
	if (!$provincia)
	{
	    $province_index = document.getElementById('lista_province').selectedIndex;
	    $provincia = document.getElementById('lista_province').options[$province_index].text;
	}
	
	http_req_listacitta = crea_http_req();
        http_req_listacitta.open( "GET", $root+"/ajax/ajaxgetlistacitta.php?&stato="+$stato+"&regione="+$regione+"&provincia="+$provincia+"&select="+$select_citta+"&opt_tutte=On&id="+Math.random());
        http_req_listacitta.setRequestHeader("Content-Type", "text/html");
        http_req_listacitta.onreadystatechange = gestisci_listacitta;
        http_req_listacitta.send(null);
}


function UploadListaCitta($stato, $regione)
{
	http_req_listacitta = crea_http_req();
        http_req_listacitta.open( "GET", $root+"/ajax/ajaxgetlistacitta.php?&stato="+$stato+"&regione="+$regione+"&id="+Math.random());
        http_req_listacitta.setRequestHeader("Content-Type", "text/html");
        http_req_listacitta.onreadystatechange = gestisci_listacitta;
        http_req_listacitta.send(null);
}


function GetChangeRegione($select)
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;
    
    if ($stato == "Italy")
    {
	UploadListaProvince($stato, $regione);
    }
    
    else
    {
	
	UploadListaCitta($stato, $regione);
    }
    
    
    
}


function GetChangeRegioneForOfferta($select_provincia, $select_citta)
{
    
    
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;
    
    if ($stato == "Italia")
    {
	UploadListaProvinceForOfferta($stato, $regione, $select_provincia);
    }
    
    else
    {
	
	UploadListaCittaForOfferta($stato, $regione,'', $select_citta);
    }
    
    
    
}

function GetChangeRegioneForDati($select_provincia)
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;
    
    
    if ($stato=="Italia")
    {	
	http_req_listaprovince = crea_http_req();
	http_req_listaprovince.open( "GET", $root+"/ajax/ajaxgetlistaprovince.php?&stato="+$stato+"&regione="+$regione+"&select="+$select_provincia+"&opt_tutte=OFF&id="+Math.random());
	http_req_listaprovince.setRequestHeader("Content-Type", "text/html");
	http_req_listaprovince.onreadystatechange = gestisci_listaprovince;
	http_req_listaprovince.send(null);
    }
    

}


function IscrizioneProfInternational()
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    if ($stato != "Italia")
    {
	document.getElementById("label_provincia").innerHTML="*Regione";
	document.getElementById("label_provincia").style.backgroundColor="";
	GetListaRegioniForProf();
	
    }
    
    if ($stato == "Italia")
    {
	document.getElementById("label_provincia").innerHTML="*Prov";
	document.getElementById('campo_provincia').innerHTML = "<input name=\"provincia\" id=\"provincia\" type=\"text\" size=\"2\" maxlength=\"2\"  style=\" margin-left:2px; width:35px; height:17px;\" />";
    }
    
    GetCurrency($stato);
    
}


function gestisci_listaregioni_prof()
{
    if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
		{			
		var output = http_req_listaregioni.responseText;
		document.getElementById('campo_provincia').innerHTML = "<select id=\"regione\" name=\"regione\" style=\"width:145px; height:22px;\">"+output+"</select>";		
		}
	    else 
		{
		
		}
    
}


function GetListaRegioniForProf()
{
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni_prof;
    http_req_listaregioni.send(null);
}


function gestisci_listaregioni_materie()
{
    if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
		{			
		var output = http_req_listaregioni.responseText;
		document.getElementById('campo_regioni').innerHTML = output;		
		}
	    else 
		{
		
		}
    
}

function GetListaRegioniForMaterie($select)
{
        
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&select="+$select+"&opt_tutte=On&id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni_materie;
    http_req_listaregioni.send(null);
}


function gestisci_listaregioni_offerta()
{
    if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
		{			
		var output = http_req_listaregioni.responseText;
		document.getElementById('div_regioni').innerHTML = output;
		//GetListaRegioniForOfferta();
		
		}
	    else 
		{
		
		}
    
}

function gestisci_listaregioni_dati()
{
    if ((http_req_listaregioni.readyState==4) || (http_req_listaregioni.readyState == "complete"))
		{			
		var output = http_req_listaregioni.responseText;
		document.getElementById('lista_regioni').innerHTML = output;
		//GetListaRegioniForOfferta();
		
		}
	    else 
		{
		
		}
    
}


function GetListaRegioniForOfferta($select)
{

    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&select="+$select+"&opt_tutte=On&id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni_offerta;
    http_req_listaregioni.send(null);
}

function GetListaRegioniForDati($sessionid)
{
        
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
        
    http_req_listaregioni = crea_http_req();
    http_req_listaregioni.open( "GET", $root+"/ajax/ajaxgetlistaregioni.php?&stato="+$stato+"&opt_tutte=Off&opt_dati=On&sessionid="+$sessionid+"id="+Math.random());
    http_req_listaregioni.setRequestHeader("Content-Type", "text/html");
    http_req_listaregioni.onreadystatechange = gestisci_listaregioni_dati;
    http_req_listaregioni.send(null);
}





function AttivazioneProvinceForOfferta()
{
    
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    $regione_index = document.getElementById('lista_regioni').selectedIndex;
    $regione = document.getElementById('lista_regioni').options[$regione_index].text;
    
    
    if (($stato == "Italia")&&($regione!="Tutte"))
    {
    document.getElementById('lista_province').disabled="";
    }
    
    
    else
    {
	
    document.getElementById('lista_province').disabled="disabled";
    document.getElementById('lista_province').selectedIndex = "0";
    }
}



function AttivazioneCittaForOfferta()
{
        
    $stato_index = document.getElementById('select_stato').selectedIndex;
    $stato = document.getElementById('select_stato').options[$stato_index].text;
    
    $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 (($stato != "Italia")&&($regione!="Tutte"))
    {
    document.getElementById('lista_citta').disabled="";
    }
    
    else if (($stato != "Italia")&&($regione=="Tutte"))
    {
    document.getElementById('lista_citta').disabled="Disabled";
    }
    
    else if (($stato == "Italia")&&($regione=="Tutte"))
    {
    document.getElementById('lista_citta').selectedIndex=0;
    document.getElementById('lista_citta').disabled="Disabled";
    }
    
    else if (($stato == "Italia")&&($regione!="Tutte"))
    {
	
    if ($provincia == "Tutte")
	{
	    document.getElementById('lista_citta').disabled="Disabled";
	}
	
	else
	{
	    document.getElementById('lista_citta').disabled="";
	    
	}
    
    
    
    }
    
}



function DisattivazioneCitta()
{
  document.getElementById('lista_citta').selectedIndex = 0;
  document.getElementById('lista_citta').disabled="Disabled";
}


function DisattivazioneProvincia()
{
    document.getElementById('lista_province').selectedIndex = 0;
    document.getElementById('lista_province').disabled="Disabled";   
}


function gestisci_currency()
{
    
    if ((http_req_currency.readyState==4) || (http_req_currency.readyState == "complete"))
		{			
		var output = http_req_currency.responseText;
		try {document.getElementById('currency').innerHTML = output;} catch (e1) {}
		//GetListaRegioniForOfferta();
		
		}
	    else 
		{
		
		}
    
    
}

function GetCurrency($nazione)
{
    
    http_req_currency = crea_http_req();
    http_req_currency.open( "GET", $root+"/ajax/ajaxgetcurrency.php?&nazione="+$nazione+"&id="+Math.random());
    http_req_currency.setRequestHeader("Content-Type", "text/html");
    http_req_currency.onreadystatechange = gestisci_currency;
    http_req_currency.send(null);
}
