<%@ include file="/project/include.jsp" %>
<script type="text/javascript" src="${j:getResourceUrlOfModule('youtouch','js/youTouch.js')}"></script>
<script type="text/javascript" src="${j:getResourceUrlOfModule('threads', 'js/threads.js')}"></script>
<script type="text/javascript">
	var runningIdThread = '${dto_threadId}';
	
	if (runningIdThread) {
		registerOnDocumentLoad(function() {	
			// C'� un thread che mi risponde
			disableButton('sh_tb__generaAccessi');
			$('#threadDiv').show(0);
			var threadMonitor = new ThreadMonitor(runningIdThread, 8000);
			threadMonitor.showState = function(state) {
				if (state == THREAD_STOP || state == THREAD_EXCEPTION) {
					showThreadIndo();
				} 
			}
			threadMonitor.start();					
		});
	}

	function showThreadIndo() {		
		$('#runningThreadDiv').hide(0);
		$('#stoppedThreadDiv').show(0);
		enableButton('sh_tb__generaAccessi');
	}	
	
	function eseguiGeneraAccessi(preview) {
		$("#previewTxt").val(preview ? 'si' : 'no');
		
		if (!preview) {
			if (!confirm("Verranno generati gli accessi.\nContinuare?")) return;
			
			var threadInCorso = jsLoadString('it.cedaf.icare.youtouch.control.action.GenerazioneAccessiInCorsoExecutor', 'idServizio=' + $("#selServizio").val());
			if (threadInCorso == 'si') {
				alert("Non � possibile eseguire l'elaborazione: c'� gi� una elaborazione in corso.");
				return;
			}						
			//showWaitDiv(0);
		}
		var form = document.getElementById('formGenera');
		juiceSubmitForm(form);
	}     	
	
	function findDataInizio() {
		var newDate = jsLoadString('it.cedaf.icare.youtouch.control.action.DataInizioPeriodoGenerazioneAccessiExecutor', 'idServizio=' + $("#selServizio").val());
		$("#periodoDaCld").val(newDate);
	}
	
	
</script>

<div id="threadDiv" style="display: none;">	
	<shell:highlight>
		<div style="padding-top: 8px; padding-bottom: 5px; text-align: left;">
		<div id="runningThreadDiv">
			<img src="${j:getResourceUrlOfModule('shell','img/wait.gif')}" border="0" align="middle"/>&nbsp;&nbsp;
			Elaborazione in corso: ${dto_monitorDesc}
		</div>
		<div id="stoppedThreadDiv" style="display: none;">
			<img src="${j:getResourceUrlOfModule('shell','img/toolbar/confirm.gif')}" border="0" align="middle"/>&nbsp;&nbsp;
			Elaborazione terminata: ${dto_monitorDesc}.
		</div>
		</div>
	</shell:highlight>
</div>

<j:form id="formGenera" name="formGenera" event="generaAccessi" method="POST"  clientValidatorProvider="it.cedaf.juice.mvc.modules.shell.view.helper.JavascriptClientValidatorProvider">
<j:bind prop="preview">
	<j:hidden id="previewTxt" />
</j:bind>	
	
<shell:fieldset title="Informazioni generali">
	<table border="0" cellspacing="3" cellpadding="0" >
		<tr>
			<td class="form-label">
				<shell:label prop="servizio" />
			</td>
			<td class="form-values">
				<j:bind prop="servizio">
					<j:select id="selServizio" class="form-input" emptyOptionDescr=" " onchange="javascript:findDataInizio();"/>
					<shell:error />
				</j:bind>
			</td>
		</tr>
	
		<tr>
			<td class="form-label">
				<shell:label prop="periodoDa" />
			</td>
			<td class="form-values">
				<j:bind prop="periodoDa">
					da: <j:text class="form-date" id="periodoDaCld" />
					<shell:calendar inputId="periodoDaCld" />
					<shell:error />
				</j:bind>
				<j:bind prop="periodoA">
					a: <j:text class="form-date" id="periodoACld" />
					<shell:calendar inputId="periodoACld" />
					<shell:error />
				</j:bind>
			</td>
		</tr>
	</table>
</shell:fieldset>	
	
</j:form>