// JavaScript Document

var ultimaActualizacion = "05/09/2010";

var KeyID = 0;
document.onkeydown = KeyCheck;
document.onkeyup = KeyUp;
var botonID = 0;

//
// muestra pie de página
//
function piePagina()
{
	var date = new Date();
	var text = "<div class='PiePagina sep'>"
		+ "<p>"
	 	+ "Última actualización " + ultimaActualizacion + "<br />"
	 	+ "www.la-primitiva.org &copy;  2009 - " + date.getFullYear() //+ " Todos los derechos reservados" 
		+ " | <a class='sinestilo' target='_blank' href='http://www.radimedia.com/gaming/aviso_legal.php?id=f4da5414-1c39-43e7-9193-9581dee487a8'>Aviso legal</a>"
		+ " | <a class='sinestilo' target='_blank' href='http://www.radimedia.com/gaming/condiciones_generales_de_uso.php?id=f4da5414-1c39-43e7-9193-9581dee487a8'>Condiciones generales de uso</a>"
	 	//+ "<br /><br />"
	 	//+ "<a rel='nofollow' href='http://www.copyscape.com/'><img src='http://banners.copyscape.com/images/cs-wh-234x16.gif' title='No copiar el contenido de esta página. El plagio será detectado por Copyscape.' width='234' height='16' border='0' /></a>"
		+ "</p>"
	 	+ "</div>";
	
	document.write(text);
}

function piePaginaImagenes()
{
	var text = "<div class='PiePagina sep3 imagenes' style='padding: 10px'>";

	var url = getURL();
	if (url == "index.html" || url == "")
	{		
		text = text + "<a href='http://www.qweb.es/_juegos-de-azar.html' target='_blank' title='Directorio de Juegos de azar'>"
			+ "<img src='http://www.qweb.es/certqweb-www.la-primitiva.org.gif' width='97' height='31' border='0' alt='Directorio de Juegos de azar' /></a>";
	}
	
	text = text
		//+ "<a class='sinestilo' href='http://validator.w3.org/check?uri=referer' target='_blank'><img src='http://www.w3.org/Icons/valid-xhtml10-blue' alt='Valid XHTML 1.0 Transitional' height='31' width='88' border='0'/></a>"
		+ "<a rel='nofollow' href='http://www.copyscape.com/' title='No copiar el contenido de esta página. El plagio será detectado por Copyscape.'><img src='http://banners.copyscape.com/images/cs-wh-234x16.gif' alt='No copiar el contenido de esta página. El plagio será detectado por Copyscape.' width='234' height='16' border='0' /></a>"
		+ "<a class='sinestilo' href='http://www.radimedia.com/gaming/juego_responsable.php?id=f4da5414-1c39-43e7-9193-9581dee487a8' target='_blank' title='Juego responsable'><img src='http://www.radimedia.com/gaming/menores_18.png' border='0' alt='Juego responsable' /></a>"
		+ "<a class='sinestilo' href='http://www.gamblingtherapy.org/es-ES/Default.aspx' target='_blank' title='Riesgos del juego'><img src='http://www.radimedia.com/gaming/riesgo.png' border='0' alt='Riesgos del juego' /></a>"
		//<!--<a href="http://www.todoencasinos.com"><img src="http://www.todoencasinos.com/imagenes/logo3.gif" alt="Guia de casinos - Todos los sistemas gratis para que ganes dinero jugando al casino" border="0" /></a>-->
	  + "</div>";
		
	document.write(text);
}

//
// obtiene nombre de la página
//
function getURL()
{
	var url = document.location.href; 
	var partes = url.split('/'); 
	return(partes[partes.length-1]);
}

//
// crea sitemap
//
function onClickLogo()
{   
    if (KeyID == 15)
		{
        window.location.href = "./crearsitemap.php";
		}
        
    KeyID = 0;
}

