var xmlhttp, xmlricerca;
var camporichiesta='';
var cambio=false;
var suggeridiv=false;
var ubicazione='';
var testoautocert=0;
var altezzacerca=0;
var timero;
var page = "economia.asp?contenuto=testochat";
var req,testo,sessione,cercastud,cercaoggetto,vedisched,cercaquest,infosched,unosched;
var cercapdf,currisched,chatutenti,chatnuova,chatpdf,allerta=0,chatta,xmlreport,xmlappunti;

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function correggi(testo) {
	var i, corretto="";
	if (testo.length>0) {
		for (i = 0; i<testo.length;i++) {
			lettera = testo.charCodeAt(i);
			switch (lettera) {
				case 38:
					corretto += "$$amp;";
					break;
				case 224:
					corretto += "$$agrave;";
					break;
				case 225:
					corretto += "$$aacute;";
					break;
				case 232:
					corretto += "$$egrave;";
					break;
				case 233:
					corretto += "$$eacute;";
					break;
				case 236:
					corretto += "$$igrave;";
					break;
				case 237:
					corretto += "$$iacute;";
					break;
				case 242:
					corretto += "$$ograve;";
					break;
				case 243:
					corretto += "$$oacute;";
					break;
				case 249:
					corretto += "$$ugrave;";
					break;
				case 250:
					corretto += "$$uacute;";
					break;
				case 39:
					corretto += "''";
					break;
				default:
					corretto += testo.charAt(i);
			}
		}
		return corretto;
	}
	else
		return testo;
}

function stripHTML(testo){
	if(testo!='') {
		var re = /(<([^>]+)>)/gi;
		var nuovotesto;
		nuovotesto=testo.replace(re, "");
		return nuovotesto;
	}
	else
		return '';
}

function isEmail( text )
{
	var pattern = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp( pattern );
	return regex.test( text );
}

function isDate(txtDate){  
   var objDate;  // date object initialized from the txtDate string  
   var mSeconds; // milliseconds from txtDate  
   
   if (txtDate.length != 10) return false;  
   var day   = txtDate.substring(3,5)  - 0;  
   var month = txtDate.substring(0,2)  - 1; // because months in JS start with 0  
   var year  = txtDate.substring(6,10) - 0;  
   
   if (txtDate.substring(2,3) != '/') return false;  
   if (txtDate.substring(5,6) != '/') return false;  
   
   if (year < 999 || year > 3000) return false;  
   
   mSeconds = (new Date(year, month, day)).getTime();  
   
   objDate = new Date();  
   objDate.setTime(mSeconds);  
   
   if (objDate.getFullYear() != year)  return false;  
   if (objDate.getMonth()    != month) return false;  
   if (objDate.getDate()     != day)   return false;  
   
   return true;  
}  

function vedilogin(forma) {
	if (forma.nomeutente.value=="" || forma.pazzword.value=="") {
		alert("Inserire username e password di Dominio");
		return false;
	}
	else
		return true;
}

function editapagina() {
	document.getElementById('editapagina').style.display='';
	document.getElementById('contenutopagina').style.display='none';
}

function recuperatesto() {
	//document.getElementById('testo').value=document.getElementById('testo').value.toLowerCase();
	document.getElementById('testo').value="pippo";
	//alert(document.getElementById('testo___Frame').text);
}

function verificautente(campo,auth) {
	var testo=campo.value;
	if (auth) {
		if (testo.indexOf('.')>=0)
			document.getElementById('domiseletto').value="studenti";
		else
			document.getElementById('domiseletto').value="personale";
	}
	else {
		if (testo.indexOf('.')>=0)
			document.getElementById('radiostude').checked=true;
		else
			document.getElementById('radioperso').checked=true;
	}
}

function controllamail(forma) {
	var rispo=true;
	if (!isEmail(forma.email1.value)) {
		alert("Email non valida");
		rispo=false;
	}
	else
		if (forma.email1.value != forma.email2.value) {
			alert("Le due email non coincidono");
			rispo=false;
		}
	return rispo;
}

function apri_pagina(lung,pagina,larg,id) {
	var wleft = (screen.width - larg) / 2;
	var wtop = (screen.height - lung) / 2;
   
	if (id != 0) 
		parametro = '&id' + id;
	else
		parametro = '';
	window.open(pagina + parametro,'nuova' + id,'width=' + larg + ',height=' + lung + ',top=' + wtop + ',left=' + wleft + ',resizable=no,scrollbars=yes,toolbar=no,location=no,menubar=no')
}

function aprichiudi(elemento) {
	//alert (document.getElementById(elemento).style.display);
	if (document.getElementById(elemento).style.display=="none") {
		document.getElementById(elemento).style.display="";
	} else {
		document.getElementById(elemento).style.display="none";
	}
}

function conferma(operazione) {
	var answer = confirm ('Confermi l\'operazione '+operazione+' ?');
	if (answer)
		return true;
	else
		return false;
}

function check_submit(form) {
	if (form.id.value=="" || isNaN(form.id.value)) {
		form.id.focus();
		return false;
	}
}

function check_lezioni(form) {
	if (form.id_form.value=="" || isNaN(form.id_form.value)) {
		alert("Selezionare un insegnamento!");
		form.id_form.focus();
		return false;
	}
}

/* ** GESTIONE NEWS * */
function valida_oggetto(testo) {
	var url="economia.asp?contenuto=validazioni&ambito=oggetto&chiavi="+document.getElementById('parolechiave').value+"&testo="+testo.value;
	//document.getElementById('oggettovalido').innerHTML = "validazione in corso..";
	testo.style.backgroundColor='white';
	if (window.XMLHttpRequest) {
		cercaoggetto = new XMLHttpRequest();
		cercaoggetto.onreadystatechange = function() {risultaoggetto(testo);};
		cercaoggetto.open("GET", url, true);
		cercaoggetto.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercaoggetto = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercaoggetto) {
			cercaoggetto.onreadystatechange = function() {risultaoggetto(testo);};
			cercaoggetto.open("GET", url, true);
			cercaoggetto.send();
		}
	}
}

function risultaoggetto(testo) {
	if (cercaoggetto.readyState == 4) {
		if (cercaoggetto.status == 200 || cercaoggetto.status == 304) {
			document.getElementById('oggettovalido').innerHTML = cercaoggetto.responseText;
			if (document.getElementById('validita')!=null && !document.getElementById('validazione').checked) {
				valido=parseInt(document.getElementById('validita').value);
				if (valido<=60) {
					if (testo.value.length>10) 
						document.getElementById('oggettovalido').style.display='';
					document.getElementById('summittanews').disabled=true;
				}
				else {
					document.getElementById('oggettovalido').style.display='none';
					document.getElementById('summittanews').disabled=false;
				}
			}
			else
				document.getElementById('summittanews').disabled=false;
		} else {
			document.getElementById('oggettovalido').innerHTML=cercaoggetto.responseText;
		}
	}
}

function check_news(forma) {
	var nomecampo;
	var risulta=true;
	if (document.getElementById('validita')!=null && !forma.validazione.checked) {
		valido=parseInt(document.getElementById('validita').value);
		if (valido<=60) {
			forma.oggetto.focus();
			forma.oggetto.style.backgroundColor='yellow';
			risulta=confirm("L\'OGGETTO non risulta fruibile.\nSi consiglia di includere ad es. il nome del docente e/o dell\'insegnamento interessato.");
		}
	}
	if (risulta) {
		var oEditor = FCKeditorAPI.GetInstance('testo') ;
		if (oEditor.GetData()=="") {
			alert("E\' richiesto un valore per il campo \'testo\'!");
			oEditor.Focus();
			risulta=false;
		}
		else
			for (i=0, n=forma.elements.length; i < n; i++) {
				nomecampo=forma.elements[i].name;
				if (nomecampo=='oggetto' || nomecampo=='ambito')
					if (forma.elements[i].value=="") {
						alert('E\' richiesto un valore per il campo \''+nomecampo+'\'');
						forma.elements[i].focus();
						risulta=false;
						break;
					}
			}
		if (risulta) {
			var myDate=new Date();
			myDate.setFullYear(forma.a_scadenza.value,forma.m_scadenza.value-1,forma.g_scadenza.value);
			// if (isDate(forma.m_scadenza.value+'/'+forma.g_scadenza.value+'/'+forma.a_scadenza.value)) *** EV.VERIFICA CORRETTEZZA DATA ***
			var today=new Date();
			if (myDate<today) {
				alert("ATTENZIONE\nNon e\' possibile indicare una scadenza con data trascorsa");
				risulta=false;
			}
		}
	}
	return risulta;
}

function check_ricerca(form,cerca) {
	if (form.ecocerca.value == "" || form.ecocerca.value==cerca) {
		form.ecocerca.focus();
		return false;
	}
}

function check_cerca(testo,cerca) {
	if (testo.value=='') {
		testo.value=cerca;
		document.getElementById('ecocerca').style.backgroundColor='white';
	} else
		if (testo.value==cerca)
			testo.value='';
	if (!suggeridiv) {
		document.getElementById('suggerimenti').style.display='none';
		document.getElementById('veditrova').style.display='none';
		document.getElementById('suggeritrova').style.display='none';
		document.getElementById('suggeriombra').style.display='none';
	}
}

function aggiorna_cerca(testo) {
	document.getElementById('ecocerca').value=testo;
	document.getElementById('formacerca').submit();
}

function sopradiv() {
	suggeridiv=true;
	document.getElementById('ecocerca').focus();
}

