var a=String.fromCharCode(225); 
var e=String.fromCharCode(233); 
var i=String.fromCharCode(237); 
var o=String.fromCharCode(243); 
var u=String.fromCharCode(250);
var n=String.fromCharCode(241);
var N=String.fromCharCode(209);
var intro=String.fromCharCode(10);

var espaciosresumen = 0;
var espacioscontenido = 0;

function categorias(div)
{
	vista=document.getElementById(div).style.display; 	
	if (vista=='none')
		expandir(div);
	else
		colapsar(div);

}

function ContarEspacios()
{
		return true;
}

function ComprobarPulsaciones(target)
{
	/*
		if (document.getElementById('virtual').checked)
		{
			
			if (document.getElementById('edit-resumen').value.length > 300)
				{
					alert("Ha excedido el tama" + n + "o permitido para el resumen");
					document.getElementById('edit-resumen').value.length = 300;					
					retorno = false;
				}
			if (document.getElementById('edit-contenido').value.length > 1000)
				{
					alert("Ha excedido el tama" + n + "o permitido para el contenido");
					document.getElementById('edit-contenido').value.length = 1000;					
					retorno = false;
				}
		
		}
		else
		{
			if (document.getElementById('edit-resumen').length > 1000)
				{
					alert("Ha excedido el tama" + n + "o permitido para el resumen");
					document.getElementById('edit-resumen').length = 1000;					
					retorno = false;
				}
			if (document.getElementById('edit-contenido').length > 5000)
				{
					alert("Ha excedido el tama" + n + "o permitido para el contenido");
					document.getElementById('edit-contenido').length = 5000;					
					retorno = false;
				}
		}

	return retorno;*/
	return true;
}

function SelectEnlace()
{
	if (document.getElementById('edit-tipo').value == 'externo')
		document.getElementById('edit-enlace').value = 'http://';
		
}

function ComprobarCheckboxes(target)
{
	if (document.getElementById('guardarExperienciar'))
	{
	if ((document.getElementById('virtual').checked) || (document.getElementById('presencial').checked) || (document.getElementById('ambas').checked))
		{
		document.getElementById('guardarExperienciar').disabled = false;
		document.getElementById('editarExperiencia').disabled = false;	
		}
	else
		{
		document.getElementById('guardarExperienciar').disabled = true;
		document.getElementById('editarExperiencia').disabled = true;	
		}
	}
	
	if (target == 'virtual')
	if (document.getElementById('virtual').checked)
	{		
		document.getElementById('presencial').checked = false;
		document.getElementById('ambas').checked = false;
	}

	if (target == 'presencial')
	if (document.getElementById('presencial').checked)
	{		
		document.getElementById('virtual').checked = false;
		document.getElementById('ambas').checked = false;
	}

	if (target == 'ambas')
	if (document.getElementById('ambas').checked)
	{		
		document.getElementById('virtual').checked = false;
		document.getElementById('presencial').checked = false;
	}

	if ((document.getElementById('ambas').checked) || (document.getElementById('presencial').checked))
		expandir('sedes');		
	else
		colapsar('sedes');		

}

function ventanaInscripcion(){
window.open("http://www.congresointernetenelaula.es/virtual/ayudaexperiencias.html","ventana1","width=550, height=550, scrollbars=yes, menubar=no, location=no, resizable=no")
}

function ventana (){
window.open("http://www.congresointernetenelaula.es/virtual/ayudainscripcion.html","ventana1","width=550, height=550, scrollbars=yes, menubar=no, location=no, resizable=no")
} 
 

function colapsar(texto)
{ 	
vista=document.getElementById(texto).style.display; 	
	vista='none';  	
document.getElementById(texto).style.display = vista; 
} 

function expandir(texto)
{ 	
vista=document.getElementById(texto).style.display; 	
	vista='block'; 	
document.getElementById(texto).style.display = vista; 
} 

function Terminos()
{
window.open("http://www.congresointernetenelaula.es/virtual/terminos.html","ventana1","width=550, height=550, scrollbars=yes, menubar=no, location=no, resizable=no")
document.getElementById('TerminosYCondiciones').style.display = 'block';

}

function TerminosVirtual()
{
window.open("http://www.congresointernetenelaula.es/virtual/terminos-virtual.html","ventana1","width=550, height=550, scrollbars=yes, menubar=no, location=no, resizable=no")
document.getElementById('TerminosYCondiciones').style.display = 'block';

}

function RequerimientosCreditos()
{
window.open("http://www.congresointernetenelaula.es/virtual/requerimientoscreditos.html","ventana1","width=550, height=550, scrollbars=yes, menubar=no, location=no, resizable=no");

}

function EnviarExperiencia(Operacion)
{
	if (Operacion == 'ok')
	    document.getElementById('Experiencia').action ='/virtual/AprobarExperiencia.php';
	else
	    document.getElementById('Experiencia').action ='/virtual/DenegarExperiencia.php';

	document.getElementById('Experiencia').submit();
}
function ActivarVisitante()
{
	if (document.getElementById('visitante').checked)	
		document.getElementById('virtual').checked = false;

	ActivarVirtual();
}
function docente()
{
	return (document.getElementById('edit-profile-profesionSelect').value == 'Docente');
}

