<%@ include file="/project/include.jsp" %>

<script type="text/javascript">
	function switchTariffarioPers(value) {
		mostraTdTariffarioPersonalizzato(value);
	}

	function onChangeTariffarioPrestazioniStd() {
		showHideLookupViewTariffarioStd();
		showHideFieldsetInfoISEETarUt();
	}

	function showHideLookupViewTariffarioStd() {
		var elemA = document.getElementById('showTariffStd_edit');
		if (elemA) {
			var idTipoIntervento = getIdTipoIntervento();
			var idTariffario = getComboValueById('idTariffarioPrestazioni');
	
			var show = idTariffario && idTariffario != '' && idTipoIntervento != null && idTipoIntervento!='';
			if (show) {
				elemA.style.display = '';
			} else {
				elemA.style.display = 'none';
			}
		}
	}
	
	function showHideFieldsetBuoni() {
		if (document.getElementById('divFieldsetBuoni') != null) {
			var idTipoIntervento = null;
			var tipoIntervento = document.getElementById('idTipoIntervento');
			if (tipoIntervento == null) {
				idTipoIntervento = cpGetMasterColumnValueOfCurrentRow('idTipoIntervento');
			} else {
				idTipoIntervento = tipoIntervento.options[tipoIntervento.selectedIndex].value;
			}
			if (idTipoIntervento && idTipoIntervento != '') {
				var buoniEnabled = jsLoadString('it.cedaf.icare.interventi.control.action.accreditamento.CheckGestioneBuoniAbilitataExecutor', '&idTipoIntervento=' + idTipoIntervento);
				if (buoniEnabled == 'true') {
					showHideFieldsetBuoni1(true);
				} else {
					showHideFieldsetBuoni1(false);
				}
			} else {
				showHideFieldsetBuoni1(false);
			}
		}
	}

	function showHideFieldsetInfoISEETarUt() {
		var div_ = document.getElementById('divFieldsetInfoISEETarUt');
		if (div_ != null) {
			var show = false;
			var idTariffario = null;
			var tariffario = document.getElementById('idTariffarioPrestazioni');
			if (tariffario && tariffario.options != null && tariffario.options.length > 0) {
				idTariffario = tariffario.options[tariffario.selectedIndex].value;
				if (idTariffario && idTariffario != '') {
					var params = 'idTariffarioPrestazioni=' + idTariffario + shellGetSelectedRowParam();
					var showISEE = jsLoadString('it.cedaf.icare.interventi.control.action.ctuisee.CheckGestioneTariffeUtenteRelISEEExecutor', params);
					show = showISEE == 'true';
				}
			} else {
				var params = 'idIntervento=' + cpGetMasterColumnValueOfCurrentRow('id') + shellGetSelectedRowParam();
				var showISEE = jsLoadString('it.cedaf.icare.interventi.control.action.ctuisee.CheckGestioneTariffeUtenteRelISEEExecutor', params);
				show = showISEE == 'true';
			}
			_showHideFieldsetInfoISEETarUt(show);
		}		
	}

	function _showHideFieldsetInfoISEETarUt(show) {
		var div_ = document.getElementById('divFieldsetInfoISEETarUt');
		if (div_ != null) {
			if (show) {
				div_.style.display = '';
			} else {
				div_.style.display = 'none';
			}	
		}		
	}
	
	function showHideFieldsetBuoni1(show) {
		if (show) {
			document.getElementById('divFieldsetBuoni').style.display = '';
		} else {
			document.getElementById('divFieldsetBuoni').style.display = 'none';
		}	
	}
	function mostraTdTariffarioPersonalizzato(value) {
		var tdStandard = document.getElementById('tdTarStd');
		var tdCustom = document.getElementById('tdTarCust');		
		if (tdStandard) {
			if (value) {
				var tarMod = '${dto_TariffarioModificabile}';
				if (tarMod=='true') {
					tdStandard.style.display = 'none';
					tdCustom.style.display = ''
				}	
			} else {
				tdStandard.style.display = '';
				tdCustom.style.display = 'none';
				
				var idTariffario = document.getElementById('id_tariffarioLookup');
				var nomeTariffario = document.getElementById('denominazione_tariffarioLookup');
				idTariffario.value = '';
				nomeTariffario.value = '';
			}
		}
		showHideLookupViewTariffarioStd();
	}
	
	function mostraRadioTariffario(value) {
		var trRadioTariffario = document.getElementById('trRadioTariffario');
		var rdTariffarioCustomSi = document.getElementById('tariffarioCustomId_0');
		var rdTariffarioCustomNo = document.getElementById('tariffarioCustomId_1');
		if (trRadioTariffario) {
			if (value == 'noRadio_ente') {
				trRadioTariffario.style.display = 'none';
				rdTariffarioCustomSi.checked = false;
				rdTariffarioCustomNo.checked = true;
				mostraTdTariffarioPersonalizzato(false);
			} else if (value == 'noRadio_custom') {
				trRadioTariffario.style.display = 'none';
				rdTariffarioCustomSi.checked = true;
				rdTariffarioCustomNo.checked = false;
				mostraTdTariffarioPersonalizzato(true);
			} else if (value == 'showRadio') {
				trRadioTariffario.style.display = '';
				if (!rdTariffarioCustomSi.checked && !rdTariffarioCustomNo.checked) {					
					rdTariffarioCustomSi.checked = false;
					rdTariffarioCustomNo.checked = true;
					mostraTdTariffarioPersonalizzato(false);
				} else {
					rdTariffarioCustomSi.checked = true;
					rdTariffarioCustomNo.checked = false;
					mostraTdTariffarioPersonalizzato(true);
				}
			}						
		} 
	}
	
	function pulisciRadioTariffario() {
		var rdTariffarioCustomSi = document.getElementById('tariffarioCustomId_0');
		var rdTariffarioCustomNo = document.getElementById('tariffarioCustomId_1');
		rdTariffarioCustomSi.checked = false;
		rdTariffarioCustomNo.checked = false;
	}
	
	
	function lookupUpdateTariffario(showMode) {
		var idIntervento = cpGetMasterColumnValueOfCurrentRow('id');
		var functionIdentifier = 'interventi.tariffarioPrestazioni';
		var init = 'it.cedaf.icare.interventi.control.initializer.TariffarioPrestazioniFromInterventoInitializer';
		var winOptions = getCenterWindowOptionsByPerc(75);
		var sm = showMode ? '&showMode=true' : '';
		buiOpenNewDataManagementAsChildInWindow(bui_datamanagement.getKey(), functionIdentifier, 
			'&init=' + init + shellGetSelectedRowParam() + '&shell_no_header=true&idIntervento=' + idIntervento + sm, 'modifyTariffario', 
			winOptions + ', ' + SHELL_WIN_MODAL_OPTIONS);
	}

	function lookupViewTariffarioStd() {
		var idTipoIntervento = getIdTipoIntervento();
		var idTariffario = getComboValueById('idTariffarioPrestazioni');

		if (idTariffario && idTariffario != '' && idTipoIntervento != null && idTipoIntervento!='') {
			var functionIdentifier = 'interventi.tariffarioPrestazioni';
			var init = 'it.cedaf.icare.interventi.control.initializer.ViewTariffarioPrestazioniStandardFromInterventoInitializer';
			var winOptions = getCenterWindowOptionsByPerc(75);
			buiOpenNewDataManagementAsChildInWindow(bui_datamanagement.getKey(), functionIdentifier, 
					'&init=' + init + shellGetSelectedRowParam() + '&shell_no_header=true&shell_win_level=' + (winLevel + 1) + '&idTariffarioPrestazioni=' + idTariffario + '&idTipoIntervento=' + idTipoIntervento, 'viewTariffarioStd', 
					winOptions + ', ' + SHELL_WIN_MODAL_OPTIONS);
		
		} else {
			alert('Selezionare un tariffario prestazioni.');
			return;
		}
	}
	
	<bui:out modes="view">
		function eformat_cpmt_tariffarioPersonalizzato(element, value, name) {
			var elemA = document.getElementById('modTariff');
			var elemSa = document.getElementById('showTariff');
			if (elemA) {
				elemA.style.display = (value == 'si' ? '' :'none');
			}	
			if (elemSa) {
				elemSa.style.display = (value == 'si' ? 'none' :'');
			}
			element.innerHTML = '';								
		}
	</bui:out>