function fuoridiv() {
	suggeridiv=false;
	altezzacerca=0;
	document.getElementById('ecocerca').style.backgroundColor='white';
}

function check_simili(testo,event) {
	var count;
	var testi;
	if((event.keyCode>=37 && event.keyCode<=40) && xmlhttp.readyState==4) {
		var testosugge=document.getElementById('suggerimenti').innerHTML.toLowerCase();
		var memosugge=document.getElementById('memosugge').innerHTML.toLowerCase();
		if(event.keyCode==38) {
			if (altezzacerca>0) {
				altezzacerca--;
				document.getElementById('veditrova').style.display='none';
				document.getElementById('suggeritrova').style.display='none';
				document.getElementById('suggeriombra').style.display='none';
			}
			if (altezzacerca==0) {
				testo.value=document.getElementById('memotesto').innerHTML;
			}
		}
		if (event.keyCode==40) {
			if (testosugge!='') {
				testi=testosugge.split("<br>");
				count=testi.length-1;
				if (altezzacerca<count) {
					altezzacerca++;
					document.getElementById('veditrova').style.display='none';
					document.getElementById('suggeritrova').style.display='none';
					document.getElementById('suggeriombra').style.display='none';
				}
			}
			else count=0;
		} 
		if (altezzacerca>0) {
			testi=memosugge.split("<br>");
			var nuovotesto='';
			for (riga in testi) {
				if(testi[riga].length>0) {
					if ((altezzacerca-1)==riga) {
						nuovotesto += "<span style=\"background-color:#A4A6FE\">"+testi[riga]+"</span><br>";
						testo.value=stripHTML(testi[riga]);
						var contatoppo=46+((riga-1)*18);
						document.getElementById('veditrova').style.top=contatoppo+'px';
						document.getElementById('veditrova').style.display='';
					}
					else
						nuovotesto += testi[riga]+"<br>";
				}
			}
			document.getElementById('suggerimenti').innerHTML=nuovotesto;
			if (event.keyCode==39) {
				document.getElementById('suggeritrova').style.top=contatoppo+'px';
				document.getElementById('suggeritrova').innerHTML='cerco..';
				document.getElementById('suggeritrova').style.display='';
				document.getElementById('suggeriombra').style.top=(contatoppo+5)+'px';
				document.getElementById('suggeriombra').innerHTML='&nbsp;';
				document.getElementById('suggeriombra').style.display='';
				vedirisultati(testo.value);
			}
			if (event.keyCode==37) {
				document.getElementById('suggeritrova').style.display='none';
				document.getElementById('suggeriombra').style.display='none';
			}
		}
		else {
			if (testosugge!='') {
				document.getElementById('ecocerca').style.backgroundColor='#DFE0FD';
				document.getElementById('suggerimenti').innerHTML=memosugge;
			}
		}
	}
	else {
		if (event.KeyCode!=13) {
			document.getElementById('veditrova').style.display='none';
			document.getElementById('suggeritrova').style.display='none';
			document.getElementById('suggeriombra').style.display='none';
			altezzacerca=0;
			document.getElementById('memotesto').innerHTML=testo.value;
			//document.getElementById('memosugge').innerHTML=document.getElementById('suggerimenti').innerHTML;

			xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null) {
			  alert ("Your browser does not support XMLHTTP!");
			  return;
			}
			
			var path="?contenuto=suggerimento&ritesto="+document.getElementById('memotesto').innerHTML+"&altezza="+altezzacerca;
			//document.getElementById('suggerimenti').innerHTML='';
			xmlhttp.onreadystatechange=cercaParole;
			xmlhttp.open("GET",path,true);
			xmlhttp.send(null);
		}
	}
}

function cercaParole() {
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		document.getElementById('suggerimenti').innerHTML=xmlhttp.responseText;
		document.getElementById('memosugge').innerHTML=xmlhttp.responseText;
		var testosugge=document.getElementById('suggerimenti').innerHTML.toLowerCase();
		if (testosugge!='') {
			document.getElementById('suggerimenti').style.display='block';
		}
	}
	else {
		if (document.getElementById('suggerimenti').innerHTML!='')
			document.getElementById('suggerimenti').innerHTML="<i>ricerca in corso...</i><br>"+document.getElementById('memosugge').innerHTML;
	}	
}

function vedirisultati(provatesto) {
	xmlricerca=GetXmlHttpObject();
	if (xmlricerca==null) {
	  alert ("Your browser does not support xmlricerca!");
	  return;
	}
	var path="?contenuto=suggerimento&ecocerca="+provatesto;
	xmlricerca.onreadystatechange=cercaRisultati;
	xmlricerca.open("GET",path,true);
	xmlricerca.send(null);

}

function cercaRisultati() {
	if (xmlricerca.readyState==4 && xmlricerca.status==200) {
		document.getElementById('suggeritrova').innerHTML=xmlricerca.responseText;
	}
	else {
		document.getElementById('suggeritrova').innerHTML="cerco risultati..";
	}	
}

function check_doc(forma) {
	var ritorna=true;
	if (forma.titolo.value == "") {
		alert("ATTENZIONE! Indicare il titolo/link del materiale");
		forma.titolo.focus();
		ritorna=false;					
	}
	if (document.getElementById('linkest').style.display!='none') { // FILE REMOTO
		var patho=forma.pathremoto.value;
		if (patho.length==0) {
			// if (forma.task.value!='fineaggiornadoc') 
			alert("Indicare il path completo del file remoto (\'http:\/\/ ...\')");
			forma.pathremoto.focus();
			ritorna=false;
		} 
		else {
			if (path.indexOf(' ')!=-1) {
				alert("ATTENZIONE! Il link remoto non puo\' contenere spazi");
				ritorna=false;
			} 
			else {
				var estens=patho.substr(patho.length-4,4);
				var inizio=patho.substr(0,4);
				if (inizio!='http') {
					alert("ATTENZIONE! Indicare un link completo (i.e. \'http:\/\/ ...\')");
					forma.pathremoto.focus();
					ritorna=false;
				} 
				else
					if (estens!='.pdf') {
						var answer=confirm ("E\' sconsigliabile linkare file diversi dal PDF. Procedere ugualmente?");
						if (!answer) {
							forma.pathremoto.focus();
							ritorna=false;
						}
					}
			}
		}
	}
	else 
		if (document.getElementById('estens').style.display!='none') { // FILE LOCALE (UPLOAD)
			if (forma.task.value!='fineaggiornadoc')
				if (forma.attach1.value=="") {
					alert("E\' necessario selezionare un file per l\'upload");
					ritorna=false;
				}
		}
	if (ritorna) {
		if (conferma("")) {
			ritorna=true;
			var radios = forma.ubica;
			for (var i=0; i < radios.length; i++)
				if (radios[i].checked)
					forma.action=forma.action+'&remoto='+radios[i].value;
		}
		else
			ritorna=false;
	}
	else
		ritorna=false;
	return ritorna;
}

function eccez(primodiv, secondodiv, bool) {
	if (bool) {
		document.getElementById(primodiv).style.display = '';
		document.getElementById(secondodiv).style.display = 'none';
	}
	else {
		document.getElementById(primodiv).style.display = 'none';
		document.getElementById(secondodiv).style.display = '';
	}
}

function eccemateriale() {
	//var radios = document.forma.radio;
	var radios = document.formdoc.ubica;
	var ceccato=false;
	for (var i=0; i < radios.length; i++)
		if (radios[i].checked) {
			document.getElementById(radios[i].value).style.display = '';
			ubicazione=radios[i].value;
			ceccato=true;
		}
		else
			document.getElementById(radios[i].value).style.display='none';
	if (ceccato) document.formdoc.submitta.disabled=false;
}

function cerca_materiale(codice) {
	var path="tipo=materiale&insegnamento="+codice;

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	xmlhttp.onreadystatechange=materialeChanged;
	xmlhttp.open("GET","xml_content.asp?"+path,true);
	xmlhttp.send(null);	
}

function materialeChanged() {
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//alert(xmlhttp.responseText);
		document.getElementById('xmlmateriale').innerHTML=xmlhttp.responseText;
	}
}

/** RICHIESTE TESI **/
function procedicorso(partecipa) {
	if (partecipa=='partecipasi') {
		document.getElementById('partecipacorso').style.display='none';
		document.getElementById('vedicrediti').style.display='';
	}
	else {
		if (document.getElementById('corsattivo').value=='true') {
			document.getElementById('partecipacorso').style.display='';
			document.getElementById('vedicrediti').style.display='none';
			document.getElementById('sceltaesa').style.display='none';
			document.getElementById('sceltadoc').style.display='none';
			document.getElementById('conferma').disabled=true;
		}
		else
			document.getElementById('partecipacorso').style.display='';

	}	
}

function annullarichiesta(idrichiesta) {
	rispa=confirm('Sei sicuro di voler annullare la richiesta corrente?\nSarai tenuto a compilarne una nuova e per un diverso docente.');
	if (rispa)
		location.href='?contenuto=richiestatesi&annulla=true&idrichiesta='+idrichiesta;
}

function reportesi(anno) {
	var url="?contenuto=reportesi&anno="+anno;
	document.getElementById('divreport').style.display='';
	document.getElementById('divreport').innerHTML = "recupero dati in corso..";
	if (window.XMLHttpRequest) {
		cercaquest = new XMLHttpRequest();
		cercaquest.onreadystatechange = function() {risultareport();};
		cercaquest.open("GET", url, true);
		cercaquest.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercaquest = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercaquest) {
			cercaquest.onreadystatechange = function() {risultareport();};
			cercaquest.open("GET", url, true);
			cercaquest.send();
		}
	}
}

