function CambiarAlto( objId, px, limite, PaddingVertical, IdObjEvento )
{
  var obj = document.getElementById(objId);
  if(!obj) return

  if(px<0)
  {
    if((obj.offsetHeight+px-PaddingVertical)>limite)
      obj.style.height = (obj.offsetHeight+px-PaddingVertical)+'px';
    else
    {
      obj.style.height = limite+'px';
      clearInterval(IdPersiana);
      obj.style.padding='10px 10px 20px 10px';
      obj = document.getElementById(IdObjEvento);
      if(!obj) return
      obj.className='EstirarCapa'
       obj.innerHTML = TextoExpandirFiltros
  	  obj.onclick=function(){EfectoPersiana('Filtrar-por', 16, 180, 20, IdObjEvento);obj.onclick='';}
  	  setCookie("CookieFiltros", getCookie("FiltroActual"), null, "/" );
    }
  }
  if(px>0)
  {
    if((obj.offsetHeight+px-PaddingVertical)<limite)
      obj.style.height = (obj.offsetHeight+px-PaddingVertical)+'px';
    else
    {
      obj.style.height = limite+'px';
      clearInterval(IdPersiana);
      obj.style.padding='10px 10px 10px 10px';
      obj = document.getElementById(IdObjEvento);
      if(!obj) return
      obj.className='ContraerCapa'
       obj.innerHTML = TextoContraerFiltros
	    obj.onclick=function(){EfectoPersiana('Filtrar-por', -16, 0, 20, IdObjEvento);obj.onclick='';}
  	  setCookie("CookieFiltros", "", null, "/" );
    }
  }
  if(objId == 'Filtrar-por')CambiarAlto( 'BloqueOperadora', px, limite, PaddingVertical, IdObjEvento )
}

function EfectoPersiana(objId, px, limite, PaddingVertical, IdObjEvento)
{
  IdPersiana = setInterval("CambiarAlto('"+objId+"', "+px+", "+limite+", "+PaddingVertical+", '"+IdObjEvento+"')", 1);
}

function MostrarEsperando(IdObj)
{
  var obj;
  if(IdObj=='')
    obj = document.getElementById('Esperando');
  else
    obj = document.getElementById(IdObj);

  if(!obj)return

  obj.style.display='block';
//    if(obj.offsetHeight<100)
    {
obj.style.top = '0px';
obj.style.height = '100%';
obj.style.width = '100%';
      if(document.documentElement.scrollTop)
        obj.style.top = document.documentElement.scrollTop+'px';
      if(document.documentElement.clientHeight);
        obj.style.height = document.documentElement.clientHeight+'px';
      if(document.documentElement.clientWidth);
        obj.style.width = document.documentElement.clientWidth+'px';
      if(window)
        window.onscroll = function(el){MostrarEsperando(IdObj);setTimeout('MostrarEsperando("'+IdObj+'")',500);}
//      setInterval('MostrarEsperando("'+IdObj+'")',100);
//      setTimeout('MostrarEsperando("'+IdObj+'")',100);
    }

    /* Desactivamos los campos select */  
    obj = document.getElementById('o');
    if (obj) obj.style.visibility = 'hidden';
    
    obj = document.getElementById('r');
    if (obj) obj.style.visibility = 'hidden';
    
    setTimeout('OcultarEsperando()',15000);
}

function OcultarEsperando(IdObj)
{
  var obj;
  if(IdObj=='')
    obj = document.getElementById('Esperando');
  else
    obj = document.getElementById(IdObj);
  if(obj)obj.style.display='none';

  /* Activamos los campos select */  
  obj = document.getElementById('o');
  if (obj) obj.style.visibility = 'visible';
    
  obj = document.getElementById('r');
  if (obj) obj.style.visibility = 'visible';
  
  if(window) window.onscroll = null;
}

function MostrarAyudaMascota(Pos, ancho)
{
  clearTimeout(IdAyuda);
  var obj = document.getElementById('fondoayuda');
  if(!obj)return
  obj.style.left = Pos + 'px';
  obj.style.width = ancho + 'px';
  obj.style.display='block';
  if(Pos > 555)
    IdAyuda = setTimeout( "MostrarAyudaMascota("+(Pos-3)+","+(ancho+3)+");", 1 );
  else
  {
    obj.style.color = 'Black';
    IdAyuda = setTimeout( "OcultarAyudaMascota("+(Pos)+","+(ancho )+");", 15000 );
  }
}

