function open_window(file, w, h, nome) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  var win = new Object();
  win = window.open(file, nome, 'width='+ w +',height='+ h +',resizable=no,scrollbars=no,status=no,left='+winl+',top='+wint+'');
}
function eSelected() {
  for(var i = 0; i < document.forms['navegadorForm'].elements.length; i++) {
    curr_elem = document.forms['navegadorForm'].elements[i];
    if (curr_elem.type == 'checkbox' && curr_elem.checked) {
      return true;
    }
  }
  return false;
}
function excluir(diretorioAtual) {
  if (eSelected()) {
    verificaCompartilhamento();
	if (confirm('Você tem certeza que deseja excluir os arquivos selecionados?')) {
      document.forms['navegadorForm'].action = 'xt_excluir.php?diretorioAtual='+ escape(diretorioAtual);
      document.forms['navegadorForm'].submit();
    }
  }
  else {
    alert('Você deve selecionar um arquivo ou diretório antes');
  }
}

function verificaCompartilhamento(){
  for(var i = 0; i < document.forms['navegadorForm'].elements.length; i++) {
    curr_elem = document.forms['navegadorForm'].elements[i];
	if (curr_elem.type == 'checkbox' && curr_elem.checked) {
	   if(curr_elem.getAttribute('bolCompartilhado')==1){
			alert("!!! AVISO !!! \nO diretório " + curr_elem.value + " está compartilhado!\n Se você excluir, outros usuários não terão acesso a este diretário.");
	   }
    }
  }	
}

function renomear(diretorioAtual) {
  if (eSelected()) {
    document.forms['navegadorForm'].action = 'renomear.php?diretorioAtual='+ escape(diretorioAtual);
    document.forms['navegadorForm'].submit();
  }
  else {
    alert('Você deve selecionar um arquivo ou diretório antes');
  }
}
function mover(diretorioAtual) {
  if (eSelected()) {
    document.forms['navegadorForm'].action = 'mover.php?diretorioAtual='+ escape(diretorioAtual);
    document.forms['navegadorForm'].submit();
  }
  else {
    alert('Você deve selecionar um arquivo ou diretório antes');
  }
}
function copiar(diretorioAtual) {
  if (eSelected()) {
    document.forms['navegadorForm'].action = 'copiar.php?diretorioAtual='+ escape(diretorioAtual);
    document.forms['navegadorForm'].submit();
  }
  else {
    alert('Você deve selecionar um arquivo antes');
  }
}
function criar_diretorio(diretorioAtual) {
  //open_window('criar_diretorio.php?diretorioAtual='+ escape(diretorioAtual), 360, 220, 'criar');
  location.href = 'criar_diretorio.php?diretorioAtual='+ escape(diretorioAtual);
}
function enviar_arquivo(diretorioAtual) {
  //open_window('enviar_arquivo.php?diretorioAtual='+ escape(diretorioAtual), 360, 220, 'enviar');
  location.href = 'enviar_arquivo.php?diretorioAtual='+ escape(diretorioAtual);
}
function compartilhar(diretorioAtual) {
  //open_window('compartilhar.php?diretorioAtual='+ escape(diretorioAtual), 467, 465, 'compartilhar');
  location.href = 'compartilhar.php?diretorioAtual='+ escape(diretorioAtual);
}
function descompartilhar(diretorioAtual) {
  if (confirm('Você tem certeza que deseja descompartilhar esta pasta?')) {
    location.href = ('xt_descompartilhar.php?diretorioAtual='+ escape(diretorioAtual));
  }
}
function selectAllNone(status) {
  for(var i=0; i<document.forms['navegadorForm'].elements.length; i++) {
    curr_elem = document.forms['navegadorForm'].elements[i];
    if (curr_elem.type == 'checkbox' && curr_elem.id != 'checkAll') {
      curr_elem.checked = status;
    }
  }
}

var LoadingWin = null;
function open_loading() {
  // Tamanho da Janela
  var w = 300;
  var h = 100;
  
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  LoadingWin = new Object();
  LoadingWin = window.open('carregando_arquivo.php', '', 'width='+ w +',height='+ h +',resizable=no,scrollbars=no,status=no,left='+winl+',top='+wint+'');
}
function close_loading() {
  if (LoadingWin) LoadingWin.close();
  LoadingWin = null;
}