function setHTMLToContenedor(contenedor,html){
	
	document.getElementById(contenedor).innerHTML = html;
	document.getElementById(contenedor).style.display = "block";
	
}

function SetContainerHTML(id,html,processScripts){
	
	mydiv = document.getElementById(id);
	
	mydiv.innerHTML = html;
	
	if(processScripts != false){
		
		var elementos = mydiv.getElementsByTagName('script');
		
		for(i=0;i<elementos.length;i++) {
			var elemento = elementos[i];
			nuevoScript = document.createElement('script');
			nuevoScript.text = elemento.innerHTML;
			nuevoScript.type = 'text/javascript';
			if(elemento.src!=null && elemento.src.length>0)nuevoScript.src = elemento.src;
			elemento.parentNode.replaceChild(nuevoScript,elemento);
		}
	}
}

function FAjax (url, capa, metodoEnvio, valores, postFunction ){
	
	if(url == null || url == ""){
		alert("No se ha definido una url");
		return;
	}
	
	var ajax=creaAjax();

	if(metodoEnvio != null && metodoEnvio.toUpperCase() == 'POST'){
		ajax.open ('POST', url, true);
	} else if (metodoEnvio != null && metodoEnvio.toUpperCase() == 'GET'){
		valores = null;
		ajax.open ('GET', url, true);
	} else {
		alert("No se ha elegido un método de envío");
		return;
	}
	
	var capaContenedora;
	
	if(capa != null && capa != ""){
		capaContenedora = document.getElementById(capa);
	} else {
		capaContenedora = document.getElementById("cuerpo");
	}
		
	ajax.onreadystatechange = function() {

		if (ajax.readyState == 1) {

			
	 
		} else if (ajax.readyState == 4){
			   
			if (ajax.status == 200){

				SetContainerHTML( capa, ajax.responseText, true);
				pageTracker._trackPageview(url);

			}
			else if (ajax.status == 404){
			
				capaContenedora.innerHTML = "No se encuentra la dirección de destino";

			} else {

				capaContenedora.innerHTML = "Error: "+ ajax.status;

			}
			//Se ejecuta la función si se ha puesto
			if(postFunction != null && postFunction != ""){
				eval(postFunction);
			}
		}		  
	}
	 
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send(valores);
	return;
}

function creaAjax(){
	var objetoAjax = false;
         
	try {
		/*Para navegadores distintos a internet explorer*/
		objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e){
	
		try {
			/*Para explorer*/
			objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) {
			objetoAjax = false;
		}
	
	}

	if (!objetoAjax && (typeof XMLHttpRequest != 'undefined')){ 
		objetoAjax = new XMLHttpRequest();
	}

	return objetoAjax;
}
function crearPeticionPOST(formulario){
    var elementosFormulario = formulario.elements;
    var pairs = new Array();

    for (var i = 0; i < elementosFormulario.length; i++) {

        if ((name = elementosFormulario[i].name) && (value = elementosFormulario[i].value))
            pairs.push(name + "=" + encode(value));
    }

    return pairs.join("&");
} 

