
	function desactivar (id) {		
		document.getElementById(id).innerHTML = 'Enviando ...';		
	}

	function verificaRegistro ($usuario, $password, $password2) {
		if ($password == $password2) { 
			if ($usuario.length == 0) {
				alert ('Tu nombre no puede estar vacio.');			
			} else if ($password.length == 0) {
				alert ('La contraseña no puede estar vacia.');
			} else  if (!document.getElementById ('aviso').checked) {
				alert ('Debes leer y aceptar el aviso legal.');
			} else if (document.getElementById ('email1') != null) { //Solo aplica para registro sin invitación
				if (document.getElementById ('email1').value == '') {
					alert ('No has indicado tu direccion de email');
				} else {
					desactivar ('boton');
					document.formRegistro.submit(); 					
				}
		    } else {
				desactivar ('boton');
				document.formRegistro.submit(); 
			}
		} else alert ('Las contraseñas no coinciden. '); 				
	}

	function createRequestObject () {
		var request_;
		var browser = navigator.appName;
		if (browser == "Microsoft Internet Explorer") {
			request_ = new ActiveXObject ("Microsoft.XMLHTTP");
		} else { request_ = new XMLHttpRequest (); }
		return request_;
	}
	
	function reenviarInvitacion () {
		document.getElementById ('botonenviar').innerHTML = '<a href="javascript:enviarInvitacionUsuario();" class="resaltadop">Enviar</a>';
		document.getElementById ('emaili').value = 'Escribe el e-mail';
		document.getElementById ('emaili').select ();
	}
		
	function enviarInvitacionUsuario () {
		var email = document.getElementById ('emaili').value;
		if ((email.indexOf (' ') != (-1)) || (email.indexOf (';') != (-1)) || (email.indexOf (',') != (-1))) {
			alert ('Solo puedes escribir un e-mail por invitacion!');
			return;
		}
		var departede = document.getElementById ('departede').value;
		var http = new Array ();
		document.getElementById ('botonenviar').innerHTML = 'Enviando ...';
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'enviarinvitacion.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('departede=' + departede + '&email=' + email); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					document.getElementById ('botonenviar').innerHTML = '<a href="javascript:enviarInvitacionUsuario();" class="resaltadop">Enviar</a>';
					document.getElementById ('emaili').value = '';
					if (document.getElementById ('labelninvit') != null)
						document.getElementById ('labelninvit').innerHTML = response;
					alert ('Tu invitacion se ha enviado correctamente ');	
					if (response > 0) {
						document.getElementById ('mrespuestai').innerHTML = 'Hemos enviado la invitaci&oacute;n. <a href="javascript:reenviarInvitacion();">&iquest;Quieres enviar otra?</a>';
					} else {
						document.getElementById ('tablainvit').innerHTML = '<span class="resaltado" style="padding-left:20px;">&iexcl;Has agotado tus invitaciones!</span>';
						document.getElementById ('mrespuestai').innerHTML = 'Hemos enviado la invitaci&oacute;n.';
					}
		        }
		    }
		}		
	}	

	function reenviarInvitacion () {
		document.getElementById ('botonenviar').innerHTML = '<a href="javascript:enviarInvitacionUsuario();" class="resaltadop">Enviar</a>';
		document.getElementById ('emaili').value = 'Escribe el e-mail';
		document.getElementById ('emaili').select ();
	}

	function cambiaEstilo (estilo, actuacion) {
		var http = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'etiquetar.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('actuacion=' + actuacion + '&estilo=' + estilo); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {
					document.getElementById ('tablacambiada').style.visibility = "visible";
					document.getElementById ('tablacambiada').style.display = "";
					document.getElementById ('tablaestilos').style.visibility = "hidden";
					document.getElementById ('tablaestilos').style.display = "none";
		        }
		    }
		}		
	}

	function refrescaRadio (actuacion) {
		var http = new Array ();
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'parametrousuario.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
    	http[curDateTime].send ('actuacion=' + actuacion + '&parametro=1'); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {			
		        	var response = http[curDateTime].responseText;	
					var lista = response.split ("###");
					document.getElementById ('fotoautor').src = lista[2];
					document.getElementById ('nombreautor').innerHTML = lista[1];
					document.getElementById ('nombreautor').href = 'javascript: parent.location.href = "usuario.php?id=' + lista[0] + '"';
					document.getElementById ('tituloactuacion').href = 'actuacionu.php?id=' + lista[3];
					document.getElementById ('tituloactuacion').innerHTML = lista[4];
					if (lista[5]. indexOf ("ninguno") != (-1)) {
						document.getElementById ('tablacambiada').style.visibility = "hidden";
						document.getElementById ('tablacambiada').style.display = "none";
						document.getElementById ('tablaestilos').style.visibility = "visible";
						document.getElementById ('tablaestilos').style.display = "";
						document.getElementById ('etiquetadacomo').style.visibility = "hidden";
						document.getElementById ('etiquetadacomo').style.display = "none";
					} else {
						document.getElementById ('tablacambiada').style.visibility = "hidden";
						document.getElementById ('tablacambiada').style.display = "none";
						document.getElementById ('tablaestilos').style.visibility = "hidden";
						document.getElementById ('tablaestilos').style.display = "none";
						document.getElementById ('etiquetadacomo').style.visibility = "visible";
						document.getElementById ('etiquetadacomo').style.display = "";
						document.getElementById ('etiquetar').options[0].selected = true;
						document.getElementById ('etiquetadacomo').innerHTML = "<span class=pequeno>Etiquetada como " + lista[5] + "</a>";
					}
		        }
		    }
		}		
	}

	function enviarAmigo (media) {
		var email = document.getElementById ('emaila').value;
		var media = document.getElementById ('media').value;
		var propietario = document.getElementById ('propietario').value;
		var params = '';
		if (media == 1){var foto = document.getElementById ('foto').value; params = '&foto=' + foto;}
		if (media == 2){var actuacion = document.getElementById ('actuacion').value; params =  '&actuacion=' + actuacion;}
		if (media == 3){var video = document.getElementById ('video').value;params = '&video=' + video}
		if ((email.indexOf (' ') != (-1)) || (email.indexOf (';') != (-1)) || (email.indexOf (',') != (-1))) {
			alert ('Solo puedes escribir un e-mail por invitacion!');
			return;
		}

		var http = new Array ();
		document.getElementById ('envio_amigo_status').innerHTML = 'Enviando ...';
		var curDateTime = new Date ();
		http[curDateTime] = createRequestObject ();
		http[curDateTime].open ('post', 'enviaramigo.php');
		http[curDateTime].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
		
    	http[curDateTime].send ('email=' + email + '&media=' + media + '&propietario=' + propietario + params); 
		http[curDateTime].onreadystatechange = function () {
			if (http[curDateTime].readyState == 4) {
		    	if (http[curDateTime].status == 200 || http[curDateTime].status == 304) {
					document.getElementById ('emaila').value = 'Email de tu amigo';
					alert ('Tu recomendación se ha enviado correctamente ');
					document.getElementById ('envio_amigo_status').innerHTML = '';
		        }
		    }
		}		
	}
	
	function mostrarCuadroCom (id) {
		var nc = document.getElementById (id);
		if (nc.style.visibility == 'hidden') {
			nc.style.visibility = 'visible';
			nc.style.display = '';	
		} else {
			nc.style.visibility = 'hidden';
			nc.style.display = 'none';			
		}
	}
	
	function crearTablon () {		
		if ( document.getElementById ('nuevotablon').value!="" && document.getElementById('nuevotablon').value!= 'Escribe aquí el título' ){
			document.getElementById ('botoncreart').innerHTML = 'Creando tabl&oacute;n ...';
			document.getElementById ('formnuevotablon').submit();
		}else{
			alert('Indique el nombre para el nuevo foro');
		}
		
	}
	
