// Tabella attivitā
var ActivityTable = {
	init: function() {
		this.findAdder();
		this.findRemover();
	},

	findAdder: function() {
		if($('add-activity')) {
			$('add-activity').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.activity-row');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				newTr = rowTemplate.clone(true, false);
				
				// Catturo i 4 campi input
				tds = newTr.getChildren();
				firstCellChildren = tds[0].getChildren();
				newIdaIn = firstCellChildren[0];
				newSeqIn = firstCellChildren[1];
				newActIn = tds[1].getFirst();
				newAvPrevIn = tds[2].getFirst();
				newAvEffIn = tds[3].getFirst();
				newRemover = tds[4].getFirst();
				
				// Aggiorno id ed i valori dei 4 campi input
				newIdaIn.setProperty('value', '');
				newSeqIn.setProperty('value', newRow + 1);
				
				newActIn.setProperty('value', '');
				newActIn.setProperty('readonly', '');
				
				newAvPrevIn.setProperty('value', '');
				newAvPrevIn.setProperty('readonly', '');
				
				newAvEffIn.setProperty('value', '');
				newAvEffIn.setProperty('readonly', '');
				
				newRemover.getParent().setProperty('title', 'Rimuovi l\'attivit&agrave;');
				
				// Aggiungo la riga
				newTr.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row').setProperty('value', newRow + 1);
				
				// Riattivo remover
				ActivityTable.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				ActivityTable.findRemover();
			});
		}
	},

	findRemover: function() {
		if($$('a.remove-activity')) {
			
			$$('a.remove-activity').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					trToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					tableaActivity = trToRemove.getParent();
					
					// Nascondo la riga
					trToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
					
					// Ciclo su tutti gli input seq
					seqs = $$('input.seq');
					for(i = 0; i < seqs.length; i++) {
						
						// Aggiorno codice attivitā secondo ordine
						seqs[i].setProperty('value', i + 1);
					}
					
					// Decremento contatore righe
					rowCount = parseInt($('row').getProperty('value')); 
					$('row').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(tableaActivity.getChildren().length <= 2){
					
						// Elimino tutti i remover
						ActivityTable.hideRemovers();						
					}
				});
			});
			
			if($$('a.remove-activity').length == 1) {
				this.hideRemovers();
			}
		}
	},
	
	showRemovers: function() {
		$$('a.remove-activity').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-activity').setStyle('display', 'none');
	}
}

// Tabella sedi
var SediTable = {
	init: function() {
		this.findAdder();
		this.findRemover();
	},

	findAdder: function() {
		if($('sedi-adder')) {
			$('sedi-adder').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row_sede').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.sede-row');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				divForm = rowTemplate.clone(true, false);
				
				// Catturo i 6 campi input
				pForms = divForm.getChildren();
				newSedeIn = pForms[0].getLast();
				newServiziIn = pForms[1].getLast();
				newDataAvvIn = pForms[2].getLast();
				newSportelliIn = pForms[3].getLast();
				newTotemIn = pForms[4].getLast();
				newTouchPadIn = pForms[5].getLast();
				newRemover = pForms[6].getLast();
				
				// Aggiorno id ed i valori dei 6 campi input
				newSedeIn.setProperty('value', '');
				newServiziIn.setProperty('value', '');
				newSportelliIn.setProperty('value', '');
				newTotemIn.setProperty('value', '');
				newTouchPadIn.setProperty('value', '');
				newDataAvvIn.setProperty('value', '');
				
				// Title per Data Avviamento 
				newDataAvvIn.getParent().setProperty('title', 'Formato gg/mm/aaaa');
				newRemover.getParent().setProperty('title', 'Rimuovi la sede');
				
				// Aggiungo la riga
				divForm.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row_sede').setProperty('value', newRow + 1);
				
				// Riattivo remover
				SediTable.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				SediTable.findRemover();
			});
		}
	},

	findRemover: function() {

		if($$('a.remove-sede')) {
			
			$$('a.remove-sede').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					divToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					divSedi = divToRemove.getParent();
					
					// Nascondo la riga
					divToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
										
					// Decremento contatore righe
					rowCount = parseInt($('row_sede').getProperty('value')); 
					$('row_sede').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(divSedi.getChildren().length <= 1){
					
						// Elimino tutti i remover
						SediTable.hideRemovers();						
					}
				});
			});
			
			if($$('a.remove-sede').length == 1) {
				this.hideRemovers();
			}
		}

	},
	
	showRemovers: function() {
		$$('a.remove-sede').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-sede').setStyle('display', 'none');
	}

}

