//VARIABILI GLOBALI
var nomeCombo;

//CREAZIONE OGGETTO XMLHTTPREQUEST PER UTILIZZARE AJAX
var xmlHttp;
function createXMLHttpRequest() { 
	if (window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}
var xmlHttp1;
function createXMLHttpRequest1() { 
	if (window.ActiveXObject){
		xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
		xmlHttp1 = new XMLHttpRequest();
	}
}

/****************************************************************************************************/
/*                               TABELLA UFFICI SCHEDA BUDGET                                       */
/****************************************************************************************************/
function dettUffici() { 
	var budgetGenerale = document.getElementById('budgetGenerale').value;
	var budgetAreaX = document.getElementById('budgetAreaX').value;
	createXMLHttpRequest();
	xmlHttp.open("GET","forms/budget/dettUffici.php?budgetAreaX="+budgetAreaX+"&budgetGenerale="+budgetGenerale+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultDettUffici;
	xmlHttp.send(null);
}
function ResultDettUffici() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			TabellaDettUffici();
		}
	}
}
function TabellaDettUffici() { 
	var XMLResult = xmlHttp.responseText;
	//alert(XMLResult);
	document.getElementById('dettUffici').innerHTML=XMLResult;

}

/****************************************************************************************************/
/*                                  CARICA COMBO SCHEDA INIZIATIVE                                  */
/****************************************************************************************************/
function caricaCB(valore,nome) { 
	createXMLHttpRequest();
	nomeCombo = nome;
	if(nome=='Macrotipo'){
		xmlHttp.open("GET","forms/iniziativa/caricaCombo.php?SettForm="+valore+"&xxx="+Math.random(),true);
		//alert(nome+' '+valore);
	}
	if(nome=='Tipo'){
		xmlHttp.open("GET","forms/iniziativa/caricaCombo.php?Macrotipo="+valore+"&xxx="+Math.random(),true);
		//alert(nome+' '+valore);
	}
	if(nome=='Sottotipo'){
		xmlHttp.open("GET","forms/iniziativa/caricaCombo.php?Tipo="+valore+"&xxx="+Math.random(),true);
		//alert(nome+' '+valore);
	}
	xmlHttp.onreadystatechange = ResultCaricaCombo;
	xmlHttp.send(null);
}
function ResultCaricaCombo() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			caricaCombo();
		}
	}
}
function caricaCombo() { 
	var XMLResult = xmlHttp.responseXML;
	//var XMLResult = xmlHttp.responseText;
	//alert(XMLResult);
	var codice = XMLResult.getElementsByTagName('codice');
	//recupero la select dei comuni
	var comboGen = document.getElementById(nomeCombo);
	//svuoto la select dei comuni
	for(var i=comboGen.length-1;i>=0;i--)
		comboGen.remove(i);
	//scorro gli elementi del file xml
	for(var i=0;i<codice.length+1;i++) 
	{ 
		//Inserisco come primo elemento la voce seleziona
		if (i==0){
			var newSel = document.createElement('option');
			newSel.value = '';
			newSel.text = ' --- Seleziona --- ';
			comboGen.options[i]=new Option(newSel.text,newSel.value);
		}
		else {
			//recupero i vari elementi singoli
			var item = codice[i-1];
			//creo il nuovo elemento OPTION da aggiungere alla combo
			var NewOpt = document.createElement('option');
			NewOpt.value=item.getAttribute('value');
			NewOpt.text=item.firstChild.nodeValue;

			//Carico la combo
			comboGen.options[i]=new Option(NewOpt.text,NewOpt.value);
		}
	}
}

/****************************************************************************************************/
/*                         FUNZIONE PER INSERIRE DINAMICAMENTE LE EDIZIONI                          */
/****************************************************************************************************/
function visualizza_edizioni(numEdi){
	createXMLHttpRequest();
	var numEdizioni = document.getElementById('numEdi').value;
	xmlHttp.open("GET","forms/iniziativa/div_edizioni.php?numEdizioni="+numEdizioni+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultDivEdizioni;
	xmlHttp.send(null);
}
function ResultDivEdizioni() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			divEdizioni();
		}
	}
}
function divEdizioni() { 
	var XMLResult = xmlHttp.responseText;
	document.getElementById('edizioni_span').innerHTML=XMLResult;
}

