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;
}

function verificaComment(myform){

	if(myform.user_name.value.length < 3){
		alert("Introduce tu nombre");
		return false;
	}

	if(!is_mail(myform.user_email.value)){
		alert("El correo electrónico no es correcto");
		return false;
	}

	if(myform.comment_body.value.length==0){
		alert("Introduce el comentario");
		return false;
	}
	return true;
}

function showHideElement(myId){
	var myElement = document.getElementById(myId);

	if(myElement.style.display=='block') myElement.style.display = 'none';
	else myElement.style.display = 'block';
}

function desplegar(myId,myLink){
	var myElement = document.getElementById(myId);
	if(myLink!=''){
		var myLink = document.getElementById(myLink);
		myLink.style.display='none';
	}
	myElement.style.height = 'auto';
}

function verificaUserData(myform){
	if(myform.user_name.value.length < 3){
		alert("Introduce tu nombre");
		return false;
	}

	if(!is_mail(myform.user_email.value)){
		alert("El correo electrónico no es correcto");
		return false;
	}
}

function verifyNewUser()
{
	vuser_real_name = document.formulario.user_real_name.value;
	vuser_name 		= document.formulario.user_name.value;
	vuser_pass_conf = document.formulario.user_pass_conf.value;
	vuser_password 	= document.formulario.user_password.value;
	vuser_email 	= document.formulario.user_email.value;

	vmes = document.formulario.mes.value;
	vdia = document.formulario.dia.value;
	vano = document.formulario.ano.value;

	vconformidad = document.formulario.conformidad.checked;

	vpaises = document.formulario.paises.value;
	vprovincia = document.formulario.provincias.value;

	document.formulario.jsenabled.value="Y";
	if(vuser_real_name.length<3){
		messageError('Nombre incorrecto.','mensajes-userrealname');
		document.formulario.user_real_name.focus();
		return false;
	}else{
		messageErrorClear('mensajes-userrealname');
	}

	if(verifyUserNameAvailable(vuser_name)==false){
		document.formulario.user_name.focus();
		return false;
	}

	if(comprobar(vuser_name,'txt',3,14)==false){
		messageError('El nombre de usuario debe tener entre 3 y 14 caracteres.','mensajes-username');
		document.formulario.user_name.focus();
		return false;
	}else{
		messageErrorClear('mensajes-username');
	}

	if(comprobar(vuser_password,'txt',3,14)==false){
		messageError('La contraseña debe tener entre 3 y 14 caracteres (letras y números).','mensajes-userpass');
		document.formulario.user_password.focus();
		return false;
	}else{
		messageErrorClear('mensajes-userpass');
	}

	if(vuser_pass_conf!=vuser_password){
		messageError('Las contraseñas no coinciden.','mensajes-userpassconf');
		document.formulario.user_pass_conf.focus();
		return false;
	}else{
		messageErrorClear('mensajes-userpassconf');
	}

	if(vpaises==-1){
		messageError('Selecciona País','mensajes-pais');
		document.formulario.paises.focus();
		return false;
	}else{
		messageErrorClear('mensajes-pais');
	}

	if(vprovincia==-1){
		messageError('Selecciona Provincia','mensajes-provincia');
		document.formulario.paises.focus();
		return false;
	}else{
		messageErrorClear('mensajes-provincia');
	}

	if(verifyUserEmail(vuser_email)==false){
		document.formulario.user_email.focus();
		return false;
	}

	if(comprobar(vuser_email,'mail',6,255)==false){
		messageError('Introduce una cuenta de e-mail correcta en la que recibiras el e-mail de validación.','mensajes-email');
		document.formulario.user_email.focus();
		return false;
	}else{
		messageErrorClear('mensajes-email');
	}

	if(vmes==0 || vdia==0 || vano==0){
		messageError('Completa la fecha de nacimiento.','mensajes-fecha');
		document.formulario.dia.focus();
		return false;
	}else{
		messageErrorClear('mensajes-fecha');
	}

	if(vconformidad==false){
		messageError('Debes aceptar las condiciones de uso','mensajes-condiciones');
		document.formulario.conformidad.focus();
		return false;
	}else{
		messageErrorClear('mensajes-condiciones');
	}

	return true;
}

