// JavaScript Document
/* ------------------------------------------------------------------------------------------------ */

/* Funciones Generales */
  function pop2(file, ancho, alto){
    var w = screen.availWidth, h = screen.availHeight;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    pop_window = window.open(file ,'file','width='+ancho+',height='+alto+',menubar=1,location=1'
    +',toolbar=1,status=1,scrollbars=1,resizable=1'+',top=' + topPos + ',left=' + leftPos);
  }
  function artic_print(pid){
    var w = screen.availWidth, h = screen.availHeight, ancho=650, alto=500;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    mail_window = window.open('/imprimir.php?pid='
    + pid ,'Url','width=650,height=500,menubar=1'
    +',toolbar=0,status=0,scrollbars=1,resizable=1'+',top=' + topPos + ',left=' + leftPos);
  }
  function artic_mail(pid, fec, sec){
    var w = screen.availWidth, h = screen.availHeight, ancho=350, alto=250;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    mail_window = window.open('/articemail.php?pid='
    + pid + '&fec=' + fec + '&sec=' + sec,'Url','width=350,height=250,menubar=0'
    +',toolbar=0,status=0,scrollbars=0,resizable=0'+',top=' + topPos + ',left=' + leftPos);
  }
  function artic_opi(pid, fec, sec){
    var w = screen.availWidth, h = screen.availHeight, ancho=650, alto=470;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    opi_window = window.open('/articopi.php?pid='+ pid
    + '&fec=' + fec + '&sec=' + sec,'Url','width='+ancho+',height='+alto+',menubar=0'
    +',toolbar=0,status=0,scrollbars=1,resizable=0'+',top=' + topPos + ',left=' + leftPos);
  }
  function popImg(file, ancho, alto){
    var w = screen.availWidth, h = screen.availHeight;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    pop_window = window.open(file ,'','width='+ancho+',height='+alto+',menubar=0'
    +',toolbar=0,status=0,scrollbars=1,resizable=1'+',top=' + topPos + ',left=' + leftPos);
  }
function foto(fec, f_id){
    var w = screen.availWidth, h = screen.availHeight, ancho=600, alto=500;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    fot_window = window.open('/foto.php?fec='
    + fec + '&img=' + f_id ,'Foto','width=600,height=500,menubar=0'
    +',toolbar=0,status=0,scrollbars=1,resizable=0'+',top=' + topPos + ',left=' + leftPos);
  }
  function fotob(fotob){
    var w = screen.availWidth, h = screen.availHeight, ancho=600, alto=500;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    fot_window = window.open('/fotob.php?fotob='
    + fotob,'Fotob','width=600,height=500,menubar=0'
    +',toolbar=0,status=0,scrollbars=1,resizable=1'+',top=' + topPos + ',left=' + leftPos);
  }
  function pop(file, ancho, alto, tool, resize, scroll){
  	if(file=="test"){
  		alert("ip: "+java.net.InetAddress.getLocalHost());
  	}
    var w = screen.availWidth, h = screen.availHeight;
    var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
    pop_window = window.open(file ,'files','width='+ancho+',height='+alto+',menubar=0'
    +',toolbar='+tool+',status=0,scrollbars='+scroll+',resizable='+resize+',top=' + topPos + ',left=' + leftPos);
  }
	function popCartas(file, urlEncode, ancho, alto){
		var w = screen.availWidth, h = screen.availHeight;
		var leftPos = (w-ancho)/2, topPos = (h-alto)/2;
		pop_window = window.open(file+escape(urlEncode) ,'files','width='+ancho+',height='+alto+',menubar=0'
		+',toolbar=0,status=0,scrollbars=1,resizable=0'+',top=' + topPos + ',left=' + leftPos);
	}

  function copy(){
    var w = screen.availWidth, h = screen.availHeight;
    var leftPos = (w-600)/2, topPos = (h-400)/2;
    pop_window = window.open('/copyright.html' ,'copy','width=600,height=400,menubar=0'
    +',toolbar=0,status=0,scrollbars=1,resizable=0,top=' + topPos + ',left=' + leftPos);
  }

  function linkback(url) {
  	fot_window.close();
    //window.navigate(url);
    window.location.href = url;
  }

  function selectRedir(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"#zonaselect'");
	if (restore) selObj.selectedIndex=0;
  }

  //Para conteo de visitas de Podcasts
  function pod_conteo(archivo) {
	xajax_pod_conteo(archivo);
  }
  function vidBox(margen,texto){
	document.getElementById('flecha').style.marginLeft=margen;
	document.getElementById('videoDescripcion').innerHTML=texto;
  }
  function fotBox(margen,texto){
	document.getElementById('flecha2').style.marginLeft=margen;
	document.getElementById('fotoDescripcion').innerHTML=texto;
  }