function risultareport() {
	if (cercaquest.readyState == 4) {
		if (cercaquest.status == 200 || cercaquest.status == 304) {
			document.getElementById('divreport').innerHTML = cercaquest.responseText;
		} else {
			document.getElementById('divreport').innerHTML=cercaquest.responseText;
		}
	}
}

function cerca_insegnamenti(codice,admin) {
	var path="docente="+codice;
	if (!admin)
		document.getElementById('conferma').disabled=true;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	document.getElementById('xmlinsegnamento').innerHTML='caricamento in corso...';
	xmlhttp.onreadystatechange=docenteChanged;
	xmlhttp.open("GET","?contenuto=docenterichiesta&admin="+admin+"&"+path,true);
	xmlhttp.send(null);	
}

function docenteChanged() {
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//alert(xmlhttp.responseText);
		document.getElementById('xmlinsegnamento').innerHTML=xmlhttp.responseText;
	}
}

function verificarichiesta(forma) {
	var autocert='';
	var verifica=false;
	var crediti = parseInt(forma.crediti.value);
	if (forma.altricrediti)
		var altricrediti = parseInt(forma.altricrediti.value);
	else
		var altricrediti = 0;
	var richiesti = parseInt(forma.richiesti.value);
	var totcrediti = crediti+altricrediti;
	if (totcrediti>=richiesti)
		if (forma.altrematerie) {
			if ((forma.altrematerie.value).length==0) {
				forma.altrematerie.style.backgroundColor="yellow";
				alert("ATTENZIONE\nE\' necessario indicare per esteso gli ulteriori esami conseguiti");
				forma.altrematerie.focus();
			}
			else
				verifica=true;
		}
		else
			verifica=true;
	else {
		if (isNaN(totcrediti))
			totcrediti=crediti;
		alert("ATTENZIONE!\nNon e\' stato raggiunto il totale crediti richiesto ("+totcrediti+" su "+richiesti+")");
	}
	if (verifica && forma.insegnascelto.value=="") {
		alert("ATTENZIONE\nE\' necessario indicare la materia svolta con il docente selezionato");
		verifica=false;
		forma.insegnascelto.focus();
	}
	if (verifica) {
		if (altricrediti>0)
			autocert="Autocertificazione\n - esami di: "+forma.altrematerie.value+"\n - tot crediti: "+altricrediti+"\n\n";
		if (forma.tipotesi.selectedIndex!=null)
			var riepilogo=autocert+"Prova: "+forma.tipotesi.options[forma.tipotesi.selectedIndex].text+"\nDocente: "+forma.sceltadocente.options[forma.sceltadocente.selectedIndex].text+"\nMateria: "+forma.insegnascelto.value;
		else
			var riepilogo=autocert+"Prova: "+forma.tipotesi.value+"\nDocente: "+forma.sceltadocente.options[forma.sceltadocente.selectedIndex].text+"\nMateria: "+forma.insegnascelto.value;
		answer=confirm("Riepilogo dati inseriti:\n\n"+riepilogo+"\n\nProcedere con la richiesta di assegnazione Tesi?");
		verifica=answer;
	}
	return verifica;
}

function abilitaesa(txt) {
	if (txt.length!=0) {
		var crediti = parseInt(document.getElementById('crediti').value);
		var altricrediti = parseInt(document.getElementById('altricrediti').value);
		var richiesti = parseInt(document.getElementById('richiesti').value);
		var totcrediti = crediti+altricrediti;
		//alert('crediti: ' + totcrediti);
		if (totcrediti>=richiesti)
			document.getElementById('procediesa').disabled=false;
		else
			document.getElementById('procediesa').disabled=true;
	}
	else
		document.getElementById('procediesa').disabled=true;
}

function abilitamedia(txt) {
	if (txt.length!=0 && parseInt(txt.value)>0)
		document.getElementById('procedidoc').disabled=false;
	else
		document.getElementById('procedidoc').disabled=true;
}

function procedifine(seletto,admin) {
	if (!admin) {
		document.getElementById('procediesa').disabled=true;
		document.getElementById('procedidoc').disabled=true;
		if ((seletto.options[seletto.selectedIndex].value).length==0) {
			document.getElementById('insegnamento').value="";
			document.getElementById('conferma').disabled=true;
		}
		else {
			document.getElementById('conferma').disabled=false;
			document.getElementById('insegnamento').value=seletto.options[seletto.selectedIndex].text;
			if (seletto.options[seletto.selectedIndex].value==0) {
				document.getElementById('insegnamento').readOnly=false;
				document.getElementById('insegnamento').style.backgroundColor="yellow";
				document.getElementById('insegnamento').focus();
				alert("ATTENZIONE! E\' stato scelto di indicare un insegnamento NON in elenco.\nNella casella in giallo digitare il nome completo dell\'insegnamento sostenuto con il docente.");
			}
			else {
				document.getElementById('insegnamento').style.backgroundColor="#C0C0FF";
				document.getElementById('insegnamento').readOnly=true;			
			}
		}
	}
	else {
		if ((seletto.options[seletto.selectedIndex].value).length==0) {
			document.getElementById('aggiornasub').disabled=true;
			document.getElementById('informa').disabled=true;
		}
		else {
			document.getElementById('aggiornasub').disabled=false;
			document.getElementById('informa').disabled=false;
			document.getElementById('tipocambio').value="relatore";
		}	
	}
}

function abilitaggtesi(campo) {
	document.getElementById('aggiornasub').disabled=false;
	document.getElementById('informa').disabled=false;
	document.getElementById('tipocambio').value=campo.name;
}

function aggiornatesi(forma,aggiorna) {
	var procedi=false;
	if (!aggiorna)
		if(forma.studenti.length==null) {
			if (forma.studenti.checked) { procedi=true; }
		}
		else {
			for (var i = 0; i < forma.studenti.length; i++) {
				if (forma.studenti[i].checked) { procedi=true; break; }
			}
		}
	else
		procedi=true;
	if (procedi)
		procedi=confirm("Verra\' inviata automaticamente una email agli interessati.\nProcedere?");
	return procedi;
}
/** fine Richieste Tesi **/

function check_elencodoc(forma) {
	var tasko=forma.task.value;
	var answer;
	
	switch (tasko) {
		case 'salva':
			if (!cambio) {
				alert("Non risultano modifiche da salvare");
				return false;
			}
			else {
				var seletto=document.getElementById('id_materiale');
				seletto.multiple=true;
				for (i=0; i<seletto.options.length;i++)
					seletto.options[i].selected = true;
				return true; 
			}
			break;
		case 'deldoc':
			if (forma.id_materiale.value=="") {
				alert("Selezionare un file");
				return false;
			} else {
				answer = confirm ('Confermi l\'eliminazione ?');
				if (answer)
					return true;
				else
					return false;
			}
			break;
		case 'nascdoc':
			if (forma.id_materiale.value=="") {
				alert("Selezionare un file");
				return false;
			} else {
				answer = confirm ('Confermi l\'operazione ?');
				if (answer)
					return true;
				else
					return false;
			}
			break;
		default:
			if (forma.id_materiale.value=="") {
				alert("Selezionare un file");
				return false;
			}
			else
				return true;
	}
}

function mod_colore(obj,m_pos) {
	if (m_pos=="mover") {
	    obj.style.backgroundColor="gray";
	    obj.style.color="white";
	} else {
	    obj.style.backgroundColor="white";
	    obj.style.color="black";
	}
}

function toggleSelect(nome_sel) {
    if (nome_sel=="uno") {
        document.form1.mese.disabled = false;
        document.form1.mese.style.backgroundColor = "white";
        document.form1.anno.disabled = false;
        document.form1.anno.style.backgroundColor = "white";
        
    } else {
        document.form1.mese.disabled = true;
        document.form1.mese.style.backgroundColor = "gray";
        document.form1.anno.disabled = true;
        document.form1.anno.style.backgroundColor = "gray";
        }
}

function verifica_ambito(campo) {
	var path;
	switch (campo)
	{
	case 'condizione':
		//path="http://host.uniroma3.it/facolta/economia/economia.asp?tabella=anagrafica&finestra=xmlreq&valore="+document.getElementById('condizione').value+"|null";
		break;
	case 'autobus23':
		path="http://host.uniroma3.it";
		var params="nav=4&service=paline&action=dettaglio&id_fermata=71907";
		//path="http://www.uniroma3.it/page.php?page=Guida_all";
		camporichiesta='autobus23';
		break;
	case 'richiesta':
		path="http://host.uniroma3.it/facolta/economia/economia.asp?contenuto=suggerimento&testo="+document.getElementById('richiesta').value;
		camporichiesta='richiesta';
		break;
	default:
		//altri casi
	}
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null) {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	}
	//xmlhttp.onreadystatechange=stateChanged(campo);
	xmlhttp.onreadystatechange=stateChanged;
	//alert("path: " + path);
	xmlhttp.open("GET",path,true);
	xmlhttp.send(null);	
}

function stateChanged() {
	if (xmlhttp.readyState==4 && xmlhttp.status==200) {
		//alert(camporichiesta);
		switch (camporichiesta) {
		case 'richiesta':
			document.getElementById('suggerimento').innerHTML=xmlhttp.responseText;
			break;
		case 'autobus23':
			document.getElementById('autobus23').innerHTML=stripHTML(xmlhttp.responseText);
			break;
		default:
			//altri casi
		}
	}
}

