<%@ include file="/project/include.jsp" %>	
 		
<script type="text/javascript">
	function calcolaPercentuale() {
		var totale = document.getElementById('totale').value;
		if (totale == '') {
			alert("Inserire l'importo disponibile");
			return;
		}
		
		var result = jsLoadString('it.cedaf.icare.customers.zcomalg.control.action.RidistribuzioneBandoAction', 'importo=' + totale + '&dmKey=' + bui_datamanagement.getKey());
		var msg = result.split(':');
		if (msg[0] == 'OK') {
			document.getElementById('percentuale').value = msg[1];
		} else {
			alert("Errore: " + msg[1]);
		}
	}

	function gotoStep0() {
		var event = 'zcomalg.ridistribuzione?step=0&dmKey=' + bui_datamanagement.getKey();
		juiceChangeLocation(event);
	}

	function gotoStep1() {
		var annoRif = document.getElementById('anno').value;
		if (annoRif == '') {
			alert('Specificare l\'anno di riferimento');
			return;
		}
		
		var event = 'zcomalg.ridistribuzione?step=1&annoRif=' + annoRif + '&dmKey=' + bui_datamanagement.getKey();
		juiceChangeLocation(event);		
	}	
	
	function gotoStep2() {
		var perc = document.getElementById('percentuale').value;
		if (perc == '') {
			alert('Specificare la percentuale per il ricalcolo dei contributi');
			return;
		}
		
		var event = 'zcomalg.ridistribuzione?step=2&dmKey=' + bui_datamanagement.getKey() + '&perc=' + perc;
		juiceChangeLocation(event);		
	}
</script>
 
		
<shell:fieldset title="Anno di riferimento">
	<c:choose>
		<c:when test="${dto_step == 0}">			
			<table border="0" cellspacing="3" cellpadding="0" >		
				<tr>
					<td class="form-label">
						Anno di riferimento <span class="form-label-required">*</span>
					</td>
					<td class="form-values">				
						<input id="anno" class="form-short-text" maxlength="4" type="text">
					</td>						
				</tr>
				<tr>
					<td>&nbsp;</td> 
					<td><shell:button text="Avanti" img="commons.navigateRight" title="Ricerca le domande accettate" href="javascript:gotoStep1();"/></td>						
				</tr>
			</table>
			<c:if test="${! empty dto_msg0}">
				<div class="msg_text_warning" style="padding: 4px 10px 4px 10px">${dto_msg0}</div>
			</c:if>	 				
		</c:when>
		<c:otherwise>
			<table border="0" cellspacing="3" cellpadding="0" >		
				<tr> <td class="form-label">Anno di riferimento</td><td class="form-values">${dto_annoRif}</td></tr>		 	
			</table>
		</c:otherwise>
	</c:choose>
</shell:fieldset>

		
<c:if test="${dto_step >= 1}">
	<shell:fieldset title="Informazioni sulle domande presentate">
		<table border="0" cellspacing="3" cellpadding="0" >		
			<tr> <td class="form-label">Nr domande presentate</td> <td class="form-values">${dto_nrDomande}</td> </tr>	
			<tr> <td class="form-label">Nr domande accettate</td> <td class="form-values">${dto_nrDomandeAccettate}</td> </tr>
			<tr> <td class="form-label">Importo totale da erogare (Euro)</td> <td class="form-values">${dto_daErogare}</td> </tr>
			<c:if test="${dto_step == 2}">
				<tr> <td class="form-label">Percentuale di ricalcolo</td> <td class="form-values">${dto_percentuale}</td> </tr>
			</c:if>
			<c:if test="${dto_step == 1}">
				<c:if test="${! empty dto_msg1}">
					<tr><td class="msg_text_info" style="padding: 4px 10px 4px 10px" colspan="2">${dto_msg1}</td> </tr>
				</c:if>
			
				<c:if test="${dto_continue == 'true'}">
					<tr> 
						<td class="form-label">Percentuale di ricalcolo <span class="form-label-required">*</span></td> 
						<td class="form-values">
							<input id="percentuale" class="form-short-text" maxlength="6" type="text"> &nbsp;&nbsp;&nbsp;
							Totale disponibile (Euro) <input id="totale" class="form-normal-text" type="text"/>
							<button class="generic-button ui-state-default ui-corner-all" onClick="calcolaPercentuale()">Calcola percentuale</button>
						</td> 
					</tr>
				</c:if>			
				
				<tr> <td>&nbsp;</td> 
					<td class="form-values"  style="padding-top: 10px;">
						<shell:button text="Indietro" img="commons.navigateLeft" title="Indietro" href="javascript:gotoStep0();"/> &nbsp;&nbsp;&nbsp;
						<shell:button text="Esegui calcolo" img="commons.navigateRight" title="Esegui calcolo" href="javascript:gotoStep2();" enabled="${dto_continue}"/>
					</td>						
				</tr>
				
			</c:if>
			<c:if test="${! empty dto_err1}">
				<tr><td class="msg_text_warning"  style="padding: 4px 10px 4px 10px" colspan="2">${dto_err1}</td> </tr>
			</c:if>
		</table>
	</shell:fieldset>
</c:if>
	

<c:if test="${dto_step == 2}">
	<shell:fieldset title="Informazioni sulle domande presentate">
		<c:if test="${! empty dto_err2}">
			<div style="padding: 4px 10px 4px 10px">
				<div class="msg_text_warning">Il ricalcolo dei contributi non � andato a buon fine.</div>
				<div class="msg_text_warning">${dto_err2}</div>	
			</div>		
		</c:if>
		<c:if test="${! empty dto_nuovoTotale}">
			<div class="msg_text_info"  style="padding: 4px 10px 4px 10px">Il ricalcolo dei contributi � andato a buon fine.</div>
			<table border="0" cellspacing="3" cellpadding="0" >		
				<tr> <td class="form-label">Totale contributi erogati</td> <td class="form-values">${dto_nuovoTotale}</td> </tr>
			</table>			
		</c:if>		
	</shell:fieldset>
</c:if>