
//************VALIDAR FORMULARIOS *************************
function validarEmail(valor){

	return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	
}


function validarSuscripcion(idioma){
	var texto;
	texto="";
	var cadena;
	cadena="";
	
	if (document.formularioNoticias.nombre.value=='') 
	{
		if (idioma=="es"){
			texto=texto+'- Debe introducir su nombre.\n';
		}
		if (idioma=="val"){
			texto=texto+'- Deu introduir el seu nom.\n';
		}
		if (idioma=="en"){
			texto=texto+'- Name.\n';
		}	
	}else{
		cadena="nombre=" + document.formularioNoticias.nombre.value;
	}
	
	if (document.formularioNoticias.apellidos.value==''){
		if (idioma=="es"){
			texto=texto+'- Debe introducir sus apellidos.\n';
		}
		if (idioma=="val"){
			texto=texto+'- Deu introduir els seus cognoms.\n';
		}
		if (idioma=="en"){
			texto=texto+'- Surnames.\n';
		}
	}else{
		cadena+="&apellidos=" + document.formularioNoticias.apellidos.value;
	}
	if(document.formularioNoticias.empresa.value==''){
		if (idioma=="es"){
			texto=texto+'- Debe introducir su empresa/universidad.\n';
		}
		if (idioma=="val"){
			texto=texto+'- Deu introduir la seua empresa/universitat.\n';
		}
		if (idioma=="en"){
			texto=texto+'- Enterprise/University.\n';
		}
	}else{
		cadena+="&empresa=" + document.formularioNoticias.empresa.value;
	}
	if (document.formularioNoticias.cargo.value==''){
		if (idioma=="es"){
			texto=texto+'- Debe introducir su cargo.\n';
		}
		if (idioma=="val"){
			texto=texto+'- Deu introduir el seu càrrec.\n';
		}
		if (idioma=="en"){
			texto=texto+'- Ocupation.\n';
		}
	}else{
		cadena+="&cargo=" + document.formularioNoticias.cargo.value;
	}
	if (document.formularioNoticias.email.value=='')
	{
		if (idioma=="es"){
			texto=texto+'- Debe introducir su Email.\n';
		}
		if (idioma=="val"){
			texto=texto+'- Deu introduir el seu Email.\n';
		}
		if (idioma=="en"){
			texto=texto+'- Email.\n';
		}
	}
	if(document.formularioNoticias.email.value!='')
	{
		if(!validarEmail(document.formularioNoticias.email.value))
		{
			texto+='- Formato de E-mail incorrecto.\n';				
			if (idioma=="es"){
			texto=texto+'- Formato de E-mail incorrecto.\n';
			}
			if (idioma=="val"){
				texto=texto+'- Format de E-mail incorrecte.\n';
			}
			if (idioma=="en"){
				texto=texto+'- Wrong E-mail format.\n';
			}
		}else{
			cadena+="&email=" + document.formularioNoticias.email.value
		}
	}
	
	if (texto!='')
	{
		if (idioma=="es"){
			alert("Se han encontrado los siguientes problemas:\n\n"+texto);
		}
		if (idioma=="val"){
			alert("Hi ha els següents problemes:\n\n"+texto);
		}
		if (idioma=="en"){
			alert("The following fields are must to:\n\n"+texto);
		}
	}else{
		http.open("GET", "actualizer/ap4nbs/suscripcion/suscripcion.asp?" + cadena + "&idioma=" + idioma, true);    
		http.onreadystatechange = handleHttpResponseSuscripcion;
		http.send(null);
	}
	
}

//*********************************************************

// ** conjunto de funciones que carga contenido en la parte derecha **
// ***********************************************************************


//DEL MENU IZQ AL CONTENIDO
function handleHttpResponse() {
	if (http.readyState == 4) {
		der.innerHTML = http.responseText;	
	}    
}
function handleHttpResponseTemasAnyos() {
	if (http.readyState == 4) {
		document.getElementById("temasDelAnyo").innerHTML = http.responseText;		
	}    
}

