// JavaScript Document

function no_activo()
{
	$('#contenido_modal').html('Opci&oacute;n temporalmente no disponible.<br>Disculpe las molestias');
	toggle_modal();
	
}

function toggle_modal()
{
	$('#fondo_total_plus').toggle();
	$('#modal_plus').toggle("slide", { direction: "left" }, 500);
}


function reseta()
{
	$('#zona_buscar_persi').hide('fast');
	$('#panel_tope').hide('slide','fast')
}



$.fn.isInViewport = function() {
  var elementTop = $(this).offset().top;
  var elementBottom = elementTop + $(this).outerHeight();

  var viewportTop = $(window).scrollTop();
  var viewportBottom = viewportTop + $(window).height();

  return elementBottom > viewportTop && elementTop < viewportBottom;
  
};

$(window).on('resize scroll',function() {
	anchix=$(window).width();
	if(anchix>719)
	{
	if($('#dcabecera').isInViewport())
	{
	//console.log('esta');
	//$('#dcabecera').hidde();
	$('#cabecera_persi').slideUp('fast');
	}
	else
	{
	//console.log('no esta');
	$('#cabecera_persi').slideDown('fast');
	}
	}
									  });
									  

/*

$(window).on('resize scroll', function() {
  $('.color').each(function() {
      var activeColor = $(this).attr('id');
    if ($(this).isInViewport()) {
      $('#fixed-' + activeColor).addClass(activeColor + '-active');
    } else {
      $('#fixed-' + activeColor).removeClass(activeColor + '-active');
    }
  });
});
*/

function inicio_navegacion()
{
	//jQuery('#nav').stellarNav();
	$("#navega_up").click(function() {
    $('html, body').animate({
        scrollTop: $("#mrx").offset().top
    }, 1000);
});
	
	//jQuery('#nav2').stellarNav();
}

function carga_plus(seccion)
{
max_descanso=4;
fxcc = "31 Dec 2020 23:59:59 GMT";		
megaban=megaban_activo;
cres=leerxc('megab');
//alert('cre '+cres);

if(cres>0)
{
cres=cres-1;	
guardarxc('megab',cres,fxcc);
}
if(cres==0)
cres=max_descanso;
cresa=leerxc('megab');
//alert('cres '+cres);
console.log('vban ','s'+seccion+' m '+megaban+' cres: '+cres+' md:'+max_descanso);
if(seccion=='' && megaban=='si' && cres==max_descanso)
{
console.log('xm');
guardarxc('megab',max_descanso-1,fxcc);
$('#megabb').show();
}
	
vecess=bvisto('LOD');
vaecess=bvisto('LODA');
loleyos=leerxc('LEIDO');

veces=parseInt(vecess);
vaeces=parseInt(vaecess);
loleyo=parseInt(loleyos);

}

function leerxc(nombre) {
		 valor=0;
         lista = document.cookie.split(";")
		 tam=lista.length;
		//alert(tam);
		micookie='';
		co=1;
         for (i in lista) {
			if(co<=tam)
			{
			co=co+1;
			 //alert(lista[i]);
             busca = lista[i].indexOf(nombre)
             if (busca > -1) {micookie=lista[i]}
			}
             }
		 if(micookie!='')
		 {
         igual = micookie.indexOf("=")
         valor = micookie.substring(igual+1)
		 }
		 //alert('v '+valor);
         return valor
         }


function bvisto(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
}

function despleg(c)
{
	$('#ul'+c).toggle('fast');
	prop=$('#icoa'+c).css('transform');
	console.log(prop);
	if(prop=='none')
	$('#icoa'+c).css({'transform' : 'rotate(90deg)'});
	else
	$('#icoa'+c).css({'transform' : 'rotate(0deg)'})
}

function cierra_aviso()
{

fxcc = "31 Dec 2020 23:59:59 GMT";		
guardarxc('LEIDO',1,fxcc);
//document.cookie="LEIDO= 1; expires ="+fecha_cad;
aviso_leido=1;
xajax_cuquis_leidas(1);
$('#infop').hide();
}

function guardarxc(Nombre,Valor,Fecha){
         document.cookie=Nombre+"="+Valor+";expires="+Fecha;
         }