//Tabella servizi web
var WebServiceTable = {
	init: function() {
		this.findAdder();
		this.findRemover();
	},

	findAdder: function() {
		if($('add-servizio-web')) {
			$('add-servizio-web').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row_servizio_web').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.servizio-web-row');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				newTr = rowTemplate.clone(true, false);
				
				// Catturo i 2 campi input
				tds = newTr.getChildren();
				newServiceIn = tds[0].getFirst();
				newDataAvvIn = tds[1].getFirst();
				newRemover = tds[2].getFirst();
				
				// Aggiorno id ed i valori dei 4 campi input
				newServiceIn.setProperty('value', '');
				newDataAvvIn.setProperty('value', '');
				
				// Title per Data Avviamento 
				newDataAvvIn.setProperty('title', 'Formato gg/mm/aaaa');
				newRemover.getParent().setProperty('title', 'Rimuovi il servizio;');
				
				// Aggiungo la riga
				newTr.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row_servizio_web').setProperty('value', newRow + 1);
				
				// Riattivo remover
				WebServiceTable.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				WebServiceTable.findRemover();
			});
		}
	},

	findRemover: function() {
		if($$('a.remove-servizio-web')) {
			
			$$('a.remove-servizio-web').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					trToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					tableaWebServices = trToRemove.getParent();
					
					// Nascondo la riga
					trToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
										
					// Decremento contatore righe
					rowCount = parseInt($('row_servizio_web').getProperty('value')); 
					$('row_servizio_web').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(tableaWebServices.getChildren().length <= 2){
					
						// Elimino tutti i remover
						WebServiceTable.hideRemovers();						
					}
				});
			});
			
			if($$('a.remove-servizio-web').length == 1) {
				this.hideRemovers();
			}
		}
	},
	
	showRemovers: function() {
		$$('a.remove-servizio-web').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-servizio-web').setStyle('display', 'none');
	}
}

//Tabella servizi telefonici
var PhoneServiceTable = {
	init: function() {
		this.findAdder();
		this.findRemover();
	},

	findAdder: function() {
		if($('add-servizio-tel')) {
			$('add-servizio-tel').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row_servizio_tel').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.servizio-tel-row');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				newTr = rowTemplate.clone(true, false);
				
				// Catturo i 2 campi input
				tds = newTr.getChildren();
				newServiceIn = tds[0].getFirst();
				newDataAvvIn = tds[1].getFirst();
				newRemover = tds[2].getFirst();
				
				// Aggiorno id ed i valori dei 4 campi input
				newServiceIn.setProperty('value', '');
				newDataAvvIn.setProperty('value', '');
				
				// Title per Data Avviamento 
				newDataAvvIn.setProperty('title', 'Formato gg/mm/aaaa');
				newRemover.getParent().setProperty('title', 'Rimuovi il servizio;');
				
				// Aggiungo la riga
				newTr.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row_servizio_tel').setProperty('value', newRow + 1);
				
				// Riattivo remover
				PhoneServiceTable.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				PhoneServiceTable.findRemover();
			});
		}
	},

	findRemover: function() {
		if($$('a.remove-servizio-tel')) {
			
			$$('a.remove-servizio-tel').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					trToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					tableaTelServices = trToRemove.getParent();
					
					// Nascondo la riga
					trToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
										
					// Decremento contatore righe
					rowCount = parseInt($('row_servizio_tel').getProperty('value')); 
					$('row_servizio_tel').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(tableaTelServices.getChildren().length <= 2){
					
						// Elimino tutti i remover
						PhoneServiceTable.hideRemovers();						
					}
				});
			});
			
			if($$('a.remove-servizio-tel').length == 1) {
				this.hideRemovers();
			}
		}
	},
	
	showRemovers: function() {
		$$('a.remove-servizio-tel').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-servizio-tel').setStyle('display', 'none');
	}
}

