/*------------------------------------------------------------------------
sendEMail( target_email )
Crea una nueva ventana sin barra de menú con el formulario de envío de 
correo electrónico. El formulario envía sus datos al servlet "NotificacionEmail"
que es quien envía el mensaje a través del servidor.
------------------------------------------------------------------------*/
function sendEMail( target_email ) 
{
   mailWindow=window.open("","mailWindow","menubar=no,width=450,height=310");
   mailWindow.document.writeln ("<HTML>");
   mailWindow.document.writeln ("<HEAD>");
   mailWindow.document.writeln ("<TITLE>Mensaje de correo electrónico</TITLE>");
   mailWindow.document.writeln ("<script type=\"text/JavaScript\" src=\"http://www.puj.edu.co/scripts_globales/mailer.js/\"></script>");
   mailWindow.document.writeln ("</HEAD>");
   mailWindow.document.writeln ("<BODY bgcolor=white>");
   mailWindow.document.writeln ("<FORM NAME=\"form_email\" ACTION=\"http://appweb.puj.edu.co/sendmail/servlet/NotificacionEmail/\" METHOD=\"POST\">");
   mailWindow.document.writeln ("<center>");
   mailWindow.document.writeln ("<table width=450>");
   mailWindow.document.writeln ("<tr>");
   mailWindow.document.writeln ("<td>Para:</td>");
   mailWindow.document.writeln ("<td><INPUT TYPE=\"text\" NAME=\"destino\" SIZE=30 MAXLENGTH=40 VALUE=\"" + target_email + "\"></td>");
   mailWindow.document.writeln ("</tr><tr>");
   mailWindow.document.writeln ("<td>De:</td>");
   mailWindow.document.writeln ("<td><INPUT TYPE=\"text\" NAME=\"frm_email\" SIZE=30 MAXLENGTH=40></td>");
   mailWindow.document.writeln ("</tr><tr>");
   mailWindow.document.writeln ("<td>Asunto:</td>");
   mailWindow.document.writeln ("<td><INPUT TYPE=\"text\" NAME=\"asunto\" SIZE=40 MAXLENGTH=40></td>");
   mailWindow.document.writeln ("</tr><tr>");
   mailWindow.document.writeln ("<td colspan=2>Mensaje:<BR><TEXTAREA NAME=\"frm_mensaje\" ROWS=\"7\" COLS=\"49\" ></TEXTAREA></td>");
   mailWindow.document.writeln ("</tr><tr>");
   mailWindow.document.writeln ("<td colspan=2>Ingrese este c&oacute;digo <img src=\"http://appweb.puj.edu.co/sendmail/servlet/ImageCode/\" width=\"50\" height=\"17\"> en este campo <input name=\"codSeg\" type=\"text\" id=\"codSeg\" size=\"5\" maxlength=\"5\"></td>");
   mailWindow.document.writeln ("</tr><tr>");
   mailWindow.document.writeln ("<td colspan=2><INPUT TYPE=\"hidden\" NAME=\"mensaje_respuesta\" VALUE=\"Mensaje enviado satisfactoriamente\"><INPUT TYPE=\"hidden\" NAME=\"close_window\" VALUE=\"true\"><INPUT TYPE=\"submit\" VALUE=\"Enviar\"><INPUT NAME=\"name\" TYPE=\"button\" VALUE=\"Cerrar\" onClick=\"self.close()\"></td></tr>");
   mailWindow.document.writeln ("</TABLE>");
   mailWindow.document.writeln ("</CENTER></FORM>");
   mailWindow.document.writeln ("</BODY>");
   mailWindow.document.writeln ("</HTML>");
   mailWindow.focus();
}
/*------------------------------------------------------------------------
recomendarWebPage( url )
Crea una nueva ventana sin barra de menú con el formulario de envío de 
correo electrónico. El formulario envía sus datos al servlet "Recomendar"
que es quien envía el mensaje a través del servidor.
------------------------------------------------------------------------*/
function recomendarWebPage( url )
{
   mailWindow=window.open("http://appweb.puj.edu.co/sendmail/recomendar.jsp?url="+url,"recomendarWindow","menubar=no,width=350,height=500,scrollbars=yes");
}

function emailCheck (emailStr) 
{
	/* Verificar si el email tiene el formato user@dominio. */
	var emailPat=/^(.+)@(.+)$/ 

	/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" 

	/* Verifica los caracteres que son válidos en una dirección de email */
	var validChars="\[^\\s" + specialChars + "\]" 
	var quotedUser="(\"[^\"]*\")" 

	/* Verifica si la dirección de email está representada con una dirección IP Válida */ 
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

	/* Verificar caracteres inválidos */ 
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

	/*domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
		//alert("Email address seems incorrect (check @ and .'s)")

		return false
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	// Si el user "user" es valido 
	if (user.match(userPat)==null) 
	{
		// Si no

		//alert("El nombre de usuario no es válido.")

		return false
	}

	/* Si la dirección IP es válida */
	var IPArray=domain.match(ipDomainPat)

	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				//alert("IP de destino inválida")

				return false
			}
		}

		return true
	}

	var domainArray=domain.match(domainPat)

	if (domainArray==null) 
	{
		//alert("El dominio parece no ser válido.")

		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length

	if (domArr[len-1].length < 2  ||  domArr[len-1].length > 3) 
	{ 
		//alert("La dicrección debe tener 3 letras si es ."com" o 2 si en de algún pais.")

		return false
	}

	if (len < 2) 
	{
		//var errStr="La dirección es erronea"

		//alert(errStr)

		return false
	}

	// La dirección de email ingresada es Válida
	return true;
}