// begind - 01 - roll-over
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// end - 01 - roll-over

// begind - 02 - tools
/////////////////////////
// AFavoritos()
/////////////////////////
function AFavoritos()
{
	var url = String(document.URL);
	var titulo = String(document.title);
	if (document.all)
		window.external.AddFavorite(url,titulo);
}

/////////////////////////
// IsNumber()
/////////////////////////
function IsNumber(number)
{
    var n = number;
    
    if (n.charAt(n.length-1) == ',')
    {
        n = n + '0';
    }
    return (/^[1-9](\d)*((\,)?(\d)+)?$/.test(n));
}
// end - 02 - tools

// begind - 03 - asociate
/////////////////////////
// CargaAficiones()
/////////////////////////
function CargaAficiones()
{
	var table = document.getElementById('aficiones');
	var tbody;

	// 1 tierra
	if (document.getElementById("chktierra").checked)
 	{
		tbody = document.getElementById("tbodytierra");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodytierra");
			var tr = document.createElement('tr');

			var td = document.createElement('td');
			var check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkbicicleta";
			check.name = "chkbicicleta";
			check.checked = false;
			td.appendChild(check);
			var br = document.createElement('br');
			td.appendChild(br);
			var txtInner = document.createTextNode("Bicicleta");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkescalada";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Escalada");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkespeleo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Espeleo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chksenderismo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Senderismo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			tbody.appendChild(tr);
			table.appendChild(tbody);
		}
	}
	else
	{
		tbody = document.getElementById("tbodytierra");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 2 agua
	if (document.getElementById("chkagua").checked)
 	{
		tbody = document.getElementById("tbodyagua");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyagua");
			var tr = document.createElement('tr');

			var td = document.createElement('td');
			var check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkpiragua";
			td.appendChild(check);
			var br = document.createElement('br');
			td.appendChild(br);
			var txtInner = document.createTextNode("Piragua");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkbarranquismo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Barranquismo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkbuceo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Buceo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chksurf";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Surf");
			td.appendChild(txtInner);
			tr.appendChild(td);

			tbody.appendChild(tr);
			table.appendChild(tbody);
		}
	}
	else
	{
		tbody = document.getElementById("tbodyagua");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 3 nieve
	if (document.getElementById("chknieve").checked)
 	{
		tbody = document.getElementById("tbodynieve");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodynieve");
			var tr = document.createElement('tr');

			var td = document.createElement('td');
			var check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkesqui";
			td.appendChild(check);
			var br = document.createElement('br');
			td.appendChild(br);
			var txtInner = document.createTextNode("Esquí");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chktabla";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Tabla");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkfondo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Fondo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkalpinismo";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Alpinismo");
			td.appendChild(txtInner);
			tr.appendChild(td);

			tbody.appendChild(tr);
			table.appendChild(tbody);
		}
	}
	else
	{
		tbody = document.getElementById("tbodynieve");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 4 aire
	if (document.getElementById("chkaire").checked)
 	{
		tbody = document.getElementById("tbodyaire");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyaire");
			var tr = document.createElement('tr');

			var td = document.createElement('td');
			var check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkparapente";
			td.appendChild(check);
			var br = document.createElement('br');
			td.appendChild(br);
			var txtInner = document.createTextNode("Parapente");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkvela";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Vela");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chkparamotor";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Paramotor");
			td.appendChild(txtInner);
			tr.appendChild(td);

			td = document.createElement('td');
			check = document.createElement('input');
			check.type = 'checkbox';
			check.id = "chksalto";
			td.appendChild(check);
			br = document.createElement('br');
			td.appendChild(br);
			txtInner = document.createTextNode("Salto");
			td.appendChild(txtInner);
			tr.appendChild(td);

			tbody.appendChild(tr);
			table.appendChild(tbody);
		}
	}
	else
	{
		tbody = document.getElementById("tbodyaire");
		if (tbody != null)
			table.removeChild(tbody);
	}
}