/****************************************************************************************************/
/*                         FUNZIONE CHE VISUALIZZA LA TABELLA DEGLI ISCRITTI                        */
/****************************************************************************************************/
function tabellaIscritti(){
	iniziativa=document.getElementById('IDINI').value;
	edizione=document.getElementById('edizioneIscrizione').value;
	_idpad = document.getElementById('_idpad').value;
	_idel = document.getElementById('_idel').value;
	//document.getElementById('vaiIscrizione').alt='Torna all\'iscrizione';
	//document.getElementById('vaiIscrizione').title='Torna all\'iscrizione';
	document.getElementById('vaiIscrizione').href='../restrict/index.php?task=iscrizioni&_idpad='+_idpad+'&_idel='+_idel+'&edizioneIscrizione='+edizione+'&ID_INIZIATIVA='+iniziativa;
	//alert(document.getElementById('vaiIscrizione').href);
	//alert(document.getElementById('vaiIscrizione').alt);
	createXMLHttpRequest();
	var IDINI = document.getElementById('IDINI').value;
	var edizioneIscrizione =  document.getElementById('edizioneIscrizione').value;
	var _idpad = document.getElementById('_idpad').value;
	var _idel = document.getElementById('_idel').value;
	xmlHttp.open("GET","../forms/forms_gestione/tabellaIscritti.php?_idpad="+_idpad+"&_idel="+_idel+"&IDINI="+IDINI+"&edizioneIscrizione="+edizioneIscrizione+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultTabellaIscritti;
	xmlHttp.send(null);
}
function ResultTabellaIscritti() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			iscritti();
		}
	}
}
function iscritti() { 
	var XMLResult = xmlHttp.responseText;
	document.getElementById('iscrizioni').style.block='none';
	document.getElementById('contenitoreForm').innerHTML=XMLResult;
}

/****************************************************************************************************/
/*                            FUNZIONE CHE CARICA LA COMBO DELLE PROVINCE                           */
/****************************************************************************************************/
var cbProv;
function cbProvince(valore,id) { 
	cbProv=id;
	createXMLHttpRequest();
	var codRegione = valore;
	xmlHttp.open("GET","forms/ajax_php/caricaProvince.php?codRegione="+codRegione+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultCbProvince;
	xmlHttp.send(null);
}
function ResultCbProvince() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			caricaCbProvince();
		}
	}
}
function caricaCbProvince() { 
	var XMLResult = xmlHttp.responseXML;
	var codprov = XMLResult.getElementsByTagName('codprov');
	var comboProv = document.getElementById(cbProv);
	//svuoto la combo
	for(var i=comboProv.length;i>=0;i--)
		comboProv.options[i]=null;

	for(var i=0;i<codprov.length+1;i++) 
	{ 
		if(i==0){
			var NewOpt = document.createElement('option');
			NewOpt.value='';
			NewOpt.text=' -------- Seleziona -------- ';	
		}
		else {
			//recupero i vari elementi singoli
			var item = codprov[i-1];
			//creo il nuovo elemento OPTION da aggiungere alla combo
			var NewOpt = document.createElement('option');
			NewOpt.value=item.getAttribute('value');
			NewOpt.text=item.firstChild.nodeValue;
		}	
		//Carico la combo
		comboProv.options[i]=new Option(NewOpt.text,NewOpt.value);
	}
}
/****************************************************************************************************/
/****************************************************************************************************/
/*                            FUNZIONE CHE CARICA LA COMBO DEI COMUNI                               */
/****************************************************************************************************/
/****************************************************************************************************/
var cbCom;
function cbComuni(id,idCom) { 
	cbCom = idCom;
	//alert(idCom);
	//alert(id);
	var codProvince=id;
	createXMLHttpRequest();
	xmlHttp.open("GET","forms/ajax_php/caricaComuni.php?codProvince="+codProvince+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultCbComuni;
	xmlHttp.send(null);
}
function ResultCbComuni() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			caricaCbComuni();
		}
	}
}
function caricaCbComuni() { 
	var XMLResult = xmlHttp.responseXML;
	//var XMLResult = xmlHttp.responseText;
	//alert(XMLResult);
	var codcom = XMLResult.getElementsByTagName('codcom');
	var comboCom = document.getElementById(cbCom);
	//svuoto la combo
	for(var i=comboCom.length;i>=0;i--)
		comboCom.options[i]=null;

	for(var i=0;i<codcom.length+1;i++) 
	{ 
		if(i==0){
			var NewOpt = document.createElement('option');
			NewOpt.value='';
			NewOpt.text=' -------- Seleziona -------- ';	
		}
		else {
			//recupero i vari elementi singoli
			var item = codcom[i-1];
			//creo il nuovo elemento OPTION da aggiungere alla combo
			var NewOpt = document.createElement('option');
			NewOpt.value=item.getAttribute('value');
			NewOpt.text=item.firstChild.nodeValue;
		}
		//Carico la combo
		comboCom.options[i]=new Option(NewOpt.text,NewOpt.value);
	}
}
/****************************************************************************************************/
/****************************************************************************************************/
/*                         CARICA IL CAP IN BASE ALLA SCELTA DEL COMUNE                             */
/****************************************************************************************************/
/****************************************************************************************************/
//Carica il Cap in base alla scelta del Luogo di residenza
var CAP = '';
function caricaCap(codCom,textCap) { 
	createXMLHttpRequest();
	var LuogoResid = document.getElementById(codCom).value;
	CAP = textCap;
	xmlHttp.open("GET","forms/ajax_php/visualizzaCap.php?LuogoResid="+LuogoResid+"&xxx="+Math.random(),true);
	xmlHttp.onreadystatechange = ResultCaricaCap;
	xmlHttp.send(null);
}
function ResultCaricaCap() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			document.getElementById(CAP).value=xmlHttp.responseText;
		}
	}
}

