function objetoAjax(){
 var xmlhttp=false;
  try{
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e){
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }catch(E){
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function Pagina(nropagina){

 divContenido = document.getElementById('contenido');

 ajax=objetoAjax();

 ajax.open("GET", "paginador.php?pagina="+nropagina);
 divContenido.innerHTML= '<img src="../casasperu/imagenes/icons/wait.gif">';
 ajax.onreadystatechange=function()
 {
  if (ajax.readyState==4)
  {divContenido.innerHTML = ajax.responseText
  revisa()
  }
 }

 ajax.send(null)
}


var actualiza = 1000;

function faltan(myanio,mymes,mydia,myhora,myminuto,id)
{

var futuro = new Date (myanio,mymes,mydia,myhora,myminuto);

var ahora = new Date();
var faltan = futuro - ahora;
if (faltan > 0){
var segundos = Math.round(faltan/1000);
var minutos = Math.floor(segundos/60);
var segundos_s = segundos%60;
var horas = Math.floor(minutos/60);
var minutos_s = minutos%60;
var dias = Math.floor(horas/24);
var horas_s = horas%24;

document.getElementById('tiempofalta').innerHTML=dias + " dias : " + horas_s + " horas : " + minutos_s + " minutos : " + segundos_s + " segundos" ;

setTimeout("faltan(" + myanio + "," + mymes + "," + mydia + "," + myhora + "," + myminuto +","+ id +")",actualiza);
}
else {
document.getElementById('tiempofalta').innerHTML= "" ;
muestra('central','transmision.php','id='+id+'&iniciar=1')
//location.reload(true)

return true;
}
}






	var waittime=1000;


	//chatmsg.focus()
	//document.getElementById("chatwindow").innerHTML = "loading...";

	var xmlhttp = false;
	var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_read(url) {
	if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
			}
		}
	}

	if(!xmlhttp) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState==4) {
		document.getElementById("chatwindow").innerHTML = "<table class=titulo border=0 >"+ xmlhttp.responseText +"</table><a name=final></a><br><br><br>";

		zeit = new Date();
		ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
		intUpdate = setTimeout("ajax_read('chat/chat.txt?x=" + ms + "')", waittime)

		}
	}

	xmlhttp.open('GET',url,true);
	xmlhttp.send(null);

}

/* Request for Writing the Message */
function ajax_write(url){
	if(window.XMLHttpRequest){
		xmlhttp2=new XMLHttpRequest();
		if(xmlhttp2.overrideMimeType){
			xmlhttp2.overrideMimeType('text/xml');
		}
	} else if(window.ActiveXObject){
		try{
			xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
			}
		}
	}

	if(!xmlhttp2) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	xmlhttp2.open('GET',url,true);
	xmlhttp2.send(null);
	 document.location.href = "#final"
}

/* Submit the Message */
function submit_msg(){
	nick = document.getElementById("chatnick").value;
	msg = document.getElementById("chatmsg").value;

	if (nick == "") {
		check = prompt("please enter username:");
		if (check === null) return 0;
		if (check == "") check = "anonymous";
		document.getElementById("chatnick").value = check;
		nick = check;
	}

	document.getElementById("chatmsg").value = "";
	ajax_write("chat/w.php?m=" + msg + "&n=" + nick);

}

/* Check if Enter is pressed */
function keyup(arg1) {
	if (arg1 == 13) submit_msg();
}
function oculta_chat()
{

if(document.getElementById('capachat').style.display=='none')
{document.getElementById('capachat').style.display='block'}
else
{document.getElementById('capachat').style.display='none'}
}
/* Start the Requests! ;) */


function visitantes(web, myusuario)
{
muestra2('capauser','useronline.php','web='+web+'&myusuario='+myusuario);
}


function cambiar(id)
{
muestra("central","detallepagina.php","id="+id+"&month="+document.getElementById('mimes').value +"&year="+document.getElementById('mianio').value)
}





var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();




var animacion;


var pcapas = new Array(2)
var num=0;

pcapas[0]="tnoticias";
pcapas[1]="teventos";





var color = 0;
var suma = 20;


function aparecer(nume){



//var obj = document.getElementById(capa);

color += suma;


if (!(color>=110)){

for (a=0;a<=pcapas.length-1;a++)
{

document.getElementById([pcapas[a]+nume]).style.display = "block";
document.getElementById([pcapas[a]+nume]).style.filter = 'alpha(opacity='+color+')';
document.getElementById([pcapas[a]+nume]).style.opacity = color /100;
document.getElementById([pcapas[a]+nume]).style.MozOpacity = color /100;
document.getElementById([pcapas[a]+nume]).style.KHTMLOpacity = color /100;
}

window.setTimeout ('aparecer("' + nume +'");', 100);
}

}



function desvanecer(nume) {
//var obj2 = document.getElementById(capa);

color -= suma;



if (!(color <=-10)){
for (a=0;a<=pcapas.length-1;a++)
{
document.getElementById([pcapas[a]+nume]).style.filter = 'alpha(opacity='+color+')';
document.getElementById([pcapas[a]+nume]).style.opacity = color /100;
document.getElementById([pcapas[a]+nume]).style.MozOpacity = color /100;
document.getElementById([pcapas[a]+nume]).style.KHTMLOpacity = color /100;
}
	window.setTimeout ('desvanecer("' + nume + '");', 100);
}
else
{
for (a=0;a<=pcapas.length-1;a++)
{
document.getElementById([pcapas[a]+nume]).style.display = "none";
}
	//num=num+1
llama();
	}
	}





function llama()
{

num=num+1
if (num>2)
{num=1;}

if(document.getElementById([pcapas[0]+num])==null)
{
clearInterval(animacion)
}
else
{

if (color<=0)
{aparecer(num);
num=num-1}
else {desvanecer(num);}
}

}


function iniciaani()
{
animacion=setInterval("llama()",10000)
}
