// JavaScript Document
var titulo; //es un elemento h3
var imagen; // es un elemento img
var sintesis; 
var totalnoticias;
//var idnoticia;
var cabecera; // es un elemento h2
var idnoticia;
var limite=1;
var fechan;

$(document).ready(function () {
 cargarDocumento();

});



function crearInstancia(){
//alert("hola");
XMLHttp = false;
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}else if(window.ActiveXObject){
var versiones = new Array ("Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP", "Microsoft.XMLHTTP");
for(var i=0; i<versiones.length; i++){
try{
XMLHttp = new ActiveXObject(versiones[i]);
if(XMLHttp){
return XMLHttp;

break;
}
}catch(e){};

}
}
}

function anteriorNoticia(){
	if(limite<parseInt(totalnoticias)-1){
		limite+=1;
		}
	
	if(limite ==1){
	var siguiente = document.createElement('a');
	siguiente.href="javascript:siguienteNoticia();";
	siguientetext = document.createTextNode("Reciente");
	siguiente.appendChild(siguientetext);
	document.getElementById("incluir_noticia_header").appendChild(siguiente);
	//$('#incluir_noticia_header').append(siguiente);
}
	
	cabecera =$("#incluir_noticia_header");
	titulo = $("#incluir_noticia_titulo");
	imagen = document.getElementById("incluir_noticia_imagen");
	sintesis = $("#contenido_noticia");
	idnoticia = $("#id_noticia");
	fechan = $("#id_fechanot");
	
	XMLHttp = crearInstancia();
	if(XMLHttp){
	url="historialnoticias/obtenernoticia.php?limite="+limite;
	XMLHttp.onreadystatechange=cambiaEstado;
	XMLHttp.open('GET',url,true);
	XMLHttp.send(null);
	}


}

function cambiaEstado(){

if(XMLHttp.readyState == 4){
var respuesta = XMLHttp.responseXML;
var restitulo = respuesta.getElementsByTagName("titulo")[0].firstChild.nodeValue;
var ressintesis = respuesta.getElementsByTagName("sintesis")[0].firstChild.nodeValue;
var resimagen = respuesta.getElementsByTagName("imagen")[0].firstChild.nodeValue;
totalnoticias = parseInt(respuesta.getElementsByTagName("total")[0].firstChild.nodeValue);
var residnoticia = respuesta.getElementsByTagName("idnoticia")[0].firstChild.nodeValue;
var resfechan = respuesta.getElementsByTagName("fecha")[0].firstChild.nodeValue;
titulo.html(restitulo);
//imagen.src = document.getElementById("variable_urln").value+"/fotos/"+resimagen;
sintesis.html(ressintesis);
fechan.html(resfechan);

//document.getElementById('id_noticia').href =document.getElementById("variable_url").value+"/noticias/index.php?idnoticia="+residnoticia;
document.getElementById('incluir_noticia_titulo').href =document.getElementById("variable_url").value+"/noticias/index.php?noticia="+residnoticia;
//alert(document.getElementById("variable_url").value+"/noticias/index.php?idnoticia="+residnoticia);

}
}


function siguienteNoticia(){
		
	
	
	
	if(limite>0){
	limite-=1;
	}
	
	
	if(limite<1){
	var sigremove =document.getElementById("incluir_noticia_header").childNodes[1];
	document.getElementById("incluir_noticia_header").removeChild(sigremove);
	if(document.getElementById("incluir_noticia_header").childNodes[1] != null)document.getElementById("incluir_noticia_header").removeChild(sigremove);
}

	



	cabecera =$("#incluir_noticia_header");
	titulo = $("#incluir_noticia_titulo");
	imagen = document.getElementById("incluir_noticia_imagen");
	sintesis = $("#contenido_noticia");
	idnoticia = $("#id_noticia");
	
	XMLHttp = crearInstancia();
	if(XMLHttp){
	url="historialnoticias/obtenernoticia.php?limite="+limite;
	XMLHttp.onreadystatechange=cambiaEstado;
	XMLHttp.open('GET',url,true);
	XMLHttp.send(null);
	}


}






