function fade_div(id) {
    $("#"+id).fadeOut(2000);
}


function details(box) {
	$('#'+box).slideToggle('slow');
}

function show_dt(id)
{
  var stato = document.getElementById(id).style.display;

  if(stato=='none')
    {
      document.getElementById(id).style.display = 'block';
    }
    else
      {
        document.getElementById(id).style.display = 'none';
      }
}

function selCombodesc(id_combo1,id_combo2,tipo) {

  id = $("select[id='" + id_combo1 + "']").val();

  $.get("/decode64desc.php?id="+id+"&tipo="+tipo,
  function(dataProvince){
    $("select[id='"+ id_combo2 + "']").empty();
    var options = '<option value="">-- Seleziona --</option>';

   var arr = eval('(' + dataProvince + ')');

      $.each(arr, function (i, elem) {
          options += '<option value="' + i + '">' + elem.toUpperCase() + '</option>';
    });

    $("select[id='"+ id_combo2 + "']").html(options);
  });

}

function searchArray (search,array) {

  var val;
  val = '';

 $.each(array, function (i, elem) {
         if (search == i) {
            val = elem;
         }
    });

    return val;


}

function selCombo(id_combo1,id_combo2,tipo) {

  id = $("select[id='" + id_combo1 + "']").val();

  $.get("/decode64.php?id="+id+"&tipo="+tipo,
  function(dataProvince){
    $("select[id='"+ id_combo2 + "']").empty();
    var options = '<option value="">-- Seleziona --</option>';

   var arr = eval('(' + dataProvince + ')');

      $.each(arr, function (i, elem) {
          options += '<option value="' + i + '">' + elem.toUpperCase() + '</option>';
    });

    $("select[id='"+ id_combo2 + "']").html(options);
  });

}


function confirm_redir(destination,type) {

  switch(type)  {

    case 'delete':
      if (confirm("Confermi cancellazione?"))
        document.location.href = destination;
      break;

    case 'activation':
      if (confirm("Modificare lo stato di questo nominativo?"))
        document.location.href = destination;
      break;
  }

}



function confirm_submit(type) {

  switch(type)  {

    case 'delete':
      if (confirm("Confermi cancellazione?"))
            return true;
        else
            return false;
      break;

    case 'activation':
      if (confirm("Modificare lo stato di questo nominativo?"))
            return true;
        else
            return false;
      break;

    case 'service':
      if (confirm("Modificare lo stato di questo servizio?"))
            return true;
        else
            return false;
      break;
  }

}





function select_jump(link)  {
    if(link!='')  {
      document.location.href = link;
    }
}





function warn_edit(obj,giorni)  {

    var regex = /[0-9]\.?\,?[0-9]*/;
    var vuoto = 1;
    var numeric = 1;
    var n_el = giorni*11;
    for(var i=0; i<=n_el; i=i+1) {

        var el_type = obj.elements[i].type;
        var el_val = obj.elements[i].value;

        if((el_type=='text') && (el_val!='')) {
           vuoto = 2;

           if(!regex.test(el_val)) {
               numeric = 2;
           }
        }
    }

    if(numeric == 2)   {
          document.getElementById("error_1").style.display = 'block';
          document.getElementById("error_1").innerHTML = 'Attenzione!! Nei campi "Ore lav." sono ammessi solo valori numerici';
          document.location.href = "#top";
          return false;
    }
    else if(vuoto==2)  {
      if(confirm("Il foglio presenze sta per essere modificato. Vuoi procedere?"))
        return true;
      else
        return false;
    }
    else  {
      document.getElementById("error_1").style.display = 'block';
      document.getElementById("error_1").innerHTML = 'Attenzione!! Nessuna presenza inserita';
      document.location.href = "#top";
      return false;
    }

}


function tot_ore()  {

    var lun = document.getElementById('ore_lun').value;
    var mar = document.getElementById('ore_mar').value;
    var mer = document.getElementById('ore_mer').value;
    var gio = document.getElementById('ore_gio').value;
    var ven = document.getElementById('ore_ven').value;
    var sab = document.getElementById('ore_sab').value;
    var dom = document.getElementById('ore_dom').value;

    lun = lun.replace(',','.');
    mar = mar.replace(',','.');
    mer = mer.replace(',','.');
    gio = gio.replace(',','.');
    ven = ven.replace(',','.');
    sab = sab.replace(',','.');
    dom = dom.replace(',','.');

    var lunFloat = parseFloat(lun);
    var marFloat = parseFloat(mar);
    var merFloat = parseFloat(mer);
    var gioFloat = parseFloat(gio);
    var venFloat = parseFloat(ven);
    var sabFloat = parseFloat(sab);
    var domFloat = parseFloat(dom);

    if(isNaN(lunFloat))
        lunFloat = 0.0;
    if(isNaN(marFloat))
        marFloat = 0.0;
    if(isNaN(merFloat))
        merFloat = 0.0;
    if(isNaN(gioFloat))
        gioFloat = 0.0;
    if(isNaN(venFloat))
        venFloat = 0.0;
    if(isNaN(sabFloat))
        sabFloat = 0.0;
    if(isNaN(domFloat))
        domFloat = 0.0;

    var tot = lunFloat + marFloat + merFloat + gioFloat + venFloat + sabFloat + domFloat;
    tot = Math.round(tot*100)/100;
    document.getElementById('totale_ore').value = tot;
}


function to_uppercase(el) {
    var text = el.value;
    if((text != '') || (text != undefined))
        el.value = text.toUpperCase();
}
