url_web = "http://www.infoconsolas.com";

function clickMeGusta(log, idpost, idusuario, accion) {
	url_action = url_web + "/wp-admin/admin-ajax.php";
	
	if (accion == "delete2")
	{	
		jQuery.post( url_action,  { action:"no_me_gusta",post:document.getElementById("me-gusta-form-post").value, usuario:document.getElementById("me-gusta-form-usuario").value, tipo:document.getElementById("me-gusta-form-tipo").value } ,function(data){
		});
	}
	else if(accion == "add2")
	{
		if (log == 1)
		{
			document.getElementById("me-gusta-infocon").disabled = true;
			document.getElementById("me-gusta-infocon").style.backgroundImage = "url("+url_web+"/wp-content/themes/infocon/images/me-gusta-ok.png)";
			document.getElementById("me-gusta-infocon").style.cursor = "default";
			url_action = url_web + "/wp-admin/admin-ajax.php";
			jQuery.post( url_action,  { action:"me_gusta",post:document.getElementById("me-gusta-form-post").value, usuario:document.getElementById("me-gusta-form-usuario").value, tipo:document.getElementById("me-gusta-form-tipo").value } ,function(data){
			});
		}
		else
		{
			document.getElementById('error_log_fav').innerHTML='Debes identificarte antes.';
			document.getElementById('error_log_fav').className='error_logueo_favoritos';
		}
	}
}

function clickNoMeGusta(idpost, idusuario) {
	url_action = url_web + "/wp-admin/admin-ajax.php";
	jQuery.post( url_action,  { action:"patata",post:idpost, usuario:idusuario} ,function(data){
	});
}