function verifyUserNameAvailable(user_name){
	var cu=nuevoAjax();
	params = "user_name="+user_name;

	cu.open("POST", "/sections/perfil/ajax.comprobacionUserName.php", false);
	cu.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	cu.setRequestHeader("Content-length", params.length);
	cu.send(params);

	if(cu.responseText!="OK"){
		messageError(cu.responseText,'mensajes-username');
		return false;
	}else {
		return true;
	}
}

function verifyUserEmail(user_email){

	var cu=nuevoAjax();
	params = "user_email="+user_email;

	cu.open("POST", "/sections/perfil/ajax.comprobacionEmail.php", false);
	cu.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	cu.setRequestHeader("Content-length", params.length);
	cu.send(params);

	if(cu.responseText!="OK"){
		messageError(cu.responseText,'mensajes-email');
		return false;
	}else {
		return true;
	}

}

function messageError(text,divInfo){
	document.getElementById(divInfo).style.display='inline';
	document.getElementById(divInfo).innerHTML=text;
}


function messageErrorClear(divInfo){
	document.getElementById(divInfo).innerHTML='';
	document.getElementById(divInfo).style.display='none';
}

function cargaProvincias(){
	var selectPaisId 	= document.getElementById('paises');
	paisId = selectPaisId.options[selectPaisId.selectedIndex].value;

	var selectProvincia	= document.getElementById('provinciasCont');
	var ajax=nuevoAjax();

	ajax.open("GET", "/libs/ajax.provincias.php?pais_id="+paisId, true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==1)
		{
			selectProvincia.innerHTML = "Cargando...";
		}
		if (ajax.readyState==4)
		{
			selectProvincia.innerHTML=ajax.responseText;
		}
	}
	ajax.send(null);
}


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,13})$/;
	}
	if(valor=='mail'){
		var comp = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	}
	if (comp.test(texto)){
		return true;
	}else{
		return false;
	}
}
// - USER
function page_comments(pag,sec,user_id,clear_log)
{
		var comments=document.getElementById('comentarios_user');
		var commentsLog=document.getElementById('comentarios_log');

	    var ajax=nuevoAjax();

	    ajax.open("GET", "/sections/perfil/ajax.Comments.php?pag="+pag+"&user_id="+user_id+"&sec="+sec+"&ms="+new Date().getTime(), true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				if(clear_log){
					commentsLog.style.display="none";
				}
				comments.innerHTML = ajax.responseText;
			}
	    }
	    ajax.send(null);

}

function ConfirmDeleteCommentUser(comment_id, user_id, pag)
{
	if(confirm("¿Seguro que quieres borrar este comentario?"))
	{
		var commentsLog=document.getElementById('comentarios_log');
		var ajax=nuevoAjax();
		ajax.open("GET", "/sections/perfil/ajax.eliminarCommentRun.php?comment_id="+comment_id, true);
	    ajax.onreadystatechange=function()
	    {
			if (ajax.readyState==4)
			{
				page_comments(pag,1,user_id,0);
				commentsLog.style.display="block";
				commentsLog.innerHTML = ajax.responseText;
			}
	    }
		ajax.send(null);

		//location.href = "/aficionados/"+user+"/?del_comment=1&comment_id="+comment_id;

	}

}

function DenunciarComentarioPerfil(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/perfil/user-denunciarcommentrun.php?comment_id="+COMMENT_ID, true);
	ajax.send(null);
}

