

//////////////////
// Calcula Edat //1
//////////////////

/*function QuinaEdatTinc(nacimiento,combo)
{
	if (nacimiento != "")
	{
		avui = new Date(); //avui... jeje
		diacompeticio = new Date(2006, 4, 23);
		cumple = new Date(nacimiento); //data introduïda al form
		edad = (diacompeticio.getTime() - cumple.getTime()); //milisegons
		edad = parseInt(edad / 1000 / 60 / 60 / 24 / 365); //enter any
		if (isNaN(edad))
		{
			alert("El Format de la edat no es reconeix");
		}
		else
		{
			//return CategoriaSegunEdad(edad);
			iCols = new Number(combo.length);
			for (iConta=1;iConta<iCols;iConta++)
			{
				edadCateg = new Number(combo[iConta].value);
				if (edad > edadCateg)
				{
					//Inscripcion.categoria.selectedIndex = iConta;
					Linea=iConta;
				}
			}
			combo.selectedIndex = Linea;
		}
	}
}*/

function get_radio_value(radiob)
{
for (var i=0; i < radiob.length; i++)
   {
   if (radiob[i].checked)
      {
      var rad_val = radiob[i].value;
	  return rad_val;
      }
   }

}

function QuinaEdatTinc2(frm)
{
	if ( (frm.dia.value != "") && (frm.mes.value!="") && (frm.any.value!= "") && (get_radio_value(frm.sexe) != "") )
	{
			if ( (isNaN(frm.dia.value)) || ((frm.dia.value<1)	|| (frm.dia.value>31)) )
			{
					alert("El dia no és correcte");
					frm.dia.focus();
					frm.dia.value="";
					return(-1);
			}
			if ( (isNaN(frm.mes.value)) || ((frm.mes.value<1)	|| (frm.mes.value>12)) )
			{
					alert("El mes no és correcte");
					frm.mes.focus();
					frm.mes.value="";
					return(-1);
			}
			if ( (isNaN(frm.any.value)) || ((frm.any.value<1900) || (frm.any.value>2010)) )
			{
					alert("l'any no és correcte");
					frm.any.value="";
					frm.any.focus();
					return(-1);
			}
			//avui = 2005 //avui... jeje
			cumple = new Date();				//ens asegurem que la data estigui creada correctament
			cumple.setFullYear(frm.any.value,frm.mes.value-1,frm.dia.value);
			
			/*
						
				añadido 2008...
				
				****** OJO!!!!!                                   ******			
				****** HAY Q RESTAR UN PUTO MES EN JAVASCRIPT!!!! ******
			*/			
			
			//cumple.setDate(frm.dia.value);
			//cumple.setMonth(frm.mes.value-1);
			//cumple.setMonth(frm.mes.value);
			//cumple.setYear(frm.any.value);
			//----------------------------------
			//Afegit per mi (david)
			avui = new Date();
			avui.setFullYear(2010,4-1,25);
			//nacimiento=dia.value + "/"+mes.value+"/"+any.value
			//cumple = new Date(nacimiento); //data introduïda al form
			edad=avui.getFullYear()-cumple.getFullYear();
			// Fi afegit per mi
			//----------------------------------
			//edad = (avui.getTime() - cumple.getTime()); //milisegons
			//edad = parseInt(edad / 1000 / 60 / 60 / 24 / 365); //enter any
			if (isNaN(edad))
			{
				alert("No es pot calcular una edat."+avui.getYear());
			}
			else
			{
				//alert("edat"+edad+"sexe"+get_radio_value(frm.sexe));
				//comprovació: les dones son veteranes a partir dels 35 anys en endavant !!!
				//----------------------------------
				//Afegit per mi (david)
				//alert('edat inicial'+edad+'\ncumple'+cumple+'\navui'+avui);
				if (edad>=35)
				//Potser esta mal calculada, mirarem el mes i dia de naixement
				{
					//alert("Edat = 35 Mes:"+cumple.getMonth()+" <-> " +avui.getMonth() + " dia:" + cumple.getDay() + "<->" + avui.getDay()) ;
					if ( (cumple.getMonth()>avui.getMonth()) || ((cumple.getMonth()==avui.getMonth()) && (cumple.getDate()>avui.getDate())) )
					{   //si va néixer DESPRES del dia de celebració de la milla, encara te un any menys
						edad=edad-1;
					}
				}
				/*if ((edad>34))
				{edad=40;}*/
				//alert('edat calculada'+edad);
				//if ( (get_radio_value(frm.sexe)=="F") && (edad>34) && (edad<40) )
				//{edad=40;}

				// Fi afegit per mi
				//----------------------------------
				//return CategoriaSegunEdad(edad);
				iCols = new Number(frm.categoria.length);
				Linea=0;
				for (iConta=iCols-1;iConta>=0;iConta--)
				{
					edadCateg = new Number(frm.categoria[iConta].value);
					//alert(iConta+"-"+edad+"-"+edadCateg);
					if (edad >= edadCateg)
					{
					//Inscripcion.categoria.selectedIndex = iConta;
					Linea=iConta;
					break;
					}
				}
				if (iConta==0)
				{
					if (edad<9)
					{
						alert("Amb aquesta edat ("+edad+"), no es pot participar.Mínim 9 anys");
						frm.any.value=avui.getYear()-9;
						frm.any.focus();
					}
					else
					{
						alert("No es troba una categoria adequada. Torna a carregar la pàgina per obtenir les categories"+iCols);
					}

				 }
				frm.categoria.selectedIndex = Linea;
            }//si no es pot calcular una edat
	}//si els dies,mesos, anys, estan buits
}