function leerxc(nombre) {
		 valor=0;
         lista = document.cookie.split(";")
		 tam=lista.length;
		micookie='';
		co=1;
         for (i in lista) {
			if(co<=tam)
			{
			co=co+1;
			 //alert(lista[i]);
             busca = lista[i].indexOf(nombre)
             if (busca > -1) {micookie=lista[i]}
			}
             }
		 if(micookie!='')
		 {
         igual = micookie.indexOf("=")
         valor = micookie.substring(igual+1)
		 }
		 //alert('v '+valor);
         return valor
         }

function ctr_ini()
{
	let vacepta = localStorage.getItem('cacepta');
	if(vacepta===undefined || vacepta!='ok')
		$('#infop').show();
}

function inicio()
{
	inicio_navegacion();
	carga_plus('');
	ctr_ini();
	var meses = new Array ("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
var diasSemana = new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado");
var f=new Date();
var vf=f.getDate() + " " + meses[f.getMonth()] + " " + f.getFullYear();
	$('#calen').html(vf);
		
	console.log('inicio');
	//inicializa_ocultador('cabecera');
	$('#naver').click(function()
							   {
								   //posicion_menu();
								   $('#panel_tope').toggle('slide','fast')
								   
							   });
	$('#naver_mov').click(function()
							   {
								   //posicion_menu();
								   $('#panel_tope').toggle('slide','fast')
								   
							   });
	
	//edit
	/*
	$('.wrp div').not('.bloque').click(function(e){
							mi_ele=$(this);
							procesos_dev(mi_ele);
							e.stopPropagation();
							});
	$('div').mouseenter(function(){
							mi_elee=$(this);
							//procesos_entrada(mi_ele);
						});
	$(document).keydown(function(ee){
								   tl=ee.which;
								   //console.log(tl);
								   if(tl==16)
								   mays=true;
								   else
								   mays=false;
								   });
	$(document).keyup(function(ee){
								   tl=ee.which;
								   if(tl==16)
								   mays=false;
								   });
	$('#panel_dev').draggable();
	//fin de edit
	*/
}

function elementVisible(e)
{
	return true;
}

function inicializa_ocultador(nombre_elemento) {
	ancho=$(window).width();
	$("#visvis").html(ancho);
	elemento=$('#'+nombre_elemento);
	$('#barra_top').hide();
  	$(window).on('scroll resize', function () {
	ancho=$(window).width();
	$("#visvis").html(ancho);
	console.log(ancho);										  
    if (elementVisible(elemento))
	{
		console.log('ya no está oculta la cabecera');
		$('#barra_top').hide();
		$('#cabecera').show();
		//$('#barra_top').css("visibility","hidden");
		//$('#cabecera').css("visibility","visible");	
    }
	else
	{
		//$('#barra_top').show();
		console.log('esta oculta la cabecera');
		$('#cabecera').hide();
		$('#barra_top').show();
		//$('#cabecera').css("visibility","hidden");			
		//$('#barra_top').css("visibility","visible");
	
	}
  });
}

function posicion_menu()
{
	pos=$('#naver').position();
	console.log(pos);
	muestra_menu(pos);
	
}

function muestra_menu(px)
{
	console.log(px.top);
	$('#barra_top_menu').css("top",px.top);
	$('#barra_top_menu').css("left",px.left);
	$('#barra_top_menu').css("height",300);
	$('#barra_top_menu').show();
	alert('Database Link Error. Module Secciones_grupo.xmd Fail');
}

function toggle_de_b()
{
	
	var al=$(window).height();
	var pbt=$('#barra_top').height();
	var af=al-pbt-20;
	//console.log('af',af);
	$('#barra_top_menu').css("height",af);
	$('#barra_top_menu').toggle()
}
function t()
{
	$('#b').html('----');
}
function activa_busqueda()
{
	$('#caja_busqueda_mov').toggle('slide','fast');
	$('#caja_busqueda_mov').focus();
}

function pop_toggle(nombre,obj,offx,offy,ancho,alto)
{
	ele=$(obj).offset();
	x=ele.left;
	y=ele.top;
	x=x+offx;
	y=y+offy;
	console.log('x: '+x+'  y:'+y);
	$('#fondo_total').toggle();
	$('#'+nombre).css({top: y});
	$('#'+nombre).css({left: x});
	$('#'+nombre).css({width: ancho});
	$('#'+nombre).css({width: ancho});
	$('#'+nombre).toggle();
	$('#'+nombre).html('x: '+x+'   y:'+y);
}