// JavaScript Document
var http = false; 
if (window.XMLHttpRequest) {
      http = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
            http = new ActiveXObject("Microsoft.XMLHTTP");
}

function subTree(option,divID,form,id) { 
if(http) {
	var obj = document.getElementById(divID); 
	var tmp =form;
	var datos = ["","contenido/articulos.php","contenido/resenhas.php","contenido/temas.php"];
	var url = datos[option];
	var params = "option="+id;
	form = document.getElementById(form);
		if(form.value == 0){
     http.open("POST", url, true); 
	 http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length",params.length);
     http.onreadystatechange = function()  { 
	 if (http.readyState == 1) { 
               obj.innerHTML = "<div align='center' style='padding:4px;'><img src='../nep/images/cargando_submenu.gif'><br><span style='font-size: 10px;'>Cargando</span></div>"; 
          } 
          if (http.readyState == 4) { 
               obj.innerHTML = http.responseText; 
          } 
     } 
http.send(params); 
	form.value = 1;
	}else{
	obj.innerHTML = ''; 
	form.value =0;
	}
}
}

function getContent(DivId, option, id){
	if(http){
		var array = ["","contenido/quienes_somos.php","contenido/agenda.php","contenido/seminarios.php","contenido/publicaciones.html","contenido/investigacion.php","contenido/contactanos.php","contenido/belaunde.php","contenido/enlaces.html"];
		var params = "option="+id;
		var url = array[option];
		var content = document.getElementById(DivId);
			http.open("POST",url,true);
			http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length",params.length);
			
			http.onreadystatechange = function()
			{ 	
				if(http.readyState==1)
				{
						content.innerHTML = "<div align='center' style='overflow:auto; height:375px;width: 584px;'><img src='../nep/images/cargando.gif' style='margin-top:150px;'><br><span style='font-size: 11px;'>Cargando</span></div>"
				}
				if(http.readyState==4)
				{
						content.innerHTML=http.responseText;
				}
			}
			http.send(params);
	}	
}

function email_contactanos(DivId, form){
	if(http){
		var content = document.getElementById(DivId);
		var	formato_email = /.+\@.+\..+/;	
		var errores = [document.getElementById('nombre_apellido').value, document.getElementById('e_mail').value, document.getElementById('asunto').value, document.getElementById('mensaje').value];
		var status = true;
		
		for(var i = 0; i < errores.length; i++){
			if(errores[i] == ''){
				status = false;
			}
		}
		if(!errores[1].match(formato_email)){
			status = false;
		}
		if(!status){
			alert("Tu formulario tiene errores, corrigelos por favor.");
		}
		if(status){
		var params = "nombre_apellido="+document.getElementById('nombre_apellido').value+"&email="+document.getElementById('e_mail').value+"&asunto="+document.getElementById('asunto').value+"&mensaje="+document.getElementById('mensaje').value;
		var url = "email/email_contactanos.php"
		http.open("POST",url,true);
			http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length",params.length);
			
			http.onreadystatechange = function()
			{ 	
				if(http.readyState==1)
				{
						content.innerHTML = "<div align='center' style='overflow:auto; height:375px;width: 584px;'><img src='http://www.ucsp.edu.pe/nep/images/cargando.gif' style='margin-top:150px;'><br><span style='font-size: 11px;'>Enviando Comentario</span></div>"
				}
				if(http.readyState==4)
				{
						content.innerHTML=http.responseText;
						
				}
			}
			http.send(params);
		}
	}
}

function getContent_subMenu(DivId, option, id){
		if(http){
		var array = ["","contenido/articulos_con.php","contenido/resenhas_con.php","contenido/temas_con.php","contenido/enlaces.html","contenido/temas_peruanos_con.php"];
		var params = "option="+id;
		var url = array[option];
		var content = document.getElementById(DivId);
			http.open("POST",url,true);
			http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length",params.length);
			
			http.onreadystatechange = function()
			{ 	
				if(http.readyState==1)
				{
						content.innerHTML = "<div align='center' style='overflow:auto; height:375px;width: 584px;'><img src='../nep/images/cargando.gif' style='margin-top:150px;'><br><span style='font-size: 11px;'>Cargando</span></div>"
				}
				if(http.readyState==4)
				{
						content.innerHTML=http.responseText;
				}
			}
			http.send(params);
	}	
}
function subMenu(DivID){
	if(document.getElementById(DivID).style.display == "none"){
		document.getElementById(DivID).style.display = "";
	}else{
		document.getElementById(DivID).style.display = "none";
	}
}