function handleHttpResponseSuscripcion() {
	if (http.readyState == 4) {
		document.formularioNoticias.reset();
		der.innerHTML = http.responseText;		
	}    
}
//--
function actualizaContenido(strDirec, id) {

	http.open("GET", "getContenido.asp?strURL=" + strDirec + "&idContenido="+ id, true);    
	http.onreadystatechange = handleHttpResponse;
	http.send(null);  
}
function actualizaContenidoBoletin(strDirec,anyo,mes) {

	http.open("GET", "getContenido.asp?strURL=" + strDirec + "&mes="+ mes + "&anyo=" + anyo, true);    
	http.onreadystatechange = handleHttpResponse;
	http.send(null);  
}

function cargaTemasAnyo(){
	http.open("GET", "getTemas2.asp?anyo=" + document.anyosNoticias.anyo.value + "&seccion=" + document.anyosNoticias.seccion.value, true);    
	http.onreadystatechange = handleHttpResponseTemasAnyos;
	http.send(null);
}
//--
function despliegaDepartamento(id) {
	if (id != "") {
		if (document.getElementById(id).style.display == "block") {
			document.getElementById(id).style.display = "none";
		} else {
			document.getElementById(id).style.display = "block";
		}
	}
}
function despliegaTema(id) {
	if (id != "") {
		if (document.getElementById(id).style.display == "block") {
			document.getElementById(id).style.display = "none";
		} else {
			document.getElementById(id).style.display = "block";
		}
	}
}

function despliegaTemaMes(id) {
	if (id != "") {
		if (document.getElementById(id).style.display == "block") {
			document.getElementById(id).style.display = "none";
		} else {
			document.getElementById(id).style.display = "block";
		}
	}
}


function despliegaBoletin(){
	if(document.getElementById("capaBoletin").style.display=='block'){
		document.getElementById("capaBoletin").style.display='none';
	}else{
		document.getElementById("capaBoletin").style.display='block';
	}
}
//--
var globalDepartamentoOrganigrama = "";
function despliegaDepartamentoOrganigrama(id) {
	document.getElementById("contenidoFotos").style.display = "none";
	if (id != "") {
		document.getElementById("portadaOrganigrama").style.display = "none";
		if (document.getElementById("contenidoDepartamento"+ id).style.display == "block") {
			document.getElementById("contenidoDepartamento"+ id).style.display = "none";
		} else {
			if (globalDepartamentoOrganigrama != "") {
				document.getElementById(globalDepartamentoOrganigrama).style.display = "none";
			}
			document.getElementById("contenidoDepartamento"+ id).style.display = "block";
			globalDepartamentoOrganigrama = "contenidoDepartamento"+ id;
		}
	}
}
//--
function detallePersonal(codigo) {
	if (codigo != "") {
		http.open("GET", "getPersonal.asp?codigo="+ codigo, true);    
		http.onreadystatechange = handleHttpResponsePersonal;
		http.send(null);  
	} else {
		document.getElementById("contenidoFotos").style.display = "none";
	}
}
//--
function handleHttpResponsePersonal() {
	if (http.readyState == 4) {
		if (http.responseText != "error") {
			document.getElementById("contenidoFotos").innerHTML = http.responseText;		
			document.getElementById("contenidoFotos").style.display = "block";
		} else {
			document.getElementById("contenidoFotos").style.display = "none";
		}
	}    
}
//--
function cargaSeccion(seccion) {
	document.location.href = 'index.asp?Page=que-hacemos&seccion='+ seccion;
}
//--
function cargaSeccionIndex(seccion) {

	if ((seccion == "formacion") || (seccion == "seminarios") || (seccion == "practicas") || (seccion == "empleo") || (seccion == "creacion") || (seccion == "innovacion") || (seccion == "proyectos") || (seccion == "gestion")) {

		// enciendo el que toca
		if (document.getElementById("tema_"+ seccion).style.display == "block") {
			document.getElementById("tema_"+ seccion).style.display = "none";
		} else {
			// los apago todos
			document.getElementById("tema_formacion").style.display = "none";
			document.getElementById("tema_seminarios").style.display = "none";
			document.getElementById("tema_practicas").style.display = "none";
			document.getElementById("tema_empleo").style.display = "none";
			document.getElementById("tema_innovacion").style.display = "none";
			document.getElementById("tema_proyectos").style.display = "none";
			document.getElementById("tema_creacion").style.display = "none";
			document.getElementById("tema_gestion").style.display = "none";

			document.getElementById("tema_"+ seccion).style.display = "block";
		}		
		
	}

}
//-
function enlazaSeccionIndex(seccion, subseccion) {
	
	document.location.href = 'index.asp?Page=que-hacemos&seccion='+ seccion +'&subseccion='+ subseccion;
}
//--
// FUNCIONES DE LA AGENDA
function mesAnterior(mes, anyo, idioma) {

	if ((mes != "") && (anyo != "")) {

		if (mes == 1) {
			mes = 12;
			anyo--;
		} else {
			mes--;
		}

		http.open("GET", "agenda.asp?mes=" + mes + "&anyo="+ anyo + "&idioma=" + idioma, true);    
		http.onreadystatechange = handleHttpResponseAgenda;
		http.send(null);  

	}

}
//--
function mesPosterior(mes, anyo, idioma) {

	if ((mes != "") && (anyo != "")) {

		if (mes == 12) {
			mes = 1;
			anyo++;
		} else {
			mes++;
		}

		http.open("GET", "agenda.asp?mes="+ mes +"&anyo="+ anyo + "&idioma=" + idioma, true);    
		http.onreadystatechange = handleHttpResponseAgenda;
		http.send(null);  

	}

}
function handleHttpResponseAgenda() {
	if (http.readyState == 4) {    	
		document.getElementById("calendario").innerHTML = http.responseText;		
	}    
}
function verEvento(dia){
	http.open("GET", "eventoAgenda.asp?dia="+ dia , true);    
	http.onreadystatechange = handleHttpResponseActualizaAgenda;
	http.send(null);
}
function handleHttpResponseActualizaAgenda() {
	if (http.readyState == 4) {    	
		document.getElementById("contenidoAgenda").innerHTML = http.responseText;		
	}    
}

	//Crear el PDF	
