/////////////////////////////////////////////////////////////////////////
//
//						funciones básicas de ajax
//
//

function newXMLHttpRequest() {
	
	var xmlreq = false;
	
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		try { 
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) { 
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
			} // de catch()
		} // de catch
 	} // de else if

	return xmlreq;
} 

function getReadyStateHandler(req, responseXmlHandler) {
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {				
					responseXmlHandler(req.responseXML);
			} 
			else {
				var hellomsg = document.getElementById("herramientas");
				hellomsg.innerHTML = "ERROR: "+ req.status;
			}
    	} // if
 	} // de return

}

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//							Funcion para unir nodes.child mayores a a 4K
//
//			fuente:
//				http://trac.openlayers.org/attachment/ticket/1006/nodeValue.patch
//
function concatChildValues (node, def) { 
	var value = ""; 
	var child = node.firstChild; 
	var childValue; 
	while(child) { 
		childValue = child.nodeValue; 
		if(childValue) { 
			value += childValue; 
		} 
		child = child.nextSibling; 
	} 
	if(value == "" && def != undefined) { 
		value = def; 
	} 
	return value; 
}



//////////////////////////////////////////////////////////////////////////////////////////
//																						//
//								Actualizar Investigaciones							//
//																						//
//																						//
//																						//



function buscarInvestigacion(ano,tag){
	
	//alert('buscarNoticias(ano,tag)');
	//alert(ano);
	//alert(tag);


	var item = document.getElementById("seccionInvestigaciones");
	item.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"4\" cellpadding=\"0\">" +
    				 "<tr>" +
                     "<td><p>&nbsp</p></td>" +
                     "</tr>" +
                     "<tr>" +
                     "<td align=\"center\"><div class=\"botonera_03\"> <IMG SRC=\"../../imagenes/big-roller.gif\" ALIGN=\"CENTER\"></div></td>" +
                     "</tr>" +
                     "<tr>" +
                     "<td><p>&nbsp</p></td>" +
                     "</tr>" +
					 "</table>";


	var req = newXMLHttpRequest();

  	var callbackHandler = getReadyStateHandler(req, actualizarInvestigaciones);
  	req.onreadystatechange = callbackHandler;
	
  	
	req.open("POST", "../../auxiliar/buscarInvestigaciones.php", true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  
	  	
	req.send("ano=" + escape(ano) + "&tag="+escape(tag));


	/**/
}

function actualizarInvestigaciones(testXML) {
	//alert ("actualizar Investigaciones");
	// Extraer los HTML de cada tag
	var seccionInvestigaciones = testXML.getElementsByTagName("seccionInvestigaciones")[0];
		seccionInvestigaciones = concatChildValues(seccionInvestigaciones);
	// Colocar los elementos HTML donde corresponde
	var item = document.getElementById("seccionInvestigaciones");
	item.innerHTML = seccionInvestigaciones;
    	
}


