// JavaScript Document

/*
=============================================================
Ventanas
=============================================================
*/


function abrirventana(url)
	{
	window.open(url, "_self"); 
	}

/*
=============================================================
Estilo 
=============================================================
*/
function cambiarcss(id, newClass){

	identity=document.getElementById(id);
	identity.className=newClass;
}



function cambiarimg (id, newImg,texto,jug){

	identity=document.getElementById(id);
	identity.src=newImg;
	
	identity=document.getElementById("hreffoto");
	identity.href=newImg;
//	alert('id:' + id + '\n identidad:  '+identity.src);
	identity=document.getElementById("tituloEquipo");
	identity.innerHTML=texto;
	
	identity=document.getElementById("jugadores");
	identity.innerHTML=jug;
	

}
	


/*
=============================================================
Comprueba formulario de Usuario
=============================================================
*/


function compruebaFormUser()
{
var alerta	=	false;
var message	=	"";
var user	=	document.formUser.usuario.value;
var pass	=	document.formUser.password.value;

if (user == '')
	{
	alerta	=	true;
	message	=	"Introduzca un usuario \n";
	}
	else{
			if (mail(user)==false)
			{
				alerta	=	true;
				message	=	message + "El formato del usuario es incorrecto debe ser un correo electrónico.\n";
			}
		}
if (pass == '')
	{
	alerta	=	true;
	message	=	message + "Introduzca un password \n";
	}
	

if (alerta== false) 	
	{
	document.formUser.submit();
	}
else {
	alert(message);
	}

}



/*
=============================================================
comprueba que es un email
=============================================================
*/


function 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;
}

/*
=============================================================
Tratamiento de fechas 
=============================================================
*/
var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 

function fecha() {
	dows = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	months = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	now = new Date();
	dow = now.getDay();
	d = now.getDate();
	m = now.getMonth();
	h = now.getTime();
	y = now.getFullYear();
	document.write(dows[dow]+" "+d+", de "+months[m]+" de "+y);
	}