function verificaActualizarDatos(form)
{
	if(form.paises.value=="0"){
		alert("Debes elegir un país");
		return false;
	}
	if(form.provincias.value=="-1"){
		alert("Debes elegir una provincia");
		return false;
	}
	if(form.dia.value=="0"){
		alert("Falta el día de tu nacimiento");
		return false;
	}
	if(form.mes.value=="0"){
		alert("Falta el mes de tu nacimiento");
		return false;
	}
	if(form.ano.value=="0"){
		alert("Falta el año de tu nacimiento");
		return false;
	}
	return true;
}

function DenunciarFotoPerfil(){
	document.getElementById('link_denunciaFoto').style.display='none';
	document.getElementById('denunciaFotoConfirm').style.display='block';
}

function CancelarDenunciarFotoPerfil(){
	document.getElementById('link_denunciaFoto').style.display='block';
	document.getElementById('denunciaFotoConfirm').style.display='none';

}

function DenunciarFotoPerfilRun(USER_ID){
	var ajax=nuevoAjax();
	document.getElementById('denunciaFotoConfirm').style.display='none';
	document.getElementById('denunciaFoto').style.display='block';
	ajax.open("GET", "/sections/perfil/user-denunciarfotorun.php?user_id="+USER_ID, true);
	ajax.send(null);
}

function DenunciarAvatarPerfil(){
	document.getElementById('link_denunciaAvatar').style.display='none';
	document.getElementById('denunciaAvatarConfirm').style.display='block';
}

function CancelarDenunciarAvatarPerfil(){
	document.getElementById('link_denunciaAvatar').style.display='block';
	document.getElementById('denunciaAvatarConfirm').style.display='none';

}

function DenunciarAvatarPerfilRun(USER_ID){
	var ajax=nuevoAjax();
	document.getElementById('denunciaAvatarConfirm').style.display='none';
	document.getElementById('denunciaAvatar').style.display='block';
	ajax.open("GET", "/sections/perfil/user-denunciaravatarrun.php?user_id="+USER_ID, true);
	ajax.send(null);
}


function enviaShout()
{
	var shoutUid=document.getElementById('shout_uid').value;
	var shoutVal=document.getElementById('shout').value;
	var shoutAnt=document.getElementById('lastShout');

	document.getElementById('shout').value="";

	shoutAnt.innerHTML = shoutVal;

	ajax=nuevoAjax();
 	ajax.open("POST", "/sections/perfil/ajax.actualizarShout.php",true);

	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("shout="+shoutVal+"&shout_uid="+shoutUid);

}

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/comments/commentsDenunciarRun.php", false);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("comment_id="+COMMENT_ID+"&url_from="+URL_ORI);
}

function changePassword()
{
	user_pass = document.formulario.user_pass.value;
	userId = document.formulario.userId.value;
	user_pass_conf = document.formulario.user_pass_conf.value;
	user_pass_now = document.formulario.user_pass_now.value;
	var messageOutput = document.getElementById('mensajes');

	if(!comprobar_user_pass(userId,user_pass_now)){
		messageOutput.className="alerta neg";
		messageOutput.innerHTML = 'Contrase&ntilde;a actual incorrecta';
		document.formulario.user_pass_now.focus();
		return false;
	}

	if(!comprobar(user_pass,'txt',3,14)){
		messageOutput.className="alerta neg";
		messageOutput.innerHTML = 'Contrase&ntilde;a nueva incorrecta. Debe tener entre 3 y 14 carácteres. Sólo puede contener letras y números.';
		document.formulario.user_pass.focus();
		return false;
	}

	if(!comprobar(user_pass_conf,'txt',3,14)){
		messageOutput.className="alerta neg";
		messageOutput.innerHTML = 'Contrase&ntilde;a de confirmación incorrecta';
		document.formulario.user_pass_conf.focus();
		return false;
	}
	if(user_pass_conf!=user_pass){
		messageOutput.className="alerta neg";
		document.getElementById('mensajes').innerHTML = 'Las contrase&ntilde;as nuevas no coinciden';
		document.formulario.user_pass_conf.focus();
		return false;
	}

	return true;
}