function handleHttpResponsePdf() {
	if (http.readyState == 4) {    	
		strResul=http.responseText;
		strResul=strResul.substring(0,3)		
		if(strResul=="pdf")
		{		
			window.open(http.responseText, "Pdf", "");
		}
		else
		{
			alert(http.responseText)
		}
	}    
}

function CreaPdf(id, tabla)
{
	var strUrl="pdf/creaPdf.asp?id="+id+"&tabla="+tabla
	http.open("GET", strUrl, false);    
	http.onreadystatechange = handleHttpResponsePdf;
	http.send(null);  
}
//--
function getHTTPObject() {
	var xmlhttp;      
  
  /*@cc_on
  @if (@_jscript_version >= 5)
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
  @else
  xmlhttp = false;
  @end @*/
  
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {  
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	}
	return xmlhttp;
}    
//--
var http = getHTTPObject(); // We create the HTTP Object
// ***********************************************************************

function CargarPdf(nombre)
{
	strAux="boletindiario\\"+nombre
	window.open(strAux, "Pdf", "");
	
}

function CargarPdfR(ruta)
{
	//strAux="boletindiario\\"+nombre
	window.open(ruta, "Pdf", "");
	
}

function bannerClick(id, linkUrl, target){
	var url = "./AjaxResponse/bannerClick.asp";
	var params = "id=" + id + "&link=" + escape(linkUrl);
	http.open("POST", url , true);
	
	http.onreadystatechange = function() {
	if (http.readyState==1) {
					  
	}else if (http.readyState==4){
			   if(http.status==200)
			   {
				  if(http.responseText !="http://" && http.responseText !=""){
					  //0Externo - 1 Interno			  
					  if(target == 0){
				  			window.open(http.responseText,'Publicidad','');
					  }else{
						  document.location.href = http.responseText;
					  }
				  }
			   }
			   else if(http.status==404){
					}else{
					}
			   }
	 }
	 
	 http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	 http.send(params);
}