// Extensiones permitidas para imagenes
	var extensionesImagen = new Array("gif", "jpg", "jpeg", "png");
	
	function subirFotoBook () {
		var fileVal = $('input#nuevafoto').val();
		var extension = (fileVal.substring(fileVal.lastIndexOf("."))).toLowerCase();
		var ext_valida = false;
		for (var i = 0; i < extensionesImagen.length; i++){
			if (extension == "." + extensionesImagen[i]) {
				ext_valida = true;
				break;
			}
		}
		if (ext_valida) {
			document.getElementById('botoncreart').innerHTML = 'Publicando foto ...';
			document.getElementById('form1').submit();
		} else {
			alert("El tipo de imagen que nos envias no es válido.\nPermitimos jpg, gif y png.");
		}
	}
	
	function subirFotoPerfil () {		
		
		var fileVal = $('input#fotop').val();
		var extension = (fileVal.substring(fileVal.lastIndexOf("."))).toLowerCase();
		var ext_valida = false;
		for (var i = 0; i < extensionesImagen.length; i++){
			if (extension == "." + extensionesImagen[i]) {
				ext_valida = true;
				break;
			}
		}
		if (ext_valida) {
			document.getElementById('botonecom').innerHTML = 'Publicando foto del perfil ...';
			document.getElementById('form1').submit();
		} else {
			alert1("El tipo de imagen que nos envias no es válido.\nPermitimos jpg, gif y png.");
		}
		
	}
	
	function subirPerfil () {
		var obj_nombre	= $('#nombre');
		var obj_email	= $('#email');

		if (obj_nombre.val().length > 0) {
			if (obj_email.val().length > 0) {
				var fileVal = $('input#fotop').val();
				var ext_valida = false;
				if (fileVal == "") {
					ext_valida = true;
				} else {
					var extension = (fileVal.substring(fileVal.lastIndexOf("."))).toLowerCase();
					
					for (var i = 0; i < extensionesImagen.length; i++) {
						if (extension == "." + extensionesImagen[i]) {
							ext_valida = true;
							break;
						}
					}
				}
				if (ext_valida) {
					document.getElementById('botonecom').innerHTML = 'Actualizando perfil ...';
					document.getElementById('form1').submit();
				} else {
					alert1("El tipo de imagen que nos env&iacute;as no es v&aacute;lido.\n Permitimos jpg, gif y png.");
				}
			} else {
				alert1("Tu email o identificador debe tener al menos un car&aacute;cter. Recuerda que lo debes usar para entrar en tu cuenta");
			}
		} else {
			alert1("Tu nombre como artista o como jurado, debe tener al menos un car&aacute;cter.");
		}
	}
	
	function validaFormUploadActuacion(seccion){
		var errores = "";
		if (document.getElementById ('titulo').value == ""){
			errores += "<li>Tienes que introducir un título para la " + seccion + "</li>"; 
		}
		
		if (document.getElementById('categoria').selectedIndex == 0){
			errores += "<li>Tienes que introducir una categoría para la " + seccion + "</li>"; 	
		}

		if (document.getElementById('select_tipo').selectedIndex != 0){
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				if (document.getElementById('nuevovideo').value == ""){ 
					errores += "<li>Tienes que introducir un archivo para la " + seccion + "</li>";
				}
			}
			if (document.getElementById('select_tipo').selectedIndex == 2){//Enlace externo
				var enlace = document.getElementById('link_ext').value;
				if (document.getElementById('link_ext').value == "") {
					errores += "<li>Tienes que introducir un enlace válido para la " + seccion + "</li>";
				} else if ((enlace.indexOf ('youtube.com/watch?v=') == (-1)) || (enlace.indexOf ('http') == (-1))) {
					errores += "<li>El formato de enlace de YouTube es http://youtube.com/watch?v= ...</li>";
				}
			}
		}else{
			errores += "<li>Selecciona si vas a subir un archivo o un enlace externo para la " + seccion + "</li>"; 
		}
		return errores;
	}
	
	function validaFormUploadVideo(seccion){
		var errores = "";
		if (document.getElementById ('titulo').value == ""){
			errores += "<li>Tienes que introducir un título para el " + seccion + "</li>"; 
		}

		if (document.getElementById('select_tipo').selectedIndex != 0){
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				if (document.getElementById('nuevovideo').value == ""){ 
					errores += "<li>Tienes que introducir un archivo para el " + seccion + "</li>";
				}
			}
			if (document.getElementById('select_tipo').selectedIndex == 2){//Enlace externo
				if (document.getElementById('link_ext').value == "") {
					errores += "<li>Tienes que introducir un enlace para el " + seccion + "</li>";
				} else if(isUrl(document.getElementById('link_ext').value)){
					errores += "<li>Tienes que introducir un enlace v&aacute;lido para el " + seccion + "</li>";
				}
			}
		}else{
			errores += "<li>Selecciona si vas a subir un archivo o un enlace externo para el " + seccion + "</li>"; 
		}
		return errores;
	}
	
	function isUrl(s) {
		var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
		return regexp.test(s);
	}
	
	function validaFormUploadActuacionConcurso(seccion){
		var errores = "";
		var lista = document.getElementById ('miactuacion');
		if ((document.getElementById ('titulo').value == "") && (lista.selectedIndex == 0)) {
			errores += "<li>Tienes que introducir un título para la " + seccion + "</li>"; 
		}
		if (document.getElementById('select_tipo').selectedIndex != 0){
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				if (document.getElementById('nuevovideo').value == ""){ 
					errores += "<li>Tienes que introducir un archivo para la " + seccion + "</li>";
				}
			}
			if (document.getElementById('select_tipo').selectedIndex == 2){//Enlace externo
				if (document.getElementById('link_ext').value == "") {
					errores += "<li>Tienes que introducir un enlace válido para la " + seccion + "</li>";
				}
			}
		} else if (lista.selectedIndex == 0) {
			errores += "<li>Selecciona si vas a subir un archivo o un enlace externo para la " + seccion + "</li>"; 
		}
		return errores;
	}
	
	function validaBuscar () {
		var palabras = document.getElementById ('buscar').value;
		if (palabras.length < 1)
			alert ('Tienes que escribir una palabra mas larga ');
		else document.getElementById('formbusqueda').submit();
	}
	
	function subirActuacion (sec) {
		var msg_err = "";
		msg_err = validaFormUploadActuacion(sec);
		if (msg_err ==""){
			$(".alerta").hide();
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				document.getElementById ('botoncreart').innerHTML = 'Publicando actuaci&oacute;n ...<br><span class="resaltadop">Puede tardar unos minutos, espera hasta que termine de recibirse</span>';
			}
		document.getElementById('form1').submit();
		}else{
			$("div.alerta").show();
			$("td.alerta_box").html(msg_err);
		}
	}
	
	function subirVideo (sec) {
		var msg_err = "";
		msg_err = validaFormUploadVideo(sec);
		if (msg_err ==""){
			$(".alerta").hide();
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				document.getElementById ('botoncreart').innerHTML = 'Publicando video ...<br><span class="resaltadop">Puede tardar unos minutos, espera hasta que termine de recibirse</span>';
			}
			document.getElementById('form2').submit();
		}else{
			$("div.alerta").show();
			$("td.alerta_box").html(msg_err);
		}
	}
	
	function subirActuacionConcurso (sec) {
		var msg_err = "";
		msg_err = validaFormUploadActuacionConcurso(sec);
		if (msg_err ==""){
			$(".alerta").hide();
			if (document.getElementById('select_tipo').selectedIndex == 1){ //Archivo
				document.getElementById ('botoncreart').innerHTML = 'Publicando actuaci&oacute;n ...<br><span class="resaltadop">Puede tardar unos minutos, espera hasta que termine de recibirse</span>';
			}
		document.getElementById('form1').submit();
		}else{
			$("div.alerta").show();
			$("td.alerta_box").html(msg_err);
		}
	}
	
	
	function enviaComentarioTablon () {
		if (document.getElementById ('comentario').value != '') {
			document.getElementById ('botonecom').innerHTML = 'Enviando comentario ...';
			document.getElementById ('formtablon').submit();		
		} else alert ('No has escrito nada!');
	}
	
	function enviaComentarioBlog () {
		if (document.getElementById ('comentario').value != '') {
			document.getElementById ('botonecom').innerHTML = 'Publicando mensaje ...';
			document.getElementById ('formtablon').submit();		
		} else alert ('No has escrito nada!');
	}	

	function enviaComentarioTablonFoto () {
		if (document.getElementById ('comentario').value != '') {
			document.getElementById ('botonecom').innerHTML = 'Enviando comentario ...';
			document.getElementById ('formtablon').submit();		
		} else alert ('No has escrito nada!');
	}
	
	function buscarVideos () {
		var texto = document.getElementById ('palabras').value;		
		if (texto == '') {
			alert ('No has escrito nada!');
		} else {
			document.getElementById ('botonbuscar').innerHTML = 'Buscando ...';
			document.getElementById ('form1').submit ();
		}
	}	
	
	function comentarTablon (id) {
		var texto = document.getElementById ('comtablon' + id).value;		
		if (texto == '') {
			alert ('No has escrito nada!');			
		} else {
			document.getElementById ('botonptabloncom' + id).innerHTML = 'Publicando ...';		
			document.getElementById ('comtablon' + id).submit ();
		}
	}		
	
	function enviarMensajeCorreo () {
		var objMensaje	= $('#mensaje');
		
		var para = document.getElementById ('para').value;
		var objPara 	= $('#para');			
		if (objPara.val() == '') {
			objPara.focus();
			alert ('Dinos a quien se lo enviamos');			
		} else if (objMensaje.val() == '') {
			objMensaje.focus();
			alert ('No has escrito nada!');	
		} else{
			document.getElementById ('botonenviar').innerHTML = 'Enviando ...';		
			document.getElementById ('form1').submit ();
		}
	}				
	
	function mostrarAyuda (id) {
		var cuadro = document.getElementById (id);
		if (cuadro.style.visibility == 'hidden') {
			cuadro.style.visibility = 'visible';
			cuadro.style.display = '';	
		} else {
			cuadro.style.visibility = 'hidden';
			cuadro.style.display = 'none';			
		}
	}
	
	function eliminarEstrellas () {
		for (i = 0; i < 5; i++) {
			document.getElementById ('star' + (i+1)).src = 'imagenes/estrella-off.gif';
		}
	}
	function muestraCalificacion (obj) {
		var id = obj.id;
		eliminarEstrellas ();
		if (id == 'star1') {
			document.getElementById ('star1').src = 'imagenes/estrella.gif';
			document.getElementById ('calificacion').value = 1;
		} else if (id == 'star2') {
			document.getElementById ('star1').src = 'imagenes/estrella.gif';
			document.getElementById ('star2').src = 'imagenes/estrella.gif';
			document.getElementById ('calificacion').value = 2;			
		} else if (id == 'star3') {
			document.getElementById ('star1').src = 'imagenes/estrella.gif';
			document.getElementById ('star2').src = 'imagenes/estrella.gif';
			document.getElementById ('star3').src = 'imagenes/estrella.gif';
			document.getElementById ('calificacion').value = 3;			
		} else if (id == 'star4') {
			document.getElementById ('star1').src = 'imagenes/estrella.gif';
			document.getElementById ('star2').src = 'imagenes/estrella.gif';
			document.getElementById ('star3').src = 'imagenes/estrella.gif';
			document.getElementById ('star4').src = 'imagenes/estrella.gif';
			document.getElementById ('calificacion').value = 4;			
		} else if (id == 'star5') {
			document.getElementById ('star1').src = 'imagenes/estrella.gif';
			document.getElementById ('star2').src = 'imagenes/estrella.gif';
			document.getElementById ('star3').src = 'imagenes/estrella.gif';
			document.getElementById ('star4').src = 'imagenes/estrella.gif';
			document.getElementById ('star5').src = 'imagenes/estrella.gif';
			document.getElementById ('calificacion').value = 5;			
		}
	}