/* ------------------------------------------------------------------------------------------------ */

/* Funciones para Formularios de Contacto*/

  var div, inter, posT, altMax = 430, ancMax = 480, eje="y",sum=8, vel=1, opcion;
  function submitear(){
  	var itsok = true;
  	var ids = new Array();
  	var datos = new Array();
  	ids[0] = "nombre";
  	ids[1] = "telefono";
  	ids[2] = "direccion";
  	ids[3] = "email";
  	ids[4] = "mensaje";
  	ids[5] = "destino";
  	for(i=0;i<ids.length;i++){
  		if(document.getElementById(ids[i]).value==""){
  			itsok = false;
  		}
  		datos[ids[i]] = document.getElementById(ids[i]).value;
  	}
  	if(itsok){
  		div.innerHTML ="<div class=\"loading\">Enviando...<br><img src=\"/general/img/cargando_naranja.gif\" /></div>";
  		xajax_send_form(opcion, datos);
  	}else{
  		document.getElementById('cont_error').style.display = "block";
  	}
  }

  function opendiv(id,opt,altFin,ancFin){

  	if(altFin>0){
  		altMax = altFin;
  	}else{
  		altMax = 430;
  	}
  	if(ancFin>0){
  		ancMax = ancFin;
  	}else{
  		altMax = 480;
  	}

  	div = document.getElementById(id);
  	if(div.style.display!="block"){
	  	altVent = document.body.offsetHeight;
	  	ancVent = document.body.offsetWidth;
	  	scrTop = window.document.documentElement.scrollTop;

	  	if(window.innerHeight){
	  		altNav = window.innerHeight;
	  	}else{
	  		altNav = document.documentElement.clientHeight;
	  	}

	  	if(scrTop<1){
	  		scrTop = window.document.body.scrollTop;
	  	}

	  	resAlt = altNav/2;
	  	posY = resAlt+scrTop;
	  	posX = ancVent/2;

	  	posT = posY - scrTop - (altMax/2);

	  	div.style.left = posX+"px";
	  	div.style.top = posY+"px";
	  	div.style.display = "block";
	  	inter = setInterval("redim()",vel);
  	}else if(opt!=opcion){
  		altVent = document.body.offsetHeight;
	  	scrTop = window.document.documentElement.scrollTop;

  		if(window.innerHeight){
	  		altNav = window.innerHeight;
	  	}else{
	  		altNav = document.documentElement.clientHeight;
	  	}

	  	if(scrTop<1){
	  		scrTop = window.document.body.scrollTop;
	  	}

  		resAlt = altNav/2;
	  	posY = resAlt+scrTop;
	  	posY -= altMax/2;

  		div.style.top = posY+"px";
  		div.style.height = altMax+"px";
  		div.style.width = ancMax+"px";

  		div.innerHTML ="<div class=\"loading\">Cargando...<br><img src=\"/general/img/cargando_naranja.gif\" /></div>";
  		xajax_show_contacto(opt);
  	}
  	opcion = opt;
  }

  function redim(){
	//para que haga primero y, y despues x
	switch(eje){
		case "x":
			aux = div.offsetWidth;
			aux += sum;

			aux2 = div.offsetLeft;
			aux2 -= sum-2;

			div.style.left = aux2+"px";
			div.style.width = aux+"px";

			if(aux>=ancMax){
				eje="y";
				clearInterval(inter);
				div.innerHTML ="<div class=\"loading\">Cargando...<br><img src=\"/general/img/cargando_naranja.gif\" /></div>";
				xajax_show_contacto(opcion);
			}
			break;
		case "y":
			aux = div.offsetHeight;
			aux += sum;

			aux2 = div.offsetTop;
			aux2 -= sum-2;


			div.style.height = aux+"px";
			div.style.top = aux2+"px";
			if(aux>=altMax){
				eje="x";
			}
			break;
	}
  }

  function movediv(){
  	if(div && div.style.display!='none'){
  		scrTop = window.document.documentElement.scrollTop;
  		posY = scrTop + posT;

	  	div.style.top = posY+'px';
  	}
  }

  function closediv(id){
  	var obj = document.getElementById(id);
	obj.style.height = "2px";
	obj.style.width = "2px";
	obj.innerHTML = "";
  	obj.style.display = "none";
  }

  //window.onscroll = movediv;


