// JavaScript Document

function opertor(rro) {
	document.location.href = rro;	
	elem = document.documentElement;
	if (elem.requestFullscreen) {
		elem.requestFullscreen();
	} else if (elem.mozRequestFullScreen) { /* Firefox */
		elem.mozRequestFullScreen();
	} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
		elem.webkitRequestFullscreen();
	} else if (elem.msRequestFullscreen) { /* IE/Edge */
		elem.msRequestFullscreen();
	}
	
	
}

function vju()
{
	xajax_vju();
}

function vju_ads()
{
	$('#gambling').show();
	console.log('*********************************** act');
}

function emergentia()
{
	console.log('emerg');
	$.confirm({
		boxWidth: '50%',
		useBootstrap: false,
		icon: 'fas fa-exclamation-triangle',
		     type: 'red',
    typeAnimated: true,
    title: 'Atención. CONTENIDO SOLO PARA ADULTOS',
		content: '<div style="text-align:center">Los contenidos de mostrados en la presente página requieren de una CONFIRMACIÓN POR PARTE DEL USUARIO de su mayoría de edad.<br><br> Al responder afirmativamente, la dirección IP quedará registrada, así como la hora y el tipo de contenido al que ha accedido.<br><br>¿Eres mayor de 18 años?</div>',
		buttons: {
			si: {
				text: 'Sí',
				action: function() {
					console.log('valid');
					xajax_vju('valida');
				}
			},
			no: {
				text:'No',
				action:function() {
					window.location.href = 'https://www.elperiodicodeaqui.com';
				}
			}
    }
});
}

function crr_cat()
{
	 $("#catf").animate({bottom:"-=90px"},300);
}

function saltex(pa)
{
		xajax_saltex(pa);
	window.location.href='http://compartimapunt.es/?utm_source=periodico_aqui&utm_medium=megabanner_mobile_320X50&utm_campaign=compartim';

}

function corden()
{
	cm=$('#orden_coment_val').val();
	$('#iicoment').html('<div style="margin-top:2rem;margin-bottom:2rem;text-align:center"><img src="'+rxp_raiz+'vmega/imagenesiface/cargando4.gif"><br>Cargando resultados<br>Un momento por favor... </div>');	
	xajax_bloque_comentarios(cm);
}

function acc_ncuenta()
{
	window.location.href=rxp_raiz+'registro-usuarios/el-periodico-de-aqui';
}

function comentex()
{
	vmx=$('#incoment').val();
	xajax_tenvio(vmx);
	$('#hipercom').hide();
	$('#hipercomr').show();
}

function hipercomenta()
{
	xajax_bloque_comentarios();
}

function vota_enc_plus_inline(en)
{
	/*fax=$("form[name*='formencuesta"+en+"'].formencuesta"+en+".input");
	fax2=$(fax[0]);
	console.log(fax);
	console.log(fax2);
	*/
	f=eval("document.iformencuesta"+en+".voto");
	fo=eval("document.iformencuesta"+en);

	fallo=true;
	for (i=0;i<f.length;i++)
		{
			if(fo.voto[i].checked)
			{
				fallo=false;
				break;
			}
			
		}
	if(!fallo)
	{
	i=i+1;
	donde='ires_enc'+en;
	console.log('fdl');
	//alert('gracias por su voto');
	//$('#fondo_total').show();
	//emergente('emergente_contenedor');
	$('#contenido_modal').html('Gracias por su participaci&oacute;n');
	toggle_modal();	
	xajax_vota_encuesta(en,i,donde);
	}
	else
	{
		$('#contenido_modal').html('Oara votar debe seleccionar una opci&oacute;n');
		toggle_modal();	
	}
}

function inicio_bus_opi(mod)
{
	$('#bloque_listado_opi').show();
	$('#bloque_listado_opi').html('<div style="margin-top:2rem;margin-bottom:2rem;text-align:center"><img src="'+rxp_raiz+'vmega/imagenesiface/cargando4.gif"><br>Cargando resultados<br>Un momento por favor... </div>');
	if(mod=='grb')
	{

		
		rtbc=$('#rtbo').val();
		xajax_lista_col_opi(rtbc);
	}
	else
	{
		xajax_lista_col_opi('xx');	
		vv=true;
	}
	
}

function ver_detalle_opi(nn,antek)
{

	window.location.href=rxp_raiz+'autores-opinion/'+antek+'/'+nn;
}

function toggle_marcas(ac)
{
	$('input[type="checkbox"]').removeAttr('checked');
	if(ac=='marca')
	{
		$('input[type="checkbox"]').attr('checked','checked');
	}
}
function lanza_busqueda()
{
		vv=$('#caja_busqueda_plus').val();
		$('#res_busqueda').toggle("slide", { direction: "left" }, 500);
		xajax_lanza_busqueda(vv,'res_busqueda_contenido');
}
function lanza_busqueda_2()
{
		vv=$('#caja_busqueda_movx').val();
		if(vv=='')
		{
		vv=$('#caja_busqueda_persi').val();
		$('html, body').animate({
        scrollTop: $("#dcabecera").offset().top
    }, 1000);
		}
		$('#res_busqueda').toggle("slide", { direction: "left" }, 500);
		xajax_lanza_busqueda(vv,'res_busqueda_contenido');
}

