function checkData(stringa){
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa)) return false;
	else{
		anno = parseInt(stringa.substr(6),10);
		mese = parseInt(stringa.substr(3, 2),10);
		giorno = parseInt(stringa.substr(0, 2),10);
		
		var data = new Date(anno, mese-1, giorno);
		if(data.getFullYear() == anno && data.getMonth()+1 == mese && data.getDate() == giorno) return true;
		else return false;
	}
}

function checkEmail(stringa){
	var espressione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!espressione.test(stringa)) return false;
	else return true;
}

function checkInteger(stringa){
	var espressione = /(^-?\d\d*$)/;
	if (!espressione.test(stringa)) return false;
	else return true;
}

function checkGenericForm(id){
	var form = document.getElementById(id);
	
	var input = form.getElementsByTagName('input');
	
	var i = 0;
	var value, idInput, pos, name;
	
	//array.item(indice)
	while(i<input.length){
		idInput = input.item(i).id;
		value = input.item(i).value;
		pos = idInput.indexOf('REQUIRED');
		if(pos >= 0){
			if ((value == '') || (value == 'undefined') || (value == undefined)){
				name = input.item(i).name;
				alert(L_esi_campo1 + name + L_esi_campo2);
				//document.writeln('<br />' + name + ' ---> ' + value + '  ' + pos);
				input.item(i).focus();
				input.item(i).select();
				return false;
			}
		}
		//document.write('<br />'+pos);
		//document.write(name + ' ---> ' + value + '  ' + pos);
		i++;
	}
	return true;
}

/***********************************************************/

var idEsitoForm = 'esito_storico';
var idCheckboxRifiuto = 'rifiuto';
var idFirma = 'firma';
var idFirmaNonRaggiunto = 'firma_non_raggiunto';
var idHiddenInput = 'OK_ESITO_FORM';

function disableAll() {
	var form = document.getElementById(idEsitoForm);
	for (var i=0; i<form.elements.length; i++){
		form.elements[i].disabled = true;
	}
}

function enableAll() {
	var form = document.getElementById(idEsitoForm);
	for (var i=0; i<form.elements.length; i++)
		form.elements[i].disabled = false;
}

function enableSoddisfazione(){
	var form = document.getElementById(idEsitoForm);
	if(form.soddisfazione == undefined) return;
	for (var i=0; i<form.soddisfazione.length; i++)
		form.soddisfazione[i].disabled = false;
}

function enableComportamento(){
	var form = document.getElementById(idEsitoForm);
	if(form.comportamento == undefined) return;
	for (var i=0; i<form.comportamento.length; i++)
		form.comportamento[i].disabled = false;
}

function enableFeedback(){
	var form = document.getElementById(idEsitoForm);
	if(form.messaggio == undefined) return;
	form.messaggio.disabled = false;
}

function enableCheckboxRifiuto(){
	document.getElementById(idCheckboxRifiuto).disabled = false;
}

function enableFirma(){
	document.getElementById(idFirma).disabled = false;
}

function disableFirma(){
	document.getElementById(idFirma).disabled = true;
}

function enableFirmaNonRaggiunto(){
	document.getElementById(idFirmaNonRaggiunto).disabled = false;
}

function disableFirmaNonRaggiunto(){
	document.getElementById(idFirmaNonRaggiunto).disabled = true;
}

function enableHiddenInput(){
	document.getElementById(idHiddenInput).disabled = false;
}

function checkAccNonRaggiunto(){
	var form = document.getElementById(idEsitoForm);
	var nonRaggiunto = document.getElementById(idCheckboxRifiuto).checked;
	
	if(nonRaggiunto){
		disableAll();
		enableFirmaNonRaggiunto();
	}
	else{
		enableAll();
		disableFirmaNonRaggiunto();
	}
	enableCheckboxRifiuto();
	enableSoddisfazione();
	enableComportamento();
	enableFeedback();
	enableHiddenInput();
	
	return nonRaggiunto;
}