function ComprobarDocencia()
{
	if (docente() && ((document.getElementById('virtual').checked) || (document.getElementById('presencial').checked)))
	 {
 		document.getElementById('edit-profile-centro').disabled = false;
		document.getElementById('edit-profile-codigocentro').disabled = false;
		document.getElementById('edit-profile-localidad').disabled = false;
		document.getElementById('edit-profile-codigocentro').disabled = false;
		document.getElementById('edit-profile-nivelSelect').disabled = false;
		document.getElementById('edit-profile-cp').disabled = false;
		document.getElementById('edit-profile-area').disabled = false;
		document.getElementById('edit-profile-cargoSelect').disabled = false;

		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			expandir('InformacionDocente');

	 }
	else
	{
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			colapsar('InformacionDocente');
		
		document.getElementById('edit-profile-centro').disabled = true;
		document.getElementById('edit-profile-codigocentro').disabled = true;
		document.getElementById('edit-profile-centro').value = "";
		document.getElementById('edit-profile-codigocentro').value = "";
		document.getElementById('edit-profile-localidad').disabled = true;
		document.getElementById('edit-profile-localidad').value = "";
		document.getElementById('edit-profile-cp').disabled = true;
		document.getElementById('edit-profile-cp').value = "";
		document.getElementById('edit-profile-nivelSelect').disabled = true;
		document.getElementById('edit-profile-nivelSelect').value = "0";
		document.getElementById('edit-profile-area').disabled = true;
		document.getElementById('edit-profile-area').value = "0";
		document.getElementById('edit-profile-cargoSelect').disabled = true;
		document.getElementById('edit-profile-cargoSelect').value = "0";
		document.getElementById('edit-profile-cargo').disabled = true;
		document.getElementById('edit-profile-cargo').value = "";

	}
	 
}