function carga_plus(seccion)
{
	var acmma=false;
	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);
	if(acmma || acmma===undefined)
	$('#megabb').show();
	}
		
	vecess=bvisto('LOD');
	vaecess=bvisto('LODA');
	loleyos=leerxc('LEIDO');

	veces=parseInt(vecess);
	vaeces=parseInt(vaecess);
	loleyo=parseInt(loleyos);
}

function cierra_aviso()
{
	localStorage.setItem('cepda', '45ffgMXO0m_333dmc');
	xajax_cuquis_leidas(1);
	console.log('cl');
	fxcc = "31 Dec 2020 23:59:59 GMT";		
	guardarxc('LEIDO',1,fxcc);
//document.cookie="LEIDO= 1; expires ="+fecha_cad;
	aviso_leido = 1;

		
	$('#infop').hide();
}

function guardarxc(Nombre,Valor,Fecha){
         document.cookie=Nombre+"="+Valor+";expires="+Fecha;
         //window.cookie=Nombre+"="+Valor+";expires="+Fecha;		 
         }

function leerxc(nombre) {
		 valor=0;
		 console.log(document.cookie);
         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()
{
	loleyos=leerxc('LEIDO');
	loleyo=parseInt(loleyos);

	if(loleyo!=1)
	{

		$('#infop').show();
	}
}

function lsp()
{
	console.log('ilsp2');
	$('.noticia_cuerpo > div > span').each(function(i,x){
		es=$(this).attr('style');
		console.log(es);
		if(es=== undefined)
		{
			console.log('un');
		}
		else
		{
			pos_col=es.search('color:');
			if(es!='font-weight: bold;' && es!='font-style: italic;' && pos_col!=0)
			{
				$(this).attr('style','');
			}
		}
		});
$('.noticia_cuerpo > div > span > span').each(function(i,x){

				$(this).attr('style','');

		});	
}

function inicio()
{
	inicio_navegacion();
	$('img[src="https://www.elperiodicodeaqui.com/netpublisher/minfo/imagenes/"]').remove();
	lsp();
	carga_plus('');
	ctr_ini();
	$('a').on('click',function(evt)
							   {
								   console.log(evt);
							   });
	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');
								   togb='<div id="pre_slide" style="position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:50" onclick="$(\'#panel_tope\').hide(\'slide\',\'fast\');$(\'#pre_slide\').hide()">&nbsp;</div>';
								   $('#navega_up').prepend(togb);									   
								   
							   });
	$('#naver_mov').click(function()
							   {
								   //posicion_menu();
								   $('#panel_tope').toggle('slide','fast');
								   togb='<div id="pre_slide" style="position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:50" onclick="$(\'#panel_tope\').hide(\'slide\',\'fast\');$(\'#pre_slide\').hide()">&nbsp;</div>';
								   $('#navega_up').prepend(togb);									   
								   
							   });
	$('#navero_txt').click(function()
							   {
								   $('#panel_tope').toggle('slide','fast');
								   togb='<div id="pre_slide" style="position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:50" onclick="$(\'#panel_tope\').hide(\'slide\',\'fast\');$(\'#pre_slide\').hide()">&nbsp;</div>';
								   $('#navega_up').prepend(togb);		
								   
							   });	
	$('.cwas').click(function(){
							  xajax_cwas();
							  });
	
	//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 no_activo()
{
	$('#contenido_modal').html('Opci&oacute;n temporalmente no disponible.<br>Disculpe las molestias');
	toggle_modal();
}

function no_priv()
{
	$('#contenido_modal').html('Para poder valorar un comentario debe acceder como usuario registrado');
	toggle_modal();
}

function autovoto()
{
	$('#contenido_modal').html('No puede votar a su propio comentario');
	toggle_modal();
}

function yahavotado()
{
	$('#contenido_modal').html('Ya ha votado a este comentario');
	toggle_modal();
}

function acomentario()
{
	$("body, html").animate({scrollTop: ($( $('#ncoment') ).offset().top)-200 }, 600);
}


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');
			$('#infra2').css('top','210px');
			$('.mizquierdo a').css({'top':'0px'});
			$('.mderecho a').css({'top':'0px'});	
	}
	else
	{
	//console.log('no esta');
	$('#cabecera_persi').slideDown('fast');
			$('.mizquierdo a').css({'top':'100px'});
			$('.mderecho a').css({'top':'100px'});		
	}
	}
									  });
									  

/*

$(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 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');
	if(prop=='none')
	$('#icoa'+c).css({'transform' : 'rotate(90deg)'});
	else
	$('#icoa'+c).css({'transform' : 'rotate(0deg)'})
}

function cierra_aviso_deprec()
{
fxcc = "31 Dec 2020 23:59:59 GMT";		
guardarxc('LEIDO',1,fxcc);
aviso_leido=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;

             busca = lista[i].indexOf(nombre)
             if (busca > -1) {micookie=lista[i]}
			}
             }
		 if(micookie!='')
		 {
         igual = micookie.indexOf("=")
         valor = micookie.substring(igual+1)
		 }

         return valor
         }

function ctr_ini()
{
	var lga = localStorage.getItem('cepda');
	console.log('lga', lga);	
	if (lga === undefined || lga== null || lga == '')
	$('#infop').show();
	// loleyos=leerxc('LEIDO');

	// loleyo=parseInt(loleyos);

	// if(loleyo!=1)
	// {

	// 	$('#infop').show();
	// }
}



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()
{
	$('#zona_buscar_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);
}