var K_ie=0;
var K_gec=0;
var actM=0;

function abreM(id)
{
	if (actM!=0 && actM!=id)
	{
		document.getElementById('contM'+actM).style.display='none';
		document.getElementById('rec'+actM).src='img/recoff.png';
	}
	if (actM!=id)
	{
		document.getElementById('contM'+id).style.display='block';
		document.getElementById('rec'+id).src='img/recon.png';
		actM=id;
	}
	else
	{
		if (document.getElementById('contM'+id).style.display=='block')
		{
			document.getElementById('contM'+id).style.display='none';
			document.getElementById('rec'+id).src='img/recoff.png';
			actM=0;
		}
		else
		{
			document.getElementById('contM'+id).style.display='inline';
			document.getElementById('rec'+id).src='img/recon.png';
			actM=id;
		}
	}
}

function init()
{
	pon_pie();
	var pos=navigator.userAgent.indexOf("MSIE");if (pos>-1) K_ie=1;
	pos=navigator.userAgent.indexOf("Gecko");if (pos>-1) K_gec=1;
	if (K_gec==1)
		document.getElementById('recnews').className='recnews_gecko';
	if (sizeCol==1)
	{
		resizeCol('not1','not2');
		resizeCol('not3','not4');
		resizeCol('not5','not6');
		resizeCol('not7','not8');
		resizeCol('not9','not10');
	}
	var x=Math.floor(Math.random()*(pil.length));
	document.getElementById('scpil').innerHTML=pil[x];
	//mueve_p();
}

function pon_pie()
{
	var p=document.getElementById('pie');
	p.style.display='inline';
	var t=document.getElementById('tc');
	var h=t.style.top;
	h=h.substring(0,h.length-2);
	p.style.top=(h-0+t.offsetHeight-0+5)+'px';
	var hh=t.offsetHeight-0+200;
	var bb=document.getElementById('banner_bot');
	if (bb!=null)
		hh+=document.getElementById('banner_bot').offsetHeight;
	var hmd=document.getElementById('mender').offsetHeight;
	if (hmd>hh)
		hh=hmd+30;
	if (hh>500)
		document.getElementById('md').style.height=hh+'px';
}

function suscribirse()
{
	document.getElementById('recnews').innerHTML="<div id='contnews' class='dF tx11' style='padding:15px'><form action='envia_news.php' name='fnews' method='post' target='ifrnews'>Escribe tu dirección de e-mail:<br /><input id='tx_news' type='text' name='email' class='dF tx11' style='margin-bottom:7px;margin-top:7px;width:146px;border:1px solid #7F9DB9'/><br /><img align='absmiddle' src='img/botok.png' alt='Buscar' style='cursor:pointer;cursor:hand;' onclick='document.fnews.submit()'/></div></form><img src='img/cerrarnews.png' style='position:absolute;right:11px;top:8px;font-size:9px;cursor:pointer;cursor:hand' onclick=\"document.getElementById('recnews').style.display='none'\"/>";
	document.getElementById('recnews').style.display='inline';
}

function imgint_dcha(id)
{
	eval("var lim=lim_"+id+";");
	eval("var act=act_"+id+";");

	if (act==lim.length-1)
		return;

	++act;
	eval("act_"+id+"=act;");
	document.getElementById('fot_'+id).src='imagenes/'+lim[act];
	if (act==lim.length-1)
	{
		document.getElementById('fdcha_'+id).style.cursor='default';
		document.getElementById('fdcha_'+id).src='img/fdchaoff.png';
	}
	if (act>0)
	{
		document.getElementById('fizda_'+id).style.cursor='pointer';
		document.getElementById('fizda_'+id).style.cursor='hand';
		document.getElementById('fizda_'+id).src='img/fizda.png';
	}

}