function KeyCheck()
{
    if (getURL() == "index.html" || getURL() == "")
    {
        //alert(event.keyCode);
        if (event.keyCode == 16) KeyID = KeyID | 1;
        if (event.keyCode == 17) KeyID = KeyID | 2;
        if (event.keyCode == 84) KeyID = KeyID | 4;
        if (event.keyCode == 67) KeyID = KeyID | 8;
    }
    else
    {
        KeyID = 0;
    }
}

function KeyUp()
{
    KeyID = 0;
}

//
// expande o contrae un control div
//
function toggleVisibility(control, divObjName)
{
	divObj = document.getElementById(divObjName);
	
	if (divObj.className == 'Oculta')
	{
		control.innerHTML = (control.lang == 'en') ? 'Close' : 'Cerrar';
		divObj.className = 'Visible';
	}
	else 
	{
		control.innerHTML = (control.lang == 'en') ? 'Read more' : 'Leer más';
		divObj.className = 'Oculta';
	}
}

function toggleVisibility2(divObjName, divObjName2)
{
	divObj = document.getElementById(divObjName);
	divObj2 = document.getElementById(divObjName2);
	
	if (divObj.className == 'Oculta')
	{
		divObj.className = 'Visible';
		divObj2.className = 'Oculta';
	}
	else 
	{
		divObj.className = 'Oculta';
		divObj2.className = 'Visible';
	}
}

function toggleVisibility3(control, divObjName, text1, text2)
{
	divObj = document.getElementById(divObjName);
	
	if (divObj.className == 'Oculta')
	{
		control.innerHTML = text2;
		divObj.className = 'Visible';
	}
	else 
	{
		control.innerHTML = text1;
		divObj.className = 'Oculta';
	}
}

