var ns4 = (document.layers) ? 1:0;     
var ie4 = (document.all)    ? 1:0;
var stAlert = new Object();
var actAlert = 0;

function cargar()
{
  stAlert[0] = "Hmmm... creo que has olvidado algo";
  stAlert[1] = "Escribe tu e-mail, por favor";
  stAlert[2] = "Creo que no es tan complicado ¿no?";
  stAlert[3] = "¿Todavía no has acabado?";
  stAlert[4] = "Sólo te estoy pidiendo el e-mail";
  stAlert[5] = "¡Teclea tu dirección, por favor!";
  stAlert[6] = "Estás acabando con mi paciencia...";
  stAlert[7] = "¡Allá tú! Si no pones tu dirección, no podré contestarte";
  stAlert[8] = "Es la penúltima vez que te lo pido";
  stAlert[9] = "¡¡¡¡ E S C R I B E   T U   E - M A I L !!!!";
}  

function reset(fmEmail)
{
 fmEmail.reset();
}

function enviar(formulario)
{
	if (formulario.realname.value==""){
		alert("Por favor, indica el nombre de la persona de contacto");
		formulario.realname.focus();
	} else if (formulario.email.value==""){
		alert("Necesitamos tu dirección de e-mail para contactar contigo");
		formulario.email.focus();
	
	} else if (!emailOK(formulario.email.value)){
		alert("La direccion de e-mail tiene un formato incorrecto");
		formulario.email.focus();
	} else {
		formulario.aliasname.value=formulario.realname.value
		formulario.aliasmail.value=formulario.email.value
		formulario.submit()
	}
}

function send(fmEmail)
{
 if (fmEmail.Nombre.value=="")
 {
  alert("¿No vas a decirnos tu nombre?");
  fmEmail.Nombre.focus();
 }
 else if (CheckIn(fmEmail)) 
 {
   // Inicio de pasar formulario a campo C
  Churro(fmEmail,'C','Nombre','Mail','Empresa','Cargo','Cuentas','Fuente','Estado','Comentario','Tipo');
  // Fin  
  fmEmail.submit();
 }
}

function emailOK(email)
{
	var patron  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (patron.test(email)) 
	{
		return true;
	}
	else
	{ 
		return false;
	}
}


function CheckIn(f)
{
  var stText = "" + f.elements['Mail'].value;
  if (stText == "")
  {
    alert(stAlert[actAlert]);
    actAlert = ++actAlert % 10;
    f.Mail.focus();
    return(false);
  }
  if (checkEmail(stText))
  {
	return(true); 
  }
  else
  {
    alert("La direccion de e-mail tiene un formato incorrecto");
    f.Mail.focus();
    return(false); 
  }
}

function checkEmail(email)
{
  var a = email.indexOf('@'), p = email.lastIndexOf('.'), l = email.length;
  if (a<1 || a>l-5 || a>p-2 || p<l-5 || p>l-3) return false;
  var especial=true;
  var sortir=false;
  for (var i=a+1; i<l && !sortir; i++)
  {
    var c = email.charAt(i).toLowerCase();
    if ((c>='0' && c<='9') || (c>='a' && c<='z')) 
	  especial = false;
    else
	  if (c=='-' || c=='.') 
	  {
        if (especial) sortir = true;
        else especial = true;
      }
      else sortir = true;
  }
  if (especial) sortir = true;
  return(!sortir);
}
