/* v2009-03-09 */
/* Generales */
function popup(surl, sname, bscroll, iwidth, iheidht) { 
	var ileft = (screen.width - iwidth) / 2;
	var itop = (screen.height - iheidht) / 2; 
	window.open(surl,sname,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+bscroll+",resizable=no,left="+ileft+",top="+itop+",width="+iwidth+",height="+iheidht);
}

function radiopopup() { 
	var ileft = (screen.width - 312) / 2;
	var itop = (screen.height - 246) / 2; 
	window.open("/98pop/popup","98POP","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+ileft+",top="+itop+",width=312,height=246");
}

function mostrar(capa) {
	var obj = document.getElementById(capa);
	var link = document.getElementById("ampliar_"+capa);
	if(obj.style.display == "block") {
		obj.style.display = "none";
		link.innerHTML = "Seguir leyendo";
	}
	else {
		obj.style.display = "block";
		link.innerHTML = "Ocultar";
	}
}

function igualar_columnas() {
	//Ajustes
	var ajuste_pub = -70;
	var ajuste_ban = 300;
	
	//Igualar Columnas (Izquierda - Derecha)
	var col_izq = document.getElementById("columna_izquierda");
	var col_der = document.getElementById("columna_derecha");
	if(col_izq.offsetHeight > col_der.offsetHeight) {
		col_der.style.height = (col_izq.offsetHeight - 2)+"px";
	}

	//Igualar Columnas Publicidad - Columna mayor (TopBanner)
	var col_pub_1 = document.getElementById("columna_pub_1");
	var col_pub_2 = document.getElementById("columna_pub_2");
	var col_mayor = 0;
	if (col_pub_1.offsetHeight > col_pub_2.offsetHeight) {
		col_mayor = col_pub_1.offsetHeight + ajuste_ban;
	}
	else {
		col_mayor = col_pub_2.offsetHeight + ajuste_ban;	
	}
	col_pub_1.style.height = (col_der.offsetHeight + ajuste_pub)+"px";
	col_pub_2.style.height = col_pub_1.style.height;
	
	//Banner Flotante
	var bLeft = document.getElementById("contenedor").offsetLeft + 513;
	var bTopFijo = 12;
	var bTopLimit = col_mayor;
	FloatDiv("floatLayer", bLeft, bTopFijo, bTopLimit).floatIt();
}

function galeria(ig, fs, eg, es) {
	var imagen = ig;
	var fotos = fs;
	var epigrafe = eg;
	var	epigrafes = es;
	var puntero = 0;

	this.setFoto = setFoto;
	function setFoto(pos) {
		puntero = pos;
		imagen.src = fotos[puntero];
		imagen.alt = epigrafes[puntero] != '' ? epigrafes[puntero] : ' ';
		imagen.title = epigrafes[puntero] != '' ? epigrafes[puntero] : ' ';
		epigrafe.innerHTML = epigrafes[puntero] != '' ? epigrafes[puntero] : ' ';
 	}

	this.sgtFoto = sgtFoto;
	function sgtFoto() {
		if (puntero < fotos.length - 1)
			setFoto(puntero + 1);
		else
			setFoto(0);
	}

	this.antFoto = antFoto;
	function antFoto() {
		if (puntero > 0)
			setFoto(puntero - 1);
		else
			setFoto(fotos.length - 1);
	}
}

function tamanoTexto(accion) {
	var obj = document.getElementById("cuerpo");
	var max = 180;
	var min = 90;
	if (obj.style.fontSize == '') {
		obj.style.fontSize = "100%";
	}
	
	if (accion == "i" ) {
		valCookie = readCookie("cuerpo");
		if (valCookie != null) {
			obj.style.fontSize = valCookie;
		}
		else {
			createCookie("cuerpo", "100%", 365);
			obj.style.fontSize = "100%";
		}
	}

	actual = parseInt(obj.style.fontSize);
	incremento = 10;
	
	if ((accion == "a") && ((actual+incremento) <= max)) {
		valor = actual+incremento;
		obj.style.fontSize = valor+"%";
		obj.lineHeight = valor+"%";
		createCookie("cuerpo", valor+"%", 365);
		igualar_columnas();
	}
	
	if ((accion == "d") && ((actual+incremento) >= min)) {
		valor = actual-incremento;
		obj.style.fontSize = valor+"%";
		obj.lineHeight = valor+"%";
		createCookie("cuerpo", valor+"%", 365);
		igualar_columnas();
	}
} 

/* Cookies */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/* Encuesta */
function validarEncuesta(form) {
	var ok = 0;
	for (i = 0; i < form.opcion.length; i++) {
		if(form.opcion[i].checked == true) {
			ok = 1; 
		}
	}	
	if (ok == 0) {
		alert("Debe ingresar primero una opción.");
		return false;
	}
}  

//Favoritos
function aFav() {
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite("http://www.elpopular.com.ar", "Diario El Popular");
	} 
	else {
		if (navigator.appName == "Netscape") alert ("Presione Crtl+D para agregar Diario El Popular a sus favoritos.")
	}
}

/* Banner Flotante */
/*   *********************************************************
     * You may use this code for free on any web page provided that 
     * these comment lines and the following credit remain in the code.
     * Floating Div from http://www.javascript-fx.com
     ********************************************************  
	 
	 Moficaciones TopLimit y Posición desde la Izquierda - 2009-03-09 - mt
*/
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function FloatDiv(id, sx, sy, tl) {
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.tl = tl;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function() {
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		if(this.cy<this.tl) {
			this.cy=this.tl;
		}
		this.cx=document.getElementById("contenedor").offsetLeft + 513;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}