//
// validar dirección de contacto
//
function validarContacto(form)
{
	try 
	{
    var nombre = form.NombreContacto.value;
    if (nombre.length < 4)
    {
        alert("Por favor introduce tú nombre.");
        form.NombreContacto.focus();
        return false;
    }
    
    var email = form.EmailContacto.value;
    apos = email.indexOf("@")
    dotpos = email.lastIndexOf(".")
    if (apos < 1 || dotpos - apos < 2)
    {
        alert("Por favor introduce tú dirección de correo electrónico.");
        form.EmailContacto.focus();
        return false;
    }
    
    var asunto = form.AsuntoContacto.value;
    if (asunto.length < 4)
    {
				alert("Por favor introduce un asunto un poco más largo.");
				form.AsuntoContacto.focus();
				return false;
    }
    
    var comentario = form.ComentarioContacto.value;
    if (comentario.length < 10)
    {
        alert("Por favor introduce algún comentario un poco más largo.");
        form.ComentarioContacto.focus();
        return false;
    }
		
		if (comentario.search(/\[\s*url\s*=/i) != -1 || comentario.search(/\[\s*link\s*=/i) != -1 || comentario.search(/\s+viagra\s*/i) != -1)
		{
				alert("El comentario contiene palabras no permitidas.");
				form.ComentarioContacto.focus();
				return false;
		}
    
    var codigo2 = form.Codigo2.value;
		if (codigo2.length == 0)
		{
				alert("Por favor introduce el código de seguridad que aparece en la imagen.");
				form.Codigo2.focus();
				return false;
		}
		
		var codigo1 = form.Codigo1.value;
		var codigo1b = "";
		for (i = 0; i < codigo1.length; i++)
		{
			if ((i % 2) != 0)
				codigo1b = codigo1b + codigo1.substring(i, i+1);
		}
		
		if (codigo1b != codigo2)
		{
				alert("El código de seguridad introducido no coincide con el que aparece en la imagen.");
				form.Codigo2.focus();
				return false;
		}
    
    return true;
	}
	catch(exception) 
	{
		if (exception.description == null) 
		{
			alert("Excepción: " + exception.message);  
		} 
		else 
		{
			alert("Excepción: " + exception.description);
		}
	}
	
	return false;
}

function botonLoterias()
{
	var timerID = setTimeout("botonLoteria()", 5000);
}

function botonLoteria()
{
	var html = "";
	
	if (botonID == 0)
	{
		// primitiva
		html = '<a href="https://lotoluck.lotopia.com/user/redirect.jsp?id=2&Afi=loteriasysorteos"><img alt="Sella tú primitiva" src="/imagenes/loterias-quinielas/boton1.png" /></a>';
	}
	else if (botonID == 1)
	{
		// quiniela
		html = '<a href="https://lotoluck.lotopia.com/user/redirect.jsp?id=6&Afi=loteriasysorteos"><img alt="Sella tú quiniela" src="/imagenes/loterias-quinielas/boton2.png" /></a>';
	}
	else if (botonID == 2)
	{
		// euromillones
		html = '<a href="https://lotoluck.lotopia.com/user/redirect.jsp?id=1&Afi=loteriasysorteos"><img alt="Sella tú euromillones" src="/imagenes/loterias-quinielas/boton3.png" /></a>';
	}
	
	botonID = (botonID + 1) % 3;
  
	document.getElementById("divBotonLoterias").innerHTML = 
		"<fieldset><legend>Sella tú boleto</legend>"
		+ "<p class='center'>" + html + "</p>"
		+ "</fieldset>";
		
	botonLoterias();
}

function checkOption(control)
{	
	if (control.className.match(/Checked/i))
	{
		control.className = control.className.replace(/Checked/i, 'Check');
	}
	else 
	{
		control.className = control.className.replace(/Check/i, 'Checked');
	}
}

function checkOptions(value)
{
	var o = document.getElementsByName('CheckOption');
	for (i=0; i < o.length; i++)
	{
		if (value == true)
		{
			o.item(i).className = 'Checked';
		}
		else
		{
			o.item(i).className = 'Check';
		}
	}
}

function addFavorite()
{
	var url = "http://www.la-primitiva.org/"; 
	var title = "Resultado primitiva";
	
	// FireFox
	if (navigator.appName == "Netscape")
	{ 
		window.sidebar.addPanel(title, url, "");
	}
	// IE
	else
	{
		window.external.AddFavorite(url, title);
	}
}

function register(form)
{
	try
	{
		var nombre = form.NombreUsuario.value;
		
		if (nombre.length < 4)
		{
				alert("Por favor introduce tú nombre.");
				form.NombreUsuario.focus();
				return false;
		}
		
		var email = form.EmailUsuario.value;
		apos = email.indexOf("@")
		dotpos = email.lastIndexOf(".")
		if (apos < 1 || dotpos - apos < 2)
		{
				alert("Por favor introduce tú dirección de correo electrónico.");
				form.EmailUsuario.focus();
				return false;
		}
		
		var o = document.getElementsByName('CheckOption');
		var checked = 0;
		var sorteos = "";
		
		for (i=0; i < o.length; i++)
		{
			if (o.item(i).className == 'Checked')
			{
				checked++;
				sorteos = sorteos + o.item(i).innerHTML + ", ";
			}
		}
		
		if (checked == 0)
		{
				alert("Por favor seleccione el sorteo que desea recibir.");
				return false;
		}
		
		sorteos = sorteos.substring(0, sorteos.length - 2);
		form.Sorteos.value = sorteos;
		
		o = document.getElementById("CheckPromocion");
		if (o.className.match(/Checked/i))
		{
			form.Promociones.value = "SI";
		}
		else
		{
			form.Promociones.value = "NO";
		}
			
		return true;
	}
	catch(exception) 
	{
		if (exception.description == null) 
		{
			alert("Excepción: " + exception.message);  
		} 
		else 
		{
			alert("Excepción: " + exception.description);
		}
	}
	
	return false;
}

function setButtonImage(imageName, imageSrc)
{
	image = document.getElementById(imageName);
	image.src = imageSrc;
}