function comprobar_user_pass(ui,up){
	var cu=nuevoAjax();
	params = "ui="+ui+"&up="+up;

	cu.open("POST", "/sections/perfil/ajax.comprobacionLogin.php", false);
	cu.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	cu.setRequestHeader("Content-length", params.length);
	cu.send(params);

	if(cu.responseText==0){
		return false;
	}else {
		return true;
	}

	/*var comprobacion_user=nuevoAjax();

	comprobacion_user.open("GET", "/js/comprobacionUserName.php?user_name="+user_name+"&ms="+new Date().getTime(), false);

	comprobacion_user.send(null);

	if(comprobacion_user.responseText!="NO"){
		messageError(comprobacion_user.responseText);
		return false;
	}else {
		document.getElementById('mensajes').innerHTML = '&nbsp;';
		return true;
	}*/
	return true;
}

//--------

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()
{
	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(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 {
		//alert(document.contactar.contacto_con.options[document.contactar.contacto_con.selectedIndex].text);
		document.contactar.contacto_subject.value=document.contactar.contacto_con.options[document.contactar.contacto_con.selectedIndex].text;
	}
	return true;
}


function EnviaAmigos(){
	document.getElementById('form-amigos').style.display="block";
	location.href="#amigos";
}

function EnviarFormAmigos()
{
	var ajax=nuevoAjax();
	nvd_from = document.felicita.navidad_from.value;
	nvd_to = document.felicita.navidad_to_email.value;
	nvd_body = document.felicita.navidad_body.value;
	document.getElementById('form-amigos').innerHTML="<img src='/img/general/ajax-loader.gif'> <small>Enviando...</small>";
	ajax.open("POST", "/sections/navidad2007/navidad-run.php", true);
	ajax.onreadystatechange=function()
	{
		document.getElementById('form-amigos').innerHTML="<div class='info'>La postal ha sido enviada a tu/s amigo/s. Gracias por participar</div>";
	}
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	ajax.send("navidad_from="+nvd_from+"&navidad_to_email="+nvd_to+"&navidad_body="+nvd_body);
}




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 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 DenunciarPost(POST_ID)
{
	//var ajax=nuevoAjax();
	//document.getElementById('link_denuncia'+POST_ID).className="";
	document.getElementById('link_denuncia'+POST_ID).style.visibility="hidden";
	document.getElementById('denuncia'+POST_ID).style.display='block';
	//ajax.open("GET", "/sections/foro/foro-denunciarpostrun.php?post_id="+POST_ID, true);
	//ajax.send(null);

}

function CancelarDenunciarPost(POST_ID)
{
	//var ajax=nuevoAjax();
	//document.getElementById('link_denuncia'+POST_ID).className="link_denuncia";
	document.getElementById('link_denuncia'+POST_ID).style.visibility="visible";
	document.getElementById('denuncia'+POST_ID).style.display='none';
	//ajax.open("GET", "/sections/foro/foro-denunciarpostrun.php?post_id="+POST_ID, true);
	//ajax.send(null);

}

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('link_denuncia'+POST_ID).style.visibility="hidden";
		document.getElementById('denuncia'+POST_ID).style.display="none";
		document.getElementById('denuncia_recibida'+POST_ID).style.display="block";
	}

	return false;
//	ajax.open("GET", "/sections/foro/foro-denunciarpostrun.php?post_id="+POST_ID, true);
//	ajax.send(null);

}

function ConfirmDeleteShout(user_id)
{
	if(confirm("?Seguro que quieres eliminar la frase?"))
	{
		var shoutAnt=document.getElementById('lastShout');
		ajax=nuevoAjax();
	 	ajax.open("POST", "/sections/perfil/ajax.eliminarShout.php",false);

		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send("shout_user_id="+user_id);
		shoutAnt.innerHTML = ajax.responseText;
	}

}

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 s?n incorrectos");
 	window.location.href="/";
}