function imgint_izda(id)
{
	eval("var lim=lim_"+id+";");
	eval("var act=act_"+id+";");

	if (act==0)
		return;

	--act;
	eval("act_"+id+"=act;");
	document.getElementById('fot_'+id).src='imagenes/'+lim[act];
	if (act==0)
	{
		document.getElementById('fizda_'+id).style.cursor='default';
		document.getElementById('fizda_'+id).src='img/fizdaoff.png';
	}
	if (act<lim.length-1)
	{
		document.getElementById('fdcha_'+id).style.cursor='pointer';
		document.getElementById('fdcha_'+id).style.cursor='hand';
		document.getElementById('fdcha_'+id).src='img/fdcha.png';
	}
}

function resizeCol(id1,id2)
{
	var a1=document.getElementById(id1);
	var a2=document.getElementById(id2);
	if (a1!=null && a2!=null)
	{
		var h1=a1.offsetHeight;
		var h2=a2.offsetHeight;
		if (h1>h2)
			a2.style.height=h1+'px';
		else
			a1.style.height=h2+'px';
	}
}

function buscador()
{
	var t=document.fbus.t.value;
	if(t.length<4)
	{
		alert('El término a buscar debe tener al menos cuatro letras');
		return;
	}
	document.fbus.submit();
}

function lista_mas(id_cat)
{
	document.getElementById('ifrmas').src='lista_mas.php?id_cat='+id_cat+'&rand='+Math.random();
}

function cajas()
{
	var e=document.getElementById('maincont').getElementsByTagName('div');
	for (var x=0;x<e.length;x++)
	{
		if (e[x].className!='caja') continue;
		var cad='';
		var inn=e[x].innerHTML;
		var p=inn.split('.');
		cad="<div id='titcaja"+x+"' onclick=\"abrecaja("+x+")\"><img src='img/recoff.png'/>&nbsp;<strong><em>"+p[0]+".</em></strong></div><div id='caja"+x+"' style='display:none;'  onclick=\"abrecaja("+x+")\">";
		for (var y=1;y<p.length;y++)
			cad+=p[y]+'.';
		cad+="</div>";
		e[x].innerHTML=cad;
		e[x].style.display='block';
	}
}

function abrecaja(id)
{
	var o=document.getElementById('caja'+id);
	if (o.style.display=='none')
		o.style.display='block';
	else
		o.style.display='none';
}

var px=460;
var ixpil=0;

function mueve_p()
{
	var o=document.getElementById('scpil');
	px-=2;
	o.style.left=px+'px';
	if (px<-o.offsetWidth)
	{
		++ixpil;
		if (ixpil==pil.length)
			ixpil=0;
		o.style.left='460px';
		o.innerHTML=pil[ixpil];
		px=460;
	}
	setTimeout('mueve_p()',50);
}

var id_articulo=0;
function imprimir()
{
	var a=screen.width;
	var b=screen.height;
	var ancho=500;
	var alto=600;
	var x=(a-ancho)/2;
	var y=(b-alto)/2;
	window.open ('imprimir.php?id='+id_articulo,'imprimir','left='+x+',top='+y+',width='+ancho+',scrollbars=yes,height='+alto);
}

function init_print()
{
	document.getElementById('cont').innerHTML=window.opener.document.getElementById('art').innerHTML;
	window.print();
}

function guardar()
{
	document.getElementById('com').src='guardar.php?id='+id_articulo;
}

function enviar()
{
	document.getElementById('com').src='enviar.php?id='+id_articulo;
}

function imprime_valoracion()
{
	var a=screen.width;
	var b=screen.height;
	var ancho=420;
	var alto=370;
	var x=(a-ancho)/2;
	var y=(b-alto)/2;
	window.open ('imprimir_valoracion.php','imprimir','left='+x+',top='+y+',width='+ancho+',scrollbars=yes,height='+alto);
}

function init_print_vac()
{
	document.getElementById('cont').innerHTML=window.opener.document.getElementById('contvac').innerHTML;
	document.getElementById('contimp').style.display='none';
	var tit=window.opener.document.getElementById('titulo_art').innerHTML;
	var id=window.opener.document.getElementById('id_art').innerHTML;
	document.getElementById('cont').innerHTML+="<br /><br />Índice VAC (Versión simple) generado por el usuario en el artículo <i>"+tit+"</i> de Sarasqueta.com.<br /><br />http://www.sarasqueta.com/articulo.php?id="+id;
	window.print();
}