function OtorgarPrivilegio()
{
  if (ValidaRUT('persona_rut', undefined))
  {
    var error = false; 
    var rut = document.getElementById('persona_rut'); 
    var privilegio = document.getElementById('persona_privilegio'); 
    if (Trim(rut.value)=="" && !error)
    {
      error = true;
      alert("Debe ingresar el rut de la persona"); 
      rut.focus();
    }
    if (!(ValidaRUTPersona("persona_rut", undefined)) && !error)
    {
      error = true;
      rut.focus();
    }
    if (privilegio.value==0 && !error)  
    {
      error = true; 
      alert("Debe seleccionar un privilegio para otorgar"); 
      privilegio.focus(); 
    }
    if (!error)
    {
      var URL = "/mantenedor/privilegios";
      var Vars = "otorgar=true&rut="+rut.value+"&privilegio="+privilegio[privilegio.selectedIndex].value; 
      document.getElementById("btnOtorgarPrivilegio").disabled = true; 
      loadXMLDoc(URL, "POST", Vars, "PrivilegioOtorgado"); 
    }
  }
}

function PrivilegioOtorgado(root)
{
  var rut = document.getElementById('persona_rut'); 
  var privilegio = document.getElementById('persona_privilegio'); 
  if (Mozilla)
  {
    var inicio = 1; 
    var incremento = 2; 
  }
  else
  {
    var inicio = 0; 
    var incremento = 1; 
  }
  var status = root.childNodes[inicio].getAttribute("status"); 
  var reason = root.childNodes[inicio].getAttribute("reason"); 
  if (status=="true")
  {
    alert("El privilegio fue otorgado a la persona indicada");
    self.location.href="/mantenedor/privilegios"; 
  }
  else
  {
    document.getElementById("btnOtorgarPrivilegio").disabled = false; 
    rut.value = ""; 
    privilegio.selectedIndex = 0; 
    alert(reason); 
    rut.focus(); 
  }
  return true;
}
