function esEmail(str)  
{
  var supported = 0; 
  if (window.RegExp) { 
    var tempStr = "a"; 
    var tempReg = new RegExp(tempStr); 
    if (tempReg.test(tempStr)) 
      supported = 1; 
  } 
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$"); 
  return (!r1.test(str) && r2.test(str)); 
}

function checkInscripciones(theForm)
{	
//alert(theForm.identificador[0].checked);
	///////////////////////////////////////////////////////////Nombre
		
	if (theForm.nombre.value.length < 1)
	{
		alert("Por favor introduzca el Nombre");
		theForm.nombre.focus();
		return (false);
	}
	
		///////////////////////////////////////////////////////////Apellidos
		
	if (theForm.apellidos.value.length < 1)
	{
		alert("Por favor introduzca el Apellido");
		theForm.apellidos.focus();
		return (false);
	}

	///////////////////////////////////////////////////////////Cargo que desempeña
		
	if (theForm.cargo.value.length < 1)
	{
		alert("Por favor introduzca el Cargo que desempeña");
		theForm.cargo.focus();
		return (false);
	}

	
	//////////////////////////////////////////////////////////Dirección
	if (theForm.direccion.value.length < 1)
	{
		alert("Por favor introduzca la Dirección");
		theForm.direccion.focus();
		return (false);
	}
	
	///////////////////////////////////////////////////////////Cpostal

if (theForm.cpostal.value.length < 5)
  {
    alert("Por favor introduzca el Código Postal\n(mínimo 5 caracteres)");
    theForm.cpostal.focus();
    return (false);
  }  
  var checkOK = "0123456789";
  var checkStr = theForm.cpostal.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("El Código postal no es correcto. Escríbalo de nuevo, por favor");
    theForm.cpostal.focus();
    return (false);
  }  
	
	//////////////////////////////////////////////////////////Ciudad
	if (theForm.ciudad.value.length < 1)
	{
		alert("Por favor introduzca la Ciudad");
		theForm.ciudad.focus();
		return (false);
	}
/////////////////////////////////////////////////////////NIF/CIF	
	if (theForm.nif.value == "")
  {
    alert("¡ Introduzca \"CIF o NIF\" !");
    theForm.nif.focus();
    return (false);
  }

if (theForm.identificador[1].checked)
{
  var resul = false;
  var temp = theForm.nif.value.toUpperCase();
  if (!/^[A-Za-z0-9]{9}$/.test(temp))
  {
    alert("El campo \"CIF\" no es correcto.\n\nDebe estar compuesto por:\n9 dígitos ");
     theForm.nif.focus();
     return (false);
  }
  if (!/^[ABCDEFGHKLMNPQS]/.test(temp))
  {
    alert("¡ El \"CIF\" introducido no es correcto !");
     theForm.nif.focus();
     return (false);
  }
  var v1 = new Array(0,2,4,6,8,1,3,5,7,9); 
  var temp = 0; 
  var temp1;
  for( i = 2; i <= 6; i += 2 ) 
    {
      temp = temp + v1[ parseInt(theForm.nif.value.substr(i-1,1)) ];
      temp = temp + parseInt(theForm.nif.value.substr(i,1));
    };
  temp = temp + v1[ parseInt(theForm.nif.value.substr(7,1)) ];
  temp = (10 - ( temp % 10));
  recibecif = (theForm.nif.value).toUpperCase()
  sacacontrol = recibecif.charAt(8)
  sincontrol = recibecif.slice(0,-1)
  nifbueno = (sincontrol+temp);
//  if (nifbueno == recibecif)
//  {
//    alert("¡ El CIF es Ok !");
//  }
  if ((temp != 10) && ((sacacontrol) != (temp)))
  {
    alert("¡ El \"CIF\" introducido no es correcto !");
    theForm.nif.focus();
    return (false);
  }
}


if (theForm.identificador[0].checked)
{
if (theForm.nif.value.length < 9)
  {
    alert("El campo \"NIF\" no es correcto.\n\nDebe contener:\n8 dígitos y la letra del NIF\n(complete con ceros a la izquierda si fuera necesario) ");
	theForm.nif.focus();
    return (false);
  }
  var checkOK = "0123456789abcdefghjklmnpqrstvwxyzABCDEFGHJKLMNPQRSTVWXYZ";
  var checkStr = theForm.nif.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("¡ El \"NIF\" introducido no es correcto !");
    theForm.nif.focus();
    return (false);
  }
	recibedni = (theForm.nif.value).toUpperCase()
	sacaletra = recibedni.charAt(8) 
	sinletra = recibedni.slice(0,-1)
	
	cadena="TRWAGMYFPDXBNJZSQVHLCKET" 
	posicion = sinletra % 23 
	letra = cadena.substring(posicion,posicion+1) 

if ((letra) != (sacaletra))
  {
    alert("¡ El \"NIF\" introducido no es correcto !");
    theForm.nif.focus();
    return (false);
  }
}



	///////////////////////////////////////////////////////////Telefono
 if (theForm.telefono.value.length < 9)
  {
    alert("Por favor introduzca un Teléfono");
    theForm.telefono.focus();
    return (false);
  }  
 var checkOK = "0123456789";
  var checkStr = theForm.telefono.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("El teléfono no es correcto. Escríbala de nuevo, por favor");
    theForm.telefono.focus();
    return (false);
  }  
  	
	/////////////////////////////////////////////////////////// E-mail
	
	if (theForm.email.value == "") {
		alert("Por favor introduzca un E-mail");
		theForm.email.focus();
		return (false);
		
	} else { 
	
	if (!esEmail(theForm.email.value))
	  {
		alert("La dirección e-mail no es correcta.\nEscríbala de nuevo, por favor");
		theForm.email.focus();
		return (false);
	  }
	  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@._-\t\r\n\f";
	  var checkStr = theForm.email.value;
	  var allValid = true;
	  for (i = 0;  i < checkStr.length;  i++)
	  {
	    ch = checkStr.charAt(i);
	    for (j = 0;  j < checkOK.length;  j++)
	      if (ch == checkOK.charAt(j))
	        break;
	    if (j == checkOK.length)
	    {
	      allValid = false;
	      break;
	    }
	  }
	  if (!allValid)
	  {
	    alert("La dirección e-mail no es correcta.\nEscríbala de nuevo, por favor");
	    theForm.email.focus();
	    return (false);
	  }
}

	///////////////////////////////////////////////////////////titulacion
		
	if (theForm.titulacion.value.length < 1)
	{
		alert("Por favor introduzca su Especialidad o Titulación");
		theForm.titulacion.focus();
		return (false);
	}
	
	if (theForm.factura.checked)
	{
		///////////////////////////////////////////////////////////razon_social			
		if (theForm.razon_social.value.length < 1)
		{
			alert("Por favor introduzca su Razón Social");
			theForm.razon_social.focus();
			return (false);
		}	
		
		///////////////////////////////////////////////////////////direccion_factura			
		if (theForm.direccion_factura.value.length < 1)
		{
			alert("Por favor introduzca una Dirección para la Factura");
			theForm.direccion_factura.focus();
			return (false);
		}
	}
	
	return (true);
}
