// JavaScript Document
var sUserAgent = navigator.userAgent;
var isIE = sUserAgent.indexOf("compatible") > -1 && sUserAgent.indexOf("MSIE") > -1;


/*Funcion para poder ubicar en el menu de la pagina el link que corresponde a la pagina actual*/
function ubicarPaginaActual()
{
	var menu = document.getElementById('listaMenu').childNodes;
	
	for(x=0;x<menu.length;x++)
	{
		
		if(menu[x].firstChild!=null)
		{
			var a = menu[x].firstChild;
			if (a.href.search("index.php")!=-1 && (a.href == window.location.href || window.location.href == a.href.split("index.php")[0]))
			{
				a.id ="pagActiva";
			}
			if( a.href.search("soluciones.php")!=-1 && (window.location.href.search("solAbogados.php")!=-1|| window.location.href.search("solBancario.php")!=-1 || window.location.href.search("solEducativo.php")!=-1 || window.location.href.search("solMensajeria.php")!=-1))																																																				   			{
				a.id ="pagActiva";																																																							   			}
			if( a.href.search("servicios.php")!=-1 && (window.location.href.search("cgd.php")!=-1|| window.location.href.search("digitalizacion.php")!=-1 || window.location.href.search("alquiler.php")!=-1 || window.location.href.search("contratosIntegralesMant.php")!=-1 || window.location.href.search("controlConsumibles.php")!=-1 || window.location.href.search("microfilmElec.php")!=-1))
			{
				a.id ="pagActiva";																																																							   			
			}
			if( a.href.search("productos.php")!=-1 && (window.location.href.search("scanners.php")!=-1|| window.location.href.search("software.php")!=-1 || window.location.href.search("microfilmElec.php")!=-1))
			{
				a.id ="pagActiva";																																																							   			}	
			else if(a.href == window.location.href)
			{
				a.id ="pagActiva";
			}
		}
	}
}




/*funciones usadas para desplegar el mapa del sitio*/
function verMapa(oEvent)
{
	var listaMapa = document.getElementById('listaMapa');
	var a  = document.getElementById('linkMapa');
	listaMapa.style.position = "absolute";
	listaMapa.style.display = "block";
	if(!isIE)
	{
		var x = a.offsetLeft;
		var y = a.offsetTop;
		listaMapa.style.top = y-185+"px";
		listaMapa.style.left =x-200+"px";
	}
	else
	{
		var obj = a.getBoundingClientRect();
		var left = obj.left;
		var top = obj.top;
		var bottom = obj.bottom;
		var right = obj.right;
			
		

		listaMapa.style.top = document.documentElement.scrollTop+top-180+"px";
		listaMapa.style.left =left-200+"px";
	}
	
	
}

function quitarMapa(oEvent)
{
	var listaMapa = document.getElementById('listaMapa');
	if(!isIE)
	{
		var nVer = navigator.appVersion;
		var nAgt = navigator.userAgent;

		if((verOffset=nAgt.indexOf("Opera"))!=-1)
		{
			var x = oEvent.clientX+document.body.scrollLeft; //posicion del mouse respecto a la pagina y no al browser
			var y = oEvent.clientY+document.body.scrollTop; //posicion del mouse respecto a la pagina y no al browser
		}
		else
		{

			var x = oEvent.clientX+this.scrollX; //posicion del mouse respecto a la pagina y no al browser
			var y = oEvent.clientY+this.scrollY; //posicion del mouse respecto a la pagina y no al browser
		}
		var x2 = listaMapa.offsetLeft; //posicion del mapa
		var y2 = listaMapa.offsetTop;  //posicion del mapa

		if(x<=x2 || x>=x2+545 || y<=y2 || y>=y2+235)
		{
			listaMapa.style.display = "none";
		}
	}
	else
	{
		var x = oEvent.clientX+( document.documentElement.scrollLeft || document.body.scrollLeft || 0); //posicion del mouse respecto a la pagina y no al browser
		var y = oEvent.clientY+( document.documentElement.scrollTop || document.body.scrollTop || 0); //posicion del mouse respecto a la pagina y no al browser
		var x2 = listaMapa.offsetLeft; //posicion del mapa
		var y2 = listaMapa.offsetTop;  //posicion del mapa

		if(x<=x2 || x>=x2+545 || y<=y2 || y>=y2+235)
		{
			listaMapa.style.display = "none";
		}
	}
	

}





function desplegarLogin()
{
	
	var espLogin = document.getElementById('espacioLogin');
	var boton  = document.getElementById('botonDespLogin');
	var mensaje = document.getElementById("mensajeLogin");

	if(espLogin.style.display == "block")
	{
		espLogin.style.display = "none";
		boton.style.background = "url(data/images/box-head.gif) 1px -17px";
		mensaje.innerHTML = "";
	}
	else
	{
		espLogin.style.display = "block";
		boton.style.background = "url(data/images/box-head2.gif) 1px -17px";
	}
}

