$(document).ready(function() {

	$("#informacionLegal1").fancybox({
		'width'			: 550,
		'height'		: 260,
		'autoScale'		: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'type'			: 'iframe'
	});

	$("#informacionLegal2").fancybox({
		'width'			: 550,
		'height'		: 260,
		'autoScale'		: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'none',
		'type'			: 'iframe'
	});
});

function quitarBlancos(formu)
{
  for (e=0; e<formu.elements.length; e++)
  {
    if ((formu.elements[e].type  == "text") || (formu.elements[e].type  == "textarea"))
    {
      str = formu.elements[e].value;
      for (i=0; (str.charAt(i) ==" ") && (i<str.length); i++);
      for (f=str.length-1; (str.charAt(f) ==" ") && (f>0); f--);
      if (i>f) str="";
      else str=str.substring(i,f+1);
      formu.elements[e].value = str;
    }
  }
}


function vacio(str)
{
  if (str.length == 0) return true;
  else return false;
}


function Error(textoError)
{
  textoCompleto="No has introducido "+textoError;
  alert(textoCompleto);
}



function emailOK(email)
{
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)) return true;
  else return false;
}

function telefonoOK(telf)
{
  if (!(/^\d{9}$/.test(telf))) return false;
  else return true;
}



function EnviarDatosInfo()
{

  var f = document.formularioInfo;
  
 
  quitarBlancos(f);

  if (vacio(f.nombre.value)) Error("el Nombre y los Apellidos");

  else if (vacio(f.email.value)) Error("el Email");
  else if (!emailOK(f.email.value)) alert ("El formato del Email introducido no es correcto");
  else if (vacio(f.confirmarEmail.value)) Error("la confirmación del Email");
  else if (f.email.value != f.confirmarEmail.value) alert ("Los emails introducidos no coinciden");

  else if (vacio(f.movil.value)) Error("el Teléfono Móvil");
  else if (!telefonoOK(f.movil.value)) alert ("El formato del Teléfono introducido no es correcto.  Recuerda que debes introducir sólo 9 dígitos consecutivos.");

  else if (f.aceptarInfo.checked) f.submit();
  else alert('Debes seleccionar la casilla "he leído protección de datos"');

}




function EnviarDatosLlamada()
{

  var f = document.formularioLlamar;
  
 
  quitarBlancos(f);

  if (vacio(f.telefonoLlamar.value)) Error("el Teléfono");
  else if (!telefonoOK(f.telefonoLlamar.value)) alert ("El formato del Teléfono introducido no es correcto.  Recuerda que debes introducir sólo 9 dígitos consecutivos.");
  else if (vacio(f.telefonoLlamarConfirmar.value)) Error("la confirmación del Teléfono");
  else if (f.telefonoLlamar.value != f.telefonoLlamarConfirmar.value) alert ("Los teléfonos introducidos no coinciden");

  else if (f.aceptarLlamada.checked) f.submit();
  else alert('Debes seleccionar la casilla "he leído protección de datos"');

}