/////////////////////////
// CompruebaFicha()
/////////////////////////
function CompruebaFicha()
{
	var nombre = document.getElementById("txtnombre").value;
	var apellidos = document.getElementById("txtapellidos").value;
	var dni = document.getElementById("txtdni").value;
	var direccion = document.getElementById("txtdireccion").value;
	var localidad = document.getElementById("txtlocalidad").value;
	var provincia = document.getElementById("txtprovincia").value;
	var cp = document.getElementById("txtcp").value;
	var telefono = document.getElementById("txttelefono").value;
	var email = document.getElementById("txtemail").value;
	var observaciones = document.getElementById("txtobservaciones").innerText;
	var error = false;

	// 1 nombre
	var table = document.getElementById('errornombre');
    if (nombre == "")
	{
		var tbody = document.getElementById("tbodyerrornombre");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrornombre");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtnombre").focus();
		error = true;
	}
	else
	{
		tbody = document.getElementById("tbodyerrornombre");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 2 apellidos
	table = document.getElementById('errorapellidos');
    if (apellidos == "")
	{
		var tbody = document.getElementById("tbodyerrorapellidos");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrorapellidos");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtapellidos").focus();
		error = true;
	}
	else
	{
		tbody = document.getElementById("tbodyerrorapellidos");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 3 dni
	table = document.getElementById('errordni');
    if (dni == "")
	{
		var tbody = document.getElementById("tbodyerrordni");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrordni");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtdni").focus();
		error = true;
	}
	else
	{
		if ((dni.length != 9) || (!IsNumber(dni.substr(0,8))) || (IsNumber(dni.charAt(8))))
		{
			var tbody = document.getElementById("tbodyerrordni");
			if (tbody == null)
			{
				var tbody = document.createElement("tbody");
				tbody.setAttribute("id","tbodyerrordni");
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				var imagen= document.createElement('img');
				imagen.src='../Imagenes/revisa.gif';
				imagen.style.border="0pt";
				imagen.style.width="60px";
				imagen.style.height="16px";
				td.appendChild(imagen);
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
			}

			document.getElementById("txtdni").focus();
			error = true;
		}
		else
		{
			tbody = document.getElementById("tbodyerrordni");
			if (tbody != null)
				table.removeChild(tbody);
		}
	}

	// 4 direccion
	table = document.getElementById('errordireccion');
    if (direccion == "")
	{
		var tbody = document.getElementById("tbodyerrordireccion");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrordireccion");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtdireccion").focus();
		error = true;
	}
	else
	{
		tbody = document.getElementById("tbodyerrordireccion");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 5 localidad
	table = document.getElementById('errorlocalidad');
    if (localidad == "")
	{
		var tbody = document.getElementById("tbodyerrorlocalidad");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrorlocalidad");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtlocalidad").focus();
		error = true;
	}
	else
	{
		tbody = document.getElementById("tbodyerrorlocalidad");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 6 provincia
	table = document.getElementById('errorprovincia');
    if (provincia == "")
	{
		var tbody = document.getElementById("tbodyerrorprovincia");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrorprovincia");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtprovincia").focus();
		error = true;
	}
	else
	{
		tbody = document.getElementById("tbodyerrorprovincia");
		if (tbody != null)
			table.removeChild(tbody);
	}

	// 7 cp
	table = document.getElementById('errorcp');
    if (cp == "")
	{
		var tbody = document.getElementById("tbodyerrorcp");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrorcp");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txtcp").focus();
		error = true;
	}
	else
	{
		if ((!IsNumber(cp)) || (cp.length != 5))
		{
			var tbody = document.getElementById("tbodyerrorcp");
			if (tbody == null)
			{
				var tbody = document.createElement("tbody");
				tbody.setAttribute("id","tbodyerrorcp");
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				var imagen= document.createElement('img');
				imagen.src='../Imagenes/revisa.gif';
				imagen.style.border="0pt";
				imagen.style.width="60px";
				imagen.style.height="16px";
				td.appendChild(imagen);
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
			}

			document.getElementById("txtcp").focus();
			error = true;
		}
		else
		{
			tbody = document.getElementById("tbodyerrorcp");
			if (tbody != null)
				table.removeChild(tbody);
		}
	}

	// 8 telefono
	table = document.getElementById('errortelefono');
    if (telefono == "")
	{
		var tbody = document.getElementById("tbodyerrortelefono");
		if (tbody == null)
		{
			var tbody = document.createElement("tbody");
			tbody.setAttribute("id","tbodyerrortelefono");
			var tr = document.createElement('tr');
			var td = document.createElement('td');
			var imagen= document.createElement('img');
			imagen.src='../Imagenes/revisa.gif';
			imagen.style.border="0pt";
			imagen.style.width="60px";
			imagen.style.height="16px";
			td.appendChild(imagen);
			tr.appendChild(td);
			tbody.appendChild(tr);
			table.appendChild(tbody);
		}

		document.getElementById("txttelefono").focus();
		error = true;
	}
	else
	{
		if (!IsNumber(telefono))
		{
			var tbody = document.getElementById("tbodyerrortelefono");
			if (tbody == null)
			{
				var tbody = document.createElement("tbody");
				tbody.setAttribute("id","tbodyerrortelefono");
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				var imagen= document.createElement('img');
				imagen.src='../Imagenes/revisa.gif';
				imagen.style.border="0pt";
				imagen.style.width="60px";
				imagen.style.height="16px";
				td.appendChild(imagen);
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
			}

			document.getElementById("txttelefono").focus();
			error = true;
		}
		else
		{
			tbody = document.getElementById("tbodyerrortelefono");
			if (tbody != null)
				table.removeChild(tbody);
		}
	}

	// 9 email
	table = document.getElementById('erroremail');
    if (email != "")
	{
		var arroba = email.split("@");
		if (arroba.length < 2)
		{
			var tbody = document.getElementById("tbodyerroremail");
			if (tbody == null)
			{
				var tbody = document.createElement("tbody");
				tbody.setAttribute("id","tbodyerroremail");
				var tr = document.createElement('tr');
				var td = document.createElement('td');
				var imagen= document.createElement('img');
				imagen.src='../Imagenes/revisa.gif';
				imagen.style.border="0pt";
				imagen.style.width="60px";
				imagen.style.height="16px";
				td.appendChild(imagen);
				tr.appendChild(td);
				tbody.appendChild(tr);
				table.appendChild(tbody);
			}

			document.getElementById("txtemail").focus();
			error = true;
		}
		else
		{
			var user = arroba[0];
			var host = arroba[1];
			var punto = host.split(".");
			if ((user == "") || (punto.length < 2) || (punto[0] == "") || (punto[1] == ""))
			{
				var tbody = document.getElementById("tbodyerroremail");
				if (tbody == null)
				{
					var tbody = document.createElement("tbody");
					tbody.setAttribute("id","tbodyerroremail");
					var tr = document.createElement('tr');
					var td = document.createElement('td');
					var imagen= document.createElement('img');
					imagen.src='../Imagenes/revisa.gif';
					imagen.style.border="0pt";
					imagen.style.width="60px";
					imagen.style.height="16px";
					td.appendChild(imagen);
					tr.appendChild(td);
					tbody.appendChild(tr);
					table.appendChild(tbody);
				}

				document.getElementById("txtemail").focus();
				error = true;
			}
			else
			{
				tbody = document.getElementById("tbodyerroremail");
				if (tbody != null)
					table.removeChild(tbody);
			}
		}
	}
	else
	{
		tbody = document.getElementById("tbodyerroremail");
		if (tbody != null)
			table.removeChild(tbody);
	}

	return error;
}

/////////////////////////
// LeeAficiones()
/////////////////////////
function LeeAficiones()
{
	var aficiones = "";
	var boxs = new Array();
	boxs = ['chkbicicleta','chkescalada','chkespeleo','chksenderismo',
			'chkpiragua','chkbarranquismo','chkbuceo','chksurf',
			'chkesqui','chktabla','chkfondo','chkalpinismo',
			'chkparapente','chkvela','chkparamotor','chksalto']
	for(var i = 0; i < boxs.length; i++)
	{
		var check = document.getElementById(boxs[i]);
		if ((check != null) && (check.checked))
			aficiones += "1";
		else
			aficiones += "0";
				
	}

	document.getElementById('chkaficiones').value = aficiones;
}

/////////////////////////
// MandarFicha()
/////////////////////////
function MandarFicha()
{
    if (!CompruebaFicha())
	{
		LeeAficiones();
		document.ficha.submit();
	}
}
// begind - 03 - asociate

