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

<script type="text/javascript">
	function uploadFile() {
		var patternNomeFileAnomalieContratti = '${dto_nomefile_anomalie_contratti }';
		var patternNomeFileAnomalieDistinte = '${dto_nomefile_anomalie_distinte }';
		
		var fileName1 = document.getElementById('idFileName1').value;
		var fileName2 = document.getElementById('idFileName2').value;
		if (fileName1 != '' && fileName2 != '') {
			if (controlloNomeFile(fileName1, patternNomeFileAnomalieContratti, fileName2, patternNomeFileAnomalieDistinte)){
				document.getElementById('idDivFormUpload').style.display='none';
				document.getElementById('idDivWaitUpload').style.display='block';
				document.getElementById('masterFileNameHidden').value = parent.cpGetMasterColumnValueOfCurrentRow('nomeFile');
				var form = document.getElementById('idFormFileUpload');
				juiceSubmitForm(form);
			}else{
				alert('Attenzione, controllare la correttezza dei file in input.');
				return false;
			}
		} else {
			alert('Attenzione, specificare entrambe i file.');
			return false;
		}
	}
	
	function controlloNomeFile(fileName1, patternNomeFileAnomalieContratti, fileName2, patternNomeFileAnomalieDistinte){
		var inputNomeFileAnomalieContratti = fileName1.substring(0, fileName1.lastIndexOf('.'));
		var inputNomeFileAnomalieDistinte = fileName2.substring(0, fileName2.lastIndexOf('.'));
		if (patternNomeFileAnomalieContratti.toUpperCase() == inputNomeFileAnomalieContratti.toUpperCase()
			&& patternNomeFileAnomalieDistinte.toUpperCase() == inputNomeFileAnomalieDistinte.toUpperCase()){
			return true;
		}
		return false;
	}
</script>

<j:form id="idFormFileUpload" name="multiplefileupload" event="multipleFileUpload" enctype="multipart/form-data" method="POST" >
	<div id="idDivFormUpload" style="display:block">
	<table border="0" cellpadding="0" cellspacing="3" width="100%">
			<tr style="vertical-align: top;">
				<td colspan="2" class="generic-label" style="padding: 5px 4px 15px 4px;">
					Selezionare i file delle anomalie da importare:
				</td>
			</tr>
		<tr>
			<td class="generic-label">
				File ${dto_nomefile_anomalie_contratti }:
			</td>
			<td>
				<j:bind prop="fileContent1">
  					<j:file id="idFileName1" size="38"/>
  				</j:bind>
			</td>
		</tr>
		<tr>
			<td class="generic-label">
				File ${dto_nomefile_anomalie_distinte }:
			</td>
			<td>
				<j:bind prop="fileContent2">
  					<j:file id="idFileName2" size="38"/>
  				</j:bind>
			</td>
		</tr>	
		<tr>
			<td colspan="2" style="padding: 15px 4px 5px 4px; text-align:center;">
				<button class="generic-button ui-state-default ui-corner-all" onclick="return uploadFile();"><img src="${j:getResourceUrlOfModule('shell', 'img/misc/confirm-small.gif')}" width="16" height="16" border="0" align="absmiddle">&nbsp;Seleziona</button>
			</td>
			<j:bind prop="masterFileName">
				<j:hidden id="masterFileNameHidden" />
			</j:bind>
		</tr>
	</table>
	</div>
	
	<div id="idDivWaitUpload" style="display:none">
	<table border="0" cellpadding="0" cellspacing="3" width="100%">
		<tr>
			<td style="text-align:center;">
				<img src="${j:getResourceUrlOfModule('shell', 'img/misc/ajax-loader.gif')}" border="0" vspace="5">
			</td>
		</tr>
		<tr>
			<td style="padding: 15px 4px 5px 4px;text-align:center;" class="generic-label">
				Preparazione file in corso...
			</td>
		</tr>
	</table>
	</div>
</j:form>