function chiamaSaveAs(titolo){
	if (document.execCommand) {
	document.execCommand('SaveAs',null,titolo);
	}
}

function move(selectO,to) {
	var index = selectO.selectedIndex;
	var selectLength  = selectO.length - 1;
	
	if (index == -1) return false;
	
	if(to == +1 && index == selectLength)
	{
		return false;
	}
	else if(to == -1 && index == 0)
	{
		return false;
	}
	swap(index,index+to,selectO);
	return true;
}
    
function swap(fIndex,sIndex,selectO) {
	cambio=true;
	fText  = selectO.options[fIndex].text;
	fValue = selectO.options[fIndex].value;
	selectO.options[fIndex].text  = selectO.options[sIndex].text;
	selectO.options[fIndex].value = selectO.options[sIndex].value;  
	
	selectO.options[sIndex].text = fText;
	selectO.options[sIndex].value = fValue;
	
	selectO.options[sIndex].selected = true;    
}

// Move the currently selected item between two select menus
function moveSelectItem(currField, newField) {
	var selectedIndex = currField.selectedIndex;
		
	if (selectedIndex == -1) {
		return;
	}
		
	var selectedOption = currField.options[selectedIndex];
	if (selectedOption.value=="" || isNaN(selectedOption.value))
		return;

	// If "None" exists in new menu, delete it.
	for (var i = 0; i < newField.options.length; i++) {
		if (newField.options[i].disabled) {
			// Delete item from old menu
			for (var j = i + 1; j < newField.options.length; j++) {
				newField.options[j - 1].value = newField.options[j].value;
				newField.options[j - 1].text = newField.options[j].text;
			}
			newField.options.length -= 1;
		}
	}

	// Add item to new menu
	newField.options.length += 1;
	newField.options[newField.options.length - 1] = new Option(selectedOption.text, selectedOption.value);

	// Delete item from old menu
	for (var i = selectedIndex + 1; i < currField.options.length; i++) {
		currField.options[i - 1].value = currField.options[i].value;
		currField.options[i - 1].text = currField.options[i].text;
	}
	currField.options.length -= 1;

	// If no items are left in the current menu, add a "None" item.
	if (currField.options.length == 0) {
		currField.options.length = 1;
		currField.options[0] = new Option('Nessuno', '');
		currField.options[0].disabled = true;
	}

	// Update selected item
	else if (currField.options.length > 0) {
		currField.selectedIndex = selectedIndex < (currField.options.length - 1) ? selectedIndex : (currField.options.length - 1);
	}
}

function seleziona_tutti(cecco,forma) {
	var cecca,i,n;
	
	for (i=0, n=forma.elements.length; i < n; i++) {
		oggetto=forma.elements[i];
		if (oggetto.type=="checkbox" && oggetto.disabled==false && oggetto.name!=cecco.name) {
			forma.elements[i].checked=cecco.checked;
		}
	}
}

//*** QUESTIONARI *** //
function duplicaquest() {
	if (conferma('di duplicazione del questionario corrente (ne verra\' creato uno nuovo)')) {
		document.getElementById('duplica').value=true;
		return true;
	}
	else
		return false;
}

function sugiuquest(forma,doma) {
	if (doma) 
		var seletto=forma.vedidomanda;
	else
		var seletto=forma.vedirisposta;
	seletto.multiple=true;
	for (i=0; i<seletto.options.length;i++)
		seletto.options[i].selected = true;
	return true; 
}

function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(campo) {
  var strField = document.getElementById(campo);
  var strLength = strField.value.length;
  var lchar = strField.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = strField.value.substring(0, (strLength) - 1);
    strField.value = myNumber;
	//document.getElementById("risposta"+idrisp+"r").innerHTML = " > &egrave; richiesto un numero < ";
  }
  return false;
}

function infoquest(idquest,tipo) {
	var url="economia.asp?contenuto=infoquest&idquest="+idquest+"&tipo="+tipo;
	document.getElementById('divquest').innerHTML = "recupero dati in corso..";
	if (window.XMLHttpRequest) {
		cercaquest = new XMLHttpRequest();
		cercaquest.onreadystatechange = function() {risultaquest();};
		cercaquest.open("GET", url, true);
		cercaquest.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercaquest = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercaquest) {
			cercaquest.onreadystatechange = function() {risultaquest();};
			cercaquest.open("GET", url, true);
			cercaquest.send();
		}
	}
}

function risultaquest() {
	if (cercaquest.readyState == 4) {
		if (cercaquest.status == 200 || cercaquest.status == 304) {
			document.getElementById('divquest').style.display='';
			document.getElementById('divquest').innerHTML = cercaquest.responseText;
		} else {
			document.getElementById('divquest').innerHTML=cercaquest.responseText;
		}
	}
}

function vediquest(forma) {
	var procedi=true;
	var colpevole='';
	for (i=0, n=forma.elements.length; i < n; i++) {
		//alert('valore: '+forma.elements[i].value+' -> procedi: '+procedi);
		switch (forma.elements[i].type) {
			case 'hidden':
				if (forma.elements[i].value=='true') {
					var nome=(forma.elements[i].name).substr(1);
					elemento=document.getElementsByName(nome);
					for (k=0, m=elemento.length; k<m; k++) {
						if (elemento[k].type=='radio')
							break;
						else
							if(elemento[k].value=='') {
								colpevole=elemento[k].name;
								procedi=false;
							}
					}
				}
				else {
					if (forma.elements[i].value=='email') {
						var nome=(forma.elements[i].name).substr(1);
						elemento=document.getElementsByName(nome);
						if (!isEmail(elemento[0].value)) {
							alert('Email non valida');
							procedi=false;
						}
					}
				}
				break;
			/*case 'text':
				if(document.getElementById('obbliga-'+forma.elements[i].name).value=='true')
					if (forma.elements[i].value=='')
						procedi=false;
				break;
			case 'select-one':
				if(document.getElementById('obbliga-'+forma.elements[i].name).value=='true')
					if (forma.elements[i].value=='')
						procedi=false;
				break;
			case 'radio':
				if(document.getElementById('obbliga-'+forma.elements[i].name).value=='true') {
					var cecco=false;
					var fine=false;
					var j=1;
					if(!forma.elements[i].checked)
						while (!fine && !cecco) {
							if(forma.elements[i].name==forma.elements[i+j].name) {
								if (forma.elements[i].checked)
									cecco=true;
							}
							else
								fine=true;
						}
				}
				break;*/
			default:
				// ** eventuali altri casi !! **
		}
	}
	if(!procedi) {
		//alert('ATTENZIONE! Compilare tutti i campi obbligatori ['+colpevole+']');
		alert('ATTENZIONE! Compilare tutti i campi * obbligatori');
		return false; 
	}
	else 
		return conferma('di invio questionario');
}

function cambiatipo(seletto) {
	for (i=1; i<6; i++)
		if (seletto!=i)
			document.getElementById('tipo'+i).style.display='none';
		else
			document.getElementById('tipo'+i).style.display='';
}

function nuovoquest(seletto) {
	if (seletto>=0)
		if (seletto==0) {
			document.getElementById('nuovoquest').style.display='';
			document.getElementById('divquest').style.display='none';
		}
		else {
			document.getElementById('nuovoquest').style.display='none';
			document.getElementById('divquest').style.display='';
			infoquest(seletto,'view');
		}
	else {
		document.getElementById('nuovoquest').style.display='none';
		document.getElementById('divquest').style.display='none';
	}
}

function aggiungirispa(forma) {
	alert(forma.tipodomanda.value);
}

function procediquest(idquest) {
	codice=document.getElementById('email').value;
	if (isEmail(codice)) {
		var url="economia.asp?contenuto=cercamailquest&utente="+codice+"&idquest="+idquest;
		//document.getElementById('infoschedule').innerHTML = "ricerca dati..";
		if (window.XMLHttpRequest) {
			infosched = new XMLHttpRequest();
			infosched.onreadystatechange = function() {risultaprocedi();};
			infosched.open("GET", url, true);
			infosched.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			infosched = new ActiveXObject("Microsoft.XMLHTTP");
			if (infosched) {
				infosched.onreadystatechange = function() {risultaprocedi();};
				infosched.open("GET", url, true);
				infosched.send();
			}
		}
	}
	else {
		alert('Inserire una mail valida');
	}
}

function risultaprocedi() {
	if (infosched.readyState == 4) {
		if (infosched.status == 200 || infosched.status == 304) {
			risulta=infosched.responseText;
			if (risulta!='') {
				document.getElementById('ajaxquest').innerHTML = risulta;
				document.getElementById('ajaxquest').style.display='';
				document.getElementById('divquest').style.display='none';
			}
			else {
				document.getElementById('divquest').style.display='';
				document.getElementById('ajaxquest').innerHTML = risulta;
				document.getElementById('ajaxquest').style.display='';
				//document.getElementById('ajaxquest').style.display='none';
				document.getElementById('utentequest').value=document.getElementById('email').value;
				document.getElementById('email').readOnly=true;
				document.getElementById('email').style.backgroundColor='#e0e0e0';
			}
		} else {
			document.getElementById('ajaxquest').innerHTML="ajax error\n"+infosched.responseText;
		}
	}
}

