// Documento JavaScript

//For Dynamic Load of JS
function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e); 
}

function NuevoAjax(){
	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 LoadWithJs(url, donde, js){
	var contenido, preloader;
	contenido = document.getElementById(donde);
	preloader = document.getElementById('preloader');
	ajax=NuevoAjax();
	ajax.open("GET", url, true);
	ajax.onreadystatechange=function(){

		if(ajax.readyState==1){
			preloader.innerHTML = "Cargando...";
			//preloader.style.background = "url('loading.gif') no-repeat";

		}else if(ajax.readyState==4){
			if(ajax.status==200){
				contenido.innerHTML = ajax.responseText;
				preloader.innerHTML = "";
				//preloader.style.background = "url('loaded.gif') no-repeat";
				if(js != ""){
					dhtmlLoadScript(js);
				}
			}else if(ajax.status==404){
				preloader.innerHTML = "La página no existe";
			}else{
				preloader.innerHTML = "Error de carga. Vuelva a intentarlo.";
			}
		}
	}
	ajax.send(null);
}

function Load(url, donde){
	LoadWithJs(url, donde, "");
}

function Cargar(url){
	//Load(url, 'contenido');
	LoadWithJs(url, 'contenido', 'js/slimbox.js');
}
function CargarFooter(){
	Load('footer.htm', 'footer');
}
function CargarGaleria(url, donde){
	LoadWithJs(url, donde, 'js/slimbox.js');
}