/****************************************************************************************************/
/****************************************************************************************************/
/*                     CARICA LA DATA DI PROGRAMMAZIONE IN BASE ALL'EDIZIONE                        */
/****************************************************************************************************/
/****************************************************************************************************/
function selDataIscrizione() { 
	createXMLHttpRequest1();
	var ID_INIZ_EDIZIONI = document.getElementById('ediz').value;
	xmlHttp1.open("GET","forms/ajax_php/selDataIscrizione.php?ID_INIZ_EDIZIONI="+ID_INIZ_EDIZIONI+"&xxx="+Math.random(),true);
	xmlHttp1.onreadystatechange = ResultSelDataIscrizione;
	xmlHttp1.send(null);
}
function ResultSelDataIscrizione() { 
	if (xmlHttp1.readyState==4){
		if (xmlHttp1.status==200){
			if(xmlHttp1.responseText!=''){
				//document.getElementById('YD_010_DataIscrizione').readOnly=true;
				//document.getElementById('YD_010_DataIscrizione').className = 'readonly';
				document.getElementById('YD_010_DataIscrizione').value=xmlHttp1.responseText;
			}
			else { 
				//document.getElementById('YD_010_DataIscrizione').readOnly=false;
				//document.getElementById('YD_010_DataIscrizione').className = '';
				document.getElementById('YD_010_DataIscrizione').value='';			
			}
		}
	}
}
function caricaIscritti(edizioneIscrizione){
	createXMLHttpRequest1();
	//alert(edizioneIscrizione); return;
	xmlHttp1.open("GET","forms/ajax_php/caricaIscritti.php?edizioneIscrizione="+edizioneIscrizione+"&xxx="+Math.random(),true);
	xmlHttp1.onreadystatechange = ResultCaricaIscritti;
	xmlHttp1.send(null);
}
function ResultCaricaIscritti() { 
	if (xmlHttp1.readyState==4){
		if (xmlHttp1.status==200){
			caricaIsc();
		}
	}
}
function caricaIsc() { 
	var XMLResult = xmlHttp1.responseXML;
	//var XMLResult = xmlHttp1.responseText;
	//alert(XMLResult);
	var codisc = XMLResult.getElementsByTagName('codisc');
	var combo = document.getElementById('YN000_Responsabile_paaf');
	//svuoto la combo
	for(var i=combo.length;i>=0;i--)
		combo.options[i]=null;

	for(var i=0;i<codisc.length;i++) 
	{ 
		//recupero i vari elementi singoli
		var item = codisc[i];
		//creo il nuovo elemento OPTION da aggiungere alla combo
		var NewOpt = document.createElement('option');
		NewOpt.value=item.getAttribute('value');
		NewOpt.text=item.firstChild.nodeValue;
		//Carico la combo
		combo.options[i]=new Option(NewOpt.text,NewOpt.value);
	}
}

function divNumEdizioni(numEdi,numScheda) {
	//alert(numScheda);
	createXMLHttpRequest1();
	xmlHttp1.open("GET","forms/ajax_php/divNumEdizioni.php?numScheda="+numScheda+"&numEdi="+numEdi+"&xxx="+Math.random(),true);
	xmlHttp1.onreadystatechange = ResultDivNumEdizioni;
	xmlHttp1.send(null);
}
function ResultDivNumEdizioni() { 
	if (xmlHttp1.readyState==4){
		if (xmlHttp1.status==200){
			document.getElementById('divNumEdi').innerHTML=xmlHttp1.responseText;
		}
	}
}