var javascript_countdown = function () {
	var time_left = 10; //number of seconds for countdown
	var output_element_id = 'javascript_countdown_time';
	var keep_counting = 1;
	var no_time_left_message = 'No time left for JavaScript countdown!';
 
	function countdown() {
		if(time_left < 2) {
			keep_counting = 0;
		}
 
		time_left = time_left - 1;
	}
 
	function add_leading_zero(n) {
		if(n.toString().length < 2) {
			return '0' + n;
		} else {
			return n;
		}
	}
 
	function format_output() {
		var hours, minutes, seconds;
		seconds = time_left % 60;
		minutes = Math.floor(time_left / 60) % 60;
		hours = Math.floor(time_left / 3600);
 
		seconds = add_leading_zero( seconds );
		minutes = add_leading_zero( minutes );
		hours = add_leading_zero( hours );
 
		return hours + ':' + minutes + ':' + seconds;
	}
 
	function show_time_left() {
		document.getElementById(output_element_id).innerHTML = format_output();//time_left;
	}
 
	function no_time_left() {
		document.getElementById(output_element_id).innerHTML = no_time_left_message;
	}
 
	return {
		count: function () {
			countdown();
			show_time_left();
		},
		timer: function () {
			javascript_countdown.count();
 
			if(keep_counting) {
				setTimeout("javascript_countdown.timer();", 1000);
			} else {
				no_time_left();
			}
		},
		//Kristian Messer requested recalculation of time that is left
		setTimeLeft: function (t) {
			time_left = t;
			if(keep_counting == 0) {
				javascript_countdown.timer();
			}
		},
		init: function (t, element_id) {
			time_left = t;
			output_element_id = element_id;
			javascript_countdown.timer();
		}
	};
}();
 
//time to countdown in seconds, and element ID
//javascript_countdown.init(3673, 'javascript_countdown_time');
// *** fine QUESTIONARI *** //

//** funzioni CLASS SCHEDULE **//
function ApriClassReport() {
	var url="economia.asp?contenuto=classreport";
		url += "&insegna="+document.getElementById('insegna').value;
		url += "&aula="+document.getElementById('aula').value;
		url += "&canale="+document.getElementById('canale').value;
		
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		xmlreport = new XMLHttpRequest();
		xmlreport.onreadystatechange = function() {classreportfine();};
		xmlreport.open("GET", url, true);
		xmlreport.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		xmlreport = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlreport) {
			xmlreport.onreadystatechange = function() {classreportfine();};
			xmlreport.open("GET", url, true);
			xmlreport.send();
		}
	}
}

function classreportfine() {
	if (xmlreport.readyState == 4) {
		document.getElementById('classreport').style.display='';
		if (xmlreport.status == 200 || xmlreport.status == 304) {
			document.getElementById('classreport').innerHTML = xmlreport.responseText;
		} else {
			document.getElementById('classreport').innerHTML="ajax error:\n" + xmlreport.responseText;
		}
	}
}
	
function enabletitsched(seletto) {
	if (isNaN(seletto.value)) {
		document.getElementById('infoschedule').style.display='none';
		document.getElementById('institolo').style.display='none';		
	}
	else {
		if (seletto.value=='0') {
			document.getElementById('institolo').style.display='';
			document.getElementById('infoschedule').style.display='none';
			document.getElementById('institolo').focus();
		}
		else {
			document.getElementById('institolo').style.display='none';
			if (seletto.value!='') {
				document.getElementById('infoschedule').style.display='';
				var url="economia.asp?contenuto=vedischedule&singolo=true&idsched="+seletto.value;
				document.getElementById('infoschedule').innerHTML = "ricerca dati..";
				if (window.XMLHttpRequest) {
					infosched = new XMLHttpRequest();
					infosched.onreadystatechange = function() {risched();};
					infosched.open("GET", url, true);
					infosched.send(null);
				// IE/Windows ActiveX version
				} else if (window.ActiveXObject) {
					infosched = new ActiveXObject("Microsoft.XMLHTTP");
					if (infosched) {
						infosched.onreadystatechange = function() {risched();};
						infosched.open("GET", url, true);
						infosched.send();
					}
				}
			}
			else
				document.getElementById('infoschedule').style.display='none';
		}
	}
}

function risched() {
	if (infosched.readyState == 4) {
		if (infosched.status == 200 || infosched.status == 304) {
			document.getElementById('infoschedule').innerHTML = infosched.responseText;
		} else {
			document.getElementById('infoschedule').innerHTML="ajax error\n"+infosched.responseText;
		}
	}
}

function inschedule(modo) {
	var conferma=true;
	if (modo=='elimina')
		conferma=confirm('Procedere con l\'eliminazione dell\'evento selezionato?');
	if (conferma) {
		var url="economia.asp?contenuto=vedischedule";
		url += "&ins="+document.getElementById('insegnamento').value;
		url += "&aula="+document.getElementById('aula').value;
		url += "&inizio="+document.getElementById('inizio').value;
		url += "&fine="+document.getElementById('fine').value;
		url += "&giorno="+document.getElementById('giorno').value;
		url += "&capienza="+document.getElementById('capienza').checked;
		url += "&numgiorni="+document.getElementById('numgiorni').checked;
		url += "&usablocchi="+document.getElementById('usablocchi').checked;
		url += "&numore="+document.getElementById('numore').checked;
		url += "&modo="+modo;
		if (document.getElementById('commenti').value!='')
			url += "&commenti="+document.getElementById('commenti').value;
		document.getElementById('divsched').innerHTML = "verifica in corso..";
		if (window.XMLHttpRequest) {
			vedisched = new XMLHttpRequest();
			vedisched.onreadystatechange = function() {risultaschedule();};
			vedisched.open("GET", url, true);
			vedisched.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			vedisched = new ActiveXObject("Microsoft.XMLHTTP");
			if (vedisched) {
				vedisched.onreadystatechange = function() {risultaschedule();};
				vedisched.open("GET", url, true);
				vedisched.send();
			}
		}
	}
}

function risultaschedule() {
	if (vedisched.readyState == 4) {
		if (vedisched.status == 200 || vedisched.status == 304) {
			var vedi=vedisched.responseText;
			if (vedi=="OK")
				document.getElementById('scheduform').submit();
			else
				document.getElementById('divsched').innerHTML = vedi;
		} else {
			document.getElementById('divsched').innerHTML="ajax error\n("+vedisched.responseText+")";
		}
	}
}

function verifica_schedule(form) {
	var steppo=form.steppo.value;
	var assigno = form.assigned;
	var assignedIds = '';
	var procedi=false;
	var selezionati=0;
	var selezione=false;
	var focuso='';
	
	switch (steppo) {
		case '0':
			if (form.schedule.value!='') {
				if (form.schedule.value=='0') {
					if (form.titolosched.value=='') {
						procedi=false;
						focuso='titolosched';
					}
					else
						procedi=true;
				}
				else
					procedi=true;
			} else
				procedi=false;
			break;
		case '1':
			// da fare
			procedi=true;
			break;
		case '2':
			for (var i = 0; i < assigno.options.length; i++) {
				if(!isNaN(assigno.options[i].value) && assigno.options[i].value>0) {
					if (assignedIds != '') {
						assignedIds += ',';
					}
					assignedIds += assigno.options[i].value;
					selezionati++;
				}
			}
			form.insAssigned.value = assignedIds;
			if (selezionati!=0)
				procedi=true;
			else
				procedi=false;
			break;
		case '4':
			for (i=0, n=form.elements.length; i < n; i++) { // da rimettere i < n
				if (form.elements[i].type=="select-one" && form.elements[i].value==0) {
					selezione=true;
					form.elements[i].style.backgroundColor='yellow';
					//break;
				}
			}
			if (!selezione)
				procedi=true;
			else {
				answer=confirm("In giallo i dati mancanti.\nSi vuole procedere ugualmente?");
				procedi=answer;
			}
			break;
		case '6':
			selezione=false;
			for (i=0, n=form.elements.length; i < n; i++)
				if (form.elements[i].type=="checkbox" && form.elements[i].checked==true) {
					selezione=true;
					break;
				}
			if (selezione)
				procedi=true;
			else
				procedi=false;
			break;
		default:
			procedi=true;
			//da fare
	}
	
	if (procedi) 
		return procedi;
	else {		
		alert('ATTENZIONE! Mancano dati per proseguire.');
		if (focuso!='') {
			document.getElementById(focuso).focus();
			document.getElementById(focuso).style.backgroundColor='yellow';
		}
		return false;
	}
}

function abilitabuttons(abilita,tipo) {
	if (tipo==1) {
		document.getElementById('elimina').disabled=false;
		document.getElementById('taglia').disabled=false;
		document.getElementById('copia').disabled=false;
		//document.getElementById('incolla').disabled=false;
		if (abilita) {
			document.getElementById('inserisci').disabled=false;
			document.getElementById('sostituisci').disabled=false;
		}
		else {
			document.getElementById('inserisci').disabled=true;
			document.getElementById('sostituisci').disabled=true;
		}
	}
	else {
		document.getElementById('inserisci').disabled=false;
		document.getElementById('sostituisci').disabled=true;
		if (abilita) {
			document.getElementById('elimina').disabled=false;
			document.getElementById('taglia').disabled=false;
			document.getElementById('copia').disabled=false;
			//document.getElementById('incolla').disabled=false;
		}
		else {
			document.getElementById('elimina').disabled=true;
			document.getElementById('taglia').disabled=true;
			document.getElementById('copia').disabled=true;
			//document.getElementById('incolla').disabled=true;
		}	
	}
}