function ActivarVirtual()
{
	if (document.getElementById('virtual').checked)	
		document.getElementById('visitante').checked = false;
	
	if ((document.getElementById('virtual').checked) || (document.getElementById('visitante').checked))
		{
		document.getElementById('edit-name').disabled = false;
		if (!((document.location.href != 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href != 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33')))
				{
				document.getElementById('pass').disabled = false;
				document.getElementById('confirmapass').disabled = false;			
				}
		}
	else
		{
		document.getElementById('edit-name').disabled = true;
		document.getElementById('edit-name').value = "";
		if (!((document.location.href != 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href != 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33')))
				{
				document.getElementById('pass').disabled = true;
				document.getElementById('pass').value = "";		
				document.getElementById('confirmapass').disabled = true;			
				document.getElementById('confirmapass').value = "";
				}
		}

	if ((document.getElementById('virtual').checked) || (document.getElementById('presencial').checked))	
	{
		document.getElementById('edit-profile-telefonofijo').disabled = false;
		document.getElementById('edit-profile-telefonomovil').disabled = false;
		document.getElementById('edit-profile-dni').disabled = false;

		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
					expandir('InformacionAdicional');

		if (docente())
		 {
 		document.getElementById('edit-profile-centro').disabled = false;
		document.getElementById('edit-profile-codigocentro').disabled = false;
		document.getElementById('edit-profile-localidad').disabled = false;
		document.getElementById('edit-profile-codigocentro').disabled = false;
		document.getElementById('edit-profile-nivelSelect').disabled = false;
		document.getElementById('edit-profile-cp').disabled = false;
		document.getElementById('edit-profile-area').disabled = false;
		document.getElementById('edit-profile-cargoSelect').disabled = false;
		

		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			expandir('InformacionDocente');

		 }
			
		 

	}
	else
	{
		document.getElementById('edit-profile-dni').disabled = true;
		document.getElementById('edit-profile-dni').value = "";
		document.getElementById('edit-profile-telefonofijo').disabled = false;
		document.getElementById('edit-profile-telefonomovil').disabled = false;
		document.getElementById('edit-profile-telefonofijo').value = "";
		document.getElementById('edit-profile-telefonomovil').value = "";	
		document.getElementById('edit-profile-nivel').disabled = true;
		document.getElementById('edit-profile-area').disabled = true;
		document.getElementById('edit-profile-nivel').value = "";
		document.getElementById('edit-profile-area').value = "";
		
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			{
			colapsar('InformacionAdicional');			
			colapsar('InformacionDocente');
			}
			
			document.getElementById('edit-profile-centro').disabled = true;
			document.getElementById('edit-profile-codigocentro').disabled = true;
			document.getElementById('edit-profile-centro').value = "";
			document.getElementById('edit-profile-codigocentro').value = "";
			document.getElementById('edit-profile-localidad').disabled = true;
			document.getElementById('edit-profile-localidad').value = "";
			document.getElementById('edit-profile-cp').disabled = true;
			document.getElementById('edit-profile-cp').value = "";
			document.getElementById('edit-profile-nivelSelect').disabled = true;
			document.getElementById('edit-profile-nivelSelect').value = "0";
			document.getElementById('edit-profile-cargoSelect').disabled = true;
			document.getElementById('edit-profile-cargoSelect').value = "0";
			document.getElementById('edit-profile-cargo').disabled = true;
			document.getElementById('edit-profile-cargo').value = "";


	}
}
function ActivarPresencial()
{
	ActivarVirtual();
	
	if (document.getElementById('presencial').checked)
	{
		document.getElementById('edit-profile-participa').disabled = false;	

		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			expandir('CongresoPresencial');

	}
	else
	{
		document.getElementById('edit-profile-participa').disabled = true;		
		document.getElementById('edit-profile-participa').checked = false;

		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			colapsar('CongresoPresencial');

	}

}


function ActivarOtrosNiveles()
{
	if (document.getElementById('edit-profile-nivelSelect').value == '-1')
		document.getElementById('edit-profile-nivel').disabled = false;
	else
		document.getElementById('edit-profile-nivel').disabled = true;
}

function ActivarOtrasComunidades()
{
	if (document.getElementById('edit-profile-comunidadSelect').value == '-1')
		document.getElementById('edit-profile-comunidad').disabled = false;
	else
		document.getElementById('edit-profile-comunidad').disabled = true;
}
function ActivarOtrasProfesiones()
{
	if (document.getElementById('edit-profile-profesionSelect').value == '-1')
		document.getElementById('edit-profile-profesion').disabled = false;
	else
		document.getElementById('edit-profile-profesion').disabled = true;
		
	ComprobarDocencia();
}
function ActivarOtrosCargos()
{
	if (document.getElementById('edit-profile-cargoSelect').value == '-1')
		document.getElementById('edit-profile-cargo').disabled = false;
	else
		document.getElementById('edit-profile-cargo').disabled = true;
}

function Borrar()
{
	document.getElementById('edit-name').value = "";
	document.getElementById('user-register').submit();

	
}
function Comprobar() {
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
		if ((document.getElementById('virtual').checked) || (document.getElementById('visitante').checked))	
			document.getElementById('user-register').action ='/virtual/?q=user/register';
		else
			document.getElementById('user-register').action ='/virtual/inscripcion.php';		

	submit = true;
	if ((!(document.getElementById('virtual').checked)) &&  (!(document.getElementById('presencial').checked)) && (!(document.getElementById('visitante').checked)))
	{
		mensaje = "Debe inscribirse en una de las dos modalidades (virtual, presencial).";
		submit = false;
	}
	
	var comprobar = true;
	if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
		comprobar = true;
	else
		comprobar = ComprobarPulsaciones();
		
	if ((submit) && (comprobar))
	{
		mensaje = "";
		
		if (!((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33')))
			if (document.getElementById('pass').value != document.getElementById('confirmapass').value)
			{
				mensaje += "Las contrase" + n + "as son diferentes" + intro;
				submit = false;
			}
		

		if (document.getElementById('edit-mail').value == '')
		{
			mensaje += "Debe introducir su e-mail" + intro;
			submit = false;
		}
		else
			if (!(mail(document.getElementById('edit-mail').value)))
			{
				mensaje += "Debe introducir un e-mail v" + a + "lido" + intro;
				submit = false;
			}

			
		if (document.getElementById('edit-profile-nombre').value == '')
		{
			mensaje += "Debe introducir su nombre" + intro;
			submit = false;
		}	

		if (document.getElementById('edit-profile-apellidos').value == '')
		{
			mensaje += "Debe introducir sus apellidos" + intro;
			submit = false;
		}	

		if (document.getElementById('edit-profile-pais').value == '')
		{
			mensaje += "Debe introducir su pa" + i + "s" + intro;
			submit = false;
		}	
		
		if (document.getElementById('edit-profile-comunidadSelect').value == '0')
		{
				mensaje += "Debe introducir su Comunidad Aut" + o + "noma" + intro;
				submit = false;
		}	

		if ((document.getElementById('edit-profile-comunidadSelect').value == '-1') && (document.getElementById('edit-profile-comunidad').value == ''))
		{
				mensaje += "Debe introducir su Comunidad Aut" + o + "noma" + intro;
				submit = false;
		}	
		
		
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			if (!(document.getElementById('aceptacion').checked))
			{
				mensaje += "Debe aceptar los t" + e + "rminos y condiciones"+ intro;
				submit = false;
				
			}


			if (document.getElementById('edit-profile-profesionSelect').value == '0')
			{
				mensaje += "Debe introducir su profesi" + o + "n" + intro;
				submit = false;
			}	

			if ((document.getElementById('edit-profile-profesionSelect').value == '-1') && (document.getElementById('edit-profile-profesion').value == ''))
			{
				mensaje += "Debe introducir su profesi" + o + "n" + intro;
				submit = false;
			}	

		
		if ((document.getElementById('virtual').checked) || (document.getElementById('presencial').checked))	
		{

		var	espana = 'espa' + n + 'a';
		var ESPANA = 'ESPA' + N + 'A';
		var Espana = 'Espa' + n + 'a';
		
			if ((document.getElementById('edit-profile-pais').value == Espana) || (document.getElementById('edit-profile-pais').value == ESPANA) || (document.getElementById('edit-profile-pais').value == espana))
				if ((document.getElementById('edit-profile-dni').value == '') && (!(document.getElementById('edit-profile-dni').disabled)))
				{
					mensaje += "Debe introducir su dni" + intro;
					submit = false;
				}	

		if (docente())					
			{
			if (document.getElementById('edit-profile-centro').value == '0')
			{
				mensaje += "Debe introducir el centro en el que imparte docencia" + intro;
				submit = false;
			}	
	
			if (document.getElementById('edit-profile-cargoSelect').value == '0')
			{
				mensaje += "Debe introducir su puesto o funci" + o + "n" + intro;
				submit = false;
			}	

			if ((document.getElementById('edit-profile-cargoSelect').value == '-1') && (document.getElementById('edit-profile-cargo').value == ''))
			{
				mensaje += "Debe introducir su puesto o funci" + o + "n" + intro;
				submit = false;
			}	

			if (document.getElementById('edit-profile-localidad').value == '0')
			{
				mensaje += "Debe introducir su localidad" + intro;
				submit = false;
			}	
			
			
			if (document.getElementById('edit-profile-nivelSelect').value == '0')
			{
				mensaje += "Debe introducir el nivel en el que imparte docencia" + intro;
				submit = false;
			}	

			if ((document.getElementById('edit-profile-nivelSelect').value == '-1') && (document.getElementById('edit-profile-nivel').value == ''))
			{
				mensaje += "Debe introducir el nivel en el que imparte docencia" + intro;
				submit = false;
			}	

			if (document.getElementById('edit-profile-area').value == '')
			{
				mensaje += "Debe introducir el " + a + "rea o materia en la que imparte docencia" + intro;
				submit = false;
			}	

			}

		}

		if ((document.getElementById('virtual').checked) || (document.getElementById('visitante').checked))		
		{
				if (document.getElementById('edit-name').value == '')
				{
					mensaje += "Debe introducir su nombre de usuario" + intro;
					submit = false;
				}	

		}
	
	}
	
	if (submit)	
	{
		if (document.getElementById('edit-profile-nivelSelect').value != '-1') 
		{
		document.getElementById('edit-profile-nivel').disabled = false;			
		document.getElementById('edit-profile-nivel').value = document.getElementById('edit-profile-nivelSelect').value;
		}
		if (document.getElementById('edit-profile-comunidadSelect').value != '-1') 
		{
		document.getElementById('edit-profile-comunidad').disabled = false;			
		document.getElementById('edit-profile-comunidad').value = document.getElementById('edit-profile-comunidadSelect').value;
		}
		if (document.getElementById('edit-profile-cargoSelect').value != '-1') 
		{
		document.getElementById('edit-profile-cargo').disabled = false;			
		document.getElementById('edit-profile-cargo').value = document.getElementById('edit-profile-cargoSelect').value;
		}

		if (document.getElementById('edit-profile-profesionSelect').value != '-1') 
		{
		document.getElementById('edit-profile-profesion').disabled = false;			
		document.getElementById('edit-profile-profesion').value = document.getElementById('edit-profile-profesionSelect').value;
		}
		
	}
	
	limpiarphp();
	
	if (submit)	
		//Inscripcion
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/33') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/33'))
			MostrarConsulta('/virtual/consulta.php?name=' + document.getElementById('edit-name').value + '&mail=' + document.getElementById('edit-mail').value);			
		//Edicion	
		else
			document.getElementById('user-register').submit();
	else
		alert(mensaje);
}

function objetoAjax(){
	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 MostrarConsulta(datos){

	ajax=objetoAjax();
	ajax.open("GET", datos);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) 
		{
			if (ajax.responseText == '0')
				{
				alert("Alta realizada con " + e + "xito. Se le enviar" + a + " un e-mail con sus datos para conectarse. Muchas gracias");
				document.getElementById('user-register').submit();
				}
			else if (ajax.responseText == '1')
				alert("Ya se ha registrado ese e-mail");
			else if (ajax.responseText == '2')
				alert("Nombre de usuario existente.");			
			else
				alert("Problema de conexion con base de datos");
		}
	}
	
	ajax.send(null)
}
/*TODO: Hacerla ...
function MeterCookie
{
}
*/
function mail(texto)
{
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(texto))
	return (true)	
} 

function limpiarphp()
{
		if (document.getElementById('edit-mail'))
			document.getElementById('edit-mail').value = limpiarphpcadena(document.getElementById('edit-mail').value);
		
		if (document.getElementById('edit-profile-nombre'))
			document.getElementById('edit-profile-nombre').value = limpiarphpcadena(document.getElementById('edit-profile-nombre').value);

		if (document.getElementById('edit-profile-apellidos'))
			document.getElementById('edit-profile-apellidos').value = limpiarphpcadena(document.getElementById('edit-profile-apellidos').value);

		if (document.getElementById('edit-profile-pais'))
			document.getElementById('edit-profile-pais').value = limpiarphpcadena(document.getElementById('edit-profile-pais').value);

		if (document.getElementById('edit-profile-dni'))
			document.getElementById('edit-profile-dni').value = limpiarphpcadena(document.getElementById('edit-profile-dni').value);

		if (document.getElementById('edit-profile-profesion'))
			document.getElementById('edit-profile-profesion').value = limpiarphpcadena(document.getElementById('edit-profile-profesion').value);

		if (document.getElementById('edit-profile-telefonofijo'))
			document.getElementById('edit-profile-telefonofijo').value = limpiarphpcadena(document.getElementById('edit-profile-telefonofijo').value);

		if (document.getElementById('edit-profile-telefonomovil'))
			document.getElementById('edit-profile-telefonomovil').value = limpiarphpcadena(document.getElementById('edit-profile-telefonomovil').value);
		
		if (document.getElementById('edit-profile-centro'))
			document.getElementById('edit-profile-centro').value = limpiarphpcadena(document.getElementById('edit-profile-centro').value);

		if (document.getElementById('edit-profile-codigocentro'))
			document.getElementById('edit-profile-codigocentro').value = limpiarphpcadena(document.getElementById('edit-profile-codigocentro').value);

		if (document.getElementById('edit-profile-comunidad'))
			document.getElementById('edit-profile-comunidad').value = limpiarphpcadena(document.getElementById('edit-profile-comunidad').value);

		if (document.getElementById('edit-profile-cargo'))
			document.getElementById('edit-profile-cargo').value = limpiarphpcadena(document.getElementById('edit-profile-cargo').value);

		if (document.getElementById('edit-profile-localidad'))
			document.getElementById('edit-profile-localidad').value = limpiarphpcadena(document.getElementById('edit-profile-localidad').value);

		if (document.getElementById('edit-profile-cp'))
			document.getElementById('edit-profile-cp').value = limpiarphpcadena(document.getElementById('edit-profile-cp').value);
			
		if (document.getElementById('edit-profile-nivel'))
			document.getElementById('edit-profile-nivel').value = limpiarphpcadena(document.getElementById('edit-profile-nivel').value);
			
		if (document.getElementById('edit-profile-area'))
			document.getElementById('edit-profile-area').value = limpiarphpcadena(document.getElementById('edit-profile-area').value);

		if (document.getElementById('edit-name'))
			document.getElementById('edit-name').value = limpiarphpcadena(document.getElementById('edit-name').value);


}
function ComprobarCreditos() {
	
		if ((document.location.href == 'http://www.congresointernetenelaula.es/virtual/?q=node/767&congreso=presencial&acceso=1') || (document.location.href == 'http://www.congresointernetenelaula.es/virtual/index.php?q=node/767&congreso=presencial&acceso=1'))
			document.getElementById('creditos_pre').action ='/virtual/insertcred_pre.php';		
  submit = true;
  
    var extrDoc = (document.getElementById('nacionalidad').value=='otra' && document.getElementById("adscrito").checked == true) ? 1 : 0;
    var docente = (document.getElementById("nouniversitario").checked == true && (document.getElementById('nacionalidad').value=='es' || extrDoc==1)) ? 1 : 0;
	
	if (submit)
	{
		mensaje = "";
		
		if((document.getElementById("docente").checked == false) && (document.getElementById("nodocente").checked == false)) {
	        alert("Por favor, complete el campo Docente.");
			submit = false;
			return false;
	    }
		
		if(document.getElementById("universitario").checked == false && document.getElementById("nouniversitario").checked == false && document.getElementById("docente").checked == true) {
	        mensaje += "Debe seleccionar su tipo de docencia: universitaria o no universitaria." + intro;
			submit = false;
	    }
		
		if(document.getElementById('nacionalidad').value=='otra' && document.getElementById("noadscrito").checked == false && document.getElementById("adscrito").checked == false && document.getElementById("docente").checked == true) {
			alert("Por favor, seleccione si está adscrito o no al sistema educativo español.");
			submit = false;
			return false;
		}
		
		if (document.getElementById('sexo').value == '') {
			mensaje += "Debe de elegir su tratamiento" + intro;
			submit = false;
		}	
		
		if (document.getElementById('nombre').value == '') {
			mensaje += "Debe introducir su nombre" + intro;
			submit = false;
		}	

		if (document.getElementById('apellido1').value == '') {
			mensaje += "Debe introducir al menos su primer apellido" + intro;
			submit = false;
		}	
		
		var dni = document.getElementById('nif').value;
		var letras = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E', 'T'];
		if(!/^\d{8}[A-Z]$/.test(dni) && document.getElementById('nacionalidad').value=='es') {
			mensaje += "El DNI introducido no es correcto (8 dígitos + 1 letra mayúscula)" + intro;
			submit = false;
		} else if (document.getElementById('nacionalidad').value=='otra' && dni == '') {
			mensaje += "El pasaporte / nie es obligatorio." + intro;
			submit = false;
		}
		/*else if(document.getElementById('nacionalidad').value=='otra' && !/^[X]\d{7}[A-Z]$/.test(dni)) {
			mensaje += "El pasaporte / nie es obligatorio (X + 7 dígitos + una letra)." + intro;
			submit = false;
		} */
   
		if (document.getElementById('email').value == '' || !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value))) {
			mensaje += "Debe introducir un email válido" + intro;
			submit = false;
		}
		if (document.getElementById('email2').value == '') {
			mensaje += "Debe confirmar su email" + intro;
			submit = false;
		}
		if (document.getElementById('email').value != document.getElementById('email2').value) {
			mensaje += "Los emails introducidos no coinciden" + intro;
			submit = false;
		}
		
		if ((document.getElementById('direccion').value == '' || document.getElementById('numero').value == '') && docente == 1) {
			mensaje += "Debe introducir su dirección personal completa (número incluido)" + intro;
			submit = false;
		}
		
		if (!/^[0-9]{5}$/.test(document.getElementById('cp').value) && docente == 1) {
			mensaje += "No ha introducido un código postal válido" + intro;
			submit = false;
		}
		
		if (document.getElementById('localidad').value == '') {
			mensaje += "Debe introducir su localidad" + intro;
			submit = false;
		}
		
		if (document.getElementById('pais').value == 0) {
			mensaje += "Debe seleccionar su pais" + intro;
			submit = false;
		}
		
		if (document.getElementById('provincia').value == '' && document.getElementById('pais').value=='España') {
			mensaje += "Debe seleccionar su provincia" + intro;
			submit = false;
		}
		
		if (!/^[0-9]{9,13}$/.test(document.getElementById('telefono').value) && docente == 1) {
			mensaje += "Debe introducir su teléfono" + intro;
			submit = false;
		}
	
		if (document.getElementById('movil').value != '' && !/^[0-9]{9}$/.test(document.getElementById('movil').value) && docente == 1) {
			mensaje += "El teléfono móvil introducido es inválido (9 dígitos)" + intro;
			submit = false;
		}
		
		if(docente == 1) {
		  var nrp = document.getElementById('nrp').value;
		  if(document.getElementById("docente").checked == true && document.getElementById('nrp').value=='') {
			mensaje += "El campo NRP no puede estar vacio" + intro;
			submit = false;
		  }
		  
		  if (document.getElementById('centro').value != '' && !/^[0-9]{8}$/.test(document.getElementById('centro').value)) {
			mensaje += "El código de centro introducido es incorrecto (8 dígitos)." + intro;
			submit = false;
		  }
		  
		  if (document.getElementById('ctronombre').value == '') {
			mensaje += "Debe introducir el centro" + intro;
			submit = false;
		  }	
		  
		  if (document.getElementById('ctrodireccion').value == '' || document.getElementById('ctrodireccion_num').value == '') {
			mensaje += "Debe introducir la dirección del centro" + intro;
			submit = false;
		  }
		  
		  if (document.getElementById('ctroprovincia').value == '0') {
			mensaje += "Debe seleccionar la provincia del centro" + intro;
			submit = false;
		  }
		  
		  if (document.getElementById('ctrolocalidad').value == '') {
			mensaje += "Debe introducir la localidad del centro" + intro;
			submit = false;
		  }
		  
		  if (!/^[0-9]{5}$/.test(document.getElementById('ctrocp').value)) {
			mensaje += "El código postal del centro es incorrecto" + intro;
			submit = false;
		  }
		  
		  if(!/^[0-9]{9,13}$/.test(document.getElementById('ctrotelefono').value)){
            mensaje += "El teléfono del centro no puede estar vacío o es inválido (9 dígitos, 13 en caso de ser internacional)" + intro;
			submit = false;
          }
		  
		  if(document.getElementById('ctrofax').value == ''){
            mensaje += "El fax del centro es obligatorio" + intro;
			submit = false;
          }
		  
		  if(document.getElementById('ctroemail').value != '' && !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('ctroemail').value)){
            mensaje += "El email del centro es inválido" + intro;
			submit = false;
          }
    
		  if (document.getElementById('especialidad').value == '') {
			mensaje += "Debe introducir su especialidad" + intro;
			submit = false;
		  }
		  
		  if (document.getElementById('cuerpo').value == '') {
			mensaje += "Debe seleccionar el cuerpo al que pertenece" + intro;
			submit = false;
		  }
		}
	
		if (document.getElementById('tipo_participacion').value == '0') {
				mensaje += "Debe introducir su tipo de participación" + intro;
				submit = false;
		}	
		if(document.getElementById("field_dia").style.display=="block"){
  		  if (document.getElementById('dia').value == '0') {
  				mensaje += "Debe introducir un dia" + intro;
  				submit = false;
  		  }	
		}
		if(document.getElementById("field_ciudad").style.display=="block"){
  		  if (document.getElementById('ciudad').value == '0') {
  				mensaje += "Debe introducir una ciudad" + intro;
  				submit = false;
  		  }	
		}
		var cargas = document.getElementById('contenedorCargas').innerHTML;
		if(cargas.indexOf('Borrar') < 0) {
			mensaje += "No has cargado ninguna participación" + intro;
  			submit = false;
		}
		
		var peticion = false;
		  try {
			peticion = new XMLHttpRequest();
		  } catch (trymicrosoft) {
			try {
			  peticion = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (othermicrosoft) {
			  try {
				peticion = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (failed) {
				peticion = false;
			  } 
			}
		  }
		  
		  peticion.open("GET", "procesarCarga.php?contar=1"); 
		  peticion.onreadystatechange = function() { 
		    if (peticion.readyState == 4) {
			  if(peticion.responseText=='1') {
			    alert("Le recordamos que solo puede optar a 1 tipo de certificado. Por favor, seleccione solo una de las participaciones.");
				submit = false;
			  }
		    } 
		  } 
		  peticion.send(null); 
		
		if (!(document.getElementById('aceptacion').checked))
			{
				mensaje += "Debe aceptar los t" + e + "rminos y condiciones"+ intro;
				submit = false;
			}
    
  /*  if(document.getElementById("field_sesion").style.display=="block")
    {
    opcionessesion = document.getElementsByName("sesion");
 
      var seleccionadosesion = false;
      for(var i=0; i<opcionessesion.length; i++) {	
        if(opcionessesion[i].checked) {
          seleccionadosesion = true;
          break;
        }
      }
       
      if(!seleccionadosesion) {
      	mensaje += "Debe introducir una sesion"+ intro;
        submit = false;
      }
    }*/
    
    }
	
	if (submit)	{
	  if(docente == 1) {
	    if(confirm('Te recordamos que asistente lleva aparejados los 2 créditos de formación correspondientes a las 20 horas de actividad congresual. Ponente, moderador o relator no tienen créditos de formación. ¿Deseas confirmar tu selección?')) {
		  document.getElementById('creditos_pre').submit();
		} else {
		  return false;
		}
	  } else {
	    document.getElementById('creditos_pre').submit();
	  }
	} else {
		alert(mensaje);
	}
}
function Capas()
{
if(document.getElementById('tipo_participacion').value=='asistente')
	{	document.getElementById("field_dia").style.display="none";
		document.getElementById("field_dia_check").style.display="block";
		document.getElementById("field_ciudad").style.display="block";
		document.getElementById("field_sesion").style.display="none";
	}
if ((document.getElementById('tipo_participacion').value == 'ponente')||(document.getElementById('tipo_participacion').value == 'moderador') || (document.getElementById('tipo_participacion').value=='relator'))
	{	document.getElementById("field_dia").style.display="block";
		document.getElementById("field_dia_check").style.display="none";
		document.getElementById("field_ciudad").style.display="block";
		document.getElementById("field_sesion").style.display="block";
	}
	
	if(document.getElementById('tipo_participacion').value == 'ponente') {
	  alert('Si has presentado más de una ponencia en el Congreso Presencial, completa el formulario seleccionando una sola de las ponencias. \nAdicionalmente envía un correo electrónico a la dirección info@congresointernetenelaula.es con el asunto: “CIeA: Más de una ponencia”, indicando tu nombre y apellidos, sede, sesión, día y nombre de todas las ponencias que has realizado');
	} else if(document.getElementById('tipo_participacion').value == 'relator') {
	  alert('Si has participado como relator en más de una ponencia en el Congreso Presencial, completa el formulario seleccionando una sola de las ponencias.\nAdicionalemente, envía un correo electrónico a la dirección info@congresointernetenelaula.es con el asunto "CIEA: Relator en más de una ponencia", indicando tu nombre y apellidos, sede, sesión, día y nombre de todas las ponencias en las que has participado como relator.');
	} else if(document.getElementById('tipo_participacion').value == 'moderador') {
	  alert('Si has participado como moderador en más de una ponencia en el Congreso Presencial, completa el formulario seleccionando una sola de las ponencias.\nAdicionalemente, envía un correo electrónico  a la dirección info@congresointernetenelaula.es con el asunto "CIEA: Moderador en más de una ponencia", indicando tu nombre y apellidos, sede, sesión, día y nombre de todas las ponencias en las que has participado como moderador.');
	}
}

function eliminarCapa(id,asistente) {
  var peticion = false;
  try {
	peticion = new XMLHttpRequest();
  } catch (trymicrosoft) {
	try {
	  peticion = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
	  try {
		peticion = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (failed) {
		peticion = false;
	  } 
	}
  }
  
  peticion.open("GET", "procesarCarga.php?eliminar="+id+"&asistente="+asistente); 
  peticion.onreadystatechange = function() { 
    if (peticion.readyState == 4) {
	  //document.getElementById(id).style.display="none";
	  document.getElementById(id).innerHTML='';
	  document.getElementById(id).parentNode.removeChild(document.getElementById(id));
    } 
  } 
  peticion.send(null); 
}

function Cargar(){
var peticion_carga = false;
try {
  peticion_carga = new XMLHttpRequest();
  } catch (trymicrosoft) {
  try {
  peticion_carga = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
  try {
  peticion_carga = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
  peticion_carga = false;
  } 
  }
}
var tipo_participacion;
var dia;
var diasmarcados = new Array();
var ciudad;
var sesion = new Array();
var sel = 0;
  tipo_participacion=document.getElementById('tipo_participacion').value;
  if(tipo_participacion == 'asistente') {
    for(var i=0; i<document.getElementsByName('dia_check[]').length; i++) {
	  if(document.getElementsByName('dia_check[]')[i].checked==true) {
	    diasmarcados.push(document.getElementsByName('dia_check[]')[i].value);
	  }
	}
	if(diasmarcados.length<1) {
		alert('Debe marcar al menos un dia de asistencia.');
		return 0;
	}
	dia = diasmarcados.join();
  } else {
	dia = document.getElementById('dia').value;
  }
  ciudad=document.getElementById('ciudad').value;
  if(tipo_participacion == '0' || dia == '0' || ciudad == '0') {
	return 0;
  }
  var cargas = document.getElementById('contenedorCargas').innerHTML;
  if(cargas.indexOf('Borrar') > 0) {
	alert("Sólo puedes seleccionar un tipo de participación, día y ponencia. Si la participación, día o ponencia seleccionadas no es correcta, por favor, utiliza la opción borrar que aparece junto a tu selección. Si es correcta, haz clic en el botón aceptar.");
  	return 0;
  }
  for(var i=0; i<document.getElementById('sesion').length; i++) {
    if(document.getElementById('sesion').options[i].selected) {
	  sesion.push(document.getElementById('sesion').options[i].value);
	  var aBorrar = document.getElementById('sesion').options[i];
	  document.getElementById('sesion').options[i].selected=false;
	  sel = 1;
	}
  }
  if(sesion.length>1) {
    alert('Sólo puedes seleccionar un tipo de participación, día y ponencia. Si la participación, día o ponencia seleccionadas no es correcta, por favor, utiliza la opción borrar que aparece junto a tu selección. Si es correcta, haz clic en el botón aceptar.');
	return 0;
  } else if(typeof(aBorrar)!='undefined') {
    aBorrar.parentNode.removeChild(aBorrar);
  }
  if(sel == 0 && tipo_participacion != 'asistente') {
    return 0;
  }
  var fragment_url = 'procesarCarga.php?tipo_participacion='+tipo_participacion+'&dia='+dia+'&ciudad='+ciudad+'&sesion='+sesion;
  peticion_carga.open("GET", fragment_url); 
    peticion_carga.onreadystatechange = function() { 
        if (peticion_carga.readyState == 4) {
	//escribimos la respuesta
	       document.getElementById('contenedorCargas').innerHTML += '<p>'+peticion_carga.responseText+'</p>';
        } 
    } 
   peticion_carga.send(null); 
}
var peticion = false;
var  testPasado = false;
try {
  peticion = new XMLHttpRequest();
  } catch (trymicrosoft) {
  try {
  peticion = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
  try {
  peticion = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (failed) {
  peticion = false;
  } 
  }
}
if (!peticion)
alert("ERROR AL INICIALIZAR!");

function ComprobarDia(element_id){
var element =  document.getElementById(element_id);
dia=document.getElementById('dia').value;
ciudad=document.getElementById('ciudad').value;
participacion=document.getElementById('tipo_participacion').value;
if(dia!=0){
 if(ciudad!=0){
 var codigo=ciudad+dia;
 var fragment_url = 'procesarEventos.php?Id='+codigo+'&participacion='+participacion;
 peticion.open("GET", fragment_url); 
    peticion.onreadystatechange = function() { 
        if (peticion.readyState == 4) {
	//escribimos la respuesta
	       element.innerHTML = peticion.responseText;
        } 
    } 
   peticion.send(null); 
    
 }
}
}
function ComprobarCiudad(element_id){
var element =  document.getElementById(element_id);
dia=document.getElementById('dia').value;
ciudad=document.getElementById('ciudad').value;
participacion=document.getElementById('tipo_participacion').value;
if(ciudad!=0){
 if(dia!=0){
 var codigo=ciudad+dia;
 var fragment_url = 'procesarEventos.php?Id='+codigo+'&participacion='+participacion;
 peticion.open("GET", fragment_url); 
    peticion.onreadystatechange = function() { 
        if (peticion.readyState == 4) {
	//escribimos la respuesta
	       element.innerHTML = peticion.responseText;
        } 
    } 
   peticion.send(null); 
 }
}
}
function mostrarMaterias(e) 
{
  alert("entre");
}

function crearXMLHttpRequest(variable) 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest(variable);
  return xmlHttp;
}

function limpiarphpcadena(cadena)
{
	while (cadena.indexOf("<?php")!= -1)
		cadena = cadena.replace("<?php","");
	while (cadena.indexOf("?>")!= -1 )
		cadena = cadena.replace("?>","");
	return cadena;
	
}

function mostrarDocente(docente) {
  if(docente==0) {
    document.getElementById('datosdelcentro').style.display='none';
	document.getElementById('nrp_field').style.display='none';
	document.getElementById('field_direccion').style.display='none';
	document.getElementById('field_cp').style.display='none';
	document.getElementById('field_tel').style.display='none';
	document.getElementById('field_mov').style.display='none';
  } else {
	document.getElementById('datosdelcentro').style.display='';
	document.getElementById('nrp_field').style.display='';
	document.getElementById('field_direccion').style.display='';
	document.getElementById('field_cp').style.display='';
	document.getElementById('field_tel').style.display='';
	document.getElementById('field_mov').style.display='';
  }
}

function extranjero(bool) {
  if(bool == 1) {
	document.getElementById('labelDNI').innerHTML = 'Pasaporte / NIE: <span class="form-required" title="Este campo es obligatorio.">*</span>';
  } else {
    document.getElementById('labelDNI').innerHTML = 'DNI: <span class="form-required" title="Este campo es obligatorio.">*</span>';
  }
}