/*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&oacute;:</p><div style='background:;border:1px solid ;padding:4px;'>");

	return "<small style='line-height:20px;'>"+new_string+"</small>";
}




// 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 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="Cargando...";
				selectDestino.appendChild(nuevaOpcion); selectDestino.disabled=true;
			}
			if (ajax.readyState==4)
			{
				selectDestino.parentNode.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)
			{
				// 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="Cargando...";
				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)
		{
			// Mientras carga elimino la opcion "Selecciona Opcion..." y pongo una que dice "Cargando..."

			tagsAlbum.innerHTML="Cargando...";
		}

		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)
{
	// 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.subalbumesVideos.php?select="+idSelectDestino+"&opcion="+opcionSeleccionada+"&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..."
				selectDestino.length=0;
				var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Cargando...";
				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.ubicacion_id.disabled==false)
	{
		if(form.ubicacion_id.value==0)
		{
			alert("?D?nde est? el asiento?");
			form.ubicacion_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_title.disabled==false)
	{
		if(form.abono_title.value=="")
		{
			alert("Pon un t?tulo a tu anuncio");
			form.abono_title.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) {
	 var radio_choice = false;

	 for (counter = 0; counter < form.porque_motivo_id.length; counter++) if (form.porque_motivo_id[counter].checked)	radio_choice = true;
		 if(!radio_choice){alert("Elige tu motivo");return false;}
		 if(form.porque_body.value.length<100){alert("Debes introducir como m?nimo 100 car?cteres");
		 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);
}

/*****************************************/
/*****************ESPIA*******************/
/*****************************************/

function verifica_espia(form) {
		 if(form.espia_title.value==""){alert("Tu noticia no tiene titular");form.espia_title.focus();return false;}
		 if(form.espia_body.value.length<100){alert("Debes introducir como m?nimo 100 car?cteres");form.espia_body.focus();return false;}
		 if(form.espia_fuente.value==""){alert("Tu noticia no tiene fuente");form.espia_fuente.focus();return false;}
	 return true;
}

function DenunciarEspia(ESPIA_ID)
{
	var ajax=nuevoAjax();
	document.getElementById('link_denuncia'+ESPIA_ID).style.display='none';
	document.getElementById('denuncia'+ESPIA_ID).style.display='block';
	ajax.open("GET", "/sections/espia/espia-denunciarespiarun.php?espia_id="+ESPIA_ID, true);
	ajax.send(null);

}

function DenunciarEspiaComment(ESPIA_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/espia/espia-denunciarcommentespiarun.php?comment_id="+COMMENT_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;}
	return true;
}

function cambiar_album(form){
	location.href=""+form.album_id.options[form.album_id.selectedIndex].id+"-igfa-"+form.album_id.options[form.album_id.selectedIndex].value+".htm";
}

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 verifica_delete_video(form) {
	 if(form.motivo_texto.value==""){alert("Debes indicar el motivo por el que deseas eliminar el v?deo");form.motivo_texto.focus();return false;}
	 return true;
}

function verifica_delete_admin(form) {
	 var radio_choice = false;

	 for (counter = 0; counter < form.motivo_asunto.length; counter++)
	 {
	 	if(form.motivo_asunto[counter].checked)	radio_choice = true;
	 }

	 if(!radio_choice){alert("Indica el motivo");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;}
	return true;
}

/*****************************************/
/*****************IDOLO*******************/
/*****************************************/

function verifica_idolo(form) {

 if(form.idolo_name.value==""){alert("Elige a tu ?dolo");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=="0" && form.rival2.value==""){alert("?Cu?l fu? el rival?");return false;}
	 if(form.memorable_titulo.value==""){alert("Pon un t?tulo a tu partido memorable");return false;}
	 if(form.memorable_body.value.length<100){alert("Debes introducir como m?nimo 100 car?cteres");form.memorable_body.focus();return false;}
	 if(form.rival1.value=="0") form.memorable_rival.value = form.rival2.value;
	 else form.memorable_rival.value = form.rival1.value;
	 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;}
		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 verifica_mover(form) {
		if(form.foro_id.value ==-1){alert("Elige un foro");return false;}
	return true;
}