</script>

<shell:fieldset title="${j:bundle('LBL_interventi_intervento_enteErog_SET')}">
	<table align="center" width="100%" border="0">
		<tr>
			<td width="50%" valign="top">
				<table>
					<tr>
						<td class="form-label">
							<shell:label prop="enteErogatore" forceRequired="true"/>
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<j:tile name="shell.plaintext" prop="enteErogatore" />
							</bui:out>
							<bui:out modes="create">
								<j:bind prop="enteErogatore">
									<j:select class="form-input" id="idEnteErogatore" emptyOptionDescr="" onChange="javascript:onChangeEnteOStruttura(true);" />
									<shell:error />
								</j:bind>
							</bui:out>			
							<bui:out modes="update">
								<j:tile name="shell.plaintext" prop="enteErogatore" />	
								<j:bind prop="enteErogatore">
									<j:hidden id="idEnteErogatoreHdn" />
								</j:bind>									
							</bui:out>
						</td>										
			 		</tr>
			 		<bui:out modes="create, update">
			 			<j:bind prop="tariffarioCustom"><c:set var="varTarifCustom" value="${j:getStatus().value}"/></j:bind>
				 		<tr id="trRadioTariffario" ${dto_showSceltaTariffarioCustom}>
				 			<td class="form-label">
				 				<shell:label prop="tariffarioCustom"/>
				 			</td>
				 			<td class="form-values">
					 			<j:bind prop="tariffarioCustom">	
							    	<j:radio id="tariffarioCustomId_0" displayValue="si" onclick="switchTariffarioPers(true);"/>${j:bundle('LBL_si')}
									<j:radio id="tariffarioCustomId_1" displayValue="no" onclick="switchTariffarioPers(false);"/>${j:bundle('LBL_no')}
									<shell:error />
								</j:bind>
				 			</td>					 			
				 		</tr>
			 		</bui:out>
			 		<tr>
			 			<td class="form-label">
							<shell:label prop="tariffarioPrestazioni" forceRequired="true"/>
						</td>
						<bui:out modes="view">
							<td class="form-values">
								<j:tile name="shell.plaintext" prop="tariffarioPrestazioni" /> &nbsp;
								<a id="modTariff" href="javascript:lookupUpdateTariffario();" style="display:none"><img id="modTariff_img" src="${j:getResourceUrlOfModule('shell', 'img/lookup/lookup.gif')}" alt="Modifica tariffario" align="absmiddle" border="0"></a>
								<a id="showTariff" href="javascript:lookupUpdateTariffario(true);" style="display:none"><img src="${j:getResourceUrlOfModule('shell', 'img/lookup/lookup.gif')}" alt="Mostra tariffario" align="absmiddle" border="0"></a>
								<j:tile name="shell.plaintext" prop="tariffarioPersonalizzato" />
							</td>
						</bui:out>
						<bui:out modes="create, update">
							<c:choose>
								<c:when test="${dto_TariffarioModificabile == 'true'}">
									<td id="tdTarStd" class="form-values" ${varTarifCustom == 'false' ? '' : 'style="display:none"'}>
										<j:bind prop="tariffarioPrestazioni">
											<j:select class="form-input" id="idTariffarioPrestazioni" emptyOptionDescr="" onchange="javascript:onChangeTariffarioPrestazioniStd();"/>
											<shell:error />
										</j:bind>
										<a id="showTariffStd_edit" href="javascript:lookupViewTariffarioStd();" style="display:none"><img src="${j:getResourceUrlOfModule('shell', 'img/lookup/lookup.gif')}" alt="Mostra tariffario" title="Mostra tariffario" align="absmiddle" border="0"></a>
									</td>	
									<td id="tdTarCust" class="form-values" ${varTarifCustom == 'true' ? '' : 'style="display:none"'}>										
										<j:bind prop="nomeTariffarioCustom">
											<j:text class="form-normal-text" readonly="true" id="denominazione_tariffarioLookup" />
										</j:bind>
										<j:bind prop="idTariffarioCustom">
											<j:hidden id="id_tariffarioLookup"/>
											<shell:error />
										</j:bind>
										<shell:lookup lookupId="tariffarioLookup" identifier="interventi.tariffarioPrestazioni" 
											init="it.cedaf.icare.interventi.control.initializer.TariffarioPrestazioniLookupInitializer" 	
											formParams="id_tariffarioLookup|inputId,idTipoIntervento|idTipoIntervento"										
											clearVisible="false" noCommitOnCreate="id=-1" />
									</td>																																		
								</c:when>
								<c:otherwise>									
									<td class="form-values">
										<j:tile name="shell.plaintext" prop="tariffarioPrestazioni" />
										<j:bind prop="tariffarioPrestazioni">
											<j:hidden />
										</j:bind>										
										<j:bind prop="nomeTariffarioCustom">
											<j:hidden id="denominazione_tariffarioLookup"/>
										</j:bind>
										<j:bind prop="idTariffarioCustom">
											<j:hidden id="id_tariffarioLookup"/>
										</j:bind>
										<c:if test="${dto_TariffarioModificabile == 'true'}">
											<shell:lookup lookupId="tariffarioLookup" identifier="interventi.tariffarioPrestazioni" 
											init="it.cedaf.icare.interventi.control.initializer.TariffarioPrestazioniLookupInitializer" 	
											formParams="id_tariffarioLookup|inputId,idTipoIntervento|idTipoIntervento"										
											clearVisible="false" noCommitOnCreate="id=-1" />
										</c:if>
									</td>
								</c:otherwise>
							</c:choose>							
						</bui:out>
			 		</tr>
			 	<icare:ifOptional prop="Aree Funzionali [p]">
 					<tr>
						<td class="form-label">
							<shell:label prop="areeFunzionali" />
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<shell:grid description="areeFunzionali" property="areeFunzionali" numOfRows="3" />
							</bui:out>
							<bui:out modes="create, update">
								<j:bind prop="areeFunzionali">
									<shell:swap swapId="idAreeFunzionali" />
								</j:bind>
							</bui:out>
						</td>
 					</tr>
 				</icare:ifOptional>	
			 	<icare:ifOptional prop="Convenzione Ente [p]">
 					<tr>
						<td class="form-label">
							<shell:label prop="convenzioneEnte" />
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<j:tile name="shell.plaintext" prop="convenzioneEnte" />
							</bui:out>
							<bui:out modes="create, update">
								<j:bind prop="convenzioneEnte">
									<j:select id="idConvenzioneEnte" class="form-input" emptyOptionDescr="" />
									<shell:error />
								</j:bind>
							</bui:out>
						</td>
 					</tr>
 				</icare:ifOptional>	 				
				</table>
			</td>
			<td width="50%">
				<table>
					<icare:ifOptional prop="Operatore Ente Erogatore [f]">
					<tr>
						<td class="form-label">
							<shell:label prop="opRifEnteErogatoreCognome" />
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<j:tile name="shell.plaintext" prop="opRifEnteErogatoreCognome" />
							</bui:out>
							<bui:out modes="create, update">
								<j:bind prop="opRifEnteErogatoreCognome">
									<j:text class="form-normal-text" />
									<shell:error />
								</j:bind>
							</bui:out>
						</td>
			 		</tr> 	
					<tr>
						<td class="form-label">
							<shell:label prop="opRifEnteErogatoreNome" />
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<j:tile name="shell.plaintext" prop="opRifEnteErogatoreNome" />
							</bui:out>
							<bui:out modes="create, update">
								<j:bind prop="opRifEnteErogatoreNome">
									<j:text class="form-normal-text" />
									<shell:error />
								</j:bind>
							</bui:out>
						</td>
			 		</tr> 	
					<tr>
						<td class="form-label">
							<shell:label prop="opRifEnteErogatoreTipo" />
						</td>
						<td class="form-values">
							<bui:out modes="view">
								<j:tile name="shell.plaintext" prop="opRifEnteErogatoreTipo" />
							</bui:out>
							<bui:out modes="create, update">
								<j:bind prop="opRifEnteErogatoreTipo">
									<j:select class="form-input" emptyOptionDescr="" />
									<shell:error />
								</j:bind>
							</bui:out>
						</td>
			 		</tr>
			 		</icare:ifOptional>
				</table>
			</td>
		</tr>				
	</table>