function validarLogin()
{
var login = document.getElementById("login");
var password = document.getElementById("passwordLogin");

if(login.value!="" && password.value!="")
{
	
	var request = zXmlHttp.createRequest();
	request.open("POST", "php/procesarLogin.php", true);
	 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.onreadystatechange = function ()
		{
			if (request.readyState == 4)
			{
				if (request.status == 200)
				{
					var mensaje = document.getElementById("mensajeLogin");
					var resp = request.responseText;
					if (resp != "1" )
					{
						mensaje.innerHTML = resp;
					}
					else
					{
						mensaje.innerHTML = "entro";
						window.location = "http://chie.uniandes.edu.co/~s3716a20/ameritec/src/usuario.php";
					}
				}
			}
		};
		request.send("login="+login.value+"&password="+password.value+"&nocache=" + Math.random());
}
else
{
	var mensaje = document.getElementById("mensajeLogin");
	if(login.value=="" && password.value=="")
	{	
		mensaje.innerHTML = "Login y password incorrectos";
	}
	else if(login.value=="" && password.value!="")
	{
		mensaje.innerHTML = "Login incorrecto";
	}
	else if(login.value!="" && password.value=="")
	{
		mensaje.innerHTML = "Password incorrecto";
	}	
}
}

/*============================================================================================================================*/
/*============================================================================================================================*/
//							FUNCIONES PARA EL TRATAMIENTO Y VALIDACION DEL FORMULARIO DE CONTACTO
/*============================================================================================================================*/
/*============================================================================================================================*/

function desplegarFormContacto(oEvent)
{
	var formContacto = document.getElementById('contenidoContactenos');
	var formContacto2 = document.getElementById('zonaForm');

	formContacto.style.display="block";
	formContacto2.style.display="block";

	 if(isIE)
	 {
		formContacto.style.width = screen.width+"px";
		formContacto2.style.left = document.getElementsByTagName("body")[0].clientWidth*0.2+80+"px";
		 formContacto2.style.top = document.documentElement.scrollTop+"px";
	 }
	 else
	 {
		 formContacto.style.width = window.screen.width+"px";
		 formContacto2.style.left = document.getElementsByTagName("body")[0].clientWidth*0.2+80+"px";
		  formContacto2.style.top = window.pageYOffset+"px";
	 }
	 
	document.getElementById('email').focus();
	var superior = document.getElementById('superior');
	superior.style.visibility="hidden";


}

function esconderContactenos()
{
	var formContacto = document.getElementById('contenidoContactenos');
	var formContacto2 = document.getElementById('zonaForm');
	formContacto.style.display="none";
	formContacto2.style.display="none";
	var superior = document.getElementById('superior');
	superior.style.visibility="visible";
}



// JavaScript Document

function validarEnviar()
{
	var nombre = document.getElementById('nombre');
	var email = document.getElementById('email');
	var comentarios = document.getElementById('comentarios');
	var empresa = document.getElementById('empresa');
	var telefono = document.getElementById('telefonoCont');
	var cargo = document.getElementById('cargo');
	var ciudad = document.getElementById('ciudad');
	
	var mensaje = document.getElementById('mensajeResultado');
	
	if(nombre.value!="" && email.value!="" && comentarios.value!="" && ciudad.value!="")
	{
		if(((telefono.value!="" && !isNaN(telefono.value)) || telefono.value=="") && email.value.indexOf('@')!=-1)
		{
			if (zXmlHttp.isSupported()) 
			{
				var oXmlHttp = zXmlHttp.createRequest();
				
				var query = "nombre="+nombre.value+"&email="+email.value+"&empresa="+empresa.value+"&telefono="+telefono.value+"&cargo="+cargo.value+"&ciudad="+ciudad.value+"&comentarios="+comentarios.value+"&nocache=" + Math.random();
		
				oXmlHttp.open("POST", "php/contacto.php", true);
				oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				oXmlHttp.onreadystatechange = function () 
				{
					if (oXmlHttp.readyState == 4) 
					{
						if (oXmlHttp.status == 200) 
						{
							mensaje.innerHTML = oXmlHttp.responseText;
							/*if(oXmlHttp.responseText == "El mensaje ha sido enviado de forma exitosa a $mail_to")
							{ 
								setTimeout("mensaje.innerHTML =''",1950);
							}*/
						}
					}
				}

				oXmlHttp.send("nombre="+nombre.value+"&email="+email.value+"&empresa="+empresa.value+"&telefono="+telefono.value+"&cargo="+cargo.value+"&ciudad="+ciudad.value+"&comentarios="+comentarios.value+"&nivel=0"+"&nocache=" + Math.random());
			}
			else 
			{
				
				
			}
		}
		else if(isNaN(telefono.value) && email.value.indexOf('@')==-1)
		{
			mensaje.innerHTML = "El telefono y el email ingresados no son v&aacute;lidos";
			
		}
		else if(isNaN(telefono.value))
		{
			//telefono incorrecto
			mensaje.innerHTML = "El telefono ingresado no es v&aacute;lido";
		}
		else if(email.value.indexOf('@')==-1)
		{
			//email incorrecto
			mensaje.innerHTML = "El email ingresado no es v&aacute;lido";
		}
	}
	else if(nombre.value=="" || email.value=="" || comentarios.value=="" || ciudad.value=="")
	{
		mensaje.innerHTML = "Los campos de nombre, comentario, email y ciudad son necesarios";
	}
	else if(nombre.value=="" && email.value.indexOf('@')==-1 && comentarios.value=="")
	{
		mensaje.innerHTML = "El email ingresado no es v&aacute;lido";
	}
}
