		function ValidarEmail(email) 
		{
			caracNoValidos = " /:,;";
			for (i = 0; i < caracNoValidos.length; i++) 
			{
				// ¿hay algún carácter no válido?
				caracMal = caracNoValidos.charAt(i);
				if (email.indexOf(caracMal,0) > -1)
					return false;
			}
			 // debe haber una @
			posArroba = email.indexOf("@",1);
			if (posArroba == -1) 
				return false;
			// y sólo una
			if (email.indexOf("@",posArroba + 1) != -1)
				return false;
			// y al menos un . después de la @ con un caracter en medio
			posPunto = email.indexOf(".",posArroba + 2);
			if (posPunto == -1)
				return false;
			// debe haber al menos 2 caracteres tras el .
			if (posPunto + 3 > email.length)
				return false;
			return true;
		}

		function Noticias()
		{
			if (ValidarEmail(document.formLeft.email.value))
			{
				parent.mainFrame.document.location.href="../noticias/entrada.php?email=" + document.formLeft.email.value + 
																								"&claven=" + document.formLeft.claven.value;
				document.formLeft.reset();
				window.setTimeout("location.reload()",3000);
			}
			else
				alert('Formato de e-mail erroneo.');
		}

		function Noticias2()
		{
			if (document.formLeft.email.value != '')
			{
				if (ValidarEmail(document.formLeft.email.value))
				{
					parent.mainFrame.document.location.href="../noticias/entrada.php?email=" + document.formLeft.email.value + 
																									"&claven=" + document.formLeft.claven.value;
					document.formLeft.reset();
					window.setTimeout("location.reload()",3000);
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
			{
				parent.mainFrame.document.location.href="../noticias/entrada.php?email=SI&claven=";
				document.formLeft.reset();
			}
		}

		function Noticias3()
		{
			parent.mainFrame.document.location.href="../marcos/main.htm";
		}

		function Noticias4()
		{
			parent.mainFrame.document.location.href="../noticias/entrada.php?email=&claven=";
		}

		function Noticias5()
		{
			if (ValidarEmail(document.formErrPass.email.value))
			{
				document.location.href="../noticias/entrada.php?email=" + document.formErrPass.email.value + 
																								"&claven=" + document.formErrPass.claven.value;
				parent.setTimeout("leftFrame.document.location.reload()",3000);
			}
			else
				alert('Formato de e-mail erroneo.');
		}

		function BajaBoletin()
		{
			if (confirm('Confirma la baja del Boletín de Noticias'))
				document.location.href="../noticias/baja.php";
		}

		function RecargarTodo()
		{
			parent.setTimeout("leftFrame.document.location.reload()",3000);
			parent.mainFrame.document.location.href="../marcos/main.htm";
		}

		function FerSubmitLeft()
		{
			document.formLeft.submit();
			document.formLeft.reset();
		}

		function FerSubmitPre()
		{
			lError = 0;
			if (document.formPre.nombre.value == '')
				lError = 1;
			if (document.formPre.apellidos.value == '')
				lError = 1;
			if (document.formPre.email.value == '')
				lError = 1;
			if (document.formPre.telefono.value == '')
				lError = 1;
			if (document.formPre.cursos.value =='')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formPre.email.value))
				{
					document.formPre.submit();
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');
		}

		function FerSubmitAlta()
		{
			lError = 0;
			if (document.formAlta.nombre.value == '')
				lError = 1;
			if (document.formAlta.apellidos.value == '')
				lError = 1;
			if (document.formAlta.email.value == '')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formAlta.email.value))
				{
					document.formAlta.submit();
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');
		}

		function ImprimirPagina()
		{
			if (window.print)
				window.print();
			else
				alert("Lo siento, pero a tu navegador no se le puede ordenar imprimir" +
							" desde la web. Actualizate o hazlo desde los menús");
		}

		function doBlink()
		{
			var blink = document.all.tags("BLINK");
			for (var i=0; i<blink.length; i++)
				blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
		}
		
		function startBlink() 
		{
			if (document.all)
				setInterval("doBlink()",1000);
		}
		
		function high(which2)
		{
			theobject=which2;
			highlighting=setInterval("highlightit(theobject)",10);
		}
		
		function low(which2)
		{
			clearInterval(highlighting);
			which2.filters.alpha.opacity=50;
		}

		function highlightit(cur2)
		{
			if (cur2.filters.alpha.opacity < 100)
				cur2.filters.alpha.opacity+=2;
			else if (window.highlighting)
				clearInterval(highlighting);
		}
		
		function initTop() 
		{
			setTimeout('document.location.reload()',16000);
			setTimeout('startBlink()',7000);
		}

		function ferSubmitAltaForo()
		{
			lError = 0;
			if (document.formAltaForo.usuario.value == '')
				lError = 1;
			if (document.formAltaForo.asunto.value == '')
				lError = 1;
			if (document.formAltaForo.texto.value == '')
				lError = 1;
			if (lError == 0)
			{
				document.formAltaForo.texto.value = ConvertBR(document.formAltaForo.texto.value);
				document.formAltaForo.submit();
			}
			else
				alert('Hay que rellenar todos los campos.');
		}

		function ferSubmitAltaForoRe()
		{
			lError = 0;
			if (document.formAltaForoRe.usuario.value == '')
				lError = 1;
			if (document.formAltaForoRe.asunto.value == '')
				lError = 1;
			if (document.formAltaForoRe.texto.value == '')
				lError = 1;
			if (lError == 0)
			{
				document.formAltaForoRe.texto.value = ConvertBR(document.formAltaForoRe.texto.value);
				document.formAltaForoRe.submit();
			}
			else
				alert('Hay que rellenar todos los campos.');
		}

		function textCounter(field, maxlimit)
		{
			if (field.value.length > maxlimit)
			{
				field.value = field.value.substring(0, maxlimit);
				alert("Límite del texto alcanzado.");
			}
		}
		
		function ConvertBR(input) 
		{
			var output = "";
			for (var i = 0; i < input.length; i++) 
			{
				if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) 
				{
					i++;
					output += "<BR>";
				}
				else
					output += input.charAt(i);
				}
			return output;
		}

		function FerSubmitIns()
		{
			if (document.formInscripcion.ciudad.value == 0)
				alert('Hay que seleccionar una ciudad');
			else
				document.formInscripcion.submit();
		}

		function FerSubmitSel()
		{
			lError = 0;
			if (document.formSeleccion.nombre.value == '')
				lError = 1;
			if (document.formSeleccion.apellidos.value == '')
				lError = 1;
			if (document.formSeleccion.dni.value == '')
				lError = 1;
			if (document.formSeleccion.email.value == '')
				lError = 1;
			if (document.formSeleccion.telefono.value == '')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formSeleccion.email.value))
				{
					lError = 1;
					for (var i = 0; i < document.formSeleccion.elements.length; i++)
					{
						var e = document.formSeleccion.elements[i];
						if ((e.type == 'checkbox') && (e.checked == true))
							lError = 0;
					}
					if (lError == 0)
						document.formSeleccion.submit();
					else
						alert('Hay que seleccionar al menos un curso.');
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');
		}

		function FerSubmitSelPago()
		{
			lError = 0;
			if (document.formSeleccion.nombre.value == '')
				lError = 1;
			if (document.formSeleccion.apellidos.value == '')
				lError = 1;
			if (document.formSeleccion.dni.value == '')
				lError = 1;
			if (document.formSeleccion.email.value == '')
				lError = 1;
			if (document.formSeleccion.telefono.value == '')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formSeleccion.email.value))
				{
					lError = 1;
					for (var i = 0; i < document.formSeleccion.elements.length; i++)
					{
						var e = document.formSeleccion.elements[i];
						if ((e.type == 'radio') && (e.checked == true))
							lError = 0;
					}
					if (lError == 0)
						document.formSeleccion.submit();
					else
						alert('Hay que seleccionar un curso.');
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');
		}

		function FerSubmitPrePro()
		{
			lError = 0;
			if (document.formPre.nombreAlu.value == '')
				lError = 1;
			if (document.formPre.nombrePro.value == '')
				lError = 1;
			if (document.formPre.email.value == '')
				lError = 1;
			if (document.formPre.pregunta.value =='')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formPre.email.value))
				{
					document.formPre.submit();
				}
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');
		}
		
		function FerSubmitMat1()
		{
			lError = 0;
			if (document.formMaterial.nombre.value == '')
				lError = 1;
			if (document.formMaterial.apellidos.value == '')
				lError = 1;
			if (document.formMaterial.dni.value == '')
				lError = 1;
			if (document.formMaterial.direccion.value == '')
				lError = 1;
			if (document.formMaterial.localidad.value == '')
				lError = 1;
			if (document.formMaterial.cp.value == '')
				lError = 1;
			if (document.formMaterial.email.value == '')
				lError = 1;
			if (document.formMaterial.telefono.value == '')
				lError = 1;
			if (lError == 0)
			{
				if (ValidarEmail(document.formMaterial.email.value))
					lError = 0;
				else
					alert('Formato de e-mail erroneo.');
			}
			else
				alert('Hay que rellenar los campos obligatorios.');

			if (lError == 0)
			{
        lError = 1;
        for (var i = 0; i < document.formMaterial.elements.length; i++) {
          var e1 = document.formMaterial.elements[i];
          var e2 = document.formMaterial.elements[i+1];
          if ((e1.type == 'checkbox') && (e1.checked == true) && (e2.value!=0)) lError = 0;
        }
        if (lError==1) alert('Hay que seleccionar al menos un material y su cantidad.');
//        else {
//          lError = 1;
//          for (var i = 0; i < document.formMaterial.elements.length; i++) {
//            var e = document.formMaterial.elements[i];
//            if ((e.type == 'select-one') && (e.value != 0) && (!e.disabled)) lError = 0;
//          }
//          if (lError==1) alert('Debe seleccionar la cantidad.');
//        }
  
        if (lError==0) document.formMaterial.submit();
      }
		}
		
		function FerSubmitMat2()
		{
			if (document.formMaterial2.formaPago[0].checked || document.formMaterial2.formaPago[1].checked) document.formMaterial2.submit();
			else alert('Hay que seleccionar la forma de pago.'); 
		}
