// DOCUMENTO JAVASCRIPT

// Esta función cargará las paginas
function navegar(url, id_contenedor){
var pagina_requerida = false
if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
pagina_requerida = new XMLHttpRequest()
} else if (window.ActiveXObject){ // pero si es IE
try {
pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){ // en caso que sea una versión antigua
try{
pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pagina_requerida.onreadystatechange=function(){ // función de respuesta
cargarpagina(pagina_requerida, id_contenedor)
}
pagina_requerida.open('GET', url, true) // asignamos los métodos open y send
pagina_requerida.send(null)
}
// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
	var contenedor = document.getElementById(id_contenedor);
	if(contenedor != undefined){
		contenedor.innerHTML=pagina_requerida.responseText;
		var s = contenedor.getElementsByTagName("script");
		for(var i=0;i<s.length;i++){
			eval(s[i].innerHTML);
		}		
	}
}

// JavaScript Document
function crearAjax()
{
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 ENVIO_CONTACTO()
{
	var t1, t2, t3, t4, t5, content;
	content = document.getElementById('content');
	t1 = document.getElementById('empresa').value;
	t2 = document.getElementById('nombre').value;
	t3 = document.getElementById('fono').value;
	t4 = document.getElementById('mail').value;    
	t5 = document.getElementById('motivo').value;
	t6 = document.getElementById('comentarios').value;
	if(t1==""){alert("FALTAN DATOS OBLIGATORIOS"); return false;}  
	if(t2==""){alert("FALTAN DATOS OBLIGATORIOS"); return false;}    
	if(t3==""){alert("FALTAN DATOS OBLIGATORIOS"); return false;}    
	if(t4==""){alert("FALTAN DATOS OBLIGATORIOS"); return false;}    
	if(t5==""){alert("FALTAN DATOS OBLIGATORIOS"); return false;}        
	ajax=crearAjax();
	ajax.open("GET", "envio_contacto.php?empresa="+t1+"&nombre="+t2+"&fono="+t3+"&mail="+t4+"&motivo="+t5+"&comentarios="+t6,true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4)
		{content.innerHTML = "MENSAJE ENVIADO CON EXITO";}
	}
	ajax.send(null);
	document.getElementById('empresa').value="";
	document.getElementById('nombre').value="";
	document.getElementById('fono').value="";
	document.getElementById('mail').value="";    
	document.getElementById('motivo').value="";
	document.getElementById('comentarios').value="";
}

/*FUNCION PARA EL GRAFICO*/
function valida_graficar(form)
{
	var popup;
	var url;

	if (form.tema.value == "")
		{ alert("Por favor seleccione un tema"); return; }
	if (form.anno.value == "")
		{ alert("Por favor seleccione un año"); return; }
		
	url = "grafico/grafico.php?&tema=" + form.tema.value + "&anno=" + form.anno.value;
	popup=window.open(url,"_blank","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
}