function caricaConvenzionati (){
	createXMLHttpRequest1();
	xmlHttp1.open("GET","forms/ajax_php/caricaConvenzionati.php?xxx="+Math.random(),true);
	xmlHttp1.onreadystatechange = ResultCaricaConvenzionati;
	xmlHttp1.send(null);
}
function ResultCaricaConvenzionati() { 
	if (xmlHttp1.readyState==4){
		if (xmlHttp1.status==200){
			caricaConv();
		}
	}
}
function caricaConv(){
	var XMLResult = xmlHttp1.responseXML;
	//var XMLResult = xmlHttp1.responseText;
	//alert(XMLResult);
	var codconv = XMLResult.getElementsByTagName('codconv');
	var combo = document.getElementById('AniPerConv_abil');
	//svuoto la combo
	for(var i=combo.length;i>=0;i--)
		combo.options[i]=null;

	for(var i=0;i<codconv.length;i++) 
	{ 
		//recupero i vari elementi singoli
		var item = codconv[i];
		//creo il nuovo elemento OPTION da aggiungere alla combo
		var NewOpt = document.createElement('option');
		NewOpt.value=item.getAttribute('value')+"_"+item.getAttribute('dataini')+"_"+item.getAttribute('datafine')+"_"+item.getAttribute('stato')+"_"+item.getAttribute('tipologia');
		NewOpt.text=item.firstChild.nodeValue;
		if(document.getElementById('AniPerConv_abil_h').value == '')
		  document.getElementById('AniPerConv_abil_h').value = item.getAttribute('value')+"_"+item.getAttribute('dataini')+"_"+item.getAttribute('datafine')+"_"+item.getAttribute('stato')+"_"+item.getAttribute('tipologia');
		else
		  document.getElementById('AniPerConv_abil_h').value += ","+item.getAttribute('value')+"_"+item.getAttribute('dataini')+"_"+item.getAttribute('datafine')+"_"+item.getAttribute('stato')+"_"+item.getAttribute('tipologia');
		//Carico la combo
		combo.options[i]=new Option(NewOpt.text,NewOpt.value);
	}
	//alert(document.getElementById('AniPerConv_abil_h').value);
}

/***********************************************FINE*************************************************/





/****************************************************************************************************/
/****************************************************************************************************/
/*                  COSTRUISCE LA TABELLA DEGLI ISCRITTI AD UNA EDIZIONE                            */
/*                                 FUNZIONE NON PIU' UTILIZZATA                                     */
/****************************************************************************************************/
/****************************************************************************************************/
/*function tabellaIscritti(){
	iniziativa=document.getElementById('IDINI').value;
	edizione=document.getElementById('edizioneIscrizione').value;
	_idpad = document.getElementById('_idpad').value;
	_idel = document.getElementById('_idel').value;
	//document.getElementById('vaiIscrizione').alt='Torna all\'iscrizione';
	//document.getElementById('vaiIscrizione').title='Torna all\'iscrizione';
	document.getElementById('nascondi').style.visibility='hidden';
	if(document.getElementById('IDINIX').value!='' || (document.getElementById('IDINIX').value!='' && document.getElementById('IDINI')!='')){
		iniziativa = document.getElementById('IDINIX').value;
		//alert(1);
		document.getElementById('vaiIscrizione').href='index.php?_idpad='+_idpad+'&_idel='+_idel+'&edizioneIscrizione='+edizione+'&ID_INIZIATIVAX='+iniziativa;	
	}
	if(document.getElementById('IDINI')!='' && document.getElementById('IDINIX').value==''){
		//alert(2);
		document.getElementById('vaiIscrizione').href='index.php?_idpad='+_idpad+'&_idel='+_idel+'&edizioneIscrizione='+edizione+'&ID_INIZIATIVA='+iniziativa;
	}
	//alert(document.getElementById('vaiIscrizione').href);
	//alert(document.getElementById('vaiIscrizione').alt);
	createXMLHttpRequest();
	var edizioneIscrizione =  document.getElementById('edizioneIscrizione').value;
	var _idpad = document.getElementById('_idpad').value;
	var _idel = document.getElementById('_idel').value;
	if(document.getElementById('IDINIX')!=''){
		IDINIX = document.getElementById('IDINIX').value;
		xmlHttp.open("GET","forms/iscrizione/tabellaIscritti.php?_idpad="+_idpad+"&_idel="+_idel+"&IDINIX="+IDINIX+"&edizioneIscrizione="+edizioneIscrizione+"&xxx="+Math.random(),true);	
	}
	if(document.getElementById('IDINI')!=''){
		IDINI = document.getElementById('IDINI').value;
		xmlHttp.open("GET","forms/iscrizione/tabellaIscritti.php?_idpad="+_idpad+"&_idel="+_idel+"&IDINI="+IDINI+"&edizioneIscrizione="+edizioneIscrizione+"&xxx="+Math.random(),true);
	}		
	xmlHttp.onreadystatechange = ResultTabellaIscritti();
	xmlHttp.send(null);
}
function ResultTabellaIscritti() { 
	if (xmlHttp.readyState==4){
		if (xmlHttp.status==200){
			iscritti();
		}
	}
}
function iscritti() { 
	var XMLResult = xmlHttp.responseText;
	document.getElementById('iscrizioni').style.block='none';
	document.getElementById('contenitoreForm').innerHTML='';
	document.getElementById('contenitoreForm').innerHTML=XMLResult;
}*/

