/********************************************************
richiede conferma su operazioni varie (cancellazione etc.)
*********************************************************/
function confirmLink(theLink, msg) {

	var is_confirmed = confirm(msg);
	if (is_confirmed) {
		theLink.href
	}

	return is_confirmed;
}

/********************************************************
seleziona/deseleziona tutti i check nel form di 
ricerca prenotazioni generale
*********************************************************/
function checkAll(CheckValue) {
var objCheckBoxes = document.forms['searchPrenGen'].elements['auleSel[]'];
var countCheckBoxes = objCheckBoxes.length;
for(var i = 0; i < countCheckBoxes; i++)
   objCheckBoxes[i].checked = CheckValue;


}


/********************************************************
validazione del form di ricerca prenotazioni generali
*********************************************************/
function ValidateForm() {
var objCheckBoxes = document.forms['searchPrenGen'].elements['auleSel[]'];
var countCheckBoxes = objCheckBoxes.length;
var aulaSel=false;
for(var i = 0; i < countCheckBoxes; i++) {
   if (objCheckBoxes[i].checked == true)
      aulaSel=true;
}

if (aulaSel==false) {
   alert('Attenzione: selezionare almeno un\'aula/laboratorio');
   return false;
}

var dataIni = document.getElementById('dataIni').value;
var dataFin = document.getElementById('dataFin').value;
if (dataIni=="" || dataFin=="") {
   alert('Attenzione: data di inizio o fine ricerca non specificata');
   return false;
}

dataInistr = dataIni.substr(6)+dataIni.substr(3, 2)+dataIni.substr(0, 2);
dataFinstr = dataFin.substr(6)+dataFin.substr(3, 2)+dataFin.substr(0, 2);

if (dataFinstr<dataInistr) {
   alert('Attenzione: data finale precedente alla data iniziale');
   return false;
}

return true;

}

/**
 * visualizza/nasconde sede ritiro certificato + linea input altro certificato
 * se as in corso e certificato di iscrizione/frequenza visualizza altrimenti nasconde
 */
function visualSedeRitiro() {
  var objCheckBoxes = document.forms['formStudenti'].elements['ascertincorso[]'];
  if (objCheckBoxes[0].checked == true)
   var asincorso = true;
  else
   var asincorso = false;

  var cert = document.getElementById('certificatodi').value;
  
  if (asincorso==true && cert=='2')
    document.getElementById('luogoritiro').style.display="block";
  else
    document.getElementById('luogoritiro').style.display="none";

  if (cert=='5')
    document.getElementById('altrocert').style.display="block";
  else
    document.getElementById('altrocert').style.display="none";
}

/**
 * visualizza/nasconde linea input altro uso
 */
function visualAltroUso() {
  var uso = document.getElementById('uso').value;
  
  if (uso=='8')
    document.getElementById('altrouso').style.display="block";
  else
    document.getElementById('altrouso').style.display="none";
}

/**
 * setta corso e pone a zero gli altri due per evitare che vengano selezionati più di uno
 */
function setCorso(corso) {
  if (corso=='ITI') {
    var corso = document.getElementById('corsoiti').value;
    if (corso!='0') {
	  document.getElementById('corsoitc').value='0';
	  document.getElementById('corsoitg').value='0';	
    }
  }
  if (corso=='ITC') {
    var corso = document.getElementById('corsoitc').value;
    if (corso!='0') {
	  document.getElementById('corsoiti').value='0';
	  document.getElementById('corsoitg').value='0';	
    }
  }
  if (corso=='ITG') {
    var corso = document.getElementById('corsoitg').value;
    if (corso!='0') {
	  document.getElementById('corsoiti').value='0';
	  document.getElementById('corsoitc').value='0';	
    }
  }

}
	
/**
 * validazione del form di richiesta certificati
 **/
function ValidateFormCert() {

var validForm = true;
var msg = "Errori di validazione:\n\n";
if (document.getElementById('nome').value==""){
  msg += "- campo 'Cognome Nome' richiesto\n";
  document.getElementById('nome').style.border="1px solid red";
  validForm = false;
} else {
	  document.getElementById('nome').style.border="1px solid #aaaaaa";
}
if (document.getElementById('luogonascita').value==""){
  msg += "- campo 'Luogo di nascita' richiesto\n";
  validForm = false;
}
if (document.getElementById('datanascita').value==""){
  msg += "- campo 'Data di nascita' richiesto\n";
  validForm = false;
}
if (document.getElementById('residentea').value==""){
  msg += "- campo 'residente a' richiesto\n";
  validForm = false;
}
if (document.getElementById('indirizzo').value==""){
  msg += "- campo 'Indirizzo' richiesto\n";
  validForm = false;
}
if (document.getElementById('telefono').value=="" && document.getElementById('email').value=="") {
  msg += "- Il campo 'telefono' oppure 'email' e' richiesto\n";
  validForm = false;
}
if (document.getElementById('freqas').value=="" && document.getElementById('freqclasse').value=="" && document.getElementById('diplomaas').value=="") {
  msg += "- Specificare l'a.s. di frequenza o di diploma\n";
  validForm = false;
}
if (document.getElementById('corsoiti').value=="0" && document.getElementById('corsoitc').value=="0" && document.getElementById('corsoitg').value=="0") {
  msg += "- Specificare un indirizzo di studi\n";
  validForm = false;
}
if (document.getElementById('numcert').value=="") {
  msg += "- Il campo 'numero certificati' e' richiesto\n";
  validForm = false;
}
if (document.getElementById('certificatodi').value=="0") {
  msg += "- Specificare il tipo di certificato\n";
  validForm = false;
}
if (document.getElementById('uso').value=="0") {
  msg += "- Specificare il tipo di uso\n";
  validForm = false;
}


if (validForm == false) {
   alert(msg);
   return false;
}

return true;

}

