// ----------------------------------------
function validateLoginForm(frm) {
	frm.txtLogin.value = trimAll(frm.txtLogin.value);
	if (isEmpty(frm.txtLogin.value)) {
		alert('El login es requerido.');
		frm.txtLogin.focus();
		return false;
	}

	frm.txtPassword.value = trimAll(frm.txtPassword.value);
	if (isEmpty(frm.txtPassword.value)) {
		alert('El Password es requerido.');
		frm.txtPassword.focus();
		return false;
	}
	return true;
}
// ----------------------------------------
function trimAll(str) {
  if (str!=null) {
    while (str.length > 0 &&
      "\n\r\t ".indexOf(str.charAt(str.length - 1)) != -1)
      str = str.substring(0, str.length - 1);
    while (str.length > 0 &&
      "\n\r\t ".indexOf(str.charAt(0)) != -1)
      str = str.substring(1, str.length);
  }
  return str;
}
// ----------------------------------------
function isEmpty(str) {
  if (str==null || str=="")
    return true;
  return false;
}
// ----------------------------------------

	var login = getSessionData("login");
	var nom_usuario = getSessionData("nom_usuario");
	var genero = getSessionData("ind_genero");

	// El usuario SI esta logueado(a) ...
	if (login != null ) {
		document.write("<img class=\"figure-left\" src=\"/disenos/v3/images/cuerpo/community.gif\" width=\"32\" height=\"26\">");		

		document.write("<p class=\"para\">");
		if (genero == 'M') {
			document.write("Bienvenido ");
		} else if (genero == 'F') {
			document.write("Bienvenida ");
		} else {
			document.write("Bienvenid@ ");
		}

		if (nom_usuario != null) {
			document.write("<b>" + nom_usuario + "</b>");
		} else {
			document.write("<b>" + login + "</b>");
		}
		document.write("</p>");
		document.write("<p class=\"para\">&#187;");
		document.write("<a href=\"javascript:cambiarAPagina('LOGOUT');\" onClick=\"return cambiarAPagina('LOGOUT');\" onMouseOver=\"status='';\">Desconectar</a>");
		document.write("</p>");
	// El usuario NO esta logueado(a) ...
	} else {
		var URL_Value = top.location.href;
		var MKC_Value = "http://www.elfinancierocr.com/cgi/mkc.pl";
		var CN_Value  = "EF_SESSION";

		document.write("<form id=\"frmLogin\" name=\"frmLogin\" method=\"post\" action=\"http://registro.nacion.com/regfinanciero/servlet/actionLogin\" onSubmit=\"return validateLoginForm(this);\">");
		document.write("<input type=\"hidden\" name=\"URL\" value=\"" + URL_Value + "\">");
		document.write("<input type=\"hidden\" name=\"MKC\" value=\"" + MKC_Value + "\">");
		document.write("<input type=\"hidden\" name=\"CN\"  value=\"" + CN_Value + "\">");
		document.write("<span class=\"exchange\">Usuario</span>&nbsp;");
		document.write("<input name=\"txtLogin\" type=\"text\" size=\"10\" maxlength=\"30\"/>");
		document.write("<br />");
		document.write("<span class=\"exchange\">Clave</span>&nbsp;");
		document.write("<input name=\"txtPassword\" type=\"password\" size=\"10\" maxlength=\"10\"/>");
		document.write("<p>");
		document.write("<input type=\"submit\" value=\"Ingresar\" name=\"cmd_ingresar\" style=\"font-family: Arial; font-size: 8pt; font-weight: bold\">");
		document.write("</p>");
		document.write("</form>");
		document.write("<p align=\"left\">");
		document.write("<a href=\"http://registro.nacion.com/regfinanciero/html/elfinancierocr/RetrievePassword.jsp?URL=" + URL_Value + "&MKC=" + MKC_Value + "&CN=" + CN_Value + "\">");
		document.write("&iquest;Olvid&oacute; la contrase&ntilde;a?</a>");
		document.write("<br>");
		document.write("Reg&iacute;strese <a href=\"https://pagos.interamerica.net/capitalfinanciero/ivpayment?cid=LANACION&sid=001\"><b>aqu&iacute;</b></a>");
		document.write("</p>");
	}