////////////////////////////////////////
// Validacions Formulari Inscripcions //
////////////////////////////////////////

function validarInscripcion(frm)
{
	textoAlert = "NO s'ha pogut fer la inscripció per:\n- - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
	bValidar = true;
	// TextBoxes.TExt.lenght > 0 i Categoria i Sexe Asignats
	if (frm.nom.value == "" || frm.dia.value == "" || frm.mes.value == "" || frm.any.value == "" || frm.categoria.value == "0" || (frm.sexe[0].checked == false && frm.sexe[1].checked == false))
	{
		bValidar = false;
		textoAlert = textoAlert + "Els camps amb asterisc(*) son obligatoris\n";
	}
	// mail amb 1 @
	if (frm.email.value != "")
	{
		correo = new String;
		correo = frm.email.value;
		algarrobas = correo.indexOf("@");
		if (algarrobas > -1)
		{
			masalgarrobas = correo.indexOf("@", algarrobas + 1);
			if (masalgarrobas > -1)
			{
				bValidar = false;
				textoAlert = textoAlert + "NO es reconeix la direcció de Correu Electrònic... quantes @ tens?\n"
			}
		}
		else
		{
			bValidar = false;
			textoAlert = textoAlert + "NO es reconeix la direcció de Correu Electrònic\n"
		}
	}
	//edad correcte
	if ( (isNaN(frm.dia.value)) || ((frm.dia.value<1)	|| (frm.dia.value>31)) )
	{
		textoAlert = textoAlert + "El dia no és correcte\n";
		frm.dia.value = "";
		bValidar = false;
	}
	if ( (isNaN(frm.mes.value)) || ((frm.mes.value<1)	|| (frm.mes.value>12)) )
	{
		textoAlert = textoAlert + "El mes no és correcte\n";
		frm.mes.value = "";
		bValidar = false;
	}
	if ( (isNaN(frm.any.value)) || ((frm.any.value<1900) || (frm.any.value>2010)) )
	{
		textoAlert = textoAlert + "l'any no és correcte\n";
		frm.any.value="";
		bValidar = false;
	}
	//acceptar reglament
	if (frm.accepto[0].checked == false)
	{
		bValidar = false;
		textoAlert = textoAlert + "Per participar s'ha d'acceptar el reglament!\n";
	}
	if (bValidar == false)
	{
		alert(textoAlert);
	}
	return bValidar;
}

function validarInscripcionSudoku(frm)
{
	textoAlert = "NO s'ha pogut fer la inscripció per:\n- - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
	bValidar = true;
	// TextBoxes.Text.lenght > 0 i Categoria i Sexe Asignats
	if (frm.nom.value == "" || frm.cognoms.value == "" || frm.dni.value == "")
	{
		bValidar = false;
		textoAlert = textoAlert + "Els camps amb asterisc(*) son obligatoris\n";
	}
	// mail amb 1 @
	if (frm.mail.value != "")
	{
		correo = new String;
		correo = frm.mail.value;
		algarrobas = correo.indexOf("@");
		if (algarrobas > -1)
		{
			masalgarrobas = correo.indexOf("@", algarrobas + 1);
			if (masalgarrobas > -1)
			{
				//mail con @>1
				bValidar = false;
				textoAlert = textoAlert + "NO es reconeix la direcció de Correu Electrònic... quantes @ tens?\n"
			}
		}
		else
		{
			//mail sin @
			bValidar = false;
			textoAlert = textoAlert + "NO es reconeix la direcció de Correu Electrònic\n"
		}
	}
	//acceptar reglament
	if (frm.accepto[0].checked == false)
	{
		bValidar = false;
		textoAlert = textoAlert + "Per participar s'ha d'acceptar el reglament!\n";
	}
	if (bValidar == false)
	{
		alert(textoAlert);
	}
	return bValidar;
}