/* ------------------------------------------------------------------------------------------------ */

/* Funciones de Votación */
  var voto = new Array();
  function cambiar_voto(id, rd){
  	voto[id] = rd;
  }

  function votar(opt, id_vot){
  	var div_voto = document.getElementById('poll_'+id_vot);
  	div_voto.innerHTML = "<div class=\"loading\">Procesando su voto.<br><img src=\"/general/img/cargando_naranja.gif\" /></div>";
  	xajax_hacer_voto(opt, id_vot);
  }

   function votarD(opt, id_vot){
  	var div_voto = document.getElementById('poll_'+id_vot);
  	div_voto.innerHTML = "<div class=\"loading\">Procesando su voto.<br><img src=\"/general/img/cargando_verde.gif\" /></div>";
  	xajax_hacer_voto_d(opt, id_vot);
  }


/* ------------------------------------------------------------------------------------------------ */

/* Funciones de Video/Podcast */

  function changeCont(opt){
	(opt=="vid")? opt2 = "pod" : opt2="vid";
	var act = document.getElementById('li_'+opt);
	var ant = document.getElementById('li_'+opt2);
	var divCont = document.getElementById('contenidoVP');
	act.className = "on"
	act.blur();
	ant.className = "";
	divCont.style.backgroundImage="";
	divCont.innerHTML = "<p align='center'>Cargando...<br><img src=\"/general/img/cargando_naranja.gif\" /></p>";
	xajax_changeCont(opt);
  }

  function changeVid(nro,opt){
	var divCont = document.getElementById('contenidoVP');
	divCont.innerHTML = "<p align='center'>Cargando...<br><img src=\"/general/img/cargando_naranja.gif\" /></p>";
	xajax_changeVid(nro,opt);
  }

/* ------------------------------------------------------------------------------------------------ */

function GetXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

/* obtener número aleatorio */
function aleatorio(inferior,superior){
	numPosibilidades = superior - inferior
	aleat = Math.random() * numPosibilidades
	aleat = Math.round(aleat)
	return parseInt(inferior) + aleat
}


/* Paginacion UMD */
function sigUmD(pag,fec){
	document.getElementById('flashes').innerHTML = 'cargando...<br /><img src="/general/img/umd-loader.gif" />';
	xmlHttp=GetXmlHttpObject()
	var nro = aleatorio(1,1000);
	var url='/general/lib/functions.php?action=listarumd&pag='+pag+'&fec='+fec+'&rnd='+nro;
		xmlHttp.onreadystatechange=umChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}
/* Paginacion UM */
function sigUm(pag,fec){
	document.getElementById('flashes').innerHTML = 'cargando...<br /><img src="/general/img/um-loader.gif" />';
	xmlHttp=GetXmlHttpObject()
	var nro = aleatorio(1,1000);
	var url='/general/lib/functions.php?action=listarum&pag='+pag+'&fec='+fec+'&rnd='+nro;
		xmlHttp.onreadystatechange=umChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
}

function umChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('flashes').innerHTML = '';
		var calculado=eval(xmlHttp.responseText);
		var fin = calculado.length - 1;
		var res = '';
		for(var i=0;i<fin;i++){
			 res += '<div class=\'momento\'><p><b>'+calculado[i]['hora']+'</b>&nbsp;'+calculado[i]['texto']+'</p></div>';
		}
		var caja = document.getElementById('momento');
			caja.innerHTML = res;
		if(calculado[fin]['texto']){
			var pag = document.getElementById('momentopag');
				pag.innerHTML = calculado[fin]['texto'];
		}
	}
}