function clickColAdd(objeto, indice) {

	if(objeto == "consola")
	{
		if(document.getElementById("activo" + indice).value == 0)
		{
			document.getElementById("edit-consola-ok" + indice).style.width = "16px";
			document.getElementById("edit-consola-ok" + indice).style.height = "16px";
			document.getElementById("edit-consola-ok" + indice).style.position = "absolute";
			document.getElementById("edit-consola-ok" + indice).style.left = "70px";
			document.getElementById("edit-consola-ok" + indice).style.top = "100px";
			document.getElementById("edit-consola-ok" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/ok.png";
			document.getElementById("activo" + indice).value = 1;
		}
		else
		{
			document.getElementById("edit-consola-ok" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/vacio.png";
			document.getElementById("activo" + indice).value = 0;
			document.getElementById("caja" + indice).value = 0;
			document.getElementById("imagencaja" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/caja.png";
			document.getElementById("manual" + indice).value = 0;
			document.getElementById("imagenmanual" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/manual.png";
		}
	}
	else if(objeto == "caja")
	{
		if(document.getElementById("activo" + indice).value == 0)
		{
			
		}
		else
		{
			if(document.getElementById("caja" + indice).value == 0)
			{
				document.getElementById("imagencaja" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/caja_ok.png";
				document.getElementById("caja" + indice).value = 1;
			}
			else
			{
				document.getElementById("imagencaja" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/caja.png";
				document.getElementById("caja" + indice).value = 0;
			}
		}
	}
	else if(objeto == "manual")
	{
		if(document.getElementById("activo" + indice).value == 0)
		{
			
		}
		else
		{
			if(document.getElementById("manual" + indice).value == 0)
			{
				document.getElementById("imagenmanual" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/manual_ok.png";
				document.getElementById("manual" + indice).value = 1;
			}
			else
			{
				document.getElementById("imagenmanual" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/manual.png";
				document.getElementById("manual" + indice).value = 0;
			}
		}
	}
}

function clickColDelete(objeto, indice) {

	if(objeto == "consola")
	{
		if(document.getElementById("activo" + indice).value == 0)
		{
			document.getElementById("edit-consola-ok" + indice).style.width = "16px";
			document.getElementById("edit-consola-ok" + indice).style.height = "16px";
			document.getElementById("edit-consola-ok" + indice).style.position = "absolute";
			document.getElementById("edit-consola-ok" + indice).style.left = "70px";
			document.getElementById("edit-consola-ok" + indice).style.top = "100px";
			document.getElementById("edit-consola-ok" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/cross.png";
			document.getElementById("activo" + indice).value = 1;
		}
		else
		{
			document.getElementById("edit-consola-ok" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/vacio.png";
			document.getElementById("activo" + indice).value = 0;
			document.getElementById("caja" + indice).value = 0;
		}
	}
}

function clickJuegoAdd(objeto, indice) {

	if(objeto == "caja")
	{
		if(document.getElementById("caja" + indice).value == 0)
		{
			document.getElementById("imagencaja" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/caja_ok.png";
			document.getElementById("caja" + indice).value = 1;
		}
		else
		{
			document.getElementById("imagencaja" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/caja.png";
			document.getElementById("caja" + indice).value = 0;
		}
	}
	else if(objeto == "manual")
	{
		if(document.getElementById("manual" + indice).value == 0)
		{
			document.getElementById("imagenmanual" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/manual_ok.png";
			document.getElementById("manual" + indice).value = 1;
		}
		else
		{
			document.getElementById("imagenmanual" + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/manual.png";
			document.getElementById("manual" + indice).value = 0;
		}
	}
}

function estrella(accion, num, indice) {
	if(accion == 0)
	{
		rate = document.getElementById("rate" + indice).value;
		for(i=1; i<=5; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star_bn.png";
		}
		for(i=1; i<=rate; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star.png";
		}
	}
	else if(accion == 1)
	{
		for(i=1; i<=5; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star_bn.png";
		}
		for(i=1; i<=num; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star.png";
		}
	}
	else if(accion == 2)
	{
		for(i=1; i<=5; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star_bn.png";
		}
		for(i=1; i<=num; i++)
		{
			document.getElementById("star" + i + indice).src = url_web + "/wp-content/themes/infocon/images/colecciones/star.png";
		}
		document.getElementById("rate" + indice).value = num;
	}
}

function addCampoJuego(ind)
{
	ind = jQuery('#total-juegos-add').val();
	ind++;
	jQuery("#col-juegos-content").append('<div class="col-juego-single" id="col-juego-single'+ind+'"><div class="col-juegos-nombre-edit"><input class="col-juegos-nombre-edit" maxlength="70" type="text" value="" name="nombre'+ind+'" id="nombre'+ind+'"></div><div class="col-juegos-complementos-edit"><div class="col-juegos-caja-edit"><img class="juego-caja" title="Caja" id="imagencaja'+ind+'" onclick="clickJuegoAdd(\'caja\', '+ind+')" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/caja.png"></div><div class="col-juegos-manual-edit"><img class="juego-manual" title="Manual" id="imagenmanual'+ind+'" onclick="clickJuegoAdd(\'manual\', '+ind+')" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/manual.png"></div></div><div class="col-juegos-valoracion-edit"><img onclick="estrella(2, 1, '+ind+')" onmouseover="estrella(1, 1, '+ind+')" onmouseout="estrella(0, 1, '+ind+')" title="1" id="star1'+ind+'" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/star.png"><img onclick="estrella(2, 2, '+ind+')" onmouseover="estrella(1, 2, '+ind+')" onmouseout="estrella(0, 2, '+ind+')" title="2" id="star2'+ind+'" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/star.png"><img onclick="estrella(2, 3, '+ind+')" onmouseover="estrella(1, 3, '+ind+')" onmouseout="estrella(0, 3, '+ind+')" title="3" id="star3'+ind+'" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/star.png"><img onclick="estrella(2, 4, '+ind+')" onmouseover="estrella(1, 4, '+ind+')" onmouseout="estrella(0, 4, '+ind+')" title="4" id="star4'+ind+'" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/star_bn.png"><img onclick="estrella(2, 5, '+ind+')" onmouseover="estrella(1, 5, '+ind+')" onmouseout="estrella(0, 5, '+ind+')" title="5" id="star5'+ind+'" src="'+url_web+'/wp-content/themes/infocon/images/colecciones/star_bn.png"></div><div class="col-juegos-fecha-edit">Hoy</div><input type="hidden" name="caja'+ind+'" id="caja'+ind+'" value="0" /><input type="hidden" name="manual'+ind+'" id="manual'+ind+'" value="0" /><input type="hidden" name="rate'+ind+'" id="rate'+ind+'" value="3" /></div>');
	document.getElementById("total-juegos-add").value = ind;
} 

function delCampoJuego()
{
	ind = jQuery('#total-juegos-add').val();
	if(ind != 0)
	{
		jQuery("#col-juego-single" + ind).remove();
		ind--;
		document.getElementById("total-juegos-add").value = ind;
	}
}

function submitJuegosAdd()
{
	jQuery("#formulario-juegos-add").submit();
}

function validacionJuegosAdd()
{
	ind = jQuery('#total-juegos-add').val();
	for(i=0; i<=ind; i++)
	{
		if(jQuery('#nombre' + i).val() == "")
		{
			alert("Faltan campos por completar");
			return false;
		}
	}
	return true;
}

function colDescripcionAdd(i)
{
	if(i == 0)
	{
		jQuery("#col-descripcion").append('<div class="col-descripcion-edit" id="col-descripcion-edit"><form method="POST" style="margin: 0px;" onSubmit="return validacionJuegosAdd()" id="formulario-juegos-add" enctype="multipart/form-data"><textarea rows="10" name="col-input-descripcion" maxlength="1600" id="col-input-descripcion"></textarea><input type="submit" class="col-descripcion-submit" name="descripcion" id="col-boton-descripcion-add" value="Enviar"></form></div>');
	}
	else if (i == 1)
	{
		desc = jQuery('#col-descripcion').html();
		strip_desc = desc.replace(/(<([^>]+)>)/ig,"");
		jQuery("#col-boton-descripcion-add").remove();
		jQuery("#col-descripcion").append('<div class="col-descripcion-edit" id="col-descripcion-edit"><form method="POST" style="margin: 0px;" onSubmit="return validacionJuegosAdd()" id="formulario-juegos-add" enctype="multipart/form-data"><textarea rows="10" name="col-input-descripcion" maxlength="1600" id="col-input-descripcion">'+strip_desc+'</textarea><input type="submit" class="col-descripcion-submit" name="descripcion" id="col-boton-descripcion-add" value="Enviar"></form></div>');
	}
}

function colCruzDelJuego(ind, act) {
	if(act == 0)
	{
		document.getElementById("col-juegos-boton-borrar" + ind).src = url_web + "/wp-content/themes/infocon/images/colecciones/cross.png";
	}
	else if(act == 1)
	{
		if(document.getElementById("del-juego" + ind).value == 0)
		{
			document.getElementById("col-juegos-boton-borrar" + ind).src = url_web + "/wp-content/themes/infocon/images/colecciones/cross_bn.png";
		}
	}
	else if(act == 2)
	{
		if(document.getElementById("del-juego" + ind).value == 1)
		{
			document.getElementById("col-juegos-boton-borrar" + ind).src = url_web + "/wp-content/themes/infocon/images/colecciones/cross_bn.png";
			document.getElementById("del-juego" + ind).value = 0;
		}
		else if(document.getElementById("del-juego" + ind).value == 0)
		{
			document.getElementById("col-juegos-boton-borrar" + ind).src = url_web + "/wp-content/themes/infocon/images/colecciones/cross.png";
			document.getElementById("del-juego" + ind).value = 1;
		}
	}
}

function colValidacionEliminarJuegos() {
	ind = jQuery('#total-juegos').val();
	for(i=0; i<=ind; i++)
	{
		if(jQuery('#del-juego' + i).val() == 1)
		{
			return true;
		}
	}
	alert("No has seleccionado juegos para eliminar");
	return false;
}

function cambioImagen(id, imagen) {
	document.getElementById(id).src = url_web + "/wp-content/themes/infocon/images/colecciones/"+imagen;
}

function submitForm(form) {
	document.forms[form].submit();
}

function cambiarColor(id, color) {
	document.getElementById(id).style.color = color;
}

function cambiarColorFondo(clase, color) {
	clase.style.backgroundColor = color;
}

function confirmar(mensaje) {
	return confirm(mensaje);
}

