var actual;

function comprobar_campos()
{
	if (document.usuari.nick.value != "")
	{
		if (document.usuari.DNI.value != "")
		{
			if (document.usuari.nom.value != "")
			{
				if (document.usuari.cognom.value != "")
				{
					if (document.usuari.cognom2.value != "")
					{
						if (document.usuari.passw.value != "")
						{
							if (document.usuari.mail.value != "")
							{
								document.usuari.action = "nou_usuari.php";
								document.usuari.submit();
							}
							else
							{
								document.usuari.mail.style.backgroundColor = "red";
							}
						}
						else
						{
							document.usuari.passw.style.backgroundColor = "red";
						}
					}
					else
					{
						document.usuari.cognom2.style.backgroundColor = "red";
					}
				}
				else
				{
					document.usuari.cognom.style.backgroundColor = "red";
				}
			}
			else
			{
				document.usuari.nom.style.backgroundColor = "red";
			}
		}
		else
		{
			document.usuari.DNI.style.backgroundColor = "red";
		}
	}
	else
	{
		document.usuari.nick.style.backgroundColor = "red";
	}
}

function comprobar_campos_2()
{
	if (document.usuari.nick.value != "")
	{
		if (document.usuari.DNI.value != "")
		{
			if (document.usuari.nom.value != "")
			{
				if (document.usuari.cognom.value != "")
				{
					if (document.usuari.cognom2.value != "")
					{
						if (document.usuari.passw.value != "")
						{
							if (document.usuari.mail.value != "")
							{
								document.usuari.action = "modificar_us.php";
								document.usuari.submit();
							}
							else
							{
								document.usuari.mail.style.backgroundColor = "red";
							}
						}
						else
						{
							document.usuari.passw.style.backgroundColor = "red";
						}
					}
					else
					{
						document.usuari.cognom2.style.backgroundColor = "red";
					}
				}
				else
				{
					document.usuari.cognom.style.backgroundColor = "red";
				}
			}
			else
			{
				document.usuari.nom.style.backgroundColor = "red";
			}
		}
		else
		{
			document.usuari.DNI.style.backgroundColor = "red";
		}
	}
	else
	{
		document.usuari.nick.style.backgroundColor = "red";
	}
}

function color_default(campo,color)
{
	campo.style.backgroundColor = color;
}

function contar_letras(letras,index)
{	
	color_default(document.usuari.DNI,'white');

	if (index==1)
	{
		caracter = letras.substring(letras.length - 1, letras.length);
	
		if (isNaN(caracter))
		{
			document.usuari.DNI.value = letras.substring(0, letras.length - 1);
		}
	
		numero = letras.length;

		if (numero==8)
		{
			document.usuari.LETRA.value = calcletra(letras)
		}
	}
	if (index==2)
	{
		caracter = letras.substring(letras.length - 1, letras.length);
	
		if (!isNaN(caracter))
		{
			document.usuari.LETRA.value = letras.substring(0, letras.length - 1);
		}
	}
}

function calcletra(dni)
{
	var JuegoCaracteres="TRWAGMYFPDXBNJZSQVHLCKET";
	var Posicion= dni % 23;
	var Letra = JuegoCaracteres.charAt(Posicion);
	return Letra;
}

function esnumero(tecla)
{
	alert("hola");
}