//Tabella sedi
var RisultatiTable = {
	init: function() {
		this.findAdder();
		this.findRemover();
	},

	findAdder: function() {
		if($('risultati-adder')) {
			$('risultati-adder').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row_risattesi').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.risultati-row');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				divForm = rowTemplate.clone(true, false);
				
				// Catturo i 6 campi input
				pForms = divForm.getChildren();
				newIdtIn = pForms[0].getFirst();
				newRisAttesiIn = pForms[0].getLast();
				newIndicatoriIn = pForms[1].getLast();
				newTargetIn = pForms[2].getLast();
				newRisultatiIn = pForms[3].getLast();
				newRemover = pForms[4].getLast();
				
				// Aggiorno id ed i valori dei 6 campi input
				newIdtIn.setProperty('value', '');
				newRisAttesiIn.setProperty('value', '');
				newIndicatoriIn.setProperty('value', '');
				newTargetIn.setProperty('value', '');
				newRisultatiIn.setProperty('value', '');
				
				// Title 
				newRemover.getParent().setProperty('title', 'Rimuovi il risultato');
				
				// Aggiungo la riga
				divForm.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row_risattesi').setProperty('value', newRow + 1);
				
				// Riattivo remover
				RisultatiTable.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				RisultatiTable.findRemover();
			});
		}
	},

	findRemover: function() {

		if($$('a.remove-risultato')) {
			
			$$('a.remove-risultato').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					trToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					tableaActivity = trToRemove.getParent();
					
					// Nascondo la riga
					trToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
										
					// Decremento contatore righe
					rowCount = parseInt($('row_risattesi').getProperty('value')); 
					$('row_risattesi').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(tableaActivity.getChildren().length <= 2){
					
						// Elimino tutti i remover
						RisultatiTable.hideRemovers();						
					}

				});
			});
			
			if($$('a.remove-risultato').length == 1) {
				this.hideRemovers();
			}
		}

	},
	
	showRemovers: function() {
		$$('a.remove-risultato').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-risultato').setStyle('display', 'none');
	}

}

// Mon2 Abilita/Disabilita entita ritardo
var RitardoFlag = {
	init: function() {
		
		if($('tempiprog-flag') && $('ritardo-flag')) {

			// Init stato disabilitato
			RitardoFlag.setState(0);
			
			// Catturo labels sorelle
			labels = $('tempiprog-flag').getAllNext();
			
			// Attivo evento su selezione tempiprog-flag
			labels.each(function(e, i) {
				checkBox = e.getFirst();
				checkBox.addEvent('click', function(){
					RitardoFlag.setState(this.value);
				});
				
				// Se c'č un checkbox selezionato
				if(checkBox.checked) {
					
					// Modifico stato
					RitardoFlag.setState(checkBox.getProperty('value'));
				}

			});
		}
	},
	
	setState: function(state) {
		if(state != '23') {
			if(!($('ritardo-flag').hasClass('disabled'))){
				$('ritardo-flag').addClass('disabled');
			}
			
			// Disabilito radio
			labels = $('ritardo-flag').getAllNext();
			labels.each(function(e, i){
				e.getFirst().setProperty('disabled', 'disabled');
				
				if(state != 0) {
					e.getFirst().checked = false;
				}
			});
			
		} else {
			if($('ritardo-flag').hasClass('disabled')){
				$('ritardo-flag').removeClass('disabled');
			}

			// Attivo radio
			labels = $('ritardo-flag').getAllNext();
			labels.each(function(e, i){
				e.getFirst().setProperty('disabled', '');
			});
		}
	}
}