function cliccasched(seletto) {
	giorno=seletto.id.substring(seletto.id.indexOf('-')+1);
	document.getElementById('giorno').selectedIndex=giorno-1;
	seleins=document.getElementById('insegnamento');
	var trovains=false;
	for (var j = 0; j < seleins.options.length; j++) {
		//alert(seleins.options[j].value+' '+seletto.options[seletto.selectedIndex].text);
		if (seleins.options[j].value==seletto.options[seletto.selectedIndex].value) {
			seleins.selectedIndex=j;
			trovains=true;
			break;
		}
	}
	document.getElementById('inizio').selectedIndex=seletto.selectedIndex+1;
	document.getElementById('fine').selectedIndex=seletto.selectedIndex+9;
	if (!trovains) 
		abilitabuttons(false,2);
	else
		abilitabuttons(true,1);
	//document.getElementById('inserisci').disabled=true;
	for (var k=2; k < 8; k++) {
		if (giorno!=k)
			document.getElementById('giorno-'+k).selectedIndex=-1;
	}
	var url="economia.asp?contenuto=vedischedule&";
		url += "&ins="+document.getElementById('insegnamento').value;
		url += "&aula="+document.getElementById('aula').value;
		url += "&inizio="+document.getElementById('inizio').value;
		url += "&fine="+document.getElementById('fine').value;
		url += "&giorno="+document.getElementById('giorno').value;
		url += "&modo=consulta";
	document.getElementById('divsched').innerHTML = "verifica in corso..";
	if (window.XMLHttpRequest) {
		unosched = new XMLHttpRequest();
		unosched.onreadystatechange = function() {vedischedule();};
		unosched.open("GET", url, true);
		unosched.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		unosched = new ActiveXObject("Microsoft.XMLHTTP");
		if (unosched) {
			unosched.onreadystatechange = function() {vedischedule();};
			unosched.open("GET", url, true);
			unosched.send();
		}
	}
}

function vedischedule() {
	if (unosched.readyState == 4) {
		if (unosched.status == 200 || unosched.status == 304) {
			var vedi=unosched.responseText;
			document.getElementById('divsched').innerHTML = vedi;
		} else {
			document.getElementById('divsched').innerHTML="ajax error\n("+unosched.responseText+")";
		}
	}
}

function tabellainsegna(idins) {
	var url="economia.asp?contenuto=veditabins&idins="+idins;
	document.getElementById('temporaneo').style.display='';
	document.getElementById('temporaneo').innerHTML = "ricerca dati in corso..";
	document.getElementById('divareaschedule').style.display='none';
	document.getElementById('divlavoro').style.display='none';
	if (window.XMLHttpRequest) {
		currisched = new XMLHttpRequest();
		currisched.onreadystatechange = function() {veditabins();};
		currisched.open("GET", url, true);
		currisched.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		currisched = new ActiveXObject("Microsoft.XMLHTTP");
		if (currisched) {
			currisched.onreadystatechange = function() {veditabins();};
			currisched.open("GET", url, true);
			currisched.send();
		}
	}
}

function veditabins() {
	if (currisched.readyState == 4) {
		if (currisched.status == 200 || currisched.status == 304) {
			var vedi=currisched.responseText;
			document.getElementById('temporaneo').innerHTML = vedi;
			goToByScroll('prefooter');
		} else {
			document.getElementById('temporaneo').innerHTML="ajax error\n("+currisched.responseText+")";
		}
	}
}

function tornaschedule() {
	document.getElementById('temporaneo').style.display='none';
	document.getElementById('divareaschedule').style.display='';
	document.getElementById('divlavoro').style.display='';
}

function cliccacurri(idcurri,idcdl) {
	//document.getElementById('giorno').selectedIndex=giorno-1;
	var url="economia.asp?contenuto=vedicurrisched&id="+idcurri+"&cdl="+idcdl;
	document.getElementById('vedicdl').innerHTML = "verifica in corso..";
	if (window.XMLHttpRequest) {
		currisched = new XMLHttpRequest();
		currisched.onreadystatechange = function() {vedicurri();};
		currisched.open("GET", url, true);
		currisched.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		currisched = new ActiveXObject("Microsoft.XMLHTTP");
		if (currisched) {
			currisched.onreadystatechange = function() {vedicurri();};
			currisched.open("GET", url, true);
			currisched.send();
		}
	}
}

function vedicurri() {
	if (currisched.readyState == 4) {
		if (currisched.status == 200 || currisched.status == 304) {
			var vedi=currisched.responseText;
			document.getElementById('vedicdl').innerHTML = vedi;
		} else {
			document.getElementById('vedicdl').innerHTML="ajax error\n("+currisched.responseText+")";
		}
	}
}

function changeseletti() {
	var abilitati=true;
	if (document.getElementById('inizio').selectedIndex>=document.getElementById('fine').selectedIndex)
		abilitati=false;
	else {
		if (document.getElementById('giorno').selectedIndex==0)
			abilitati=false;
		else
			if (document.getElementById('insegnamento').selectedIndex==0)
				abilitati=false;		
	}
	if (abilitati)
		abilitabuttons(true,1);
	else
		abilitabuttons(false,1);
}
//** fine funzioni Class Schedule **//

function asse_docins(form) {
	var assigno = form.assigned;
	var assignedIds = '';
	var assidoce = form.assidocenti;
	var assignedDIds = '';
	var procedi=true;
	var selezionati=0;
	
	if (assidoce.options.length<=3) {
		for (var j = 0; j < assidoce.options.length; j++) {
			if (assignedDIds != '') {
				assignedDIds += ':';
			}
			assignedDIds += assidoce.options[j].value;
			if((assidoce.options[j].value).length>0)
				selezionati++;
		}
		form.insDocAssigned.value = assignedDIds;
	}
	else {
		alert("Si possono selezionare al massimo 3 docenti");
		procedi=false;
	}
	
	if (assigno.options.length<=3) {
		for (var i = 0; i < assigno.options.length; i++) {
			if (assignedIds != '') {
				assignedIds += ':';
			}
			assignedIds += assigno.options[i].value;
			if((assigno.options[i].value).length>0)
				selezionati++;
		}
		form.insAssigned.value = assignedIds;		
	}
	else {
		alert("Si possono selezionare al massimo 3 insegnamenti");
		procedi=false;
	}
	if (selezionati!=0)
		return procedi;
	else {
		alert('ATTENZIONE! Non hai selezionato nessun docente o insegnamento.\nSe vuoi puoi annullare la tua iscrizione al servizio dalla pagina principale di AlertMail.');
		return false;
	}
}

