// JavaScript Document
<!--
// url_encode version 1.0 
function url_encode(str) { 
    var hex_chars = "0123456789ABCDEF"; 
    var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
    var n, strCode, hex1, hex2, strEncode = ""; 

    for(n = 0; n < str.length; n++) { 
        if (noEncode.test(str.charAt(n))) { 
            strEncode += str.charAt(n); 
        } else { 
            strCode = str.charCodeAt(n); 
            hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
            hex2 = hex_chars.charAt(strCode % 16); 
            strEncode += "%" + (hex1 + hex2); 
        } 
    } 
    return strEncode; 
} 

// url_decode version 1.0 
function url_decode(str) { 
    var n, strCode, strDecode = ""; 

    for (n = 0; n < str.length; n++) { 
        if (str.charAt(n) == "%") { 
            strCode = str.charAt(n + 1) + str.charAt(n + 2); 
            strDecode += String.fromCharCode(parseInt(strCode, 16)); 
            n += 2; 
        } else { 
            strDecode += str.charAt(n); 
        } 
    } 
    return strDecode; 
}  

// finaliza

function finaliza(nome_arquivo){
// substitui as flag ara acentos
/*
_o -> ó
_1a -> á
_3 -> ê
_i -> í
_2a -> ã
__c -> ç
*/
var casos = new Array();
var respostas = new Array();

casos = ["_1a","_2a","_3a","_4a","_5a","_1e","_3e","_4e","_1i","_3i","_4i","_1o","_2o","_3o","_4o","_1u","_3u","_4u","__c"];
respostas = ["&acute;","&atilde;","&agrave;","&acirc;","&Acirc;","&eacute;","&egrave;","&ecirc;","&iacute;","&igrave;","&icirc;","&Oacute;","&otilde;","&ograve;","&ocirc;","&uacute;","&ugrave;","&ucirc;","&ccedil;"]

for (i = 0; i < 19 ; i++)
{
  while(nome_arquivo.indexOf(casos[i]) != -1)
  {
   nome_arquivo = nome_arquivo.replace(casos[i],respostas[i]);
  }
}

return nome_arquivo;
}


function AjaXmonta_Combo(combo, modulo, funcao, params)
{
  var handler = function (responseText)
  {
    data = responseText;
    combo.options.length = 1;
    combo.options[0] = new Option('Selecione','');
    for( i = 0 ; i < data.length ; i++)
    {                      
      combo.options[i+1] = new Option(url_decode(data[i][0]),data[i][1]);
    }
  } 
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}

function AjaXCarregaDiv(DIV, modulo, funcao, params)
{ 
  var handler = function (responseText)
  {
    DIV.innerHTML = url_decode(responseText);
  } 
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}



function AjaXDeleta(modulo, funcao, params)
{
  var handler = function (responseText)
  {
    if(responseText == '')
    {
      alert('Deletado com Sucesso!');
      var DIV = document.getElementById('DivFotos');
      var ID = document.getElementById('Ident');
      AjaXCarregaDiv(DIV, modulo, 'carrega_fotos', "pasta ="+ID.value);
    }
    else
    {
      alert('Erro ao deletar o arquivo\n'+responseText);	    
    }
  } 
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}


function AjaXMontaMenu(modulo, funcao, nivel)
{
  var handler = function (responseText)
  {
     var DIV = document.getElementById('pri_'+nivel);	  
     var text = responseText;
     var ul = document.createElement('ul');
     ul.innerHTML = finaliza(text);
     DIV.appendChild(ul);
     mainmenu.destroy();
     mainmenu = DynarchMenu.setup('menu_principal', { shadows: [-1, 0, 5, 5], electric: 5000, timeout: 0, lazy: true});
  } 
  var params = 'nivel ='+nivel;
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}

function AjaXCriaBackup(modulo, funcao, params)
{
  var handler = function (responseText)
  {
    if(responseText != '')
    {
	  var msg = responseText;
	  alert(msg);
    }
    else
    {
      alert('Erro ao criar o arquivo\n'+responseText);
    }
  } 
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}

function AjaXRestauraBackup(modulo, funcao, params)
{
  var handler = function (responseText)
  {
    if(responseText != '')
    {
      var msg = responseText;
      alert(msg);
    }
    else
    {
      alert('Erro ao criar o arquivo\n'+responseText);
    }
  } 
  params = "arq="+params;
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}


function AjaXAdmin(modulo, funcao, params)
{
  var handler = function (responseText)
  {
    if(responseText != '')
    {
      alert('Erro !\n'+responseText);	    
    }
  } 
  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}

function AjaXBuscaFesta(modulo, funcao, params)
{
  var handler = function (responseText)
  {
    var data = responseText;
    var FesNome = document.getElementById('FesNome');
    var FesDataLimite = document.getElementById('FesDataLimite');
    var FesDescricao = document.getElementById('FesDescricao');
    FesNome.value =      url_decode(data[0]);
    FesDataLimite.value = url_decode(data[1]);
    FesDescricao.value = url_decode(data[2]);
  } 

  var args = "$this."+modulo+"."+funcao;
  cExecute (args, handler, params);
}
//-->

