function cargarWeb(idContent) {
	cargarPag(idContent+".php", "web");
}

function formatLinks(destino)
{
	var links = new Array();
	links = (destino ? document.getElementById(destino).getElementsByTagName("a") : document.links);

	if (links.length > 0)
	{
		for (i in links)
		{
			if (links[i])
			{
				if (links[i].rel == "menu")
				{
					links[i].onclick = function()
					{
						cargarPag(this.href+".php", "secciones")
						return false;
					}
				}
				if (links[i].rel == "foto")
				{
					links[i].onmouseover = function()
					{
						this.style.filter = "alpha(opacity=50)";
						this.style.opacity = ".5";
					}
					links[i].onmouseout = function()
					{
						this.style.filter = "alpha(opacity=100)";
						this.style.opacity = "1";
					}
					links[i].target = "_blank";
					/*links[i].onclick = function()
					{
						imgLoader(this.href);
						return false;
					}*/
				}

				links[i].onfocus = function()
				{
					this.blur();
				}
			}
		}
	}
}
/*function formatImgs(gal)
{
	var imagenes = document.getElementById(gal).getElementsByTagName("img");

	if (imagenes.length > 0)
	{
		for (i in imagenes)
		{
			imagenes[i].onmouseover = function()
			{
				this.style.filter = "alpha(opacity=50)";
				this.style.opacity = ".5";
			}
			imagenes[i].onmouseout = function()
			{
				this.style.filter = "alpha(opacity=100)";
				this.style.opacity = "1";
			}
			imagenes[i].onclick = function()
			{
				imgLoader(this.name);
			}
		}
	}
}*/

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 cargarPag(url, idContent)
{
	contenedor = document.getElementById(idContent);

	ajax = NuevoAjax();
	ajax.open("GET", url, true);

	ajax.onreadystatechange = function() {
		var loader = document.getElementById("loader");

		if (ajax.readyState == 1){
			if (idContent != "web")	{
				contenedor.innerHTML = "";
			}
			loader.style.visibility = "visible";
		}
		else if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				loader.style.visibility = "hidden";
				contenedor.innerHTML = ajax.responseText;
				if (idContent == "web")
				{
					formatLinks();
					cargarPag("home.php", "secciones")
				}
				/*else if (url.match("nosotros"))
				{
					formatImgs("galeria");
				}*/
				else
				{
					formatLinks("secciones");
				}
			}
			else if (ajax.status == 404) {
				cargarPag("error.html", idContent);
			}
			else {
				contenedor.innerHTML = "Error: " + ajax.status;
			}
		}
	}

	ajax.send(null);
}

function cargarServicios(cat)
{
	contenedor = document.getElementById("serviciosContent");

	ajax = NuevoAjax();
	ajax.open("GET", "servicios.php?cat="+cat.getAttribute("name"), true);
	ajax.onreadystatechange = function() {

		if (ajax.readyState == 1){
			contenedor.innerHTML = "cargando lista...";
		}
		else if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				contenedor.innerHTML = ajax.responseText;
			}
			else if (ajax.status == 404) {
				contenedor.innerHTML = "Error. Categoria invalida.";
			}
			else {
				contenedor.innerHTML = "Error: " + ajax.status;
			}
		}
	}

	ajax.send(null);
}

function enviar()
{
	nombre = document.enviarMail.nombre.value;
	mail = document.enviarMail.mail.value;
	comentario = document.enviarMail.comentario.value;
	statusMail = document.getElementById("mensaje");

	if (nombre == "nombre" || mail == "mail" || comentario == "comentario" || !mail.match("@"))
	{
		statusMail.innerHTML = "existen campos inválidos";
		return false;
	}
	else
	{
		enviarMail("contacto.php?nombre="+nombre+"&mail="+mail+"&comentario="+comentario, "mensaje");
	}
}

function enviarMail(url, idContent)
{
	statusMail = document.getElementById(idContent);

	ajax = NuevoAjax();
	ajax.open("GET", url, true);

	ajax.onreadystatechange = function() {

		if (ajax.readyState == 1){
			statusMail.innerHTML = "enviando...";
		}
		else if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				statusMail.innerHTML = ajax.responseText;
			}
			else if (ajax.status == 404) {
				statusMail.innerHTML = "Error en el envio, intente mas tarde.";
			}
		}
	}

	ajax.send(null);
}

/*function imgLoader(imgSrc)
{
	loader = document.createElement("div");
	loader.id = "loaderMain";

	veil = document.createElement("div");
	veil.id = "veil";

	boxLoader = document.createElement("div");
	boxLoader.id = "fotoLoader";
	boxLoader.style.opacity = ".7";
	boxLoader.style.display = "none";
	boxLoader.style.width = "125px";
	boxLoader.style.top = document.body.clientHeight/2 - boxLoader.offsetHeight/2;
	boxLoader.style.left = document.body.clientWidth/2 - boxLoader.offsetWidth/2;
	boxLoader.innerHTML = "cargando imagen...";

	imgLoaded = new Image();
	imgLoaded.src = imgSrc;

	imgClose = document.createElement("div");
	imgClose.id = "cerrarImagen";

	cargandoFoto = setInterval('imgProgress(imgLoaded);' , 100);

	imgClose.onclick = function() {
		unloadImgLoader();
	}

	loader.appendChild(veil);
	loader.appendChild(boxLoader);

	document.body.appendChild(loader);
}
function imgProgress(img)
{
	if (img.complete)
	{
		porcentaje = 1;

		logo = document.getElementById("logo");
		footer = document.getElementById("footer");

		loader.removeChild(boxLoader);

		imagenL = document.createElement("div");
		imagenL.id = "imagenL";

		imagenL.appendChild(imgClose);
		imagenL.appendChild(imgLoaded);

		if (document.body.clientWidth > document.body.clientHeight)
		{
			if((img.height+33) > document.body.clientHeight)
			{
				porcentaje = ((document.body.clientHeight-30) / (img.height+33));
			}
		}
		else
		{
			if ((img.width+20) > document.body.clientWidth)
			{
				porcentaje = ((document.body.clientWidth-30) / (img.width+20));
			}
		}

		img.width = img.width*porcentaje;
		img.height = img.height*porcentaje;

		imagenL.style.width = img.width;
		imagenL.style.height = img.height + 18;
		imagenL.style.top = document.body.clientHeight/2 - (img.height+33)/2;
		imagenL.style.left = document.body.clientWidth/2 - (img.width+20)/2;

		logo.style.visibility = "hidden";
		footer.style.visibility = "hidden";

		loader.appendChild(imagenL);
		clearInterval(cargandoFoto);
	}
	else
	{
		boxLoader.style.display = "block";
	}
}

function unloadImgLoader()
{
	logo = document.getElementById("logo");
	footer = document.getElementById("footer");
	boxL = document.getElementById("loaderMain");

	document.body.removeChild(boxL);

	logo.style.visibility = "visible";
	footer.style.visibility = "visible";
}*/
