//autorizzazioni = Array();
/*
function addAuth(){
  x_aggiornaArrayAutorizzazioni(aggiornaArrayAutorizzazioniCallback);
}
*/
/*
function selAllChanged(auths){
    var authArray= auths.split(',');
    var x = 0;
    var selAll = document.getElementById("selAll").checked;

    if(selAll){
	for(x=0; x<authArray.length -1; x++){
	    document.getElementById(authArray[x] + "autorizzazioni").checked = true;
	}
    }else{
	for(x=0; x<authArray.length -1; x++){
	    document.getElementById(authArray[x] + "autorizzazioni").checked = false;
	}
    }
}
function aggiornaArrayAutorizzazioniCallback(focus, z){
  var matricole = document.getElementById('agenti');
  var matricola = parseInt(matricole.options[matricole.selectedIndex].id);
  var password = document.getElementById("password").value;
  var cpassword = document.getElementById("cpassword").value;
  var autorizzazioni = Array();

  var result = z.split(";");

  while(autorizzazioni.lengh)
    autorizzazioni.pop();

  if(password != cpassword){
    alert('le password non corrispondono!');
    return;
  }

  if(password.length < 6){
    if (!confirm("La lunghezza minima consigliata della password e' di 6 caratteri...\nTu hai inserito una password di " + password.length.toString() + " caratteri. Continuo ugualmente?"))
    return;
  }

  try{
    for(x = 0; x < result.length - 1; x++){
      if(document.getElementById(result[x] + "autorizzazioni").checked){
	autorizzazioni.push(result[x]);
	//document.getElementById("homeDiv").innerHTML = document.getElementById("homeDiv").innerHTML + result[x] + " ; ";
      }
    }
  }catch(ex){
    alert (ex);
  }

  hideObj("blur");
  hideObj("foregroundInsertContainer");

  password = hex_md5(password);

  alert(password);

  x_addAuth(matricola, password, autorizzazioni, generalAjaxCallback);
}
*/
function emptyCallback(z){}

function delAuth(auth, matricola){
  if(!confirm("Sei sicuro di voler eliminare tutte le autorizzazioni per la matricola " + matricola + "?"))
    return;

  x_delAuth(auth, generalAjaxCallback);
}
/*
function editAuthForm(auth){

  showObj("blur");
  showObj("foregroundInsertContainer");

  x_drawEditAuthForm(auth, insertAjaxCallback);
  //  x_editAuthForm(auth, insertAjaxCallback);
}
*/
function editPassword(){
  var password = document.getElementById("password").value;
  var npassword = document.getElementById("npassword").value;
  var cpassword = document.getElementById("cpassword").value;

  if(npassword != cpassword){
    hideObj("loadingDiv");
    alert('le password non corrispondono!');
    return;
  }

  npassword = hex_md5(npassword);
  password = hex_md5(password);
  x_editPassword(password, npassword, insertAjaxCallback);
}
/*
function editAuth(auth, auths){

  hideObj("blur");
  hideObj("foregroundInsertContainer");

  x_editAuth(auth, auths, generalAjaxCallback);
}

function aggiornaArrayAutorizzazioniCallback_edit(focus, z){
  var auth = document.getElementById('auth').value;
  var autorizzazioni = Array();

  var result = z.split(";");

  while(autorizzazioni.lengh)
    autorizzazioni.pop();

  try{
    for(x = 0; x < result.length - 1; x++){
      if(document.getElementById(result[x] + "autorizzazioni").checked){
	autorizzazioni.push(result[x]);
	//document.getElementById("homeDiv").innerHTML = document.getElementById("homeDiv").innerHTML + result[x] + " ; ";
      }
    }
  }catch(ex){
    alert (ex);
  }

  hideObj("blur");
  hideObj("foregroundInsertContainer");

  x_editAuth(auth, autorizzazioni, generalAjaxCallback);
}
*/
function aggiungiGruppo(){
    var nome = document.getElementById("nuovoGruppo").value;
    var descrizione = document.getElementById("descrizioneGruppo").value;
    var copiaDaSelect = document.getElementById("gruppoOrigine");
    var copiaDa = parseInt(copiaDaSelect.options[copiaDaSelect.selectedIndex].id);

    x_aggiungiGruppo(nome, descrizione, copiaDa, generalAjaxCallback);
}