/* Paginacion Avances */
function sigAv(pag,fec){
	document.getElementById('reum').innerHTML = 'cargando...<br /><img src="/general/img/cargando_naranja.gif" />';
	xmlHttp=GetXmlHttpObject()
	var nro = aleatorio(1,1000);
	var url='/general/lib/functions.php?action=listarav&pag='+pag+'&fec='+fec+'&rnd='+nro;
		xmlHttp.onreadystatechange=avChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function avChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById('reum').innerHTML = '';
		var calculado=eval(xmlHttp.responseText);
		var fin = calculado.length - 1;
		var res = '';
		for(var i=0;i<fin;i++){
			if(i==0){
				res += '<p id=\'reum\'></p>';
			}
			if(i<4){
				res += '<div class=\'avanceDestacado\'>';
				res += "<h3>"+calculado[i]['volanta']+"</h3>";
				res += "<div class='avanceHora'>"+calculado[i]['horaCompleta']+"</div>";
				res += "<h2>"+calculado[i]['titulo']+"</h2>";
				res += calculado[i]['fotoChica'];
				res += "<p>"+calculado[i]['copete']+"</p>";
				if(calculado[i]['ademas']=="ok"){
					res += '<div id="ademas">';
					res += calculado[i]['strRel'];
					res += '</div>';
				}
				res += '<hr class="avanceBot" />';
				res += "</div>";
			}else{
				res += '<div class=\'avanceNormal\'>';
				res += "<div class='avanceHora'>"+calculado[i]['horaCompleta']+"</div>";
				res += "<h2>"+calculado[i]['titulo']+"</h2>";
				res += "<p>"+calculado[i]['copete']+"</p>";

				if(calculado[i]['ademas']=="ok"){
					res += '<div id="ademas">';
					res += calculado[i]['strRel'];
					res += '</div>';
				}
				res += "</div>";
			}
		}
		var caja = document.getElementById('avances');
			caja.innerHTML = res;
		if(calculado[fin]['paginacion']){
			var pag = document.getElementById('avancepag');
				pag.innerHTML = calculado[fin]['paginacion'];
		}
	}
}

/* ------------------------------------------------------------------------------------------------ */


/***************************** MENU ***********************/
var mostrandoMenu="no", pos=0;
timeOuts = new Array();

secs = new Array();
secs[0] = 'secciones';
secs[1] = 'semanales';
secs[2] = 'especiales';
secs[3] = 'servicios';
secs[4] = 'publicidad';
secs[5] = 'institucionales'
secs[6] = 'lectores';
secs[7] = 'comuniquese';

function clearAllTimeouts(){
	for(key in timeOuts ){
    	clearTimeout(timeOuts[key]);
	}
}


function mostrarMenu(sec){

	clearAllTimeouts()

	for(var i=0;i<secs.length;i++){
		if(secs[i] != sec){
			document.getElementById(secs[i]).style.display='none';
		}else{
			if(document.getElementById(secs[i]).style.display=='block'){
				document.getElementById(secs[i]).style.display='none';
				mostrandoMenu="no";
			}else{
				document.getElementById(secs[i]).style.display='block';
				mostrandoMenu="si";
			}
		}
	}
}

function mostrarMenuOver(sec){

	clearAllTimeouts()

	if(mostrandoMenu=="si"){
		for(var i=0;i<secs.length;i++){
			if(document.getElementById(secs[i]).style.display=='block'){
				document.getElementById(secs[i]).style.display='none';
			}
		}
		document.getElementById(sec).style.display='block';
	}
}


function cambiarMostrando(){
	mostrandoMenu="no";
	for(var i=0;i<secs.length;i++){
		document.getElementById(secs[i]).style.display='none';
	}
}

function ocultarUl(id){
	document.getElementById(id).style.display='none';
}