///////////////////////////////////////////////////
// Validacions Inscripcions Participants d'1 Club//
///////////////////////////////////////////////////

function ValidarParticipanteClub(frm)
{
	bValidar = true;
	texto = "NO es pot afegir el participant per:\n- - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
	//todos los campos llenos
	if (frm.nom_part.value == "" || frm.cog_part.value == "" || frm.dia.value == "" || frm.mes.value == "" || frm.any.value == "" || frm.categoria.selectedIndex == 0 || (frm.sexe[0].checked == false && frm.sexe[1].checked == false))
	{
		bValidar = false;
		texto = texto + "S'han de omplir tots els camps\n";
	}
	//edad correcte
	//cumple = new Date(frm.datanaixament.value);
	//if (isNaN(cumple))
	//{
	//	bValidar = false;
	//	textoAlert = textoAlert + "El format de la data de naixament no es reconeix\n";
	//}
	if (bValidar == false)
	{
		alert(texto);
	}
	return bValidar;
}


///////////////////////////////////////////////////
// Validacions Inscripcions Participants d'1 Club//
///////////////////////////////////////////////////

function validarInscripcionGrup(frm)
{
	bValidar = true;
	texto = "NO es pot inscriure el grup per:\n- - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
	//campos obligatorios rellenados
	if (frm.nom.value == "" || frm.telefon_delegat.value == "" ||frm.nom_delegat.value == "")
	{
		bValidar = false;
		texto = texto + "Els camps amb asterisc(*) son obligatoris\n";
	}
	//participants > 0
	if (FrameParticipants.inscripcioGpersona.numparticipants.value == "0")
	{
		bValidar = false;
		texto = texto + "El Club ha de tenir participants\n";
	}
	//acceptar reglament
	if (frm.accepto[0].checked == false)
	{
		bValidar = false;
		texto = texto + "Per participar s'ha d'acceptar el reglament!\n";
	}
	if (bValidar == false)
	{
		alert(texto);
	}
	return bValidar;
}


////////////////////////
// Mostrar Reglamento //
////////////////////////

function Reglamento()
{
	anchoNueva = 570;
	altoNueva = 500;
    RegLeft = screen.availWidth / 2 - anchoNueva / 2;
	RegTop = screen.availHeight / 2 - altoNueva / 2;
	Reg = window.open("http://www.claror.org/esport/esdeveniments/Raid/reglaments.htm","Reglament","toolbar=no, width=anchoNueva, height=altoNueva, resizable=yes, scrollbars=yes, status=yes");
	//Reg.moveTo(RegLeft,RegTop)
	Reg.status="Reglament Milla 2010";
}

function ReglamentoMilla()
{
	anchoNueva = 570;
	altoNueva = 500;
    RegLeft = screen.availWidth / 2 - anchoNueva / 2;
	RegTop = screen.availHeight / 2 - altoNueva / 2;
	Reg = window.open("http://www.claror.cat/Esport/Esdeveniments/milla/reglament.htm","Reglament","toolbar=no, width=anchoNueva, height=altoNueva, resizable=yes, scrollbars=yes, status=yes");
	//Reg.moveTo(RegLeft,RegTop)
	Reg.status="Reglament Milla";
}

function ReglamentoSudokus()
{
	anchoNueva = 350;
	altoNueva = 400;
    RegLeft = screen.availWidth / 2 - anchoNueva / 2;
	RegTop = screen.availHeight / 2 - altoNueva / 2;
	Reg = window.open("http://www.claror.org/esport/esdeveniments/Sudoku/reglament.htm","Reglament","toolbar=no, width=anchoNueva, height=altoNueva, resizable=yes, scrollbars=yes, status=yes");
	//Reg.moveTo(RegLeft,RegTop)
	Reg.status="Reglament Campionat Sudokus";
}
