var statusOpen = false;var statusClose = false;var lastExpanded = '';
var Toogleador = function(){
    this.ids = new Array();
}
Toogleador.prototype.add = function(id){
    var idArray = this.ids.length;
    this.ids[idArray] = id;
}
Toogleador.prototype.setLast = function(id){
    
}
Toogleador.prototype.change = function(id){
    cerrar(2);    cerrar(1);	if ( lastExpanded==id && $(id).style.display != 'none'){	  Effect.BlindUp(id);        }
	else{	  if(lastExpanded!= '' && lastExpanded!=id && $(lastExpanded).style.display != 'none'){    	  	Effect.BlindUp(lastExpanded);	  }	  Effect.BlindDown(id,lastExpanded);	}	    /*if ( this.ids[i]==id && $(id).style.display != 'none'){      Effect.BlindUp(id);
    }
	 if ( this.ids[i]==id && $(id).style.display == 'none'){
      Effect.BlindDown(id); 
    }*/
    overflow(id);
	//}
}
function blind(id,caso){
cerrar(caso);	
if($(id).style.display == 'none'){
		Effect.BlindDownHijo(id);	}else{
		Effect.BlindUpHijo(id);
}
}

function cerrar(caso){
  if (caso == 1){
  oItems = $$("ul.root ul");  
  }
  if (caso == 2){
  oItems = $$("ul.nieto ul"); 
  } 
  if (caso == 3){
  oItems = $$("ul.bisnieto ul"); 
  } 
  for(j=0;j<oItems.length;j++){
    if(oItems[j].style.display != 'none'){
      /*Effect.BlindUp(oItems[j]);*/
      $(oItems[j]).hide();
     oItems[j].style.overflow = 'auto';
    } 
  }
  
}
function overflow(id){
     oItems = $$("ul.bisnieto"); 
    for(var j=0;j<oItems.length;j++){
     //oItems[j].style.display = 'none';
     oItems[j].style.overflow = 'hidden';
  }    
  oItems = $$("ul.nieto");
  for(var j=0;j<oItems.length;j++){
     oItems[j].style.overflow = 'hidden';
  } 
  $(id).style.overflow = 'hidden';
}

function checkForm(e) {
	if (e.keyCode == 13) {
        url = 'prov='+$F('cmbProvincias')+'&jur='+$F('cmbJurisdiccion')+'&query='+$F('txtQuery');
		showDefensoria('/guia/buscadorDefensoriaAjax',url);
	}
}
function showDefensoria(url,param){
	new Ajax.Updater('guia', url, { asynchronous:true, evalScripts:true,
  method: 'post' ,
  parameters:param,
  onLoading: function(request){
  $('ul.defensorias').innerHTML='';	
  $('cargando').show();
  $('mensaje').hide();
  $('cargando').setStyle({background:'url(/images/cargador.gif) no-repeat 0 0'});},
  onComplete: function(request){
  $('cargando').hide();
 $('mensaje').show();
	  }
  });
}
function eliminarArchivo(id, url, param){
  new Ajax.Updater(id, url, { asynchronous:true, evalScripts:true,
  method: 'post' ,
  parameters:'id_archivo='+param,
  onLoading: function(request){
      document.getElementById(id).style.display="none";
      document.getElementById('Name'+id).disabled="disabled";
      document.getElementById('TmpName'+id).disabled="disabled";
      document.getElementById('Type'+id).disabled="disabled";
      document.getElementById('Id'+id).disabled="disabled";

  }
    ,
  onComplete: function(request){

	  }
  });
}

function ajaxUpdater(url){
    var button = $('#upload_button'), interval;
    new AjaxUpload('#upload_button', {
        action: url,
        onSubmit : function(file , ext){
        if (! (ext && /^(pdf|txt|doc|docx|zip|rtf|xls)$/.test(ext))){
            // extensiones permitidas
            alert('Error: el tipo de archivo no es aceptado.');
            // cancela upload
            return false;
        } else {
             // Cambio el texto del boton y lo deshabilito

            this.disable();
        }
        },
        onComplete: function(file, response){
            var str=response;

            var datos = str.split(":");

            var ext = datos[2].split("/");
            if(!(/^(pdf|vnd.ms-exc|plain|zip|msword)$/.test(ext[1])))
            ext[1] = 'default';

            // habilito upload button
            this.enable();
            // Agrega archivo a la lista
            new Insertion.Before('comienzo',"<div class='adjuntos'><img src='/images/backend/ic-"+ext[1]+".gif' height='25px' />"+file+"</div><input type=hidden value='"+datos[0]+"' name=fileTmpName[] /><input type=hidden value='"+datos[1]+"' name=fileName[] /><input type=hidden value='"+datos[2]+"' name=fileType[] />");
        }
    });
}





