var COLOR_LISTA = "#5bc7d7";
var COLOR_LISTA2 = "#edf9fb";
var INVITADO = "";
function clearInput(valor, control){
	var valorActual = document.getElementById(control).value;
	if (valor == valorActual){
		document.getElementById(control).value= '';
		document.getElementById(control).style.color = "#3C3D3B";
	}
}
function clearInput2(valor, control){
	var valorActual = document.getElementById(control).value;
	if (valorActual == ''){
		document.getElementById(control).value = valor;
		document.getElementById(control).style.color = "#C1C1C1";
	}
}
function cargarTextos() {
	if (document.getElementById('iden_correo').value == '' || document.getElementById('iden_correo').value == 'correo electrónico') {
		document.getElementById('iden_correo').value = 'correo electrónico';
		document.getElementById('iden_correo').style.color = "#C1C1C1";
	}
	if (document.getElementById('invi_correo').value == '' || document.getElementById('invi_correo').value == 'correo electrónico') {
		document.getElementById('invi_correo').value = 'correo electrónico';
		document.getElementById('invi_correo').style.color = "#C1C1C1";
	}
	if (document.getElementById('invi_correo').value == '' || document.getElementById('invi_correo').value == 'correo electrónico') {
		document.getElementById('invi_correo').value = 'correo electrónico';
		document.getElementById('invi_correo').style.color = "#C1C1C1";
	}
	if (document.getElementById('mensaje_orientador')) {
		if (document.getElementById('mensaje_orientador').value == '' || document.getElementById('mensaje_orientador').value == 'Cuéntanos aquí tu experiencia y formación como Orientador Laboral') {
			document.getElementById('mensaje_orientador').value = 'Cuéntanos aquí tu experiencia y formación como Orientador Laboral';
			document.getElementById('mensaje_orientador').style.color = "#C1C1C1";
		}	
	}
}
function cargarTextosInicio() {
	cargarTextosPerfil();
}
function cargarTextosPerfil() {
	if (document.getElementById('estado_actual')) {
		document.getElementById('estado_actual').value = 'Escribe aquí tu mensaje personal';
		document.getElementById('estado_actual').style.color = "#C1C1C1";
	}	
	if (document.getElementById('estado_ciudad')) {
		document.getElementById('estado_ciudad').value = 'Ciudad';
		document.getElementById('estado_ciudad').style.color = "#C1C1C1";
	}
	if (document.getElementById('estado_cantidad_personas')) {
		document.getElementById('estado_cantidad_personas').value = 'Nº de Personas';
		document.getElementById('estado_cantidad_personas').style.color = "#C1C1C1";
	}
	if (document.getElementById('estado_responder')) {
		document.getElementById('estado_responder').value = 'Escribe aquí';
		document.getElementById('estado_responder').style.color = "#C1C1C1";
	}
	if (document.getElementById('descripcion_evento')) {
		document.getElementById('descripcion_evento').value = 'Escribe aquí la descripción del evento';
		document.getElementById('descripcion_evento').style.color = "#C1C1C1";
	}

	if (document.getElementById('alojamiento_tipo_alojamiento')) {
		if (document.getElementById('alojamiento_tipo_alojamiento').value == '' || document.getElementById('alojamiento_tipo_alojamiento').value == 'Tipo de Alojamiento') {
			document.getElementById('alojamiento_tipo_alojamiento').value = 'Tipo de Alojamiento';
			document.getElementById('alojamiento_tipo_alojamiento').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('alojamiento_ciudad')) {
		if (document.getElementById('alojamiento_ciudad').value == '' || document.getElementById('alojamiento_ciudad').value == 'Ciudad') {
			document.getElementById('alojamiento_ciudad').value = 'Ciudad';
			document.getElementById('alojamiento_ciudad').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('alojamiento_cantidad_personas')) {
		if (document.getElementById('alojamiento_cantidad_personas').value == '' || document.getElementById('alojamiento_cantidad_personas').value == 'Nº de Personas') {
			document.getElementById('alojamiento_cantidad_personas').value = 'Nº de Personas';
			document.getElementById('alojamiento_cantidad_personas').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('alojamiento_periodo')) {
		if (document.getElementById('alojamiento_periodo').value == '' || document.getElementById('alojamiento_periodo').value == 'Meses / Temporada') {
			document.getElementById('alojamiento_periodo').value = 'Meses / Temporada';
			document.getElementById('alojamiento_periodo').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('alojamiento_duracion')) {
		if (document.getElementById('alojamiento_duracion').value == '' || document.getElementById('alojamiento_duracion').value == 'Duración estancia') {
			document.getElementById('alojamiento_duracion').value = 'Duración estancia';
			document.getElementById('alojamiento_duracion').style.color = "#C1C1C1";
		}
	}

	if (document.getElementById('practica_descripcion')) {
		if (document.getElementById('practica_descripcion').value == '' || document.getElementById('practica_descripcion').value == 'Escribe aquí la descripción') {
			document.getElementById('practica_descripcion').value = 'Escribe aquí la descripción';
			document.getElementById('practica_descripcion').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('practica_requisitos')) {
		if (document.getElementById('practica_requisitos').value == '' || document.getElementById('practica_requisitos').value == 'Escribe aquí los requisitos') {
			document.getElementById('practica_requisitos').value = 'Escribe aquí los requisitos';
			document.getElementById('practica_requisitos').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('practica_informacion')) {
		if (document.getElementById('practica_informacion').value == '' || document.getElementById('practica_informacion').value == 'Escribe aquí la información adicional') {
			document.getElementById('practica_informacion').value = 'Escribe aquí la información adicional';
			document.getElementById('practica_informacion').style.color = "#C1C1C1";
		}
	}
	
	if (document.getElementById('buscar_practica')) {
		if (document.getElementById('buscar_practica').value == '' || document.getElementById('buscar_practica').value == 'Buscar') {
			document.getElementById('buscar_practica').value = 'Buscar';
			document.getElementById('buscar_practica').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('buscar_practica_empresa')) {
		if (document.getElementById('buscar_practica_empresa').value == '' || document.getElementById('buscar_practica_empresa').value == 'Nombre empresa') {
			document.getElementById('buscar_practica_empresa').value = 'Nombre empresa';
			document.getElementById('buscar_practica_empresa').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('buscar_practica_ciudad')) {
		if (document.getElementById('buscar_practica_ciudad').value == '' || document.getElementById('buscar_practica_ciudad').value == 'Ciudad') {
			document.getElementById('buscar_practica_ciudad').value = 'Ciudad';
			document.getElementById('buscar_practica_ciudad').style.color = "#C1C1C1";
		}
	}
	cargarTextoBuscar();
}
function cargarTextoAmigos() {
	if (document.getElementById('mensaje_texto')) {
		document.getElementById('mensaje_texto').value = 'Escribe aquí el mensaje a enviar (opcional)';
		document.getElementById('mensaje_texto').style.color = "#C1C1C1";
	}	
	cargarTextoBuscar();
}
function cargarTextosMensajes() {
	cargarTextoBuscar();
}
function cargarTextoAlbum() {
	cargarTextoBuscar();
}
function cargarTextoBuscar() {
	if (document.getElementById('buscar')) {
		if (document.getElementById('buscar').value == '' || document.getElementById('buscar').value == 'Buscar...') {
			document.getElementById('buscar').value = 'Buscar...';
			document.getElementById('buscar').style.color = "#C1C1C1";
		}
	}
	if (document.getElementById('mensaje_orientador')) {
		if (document.getElementById('mensaje_orientador').value == '' || document.getElementById('mensaje_orientador').value == 'Cuéntanos aquí tu experiencia y formación como Orientador Laboral') {
			document.getElementById('mensaje_orientador').value = 'Cuéntanos aquí tu experiencia y formación como Orientador Laboral';
			document.getElementById('mensaje_orientador').style.color = "#C1C1C1";
		}	
	}	
}
function cargarIdentificate() {
	COLOR_TEXTOS = "#C1C1C1";
	color = COLOR_TEXTOS.toUpperCase();
	if (document.getElementById("iden_correo").value == "" || document.getElementById("iden_correo").value == "correo electrónico") {
		alert("Debe de introducir el correo electrónico");
		document.getElementById("iden_correo").focus();
		return false;
	}
	if (document.getElementById("iden_contrasena").value == "" || document.getElementById("iden_contrasena").value == "contraseña") {
		alert("Debe de introducir la contraseña");
		document.getElementById("iden_contrasena").focus();
		return false;
	}
	document.getElementById("paso").value = "IDEN";
	//alert(document.getElementById("paso").value);
	document.formulario.submit();
}
function cargarRegistrarse() {
	if (document.getElementById("reg_nombre").value == "") {
		alert("Debe de introducir el nombre");
		document.getElementById("reg_nombre").focus();
		return false;
	}
	if (document.getElementById("tab_apellidos1").style.display != 'none') {
		if (document.getElementById("reg_apellidos").value == "") {
			alert("Debe de introducir los apellidos");
			document.getElementById("reg_apellidos").focus();
			return false;
		}
	}
	if (document.getElementById("reg_correo").value == "") {
		alert("Debe de introducir el correo electrónico");
		document.getElementById("reg_correo").focus();
		return false;
	}	
	if (document.getElementById("reg_contrasena").value == "") {
		alert("Debe de introducir la contraseña");
		document.getElementById("reg_contrasena").focus();
		return false;
	}
	if (document.getElementById("reg_contrasena").value != document.getElementById("reg_contrasena_repetida").value) {
		alert("Debe de introducir la contraseña correctamente");
		document.getElementById("reg_contrasena").focus();
		return false;
	}
	/*
	if (document.getElementById("reg_fecha_nacimiento").value == "") {
		alert("Debe de introducir la fecha de nacimiento");
		document.getElementById("reg_fecha_nacimiento").focus();
		return false;
	}
	*/
	if (document.getElementById("codSeguridad").style.display == "none" || document.getElementById("captcha").value == "") {
		document.getElementById("codSeguridad").style.display = "block";
		document.getElementById("captcha").focus();
		return false;
	}
	document.getElementById("paso").value = "REG";
	document.formulario.submit();
}
function cargarInvitados() {
	if (document.getElementById("invi_correo").value == "" || document.getElementById("invi_correo").value == "correo electrónico") {
		alert("Debe de introducir el correo electrónico");
		document.getElementById("invi_correo").focus();
		return false;
	}
	document.getElementById("paso").value = "INVI";
	document.formulario.submit();
}
function cargarBoton(control, imagen) {
	control.src=imagen;
}
function quitarBoton(control, imagen) {
	control.src=imagen;
}
function modificarDatos(accion) {
	if (accion == 'GRA') {
		if (es_invitado()) { return false; }
		if (document.getElementById("nombre").value == "") {
			alert("Debe de introducir el nombre");
			document.getElementById("nombre").focus();
			return false;
		}
		/*
		if (document.getElementById("apellidos").value == "") {
			alert("Debe de introducir los apellidos");
			document.getElementById("apellidos").focus();
			return false;
		}
		*/
		if (document.getElementById("email").value == "") {
			alert("Debe de introducir el correo electrónico");
			document.getElementById("email").focus();
			return false;
		}	
		if (document.getElementById("contrasena").value != document.getElementById("contrasena2").value) {
			alert("La contraseña está mal escrita");
			document.getElementById("contrasena").focus();
			return false;
		}
		/*
		if (document.getElementById("fechaNacimiento").value == "") {
			alert("Debe de introducir la fecha de nacimiento");
			document.getElementById("fechaNacimiento").focus();
			return false;
		}
		*/
	}
	document.getElementById("paso").value = accion;
	document.formulario.submit();
}
function HeightMiddle(altoElemento) {
	altoElemento = altoElemento.replace("px","");
	if(window.innerHeight) { altoActual = window.innerHeight; } else { altoActual = document.body.offsetHeight; }
	alto = (altoActual/2)-(altoElemento/2);
	return alto;
}
function WithMiddle(anchoElemento) {
	anchoElemento = anchoElemento.replace("px","");
	if(window.innerWidth) { anchoActual = window.innerWidth; } else { anchoActual = document.body.offsetWidth; }
	ancho = (anchoActual/2)-(anchoElemento/2);
	return ancho;
}
function modificarFotoPerfil() {
	if (es_invitado()) { return false; }
	validacionesExtras();
	if (document.getElementById("file_foto").value == "") {
		alert("Debe de seleccionar la foto a añadir");
		document.getElementById("file_foto").focus();
		return false;
	}
	document.formulario_foto.submit();
}
function modificarNuevoAlbum() {
	if (es_invitado()) { return false; }
	if (document.getElementById("nuevo_album").value == "") {
		alert("Debe de introducir el nombre del album");
		document.getElementById("nuevo_album").focus();
		return false;
	}
	document.getElementById("formulario_nuevo_album").action = 'perfil.php';
	document.getElementById("nuevo_album_x").value = "S";
	document.formulario_nuevo_album.submit();
}
function nuevoEvento() {
	if (es_invitado()) { return false; }
	if (document.getElementById("nuevo_evento").value == "") {
		alert("Debe de introducir el nombre del evento");
		document.getElementById("nuevo_evento").focus();
		return false;
	}
	if (document.getElementById("fecha_evento").value == "") {
		alert("Debe de introducir la fecha del evento");
		document.getElementById("fecha_evento").focus();
		return false;
	}
	if (document.getElementById("para_amigos_codigos")) {
		if (document.getElementById("para_amigos_codigos").value == "") {
			alert("Debe de introducir amigos para compartir el evento");
			document.getElementById("para_amigos_codigos").focus();
			return false;
		}
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		if (document.getElementById("para_amigos_codigos_yyy").value == "") {
			alert("Debe de introducir amigos para compartir el evento");
			document.getElementById("para_amigos_codigos_yyy").focus();
			return false;
		}
	}
	document.getElementById("nuevo_evento_x").value = "S";
	document.formulario_nuevo_evento.submit();
}
function modificarNuevaFoto() {
	if (document.getElementById("file_nueva_foto").value == "") {
		alert("Debe de introducir la foto");
		document.getElementById("file_nueva_foto").focus();
		return false;
	}
	document.getElementById("nueva_foto_x").value = "S";
	document.formulario_nueva_foto.submit();
}

function eliminarFotoPerfil() {
	if (es_invitado()) { return false; }
	if (!confirm('¿Estás seguro de querer eliminar la imagen del perfil de forma permanente?')) { return false; }
	validacionesExtras();
	document.getElementById("eliminarFoto").value = "S";
	document.formulario_foto.submit();
}
function cambiarEmpresa(usuario) {
	if (usuario == 'S') {
		document.getElementById("tab_apellidos1").style.display = 'block';
		document.getElementById("tab_apellidos2").style.display = 'block';
		document.getElementById("tab_fecha_nacimiento1").style.display = 'block';
		document.getElementById("tab_fecha_nacimiento2").style.display = 'block';
		document.getElementById("tab_tipo_usuario1").style.display = 'block';
		document.getElementById("tab_tipo_usuario2").style.display = 'block';
		cargarOrientacionLaboral();
		document.getElementById("tab_nombre").innerHTML = 'Nombre';
	} else {
		document.getElementById("tab_apellidos1").style.display = 'none';
		document.getElementById("tab_apellidos2").style.display = 'none';
		document.getElementById("tab_fecha_nacimiento1").style.display = 'none';
		document.getElementById("tab_fecha_nacimiento2").style.display = 'none';
		document.getElementById("tab_tipo_usuario1").style.display = 'none';
		document.getElementById("tab_tipo_usuario2").style.display = 'none';
		document.getElementById("td_mensaje_orientador").style.display = 'none';
		document.getElementById("tab_nombre").innerHTML = 'Empresa';
	}
}
function verComboAlbum(valor, nombre) {
	document.getElementById("FF_FILTRO_ALBUM").value = valor;
	document.getElementById("FF_FILTRO_NOM_ALBUM").value = nombre;
	if (valor != "") {
		document.getElementById("formulario_album").action = 'album.php';
		document.formulario_album.submit();
	} else {
		if (document.getElementById("ALBUM_XXX").style.display == "block") {
			document.getElementById("ALBUM_XXX").style.display = "none";
		} else {
			document.getElementById("ALBUM_XXX").style.display = "block";
		}
	}
}
function cambiaColor(control) {
	control.bgColor = COLOR_LISTA;
}
function cambiaColor2(control) {
	control.bgColor = COLOR_LISTA2;
}
function devuelveColor(control) {
	control.bgColor = "";
}
function cambiaColor3(control) {
	control.className = "fondo_menu2";
}
function devuelveColor3(control) {
	control.className = "fondo_menu";
}
function paginarAlbum(p_album, fichero, perfilAmigo) {
	//document.getElementById("FF_FILTRO_ALBUM").value = "";
	//document.getElementById("FF_FILTRO_NOM_ALBUM").value = "";
	document.getElementById("cambio_pagina").value = 'S';
	document.getElementById("p_album").value = p_album;
	document.getElementById("formulario_album").action = fichero;
	document.getElementById("perfilAmigo3").value = perfilAmigo;
	document.formulario_album.submit();
}
function paginarFoto(p_foto, perfilAmigo) {
	document.getElementById("p_foto").value = p_foto;
	if (document.getElementById("perfilAmigo4")) {
		document.getElementById("perfilAmigo4").value = perfilAmigo;
	}
	document.getElementById("formulario_nueva_foto").action = 'album.php';
	document.formulario_nueva_foto.submit();
}
function cargarAlbum(cod_album, nom_album, p_album, cod_amigo) {
	document.getElementById("FF_FILTRO_ALBUM").value = cod_album;
	document.getElementById("FF_FILTRO_NOM_ALBUM").value = nom_album;
	document.getElementById("p_album").value = p_album;
	document.getElementById("formulario_album").action = 'album.php';
	if (document.getElementById("perfilAmigo3")) {
		document.getElementById("perfilAmigo3").value = cod_amigo;
	}
	document.formulario_album.submit();
	
}
function cargarBotonesFoto(modo, cod_foto) {
	if (document.getElementById("botones_foto_"+cod_foto)) {
		if (modo) {
			document.getElementById("botones_foto_"+cod_foto).style.display = "block";
		} else {
			document.getElementById("botones_foto_"+cod_foto).style.display = "none";
		}
	}
}
function cargarBotonesEstado(modo, cod_estado) {
	if (document.getElementById("botones_estados_"+cod_estado)) {
		if (modo) {
			document.getElementById("botones_estados_"+cod_estado).style.display = "block";
		} else {
			document.getElementById("botones_estados_"+cod_estado).style.display = "none";
		}
	}
}
function cargarBotonesMensajesOrientador(modo, cod_mensaje) {
	if (document.getElementById("botones_mensaje_orientador_"+cod_mensaje)) {
		if (modo) {
			document.getElementById("botones_mensaje_orientador_"+cod_mensaje).style.display = "block";
		} else {
			document.getElementById("botones_mensaje_orientador_"+cod_mensaje).style.display = "none";
		}
	}
}
function cargarBotonesRespuesta(modo, cod_respuesta) {
	if (document.getElementById("botones_respuestas_"+cod_respuesta)) {
		if (modo) {
			document.getElementById("botones_respuestas_"+cod_respuesta).style.display = "block";
		} else {
			document.getElementById("botones_respuestas_"+cod_respuesta).style.display = "none";
		}
	}
}
function cargarBotonesComentariosEvento(modo, cod_evento_comentario) {
	if (document.getElementById("botones_eventos_"+cod_evento_comentario)) {
		if (modo) {
			document.getElementById("botones_eventos_"+cod_evento_comentario).style.display = "block";
		} else {
			document.getElementById("botones_eventos_"+cod_evento_comentario).style.display = "none";
		}
	}
}
function cargarBotonesPracticas(modo, cod_practica) {
	if (document.getElementById("botones_practicas_"+cod_practica)) {
		if (modo) {
			document.getElementById("botones_practicas_"+cod_practica).style.display = "block";
		} else {
			document.getElementById("botones_practicas_"+cod_practica).style.display = "none";
		}
	}
}
function moverImagen(orden_imagen, orden_imagen_cod) {
	document.getElementById("orden_imagen").value = orden_imagen;
	document.getElementById("orden_imagen_cod").value = orden_imagen_cod;
	document.formulario_nueva_foto.submit();
}
function borrarImagen(borrar_imagen, cCont) {
	if (!confirm('¿Estás seguro de querer eliminar la imagen?')) { return false; }
	if (cCont == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_foto").value > 1) {
			document.getElementById("p_foto").value = document.getElementById("p_foto").value - 1;
		}
	}
	document.getElementById("borrar_imagen").value = borrar_imagen;
	document.formulario_nueva_foto.submit();	
}
function validacionesExtras() {
	if (document.getElementById("formulario_foto").action.indexOf('album.php') > 0) {
		document.getElementById("formulario_foto").action = 'perfil.php';
	}
}
function cargarCometarios(cod_foto) {
	if (document.getElementById("tab_cometarios_"+cod_foto).style.display == "block") {
		document.getElementById("tab_cometarios_"+cod_foto).style.display = "none";
		document.getElementById("id_foto_"+cod_foto).className = "";
		document.getElementById("id_foto_"+cod_foto).bgColor="";
	} else {
		document.getElementById("tab_cometarios_"+cod_foto).style.display = "block";
		document.getElementById("comentario_"+cod_foto).focus();
		document.getElementById("id_foto_"+cod_foto).className = "borde";
		document.getElementById("id_foto_"+cod_foto).bgColor="#edf9fb";
	}
}
function escribirComentario(cod_foto, perfilAmigo) {
	if (document.getElementById("comentario_"+cod_foto).value == "") {
		alert("Escribe el comentario sobre la foto");
		document.getElementById("comentario_"+cod_foto).focus();
		return false;
	}	
	document.getElementById("comentario_grabar").value = document.getElementById("comentario_"+cod_foto).value;
	document.getElementById("comentario_cod_foto").value = cod_foto;
	if (document.getElementById("perfilAmigo4")) {
		document.getElementById("perfilAmigo4").value = perfilAmigo;
	}
	document.formulario_nueva_foto.submit();
}
function escribirComentario_frame(cod_foto) {
	if (document.getElementById("comentario")) {
		if (document.getElementById("comentario").value == "") {
			alert("Escribe el comentario sobre la foto");
			document.getElementById("comentario").focus();
			return false;
		}
	}
	document.getElementById("cod_foto").value = cod_foto;
	document.formulario_comentario_foto.submit();
}
function borrarAlbum(borrar_album) {
	if (!confirm('¿Estás seguro de querer eliminar el album?')) { return false; }
	document.getElementById("borrar_album").value = borrar_album;
	document.getElementById("formulario_nueva_foto").action = 'perfil.php';
	document.formulario_nueva_foto.submit();		
}
function paginarAmigo(p_amigo, perfilAmigo, fichero, alojamiento) {
	if (document.getElementById("perfilAmigo2")) {
		document.getElementById("perfilAmigo2").value = perfilAmigo;
	}
	if (document.getElementById("alojamiento")) {
		document.getElementById("alojamiento").value = alojamiento;	
	}
	document.getElementById("p_amigo").value = p_amigo;
	document.getElementById("formulario_amigo").action = fichero;
	document.formulario_amigo.submit();	
}
function paginarPerfil(p_estado, pagina, perfilAmigo, alojamiento) {
	if (document.getElementById("perfilAmigo")) {
		document.getElementById("perfilAmigo").value = perfilAmigo;
	}
	document.getElementById("p_estado").value = p_estado;
	if (alojamiento == '') {
		if (pagina == '1') {
			document.getElementById("formulario_perfil").action = 'perfil.php';
		} else {
			document.getElementById("formulario_perfil").action = 'inicio.php';
		}
	} else {
		if (alojamiento == 'rss') {
			document.getElementById("formulario_perfil").action = 'recursos.php';
		} else {
			document.getElementById("formulario_perfil").action = 'estancias.php';
		}
	}
	document.formulario_perfil.submit();	
}
function paginarMensajes(p_mensaje, bandeja) {
	document.getElementById("bandeja").value = bandeja;
	document.getElementById("p_mensaje").value = p_mensaje;
	document.getElementById("formulario_bandejas").action = 'mensajes.php';
	document.formulario_bandejas.submit();	
}
function paginarAmigo_principal(p_amigo_principal, buscar_amigos) {
	document.getElementById("buscar_amigos2").value = buscar_amigos;
	document.getElementById("p_amigo_principal").value = p_amigo_principal;
	document.getElementById("formulario_amigo_principal").action = 'amigos.php';
	document.formulario_amigo_principal.submit();	
}
function paginarRecursosRss(p_estado, orientacion) {
	document.getElementById("orientacion").value = orientacion;
	document.getElementById("p_estado").value = p_estado;
	if (orientacion == 'S') {
		document.getElementById("formulario_perfil").action = 'orientacion.php';
	} else {
		document.getElementById("formulario_perfil").action = 'recursos.php';
	}
	document.formulario_perfil.submit();	
}
function paginarObservatorio(p_estado) {
	document.getElementById("p_estado").value = p_estado;
	document.formulario_perfil.submit();	
}
function paginarUsuario_orientador(p_amigo_principal) {
	document.getElementById("orientacion").value = 'S';
	document.getElementById("p_amigo_principal").value = p_amigo_principal;
	document.getElementById("formulario_perfil").action = 'orientacion.php';
	document.formulario_perfil.submit();	
}
function paginarMensajes_orientador(p_orientacion) {
	document.getElementById("orientacion").value = 'S';
	document.getElementById("p_orientacion").value = p_orientacion;
	document.getElementById("formulario_perfil").action = 'orientacion.php';
	document.formulario_perfil.submit();	
}
function buscarAmigos() {
	if (!document.getElementById("am_donde").checked) {
		document.getElementById("y_am_donde").value = 'todos';
	} else {
		document.getElementById("y_am_donde").value = 'amigos';
	}
	if (document.formulario_buscar_amigos.am_sexo[0].checked) {
		document.getElementById("y_am_sexo").value = 'M';
	}
	if (document.formulario_buscar_amigos.am_sexo[1].checked) {
		document.getElementById("y_am_sexo").value = 'F';
	}
	if (document.formulario_buscar_amigos.am_sexo[2].checked) {
		document.getElementById("y_am_sexo").value = 'A';
	}
	if (document.getElementById("am_tipo_usuario").value != '') {
		document.getElementById("y_am_tipo_usuario").value = document.getElementById("am_tipo_usuario").value;
	} else {
		document.getElementById("y_am_tipo_usuario").value = '';
	}
	document.getElementById("y_am_nombre").value = document.getElementById("am_nombre").value;
	document.getElementById("y_am_pais").value = document.getElementById("am_pais").value;
	document.getElementById("y_am_ciudad").value = document.getElementById("am_ciudad").value;
	if (document.formulario_buscar_amigos.am_estudios[0].checked) {
		document.getElementById("y_am_estudios").value = 'colegio';
	}
	if (document.formulario_buscar_amigos.am_estudios[1].checked) {
		document.getElementById("y_am_estudios").value = 'universidad';
	}
	if (document.formulario_buscar_amigos.am_estudios[2].checked) {
		document.getElementById("y_am_estudios").value = 'titulacion';
	}	
	document.getElementById("y_am_texto_estudios").value = document.getElementById("am_texto_estudios").value;
	document.getElementById("y_am_empresa").value = document.getElementById("am_empresa").value;
	
	if (document.getElementById("am_situacion_laboral").value != '') {
		document.getElementById("y_am_situacion_laboral").value = document.getElementById("am_situacion_laboral").value;
	} else {
		document.getElementById("y_am_situacion_laboral").value = '';
	}
	document.getElementById("y_am_actividad_laboral").value = document.getElementById("am_actividad_laboral").value;
	if (document.getElementById("am_territorio").value != '') {
		document.getElementById("y_am_territorio").value = document.getElementById("am_territorio").value;
	} else {
		document.getElementById("y_am_territorio").value = '';
	}
	
	document.getElementById("buscar_amigos2").value = 'S';
	
	if (document.getElementById("p_amigo_principal")) { document.getElementById("p_amigo_principal").value = 1; }
	
	document.formulario_amigo_principal.submit();	
}
function cargarFotoRecortar(foto, anchura_foro, imagen_foto_aux, cod_foto_temp) {
	document.getElementById("marco").style.left = "0px";
	document.getElementById("marco").style.top = "0px";
	document.getElementById("marco").style.width = "0px";
	document.getElementById("marco").style.height = "0px";
	
	document.getElementById("foto_temp").value = imagen_foto_aux;
	document.getElementById("cod_foto_temp").value = cod_foto_temp;
	document.getElementById("anchura_foto").value = anchura_foro;
	document.getElementById("foto_para_recortar").src = foto;
	document.getElementById("res").src = foto;
}
function cargarFotoEtiquetar(foto, anchura_foro, imagen_foto_aux, cod_foto_temp, cadena_etiqueta_amigo) {
	document.getElementById("marcoX").style.left = "0px";
	document.getElementById("marcoX").style.top = "0px";
	document.getElementById("marcoX").style.width = "0px";
	document.getElementById("marcoX").style.height = "0px";
	
	document.getElementById("foto_leftX").style.height = "";
	document.getElementById("foto_topX").style.height = "";
	document.getElementById("foto_widthX").style.height = "";
	document.getElementById("foto_heightX").style.height = "";
	
	document.getElementById("foto_tempX").value = imagen_foto_aux;
	document.getElementById("cod_foto_tempX").value = cod_foto_temp;
	
	document.getElementById("foto_para_etiquetarX").src = foto;
	
	for (i=0;i<50;i++) {
		document.getElementById("marcoX_"+i).style.left = "0px";
		document.getElementById("marcoX_"+i).style.top = "0px";
		document.getElementById("marcoX_"+i).style.width = "0px";
		document.getElementById("marcoX_"+i).style.height = "0px";		
		document.getElementById("marcoX_"+i).style.display = "none";
	}
	if (cadena_etiqueta_amigo != '') {
		v_cadena_etiqueta_amigo = cadena_etiqueta_amigo.split('§');
		for (i=0;i<v_cadena_etiqueta_amigo.length;i++) {
			if (v_cadena_etiqueta_amigo[i] != '') {
				v_v_cadena_etiqueta_amigo = v_cadena_etiqueta_amigo[i].split('/')
				
				document.getElementById("marcoX_"+i).style.left = v_v_cadena_etiqueta_amigo[0]+"px";
				document.getElementById("marcoX_"+i).style.top = v_v_cadena_etiqueta_amigo[1]+"px";
				document.getElementById("marcoX_"+i).style.width = v_v_cadena_etiqueta_amigo[2]+"px";
				document.getElementById("marcoX_"+i).style.height = v_v_cadena_etiqueta_amigo[3]+"px";
				document.getElementById("marcoX_"+i).style.display = "block";
			}
		}
	}
	document.getElementById("cadena_etiqueta_amigo").value = cadena_etiqueta_amigo;
}
function cargarEtiqueta(e,i) {
	var _IE_ = navigator.userAgent.indexOf("MSIE") != -1; // Si es IE
	var _Opera_ = navigator.userAgent.indexOf("Opera") != -1; // Si es Opera	
	xiniE = 0;
	yiniE = 0;
	if (_IE_ || _Opera_) {
		xiniE = e.offsetX;
		yiniE = e.offsetY;
	} else {
		xiniE = e.layerX;
		yiniE = e.layerY;
	}
	document.getElementById("div_nombre_etiqueta").style.left = (parseInt(document.getElementById("marcoX_"+i).style.left.replace('px',''))+xiniE+20)+"px";
	document.getElementById("div_nombre_etiqueta").style.top = (parseInt(document.getElementById("marcoX_"+i).style.top.replace('px',''))+yiniE-20)+"px";
	
	cadena_etiqueta_amigo = document.getElementById("cadena_etiqueta_amigo").value;
	if (cadena_etiqueta_amigo != '') {
		v_cadena_etiqueta_amigo = cadena_etiqueta_amigo.split('§');
		v_v_cadena_etiqueta_amigo = v_cadena_etiqueta_amigo[i].split('/')
		document.getElementById("td_label_nombre_etiqueta").innerHTML = v_v_cadena_etiqueta_amigo[4];
	} else {
		document.getElementById("td_label_nombre_etiqueta").innerHTML = "";
	}
	document.getElementById("div_nombre_etiqueta").style.display = "block";	
}
function quitarEtiqueta() {
	document.getElementById("div_nombre_etiqueta").style.display = "none";
}

function obtenerCoordenadasEtiqueta() {
	if (document.getElementById("marcoX").style.width == "" || document.getElementById("marcoX").style.width == "0" || document.getElementById("marcoX").style.width == "0px") {
		alert("Haz un rectángulo sobre la foto para marcar a tu amigo.");
		return false;
	}
	if (document.getElementById("amigo_etiqueta").value == "") {
		alert("Seleccione el amigo a etiquetar.");
		return false;
	}	
	document.getElementById("foto_leftX").value = document.getElementById("marcoX").style.left;
	document.getElementById("foto_topX").value = document.getElementById("marcoX").style.top;
	document.getElementById("foto_widthX").value = document.getElementById("marcoX").style.width;
	document.getElementById("foto_heightX").value = document.getElementById("marcoX").style.height;
	document.formulario_nueva_foto.submit();
}
function recortarFotografia(foto_aux_cortar) {
	document.getElementById("foto_aux_cortar").value = document.getElementById("foto_temp").value;
	document.formulario_nueva_foto.submit();	
}
function grabarEstado() {
	if (es_invitado()) { return false; }
	if (document.getElementById("estado_tipo1").checked) {
		if (document.getElementById("estado_actual").value == "" || document.getElementById("estado_actual").value == "Escribe aquí tu mensaje personal") {
			alert("Escribe el estado actual en el que se encuentra");
			document.getElementById("estado_actual").focus();
			return false;
		}	
	}
	if (document.getElementById("estado_tipo2").checked || document.getElementById("estado_tipo3").checked) {
		if (document.getElementById("estado_ciudad").value == "" || document.getElementById("estado_ciudad").value == "Ciudad") {
			alert("Escribe la ciudad que buscas u ofreces.");
			document.getElementById("estado_ciudad").focus();
			return false;
		}	
	}
	document.getElementById("p_estado").value = 1;
	document.getElementById("paso").value = 'DOS';
	document.formulario_perfil.submit();		
}
function grabarEstado2() {
	if (es_invitado()) { return false; }
	if (document.getElementById("titulo_rss").value == "") {
		alert("Escribe el título del mensaje.");
		document.getElementById("titulo_rss").focus();
		return false;
	}
	if (document.getElementById("estado_actual2").value == "") {
		alert("Escribe el mensaje.");
		document.getElementById("estado_actual2").focus();
		return false;
	}	
	document.getElementById("p_estado").value = 1;
	document.getElementById("paso").value = 'DOS';
	document.formulario_perfil.submit();		
}
function cargarEstado(tipo) {
	if (tipo == 'P') {
		document.getElementById("estado_1").style.display = "block";
		document.getElementById("estado_2").style.display = "none";
	} else if (tipo == 'B' || tipo == 'O') {
		document.getElementById("estado_1").style.display = "none";
		document.getElementById("estado_2").style.display = "block";
	}
	if (tipo == 'B') {
		document.getElementById("solo_necesito").style.display = "block";
		document.getElementById("solo_dispongo").style.display = "none";
		document.getElementById("ofrezco_album").style.display = "none";
	}
	if (tipo == 'O') {
		document.getElementById("solo_necesito").style.display = "none";
		document.getElementById("solo_dispongo").style.display = "block";
		document.getElementById("ofrezco_album").style.display = "block";
	}
}

function ponerEtiquetaEnRespuesta(tipo_respuesta, codigo, nombre, texto, texto2, tipo_alojamiento) {
	if (document.getElementById('tipo_respuesta')) {
		document.getElementById('tipo_respuesta').value = tipo_respuesta;
	}	
	if (document.getElementById('codigo_padre_respuesta')) {
		document.getElementById('codigo_padre_respuesta').value = codigo;
	}
	
	if (tipo_respuesta == 'T') {
		if (document.getElementById('nombre_padre_respuesta')) {
			document.getElementById('nombre_padre_respuesta').innerHTML = 'Responde a ' + nombre;
		}
		if (document.getElementById('nombre_padre_respuesta2')) {
			document.getElementById('nombre_padre_respuesta2').innerHTML = nombre + ' dice:';
		}
		if (document.getElementById('texto_padre_respuesta')) {
			document.getElementById('texto_padre_respuesta').innerHTML = replaceAll_X(texto, '§', '<BR>');
		}
		if (document.getElementById('boton_respuesta')) {
			document.getElementById('boton_respuesta').innerHTML = 'Responder';
		}		
		document.getElementById('tr_respuesta_texto').style.display = "";
		document.getElementById('tr_respuesta_foto').style.display = "none";
	} 
	if (tipo_respuesta == 'F') {
		if (document.getElementById('nombre_padre_respuesta')) {
			document.getElementById('nombre_padre_respuesta').innerHTML = 'Comenta el album de ' + nombre;
		}
		if (document.getElementById('nombre_padre_respuesta2')) {
			document.getElementById('nombre_padre_respuesta2').innerHTML = 'La foto principal del album ' + texto2 + ' es:';
		}
		if (document.getElementById('foto_respuesta')) {
			document.getElementById('foto_respuesta').src = texto;
		}
		if (document.getElementById('boton_respuesta')) {
			document.getElementById('boton_respuesta').innerHTML = 'Comentar';
		}
		document.getElementById('tr_respuesta_texto').style.display = "none";
		document.getElementById('tr_respuesta_foto').style.display = "";
	}
	if (tipo_respuesta == 'G') {
		for (i=0;i<document.getElementById('total_videos').value;i++) {
			if (document.getElementById('video_'+i)) {
				document.getElementById('video_'+i).style.display = 'none';
			}
		}
		if (document.getElementById('nombre_padre_respuesta')) {
			document.getElementById('nombre_padre_respuesta').innerHTML = 'Comenta el texto de ' + nombre;
		}
		if (document.getElementById('nombre_padre_respuesta2')) {
			document.getElementById('nombre_padre_respuesta2').innerHTML = nombre + ' dice:';
		}
		if (document.getElementById('texto_padre_respuesta')) {
			document.getElementById('texto_padre_respuesta').innerHTML = replaceAll_X(texto, '§', '<BR>');
		}
		if (document.getElementById('boton_respuesta')) {
			document.getElementById('boton_respuesta').innerHTML = 'Comentar';
		}		
		document.getElementById('tr_respuesta_texto').style.display = "";
		document.getElementById('tr_respuesta_foto').style.display = "none";
	} 
	if (document.getElementById('alojamiento_y')) {
		document.getElementById('alojamiento_y').value = tipo_alojamiento;
	}
}
function replaceAll_X(cadena, valor, valor_nuevo) {
	 while(cadena.indexOf(valor) >= 0) {
	 	cadena = cadena.replace(valor, valor_nuevo); 
	} 
	return cadena; 
}
function grabarRespuesta() {
	if (document.getElementById("estado_responder").value == "" || document.getElementById("estado_responder").value == "Escribe aquí") {
		alert("Escribe la respuesta.");
		document.getElementById("estado_responder").focus();
		return false;
	}		
	document.getElementById("paso_respuesta").value = 'DOS';
	document.formulario_responder.submit();	
}
function mostrarRespuestas(codigo_estado, total) {
	if (document.getElementById("tr_respuesta_"+codigo_estado+"_0")) {
		document.getElementById("tr_respuesta_"+codigo_estado+"_0").style.display = "none";
	}
	for (i=1;i<=total;i++) {
		if (document.getElementById("tr_respuesta_"+codigo_estado+"_"+i)) {
			document.getElementById("tr_respuesta_"+codigo_estado+"_"+i).style.display = "";
		}
	}
}
function borrarEstado(tipo, cod_estado, cCont) {
	if (tipo == 'T') {
		if (!confirm('¿Estás seguro de querer eliminar el estado y todas sus respuestas?')) { return false; }
		if (cCont == 1) {
			// Si es la primera de la pagina resto una pagina
			if (document.getElementById("p_estado").value > 1) {
				document.getElementById("p_estado").value = document.getElementById("p_estado").value - 1;
			}
		}
		document.getElementById("tipo").value = tipo;
		document.getElementById("eliminarEstado").value = cod_estado;
		document.formulario_perfil.submit();
	}
	if (tipo == 'G') {
		if (!confirm('¿Estás seguro de querer eliminar el mensaje y todas sus respuestas?')) { return false; }
		if (cCont == 1) {
			// Si es la primera de la pagina resto una pagina
			if (document.getElementById("p_estado").value > 1) {
				document.getElementById("p_estado").value = document.getElementById("p_estado").value - 1;
			}
		}
		document.getElementById("tipo").value = tipo;
		document.getElementById("eliminarEstado").value = cod_estado;
		document.formulario_perfil.submit();
	}
}
function borrarMensajeOrientador(cod_mensaje, cCont) {
	if (!confirm('¿Estás seguro de querer eliminar el mensaje?')) { return false; }
	if (cCont == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_orientacion").value > 1) {
			document.getElementById("p_orientacion").value = document.getElementById("p_orientacion").value - 1;
		}
	}
	document.getElementById("eliminarMensajeOrientador").value = cod_mensaje;
	document.formulario_mensaje_orientador.submit();
}
function borrarRespuesta(tipo, cod_respuesta) {
	if (tipo == 'T') {
		if (!confirm('¿Estás seguro de querer eliminar la respuesta de forma permanente?')) { return false; }
	}
	if (tipo == 'F') {
		if (!confirm('¿Estás seguro de querer eliminar el comentario de forma permanente?')) { return false; }
	}
	document.getElementById("tipo").value = tipo;
	document.getElementById("eliminarRespuesta").value = cod_respuesta;
	document.formulario_perfil.submit();	
}
function ampliarMensajeEstado(cod_estado, estado_actual) {
	document.getElementById("etiqueta_estado_"+cod_estado).innerHTML = estado_actual;
}
function ampliarMensajeOrientador(cod_orientador, mensaje_orientador) {
	document.getElementById("etiqueta_orientador_"+cod_orientador).innerHTML = mensaje_orientador;
}
function ampliarMensajeRespuestas(cod_respuesta, texto) {
	document.getElementById("etiqueta_respuesta_"+cod_respuesta).innerHTML = texto;
}
function ampliarMensajePractica(cod_practica, practica_descripcion) {
	document.getElementById("practica_descripcion_"+cod_practica).innerHTML = practica_descripcion;
}
function ampliarMensajeInformacion(cod_practica, practica_informacion) {
	document.getElementById("practica_informacion_"+cod_practica).innerHTML = practica_informacion;
}
function editarEstado(tipo, cod_estado) {
	if (tipo == 'T') {
		if (document.getElementById("texto_estado_"+cod_estado+"_2").style.display == "none") {
			document.getElementById("texto_estado_"+cod_estado+"_1").style.display = "none";
			document.getElementById("texto_estado_"+cod_estado+"_2").style.display = "";
		} else {
			document.getElementById("texto_estado_"+cod_estado+"_1").style.display = "";
			document.getElementById("texto_estado_"+cod_estado+"_2").style.display = "none";
		}
	}
}
function editarRespuesta(cod_respuesta) {
	if (document.getElementById("texto_respuesta_"+cod_respuesta+"_2").style.display == "none") {
		document.getElementById("texto_respuesta_"+cod_respuesta+"_1").style.display = "none";
		document.getElementById("texto_respuesta_"+cod_respuesta+"_2").style.display = "";
	} else {
		document.getElementById("texto_respuesta_"+cod_respuesta+"_1").style.display = "";
		document.getElementById("texto_respuesta_"+cod_respuesta+"_2").style.display = "none";
	}
}
function editarComentarioEvento(cod_evento_comentario) {
	if (document.getElementById("texto_evento_comentario_"+cod_evento_comentario+"_2").style.display == "none") {
		document.getElementById("texto_evento_comentario_"+cod_evento_comentario+"_1").style.display = "none";
		document.getElementById("texto_evento_comentario_"+cod_evento_comentario+"_2").style.display = "";
	} else {
		document.getElementById("texto_evento_comentario_"+cod_evento_comentario+"_1").style.display = "";
		document.getElementById("texto_evento_comentario_"+cod_evento_comentario+"_2").style.display = "none";
	}
}
function grabarModificarEstado(cod_estado) {
	document.getElementById("modificarEstado").value = cod_estado;
	document.formulario_perfil.submit();
}
function grabarModificarRespuesta(tipo, cod_respuesta) {
	document.getElementById("tipo").value = tipo;
	document.getElementById("modificarRespuesta").value = cod_respuesta;
	document.formulario_perfil.submit();
}
function escribirMensajeConComentario(codigo_desde, codigo_para, nombre_desde, nombre_para, mensaje_asunto, mensaje_tipo, mensaje_automatico, mensaje_respuesta, mensaje_texto) {
	escribirMensaje(codigo_desde, codigo_para, nombre_desde, nombre_para, mensaje_asunto, mensaje_tipo, mensaje_automatico, mensaje_respuesta, mensaje_texto);
	document.getElementById("solicitud_ya_hecha").innerHTML = "Esta solicitud de amistad ya se realizó!!!";	
}
function escribirMensaje(codigo_desde, codigo_para, nombre_desde, nombre_para, mensaje_asunto, mensaje_tipo, mensaje_automatico, mensaje_respuesta, mensaje_texto) {
	document.getElementById("solicitud_ya_hecha").innerHTML = "";
	v_codigo_para = codigo_para.split(',');
	if (v_codigo_para.length == 1 && codigo_para != '') {
		document.getElementById("tr_para_uno").style.display = "";
		document.getElementById("tr_para_varios").style.display = "none";
		document.getElementById("codigo_para").value = codigo_para;	
		document.getElementById("mensaje_para").innerHTML = nombre_para;		
	} else {
		document.getElementById("tr_para_uno").style.display = "none";
		document.getElementById("tr_para_varios").style.display = "";
		if (document.getElementById("para_amigos_codigos")) {
			document.getElementById("para_amigos_codigos").value = codigo_para;	
			document.getElementById("para_amigos_nombres").value = nombre_para;
		}
		if (document.getElementById("para_amigos_codigos_yyy")) {
			document.getElementById("para_amigos_codigos_yyy").value = codigo_para;	
			document.getElementById("para_amigos_nombres_yyy").value = nombre_para;
		}
		cargarEtiquetasMensajes();
	}
	
	document.getElementById("codigo_desde").value = codigo_desde;
	document.getElementById("mensaje_desde").innerHTML = nombre_desde;

	document.getElementById("mensaje_asunto").value = mensaje_asunto;
	document.getElementById("mensaje_tipo").value = mensaje_tipo;
	document.getElementById("mensaje_automatico").value = mensaje_automatico;
	document.getElementById("mensaje_respuesta").value = mensaje_respuesta;
	if (document.getElementById("mensaje_texto")) {
		document.getElementById("mensaje_texto").value = mensaje_texto;
		if (document.getElementById('mensaje_texto').value == '') {
			document.getElementById('mensaje_texto').value = 'Escribe aquí el mensaje a enviar (opcional)';
			document.getElementById('mensaje_texto').style.color = "#C1C1C1";
		}			
	}
}
function enviarMensaje() {
	if (es_invitado()) { return false; }
	if (document.getElementById("y_am_donde")) { document.getElementById("z_am_donde").value = document.getElementById("y_am_donde").value; }
	if (document.getElementById("y_am_sexo")) { document.getElementById("z_am_sexo").value = document.getElementById("y_am_sexo").value; }
	if (document.getElementById("y_am_tipo_usuario")) { document.getElementById("z_am_tipo_usuario").value = document.getElementById("y_am_tipo_usuario").value; }
	if (document.getElementById("y_am_nombre")) { document.getElementById("z_am_nombre").value = document.getElementById("y_am_nombre").value; }
	if (document.getElementById("y_am_pais")) { document.getElementById("z_am_pais").value = document.getElementById("y_am_pais").value; }
	if (document.getElementById("y_am_ciudad")) { document.getElementById("z_am_ciudad").value = document.getElementById("y_am_ciudad").value; }
	if (document.getElementById("y_am_estudios")) { document.getElementById("z_am_estudios").value = document.getElementById("y_am_estudios").value; }
	if (document.getElementById("y_am_texto_estudios")) { document.getElementById("z_am_texto_estudios").value = document.getElementById("y_am_texto_estudios").value; }
	if (document.getElementById("y_am_empresa")) { document.getElementById("z_am_empresa").value = document.getElementById("y_am_empresa").value; }
	
	if (document.getElementById("y_am_situacion_laboral")) { document.getElementById("z_am_situacion_laboral").value = document.getElementById("y_am_situacion_laboral").value; }
	if (document.getElementById("y_am_actividad_laboral")) { document.getElementById("z_am_actividad_laboral").value = document.getElementById("y_am_actividad_laboral").value; }
	if (document.getElementById("y_am_territorio")) { document.getElementById("z_am_territorio").value = document.getElementById("y_am_territorio").value; }
	
	if (document.getElementById("p_amigo_principal")) { document.getElementById("x_p_amigo_principal").value = document.getElementById("p_amigo_principal").value; }
	
	if (document.getElementById("mensaje_asunto").value == "") {
		alert("Escribe el asunto del mensaje");
		document.getElementById("mensaje_asunto").focus();
		return false;
	}	
	if (document.getElementById("formulario_nuevo_mensaje").action.indexOf('album.php') > 0) {
		document.getElementById("formulario_nuevo_mensaje").action = 'perfil.php';
	}
	document.getElementById("solicitud_ya_hecha").innerHTML = "";
	document.formulario_nuevo_mensaje.submit();
}
function cargarBandeja(tipo) {
	document.getElementById("p_mensaje").value = 1;
	document.getElementById("bandeja").value = tipo;	
	document.formulario_bandejas.submit();
}
function verMensajePersonal(codigo) {
	if (document.getElementById("tr_mensaje_"+codigo).style.display == "none") {
		document.getElementById("tr_mensaje_"+codigo).style.display = "";
		document.getElementById("label_mensaje_"+codigo).innerHTML= "Ocultar Mensaje Personal";
	} else {
		document.getElementById("tr_mensaje_"+codigo).style.display = "none";
		document.getElementById("label_mensaje_"+codigo).innerHTML= "Ver Mensaje Personal";
	}
}
function solicitud_amistad(men_tipo, men_codigo, men_resultado) {
	document.getElementById("men_tipo").value = men_tipo;
	document.getElementById("men_codigo").value = men_codigo;
	document.getElementById("men_resultado").value = men_resultado;
	
	if (document.getElementById("total").value == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_mensaje").value > 1) {
			document.getElementById("p_mensaje").value = document.getElementById("p_mensaje").value - 1;
		}
	}
	
	document.formulario_bandejas.submit();
}
function cargarParaBorrar(control) {
	if (document.getElementById(control.id).checked) {
		document.getElementById("para_borrar").value = document.getElementById("para_borrar").value + control.id + ",";
	}
	if (!document.getElementById(control.id).checked) {
		document.getElementById("para_borrar").value = document.getElementById("para_borrar").value.replace(control.id + ",", "");
	}
}
function borrar_mensajes(bandeja) {
	verComboMensajes();
	if (document.getElementById("para_borrar").value == '') {
		alert("No tienes ningún mensaje seleccionado para borrar");
		return false;
	}
	if (bandeja == 'P') {
		if (!confirm('¿Estás seguro que quieres eliminar los mensajes seleccionados?')) { return false; }
	}
	para_borrar = document.getElementById("para_borrar").value;
	v_para_borrar = para_borrar.split(',');
	if (v_para_borrar.length-1 == document.getElementById("total").value) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_mensaje").value > 1) {
			document.getElementById("p_mensaje").value = document.getElementById("p_mensaje").value - 1;
		}
	}	
	document.getElementById("borrar").value = 'S';
	document.formulario_bandejas.submit();
}
function no_leido_mensaje(bandeja) {
	verComboMensajes();
	if (document.getElementById("para_borrar").value == '') {
		alert("No tienes ningún mensaje seleccionado");
		return false;
	}
	document.getElementById("no_leido").value = 'S';
	document.formulario_bandejas.submit();
}
function leido_mensaje(bandeja) {
	verComboMensajes();
	if (document.getElementById("para_borrar").value == '') {
		alert("No tienes ningún mensaje seleccionado");
		return false;
	}
	document.getElementById("leido").value = 'S';
	document.formulario_bandejas.submit();
}
function recuperar_mensajes() {
	verComboMensajes();
	if (document.getElementById("para_borrar").value == '') {
		alert("No tienes ningún mensaje seleccionado para recuperar");
		return false;
	}
	if (!confirm('¿Estás seguro que quieres recuperar los mensajes seleccionados?')) { return false; }
	para_recuperar = document.getElementById("para_borrar").value;
	v_para_recuperar = para_recuperar.split(',');
	if (v_para_recuperar.length-1 == document.getElementById("total").value) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_mensaje").value > 1) {
			document.getElementById("p_mensaje").value = document.getElementById("p_mensaje").value - 1;
		}
	}	
	document.getElementById("borrar").value = 'R';
	document.formulario_bandejas.submit();
}
function verComboMensajes() {
	if (document.getElementById("MENSAJES_XXX").style.display == "block") {
		document.getElementById("MENSAJES_XXX").style.display = "none";
	} else {
		document.getElementById("MENSAJES_XXX").style.display = "block";
	}
}
function verComboMensajesAmigos() {
	if (document.getElementById("MENSAJES_AMIGOS_XXX")) {
		if (document.getElementById("MENSAJES_AMIGOS_XXX").style.display == "block") {
			document.getElementById("MENSAJES_AMIGOS_XXX").style.display = "none";
		} else {
			document.getElementById("MENSAJES_AMIGOS_XXX").style.display = "block";
		}
	}
	if (document.getElementById("MENSAJES_AMIGOS_YYY")) {
		if (document.getElementById("MENSAJES_AMIGOS_YYY").style.display == "block") {
			document.getElementById("MENSAJES_AMIGOS_YYY").style.display = "none";
		} else {
			document.getElementById("MENSAJES_AMIGOS_YYY").style.display = "block";
		}
	}	
}
function verComboPaises() {
	if (document.getElementById("PAIS_ZZZ").style.display == "block") {
		document.getElementById("PAIS_ZZZ").style.display = "none";
	} else {
		document.getElementById("PAIS_ZZZ").style.display = "block";
	}
}
function verAmigosEtiqueta() {
	if (document.getElementById("AMIGOS_ZZZ").style.display == "block") {
		document.getElementById("AMIGOS_ZZZ").style.display = "none";
	} else {
		document.getElementById("AMIGOS_ZZZ").style.display = "block";
	}
}
function verComboIconos() {
	if (document.getElementById("MENSAJES_ICONOS_XXX").style.display == "block") {
		document.getElementById("MENSAJES_ICONOS_XXX").style.display = "none";
	} else {
		document.getElementById("MENSAJES_ICONOS_XXX").style.display = "block";
	}
}
function cargarCalendario(div_calendario) {
	if (document.getElementById(div_calendario).style.display == "block") {
		document.getElementById(div_calendario).style.display = "none";
	} else {
		document.getElementById(div_calendario).style.display = "block";
	}
}
function seleccionarAmigoMensaje(cod, nombre) {
	if (document.getElementById("para_amigos_codigos")) {
		document.getElementById("para_amigos_codigos").value = document.getElementById("para_amigos_codigos").value + ',' + cod;
		document.getElementById("para_amigos_nombres").value = document.getElementById("para_amigos_nombres").value + ',' + nombre;
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		document.getElementById("para_amigos_codigos_yyy").value = document.getElementById("para_amigos_codigos_yyy").value + ',' + cod;
		document.getElementById("para_amigos_nombres_yyy").value = document.getElementById("para_amigos_nombres_yyy").value + ',' + nombre;
	}
	
	nuevo_amigo = cargar_un_amigo(cod, nombre);
	if (document.getElementById("label_amigo_mensaje")) {
		document.getElementById("label_amigo_mensaje").innerHTML = document.getElementById("label_amigo_mensaje").innerHTML + nuevo_amigo;
	}
	if (document.getElementById("label_amigo_mensaje_yyy")) {
		document.getElementById("label_amigo_mensaje_yyy").innerHTML = document.getElementById("label_amigo_mensaje_yyy").innerHTML + nuevo_amigo;
	}
	if (document.getElementById("MENSAJES_AMIGOS_XXX")) {
		document.getElementById("MENSAJES_AMIGOS_XXX").style.display = "none";
	}
	if (document.getElementById("MENSAJES_AMIGOS_YYY")) {
		document.getElementById("MENSAJES_AMIGOS_YYY").style.display = "none";
	}
}
function seleccionarPais(cod, nombre) {
	document.getElementById("practica_pais").value = cod;
	document.getElementById("label_pais_zzz").innerHTML = nombre;
	document.getElementById("PAIS_ZZZ").style.display = "none";
}
function seleccionarAmigoEtiqueta(cod, nombre) {
	document.getElementById("amigo_etiqueta").value = cod;
	document.getElementById("label_amigo_etiqueta").innerHTML = nombre;
	document.getElementById("AMIGOS_ZZZ").style.display = "none";
}
function cargar_icono(icono) {
	document.getElementById("icono_evento").value = icono;
	document.getElementById("label_icono").innerHTML = '<img src="images/evento_'+icono+'.gif" border="0">';
	document.getElementById("MENSAJES_ICONOS_XXX").style.display = "none";
}
function quitarAmigoMensaje(cod_amigo, nom_amigo) {
	if (document.getElementById("para_amigos_codigos")) {
		codigos_amigos = document.getElementById("para_amigos_codigos").value + ',';
		nombres_amigos = document.getElementById("para_amigos_nombres").value + ',';
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		codigos_amigos = document.getElementById("para_amigos_codigos_yyy").value + ',';
		nombres_amigos = document.getElementById("para_amigos_nombres_yyy").value + ',';
	} 

	codigos_amigos = codigos_amigos.replace(cod_amigo+',','');
	nombres_amigos = nombres_amigos.replace(nom_amigo+',','');
	if (document.getElementById("para_amigos_codigos")) {
		if (codigos_amigos.length>1) {
			document.getElementById("para_amigos_codigos").value = codigos_amigos.substring(0,codigos_amigos.length-1);
		} else {
			document.getElementById("para_amigos_codigos").value = '';
		}
		if (nombres_amigos.length>1) {
			document.getElementById("para_amigos_nombres").value = nombres_amigos.substring(0,nombres_amigos.length-1);
		} else {
			document.getElementById("para_amigos_nombres").value = '';
		}
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		if (codigos_amigos.length>1) {
			document.getElementById("para_amigos_codigos_yyy").value = codigos_amigos.substring(0,codigos_amigos.length-1);
		} else {
			document.getElementById("para_amigos_codigos_yyy").value = '';
		}
		if (nombres_amigos.length>1) {
			document.getElementById("para_amigos_nombres_yyy").value = nombres_amigos.substring(0,nombres_amigos.length-1);
		} else {
			document.getElementById("para_amigos_nombres_yyy").value = '';
		}
	}
	cargarEtiquetasMensajes();
}
function cargarEtiquetasMensajes() {
	if (document.getElementById("para_amigos_codigos")) {
		v_amigos_codigos = document.getElementById("para_amigos_codigos").value.split(',');
		v_amigos_nombres = document.getElementById("para_amigos_nombres").value.split(',');
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		v_amigos_codigos = document.getElementById("para_amigos_codigos_yyy").value.split(',');
		v_amigos_nombres = document.getElementById("para_amigos_nombres_yyy").value.split(',');
	}
	if (document.getElementById("label_amigo_mensaje")) {
		document.getElementById("label_amigo_mensaje").innerHTML = "";
	}
	if (document.getElementById("label_amigo_mensaje_yyy")) {
		document.getElementById("label_amigo_mensaje_yyy").innerHTML = "";
	}

	for (i=0;i<v_amigos_codigos.length;i++) {
		if (v_amigos_codigos[i]!='') {
			nombre = v_amigos_nombres[i];
			cod = v_amigos_codigos[i];
			nuevo_amigo = cargar_un_amigo(cod, nombre);
			if (document.getElementById("label_amigo_mensaje")) {
				document.getElementById("label_amigo_mensaje").innerHTML = document.getElementById("label_amigo_mensaje").innerHTML + nuevo_amigo;
			}
			if (document.getElementById("label_amigo_mensaje_yyy")) {
				document.getElementById("label_amigo_mensaje_yyy").innerHTML = document.getElementById("label_amigo_mensaje_yyy").innerHTML + nuevo_amigo;
			}
		}
	}
	if (document.getElementById("MENSAJES_AMIGOS_XXX")) {
		document.getElementById("MENSAJES_AMIGOS_XXX").style.display = "none";
	}
	if (document.getElementById("MENSAJES_AMIGOS_YYY")) {
		document.getElementById("MENSAJES_AMIGOS_YYY").style.display = "none";
	}
}
function cargar_un_amigo(cod, nombre) {
	return '<span style="padding:1px 1px 1px 1px; display:inline-table"><table border="0" cellpadding="2" cellspacing="0" class="texto_amigo_mensaje"><tr><td>'+nombre+'</td><td><a href="#" onClick="quitarAmigoMensaje(\''+cod+'\',\''+nombre+'\');return false;"><img src="images/borrar_foto.png" width="9px" border="0"/></a></td></tr></table></span>';
}
function marcar_todos(marcar) {
	verComboMensajes();
	todos = document.getElementById("todos").value;
	v_todos = todos.split(',');
	for (i=0;i<v_todos.length;i++) {
		if (v_todos[i] != '') {
			if (document.getElementById(v_todos[i])) {
				document.getElementById(v_todos[i]).checked = marcar;
			}
		}
	}
	if (marcar) {
		document.getElementById("para_borrar").value = document.getElementById("todos").value;
	} else {
		document.getElementById("para_borrar").value = '';
	}
}
function cargarPerfilAmigo(cod_amigo, formulario) {
	if (document.getElementById("p_amigo")) {
		document.getElementById("p_amigo").value = 1;
	}
	if (document.getElementById("alojamiento")) {
		document.getElementById("alojamiento").value = '';
	}
	document.getElementById(formulario).action = 'perfil.php';
	if (formulario == 'formulario_perfil') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_perfil.submit();
	}
	if (formulario == 'formulario_amigo') {
		document.getElementById("perfilAmigo2").value = cod_amigo;
		document.formulario_amigo.submit();
	}
	if (formulario == 'formulario_amigo_principal') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_amigo_principal.submit();
	}
	if (formulario == 'formulario_bandejas') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_bandejas.submit();
	}
	if (formulario == 'formulario_evento') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_evento.submit();
	}
	if (formulario == 'formulario_practicas') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_practicas.submit();
	}
	if (formulario == 'formulario_practicas_detalle') {
		document.getElementById("perfilAmigo").value = cod_amigo;
		document.formulario_practicas_detalle.submit();
	}
}
function textarea_autosize(caja_texto) {
	anchura_letra = 7;
	altura_letra = 15;
	altura_minima = 60;
	altura_maxima = 200;
	anchura = document.getElementById(caja_texto).style.width.replace('px','');
	altura_aux = Math.ceil(anchura_letra * document.getElementById(caja_texto).value.length / anchura);
	altura = altura_aux * altura_letra;
	if (altura<altura_minima) { altura = altura_minima; }
	if (altura>altura_maxima) { altura = altura_maxima; }
	document.getElementById(caja_texto).style.height = altura+'px';
}
function filtrarEstados(cod_amigo) {
	if (document.getElementById("x_alojamiento_tipo_alojamiento") && document.getElementById("alojamiento_tipo_alojamiento")) { document.getElementById("x_alojamiento_tipo_alojamiento").value = document.getElementById("alojamiento_tipo_alojamiento").value; }
	if (document.getElementById("x_alojamiento_ciudad") && document.getElementById("alojamiento_ciudad")) { document.getElementById("x_alojamiento_ciudad").value = document.getElementById("alojamiento_ciudad").value; }
	if (document.getElementById("x_alojamiento_pais") && document.getElementById("alojamiento_pais")) { document.getElementById("x_alojamiento_pais").value = document.getElementById("alojamiento_pais").value; }
	if (document.getElementById("x_alojamiento_cantidad_personas") && document.getElementById("alojamiento_cantidad_personas")) { document.getElementById("x_alojamiento_cantidad_personas").value = document.getElementById("alojamiento_cantidad_personas").value; }
	if (document.getElementById("x_alojamiento_periodo") && document.getElementById("alojamiento_tipo_alojamiento")) { document.getElementById("x_alojamiento_periodo").value = document.getElementById("alojamiento_periodo").value; }
	if (document.getElementById("x_alojamiento_duracion") && document.getElementById("alojamiento_duracion")) { document.getElementById("x_alojamiento_duracion").value = document.getElementById("alojamiento_duracion").value; }
	document.getElementById("perfilAmigo").value = cod_amigo;
	document.getElementById('p_estado').value = 1;
	document.formulario_perfil.submit();
}
function cargarAlojamientos(alojamiento) {
	if (document.getElementById("x_alojamiento_tipo_alojamiento") && document.getElementById("alojamiento_tipo_alojamiento")) { document.getElementById("x_alojamiento_tipo_alojamiento").value = document.getElementById("alojamiento_tipo_alojamiento").value; }
	if (document.getElementById("x_alojamiento_ciudad") && document.getElementById("alojamiento_ciudad")) { document.getElementById("x_alojamiento_ciudad").value = document.getElementById("alojamiento_ciudad").value; }
	if (document.getElementById("x_alojamiento_pais") && document.getElementById("alojamiento_pais")) { document.getElementById("x_alojamiento_pais").value = document.getElementById("alojamiento_pais").value; }
	if (document.getElementById("x_alojamiento_cantidad_personas") && document.getElementById("alojamiento_cantidad_personas")) { document.getElementById("x_alojamiento_cantidad_personas").value = document.getElementById("alojamiento_cantidad_personas").value; }
	if (document.getElementById("x_alojamiento_periodo") && document.getElementById("alojamiento_periodo")) { document.getElementById("x_alojamiento_periodo").value = document.getElementById("alojamiento_periodo").value; }
	if (document.getElementById("x_alojamiento_duracion") && document.getElementById("alojamiento_duracion")) { document.getElementById("x_alojamiento_duracion").value = document.getElementById("alojamiento_duracion").value; }
	document.getElementById("alojamiento").value = alojamiento;
	document.getElementById('p_estado').value = 1;
	document.formulario_perfil.submit();	
}
function filtrarOrientacion() {
	if (document.getElementById('p_estado')) { document.getElementById('p_estado').value = 1; }
	if (document.getElementById('p_amigo_principal')) { document.getElementById('p_amigo_principal').value = 1; }
	document.formulario_perfil.submit();
}
function cargar_eventos_dia(fecha) {
	document.getElementById("fecha_evento_cargada").value = fecha;
	document.formulario_calendario.submit();
}
function cargar_evento(cod_evento, fecha_evento, fecha_mes_evento) {
	document.getElementById("eve_codigo").value = cod_evento;
	document.getElementById("eve_fecha").value = fecha_evento;
	document.getElementById("eve_fecha_mes").value = fecha_mes_evento;
	document.formulario_eventos.submit();
}
function modificar_evento(eve_codigo, eve_nombre, eve_fecha, eve_hora, eve_icono, eve_descripcion, para_amigos_codigos, para_amigos_nombres) {
	document.getElementById("tit_evento").innerHTML = 'Modificar Evento';
	document.getElementById("boton_evento").innerHTML = 'Modificar Evento';
	document.getElementById("cod_evento_modificar").value = eve_codigo;
	document.getElementById("nuevo_evento").value = eve_nombre;
	document.getElementById("fecha_evento").value = eve_fecha;
	document.getElementById("hora_evento").value = eve_hora;
	if (document.getElementById("para_amigos_codigos")) {
		document.getElementById("para_amigos_codigos").value = para_amigos_codigos;
		document.getElementById("para_amigos_nombres").value = para_amigos_nombres;
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		document.getElementById("para_amigos_codigos_yyy").value = para_amigos_codigos;
		document.getElementById("para_amigos_nombres_yyy").value = para_amigos_nombres;
	}
	cargarEtiquetasEvento();
	if (eve_icono != '') {
		document.getElementById("icono_evento").value = eve_icono;
		document.getElementById("label_icono").innerHTML = '<img src="images/evento_'+eve_icono+'.gif" border="0">';
	}
	if (eve_descripcion != '') {
		document.getElementById("descripcion_evento").value = replaceAll_X(eve_descripcion,"§","\n");
		document.getElementById('descripcion_evento').style.color = "";
	}
}
function cargarEtiquetasEvento() {
	if (document.getElementById("para_amigos_codigos")) {
		v_amigos_codigos = document.getElementById("para_amigos_codigos").value.split(',');
		v_amigos_nombres = document.getElementById("para_amigos_nombres").value.split(',');
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		v_amigos_codigos = document.getElementById("para_amigos_codigos_yyy").value.split(',');
		v_amigos_nombres = document.getElementById("para_amigos_nombres_yyy").value.split(',');
	}
	if (document.getElementById("label_amigo_mensaje")) {
		document.getElementById("label_amigo_mensaje").innerHTML = "";
	}
	if (document.getElementById("label_amigo_mensaje_yyy")) {
		document.getElementById("label_amigo_mensaje_yyy").innerHTML = "";
	}

	for (i=0;i<v_amigos_codigos.length;i++) {
		if (v_amigos_codigos[i]!='') {
			nombre = v_amigos_nombres[i];
			cod = v_amigos_codigos[i];
			nuevo_amigo = cargar_un_amigo(cod, nombre);
			if (document.getElementById("label_amigo_mensaje")) {
				document.getElementById("label_amigo_mensaje").innerHTML = document.getElementById("label_amigo_mensaje").innerHTML + nuevo_amigo;
			}
			if (document.getElementById("label_amigo_mensaje_yyy")) {
				document.getElementById("label_amigo_mensaje_yyy").innerHTML = document.getElementById("label_amigo_mensaje_yyy").innerHTML + nuevo_amigo;
			}
		}
	}
	if (document.getElementById("MENSAJES_AMIGOS_XXX")) {
		document.getElementById("MENSAJES_AMIGOS_XXX").style.display = "none";
	}
	if (document.getElementById("MENSAJES_AMIGOS_YYY")) {
		document.getElementById("MENSAJES_AMIGOS_YYY").style.display = "none";
	}
}
function limpiar_evento() {
	document.getElementById("tit_evento").innerHTML = 'Nuevo Evento';
	document.getElementById("boton_evento").innerHTML = 'Nuevo Evento';
	document.getElementById("cod_evento_modificar").value = '';
	document.getElementById("nuevo_evento").value = '';
	document.getElementById("fecha_evento").value = '';
	document.getElementById("hora_evento").value = '';
	if (document.getElementById("para_amigos_codigos")) {
		document.getElementById("para_amigos_codigos").value = '';
		document.getElementById("para_amigos_nombres").value = '';
	}
	if (document.getElementById("para_amigos_codigos_yyy")) {
		document.getElementById("para_amigos_codigos_yyy").value = '';
		document.getElementById("para_amigos_nombres_yyy").value = '';
	}
	document.getElementById("icono_evento").value = '';
	document.getElementById("label_icono").innerHTML = '';
	if (document.getElementById("label_amigo_mensaje")) {
		document.getElementById("label_amigo_mensaje").innerHTML = '';
	}
	if (document.getElementById("label_amigo_mensaje_yyy")) {
		document.getElementById("label_amigo_mensaje_yyy").innerHTML = '';
	}
	if (document.getElementById('descripcion_evento')) {
		document.getElementById('descripcion_evento').value = 'Escribe aquí la descripción del evento';
		document.getElementById('descripcion_evento').style.color = "#C1C1C1";
	}
}
function escribirComentario_evento(eve_codigo, eve_fecha) {
	if (document.getElementById("comentario_evento").value == "") {
		alert("Escribe el comentario del evento");
		document.getElementById("comentario_evento").focus();
		return false;
	}	
	document.getElementById("altaEventoComentario").value = eve_codigo;

	document.getElementById("evento_cod_evento").value = eve_codigo;
	document.getElementById("evento_fecha_mes").value = eve_fecha;	
	document.formulario_evento.submit();
}
function grabarModificarEventoComentario(eve_codigo, cod_comentario, eve_fecha_mes_comentario) {
	if (document.getElementById("comentario_evento_"+cod_comentario)) {
		if (document.getElementById("comentario_evento_"+cod_comentario).value == "") {
			alert("Escribe el comentario del evento");
			document.getElementById("comentario_evento_"+cod_comentario).focus();
			return false;
		}
	}
	document.getElementById("modificarEventoComentario").value = cod_comentario;

	document.getElementById("evento_cod_evento").value = eve_codigo;
	document.getElementById("evento_fecha_mes").value = eve_fecha_mes_comentario;
	document.formulario_evento.submit();
}
function borrarComentarioEvento(eve_codigo, cod_comentario, eve_fecha_mes_comentario, cCont) {
	if (!confirm('¿Estás seguro de querer eliminar el comentario?')) { return false; }
	if (cCont == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_evento").value > 1) {
			document.getElementById("p_evento").value = document.getElementById("p_evento").value - 1;
		}
	}
	document.getElementById("eliminarEventoComentario").value = cod_comentario;
	
	document.getElementById("evento_cod_evento").value = eve_codigo;
	document.getElementById("evento_fecha_mes").value = eve_fecha_mes_comentario;
	document.formulario_evento.submit();
}
function paginarComentariosEventos(p_evento, cod_evento, eve_fecha_mes) {
	document.getElementById("p_evento").value = p_evento;
	document.getElementById("evento_cod_evento").value = cod_evento;
	document.getElementById("evento_fecha_mes").value = eve_fecha_mes;	
	document.formulario_evento.submit();
}
function invitar_amigos() {
	if (es_invitado()) { return false; }
	if (document.getElementById("email_amigo").value == "") {
		alert("Escribe el mail de tu amigo");
		document.getElementById("email_amigo").focus();
		return false;
	}		
	document.formulario_invitar.submit();
}
function buscar_alojamientos() {
	document.getElementById("x_alojamiento_tipo_alojamiento").value = document.getElementById("alojamiento_tipo_alojamiento").value;
	document.getElementById("x_alojamiento_ciudad").value = document.getElementById("alojamiento_ciudad").value;
	document.getElementById("x_alojamiento_pais").value = document.getElementById("alojamiento_pais").value;
	document.getElementById("x_alojamiento_cantidad_personas").value = document.getElementById("alojamiento_cantidad_personas").value;
	document.getElementById("x_alojamiento_periodo").value = document.getElementById("alojamiento_periodo").value;
	document.getElementById("x_alojamiento_duracion").value = document.getElementById("alojamiento_duracion").value;
	document.formulario_perfil.submit();
}
function buscar_practicas() {
	document.getElementById("x_buscar_practica").value = document.getElementById("buscar_practica").value;
	document.getElementById("x_buscar_practica_empresa").value = document.getElementById("buscar_practica_empresa").value;
	document.getElementById("x_buscar_practica_ciudad").value = document.getElementById("buscar_practica_ciudad").value;
	document.getElementById("x_buscar_practica_pais").value = document.getElementById("buscar_practica_pais").value;
	document.formulario_practicas.submit();
}
function crear_modificar_oferta(codigo) {
	if (document.getElementById("codigo").value != '') {
		document.getElementById("modificar_practica").value = document.getElementById("codigo").value
	} else {
		document.getElementById("modificar_practica").value = '';
		document.getElementById("p_practicas").value = 1;
	}
	if (document.getElementById("practica_ciudad")) {
		if (document.getElementById("practica_ciudad").value == "") {
			alert("Debe de introducir la ciudad");
			document.getElementById("practica_ciudad").focus();
			return false;
		}
	}
	if (document.getElementById("practica_pais")) {
		if (document.getElementById("practica_pais").value == "") {
			alert("Debe de introducir el pais");
			document.getElementById("practica_pais").focus();
			return false;
		}
	}
	document.getElementById("paso").value = 'DOS';
	document.formulario_nueva_practica.submit();
}
function crear_modificar_mensaje_orientacion(codigo) {
	if (document.getElementById("orientador_mensaje_codigo").value != '') {
		document.getElementById("modificar_mensaje_orientador").value = document.getElementById("orientador_mensaje_codigo").value
	} else {
		document.getElementById("modificar_mensaje_orientador").value = '';
	}
	if (document.getElementById("orientador_mensaje_nombre")) {
		if (document.getElementById("orientador_mensaje_nombre").value == "") {
			alert("Debe de introducir el título del mensaje");
			document.getElementById("orientador_mensaje_nombre").focus();
			return false;
		}
	}
	if (document.getElementById("orientador_mensaje_descripcion")) {
		if (document.getElementById("orientador_mensaje_descripcion").value == "" || document.getElementById("orientador_mensaje_descripcion").value == "Escribe aquí tu mensaje") {
			alert("Debe de introducir el mensaje");
			document.getElementById("orientador_mensaje_descripcion").focus();
			return false;
		}
	}
	document.getElementById("orientador_mensaje_paso").value = 'DOS';
	document.formulario_mensaje_orientador.submit();
}
function paginarPracticas(p_practicas, perfilAmigo) {
	if (document.getElementById("perfilAmigo")) {
		document.getElementById("perfilAmigo").value = perfilAmigo;
	}
	document.getElementById("p_practicas").value = p_practicas;
	
	if (document.getElementById("x_buscar_practica")) {	document.getElementById("x_buscar_practica").value = document.getElementById("buscar_practica").value; }
	if (document.getElementById("x_buscar_practica_empresa")) {	document.getElementById("x_buscar_practica_empresa").value = document.getElementById("buscar_practica_empresa").value; }
	if (document.getElementById("x_buscar_practica_ciudad")) {	document.getElementById("x_buscar_practica_ciudad").value = document.getElementById("buscar_practica_ciudad").value; }
	if (document.getElementById("x_buscar_practica_pais")) {	document.getElementById("x_buscar_practica_pais").value = document.getElementById("buscar_practica_pais").value; }
	
	if (document.getElementById("o_cod_practica_detalle")) { document.getElementById("o_cod_practica_detalle").value = ''; }
	if (document.getElementById("o_nom_practica_detalle")) { document.getElementById("o_nom_practica_detalle").value = ''; }
	if (document.getElementById("o_usu_practica_detalle")) { document.getElementById("o_usu_practica_detalle").value = ''; }

	document.formulario_practicas.submit();	
}
function editarPractica(codigo, practica_ciudad_defecto, practica_pais_defecto, practica_pais_nombre_defecto) {
	if (codigo != '') {
		document.getElementById("codigo").value = codigo;
		document.getElementById("practica_cod_ref").value = document.getElementById("practica_cod_ref_X_"+codigo).value;
		document.getElementById("practica_ciudad").value = document.getElementById("practica_ciudad_X_"+codigo).value;
		document.getElementById("practica_pais").value = document.getElementById("practica_pais_X_"+codigo).value;
		document.getElementById("label_pais_zzz").innerHTML = document.getElementById("practica_ds_pais_X_"+codigo).value;
		document.getElementById("practica_duracion").value = document.getElementById("practica_duracion_X_"+codigo).value;
		document.getElementById("practica_puesto").value = document.getElementById("practica_puesto_X_"+codigo).value;
		document.getElementById("practica_plazas").value = document.getElementById("practica_plazas_X_"+codigo).value;
		document.getElementById("practica_fecha_desde").value = document.getElementById("practica_fecha_desde_X_"+codigo).value;
		document.getElementById("practica_fecha_hasta").value = document.getElementById("practica_fecha_hasta_X_"+codigo).value;
		document.getElementById("practica_descripcion").value = document.getElementById("practica_descripcion_X_"+codigo).value;
		document.getElementById('practica_descripcion').style.color = "";
		document.getElementById("practica_requisitos").value = document.getElementById("practica_requisitos_X_"+codigo).value;
		document.getElementById('practica_requisitos').style.color = "";
		
		document.getElementById("practica_empresa").value = document.getElementById("practica_empresa_X_"+codigo).value;
		document.getElementById("practica_contacto").value = document.getElementById("practica_contacto_X_"+codigo).value;
		document.getElementById("practica_enlace").value = document.getElementById("practica_enlace_X_"+codigo).value;
		document.getElementById("practica_informacion").value = document.getElementById("practica_informacion_X_"+codigo).value;
		document.getElementById('practica_informacion').style.color = "";
		
		document.getElementById('boton_practica').innerHTML = "Modificar";
	} else {
		document.getElementById("practica_cod_ref").value = '';
		document.getElementById("practica_ciudad").value = practica_ciudad_defecto;
		document.getElementById("practica_pais").value = practica_pais_defecto;
		document.getElementById("label_pais_zzz").innerHTML = practica_pais_nombre_defecto;
		document.getElementById("practica_duracion").value = ''
		document.getElementById("practica_puesto").value = '';
		document.getElementById("practica_plazas").value = '';
		document.getElementById("practica_fecha_desde").value = '';
		document.getElementById("practica_fecha_hasta").value = '';
		document.getElementById("practica_descripcion").value = 'Escribe aquí la descripción';
		document.getElementById('practica_descripcion').style.color = "#C1C1C1";
		document.getElementById("practica_requisitos").value = 'Escribe aquí los requisitos';
		document.getElementById('practica_requisitos').style.color = "#C1C1C1";
		
		document.getElementById("practica_empresa").value = '';
		document.getElementById("practica_contacto").value = '';
		document.getElementById("practica_enlace").value = '';
		document.getElementById("practica_informacion").value = 'Escribe aquí la información adicional';
		document.getElementById('practica_informacion').style.color = "#C1C1C1";
		
		document.getElementById('boton_practica').innerHTML = "Crear";
	}
}
function nuevoMensajeOrientador(codigo) {
	if (codigo != '') {
		document.getElementById("orientador_mensaje_codigo").value = codigo;
		document.getElementById("orientador_mensaje_nombre").value = document.getElementById("orientador_mensaje_nombre_X_"+codigo).value;
		document.getElementById("orientador_mensaje_descripcion").value = document.getElementById("orientador_mensaje_descripcion_X_"+codigo).value;
		document.getElementById('orientador_mensaje_descripcion').style.color = "";
		
		document.getElementById('boton_orientador').innerHTML = "Modificar";
	} else {
		document.getElementById("orientador_mensaje_codigo").value = '';
		document.getElementById("orientador_mensaje_nombre").value = '';
		document.getElementById("orientador_mensaje_descripcion").value = 'Escribe aquí tu mensaje';
		document.getElementById('orientador_mensaje_descripcion').style.color = "#C1C1C1";
		
		document.getElementById('boton_orientador').innerHTML = "Crear";
	}
}
function borrarPractica(cod_practica, cCont) {
	if (!confirm('¿Estás seguro de querer eliminarla de forma permanente?')) { return false; }
	if (cCont == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_practicas").value > 1) {
			document.getElementById("p_practicas").value = document.getElementById("p_practicas").value - 1;
		}
	}
	document.getElementById("borrar_practica").value = cod_practica;
	document.formulario_practicas.submit();	
}
function ver_oferta(codigo, nombre, cod_usuario) {
	document.getElementById("o_cod_practica_detalle").value = codigo;
	document.getElementById("o_nom_practica_detalle").value = nombre;
	document.getElementById("o_usu_practica_detalle").value = cod_usuario;
	document.formulario_practicas.submit();
}
function recordarContrasena() {
	if (document.getElementById("iden_correo").value == "" || document.getElementById("iden_correo").value == "correo electrónico") {
		alert("Escriba el correo electrónico y se le enviará la contraseña.");
		return false;
	}
	document.getElementById("paso").value = 'RECORDAR';
	document.formulario.submit();
}
function darse_de_baja() {
	if (!confirm('¿Estás seguro de querer darse de baja de forma permanente?')) { return false; }
	document.getElementById("paso").value = 'BAJA';
	document.formulario_baja.submit();
}
function desactivar_notificaciones() {
	if (!confirm("¿Está seguro que quiere desactivar las notificaciones al correo?")) { return false; }
	document.getElementById("paso").value = 'DESACTIVAR';
	document.formulario_desactivar.submit();
}
function darse_de_baja_cuenta(enlace) {
	if (es_invitado()) { return false; }
	if (!confirm('¿Estás seguro de querer darse de baja de forma permanente?')) { return false; }
	document.location.href = enlace;
}
function cargar_buscar(fichero) {
	if (fichero.indexOf('inicio')>0 || fichero.indexOf('perfil')>0 || fichero.indexOf('estancias')>0) {
		if (document.getElementById("buscar_x_inicio") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_inicio").value = document.getElementById("buscar").value;
			document.formulario_perfil.submit();
		}
	}
	if (fichero.indexOf('amigos')>0) {
		if (document.getElementById("buscar_x_amigos") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_amigos").value = document.getElementById("buscar").value;
			document.formulario_amigo_principal.submit();
		}
	}
	if (fichero.indexOf('mensajes')>0) {
		if (document.getElementById("buscar_x_mensajes") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_mensajes").value = document.getElementById("buscar").value;
			document.formulario_bandejas.submit();
		}
	}
	if (fichero.indexOf('ofertas')>0 || fichero.indexOf('practicas')>0 || fichero.indexOf('ong')>0) {
		if (document.getElementById("buscar_x_practicas") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_practicas").value = document.getElementById("buscar").value;
			document.formulario_practicas.submit();
		}
	}
	if (fichero.indexOf('orientacion')>0 || fichero.indexOf('recursos')>0) {
		if (document.getElementById("buscar_x_mensaje") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_mensaje").value = document.getElementById("buscar").value;
			document.formulario_perfil.submit();
		}
	}
	if (fichero.indexOf('observatorio')>0) {
		if (document.getElementById("buscar_x_inicio") && document.getElementById("buscar")) {
			document.getElementById("buscar_x_inicio").value = document.getElementById("buscar").value;
			document.formulario_perfil.submit();
		}
	}
}
function es_invitado() {
	if (INVITADO == 'S') {
		alert('Has entrado como invitado!!!');
		return true;
	}
	return false;
}
function cambiarCalendario(mes, tipo, cerrar, control) {
	mes_y = parseInt(document.getElementById("mes_x").value) + mes;
	document.location.href = "calendario.php?mes="+mes_y+"&anno="+document.getElementById("anno_x").value+"&tipo="+tipo+"&cerrar="+cerrar+"&control="+control;
}
function hacerFotoPrincipal(cod_foto_principal_aux) {
	if (!confirm('¿Estás seguro de querer poner esta foto como principal de tu perfil?\nLa foto se recortará automáticamente para que quede cuadrada')) { return false; }	
	document.getElementById("cod_foto_principal_aux").value = cod_foto_principal_aux;
	document.formulario_nueva_foto.submit();
}
function cambioFicheroX(sValor, sValor2) {
	sValor2.value = sValor.value.replace('C:\\fakepath\\','');
}
function verMensajeOculto(cod_mensaje, cod_usuario, tipo) {
	if (document.getElementById("table_mensaje_"+cod_mensaje).style.display == "none") {
		document.getElementById("table_mensaje_"+cod_mensaje).style.display = "";
		if (document.getElementById("enlace_mensaje_"+cod_mensaje).className != "enlace_naranja_peque2") {
			marcarComoLeido(cod_mensaje, cod_usuario, tipo);
			document.getElementById("enlace_mensaje_"+cod_mensaje).className = "enlace_naranja_peque2";
		}
	} else {
		document.getElementById("table_mensaje_"+cod_mensaje).style.display = "none";
	}
}
function marcarComoLeido(cod_mensaje, cod_usuario, tipo) {
	if (tipo == '') { tipo = 'R'}
	llamarasincrono('cambiar_leidos.php?cod_mensaje='+cod_mensaje+'&cod_usuario='+cod_usuario+'&tipo='+tipo,'contenedor_mensajes_'+tipo);
}
function borrarEtiqueta(cod_foto) {
	if (!confirm("¿Está seguro que quiere borrar la etiqueta de la foto?")) { return false; }
	document.getElementById("cod_foto_etiqueta_borrar").value = cod_foto;
	document.formulario_etiqueta.submit();
}
function cargarOrientacionLaboral() {
	if (document.getElementById("tipo_usuario").value == '1') {
		document.getElementById("td_mensaje_orientador").style.display = "";
	} else {
		document.getElementById("td_mensaje_orientador").style.display = "none";
	}
}
///////////////////////// AJAX //////////////////////////
function llamarasincrono(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);
}
function cargarpagina (pagina_requerida, id_contenedor) {
    if (pagina_requerida.readyState == 4 && (pagina_requerida.status == 200 || window.location.href.indexOf ("http") == - 1))
	if (document.getElementById(id_contenedor)) {
	    document.getElementById(id_contenedor).innerHTML = pagina_requerida.responseText;
	}
	if (id_contenedor != 'contenedor_mensajes') {
		llamarasincrono('calcular_total_mesajes.php','contenedor_mensajes');
	}
}
function quitarAmistad(codigo_mio_borrar, codigo_amigo_borrar, cCont) {
	if (!confirm('¿Estás seguro de querer dejar de compartir el muro?')) { return false; }

	if (cCont == 1) {
		// Si es la primera de la pagina resto una pagina
		if (document.getElementById("p_amigo_principal").value > 1) {
			document.getElementById("p_amigo_principal").value = document.getElementById("p_amigo_principal").value - 1;
		}
	}
	
	document.getElementById("codigo_mio_borrar").value = codigo_mio_borrar;
	document.getElementById("codigo_amigo_borrar").value = codigo_amigo_borrar;
	document.getElementById("formulario_amigo_principal").action = 'amigos.php';
	document.formulario_amigo_principal.submit();	
}
////////////////////////////////////////////////////////
function OpenNewWindow(Destination,WindowName,Width,Height,Position,Scrollbars,Resizable,Left,Top)	{
/*	var features = "resizable:"+Resizable+";scroll:"+Scrollbars+";status:no;center:yes;help:no;dialogWidth:"+Width+"px;dialogHeight:"+Height+"px;";
	window.showModalDialog(Destination, window, features);
*/
//   Position where the window will open
//   --------------------
//   |   TL   TC   TR   |
//   |   ML   MC   MR   |
//   |   BL   BC   BR   |
//   --------------------
	DefaultPosition = 'MC';
	DefaultWidth = 200;
	DefaultHeight = 150;
	DefaultMargin = 10;
	
	if (!Position)
		{ Position = DefaultPosition; }

	if (!Height)
		{ Height = DefaultHeight; }

	if (!Width)
		{ Width = DefaultWidth; }

	if (!Scrollbars && !Resizable)
		{
		Scrollbars = 'no';
		Resizable = 'no';
		}

	if (!Left && !Top)
		{
		Left = DefaultMargin;
		Top = DefaultMargin;
		}

	if (Position == 'TC')
		{ Left = (screen.width - Width) / 2; }
	else if (Position == 'TR')
		{ Left = screen.width - Width - (Left * 2); }
	else if (Position == 'ML')
		{ Top = (screen.height - Height) / 2; }
	else if (Position == 'MC')
		{
		Left = (screen.width - Width) / 2;
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'MR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = (screen.height - Height) / 2;
		}
	else if (Position == 'BL')
		{ Top = screen.height - (Height + (Top * 2) + 45); }
	else if (Position == 'BC')
		{
		Left = (screen.width - Width) / 2;
		Top = screen.height - (Height + (Top * 2) + 45);
		}
	else if (Position == 'BR')
		{
		Left = screen.width - Width - (Left * 2);
		Top = screen.height - (Height + (Top * 2) + 45);
		}

 	WindowName = window.open(Destination,WindowName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + Scrollbars + ",resizable=" + Resizable + ",copyhistory=yes,top=" + Top + ",left=" + Left + ",width=" + Width + ",height=" + Height+",dialog=yes,modal=yes")
	WindowName.focus();

/*	if (ErrorOpeningPopups && !Window)
		{ alert(ErrorOpeningPopups); }
*/
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
function cambioFichero1(sValor, sValor2) {
	sValor2.value = sValor.value.replace('C:\\fakepath\\','');
}