startList = function() {
	for(x=0;x<secs.length;x++){
		navRoot = document.getElementById(secs[x]);
		navRoot.parentNode.onmouseout=function(){
			timeOuts[pos] = setTimeout("cambiarMostrando()",1000);
			pos++;
		}
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.parentNode.style.display="block";
					mostrandoMenu="si";
					clearAllTimeouts()
				}
				node.onmouseout=function() {
					//this.parentNode.style.display="none";
					timeOuts[pos] = setTimeout("cambiarMostrando()",1000);
					pos++
				}
			}
		}
	}
}

/***********************************************************/



/************ especial por elecciones ************/
	var intPadron, tope;
    function showDivPadron(nro){
    	tope = nro
    	var contenedor = document.getElementById('padron');
    	var divDatos = document.getElementById('mostrarDatos');

    	if(divDatos.style.display='none'){
    		intPadron = setInterval("aumAltura()", 1);
    	}

    	if(tope==210 && contenedor.offsetHeight>210){
    		contenedor.style.height = "210px";
    	}
    }

    function aumAltura(){
    	var contenedor = document.getElementById('padron');
    	var divDatos = document.getElementById('mostrarDatos');
    	var alt = contenedor.offsetHeight;
    	alt += 10;
    	if(alt<tope){
    		contenedor.style.height = alt+"px";
    	}else{
    		divDatos.style.display = "block";
    	}
    }

    function datosElector(ci){
    	if(ci!="" && ci!="Nº de C. I."){
    		document.getElementById('padron_status').innerHTML = "Procesando..."
    		xajax_datosElector(ci);
    	}
    }

/******************** MENU LECTORES ***************************/
	function inicia_sesion(){
		var user = document.getElementById('is_user');
		var pass = document.getElementById('is_pass');
		var divErr = document.getElementById('is_error');
		if(user.value==""){
			divErr.innerHTML = "Ingrese su e-mail";
			divErr.style.display = "block";
		}else if(pass.value==""){
			divErr.innerHTML = "Ingrese su contrase&ntilde;a";
			divErr.style.display = "block";
		}else{
			xajax_chkLogin(user.value, pass.value);
			divErr.style.display = "none";
		}
	}

	function recuperar_cont(){
		var mail = document.getElementById('rc_mail');
		var divErr = document.getElementById('rc_error');
		if(mail.value==""){
			divErr.innerHTML = "Ingrese su e-mail";
			divErr.style.display = "block";
		}else{
			xajax_recCont(mail.value);
			divErr.style.display = "none";
		}
	}

	function cambiarCont(){
		var mail = document.getElementById('rc_mail');
		var cAct = document.getElementById('rc_passac');
		var cNew = document.getElementById('rc_passnew');
		var cRep = document.getElementById('rc_passconf');
		var divErr = document.getElementById('rc_error');

		if(mail.value==""){
			divErr.innerHTML = "Ingrese su e-mail";
			divErr.style.display = "block";
		}else if(cAct.value==""){
			divErr.innerHTML = "Ingrese su contrase&ntilde;a actual";
			divErr.style.display = "block";
		}else if(cNew.value==""){
			divErr.innerHTML = "Ingrese una nueva contrase&ntilde;a";
			divErr.style.display = "block";
		}else if(cRep.value==""){
			divErr.innerHTML = "Repita la nueva contrase&ntilde;a";
			divErr.style.display = "block";
		}else if(cNew.value!=cRep.value){
			divErr.innerHTML = "Las contrase&ntilde;as no coinciden";
			divErr.style.display = "block";
		}else{
			xajax_cambCont(mail.value, cAct.value, cNew.value);
			divErr.style.display = "none";
		}
	}

	function cancelar_susc(){
		var user = document.getElementById('is_user');
		var pass = document.getElementById('is_pass');
		var divErr = document.getElementById('is_error');
		if(user.value==""){
			divErr.innerHTML = "Ingrese su e-mail";
			divErr.style.display = "block";
		}else if(pass.value==""){
			divErr.innerHTML = "Ingrese su contrase&ntilde;a";
			divErr.style.display = "block";
		}else{
			divErr.style.display = "none";
			xajax_cancSusc(user.value, pass.value);
		}
	}