function verifica_mover_foto(form) {
		if(form.album_id.value ==0){alert("Debes seleccionar un álbum de destino");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 emails 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 VideosActionCookie(action)
{
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie="a_ivi = " + action + "; expires = "+ cookie_date.toGMTString();
}


function VideosAlbumCookie(album_id)
{
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie="a_id_ivi = " + album_id + "; expires = "+ cookie_date.toGMTString();
}

function FotosActionCookie(action,pos)
{
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie="a_igf = " + action + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString();
	document.cookie="p_igf = " + pos + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString();
}

function baseDomainString(){
  e = document.domain.split(/\./);
  if(e.length > 1) {
    return("domain=." + e[e.length-2] + "." +  e[e.length-1]) + ";"  ;
  }else{
    return("");
  }
}

function FotosSearchCookie(vb,pos)
{
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie="vb_id_igf = " + vb + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString();
	document.cookie="p_igf = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString();
}

function FotosAlbumCookie(album_id,pos)
{
	var cookie_date = new Date();
	cookie_date.setTime ( cookie_date.getTime() + 360000000 );
	document.cookie="a_id_igf = " + album_id + ";" + baseDomainString() + "  expires = "+ cookie_date.toGMTString();
	document.cookie="p_igf = " + pos + ";" + baseDomainString() + "   expires = "+ cookie_date.toGMTString();
}

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 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='/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='/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='/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 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";
	}

	my_menu.className="linkMenuSelected";
	my_submenu.style.display="block";
}

function hideMenu(menuVal){
	var my_submenu = document.getElementById('iSubMenu'+menuVal);
	var Items = document.getElementsByName('Wal');

	for (counter = 0; counter < Items.length; counter++){
		 Items[counter].className="linkMenu";
	}

	my_submenu.style.display="none";
}

/*****************************************/
/***************TRIVIAL*******************/
/*****************************************/

function verificaRespuestaTrivial(IDRespuesta)
{
	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;
           }
        }
           alert("Debes seleccionar una respuesta");
           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 al menos 2 respuestas");form.resp1.focus();return false;}
	 if(form.resp2.value==""){alert("Debes introducir al menos 2 respuestas");return false;}
	 if(document.getElementById("resp3").style.display=="block"){if(form.resp3.value==""){alert("Debes introducir la respuesta 3");return false;}}
	 radio = form.resp_ok;
        for (i=0;i<radio.length;i++){
           if (radio[i].checked){
              n=radio[i].value;
              return true;
           }
        }
           alert("Debes marcar la respuesta correcta");
           return false;
}

function verifyJs(formName)
{
	formName.jsenabled.value="Y";
}

function denunciarPregunta()
{
	document.getElementById('link_denuncia').style.display="none";
	document.getElementById('denuncia').style.display='block';
}

function denunciarPreguntaRun(PREGUNTA_ID)
{
	var ajax=nuevoAjax();

	if(document.forms['FormDenuncia'].denuncia_motivo_texto.value==""){
		alert("Por favor, indica un motivo");
	}else{
		motivo = document.forms['FormDenuncia'].denuncia_motivo_texto.value;
	}

		ajax.open("GET", "/sections/trivial/trivialDenunciarPreguntaRun.php?pregunta_id="+PREGUNTA_ID+"&motivo="+motivo, true);
		ajax.send(null);

		document.getElementById('denuncia').style.display="none";
		document.getElementById('denuncia_recibida').style.display="block";

	return false;
}

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 BajaUsuario(UserID,UserName){
	if(confirm("¿Seguro que quieres darte de baja de la web?"))
	{
		location.href="/sections/perfil/user-baja.php?user_id="+UserID+"&user_name="+UserName;
	}
}

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 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;
}