
function contactoOtroMotivo(valor){
	if(valor=='OTRO'){
		document.getElementById('otro_motivo').style.display='block';
		document.getElementById('otro_motivo2').style.display='block';
	}else{
		document.getElementById('otro_motivo').style.display='none';
		document.getElementById('otro_motivo2').style.display='none';
	}
}

function verificaContacto()
{
	contacto_email = document.contactar.contacto_email.value;
	if(document.contactar.contacto_email.value.length==0){
		alert("Debes introducir tu dirección de e-mail");
		document.contactar.contacto_email.focus();
		return false;
	}
	if(!is_mail(contacto_email))
	{
		alert(contacto_email+"  no es una dirección de e-mail válida");
		document.contactar.contacto_email.focus();
		return false;
	}
	if(document.contactar.contacto_con.value==0){
		alert("Por favor, selecciona el motivo");
		return false;
	}
	if(document.contactar.contacto_con.value=='OTRO'){
		if(document.contactar.contacto_asunto.value.length==0){
			alert("Por favor, especifica el motivo");
			document.contactar.contacto_asunto.focus();
			return false;
		}else {document.contactar.contacto_subject.value=document.contactar.contacto_asunto.value;}
	}else {
		document.contactar.contacto_subject.value=document.contactar.contacto_con.options[document.contactar.contacto_con.selectedIndex].text;
	}

	if(document.contactar.contacto_mensaje.value==""){
		alert("Por favor, especifica el mensaje");
		document.contactar.contacto_mensaje.focus();
		return false;
	}
	return true;
}

function desplegar(categoria){
	var menu = document.getElementById(categoria);
	var menu2 = document.getElementById('aniversarios2');

	if(menu2.style.display == "none"){
		menu.style.display = "none";
		menu2.style.display = "block";
	}
	else{
		menu.style.display = "block";
		menu2.style.display = "none";
	}
}