function comprobar_camp(camp)
{
	if (camp != '')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isNumber(e) {
    k = (document.all) ? e.keyCode : e.which;
    if (k==8 || k==0) return true;
    patron = /\d/;
    n = String.fromCharCode(k);
    return patron.test(n);
}

function cargar_mapa(index)
{
	if (index==1)
	{	
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Avinguda del Parc, 5&ci1=Granollers&c2=Carrer de Francesc Ribas&ci2=Granollers";
	}
	if (index==2)
	{		
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Avinguda del Parc, 5&ci1=Granollers&c2=Carrer de Joan Prim&ci2=Granollers";
	}
	if (index==3)
	{
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Avinguda del Parc, 5&ci1=Granollers&c2=Pl. Maluquer i Salvador&ci2=Granollers";
	}
	if (index==4)
	{
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Plaça de Serrat i Bonastre&ci1=Granollers&c2=Carrer de Francesc Ribas&ci2=Granollers";
	}
	if (index==5)
	{
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Plaça de Serrat i Bonastre&ci1=Granollers&c2=Carrer de Joan Prim&ci2=Granollers";
	}
	if (index==6)
	{
		document.getElementsByName('mapa').item(0).src="ruta.php?c1=Plaça de Serrat i Bonastre&ci1=Granollers&c2=Pl. Maluquer i Salvador&ci2=Granollers";
	}
}

function cicle_noticies()
{
	location.href='noticias_adm.php?cicle=' + document.select_cicle.desti.value;
}

//Estas funciones se encargan de ajustar el tamaño de la pagina segun el contenido del IFRAME
//-------------------------------------------------------------------------------------------

function ajustar(xframe)
{
	//document.getElementsByName('IL').item(0).style.height = 800;
	xframe.style.height = 1000;
	var alturaPagina = xframe.contentWindow.document.body.scrollHeight;
	if (alturaPagina > 100)
	{
		xframe.style.height = alturaPagina;
	}
	else
	{
		xframe.style.height = 1000;
	}
}

function ajustar2(xframe)
{
	var alturaPagina = xframe.contentWindow.document.body.scrollHeight;
	
	if (alturaPagina > 1200)
	{
		xframe.style.height = alturaPagina;
	}
	else
	{
		xframe.style.height = 800;
	}
}
//-------------------------------------------------------------------------------------------

function confirmar(mensaje)
{
	
	var res;
	if (confirm(mensaje))
	{
		res=true;
	}
	else
	{
		res=false;
	}
	return res;
}

function contar_fill(pare)
{	
	var n=0;
	var url="relacio_usuari.php?pare=" + pare
	
	for (i=0; ele=document.fills.elements[i]; i++) 
	{
		if(ele.checked)
		{
			n++;
			url = url + "&alumne" + i + "=" + ele.value;
		}
	}
	
	url = url + "&nfills=" + n + "&accion=relacionar";
	location.href = url;
}

function cambiacolor(id,accion)
{
	if (accion==1)
	{
		document.getElementById("i"+id).style.cursor = 'pointer';
		document.getElementById("i"+id).style.background = '#E67F32';
	}
	
	if (accion==2)
	{
		if(id != actual)
		{
			document.getElementById("i"+id).style.cursor = 'default';
			document.getElementById("i"+id).style.background='#27316E';
		}			
	}
}

function navegar_menu(link,id)
{
	window.scrollTo(0,0);
	
	document.getElementsByName('IL').item(0).style.height = 800;
	document.getElementsByName('IL').item(0).src = link;

	if (id != actual)
	{
		document.getElementById("i"+id).style.background = "#E67F32";	
		document.getElementById("i"+id).style.fontWeight = "bold";
		if(actual != null)
		{
			document.getElementById("i"+actual).style.background = "#27316E";
			document.getElementById("i"+actual).style.fontWeight = "normal";
		}
	}
	
	actual = id;
}

function navegar(link)
{
	location.href = link;
}

function reloja()
{
	var data,diasem, dia, mes, dianum, any;
	
	ahora = new Date();
	hora = ahora.getHours();
	minut = ahora.getMinutes();
	//segons = ahora.getSeconds();
	dia = ahora.getDate();
	diasem = ahora.getDay();
	mes = ahora.getMonth();
	any = ahora.getFullYear();

	switch(diasem)
	{
		case 1:diasem = "Dilluns";break;
		case 2:diasem = "Dimarts";break;
		case 3:diasem = "Dimecres";break;
		case 4:diasem = "Dijous";break;
		case 5:diasem = "Divendres";break;
		case 6:diasem = "Dissabte";break;
		case 0:diasem = "Diumenge";break;
	}		

	switch(mes)
	{
		case 0:mes = "de Gener";break;
		case 1:mes = "de Febrer";break;
		case 2:mes = "de Març";break;
		case 3:mes = "d'Abril";break;
		case 4:mes = "de Maig";break;
		case 5:mes = "de Juny";break;
		case 6:mes = "de Juliol";break;
		case 7:mes = "d'Agost";break;
		case 8:mes = "de Septembre";break;
		case 9:mes = "de Octubre";break;
		case 10:mes = "de Novembre";break;
		case 11:mes = "de Desembre";break;
	}
	/*if (segons<10)
	{
		segons = "0"+segons;
	}*/
	if (minut<10)
	{
		minut = "0"+minut;
	}
	if (hora<10)
	{
		hora = "0"+hora;
	}
	//alert(document.getElementById('dia'));
	document.getElementById('dia').value = diasem+" "+dia+" "+mes+" del "+any+"     "+hora+":"+minut//+":"+segons;
}

function cambiar_cursor(estado)
{
	if (estado)
	{
		document.body.style.cursor = 'pointer';
	}
	else
	{
		document.body.style.cursor = 'default';
	}
}

function campo_blanco (texto)
{
	if (texto=="")
	{
		alert('El camp esta en blanc.');
		res=false;
	}
	else
	{
		res=true;
	}
	return res;
}