/**** funzioni CHAT AJAX *****/
	function aggiungichat(nomeutente,idsessione,sessionechat) {
		var url="economia.asp?contenuto=nuovachat&nomeutente="+nomeutente+"&idsessione="+idsessione+"&sessionechat="+sessionechat;
		//document.getElementById('chatdiv').innerHTML="<p><u>nuova conversazione con "+nomeutente+"</u></p>";
		document.getElementById('chatdiv').innerHTML="";
		document.getElementById('interlocutore').value=nomeutente;
		if (window.XMLHttpRequest) {
			chatnuova = new XMLHttpRequest();
			chatnuova.onreadystatechange = function() {chataggiungi(nomeutente);};
			chatnuova.open("GET", url, true);
			chatnuova.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			chatnuova = new ActiveXObject("Microsoft.XMLHTTP");
			if (chatnuova) {
				chatnuova.onreadystatechange = function() {chataggiungi(nomeutente);};
				chatnuova.open("GET", url, true);
				chatnuova.send();
			}
		}
	}

	function chataggiungi(nomeutente) {
		if (chatnuova.readyState == 4) {
			if (chatnuova.status == 200 || chatnuova.status == 304) {
				document.getElementById('infochat').innerHTML = chatnuova.responseText;
				ajaxtesto('consenti',nomeutente);
			} else {
				document.getElementById('infochat').innerHTML="Errore richiesta dati\n[" + chatnuova.responseText+"]";
			}
		}
	}

	function ajaxchatutenti() {
		var url="economia.asp?contenuto=aggiornautentichat";
		//document.getElementById('studentiattesa').innerHTML="aggiornamento coda..";
		// native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			chatutenti = new XMLHttpRequest();
			chatutenti.onreadystatechange = function() {utentiDone();};
			chatutenti.open("GET", url, true);
			chatutenti.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			chatutenti = new ActiveXObject("Microsoft.XMLHTTP");
			if (chatutenti) {
				chatutenti.onreadystatechange = function() {utentiDone();};
				chatutenti.open("GET", url, true);
				chatutenti.send();
			}
		}
		setTimeout("ajaxchatutenti()", 5000);
	}

	function utentiDone() {
		var chatinfo;
		if (chatutenti.readyState == 4) {
			if (chatutenti.status == 200 || chatutenti.status == 304) {
				var risposta=(chatutenti.responseText).split('|');
				document.getElementById('studentiattesa').innerHTML=risposta[0];
				document.getElementById('studentichiusi').innerHTML=risposta[1];
				if (risposta[2]=="abilitachat") {
					document.getElementById('chatsubmit').disabled=false;
					document.getElementById('chatstrumenti').style.display='';
					//chatinfo=" [abilitata]";
				}
				else {
					document.getElementById('chatsubmit').disabled=true;
					document.getElementById('chatstrumenti').style.display='none';
					//ajaxchat(true);
					//chatinfo=" [disabilitata]";
				}
				document.getElementById('infochat').innerHTML=risposta[3];
				document.getElementById('elencovedistudente').innerHTML=risposta[4];
				document.getElementById('strumentostud').innerHTML=risposta[5];
				if (risposta[6]!='admin') 
					document.getElementById('interlocutore').value=risposta[6];
				document.getElementById('vedirisorse').innerHTML=risposta[7];
				//var posizione=(document.getElementById('condivisioni').innerHTML).indexOf('<ul>');
				//if (posizione==-1) {
				if (document.getElementById('aggiornastrumenti').value!='true') {
					document.getElementById('condivisioni').innerHTML=risposta[8];
					document.getElementById('aggiornastrumenti').value='true';
				}
			}
			else {
				document.getElementById('studentiattesa').innerHTML="Errore richiesta dati\n["+chatutenti.responseText+"]";
			}
		}
	}
	
	function alertchat(condivisione,tipo) {
		if (tipo=='alt') {
			alert("E richiamata la tua attenzione in chat");
			document.getElementById('messaggio').focus();
		}
		else {
			allerta++;
			if (allerta<10) {
				if (allerta % 2) {
					var interlocu=document.getElementById('interlocutore').value;
					if (condivisione) messaggio="a condivisione"; else messaggio="o messaggio";
					document.title="Nuov"+messaggio+" da "+interlocu+"!";
					//playSound('beep');
				}
				else
					document.title="UniRomaTre - Facolta di Economia - Sportello Chat";
			}
			else {
				document.title="UniRomaTre - Facolta di Economia - Sportello Chat";
				allerta=0;
				clearTimeout(timero);
			}
			if (allerta!=0) 
				timero=setTimeout("alertchat("+condivisione+",'null')", 2000);
		}
	}
	
	function ajaxchat(ferma) {
		if (!ferma) {
			var url="economia.asp?contenuto=aggiornachat";
			document.getElementById('aprichatdiv').style.display='';
			// native XMLHttpRequest object
			if (window.XMLHttpRequest) {
				req = new XMLHttpRequest();
				req.onreadystatechange = function() {ajaxDone();};
				req.open("GET", url, true);
				req.send(null);
			// IE/Windows ActiveX version
			} else if (window.ActiveXObject) {
				req = new ActiveXObject("Microsoft.XMLHTTP");
				if (req) {
					req.onreadystatechange = function() {ajaxDone();};
					req.open("GET", url, true);
					req.send();
				}
			}
			chatta=setTimeout("ajaxchat()", 2000);
		}
		else
			clearTimeout(chatta);
	}

	function ajaxDone() {
		if (req.readyState == 4) {
			if (req.status == 200 || req.status == 304) {
				results = req.responseText;
				var interlocu=document.getElementById('interlocutore').value;
				var objDiv=document.getElementById('chatdiv');
				var posizione=results.indexOf('##');
				if (posizione!=-1) {
					var risposte=results.split('##');
					var risultachat=risposte[0];
					var tipo=risposte[1];
					var valore=risposte[2];
					switch (tipo) {
						case 'app':
							condividi_appunti(valore);
							break;
						case 'spo':
							condividi_sportello(valore);
							break;
						case 'pdf':
							condividi_risorsa(valore,'pdf');
							break;
						case 'lnk':
							var posizione=valore.indexOf('economia.asp');
							if (posizione!=-1)
								window.open(valore,'linkeconomia');
							else
								condividi_risorsa(valore,'lnk');
							break;
						default:
							//altro
					}					
					document.getElementById('vedirisorse').style.display='';
					objDiv.innerHTML = objDiv.innerHTML + risultachat;
					if (risultachat!='' && risposte[3]==interlocu) alertchat(true,tipo);
					objDiv.scrollTop = objDiv.scrollHeight;
				}
				else {
					posizione=results.indexOf('|');
					if (posizione!=-1) {
						var righe=results.split('|');
						//for (var r=0; r<righe.length;r++) {
						for (r in righe) {
							ajaxDoneTesto(interlocu,objDiv,righe[r],r);
						}
					}
					else
						ajaxDoneTesto(interlocu,objDiv,results,0);
					objDiv.scrollTop = objDiv.scrollHeight;
				}
			} else {
				document.getElementById('chatdiv').innerHTML="Errore richiesta dati\n["+req.statusText+" - "+req.responseText+"]";
			}
		}
	}
	
	function ajaxDoneTesto(interlocu,oggetto,risultato,multiplo) {
		posizione=risultato.indexOf('@@');
		if (posizione!=-1) {
			var risposte=risultato.split('@@');
			oggetto.innerHTML = oggetto.innerHTML + risposte[1];
			if (risultato!='' && risposte[0]==interlocu && multiplo==0) alertchat(false,'null');
		}
	}
	
	function ajaxtesto(contesto,info) {
		//alert(contesto + ' - ' + info);
		var procedi=true;
		if (!document.getElementById('chatsubmit').disabled) {
			switch (contesto) {
				case 'alertchat':
					var url="economia.asp?contenuto=nuovachat&contesto=alertchat&nuovotesto="+info;
					break;
				case 'formachat':
					var messa=document.getElementById('messaggio');
					//var url="economia.asp?contenuto=nuovachat&nuovotesto=" + (messa.value).replace(/'/g,"''");
					//var url="economia.asp?contenuto=nuovachat&nuovotesto=" + correggi(messa.value);
					//alert(messa.value.charCodeAt(0));
					if (document.getElementById('messaggiotutti').checked)
						contenuto="messaggiotutti";
					else
						contenuto="nuovachat";
					if (messa.value.length>0)
						var url="economia.asp?contenuto="+contenuto+"&nuovotesto=" + correggi(messa.value);
					else
						procedi=false;
					break;
				case 'sportello':
					var url="economia.asp?contenuto=nuovachat&contesto=sportello&nuovotesto="+info;
					break;
				case 'consenti':
					var url="economia.asp?contenuto=nuovachat&contesto=consenti&nuovotesto="+info;
					break;
				case 'chiudichat':
					var url="economia.asp?contenuto=nuovachat&contesto=chiudichat&nuovotesto="+info;
					break;
				case 'condilink':
					var infolink=document.getElementById('testolink').value;
					var url="economia.asp?contenuto=nuovachat&contesto=condilink&nuovotesto="+infolink;
					break;
				case 'condiappunti':
					var oEditor = FCKeditorAPI.GetInstance('appunti');
					var nuovotesto=oEditor.GetHTML();
					//alert(nuovotesto);
					var url="economia.asp?contenuto=nuovachat&contesto=appunti&nuovotesto="+nuovotesto;
					break;
				default:
					//altri
			}
			if (procedi) {	
				// native XMLHttpRequest object
				if (window.XMLHttpRequest) {
					testo = new XMLHttpRequest();
					testo.onreadystatechange = function() {ajaxtestoDone();};
					testo.open("GET", url, true);
					testo.send(null);
				// IE/Windows ActiveX version
				} else if (window.ActiveXObject) {
					testo = new ActiveXObject("Microsoft.XMLHTTP");
					if (testo) {
						testo.onreadystatechange = function() {ajaxtestoDone();};
						testo.open("GET", url, true);
						testo.send();
					}
				}
				resetmessaggio();
			}
		}
		return false;
	}

	function ajaxtestoDone() {
		if (testo.readyState == 4) {
			if (testo.status == 200 || testo.status == 304) {
				results = testo.responseText;
				//document.getElementById('pippo').innerHTML = document.getElementById('pippo').innerHTML + results;
			} else {
				//document.getElementById('pippo').innerHTML="ajax error:\n" +
				//testo.statusText;
			}
		}
	}

	function resetmessaggio() {
		document.getElementById('messaggio').value="";
		document.getElementById('messaggio').focus();
		document.getElementById('messaggiotutti').checked=false;
	}

	function avviachat(idsportello,titolo) {
		var url="economia.asp?contenuto=avviachat&idsportello="+idsportello;
		document.getElementById('avviachat').style.display='none';
		document.getElementById('prefooterchat').style.display='';
		document.getElementById('titolochat').innerHTML=titolo;
		// native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			sessione = new XMLHttpRequest();
			sessione.onreadystatechange = function() {chatavviata();};
			sessione.open("GET", url, true);
			sessione.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			sessione = new ActiveXObject("Microsoft.XMLHTTP");
			if (sessione) {
				sessione.onreadystatechange = function() {chatavviata();};
				sessione.open("GET", url, true);
				sessione.send();
			}
		}
	}

	function chatavviata() {
		if (sessione.readyState == 4) {
			results = sessione.responseText;
			if (sessione.status == 200 || sessione.status == 304) {
				document.getElementById('chatlog').innerHTML = document.getElementById('chatlog').innerHTML + results;
			} else {
				document.getElementById('pippo').innerHTML="ajax error:\n"+results;
				//sessione.statusText;
			}
		}
	}

	function condividi_sportello(codice) {
		var url="economia.asp?contenuto=condisportello&id="+codice;
		document.getElementById('condisportello').innerHTML = "ricerca sezione..";
		if (window.XMLHttpRequest) {
			cercastud = new XMLHttpRequest();
			cercastud.onreadystatechange = function() {risultasportello();};
			cercastud.open("GET", url, true);
			cercastud.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			cercastud = new ActiveXObject("Microsoft.XMLHTTP");
			if (cercastud) {
				cercastud.onreadystatechange = function() {risultasportello();};
				cercastud.open("GET", url, true);
				cercastud.send();
			}
		}
	}

	function risultasportello() {
		if (cercastud.readyState == 4) {
			if (cercastud.status == 200 || cercastud.status == 304) {
				document.getElementById('condisportello').innerHTML = cercastud.responseText;
			} else {
				document.getElementById('condisportello').innerHTML="Errore richiesta dati\n["+cercastud.responseText+"]";
			}
		}
	}
	
	function condividi_appunti(testo) {
		var oEditor = FCKeditorAPI.GetInstance('appunti');
		oEditor.SetHTML(testo);
		//alert(testo);
		//document.getElementById('condiappunti').innerHTML=document.getElementById('condiappunti').innerHTML+testo;
	}
	
	function condividi_appuntis(testo) {
		var url="economia.asp?contenuto=condirisorsa&testo="+testo;
		document.getElementById('condiappunti').innerHTML = "ricerca sezione..";
		if (window.XMLHttpRequest) {
			xmlappunti = new XMLHttpRequest();
			xmlappunti.onreadystatechange = function() {risultappunti();};
			xmlappunti.open("GET", url, true);
			xmlappunti.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			xmlappunti = new ActiveXObject("Microsoft.XMLHTTP");
			if (xmlappunti) {
				xmlappunti.onreadystatechange = function() {risultappunti();};
				xmlappunti.open("GET", url, true);
				xmlappunti.send();
			}
		}
	}

	function risultappunti() {
		if (xmlappunti.readyState == 4) {
			if (xmlappunti.status == 200 || xmlappunti.status == 304) {
				document.getElementById('condiappunti').innerHTML = xmlappunti.responseText;
			} else {
				document.getElementById('condiappunti').innerHTML="Errore richiesta dati\n["+xmlappunti.responseText+"]";
			}
		}
	}
	
	function attivappunti() {
		var url="economia.asp?contenuto=attivappunti";
		if (window.XMLHttpRequest) {
			xmlappunti = new XMLHttpRequest();
			xmlappunti.onreadystatechange = function() {attivappufine();};
			xmlappunti.open("GET", url, true);
			xmlappunti.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			xmlappunti = new ActiveXObject("Microsoft.XMLHTTP");
			if (xmlappunti) {
				xmlappunti.onreadystatechange = function() {attivappufine();};
				xmlappunti.open("GET", url, true);
				xmlappunti.send();
			}
		}
	}

	function attivappufine() {
		if (xmlappunti.readyState == 4) {
			document.getElementById('condiappunti').style.display='';
			if (xmlappunti.status == 200 || xmlappunti.status == 304) {
				document.getElementById('condiappunti').innerHTML = xmlappunti.responseText;
			} else {
				document.getElementById('condiappunti').innerHTML="Errore richiesta dati\n[" + xmlappunti.responseText+"]";
			}
		}
	}
	
	function uploadpdf() {
		var url="economia.asp?contenuto=uploadpdf";
		//document.getElementById('avviachat').style.display='none';
		// native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			chatpdf = new XMLHttpRequest();
			chatpdf.onreadystatechange = function() {uploadpdfine();};
			chatpdf.open("GET", url, true);
			chatpdf.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			chatpdf = new ActiveXObject("Microsoft.XMLHTTP");
			if (chatpdf) {
				chatpdf.onreadystatechange = function() {uploadpdfine();};
				chatpdf.open("GET", url, true);
				chatpdf.send();
			}
		}
	}

	function uploadpdfine() {
		if (chatpdf.readyState == 4) {
			document.getElementById('divuploadpdf').style.display='';
			if (chatpdf.status == 200 || chatpdf.status == 304) {
				document.getElementById('divuploadpdf').innerHTML = chatpdf.responseText;
			} else {
				document.getElementById('divuploadpdf').innerHTML="Errore richiesta dati\n[" + chatpdf.responseText+"]";
			}
		}
	}

	function condividi_risorsa(nomefile,tipo) {
		var url="economia.asp?contenuto=condirisorsa&risorsa="+nomefile+"&tipo="+tipo;
		if (tipo=='pdf') {
			document.getElementById('condipdf').style.display='';
			document.getElementById('condipdf').innerHTML = "caricamento PDF..";
			document.getElementById('condilink').style.display='none';
		}
		else {
			document.getElementById('condilink').style.display='';
			document.getElementById('condilink').innerHTML = "caricamento link..";
			document.getElementById('condipdf').style.display='none';
		}
		if (window.XMLHttpRequest) {
			cercapdf = new XMLHttpRequest();
			cercapdf.onreadystatechange = function() {risultarisorsa(tipo);};
			cercapdf.open("GET", url, true);
			cercapdf.send(null);
		// IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			cercapdf = new ActiveXObject("Microsoft.XMLHTTP");
			if (cercapdf) {
				cercapdf.onreadystatechange = function() {risultarisorsa(tipo);};
				cercapdf.open("GET", url, true);
				cercapdf.send();
			}
		}
	}

	function risultarisorsa(tipo) {
		if (cercapdf.readyState == 4) {
			if (cercapdf.status == 200 || cercapdf.status == 304) {
				//document.getElementById('infochat').innerHTML="<i>nuova condivisione</i>";
				if (tipo=='pdf')
					document.getElementById('condipdf').innerHTML = cercapdf.responseText;
				else
					document.getElementById('condilink').innerHTML = cercapdf.responseText;
			} else {
				document.getElementById('condipdf').innerHTML="Errore richiesta dati\n["+cercapdf.responseText+"]";
			}
		}
	}

	function condividi_link() {
		//da fare
		document.getElementById('condilink').innerHTML="Condivisione link sito/pagina Web";
	}
	
	function PlaySound(soundObj) {
		var sound = document.getElementById(soundObj);
		sound.Play();
	}	