//Tabella attivitā Mon 2
var ActivityTableMon2 = {
	init: function() {
		this.initOutput();
		this.findAdder();
		this.findRemover();
	},

	initOutput: function() {
		if($('activity-table-mon2')) {
		
			// Catturo righe attivitā
			trList = $('activity-table-mon2').getElements('tr.activity-row-mon2');
			
			// Per ogni riga
			trList.each(function(tr, i){
	
				tds = tr.getChildren();
				
				// Catturo figlio input del quarto td
				tdOut = tds[4];
				outField = tdOut.getFirst(); 
								
				// Catturo figlio input del terzo td
				tdAv = tds[3];
				avField = tdAv.getFirst();
				
				// Init textarea out
				ActivityTableMon2.enableOutput(outField, parseInt(avField.getProperty('value')) == 100)
				
				// Attivo evento su modifica avanzamento
				avField.addEvent('change', function(){
					
					// Risalgo al tr
					trRoot = this.getParent().getParent();
					
					// Catturo textarea output
					tdOutRel = trRoot.getChildren();
					tdOutRel = tdOutRel[4];
					outRel = tdOutRel.getFirst(); 
				
					// Abilito/Disabilito textarea
					ActivityTableMon2.enableOutput(outRel, parseInt(this.getProperty('value')) == 100)
					
				});
				
			});			
		}
	},
	

	// Abilita/Disabilita output field in input
	enableOutput: function(outputField, enable) {
		if(enable) {
			outputField.setProperty('readonly', '');
			
			if(outputField.hasClass('disabled')) {
				outputField.removeClass('disabled')
			}
			
			
			
		} else {
			outputField.setProperty('readonly', 'readonly');
			outputField.setProperty('value', '');
			
			if(!outputField.hasClass('disabled')) {
				outputField.addClass('disabled')
			}
		}
	},
	
	findAdder: function() {
		if($('add-activity-mon2')) {
			$('add-activity-mon2').addEvent('click', function(event){
				
				// Fermo evento
				new Event(event).stop();

				// Catturo indice per corrente riga
				newRow = parseInt($('row').getProperty('value'));
				
				// Preparo una nuova riga come clone della precedente
				rowTemplate = $$('.activity-row-mon2');
				rowTemplate = rowTemplate[rowTemplate.length - 1];
				newTr = rowTemplate.clone(true, false);
				
				// Catturo i 4 campi input
				tds = newTr.getChildren();
				firstCellChildren = tds[0].getChildren();
				newIdaIn = firstCellChildren[0];
				newSeqIn = firstCellChildren[1];
				newActIn = tds[1].getFirst();
				newAvPrevIn = tds[2].getFirst();
				newAvEffIn = tds[3].getFirst();
				newOutIn = tds[4].getFirst();
				newRemover = tds[5].getFirst();
				
				// Aggiorno id ed i valori dei 4 campi input
				newIdaIn.setProperty('value', '');
				newSeqIn.setProperty('value', newRow + 1);
				newActIn.setProperty('value', '');
				newAvPrevIn.setProperty('value', '');
				newAvEffIn.setProperty('value', '');
				newOutIn.setProperty('value', '');
				newRemover.getParent().setProperty('title', 'Rimuovi l\'attivit&agrave;');
				
				// Aggiungo la riga
				newTr.injectAfter(rowTemplate);
				
				// Incremento contatore righe
				$('row').setProperty('value', newRow + 1);
				
				// Riattivo remover
				ActivityTableMon2.showRemovers();
				
				// Riinizializzo tooltip
				ToolTips.init();
				
				// Aggiungo rimozione a nuova riga
				ActivityTableMon2.findRemover();
				
				// Ricontrollo output
				ActivityTableMon2.initOutput();
			});
		}
	},

	findRemover: function() {
		if($$('a.remove-activity-mon2')) {
			
			$$('a.remove-activity-mon2').each(function(el){
				
				// Ripulisco eventi
				el.removeEvents('click');
				
				// Attivo funzione on click
				el.addEvent('click', function(event){
					
					// Fermo evento
					new Event(event).stop();		

					// Catturo tr
					trToRemove = this.getParent().getParent();
					
					// Catturo la tabella
					tableaActivity = trToRemove.getParent();
					
					// Nascondo la riga
					trToRemove.dispose();
					
					// Nascondo tutti i tooltip attivi
					$$('div.tip').getParent().setStyle('visibility', 'hidden');
					
					// Ciclo su tutti gli input seq
					seqs = $$('input.seq');
					for(i = 0; i < seqs.length; i++) {
						
						// Aggiorno codice attivitā secondo ordine
						seqs[i].setProperty('value', i + 1);
					}
					
					// Decremento contatore righe
					rowCount = parseInt($('row').getProperty('value')); 
					$('row').setProperty('value', rowCount - 1);
					
					// Controllo se c'č solo una riga (+ intestazione = 2)
					if(tableaActivity.getChildren().length <= 2){
					
						// Elimino tutti i remover
						ActivityTable.hideRemovers();						
					}
				});
			});
			
			if($$('a.remove-activity-mon2').length == 1) {
				this.hideRemovers();
			}
		}
	},
	
	showRemovers: function() {
		$$('a.remove-activity-mon2').setStyle('display', 'inline');
	},
	
	hideRemovers: function() {
		$$('a.remove-activity-mon2').setStyle('display', 'none');
	}
}