</shell:fieldset>
<j:tile name="interventi.contrattoMMG"/>
<c:choose>
	<c:when test="${dto_gestioneBuoniAbilitata == 'true'}">
		<j:tile name="interventi.buonoAttivazione"/>
	</c:when>
	<c:otherwise>
		<j:tile name="interventi.buonoAttivazioneBase"/>
	</c:otherwise>
</c:choose>
<div id="divFieldsetInfoISEETarUt" style="display:none">
<shell:fieldset title="Informazioni ISEE per calcolo Tariffe utente">
	<table align="center" width="100%" border="0">
 		<tr>
			<td class="form-label">
				<shell:label prop="situazioneISEE" />
			</td>
			<td class="form-values">
				<bui:out slave="${_slave}" modes="view">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="situazioneISEE" />
				</bui:out>
				<bui:out slave="${_slave}" modes="create,update">
					<j:bind prop="situazioneISEE">
						<j:valueSetIterator>
							<j:radio/>${j:getValueSetItem().description}&nbsp;&nbsp;
						</j:valueSetIterator>
						<j:radio displayValue=""/>${j:bundle('LBL_interventi_situazioneISEE_@NULL')}							
						<shell:error />
					</j:bind>	
				</bui:out>
			</td>
 		</tr>
		<tr>
			<td class="form-label">
				<shell:label prop="accettazioneTarUtISEEMax" />
			</td>
			<td class="form-values">
				<bui:out modes="view">
					<j:tile name="shell.plaintext" prop="accettazioneTarUtISEEMax" />
				</bui:out>
				<bui:out modes="create, update">
					<j:bind prop="accettazioneTarUtISEEMax">
						<j:radio displayValue="si"/>${j:bundle('LBL_si')}
						<j:radio displayValue="no"/>${j:bundle('LBL_no')}
						<shell:error />
					</j:bind>
				</bui:out>
			</td>
 		</tr>
 	</table>
</shell:fieldset>
</div>