function EscribeTiempoActualizacion(idCapa,tsWeb,tsContenido)
{
	var diff = tsWeb-tsContenido;
	var minDiff = Math.floor(diff/60);
	if(minDiff < 2)
	{
		document.getElementById(idCapa).innerHTML = "Actualizado hace 1 min";
	}
	else if(minDiff < 60)
	{
		document.getElementById(idCapa).innerHTML = "Actualizado hace "+minDiff+" min";
	}
}

function AmpliarFoto(link,id,width,height)
{
	width2 = width + 40;
	height2 = height + 130;
	
	if (width2 > 800)
	{
		width2 = 800;
	}
	
	if (height2 > 600)
	{
		height2 = 600;
	}
	
	//window.open(link,'imagen_'+id,'top=10,left=10,width='+width2+',height='+height+',scrollbars=yes');
	window.open(link,'imagen_'+id,'top=10,left=10,width='+width2+',height='+height2+',scrollbars=yes');
	return false;
}

function AbrirDirecto(deporte,id)
{
	window.open('http://www.20minutos.es/directo/'+deporte+'/'+id+'/',deporte+id,'width=650,height=545,scrollbars=no'); 
	return false;	
}

function AbrirDirecto640x600(deporte,id)
{
	window.open('http://www.20minutos.es/directo/'+deporte+'/'+id+'/',deporte+id,'width=640,height=600,scrollbars=no'); 
	return false;	
}

function AbrirDirectoMedidas(deporte,id,ancho,alto)
{
	window.open('http://www.20minutos.es/directo/'+deporte+'/'+id+'/',deporte+id,'width='+ancho+',height='+alto+',scrollbars=no'); 
	return false;	
}

function ModuleTabs(tab,idMod,modname,limit)
{
	if(document.getElementById('modtabs'+modname+'_'+tab+'_'+idMod).blur)
	{
		document.getElementById('modtabs'+modname+'_'+tab+'_'+idMod).blur();	
	}
	for(i=0;i<limit;i++)
	{
		document.getElementById(modname+'_'+i+'_'+idMod).style.display = 'none';
	}
	document.getElementById(modname+'_'+tab+'_'+idMod).style.display = 'block';
	for(i=0;i<limit;i++)
	{
		document.getElementById('modtabs'+modname+'_'+i+'_'+idMod).className = '';
	}
	document.getElementById('modtabs'+modname+'_'+tab+'_'+idMod).className = 'current';
	return false;
}

function VolverUrlCabeceraIdentificacion(form_name,input_name,url_volver)
{
	var url_retorno=location.href;
	//Si el formulario es el de comentarios
	if (form_name=="comments_volver"){
		var posicion=url_retorno.toString().indexOf('#');
		if (posicion != -1){
			url_retorno=url_retorno.substring(0,posicion)
		}
		url_retorno=url_retorno+'#nuevo_comentario';
	}
	
	document.getElementById(input_name).value=url_retorno;
	document.getElementById(form_name).target = "_self";
	document.getElementById(form_name).action = url_volver;
	document.getElementById(form_name).submit();	
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		};
	}
}

var IEContentLoad = {
	list: [],

	add: function(func) {
		if (document.readyState == 'complete') {
			func();
			return;
		}

		// store function
		this.list.push(func);

		// check DOM loaded only once
		if (this.list.length == 1) {
			this.check();

			// trying to always fire before onload
			document.onreadystatechange = function() {
				if (document.readyState == 'complete') {
					document.onreadystatechange = null;
					IEContentLoad.load();
				}
			};
		}
	},

	// If IE is used, use the trick by Diego Perini
	// http://javascript.nwbox.com/IEContentLoaded/
	check: function() {
		try {
			// throws errors until after ondocumentready
			document.documentElement.doScroll('left');
		} catch (e) {
			// alert('timeout');
			setTimeout(IEContentLoad.check, 100);
			return;
		}
		// no errors, fire
		IEContentLoad.load();
	},

	load: function() {
		while (func = this.list.shift()) {
			func();
		}
	}
};

function addDOMLoadEvent(func)
{
	if(document.all)
	{
		//IE, lo hacemos en el onload
		// addLoadEvent(func);
		IEContentLoad.add(func);
	}
	else if(typeof(jQuery) == 'function')
	{
		//Resto, lo hacemos con JQuery(si existe)
		$(document).ready(func);
	}
	else
	{
		addLoadEvent(func);
	}	
}

/* Funciones de cadenas */
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function Reemplazar(cadena,origen,destino)
{

	aux = cadena;
	while(aux.indexOf(origen,0) != -1)
	{
		posencontrada = aux.indexOf(origen,0);
		aux = aux.substring(0,posencontrada) + destino + aux.substring(posencontrada+origen.length,aux.length);
	}
	return aux;
}

function calcHeight(iframe)
{
		//Calculamos la altura de un iframe iframe
		var the_height= document.getElementById(iframe).contentWindow.document.body.scrollHeight;
		
		//Cambiamos la altura del iframe
		document.getElementById(iframe).height= the_height;
}

function calcTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		do {
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return curtop;
}

function GetReferer() { return document.URL; }

var DIA_DE_LA_SEMANA = ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"];