/*** fine funzioni CHAT AJAX *****/

function eventimese(nomeutente,vedimese,vedianno) {
	var url="economia.asp?contenuto=vedidati&tipo=calendario&nomeutente="+nomeutente+"&vedimese="+vedimese+"&vedianno="+vedianno;
	//document.getElementById('eventimese').innerHTML='Ricerca dati in corso..';
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		cercastud = new XMLHttpRequest();
		cercastud.onreadystatechange = function() {risultamese();};
		cercastud.open("GET", url, true);
		cercastud.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercastud = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercastud) {
			cercastud.onreadystatechange = function() {risultamese();};
			cercastud.open("GET", url, true);
			cercastud.send();
		}
	}
}

function risultamese() {
	if (cercastud.readyState == 4) {
		if (cercastud.status == 200 || cercastud.status == 304) {
			results = cercastud.responseText;
			document.getElementById('eventimese').innerHTML = results;
		} else {
			document.getElementById('eventimese').innerHTML="Errore nella richiesta dati\n["+cercastud.responseText+"]";
		}
	}
}

function cercastudente(codice) {
	var url="economia.asp?contenuto=datistudente&idstud="+codice;
	document.getElementById('datistudente').innerHTML='Ricerca dati in corso..';
	// native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		cercastud = new XMLHttpRequest();
		cercastud.onreadystatechange = function() {risultastudente();};
		cercastud.open("GET", url, true);
		cercastud.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercastud = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercastud) {
			cercastud.onreadystatechange = function() {risultastudente();};
			cercastud.open("GET", url, true);
			cercastud.send();
		}
	}
}

function risultastudente() {
	if (cercastud.readyState == 4) {
		if (cercastud.status == 200 || cercastud.status == 304) {
			results = cercastud.responseText;
			document.getElementById('datistudente').innerHTML = results;
		} else {
			document.getElementById('datistudente').innerHTML="Errore nella richiesta dati\n["+cercastud.responseText+"]";
		}
	}
}

function studentetesi(codice) {
	var url="economia.asp?contenuto=studetesi&username="+codice;
	document.getElementById('studetesi').style.display='';
	document.getElementById('studetesi').innerHTML = "ricerca in corso..";
	if (window.XMLHttpRequest) {
		cercastud = new XMLHttpRequest();
		cercastud.onreadystatechange = function() {risultastutesi();};
		cercastud.open("GET", url, true);
		cercastud.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		cercastud = new ActiveXObject("Microsoft.XMLHTTP");
		if (cercastud) {
			cercastud.onreadystatechange = function() {risultastutesi();};
			cercastud.open("GET", url, true);
			cercastud.send();
		}
	}
}

function risultastutesi() {
	if (cercastud.readyState == 4) {
		if (cercastud.status == 200 || cercastud.status == 304) {
			document.getElementById('studetesi').innerHTML = cercastud.responseText;
		} else {
			document.getElementById('studetesi').innerHTML="Errore richiesta dati\n("+cercastud.responseText+")";
		}
	}
}

// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
	if (cal.sel.id=='accadeoggi') {
		var vedidata=cal.sel.value.replace(/\//g, "_");
		location.href=('economia.asp?contenuto=accadeoggi&vedidata='+vedidata);
	}
	else
		cal.hide();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, dateFormat, img) {
	var el = document.getElementById(id);
	var elimg = document.getElementById(img);
	//alert("el: " + el);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(2009, 2030);	// min/max year allowed

		if (dateFormat)	// optional date format
		{
			cal.setDateFormat(dateFormat);
		}

		calendar.create();		// create a popup calendar
		calendar.parseDate(el.value); // set it to a new date
	}
	calendar.sel = el;				// inform it about the input field in use
	calendar.showAtElement(elimg);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

// GooglePlus render
  window.___gcfg = {lang: 'it'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
// end GPlus render