function DenunciarComentarioPartido(COMMENT_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/partido/partido-denunciarcommentrun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function DenunciarComentarioPartidoCampeonato(COMMENT_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/campeonato/campeonatoDenunciarcommentrun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function AbonoNoDisponible(ABONO_ID){
	if(confirm("¿Estás seguro de marcar como vendido/adquirido?")){
		location.href="/sections/entradas/entradas-vendidorun.php?abono_id="+ABONO_ID;
	}
}

function DenunciarComentarioFoto(COMMENT_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/gallery/galleryDenounceCommentRun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function denunciarComentarioVideo(COMMENT_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/videos/videos-denunciarcommentrun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function denunciarFoto()
{
	document.getElementById('link_denuncia').style.visibility="hidden";
	document.getElementById('denuncia').style.display='block';
}
function denunciarFotoRun(FOTO_ID)
{
 	var radio_choice = false;
	var ajax=nuevoAjax();

	for (counter = 0; counter < document.forms['FormDenuncia'].denuncia_motivo.length; counter++){
		if (document.forms['FormDenuncia'].denuncia_motivo[counter].checked){
			if(document.forms['FormDenuncia'].denuncia_motivo[counter].value=="OTRO"){
				if(document.forms['FormDenuncia'].denuncia_motivo_texto.value==""){
					alert("Por favor, indica un motivo");
				}else{
					motivo = document.forms['FormDenuncia'].denuncia_motivo_texto.value;
				}
			}else{
				motivo = document.forms['FormDenuncia'].denuncia_motivo[counter].value;
			}
			radio_choice = true;
		}
	}

	if(!radio_choice){
		alert("Por favor, indica un motivo");
	}else{
		ajax.open("GET", "/sections/gallery/galleryDenouncePhotoRun.php?foto_id="+FOTO_ID+"&motivo="+motivo, true);
		ajax.send(null);

		document.getElementById('denuncia').style.display="none";
		document.getElementById('denuncia_recibida').style.display="block";
	}

	return false;

}

function cancelarDenunciarFoto()
{
	document.getElementById('link_denuncia').style.visibility="visible";
	document.getElementById('denuncia').style.display='none';
}

function eliminarFoto(FOTO_ID,FOTO_URL){
	if(confirm("¿Estás seguro de eliminar esta fotografía?"))
	{
		location.href="/sections/gallery/galleryDelPhoto.php?foto_id="+FOTO_ID+"&foto_url="+FOTO_URL;
	}
}

function denunciarVideo()
{

	document.getElementById('link_denuncia').style.display="none";
	document.getElementById('denuncia').style.display='block';
}

function denunciarVideoRun(VIDEO_ID)
{
 	var radio_choice = false;
	var ajax=nuevoAjax();

	for (counter = 0; counter < document.forms['FormDenuncia'].denuncia_motivo.length; counter++){
		if (document.forms['FormDenuncia'].denuncia_motivo[counter].checked){
			if(document.forms['FormDenuncia'].denuncia_motivo[counter].value=="OTRO"){
				if(document.forms['FormDenuncia'].denuncia_motivo_texto.value==""){
					alert("Por favor, indica un motivo");
				}else{
					motivo = document.forms['FormDenuncia'].denuncia_motivo_texto.value;
				}
			}else{
				motivo = document.forms['FormDenuncia'].denuncia_motivo[counter].value;
			}
			radio_choice = true;
		}
	}

	if(!radio_choice){
		alert("Por favor, indica un motivo");
	}else{
		ajax.open("GET", "/sections/videos/videos-denunciarvideorun.php?video_id="+VIDEO_ID+"&motivo="+motivo, true);
		ajax.send(null);

		document.getElementById('denuncia').style.display="none";
		document.getElementById('denuncia_recibida').style.display="block";
	}

	return false;

}

function cancelarDenunciarVideo()
{
	document.getElementById('link_denuncia').style.display="block";
	document.getElementById('denuncia').style.display='none';
}

function DenunciarPost(POST_ID){
	document.getElementById('link_denuncia'+POST_ID).style.visibility="hidden";
	document.getElementById('denuncia'+POST_ID).style.display='block';
}

function CancelarDenunciarPost(POST_ID){
	document.getElementById('link_denuncia'+POST_ID).style.visibility="visible";
	document.getElementById('denuncia'+POST_ID).style.display='none';
}

function DenunciarPostRun(POST_ID){
 	var radio_choice = false;
	var ajax=nuevoAjax();
	var fname='FormDenuncia'+POST_ID;

	var total=document.forms[fname].denuncia_motivo.length;
	for (counter = 0; counter < total; counter++){
		if (document.forms[fname].denuncia_motivo[counter].checked){
			if(document.forms[fname].denuncia_motivo[counter].value=="OTRO"){
				if(document.forms[fname].denuncia_motivo_texto.value==""){
					alert("Especifica el motivo");
				}else{
					motivo = document.forms[fname].denuncia_motivo_texto.value;
				}
			}else{
				motivo = document.forms[fname].denuncia_motivo[counter].value;
			}
			radio_choice = true;
		}
	}

	if(!radio_choice){
		alert("Por favor, indica un motivo");
	}else{
		ajax.open("GET", "/sections/foro/foro-denunciarpostrun.php?post_id="+POST_ID+"&motivo="+motivo, true);
		ajax.send(null);

		document.getElementById('denuncia'+POST_ID).style.display="none";
		document.getElementById('denuncia_recibida'+POST_ID).style.display="block";
	}

	return false;
}

function obre_s(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=800,height=600');");
}

function error(){
 alert("El usuario o la contraseña son incorrectos");
 	window.location.href="/";
}

function changeOptionPost(form){

	if(form.u.checked){
		form.u.checked=0;
		form.d.checked=1;
	}
}

function changeOptionUser(form){

	if(form.d.checked){
		form.d.checked=0;
		form.u.checked=1;
	}
}

/*Alta de usuario*/

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function unquote (my_string)
{
	var new_string = String (my_string);

	nRegClose=/\[\/quote\]/g;
	nRegOpen =/\[quote=/g;
	nRegOpenDiv = /\]/g;
	new_string = new_string.replace (nRegClose, "</div>");
	new_string = new_string.replace (nRegOpen, "<p style='font-weight:bold;'>");
	new_string = new_string.replace (nRegOpenDiv, " escribió:</p><div style='background:;border:1px solid ;padding:4px;'>");

	return "<small style='line-height:20px;'>"+new_string+"</small>";
}


function nuevoAjax()
{
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
        var obj;

        if(window.XMLHttpRequest){
            obj = new XMLHttpRequest();
        } else if(window.ActiveXObject) {
			obj = new ActiveXObject("Microsoft.XMLHTTP");
        }

        return obj;

}

// Declaro los selects que componen el documento HTML. Su atributo ID debe figurar aqui.
var listadoSelects=new Array();
listadoSelects[0]="paises";
listadoSelects[1]="estados";

var listadoSelectsPartidos=new Array();
listadoSelectsPartidos[0]="temporada_id";
listadoSelectsPartidos[1]="partido_id";

var listadoSelectsAlbumes=new Array();
listadoSelectsAlbumes[0]="album";
listadoSelectsAlbumes[1]="subalbum1";
listadoSelectsAlbumes[2]="subalbum2";
listadoSelectsAlbumes[3]="subalbum3";
listadoSelectsAlbumes[4]="subalbum4";
listadoSelectsAlbumes[5]="subalbum5";


function buscarEnArray(array, dato)
{
	// Retorna el indice de la posicion donde se encuentra el elemento en el array o null si no se encuentra
	var x=0;
	while(array[x])
	{
		if(array[x]==dato) return x;
		x++;
	}
	return null;
}

function cargaContenido(idSelectOrigen)
{
	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	var posicionSelectDestino=buscarEnArray(listadoSelects, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);
	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;

	if(opcionSeleccionada==0)
	{
		var x=posicionSelectDestino, selectActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(listadoSelects[x])
		{
			selectActual=document.getElementById(listadoSelects[x]);
			selectActual.length=0;

			var nuevaOpcion=document.createElement("option");
			nuevaOpcion.value=0;
			nuevaOpcion.innerHTML="Seleccionar opción...";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena
	else if(idSelectOrigen!=listadoSelects[listadoSelects.length-1])
	{
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=listadoSelects[posicionSelectDestino];
		var selectDestino=document.getElementById(idSelectDestino);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		var ajax=nuevoAjax();

		ajax.open("GET", "/libs/ajax.provincias.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada, true);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option");
				nuevaOpcion.value=0;
				nuevaOpcion.innerHTML="Seleccionar opción...";
				selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
	}
}
function cargaPartidos(idSelectOrigen)
{
	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	var posicionSelectDestino=buscarEnArray(listadoSelectsPartidos, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);
	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;
	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	if(opcionSeleccionada==0)
	{
		var x=posicionSelectDestino, selectActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(listadoSelectsPartidos[x])
		{
			selectActual=document.getElementById(listadoSelectsPartidos[x]);
			selectActual.length=0;

			var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena
	else if(idSelectOrigen!=listadoSelectsPartidos[listadoSelectsPartidos.length-1])
	{
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=listadoSelectsPartidos[posicionSelectDestino];
		var selectDestino=document.getElementById(idSelectDestino);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		var ajax=nuevoAjax();

		ajax.open("GET", "/libs/ajax.partidos.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada, true);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
				selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
	}
}

function cargaPartidosTemporada()
{
 	var myPartidos = document.getElementById('hola');
 	idTemporada = document.getElementById('temporada_id').value;

	var ajax=nuevoAjax();
	ajax.open("GET", "/libs/ajax.partidos.php?id_temp="+idTemporada, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1)
		{
			myPartidos.innerHTML = "Seleccionar opción...";
		}
		if (ajax.readyState==4)
		{
			myPartidos.innerHTML=ajax.responseText;
		}
	}

	ajax.send(null);
}

function cargaJornadasTemporada(COMP_ID)
{
 	var myJornadas = document.getElementById('jornada');
 	idTemporada = document.getElementById('temporada_id').value;

	var ajax=nuevoAjax();
	ajax.open("GET", "/sections/resultados/ajax.cargaJornadas.php?id_temp="+idTemporada+"&id_comp="+COMP_ID, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1)
		{
			myJornadas.innerHTML = "Seleccionar opción...";
		}
		if (ajax.readyState==4)
		{
			myJornadas.innerHTML=ajax.responseText;
		}
	}

	ajax.send(null);
}


function cargaSubalbumes(idSelectOrigen)
{
	// Obtengo la posicion que ocupa el select que debe ser cargado en el array declarado mas arriba
	var posicionSelectDestino=buscarEnArray(listadoSelectsAlbumes, idSelectOrigen)+1;
	// Obtengo el select que el usuario modifico
	var selectOrigen=document.getElementById(idSelectOrigen);
	// Obtengo la opcion que el usuario selecciono
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;

	document.upload.album_id.value = opcionSeleccionada;

	// Si el usuario eligio la opcion "Elige", no voy al servidor y pongo los selects siguientes en estado "Selecciona opcion..."
	if(opcionSeleccionada==0)
	{
		var x=posicionSelectDestino, selectActual=null; trActual=null;
		// Busco todos los selects siguientes al que inicio el evento onChange y les cambio el estado y deshabilito
		while(listadoSelectsAlbumes[x])
		{
			selectActual=document.getElementById(listadoSelectsAlbums[x]);
			selectActual.length=0;

			var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;

			trActual=document.getElementById('tr_'+listadoSelectsAlbums[x]);
			trActual.style.display='none';
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena
	else if(idSelectOrigen!=listadoSelectsAlbumes[listadoSelectsAlbumes.length-1])
	{
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=listadoSelectsAlbumes[posicionSelectDestino];
		var selectDestino=document.getElementById(idSelectDestino);
		var trDestino=document.getElementById('tr_'+idSelectDestino);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		var ajax=nuevoAjax();

		ajax.open("GET", "/libs/ajax.subalbumes.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada+"&ms="+new Date().getTime(), true);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
				selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if(ajax.responseText!="none")
				{
					trDestino.style.display='';
					x=posicionSelectDestino+1;
					while(listadoSelectsAlbumes[x])
					{
						trDestino=document.getElementById('tr_'+listadoSelectsAlbumes[x]);
						trDestino.style.display='none';
						x++;
					}
					selectDestino.parentNode.innerHTML=ajax.responseText;
				}
				else
				{
					trDestino.style.display='none';
					x=posicionSelectDestino+1;
					while(listadoSelectsAlbumes[x])
					{
						trDestino=document.getElementById('tr_'+listadoSelectsAlbumes[x]);
						trDestino.style.display='none';
						x++;
					}
				}
			}
		}
		ajax.send(null);
	}
}

function cargaTagsAlbum(albumId){
	var tagsAlbum 	= document.getElementById('tagsAlbum');
	var ajax		= nuevoAjax();
	var labelTags 	= document.getElementById('labelRecomendadas');

	ajax.open("GET", "/libs/ajax.getAlbumTags.php?album_id="+albumId, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1)
		{
			tagsAlbum.innerHTML="Seleccionar opción...";
		}

		if (ajax.readyState==4)
		{
			tagsAlbum.innerHTML=ajax.responseText;
			if(ajax.responseText==""){
				labelTags.style.display="none";
			}else{
				labelTags.style.display="block";
			}
		}
	}
	ajax.send(null);
}

function addTag2Foto(tagId,tagValue){
	var inputTags = document.upload.keywords;
	var tagLink	  = document.getElementById('tag'+tagId);
	inputTags.value = inputTags.value+" "+tagValue;
	tagLink.className="bgc10";
	tagLink.innerHTML = tagValue;
}

function cargaSubalbumesVideo(idSelectOrigen)
{
	var posicionSelectDestino=buscarEnArray(listadoSelectsAlbumes, idSelectOrigen)+1;
	var selectOrigen=document.getElementById(idSelectOrigen);
	var opcionSeleccionada=selectOrigen.options[selectOrigen.selectedIndex].value;

	document.upload.album_id.value = opcionSeleccionada;

	if(opcionSeleccionada==0)
	{
		var x=posicionSelectDestino, selectActual=null; trActual=null;
		while(listadoSelectsAlbumes[x])
		{
			selectActual=document.getElementById(listadoSelectsAlbums[x]);
			selectActual.length=0;

			var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
			selectActual.appendChild(nuevaOpcion);	selectActual.disabled=true;

			trActual=document.getElementById('tr_'+listadoSelectsAlbums[x]);
			trActual.style.display='none';
			x++;
		}
	}
	// Compruebo que el select modificado no sea el ultimo de la cadena
	else if(idSelectOrigen!=listadoSelectsAlbumes[listadoSelectsAlbumes.length-1])
	{
		// Obtengo el elemento del select que debo cargar
		var idSelectDestino=listadoSelectsAlbumes[posicionSelectDestino];
		var selectDestino=document.getElementById(idSelectDestino);
		var trDestino=document.getElementById('tr_'+idSelectDestino);
		// Creo el nuevo objeto AJAX y envio al servidor el ID del select a cargar y la opcion seleccionada del select origen
		var ajax=nuevoAjax();

		ajax.open("GET", "/libs/ajax.subalbumesVideos.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada+"&ms="+new Date().getTime(), true);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Seleccionar opción...";
				selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				if(ajax.responseText!="none")
				{
					trDestino.style.display='';
					x=posicionSelectDestino+1;
					while(listadoSelectsAlbumes[x])
					{
						trDestino=document.getElementById('tr_'+listadoSelectsAlbumes[x]);
						trDestino.style.display='none';
						x++;
					}
					selectDestino.parentNode.innerHTML=ajax.responseText;
				}
				else
				{
					trDestino.style.display='none';
					x=posicionSelectDestino+1;
					while(listadoSelectsAlbumes[x])
					{
						trDestino=document.getElementById('tr_'+listadoSelectsAlbumes[x]);
						trDestino.style.display='none';
						x++;
					}
				}
			}
		}
		ajax.send(null);
	}
}


function foro_over(src){
	src.style.background = '#FFF5E6';

}

function foro_out1(src){
	src.style.background = '#EFEFEF';


}

function foro_out2(src){
	src.style.background = '#F9F9F9';

}


function is_mail(texto){

    var mailres = true;
    var cadena = "abcdefghijklmn?opqrstuvwxyzABCDEFGHIJKLMN?OPQRSTUVWXYZ1234567890@._-";

    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;

    var punto = texto.lastIndexOf(".");

     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;

    return mailres;
}



function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }

/*****************************************/
/*****************ABONOS******************/
/*****************************************/

function verifica_abonos(form){
	if(form.partido_id.value==0){ alert("¿De qué partido hablamos?");form.partido_id.focus(); return false;}

	if(form.abono_precio.disabled==false)
	{
		if(form.abono_precio.value=="")
		{
			alert("¿Cuánto cuesta tu abono?");
			form.abono_precio.focus();
			return false;
		}
		if(!IsNumeric(form.abono_precio.value))
		{
			alert(form.abono_precio.value+" no es un precio");
			form.abono_precio.focus();
			return false;
		}
	}

	if(form.abono_mail.value=="" && form.abono_telefono.value==""){
		alert("Tienes que introducir alguna de las dos formas de contacto");
		form.abono_mail.focus();
		return false;

	}

	if(!form.abono_mail.value=="")
	{
		if(!is_mail(form.abono_mail.value))
		{
			alert(form.abono_mail.value+" no es una dirección de e-mail válida");
			form.abono_mail.focus();
			return false;
		}
	}
	 return true;
}

function oculta_abonos() {
	document.abonos.ubicacion_id.disabled=true;
	document.abonos.abono_precio.disabled=true;
	document.abonos.abono_title.disabled=false;

}

function muestra_abonos() {
	document.abonos.ubicacion_id.disabled=false;
	document.abonos.abono_precio.disabled=false;
	document.abonos.abono_title.disabled=true;
}

/*****************************************/
/*****************PORQUE******************/
/*****************************************/

function verifica_porque(form) {

	 if(form.porque_body.value==""){alert("Debes introducir tu porqué");form.porque_body.focus();return false;}
	 return true;
}

function DenunciarPorque(PORQUE_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+PORQUE_ID).style.display='none';
	document.getElementById('denuncia'+PORQUE_ID).style.display='block';
	ajax.open("GET", "/sections/porque/porque-denunciarporquerun.php?porque_id="+PORQUE_ID, true);
	ajax.send(null);
}

/*****************************************/
/**********PAARTIDO_COMMENT****************/
/*****************************************/

function verifica_partido_comment(form) {
	if(form.pc_comment_body.value==""){alert("No puedes introducir comentarios vacíos");form.pc_comment_body.focus();return false;}
	return true;
}




/*****************************************/
/*****************PORRIELA****************/
/*****************************************/

function porriela_edit_nueva() {
	document.getElementById('nueva').style.display='none';
	document.getElementById('mandar').style.display='block';
	document.mi_apuesta.apuesta_casa.disabled=false;
	document.mi_apuesta.apuesta_fuera.disabled=false;
	document.mi_apuesta.apuesta_casa.className='borde_input';
	document.mi_apuesta.apuesta_fuera.className='borde_input';
	document.mi_apuesta.apuesta_casa.focus();
}

function porriela_edit_cambiar() {
	document.getElementById('cambiar').style.display='none';
	document.getElementById('mandar').style.display='block';
	document.mi_apuesta.apuesta_casa.disabled=false;
	document.mi_apuesta.apuesta_fuera.disabled=false;
	document.mi_apuesta.apuesta_casa.className='borde_input';
	document.mi_apuesta.apuesta_fuera.className='borde_input';
	document.mi_apuesta.apuesta_casa.focus();
}

/*****************************************/
/*****************GALERIA*****************/
/*****************************************/

function verifica_upload(form){
	document.getElementById('bot_upload').disabled="disabled";
	if(form.album_id.value==0){ alert("Debes especificar el álbum"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	if(form.imagen.value.length==0){alert("Debes especificar la imagen"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	if(form.titulo.value.length==0){alert("Debes introducir un título para la imagen"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	if(!validate_text(form.titulo.value)){alert("El título debe contener letras o números"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	if(form.keywords.value.length==0){alert("Debes introducir las etiquetas"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	return true;
}


function verifica_delete(form) {
	 if(form.motivo_texto.value==""){alert("Debes indicar el motivo por el que deseas eliminar la foto");form.motivo_texto.focus();return false;}
	 return true;
}


function verificaBuscador(form) {
		if(form.vb.value==""){alert("Debes introducir lo que quieres buscar");form.vb.focus();return false;}
		return true;
}

/*****************************************/
/*****************VIDEO*******************/
/*****************************************/
function verifica_video(){
	document.getElementById('bot_upload').disabled="disabled";
	if(document.upload.album_id.value==0){ alert("Debes especificar el álbum");document.getElementById('bot_caption').innerHTML="Subir vídeo"; document.getElementById('bot_upload').disabled="";return false;}
	if(document.upload.titulo.value.length==0){alert("Debes introducir un título para el vídeo");document.getElementById('bot_caption').innerHTML="Subir vídeo"; document.getElementById('bot_upload').disabled="";return false;}
	if(!validate_text(document.upload.titulo.value)){alert("El título debe contener letras o números");document.getElementById('bot_caption').innerHTML="Subir vídeo"; document.getElementById('bot_upload').disabled="";return false;}
	if(document.upload.keywords.value.length==0){alert("Debes introducir las etiquetas"); document.getElementById('bot_caption').innerHTML="Subir foto"; document.getElementById('bot_upload').disabled=""; return false;}
	return true;
}

/*****************************************/
/*****************IDOLO*******************/
/*****************************************/

function verifica_idolo(form) {

 form.idolo_name.value = trim(form.idolo_name.value,'');
 if(form.idolo_name.value==""){alert("Elige a tu ídolo");return false;}
 if(form.idolo_name.value.length>80){alert("El título debe ser inferior a 80 carácteres");form.idolo_name.focus();return false;}
 form.idolo_body.value = trim(form.idolo_body.value,'');
 if(form.idolo_body.value.length<100){alert("Debes introducir como mínimo 100 carácteres");form.idolo_body.focus();return false;}
 return true;

}

function DenunciarIdolo(IDOLO_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+IDOLO_ID).style.display='none';
	document.getElementById('denuncia'+IDOLO_ID).style.display='block';
	ajax.open("GET", "/sections/idolo/idolo-denunciaridolorun.php?idolo_id="+IDOLO_ID, true);
	ajax.send(null);
}

/*****************************************/
/*****************MEMORABLE***************/
/*****************************************/

function verifica_memorable(form) {

	 if((form.rival1.value=="" || form.rival1.value==0) && form.rival2.value==""){alert("¿Cuál fue el rival?");return false;}
	 form.memorable_titulo.value = trim(form.memorable_titulo.value);
	 if(form.memorable_titulo.value==""){alert("Pon un título a tu partido memorable");return false;}
	 if(form.memorable_titulo.value.length>80){alert("El título debe ser inferior a 80 carácteres");form.memorable_titulo.focus();return false;}
	 form.memorable_body.value = trim(form.memorable_body.value);
	 if(form.memorable_body.value.length<100){alert("Debes introducir como mínimo 100 carácteres");form.memorable_body.focus();return false;}
	 return true;
}

function DenunciarMemorable(MEMORABLE_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+MEMORABLE_ID).style.display='none';
	document.getElementById('denuncia'+MEMORABLE_ID).style.display='block';
	ajax.open("GET", "/sections/memorable/memorable-denunciarmemorablerun.php?memorable_id="+MEMORABLE_ID, true);
	ajax.send(null);
}


/*****************************************/
/*****************FORO********************/
/*****************************************/

function verifica_foro(form) {
	document.getElementById('bot_boton').disabled='disabled';
	if(form.action.value==1){
		if(form.post_title.value.length == 0){alert("Rellena el asunto");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		else{post_title = trim(form.post_title.value, '');
		if(!validate_text(form.post_title.value)){alert("El asunto debe contener letras o números");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		if(post_title==""){
				alert("El asunto debe tener carácteres");
				document.getElementById('bot_boton').disabled='';
				document.getElementById('bot_caption').innerHTML="Enviar";
				return false;
			}
		}
		if(form.foro_id.value ==-1){alert("Elige un foro");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		if(form.post_body.value.length == 0){alert("Introduce el mensaje");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
	}else{
		if(form.post_body.value.length == 0){alert("Introduce el mensaje");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
	}

	return true;
}

function verificaBuscadorKey(form) {
		if(form.keyword.value==""){alert("Debes introducir lo que quieres buscar");form.keyword.focus();return false;}
		return true;
}


function verifica_respuesta_rapida(form) {
	document.getElementById('bot_boton').disabled='disabled';
	if(form.post_body.value.length == 0){alert("Introduce el mensaje");document.getElementById('bot_boton').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
	return true;
}

function valid_form_search(pagi){

	document.form_search.pag.value=pagi;
	document.form_search.submit();
}

function Verifica(form) {
	if(form.user_name.value.length<3){alert("Tu nick debe tener como mínimo 3 carácteres.");form.user_name.focus();return false;}
	if(form.user_pass.value.length<4){alert("Tu contraseña debe tener como mínimo 4 carácteres.");form.user_pass.focus();return false;}
	if(form.conformidad.checked==false){alert("Debes aceptar las condiciones de uso para poder registrarte.");return false;}

	if(form.user_pass_conf.value!=form.user_pass.value){alert("Las contraseñas no coinciden.");form.user_pass_conf.focus();return false;}

	if(form.paises.value==-1){alert("Debes indicar un país.");form.paises.focus();return false;}
	if(form.estados.value==-1 || form.estados.value.length==0){alert("Debes indicar una provincia");form.estados.focus();return false;}

	if(!is_mail(form.user_email.value)){alert("'"+form.user_email.value+"'  no es válido, por favor revísalo.");form.user_email.focus();return false;}

	return true;
}

function verifica_recomendar(form) {

	if(form.nombre.value==""){
		alert("Debes introducir tu nombre");
		form.nombre.focus();
		return false;
	}

	if(!is_mail(form.email.value))
	{
		alert(form.email.value+"  no es una dirección de e-mail válida");
		form.email.focus();
		return false;
	}

	if(form.recomendados.value==""){
		alert("Introduce los e-mails de tus amigos");
		form.recomendados.focus();
		return false;
	}
	return true;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



function trim1 (string) {
	string = string.replace(/^s+/, '');
	for (var i = string.length; i > 0; i--) {
		if (/S/.test(string.charAt(i))) {
			string = string.substring(0, i);
			break;
		}
	}
	return string;
}

function baseDomainString(){
  e = document.domain.split(/\./);
  
  if(e.length > 3){
  	return("domain=." + e[e.length-3] + "." + e[e.length-2] + "." +  e[e.length-1]) + ";"  ;
  }else{
	  if(e.length > 2) {
	    return("domain=." + e[e.length-2] + "." +  e[e.length-1]) + ";"  ;
	  }else{
	    return("");
	  }
  }
}

function VideosActionCookie(site,action,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_a_ivi = " + action + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_ivi = " + pos + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
}

function VideosAlbumCookie(site,album_id,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_a_id_ivi = " + album_id + ";" + baseDomainString() + " expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_ivi = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString() +"; path=/";
}

function VideosSearchCookie(site,vb,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_vb_id_ivi = " + vb + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_ivi = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString() +"; path=/";
}

function FotosActionCookie(site,action,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_a_igf = " + action + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_igf = " + pos + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	if(action!=0){
		FotosAlbumCookie(site,'',pos);
	}
}

function FotosAlbumCookie(site,album_id,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_a_id_igf = " + album_id + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_igf = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString() +"; path=/";
}

function FotosSearchCookie(site,vb,pos){
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie=site+"_vb_id_igf = " + vb + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString() +"; path=/";
	document.cookie=site+"_p_igf = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString() +"; path=/";
}

function selectsmile(n){
		document.getElementById('smileselector1').className='';
		document.getElementById('smileselector2').className='';
		document.getElementById('smileselector3').className='';
		document.getElementById('smileselector4').className='';
		document.getElementById('smileselector' + n).className='selected';
		document.getElementById('commentsmile').value=n;
}

function messageError(text)
{
	document.getElementById('mensajes').style.display='block';
	document.getElementById('mensajes').className='alerta';
	document.getElementById('mensajes').innerHTML=text;

	document.location = "#errores";
}

function spam_email(uemail){

	uemail = uemail.toLowerCase();

	if(uemail.indexOf('10minutemail',0)!=-1 ||
	uemail.indexOf('bugmenot',0)!=-1 ||
	uemail.indexOf('guerrillamail',0)!=-1 ||
	uemail.indexOf('jetable',0)!=-1 ||
	uemail.indexOf('mailinator',0)!=-1 ||
	uemail.indexOf('mierdamail',0)!=-1 ||
	uemail.indexOf('mailexpire',0)!=-1 ||
	uemail.indexOf('mailnull',0)!=-1 ||
	uemail.indexOf('trashymail',0)!=-1 ||
	uemail.indexOf('tempemail',0)!=-1 ||
	uemail.indexOf('flirztmail',0)!=-1 ||
	uemail.indexOf('trash2009',0)!=-1 ||
	uemail.indexOf('mytrashmail',0)!=-1 ||
	uemail.indexOf('temporaryinbox',0)!=-1 ||
	uemail.indexOf('maileater',0)!=-1 ||
	uemail.indexOf('tempomail',0)!=-1 ||
	uemail.indexOf('pookmail',0)!=-1 ||
	uemail.indexOf('greensloth',0)!=-1 ||
	uemail.indexOf('spam',0)!=-1 ){
		return true;
	}else{
		return false;
	}
}

function comprobar(texto,valor,minLong,maxLong){
  var variable = texto;

  if(variable.length<minLong || variable.length>maxLong){
  	return false;
  }

  if(valor=='txt'){
  	var comp = /^([a-zA-Z0-9]{2,14})$/;
  }

  if(valor=='mail'){
  	var comp = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
  }

  if (comp.test(texto)) {return true;}
  else {return false;}
}


function DescargarFotoOriginal(){
	var link_descarga = document.getElementById('descargar');
	var link_alta     = document.getElementById('alta');

	link_descarga.style.display="none";
	link_alta.style.display="block";
}

function editoresSearch() {
	var usr_keyw = document.getElementById("usr_keyw").value;

	var divResults = document.getElementById("editoresResults");
	var ajax=nuevoAjax();
	ajax.open("GET", "/sections/wiki/wiki-editoresSearch.php?usr_keyw="+usr_keyw, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1){
			// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
			divResults.innerHTML = "<img src='/media/img/general/ajax-loader.gif'>";

		}
		if (ajax.readyState==4){
			divResults.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

function wikiUploaderStatusChange(){
	var divUpload = document.getElementById('imgUploader');
	var linkStatus = document.getElementById('linkWikiChangeStatus');
	if(divUpload.style.display=='block'){
		divUpload.style.display='none';
		linkStatus.innerHTML = "Añadir imagen al artículo";
	}else{
		divUpload.style.display='block';
		linkStatus.innerHTML = "Cerrar";
	}
}

function ocultarTabla(){
	var divTabla = document.getElementById('idContent');
	var linkTabla = document.getElementById('linkOcultar');
	if(divTabla.style.display=='none'){
		divTabla.style.display='block';
		linkTabla.innerHTML = "ocultar";
	} else {
		linkTabla.innerHTML = "mostrar";
		divTabla.style.display='none';
	}
}

function denunciarWikiArticulo(){
	var divDenuncia = document.getElementById('formDenunciar');
	var linkDenunciar = document.getElementById('linkDenunciar');
		if(divDenuncia.style.display=='none'){
		divDenuncia.style.display='block';
		linkDenunciar.innerHTML = "Cerrar";
	} else {
		divDenuncia.style.display='none';
		linkDenunciar.innerHTML = "Denunciar artículo";
	}
}

function denunciarWikiArticuloRun(){
	if(document.denunciarArticulo.denunciaTexto.value.length == 0){
		alert("Por favor, copia la parte del texto que quieres denunciar");
		document.denunciarArticulo.denunciaTexto.focus();
	}else{
		document.denunciarArticulo.submit();
	}
}

function reportarAbusoAdmin(divAbuso,linkAbuso){
	var divAbuso = document.getElementById(divAbuso);
	var linkAbuso = document.getElementById(linkAbuso);
		if(divAbuso.style.display=='none'){
		divAbuso.style.display='block';
		linkAbuso.innerHTML = 'Cerrar';
	} else {
		divAbuso.style.display='none';
		linkAbuso.innerHTML = 'Reportar al administrador';
	}

}

function reportarAbusoAdminRun(divAbuso,linkAbuso,divReportado,formAbuso){
	var divAbuso = document.getElementById(divAbuso);
	var linkAbuso = document.getElementById(linkAbuso);
	var divReportado = document.getElementById(divReportado);
	var abusoInfo  = formAbuso.abusoInfo.value;
	var abusoTexto = formAbuso.abusoTexto.value;

	if(abusoTexto.length==0){
		alert("Por favor, indica el abuso realizado en la enciclopedia");

	}else{
		var ajax=nuevoAjax();
		ajax.open("GET", "/sections/wiki/wiki-reportarAbusoRun.php?abusoInfo="+abusoInfo+"&abusoTexto="+abusoTexto, true);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				divAbuso.innerHTML = "<img src='/media/img/general/ajax-loader.gif'>";

			}
			if (ajax.readyState==4){
				divAbuso.style.display='none';
				linkAbuso.style.display='none';
				divReportado.style.display='block';
			}
		}
		ajax.send(null);

	}

}

function cambiarStatusArticulo(page_id,currentStatus){
	var divOpen = document.getElementById('statusOpen');
	var divClosed = document.getElementById('statusClosed');

	if(currentStatus == 'closed'){
		divOpen.style.display  = 'block';
		divClosed.style.display = 'none';
	}else{
		divOpen.style.display  = 'none';
		divClosed.style.display = 'block';
	}

	var ajax=nuevoAjax();
	ajax.open("GET", "/sections/wiki/wiki-changePageStatus.php?page_id="+page_id+"&current="+currentStatus+"&ms="+new Date().getTime(), false);
	ajax.send(null);
}

function cambiarArticuloDestacado(page_id,current){
	var spanDestacado = document.getElementById('articuloDestacado');

	var ajax=nuevoAjax();
	ajax.open("GET", "/sections/wiki/wiki-changePageDestacado.php?page_id="+page_id+"&current="+current+"&ms="+new Date().getTime(), true);
	ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				spanDestacado.innerHTML = "<img src='/media/img/general/ajax-loader.gif' width='16' height='16' />";
			}
			if (ajax.readyState==4){

				spanDestacado.innerHTML=ajax.responseText;
			}
		}
	ajax.send(null);
}


function showMenu(menuVal){
	var my_menu = document.getElementById('menu'+menuVal);
	var my_submenu = document.getElementById('iSubMenu'+menuVal);
	var my_arrow = document.getElementById('iArrowInd'+menuVal);
	var Items = document.getElementsByName('subWal');

	for (counter = 0; counter < Items.length; counter++){
		 Items[counter].style.display='none';
	}

	var Items = document.getElementsByName('Wal');

	for (counter = 0; counter < Items.length; counter++){
		 Items[counter].className="linkMenu t3 neg";
	}

	if (my_menu){my_menu.className="linkMenuSelected t3 neg";}
	if (my_arrow){my_arrow.className="issetSubHo";}
	if (my_submenu){my_submenu.style.display="block";}
}

function hideMenu(menuVal){
	var my_submenu = document.getElementById('iSubMenu'+menuVal);
	var my_arrow = document.getElementById('iArrowInd'+menuVal);
	var Items = document.getElementsByName('Wal');

	for (counter = 0; counter < Items.length; counter++){
		 Items[counter].className="linkMenu t3 neg";
	}

	if (my_arrow){my_arrow.className="issetSub";}
	if (my_submenu){my_submenu.style.display="none";}
}

/*****************************************/
/***************TRIVIAL*******************/
/*****************************************/

function verificaRespuestaTrivial(IDRespuesta)
{
	var myAlert= document.getElementById('faltaRespuesta');
	document.FormPreguntasTrivial.jsenabled.value="Y";
	radio = document.FormPreguntasTrivial.answer;
        for(i=0; i< radio.length;i++){
           if (radio[i].checked){
              n=radio[i].value;
              return true;
           }
        }
           myAlert.style.display="block";
           return false;
}

function verifica_add_trivial(form) {

	 form.jsenabled.value="Y";
	 if(form.preg.value==""){alert("Debes introducir una pregunta");return false;}
	 if(form.resp1.value==""){alert("Debes introducir las 3 respuestas");form.resp1.focus();return false;}
	 if(form.resp2.value==""){alert("Debes introducir las 3 respuestas");return false;}
	 if(form.resp3.value==""){alert("Debes introducir las 3 respuestas");return false;}
	 return true;
}

function verifyJs(formName)
{
	formName.jsenabled.value="Y";
}

function verifyJsAdd(formName)
{
	formName.jsenabled.value="Y";

	if(confirm("¿Seguro que quieres plantarte?"))
	{
		formName.action="/sections/trivial/trivialPlantarse.php";
	}else{
		formName.action="/sections/trivial/trivialGame.php";
	}
}

function denunciarPregunta()
{
	document.getElementById('link_denuncia').style.display="none";
	document.getElementById('denuncia').style.display='block';
}

function denunciarPreguntaRun(PREGUNTA_ID)
{
	pregunta = document.forms['FormDenuncia'].denuncia_title.value;
	var ajax=nuevoAjax();

	params="pregunta="+pregunta+"&pregunta_id="+PREGUNTA_ID;
	ajax.open("POST", "/sections/trivial/ajax.trivialDenunciarPregunta.php", true);
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);

		document.getElementById('denuncia').style.display="none";
		document.getElementById('denuncia_recibida').style.display="block";

	ajax.send(params);
}

function muestraRegistro()
{
	document.getElementById("registrate").style.display="none";
	document.getElementById("registrarme").style.display="block";
}

function muestraReglas()
{
	document.getElementById("reglas").style.display="block";
	document.getElementById("link_muestra_reglas").style.display="none";
	document.getElementById("link_oculta_reglas").style.display="block";
}
function ocultaReglas()
{
	document.getElementById("reglas").style.display="none";
	document.getElementById("link_muestra_reglas").style.display="block";
	document.getElementById("link_oculta_reglas").style.display="none";
}

function muestraRespuesta()
{
	document.getElementById("resp3").style.display="block";
	document.getElementById("link_otra_resp").style.display="none";
}

function ocultaRespuesta()
{
	document.getElementById("resp3").style.display="none";
	document.getElementById("link_otra_resp").style.display="block";
}

function Tiempoentrepreguntas()
{
	var num = 30;
	var inter = setInterval(function Tiempoentrepreguntas(){

		var dTimer = document.getElementById("timeout");
		if (!dTimer) return; dTimer.innerHTML = num--;
		if (num == -1)
		{
			clearInterval(inter);
			verifyJs(document.FormRespuestaVerificada);
			document.FormRespuestaVerificada.submit();
		}
	}, 1000);
}

function cancelarDenunciarPregunta()
{
	document.getElementById('link_denuncia').style.display="block";
	document.getElementById('denuncia').style.display='none';
}

function muestraContacto(myId){
	var id2show=document.getElementById('contact-'+myId);
	if(id2show.style.display=='none'){
		id2show.style.display='block';
	}else{
		id2show.style.display='none';
	}
}

function DenunciarComentario(COMMENT_ID,URL_ORI){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia'+COMMENT_ID).style.display='block';
	ajax.open("POST", "/sections/campeonato/campeonatoCommentDenunciarRun.php", false);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("comment_id="+COMMENT_ID+"&url_from="+URL_ORI);
}

function SendFriendObject(recomiendaAmigo)
{
		if(recomiendaAmigo.nombre.value==""){
			alert("Debes introducir tu nombre");
			recomiendaAmigo.nombre.focus();
			return false;
		}

		if(recomiendaAmigo.recomendados.value==""){
			alert("Introduce los e-mails de tus amigos");
			recomiendaAmigo.recomendados.focus();
			return false;
		}

		if(recomiendaAmigo.checkHuman.value==""){
			alert("Te has olvidado del texto que sale en la imagen");
			recomiendaAmigo.checkHuman.focus();
			return false;
		}

		var MostrarRespuesta = document.getElementById('enviar_amigo');
	 	var ajax=nuevoAjax();

	 	nombre=recomiendaAmigo.nombre.value;
	 	email=recomiendaAmigo.email.value;
	 	recomendados=recomiendaAmigo.recomendados.value;
	 	texto_opcional=recomiendaAmigo.texto_opcional.value;
	 	object_name=recomiendaAmigo.object_name.value;
		description=recomiendaAmigo.description.value;
		object_envio=recomiendaAmigo.object.value;
		object_id=recomiendaAmigo.object_id.value;
		thumbnail_path_foto=recomiendaAmigo.thumbnail_path_foto.value;
		thumbnail_path_video=recomiendaAmigo.thumbnail_path_video.value;
		checkHuman=recomiendaAmigo.checkHuman.value;
		captcha=recomiendaAmigo.captcha.value;


	 	var myString = new String(recomendados);
		var myArray = myString.split(',');

		for (counter = 0; counter < myArray.length; counter++){
			if(comprobar(myArray[counter],'mail',6,255)==false){alert("El e-mail " + myArray[counter] + " no es un e-mail correcto");recomiendaAmigo.email.focus();return false;}
		}
		var aleatorio=Math.random();
	 	params="nombre="+nombre+"&email="+email+"&description="+description+"&recomendados="+recomendados+"&texto_opcional="+texto_opcional+"&object_name="+object_name+"&object_envio="+object_envio+"&object_id="+object_id+"&thumbnail_path_foto="+thumbnail_path_foto+"&thumbnail_path_video="+thumbnail_path_video+"&checkHuman="+checkHuman+"&captcha="+captcha+"&nocache="+aleatorio;
		ajax.open("POST", "/js/ajax.EnviaRecomendacionAmigo.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				MostrarRespuesta.innerHTML = "<center><img src='/media/img/general/ajax-loader.gif' width='16' height='16' /></center>";
			}
			if (ajax.readyState==4){
					MostrarRespuesta.innerHTML = ajax.responseText;
			}
		}
		ajax.send(params);
		return false;
}

function restaComodin(USER_ID,GAME_ID,NUM_COMODIN)
{
		if(NUM_COMODIN==1){
			var borracomodin = document.getElementById('comodin1');
		}

		if(NUM_COMODIN==3){
			var borracomodin = document.getElementById('comodin3');
		}

		var ajax=nuevoAjax();

	    ajax.open("GET", "/sections/trivial/ajax.trivialGastaComodin.php?user_id="+USER_ID+"&gid="+GAME_ID+"&comodin="+NUM_COMODIN,true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				borracomodin.innerHTML = "";
			}
	    }
	    ajax.send(null);
	    return true;
}

/*******************************************/
/***************REPORTERO*******************/
/*******************************************/

function changeHoverUpload(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="linkUpLeftH";
		myIdLink.className="linkUpH";
		myRightId.className="linkUpRightH";
}

function resetHoverUpload(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="linkUpLeft";
		myIdLink.className="linkUp";
		myRightId.className="linkUpRight";
}

function changeHoverSubNav(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="subNavLeftH";
		myIdLink.className="linkSubNavH";
		myRightId.className="subNavRightH";
}

function resetHoverSubNav(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="subNavLeft";
		myIdLink.className="linkSubNav";
		myRightId.className="subNavRight";
}

function changeHoverSendFriend(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="sendFriendLeftH";
		myIdLink.className="linkSendFriendH";
		myRightId.className="sendFriendRightH";
}

function resetHoverSendFriend(LeftId,IdLink,RightId){
		myLeftId = document.getElementById(LeftId);
		myIdLink = document.getElementById(IdLink);
		myRightId = document.getElementById(RightId);

		myLeftId.className="sendFriendLeft";
		myIdLink.className="linkSendFriend";
		myRightId.className="sendFriendRight";
}

function cambiaPestChamp(invisibleId,visibleId,pestNotSelId,pestSelId,newClassName){
		myInvisibleId = document.getElementById(invisibleId);
		myVisibleId = document.getElementById(visibleId);
		myPestNotSelId = document.getElementById(pestNotSelId);
		myPestSelId = document.getElementById(pestSelId);
		var myContainerBig = document.getElementById('contChampBig');

		myInvisibleId.style.display="none";
		myVisibleId.style.display="block";
		myPestNotSelId.className="notSelectedChamp";
		myPestSelId.className="selectedChamp";
		myContainerBig.className=newClassName;

}

function verifica_reportero_rumor(form) {
 		document.getElementById('bot_upload').disabled='disabled';
		 if(form.reportero_title.value==""){alert("Tu rumor no tiene titular");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(form.reportero_title.value.length>100){alert("El título es demasiado largo");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(!validate_text(form.reportero_title.value)){alert("El título debe contener letras o números");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 form.reportero_body.value = trim(form.reportero_body.value,'');
		 if(form.reportero_body.value.length<100){alert("Debes introducir como mínimo 100 carácteres");form.reportero_body.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(form.imagen.value.length!=0){
		 	if(form.titulo_imagen.value==""){alert("Debes introducir un pie de foto");form.titulo_imagen.focus();
			 	document.getElementById('bot_upload').disabled='';
			 	document.getElementById('bot_caption').innerHTML="Subir foto";
		 	return false;}
		 }
	 return true;

}

function verifica_reportero_noticia(form) {
		document.getElementById('bot_upload').disabled='disabled';
		 if(form.reportero_title.value==""){alert("Tu noticia no tiene titular");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(form.reportero_title.value.length>100){alert("El título es demasiado largo");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(!validate_text(form.reportero_title.value)){alert("El título debe contener letras o números");form.reportero_title.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 form.reportero_body.value = trim(form.reportero_body.value,'');
		 if(form.reportero_body.value.length<100){alert("Debes introducir como mínimo 100 carácteres");form.reportero_body.focus();document.getElementById('bot_upload').disabled='';document.getElementById('bot_caption').innerHTML="Enviar";return false;}
		 if(form.imagen.value.length!=0){
		 	if(form.titulo_imagen.value==""){alert("Debes introducir un pie de foto");form.titulo_imagen.focus();
			 	document.getElementById('bot_upload').disabled="";
			 	document.getElementById('bot_caption').innerHTML="Subir foto";
		 	return false;}
		 }
	 return true;
}

function verifica_reportero_edit(form) {
		 if(form.reportero_title.value==""){alert("Tu noticia o rumor no tiene titular");form.reportero_title.focus();return false;}
		 if(form.reportero_title.value.length>100){alert("El título es demasiado largo");form.reportero_title.focus();return false;}
		 if(!validate_text(form.reportero_title.value)){alert("El título debe contener letras o números");form.reportero_title.focus();return false;}
		 form.reportero_body.value = trim(form.reportero_body.value,'');
		 if(form.reportero_body.value.length<100){alert("Debes introducir como mínimo 100 carácteres");form.reportero_body.focus();return false;}
		 if(form.imagen.value.length!=0){
		 	if(form.titulo_imagen.value==""){alert("Debes introducir un pie de foto");form.titulo_imagen.focus();
		 	document.getElementById('bot_caption').innerHTML="Subir foto";
		 	document.getElementById('bot_upload').disabled="";
		 	return false;}
		 }
	 return true;
}

function verifica_reporteroComment(form) {
		if(form.reportero_comment_body.value==""){alert("Debes introducir algún comentario");form.reportero_comment_body.focus();return false;}
		return true;
}

function DenunciarReportero(REPORTERO_ID)
{
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+REPORTERO_ID).style.display='none';
	document.getElementById('denuncia'+REPORTERO_ID).style.display='block';
	ajax.open("GET", "/sections/reportero/reporteroDenunciarReporteroRun.php?reportero_id="+REPORTERO_ID, true);
	ajax.send(null);
}

function DenunciarReporteroComment(REPORTERO_ID,COMMENT_ID)
{
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia_comment'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia_comment'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/reportero/reporteroDenunciarCommentRun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function DenunciarReporteroFoto(REPORTERO_ID,FOTO_ID)
{
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia_foto'+FOTO_ID).style.display='none';
	document.getElementById('denuncia_foto'+FOTO_ID).style.display='block';
	ajax.open("GET", "/sections/reportero/reporteroDenunciarFotoRun.php?foto_id="+FOTO_ID, true);
	ajax.send(null);
}

function VotarReportero(REPORTERO_ID,VOTO,CMP)
{
		var manos_voto = document.getElementById('principalVotePost');
		var votacion = document.getElementById('reporteroYaVotadoArriba');
		var votacion_hor = document.getElementById('votacion_secundary');
		var mymainResultado = document.getElementById('mainResultado');
	 	var ajax=nuevoAjax();

	 	params="rid="+REPORTERO_ID+"&b="+VOTO;
		ajax.open("POST", "/sections/reportero/reporteroVoteRun.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);

		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				manos_voto.style.display='none';
				votacion_hor.innerHTML = "<img src='/media/img/general/ajax-loader.gif' width='16' height='16' />";
			}

			if (ajax.readyState==4){

				if(CMP==2){
					votacion.style.display="block";
					votacion.innerHTML = ajax.responseText;
					votacion_hor.innerHTML = ajax.responseText;
				}else{
					mymainResultado.innerHTML = ajax.responseText;
					votacion_hor.innerHTML = "<p class='info inline'>Gracias por participar</p>";
					votacion.style.display="block";
					votacion.innerHTML = "<p class='info'>Gracias por participar</p>";
				}
			}
		}
		ajax.send(params);
}

function verRumores(){
	document.getElementById('notiPestReport').className="";
	document.getElementById('linkNotiReport').className="linkGeneral neg";
	document.getElementById('rumorPestReport').className="selected";
	document.getElementById('linkRumorReport').className="itemSelectedNewSubMenu";
	document.getElementById('noticiasContentHome').style.display='none';
	document.getElementById('rumoresContentHome').style.display='block';
	document.getElementById('subeNotiHomeReport').style.display='none';
	document.getElementById('subeRumorHomeReport').style.display='block';
}

function verNoticias(){
	document.getElementById('notiPestReport').className="selected";
	document.getElementById('linkNotiReport').className="itemSelectedNewSubMenu";
	document.getElementById('rumorPestReport').className="";
	document.getElementById('linkRumorReport').className="linkGeneral neg";
	document.getElementById('noticiasContentHome').style.display='block';
	document.getElementById('rumoresContentHome').style.display='none';
	document.getElementById('subeNotiHomeReport').style.display='block';
	document.getElementById('subeRumorHomeReport').style.display='none';
}

function mostrarSubirFoto(){
	document.getElementById('cambiar_foto').style.display='none';
	document.getElementById('mostrar_subir_foto').style.display='block';
}

function verificaMetacrilato(form)
{
	if(form.regalo.value==1){
		 alert("Debes escoger una forma para tu fotografía");
		 form.regalo.focus();
		 return false;
	 }
	 if(form.nombre.value==""){
		 alert("Debes introducir tu nombre");
		 form.nombre.focus();
		 return false;
	 }
	 if(form.email.value==""){
		 alert("Debes introducir tu dirección de e-mail");
		 form.email.focus();
		 return false;
	 }
	 if(form.calle.value==""){
		 alert("Debes introducir la calle donde quieres recibir tu fotoescultura, llavero o reloj");
		 form.calle.focus();
		 return false;
	 }
	 if(!IsNumeric(form.numero.value)  || form.numero.value==""){
		alert("El número debe ser un valor numérico");
		form.numero.focus();
		return false;
	 }
	 if(form.ciudad.value==""){
		 alert("Debes introducir la ciudad donde quieres recibir tu fotoescultura, llavero o reloj");
		 form.ciudad.focus();
		 return false;
	 }
	 if(!IsNumeric(form.codigo_postal.value) || form.codigo_postal.value==""){
		 alert("El código postal debe ser un valor numérico");
		 form.codigo_postal.focus();
		 return false;
	 }
	 return true;
}

function VotarDerbi(){
	var link_descarga = document.getElementById('descargar');
	var link_alta     = document.getElementById('alta');

	link_descarga.style.display="none";
	link_alta.style.display="block";
}

function trivial_ranking(filter,orden)
{
		var ranking=document.getElementById('tabla_ranking');
	    var ajax=nuevoAjax();

	    ajax.open("GET", "/js/ajax.TrivialRanking.php?filter="+filter+"&ord="+orden,true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				ranking.innerHTML = ajax.responseText;
			}
	    }
	    ajax.send(null);
}

function trivial_ranking_completa(filter,orden,pag)
{
		var ranking=document.getElementById('tabla_ranking');
	    var ajax=nuevoAjax();

	    ajax.open("GET", "/js/ajax.TrivialRanking.php?filter="+filter+"&ord="+orden+"&pag="+pag,true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				ranking.innerHTML = ajax.responseText;
			}
	    }
	    ajax.send(null);
}

function verifica_juego_jugadores(form){
	if(form.jugador_1.value==0){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_1.focus();
		 return false;
	 }
	 if(form.jugador_2.value==0){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_2.focus();
		 return false;
	 }
	 if(form.jugador_3.value==0){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_3.focus();
		 return false;
	 }
	 return true;
}

function juego_jugadores_fuera()
{
		var ranking = document.getElementById('tabla_jugadores');
	    var ajax=nuevoAjax();

	    ajax.open("GET", "/sections/juegos/ajax.JugadoresFuera.php",true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				ranking.innerHTML = ajax.responseText;
			}
	    }
	    ajax.send(null);
}

function verifica_juego_jugadores_dentro(form){
	if(form.jugador_in_1.value==""){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_in_1.focus();
		 return false;
	 }
	 if(form.jugador_in_2.value==""){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_in_2.focus();
		 return false;
	 }
	 if(form.jugador_in_3.value==""){
		 alert("Debes elegir 3 jugadores");
		 form.jugador_in_3.focus();
		 return false;
	 }
	 return true;
}

function juego_jugadores_dentro()
{
		var ranking = document.getElementById('tabla_jugadores_dentro');
	    var ajax=nuevoAjax();

	    ajax.open("GET", "/sections/juegos/ajax.JugadoresDentro.php",true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				ranking.innerHTML = ajax.responseText;
			}
	    }
	    ajax.send(null);
}

function showFeeds(){
	document.getElementById('showMoreFeeds').style.display="none";
	document.getElementById('allFeeds').style.display="block";
	document.getElementById('showLessFeeds').style.display="block";
}

function hideFeeds(){
	document.getElementById('showMoreFeeds').style.display="block";
	document.getElementById('allFeeds').style.display="none";
	document.getElementById('showLessFeeds').style.display="none";
}

function showPosts(){
	document.getElementById('showMorePosts').style.display="none";
	document.getElementById('allPosts').style.display="block";
	document.getElementById('showLessPosts').style.display="block";
}

function hidePosts(){
	document.getElementById('showMorePosts').style.display="block";
	document.getElementById('allPosts').style.display="none";
	document.getElementById('showLessPosts').style.display="none";
}

function ponerAvatar(form)
{
	var avatar = document.getElementById('ponerAvatar');
	var ajax=nuevoAjax();

	foto_avatar = form.foto.value;

	params ="av="+foto_avatar;
		ajax.open("POST", "/sections/gallery/ajax.ponerAvatar.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				avatar.innerHTML = "<center><img src='/media/img/general/ajax-loader.gif' width='16' height='16' /></center>";
			}
			if (ajax.readyState==4){
					avatar.innerHTML = ajax.responseText;
			}
		}
		ajax.send(params);

	return false;
}

function cambiarEstadoAnimo(user_id,ESTADO)
{
	var ajax = nuevoAjax();

	document.getElementById('estado_novotado').style.display="none";
	document.getElementById('estado_votado').style.display="block";
	var estado = document.getElementById('estado_votado');

	ajax.open("GET", "/sections/perfil/ajax.cambiarEstadoAnimo.php?user_id="+user_id+"&est="+ESTADO, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4){
				estado.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

// WIKI 2.0

function cambiarArticuloFavorito(page_id,current){
	var spanFavorito = document.getElementById('articuloFavorito');

	var ajax=nuevoAjax();
	ajax.open("GET", "/sections/wiki/wiki-changePageFavorito.php?page_id="+page_id+"&current="+current+"&ms="+new Date().getTime(), true);
	ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1){
				// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."
				spanFavorito.innerHTML = "<img src='/media/img/general/ajax-loader.gif' width='16' height='16' />";
			}
			if (ajax.readyState==4){

				spanFavorito.innerHTML=ajax.responseText;
			}
		}
	ajax.send(null);
}

function crearArticuloWiki(){
	document.getElementById('crearArticulo').style.display="block";
}

// VIVENCIAS CAMPEONATO
function verifica_vivencias(form) {

	 if(form.vivencia_body.value==""){alert("Debes introducir tu vivencia");form.vivencia_body.focus();return false;}

	 var radio = false;
	 for (counter = 0; counter < form.vivencia_hermano.length; counter++){
	 	if(form.vivencia_hermano[counter].checked)	radio = true;
	 }
	 if(!radio){alert("¿Puedes seleccionar uno de los equipos?");return false;}

	 if(form.vivencia_jugador.value==""){alert("¿Podrías introducir un jugador?");form.vivencia_jugador.focus();return false;}
	 if(form.vivencia_sugerencias.value==""){alert("¿Podrías introducir alguna sugerencia?");form.vivencia_sugerencias.focus();return false;}
	 return true;
}

function DenunciarVivencia(VIVENCIA_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+VIVENCIA_ID).style.display='none';
	document.getElementById('denuncia'+VIVENCIA_ID).style.display='block';
	ajax.open("GET", "/sections/vivencias/vivencias-denunciarVivenciasRun.php?vivencia_id="+VIVENCIA_ID, true);
	ajax.send(null);
}

function changeTabMatch(tabSel){
	var pestDivCur = document.getElementById('currentMatch');
	var pestDivNex = document.getElementById('nextMatch');
	var pestDivClas = document.getElementById('clasHome');
	var linkDivCur = document.getElementById('tabsMatch1');
	var linkDivNex = document.getElementById('tabsMatch2');
	var linkDivClas = document.getElementById('tabsMatch3');
	var divCur = document.getElementById('cur');
	var divNex = document.getElementById('nex');
	var divClas = document.getElementById('clas');
	if(tabSel=='currentMatch'){
		pestDivCur.className="matchesBlockSel";
		pestDivNex.className="";
		linkDivCur.className="selectedTabsMatch";
		linkDivNex.className="linkGeneralU";
		divCur.className="dBlock";
		divNex.className="dNone";
		if(pestDivClas){
			linkDivClas.className="linkGeneralU";
			pestDivClas.className="";
			divClas.className="dNone";
		}
	}else if(tabSel=='nextMatch'){
		pestDivCur.className="";
		pestDivNex.className="matchesBlockSel";
		linkDivCur.className="linkGeneralU";
		linkDivNex.className="selectedTabsMatch";
		divCur.className="dNone";
		divNex.className="dBlock";
		if(pestDivClas){
			linkDivClas.className="linkGeneralU";
			pestDivClas.className="";
			divClas.className="dNone";
		}
	}else{
		pestDivCur.className="";
		pestDivNex.className="";
		linkDivCur.className="linkGeneralU";
		linkDivNex.className="linkGeneralU";
		divCur.className="dNone";
		divNex.className="dNone";
		if(pestDivClas){
			linkDivClas.className="selectedTabsMatch";
			pestDivClas.className="matchesBlockSel";
			divClas.className="dBlock";
		}
	}
}

function validate_text(text){

	text = trim(text,'');

	expr = /([a-zA-Z0-9]){1,}/;

	if (expr.test(text)) {return true;}
  	else {return false;}

}

function showArea(areaID,log){
	if(log==0)birthdaysNeedReg(areaID);die;
	var myAn = document.getElementById('birdth'+areaID);
	myAn.innerHTML='<div class="bgZonaNoDest w250 oHidden"><div class="posAbsCloser"><img class="cPoint" onclick="javascript:closeArea('+areaID+');" src="/media/img/iconos/closeX.gif" /></div><small class="color57 cursiva">* El mensaje se enviará directamente a su ficha</small><textarea class="reliefTxtArea mTop5"></textarea><button class="t5">Enviar</button></div>';
}

function closeArea(areaID){
	var myAn = document.getElementById('birdth'+areaID);
	myAn.innerHTML='<a href="javascript:showArea('+areaID+');" class="linkGeneralU t5">Felicítalo</a>';
}

function changeTabUsers(whichOne){
	var showUsers = document.getElementById('lastUsers');
	var showBirdthdays = document.getElementById('birdthUsers');
	var tab_1 = document.getElementById('tab1');
	var tab_2 = document.getElementById('tab2');

	if(whichOne==2){
		tab_1.innerHTML='<a class="linkGeneralU t5" href="javascript:changeTabUsers(1);">Los nuevos</a>';
		tab_2.innerHTML='<small class="neg">Los cumpleañeros</span>';
		showUsers.className="dNone";
		showBirdthdays.className="dBlock";
	}else{
		tab_1.innerHTML='<small class="neg">Los nuevos</span>';
		tab_2.innerHTML='<a class="linkGeneralU t5" href="javascript:changeTabUsers(2);">Los cumpleañeros</a>';
		showUsers.className="dBlock";
		showBirdthdays.className="dNone";
	}
}


function moreBirthdays(pag,nbirth){
	var birdthUsers = document.getElementById('birdthUsers');

	var ajax=nuevoAjax();
	ajax.open("GET", "/blocks/usuarios/ajax.MoreBirthdays.php?pag="+pag+"&nbirth="+nbirth+"&ms="+new Date().getTime(), true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==1)birdthUsers.innerHTML = "<div class='taCenter padd8'><img src='/media/img/general/ajax-loader.gif' width='16' height='16' /></div>";
			if (ajax.readyState==4)birdthUsers.innerHTML = ajax.responseText;
	}
	ajax.send(null);
}


function birthdaysNeedReg(areaID){
	var showArea = document.getElementById('birdth'+areaID);
	var link_alta     = document.getElementById('alta');

	showArea.style.display="none";
	link_alta.style.display="block";
}

function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat);

	if (matchArray == null) {return false;}

	month = matchArray[1];
	day = matchArray[3];
	year = matchArray[5];

	if (month < 1 || month > 12) {return false;}

	if (day < 1 || day > 31) {return false;}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {return false;}

	if (month == 2) {
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {return false;}
	}
	return true;
}

function dataStaff(){

	var showForm  = document.getElementById('aparecer_staff');
	var staff = document.getElementById('staff');
	var datos = document.getElementById('datos_reales');

	if(staff.checked==true){
		showForm.style.display="block";
	}else{
		showForm.style.display="none";
		datos.style.display="none";
	}

}

function showStaffForm(){

	var showFormFull  = document.getElementById('datos_reales');
	var nick  = document.getElementById('nick');
	var nombre  = document.getElementById('nombre');

	if(nick.checked==true){
		showFormFull.style.display="none";
	}else{
		showFormFull.style.display="block";
	}
}

function verificaColaborar(form){

	colaborar_donde = trim(form.colaborar_donde.value);
	if(form.colaborar_donde.value.length==""){alert("Debes indicarnos en que sección te gustaría colaborar");form.colaborar_donde.focus();return false;}

	var staff  = document.getElementById('staff');

	if(staff.checked==true){

		 var radio = false;
		 var radio_checked;
		 for(counter = 0; counter< form.nick_name.length; counter++){
		 	if(form.nick_name[counter].checked){
		 		radio = true;
		 		radio_checked = form.nick_name[counter].value;
		 	}
		 }
		 if(!radio){alert("¿Qué quieres que aparezca, tu nombre o tu nick?");return false;}

		 if(radio_checked==1){

		 	if(trim(form.colaborar_nombre.value).length==""){alert("Debes indicarnos tu nombre");form.colaborar_nombre.focus();return false;}
		 	if(trim(form.colaborar_apellidos.value).length==""){alert("Debes indicarnos tus apellidos");form.colaborar_apellidos.focus();return false;}
		 	if(form.tu_foto.value.length==0){alert("Debes subir tu foto");return false;}
		 }
	}
}

function howParticipate(){

	var participar  = document.getElementById('participar');

	if(participar.style.display=="block"){
		participar.style.display="none";
	}else{
		participar.style.display="block";
	}
}

function ps3Validate(){
	if(document.fifa2010.jugador_type.value==0){
		alert('Selecciona si quieres ser jugador o jugador/capit�n');
		return false;
	}
	if(document.fifa2010.id_ps3.value.length<3){
		alert('Indica un ID de PS3 v�lido');
		return false;
	}
	document.fifa2010.submit();
}

function derbiApuesta(form){

		var partido = document.getElementById('partido_id').value;
		var ac = form.apuesta_casa.value;
		var af = form.apuesta_fuera.value;

		if(ac==""){alert("¡Apuesta incompleta!");form.apuesta_casa.focus();return false;}
		if(af==""){alert("¡Apuesta incompleta!");form.apuesta_fuera.focus();return false;}

		var apostar = document.getElementById('apostar');

		var ajax=nuevoAjax();

		params="partido_id="+partido+"&apuesta_casa="+ac+"&apuesta_fuera="+af;
		ajax.open("POST", "/sections/eventos/eventosPorrielaRun.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);

		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4){
				apostar.innerHTML = ajax.responseText;
			}
		}
		ajax.send(params);
		return false;
}


function hideHour()
{
		var allday = document.getElementById('alldaycheckbox');
		var eventHour = document.getElementById('date_fin');

		if(allday.checked==true){
			eventHour.style.display="none";
		}else{
			eventHour.style.display="block";
		}
}

function eleccionesVotar(obId){

	var myDiv = document.getElementById('candidato'+obId);
	var ajax=nuevoAjax();

	for(i=0; i<5; i++){
		if(obId!=i){
			document.getElementById('candidato'+i).innerHTML = '<div class="addsElections"><a class="linkFooter neg t1" href="javascript:eleccionesVotar('+i+');">Lo banco</a></div>';
		}
	}
	ajax.open("GET", "/sections/adds/elecciones/ajax.eleccionesVoteRun.php?vote="+obId+"&ms="+new Date().getTime(), true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==1){
			myDiv.innerHTML = "<div class='addsElectionsNot'><img src='/media/img/general/ajax-loader.gif' width='16' height='16' /></div>";
		}
		if (ajax.readyState==4){

			myDiv.innerHTML = ajax.responseText;
		}
	}
	ajax.send(null);
}

function cavaSendOrder(Objform){
	if(!Objform.cv_nombrepers.value.length ||
	!Objform.cv_frasepers.value.length ||
	!Objform.cv_nombre.value.length ||
	!Objform.cv_apellidos.value.length ||
	!Objform.cv_telefono.value.length ||
	!Objform.cv_email.value.length ||
	!Objform.cv_direccion.value.length ||
	!Objform.cv_codigopostal.value.length ||
	!Objform.cv_ciudad.value.length ||
	!Objform.cv_provincia.value.length ){
		alert('Debes rellenar todos los campos');
		return false;
	}
	return true;
}

function datePast(input){

	var date = input.split('-');
	var dia = date[2].split(' ');
	var hora = dia[1].split(':');
	var miFecha = new Date(date[0],date[1]-1,dia[0],hora[0],hora[1]);

	var today = new Date();
	var dia_actual = today.getDate();
	var mes_actual = today.getMonth() + 1;
	var anno_actual = today.getFullYear();
	var hora_actual = today.getHours();
	var min_actual = today.getMinutes();
	var fecha = new Date(anno_actual,mes_actual-1,dia_actual,hora_actual,min_actual);

	if(miFecha<fecha)return false;
	else return true;
}

function validateEvent(Objform){

	event_date_ini_f = Objform.event_date_ini.value+" "+Objform.event_date_ini_h.value;
	event_date_fin_f = Objform.event_date_fin.value+" "+Objform.event_date_fin_h.value;
	event_title = trim(Objform.event_titulo.value);
	if(event_title.length==""){alert("Debes introducir un título");Objform.event_titulo.focus();return false;}
	if(event_title.length>60){alert("El título es demasiado largo");Objform.event_titulo.focus();return false;}
	if(!validate_text(event_title)){alert("El título debe contener letras o números");Objform.event_titulo.focus();return false;}

	if(Objform.event_date_ini.value==""){alert("Debes indicar una fecha de inicio");return false;}
	if(Objform.alldaycheckbox.checked==false){
		if(Objform.event_date_fin.value==""){alert("Debes indicar una fecha de fin");return false;}
	}
	if(!datePast(event_date_ini_f)){alert("La fecha de inicio no puede ser anterior a la actual");return false;}
	if(!datePast(event_date_fin_f)){alert("La fecha de fin no puede ser anterior a la actual");return false;}
	if(event_date_fin_f<event_date_ini_f){alert("La fecha de fin no puede ser anterior a la de inicio");return false;}
	
	event_body = trim(Objform.event_descripcion.value,'');
	if(event_body.length==""){alert("¿Podrías describir de qué trata el evento?");Objform.event_descripcion.focus();return false;}
	if(Objform.imagen.value.length==0){alert("Debes especificar la imagen");return false;}
	return true;
}

function validateEventMod(Objform){

	event_title = trim(Objform.event_titulo.value);
	if(event_title.length==""){alert("Debes introducir un título");Objform.event_titulo.focus();return false;}
	if(event_title.length>100){alert("El título es demasiado largo");Objform.event_titulo.focus();return false;}
	if(!validate_text(event_title)){alert("El título debe contener letras o números");Objform.event_titulo.focus();return false;}

	event_body = trim(Objform.event_descripcion.value,'');
	if(event_body.length==""){alert("¿Podrías describir de qué trata el evento?");Objform.event_descripcion.focus();return false;}
	return true;
}


function denunciarCommentEvent(EVENT_ID,COMMENT_ID){
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia_comment'+COMMENT_ID).style.display='none';
	document.getElementById('denuncia_comment'+COMMENT_ID).style.display='block';
	ajax.open("GET", "/sections/events/eventsDenunciarCommentRun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function goEvent(EVENT_ID,VOY)
{
		var asist1 = document.getElementById('asist1');
		var asist2 = document.getElementById('asist2');
		var asist0 = document.getElementById('asist0');
		var asistentes = document.getElementById('asistentes');
		var votacion = document.getElementById('votacion');

	 	var ajax=nuevoAjax();

	 	params="evid="+EVENT_ID+"&b="+VOY;
		ajax.open("POST", "/sections/events/ajax.eventsGoEventRun.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);

		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4){
				if(VOY==1){
					asist1.className="btnAsistenciaSelect";
					asist2.className="btnAsistencia";
					asist0.className="btnAsistencia";
				}
				if(VOY==2){
					asist1.className="btnAsistencia";
					asist2.className="btnAsistenciaSelect";
					asist0.className="btnAsistencia";
				}
				if(VOY==0){
					asist1.className="btnAsistencia";
					asist2.className="btnAsistencia";
					asist0.className="btnAsistenciaSelect";
				}
				var respuestaAjax = ajax.responseText;
				var buscaInfo = respuestaAjax.indexOf("<p class='info'>");
				if(buscaInfo == -1){
					asistentes.innerHTML = respuestaAjax;
				}else{
					votacion.innerHTML = respuestaAjax;
				}
			}
		}
		ajax.send(params);
}

function goEventPartido(EVENT_ID,VOY,PARTIDO_ID)
{
		var asist1 = document.getElementById('asist1');
		var asist2 = document.getElementById('asist2');
		var asist0 = document.getElementById('asist0');
		var asistentes = document.getElementById('asistentes');
		var votacion = document.getElementById('votacion');

	 	var ajax=nuevoAjax();

	 	params="evid="+EVENT_ID+"&b="+VOY+"&parId="+PARTIDO_ID;
		ajax.open("POST", "/sections/events/ajax.eventsGoEventPartidoRun.php", true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", params.length);

		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==4){
				if(VOY==1){
					asist1.className="btnAsistenciaSelect";
					asist2.className="btnAsistencia";
					asist0.className="btnAsistencia";
				}
				if(VOY==2){
					asist1.className="btnAsistencia";
					asist2.className="btnAsistenciaSelect";
					asist0.className="btnAsistencia";
				}
				if(VOY==0){
					asist1.className="btnAsistencia";
					asist2.className="btnAsistencia";
					asist0.className="btnAsistenciaSelect";
				}
				var respuestaAjax = ajax.responseText;
				var buscaInfo = respuestaAjax.indexOf("<p class='info'>");
				if(buscaInfo == -1){
					asistentes.innerHTML = respuestaAjax;
				}else{
					votacion.innerHTML = respuestaAjax;
				}
			}
		}
		ajax.send(params);
}


function lotSendOrder(Objform){
	if(!Objform.lot_nombre.value.length ||
	!Objform.lot_apellidos.value.length ||
	!Objform.lot_telefono.value.length ||
	!Objform.lot_email.value.length ||
	!Objform.lot_codigosms.value.length ||
	!Objform.lot_direccion.value.length ||
	!Objform.lot_codigopostal.value.length ||
	!Objform.lot_ciudad.value.length ||
	!Objform.lot_provincia.value.length ){
		alert('Debes rellenar todos los campos');
		return false;
	}
	return true;
}

function champAfricaSend(Objform){
	if(!Objform.ch_nombre.value.length ||
	!Objform.ch_apellidos.value.length ||
	!Objform.ch_localidad.value.length ||
	!Objform.ch_email.value.length ||
	!Objform.ch_telefono.value.length ||
	trim(Objform.ch_comentarios.value) == ""){
		alert('Debes rellenar todos los campos');
		return false;
	}
	return true;
}

function mbusSendOrder(Objform){
	if(!Objform.add_nombre.value.length ||
	!Objform.add_apellidos.value.length ||
	!Objform.add_telefono.value.length ||
	!Objform.add_email.value.length ||
	!Objform.add_num.value.length ){
		alert('Debes rellenar todos los campos');
		return false;
	}
	return true;
}

function formGallery(){

	$("#myFormC").slideToggle("slow");

}

function uploadConcurso(Objform){

	if(Objform.foto_nombre.value.length==0){alert("Debes introducir un título para la imagen"); return false;}
	if(!validate_text(Objform.foto_nombre.value)){alert("El título debe contener letras o números"); return false;}
	if(Objform.imagen.value.length==0){alert("Debes especificar la imagen"); return false;}
	return true;
}

function insertEmotion(file_name, title) {
	//title = tinyMCE.getLang(title);

	if (title == null)
		title = "";

	// XML encode
	title = title.replace(/&/g, '&amp;');
	title = title.replace(/\"/g, '&quot;');
	title = title.replace(/</g, '&lt;');
	title = title.replace(/>/g, '&gt;');

	//alert(file_name);
	//var html = '<img src="' + tinyMCE.baseURL + "/plugins/emotions/images/" + file_name + '" mce_src="' + tinyMCE.baseURL + "/plugins/emotions/images/" + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';
//	var html = '<img src="/js/plugins/emotions/images/' + file_name + '" mce_src="js/plugins/emotions/images/"' + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';
	var html = '<img src="' + file_name + '" mce_src="' + file_name + '" border="0" alt="' + title + '" title="' + title + '" />';
//	alert(tinyMCE.baseURL);
	tinyMCE.execCommand('mceInsertContent', false, html);
	//tinyMCEPopup.close();
}

function verificaEventComment(form) {
		if(form.event_comment_body.value==""){alert("Debes introducir algún comentario");form.event_comment_body.focus();return false;}
		return true;
}


function deleteCommentEvent(EVENT_ID,EVENT_COMMENT_ID){
	if(confirm("¿Estás seguro de eliminar este comentario?"))
		{
			location.href="/sections/events/eventsDelComment.php?event_id="+EVENT_ID+"&event_comment_id="+EVENT_COMMENT_ID;
		}
}
