var d = document;

function $( e ){
	return d.getElementById( e );
}

var obj = $('news');
function fade(speed){
color += speed;
obj.style.opacity = 0;
obj.style.MozOpacity = 0;
obj.style.KHTMLOpacity = 0;
	if (!(color >= 110)){
	obj.style.filter = 'alpha(opacity='+ color +')';
			obj.style.opacity = color / 100;
			obj.style.MozOpacity = color / 100;
			obj.style.KHTMLOpacity = color / 100;
			var v = window.setTimeout('fade('+ speed +')', 60);
	}else{
		obj.style.opacity = 100;
		obj.style.MozOpacity = 100;
		obj.style.KHTMLOpacity = 100;
		clearTimeout(v);
	}
}

window.onload = load;

var xmlhttp;

function load(){
	if (window.XMLHttpRequest){
		// IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}else{
		// IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			color = 0;
			fade(10);
			$("news").innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.open("GET","news.php",true);
	xmlhttp.send();
}

var pag = 1;
var sitio;

function nav(accion){

	if(accion == '-' && pag > 1){ // que no pase de la pag 1
		pag--;
		sitio = "news.php?p="+pag;
	}else if(accion == '+' && pag < 10){ //que no pase de la pag 10
		pag++;
		sitio = "news.php?p="+pag;
	}else{
		if( isNaN(accion) && accion.length > 0 ){
			sitio = accion;
		}else{
			sitio = "news.php";
		}	
	}
	
	if (window.XMLHttpRequest){
		// IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}else{
		// IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			color = 0;
			fade(10);
			$("news").innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.open("GET",sitio,true);
	xmlhttp.send();
}

function cargarUrl(url){

if (url.length == 0){ 
  $('enlace').innerHTML = "";
  $('loading').style.display = 'none';
  }

if (url.length != 0){
  $('loading').style.display = 'block';
  }

	if (window.XMLHttpRequest){
		// IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}else{
		// IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
			$('enlace').innerHTML = xmlhttp.responseText;
			$('loading').style.display = 'none';
		}
	}
	
	xmlhttp.open("GET","process.php?url="+url,true);
	xmlhttp.send();
}