// Attivazione domanda su form 5
var AttivaDomandaRitardo = {
	init: function() {
		if($('uploadform-pirtre')) {
			$$('input[name=tempiprog]').addEvent('click', function(){
				AttivaDomandaRitardo.upd();
			});
			//tempiprog_23
			
			// Init
			AttivaDomandaRitardo.upd();
		}
	},
	
	upd: function(){
		if($('tempiprog_23').checked) {

			// Attivo domanda ritardo
			$$('input[name=ritardo]').setProperty('disabled', false);
			
		} else {

			// Disattivo domanda ritardo
			$$('input[name=ritardo]').setProperty('disabled', 'disabled');

		}
	}
}

// Alert in caso di errore
var ErrorAlert = {
	init: function() {
		if($$('.shwerror') && $$('.shwerror').length > 0) {
			alert('I dati non sono stati salvati, si č verificato un problema nella compilazione.\nRivedere cortesemente le risposte fornite: le domande interessate dal problema sono evidenziate in rosso');
		}
	}
}

// Select provincia autopopolata su selezione di regione
var ProvinceRegioni = {
	init: function() {
		if($('regione') && $('provincia')) {
			$('regione').addEvent('change', function(){

				// Invio richiesta a servizio
				// per caricamento dati province
				regione = $('regione').getProperty('value');
				var provinceJSON = new Request.JSON({
					
					url:'province.php',
					//all-if-any-member
					onSuccess: function(responseJSON, responseText) {
						var province = responseJSON;

						var provinciaSelect = $('provincia');
						
						// Svuoto select province
						provinciaSelect.getChildren().dispose();
						
						// Preparo option per selezione base
						optionBase = new Element('option', {
							'html': 'Seleziona',
						    'value': '0'
						});
						
						// Aggiungo a select
						provinciaSelect.adopt(optionBase);
						
						for(i = 0; i < province.length; i++) {
							provincia = province[i];
							
							// Preparo option
							optionProvincia = new Element('option', {
								'html': provincia.provincia,
							    'value': provincia.id
							});
							
							// Aggiungo a select
							provinciaSelect.adopt(optionProvincia);
						}						
					}
				
				}).post({'regione': regione});
			});
		}
	}
}

var PremioQForm = {
	init: function() {
		
		// Init visibilitā campi in funzione
		// dello stato dei radio "Tipo di candidatura"
		if($('q_2_201') && $('premioq-amministrazione-fields') &&
				$('q_2_202') && $('premioq-unita-fields')) {
			
			if(!$('q_2_201').checked) {
				$('premioq-amministrazione-fields').slide('hide');	
			}

			if(!$('q_2_202').checked) {
				$('premioq-unita-fields').slide('hide');	
			}

			$('q_2_201').addEvent('click', function(){
				$('premioq-amministrazione-fields').slide('in');
				$('premioq-unita-fields').slide('out');
			});
			
			$('q_2_202').addEvent('click', function(){
				$('premioq-amministrazione-fields').slide('out');
				$('premioq-unita-fields').slide('in');
			});
		}
	}
}

//Event on domready
addEvent("domready", function() {
	ActivityTable.init();	
	SediTable.init();
	WebServiceTable.init();
	PhoneServiceTable.init();
	RisultatiTable.init();
	RitardoFlag.init();
	ActivityTableMon2.init();
	AttivaDomandaRitardo.init();
	ProvinceRegioni.init();
	PremioQForm.init();
	ErrorAlert.init();
});