function OcultarAyudaMascota(Pos, ancho)
{
  clearTimeout(IdAyuda);
  var obj = document.getElementById('fondoayuda');
  if(!obj)return
  obj.style.left = Pos + 'px';
  obj.style.width = ancho + 'px';
  obj.style.display='block';
  if(ancho > 0)
    IdAyuda = setTimeout( "OcultarAyudaMascota("+(Pos+3)+","+(ancho-3)+");", 1 );
  else
  {
    obj.style.width = '0px';
    obj.style.display='none';
  }
}
function MostrarFiltrosSeleccionados(el)
{
  var obj = document.getElementsBySelector('.FiltrosContraidos');
  if(!obj)
    el.scrollIntoView(false);
  else if(obj.length==0)
    el.scrollIntoView(false);
  else
  {
    obj = document.getElementById('ImagenAccionFiltro');
    if(!obj) return
    obj.className='EstirarCapa'
	  obj.onclick=function(){EfectoPersiana('Filtrar-por', 16, 180, 20, IdObjEvento);obj.onclick='';}
  }
}
function MostrarBotonPersiana(el)
{
  var obj = document.getElementsBySelector('.FiltrosContraidos');
  if(!obj)
  {
    el.className='ContraerCapa'
    el.innerHTML = TextoContraerFiltros
	el.onclick=function(){IdPersiana = setInterval("CambiarAlto('Filtrar-por', -16, 0, 20, 'ImagenAccionFiltro')", 1);}
  }
  else if(obj.length==0)
  {
    el.className='ContraerCapa'
    el.innerHTML = TextoContraerFiltros
  	el.onclick=function(){IdPersiana = setInterval("CambiarAlto('Filtrar-por', -16, 0, 20, 'ImagenAccionFiltro')", 1);}
  }
  else
  {
    el.className='EstirarCapa'
    el.innerHTML = TextoExpandirFiltros
	  el.onclick=function(){EfectoPersiana('Filtrar-por', 16, 180, 20, el.id);el.onclick='';}
	}
}

var TextoContraerFiltros = "Ocultar&nbsp;filtros"
var TextoExpandirFiltros = "Mostrar&nbsp;filtros"
var IdPersiana;
var IdAyuda;
var myrules = {
	'a' : function(el){el.onclick = function(){MostrarEsperando();}},
	'a.disabled' : function(el){el.onclick = function(){return false;}},
  'body' : function(el){
                         IdAyuda = setTimeout( "MostrarAyudaMascota(861,0);", 25000 );
                         window.onscroll = function(){clearTimeout(IdAyuda);}
                       },
	'form' : function(el){el.onsubmit = function(){MostrarEsperando();}},
	                         
	'input' : function(el){el.onfocus = function(){ el.select(); el.style.background = 'white'; }},
	'tr.anuncio a' : function(el){ el.style.textDecoration='none'; el.style.color='black';el.onclick = function(){return false;}},
	'tr.anuncio' : function(el){
	                     el.style.cursor='pointer';
	                     el.onmousemove=function(){el.style.backgroundColor='#f9e78e';};
	                     el.onmouseout=function(){el.style.backgroundColor='';};
	                     el.onclick=function(){
	                       var Tag = el.getAttribute('Tag');
	                       var MayorEdad = getCookie("MayorEdad")
	                       if( ((Tag.substr(0,4)=='1504')||(Tag.substr(0,4)=='1505')||(Tag.substr(0,4)=='1506')||(Tag.substr(0,4)=='1507')||(Tag.substr(0,4)=='1508')) && ( MayorEdad != "MayorEdad") ) 
	                       {
	                         if( !confirm('El anuncio puede tener contenido sólo para adultos\n¿Eres mayor de edad?') )
	                           return false;
	                         else
	                           setCookie("MayorEdad", "MayorEdad", null, "/" );
	                       }
	                       MostrarEsperando();
	                       Tag = Tag.substr( Tag.indexOf('/') )
	                       location.href=Tag;};
	                   },
	'.Btn_Buscar' : function(el){el.style.display='none';},
	'.limarcado' : function(el){MostrarFiltrosSeleccionados(el);},
	'#criterios-ayuda' : function(el){el.onmousemove=function(){MostrarAyudaMascota(555,310);};el.onmouseout=function(){OcultarAyudaMascota(555,0);}},
	'#ImagenAccionFiltro' : function(el){MostrarBotonPersiana(el);},
	'#o' : function(el){ el.onchange=function(){MostrarEsperando();el.form.submit();}},
//  '#pagina' : function(el){ el.scrollIntoView(true);},
	'#r' : function(el){el.onchange=function(){MostrarEsperando();el.form.submit();}},
	'#Filtrar-por' : function(el){  
/*
	  el.style.overflow='hidden';
	  IdPersiana = setInterval("CambiarAlto('Filtrar-por', -13, 0, 20)", 1);
*/	                             }
              };
Behaviour.register(myrules);
