function fn_ValidarUnEmailValido (pvStr_Cadena)
{
	var arroba = pvStr_Cadena.indexOf ("@");
	var i;
	
	if (arroba == -1)
		return false;
		
	var arroba2 = pvStr_Cadena.indexOf ("@", arroba + 1);
	
	if (arroba2 != -1)
		return false;
	
	if (arroba == 0)
		return false;
	
	if (arroba == pvStr_Cadena.length - 1)
		return false;
	
	for (i = 0; i < pvStr_Cadena.length; i++)
	{
		if (pvStr_Cadena.substr (i, 1) == "/" || pvStr_Cadena.substr (i, 1) == " " || pvStr_Cadena.substr (i, 1) == ";" || pvStr_Cadena.substr (i, 1) == "," || pvStr_Cadena.substr (i, 1) == String.fromCharCode (34) || pvStr_Cadena.substr (i, 1) == String.fromCharCode (39))
			return false;
	}

	return true;
}

function fn_BusquedaGeneral_KeyPress (evento)
{
	if (!evento)
		var evento = window.event;

	if (evento.keyCode == 13)
		fn_BusquedaGeneral ();
}

function fn_BusquedaGeneral ()
{
	var control = document.getElementById ("txt_BusquedaGeneral");
	var texto = trim (control.value);
	
	texto = fn_ReemplazarComillasSimples (texto);	// Reemplazamos las comillas simples por espacios en blanco.
	texto = trim (texto);

	if (texto == "")			
	{
		alert ("Ingrese el texto a buscar.");
		control.focus ();
	}
	else	
	{
		texto = fn_Escape (texto);
		
		window.location.href = "./resultado.php?buscar=" + texto;
	}
}

function fn_Escape (cadena)
{
	var resultado = escape (cadena);
	
	while (resultado.indexOf ("+") >= 0)
		resultado = resultado.replace ("+", "%2B");

	return resultado;
}

function fn_ReemplazarComillasSimples (cadena)
{
	var caracter = "'";
	var resultado = cadena;
	
	while (resultado.indexOf (caracter) >= 0)
		resultado = resultado.replace (caracter, " ");

	return resultado;
}

function trim (cadena)
{
	var i;
	var cadena2 = cadena;
	var cadena3;
	
	if (cadena.length == 0) return cadena;
	
	for (i = 0; i < cadena.length; i++)
	{
		if (cadena.substr (i, 1) == ' ')
			cadena2 = cadena.substr (i + 1);
		else
			break;
	}

	if (cadena2.length == 0) return cadena2;
	
	cadena3 = cadena2;
	
	for (i = cadena2.length - 1; i >= 0; i--)
	{
		if (cadena2.substr (i, 1) == ' ')
			cadena3 = cadena2.substr (0, i);
		else
			break;
	}

	return cadena3;
}

function fn_Casita_MouseOver ()
{
	clearTimeout (popTimer);
	hideAllBut (0);
	document.getElementById ("img_Casita").src = "./img/btn0b_res3.gif";
}

function fn_Casita_MouseOut ()
{
	popTimer = setTimeout ("document.getElementById ('img_Casita').src = './img/btn0b.gif'", 500);
}

function fn_MostrarMapa ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Seteamos el DIV del mapa.	
	altoMinimo = parseInt ((document.body.clientWidth - 40) / 1.9);
	
	if (document.body.clientHeight < altoMinimo)
	{
		alto = document.body.clientHeight - 40;
		ancho = parseInt (alto * 1.9);

		left = parseInt ((document.body.clientWidth - ancho) / 2);
		top = 20;
	}
	else
	{
		ancho = document.body.clientWidth - 40;
		alto = parseInt (ancho / 1.9);

		top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;;
		left = 20;
	}	

	document.getElementById ("div_Mapa").style.width = ancho.toString () + "px";
	document.getElementById ("div_Mapa").style.height = alto.toString () + "px";
	document.getElementById ("div_Mapa").style.top = top.toString () + "px";
	document.getElementById ("div_Mapa").style.left = left.toString () + "px";
	
	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Mapa").style.display = "block";
}

function fn_CerrarMapa ()
{
	document.getElementById ("div_Mapa").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_MostrarClima ()
{
	var ancho, alto, top, left;

	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Seteamos el DIV del mapa.	
	ancho = 342; // 340
	alto = 476;
	left = parseInt ((document.body.clientWidth - ancho) / 2);
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;;

	document.getElementById ("div_Clima").style.width = ancho.toString () + "px";
	document.getElementById ("div_Clima").style.height = alto.toString () + "px";
	document.getElementById ("div_Clima").style.top = top.toString () + "px";
	document.getElementById ("div_Clima").style.left = left.toString () + "px";
	
	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Clima").style.display = "block";
}

function fn_CerrarPronostico ()
{
	document.getElementById ("div_Clima").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

window.onscroll = fn_ScrollVentana;

function fn_ScrollVentana ()
{
	var objeto1 = document.getElementById ("div_OpcionesHijas");
	var objeto2 = document.getElementById ("div_Filtros");
	var objeto3 = document.getElementById ("div_Mapa");
	var objeto4 = document.getElementById ("div_Clima");
	var objeto5 = document.getElementById ("div_Login");
	var objeto6 = document.getElementById ("div_MensajeSistemaExterno");
	var objeto7 = document.getElementById ("div_EsperaSistemaExterno");
	var objeto8 = document.getElementById ("div_MensajeRegistracionOk");
	var objeto9 = document.getElementById ("div_Recuperacion");

	var alto, top;
	
	if (objeto1)
	{
		if (objeto1.style.display == "block")	
		{
			alto = objeto1.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto1.style.top = top.toString () + "px";
		}
	}

	if (objeto2)
	{
		if (objeto2.style.display == "block")	
		{
			alto = objeto2.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto2.style.top = top.toString () + "px";
		}
	}

	if (objeto3)
	{
		if (objeto3.style.display == "block")	
		{
			alto = objeto3.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto3.style.top = top.toString () + "px";
		}
	}

	if (objeto4)
	{
		if (objeto4.style.display == "block")	
		{
			alto = objeto4.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto4.style.top = top.toString () + "px";
		}
	}

	if (objeto5)
	{
		if (objeto5.style.display == "block")	
		{
			alto = objeto5.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto5.style.top = top.toString () + "px";
		}
	}

	if (objeto6)
	{
		if (objeto6.style.display == "block")	
		{
			alto = objeto6.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto6.style.top = top.toString () + "px";
		}
	}

	if (objeto7)
	{
		if (objeto7.style.display == "block")	
		{
			alto = objeto7.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto7.style.top = top.toString () + "px";
		}
	}

	if (objeto8)
	{
		if (objeto8.style.display == "block")	
		{
			alto = objeto8.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto8.style.top = top.toString () + "px";
		}
	}
	
	if (objeto9)
	{
		if (objeto9.style.display == "block")	
		{
			alto = objeto9.clientHeight;		
			top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
		
			objeto9.style.top = top.toString () + "px";
		}
	}
}

/* Objeto y funciones para AJAX. */
var xmlHttp;

function fn_QuitarBasuraExtremos (pvstr_Texto)
{
	var lvstr_Cadena = pvstr_Texto;
	var lvstr_Limpia = pvstr_Texto;
		
	if (lvstr_Cadena.length > 0)
	{
		for (i = 0; i < lvstr_Cadena.length; i++)
		{
			if (lvstr_Cadena.substr (i, 1) == " " || lvstr_Cadena.charCodeAt (i) == 10 || lvstr_Cadena.charCodeAt (i) == 13)
				lvstr_Limpia = lvstr_Cadena.substr (i + 1);
			else
				break;
		}
	
		lvstr_Cadena = lvstr_Limpia;
	
		for (i = lvstr_Cadena.length - 1; i >= 0; i--)
		{
			if (lvstr_Cadena.substr (i, 1) == " " || lvstr_Cadena.charCodeAt (i) == 10 || lvstr_Cadena.charCodeAt (i) == 13)
				lvstr_Limpia = lvstr_Cadena.substr (0, i);
			else
				break;
		}
	}
	
	return lvstr_Limpia;
}

function fn_InvocarAjax_Post (archivo, parametros)
{
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest ();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert ("Su navegador no soporta AJAX.");
				return false;
			}
		}
	}
	
	xmlHttp.onreadystatechange = fn_ProcesarRespuestaAjax;

	xmlHttp.open ("POST", archivo, true);	
	xmlHttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader ("Content-length", parametros.length);
	xmlHttp.setRequestHeader ("Connection", "close");
	xmlHttp.send (parametros);
}
	
function fn_ProcesarRespuestaAjax ()
{
	var resultado;
	
	if (xmlHttp.readyState == 4)
	{
		resultado = fn_QuitarBasuraExtremos (xmlHttp.responseText);	

		eval (resultado);
	}
}
/* Fin objeto y funciones para AJAX. */

function fn_AbrirVentanaLogin ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	document.getElementById ("txt_UsuLog").value = "";
	document.getElementById ("txt_Pwd").value = "";

	fn_HabilitarBotonesLogin ();

	document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "none";

	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Login").style.display = "block";

	// Seteamos el DIV del login.
	ancho = 400;
	alto = document.getElementById ("div_Login").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_Login").style.width = ancho.toString () + "px";
	document.getElementById ("div_Login").style.top = top.toString () + "px";
	document.getElementById ("div_Login").style.left = left.toString () + "px";

	document.getElementById ("txt_UsuLog").focus ();
}

function fn_CerrarVentanaLogin ()
{
	document.getElementById ("div_Login").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
	
	document.getElementById ("txt_DerivarSistema").value = "";
}

function fn_CerrarVentanaLogin_SinSistemaExterno ()
{
	document.getElementById ("div_Login").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_RealizarLogin ()
{
	var control_UsuLog = document.getElementById ("txt_UsuLog");
	var control_Pwd = document.getElementById ("txt_Pwd");
	var mensajeError = "";
	
	if (trim (control_UsuLog.value) == "")
	{
		mensajeError = "Debe ingresar el usuario.";
		control_UsuLog.focus ();
	} 
	else if (trim (control_Pwd.value) == "")
	{
		mensajeError = "Debe ingresar la contraseña.";
		control_Pwd.focus ();
	}

	if (mensajeError != "")
	{
		document.getElementById ("span_LeyendaProcesandoLogin").innerHTML = mensajeError;
		document.getElementById ("span_LeyendaProcesandoLogin").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "block"; }
	}
	else
	{
		fn_BloquearBotonesLogin ();

		document.getElementById ("span_LeyendaProcesandoLogin").innerHTML = "Validando usuario y contraseña, por favor espere...";
		document.getElementById ("span_LeyendaProcesandoLogin").className = "textoLeyendaProcesandoMicrositios";
	
		try { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "block"; }
		
		fn_InvocarAjax_Post ("usuarios_ajax.php", "txt_HacerLogin=-1&txt_UsuLog=" + fn_Escape (trim (control_UsuLog.value)) + "&txt_Pwd=" + fn_Escape (trim (control_Pwd.value)));
	}
}

function fn_ResultadoLogin (idUsuario, nombre, apellido)
{
	if (idUsuario == "")
	{
		// Ingreso fallido.
		fn_HabilitarBotonesLogin ();

		document.getElementById ("span_LeyendaProcesandoLogin").innerHTML = "Usuario y/o contraseña incorrectos.";
		document.getElementById ("span_LeyendaProcesandoLogin").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoLogin").style.display = "block"; }
	}
	else
	{
		// Ingreso exitoso.
		fn_CerrarVentanaLogin_SinSistemaExterno ();
		
		if (apellido != "")		
			document.getElementById ("span_NombreUsuarioLogueado").innerHTML = "&nbsp;&nbsp;" + nombre + "&nbsp;" + apellido;
		else
			document.getElementById ("span_NombreUsuarioLogueado").innerHTML = "&nbsp;&nbsp;" + nombre;
		
		document.getElementById ("img_IconoEnUsuarioLogueado").style.cursor = "pointer";
		document.getElementById ("span_TextoSalirEnUsuarioLogueado").style.cursor = "pointer";

		document.getElementById ("div_UsuarioNoLogueado").style.display = "none";
		document.getElementById ("div_UsuarioLogueado").style.display = "block";

		document.getElementById ("txt_IdUsuario").value = idUsuario;
		
		if (document.getElementById ("txt_DerivarSistema").value != "")
			fn_VerificarSistemaExternoHabilitado ();
	}
}

function fn_CerrarSesion ()
{
	document.getElementById ("img_IconoEnUsuarioLogueado").style.cursor = "wait";
	document.getElementById ("span_TextoSalirEnUsuarioLogueado").style.cursor = "wait";

	fn_InvocarAjax_Post ("usuarios_ajax.php", "txt_HacerCerrarSesion=-1");
}

function fn_SesionCerrada ()
{
	document.getElementById ("div_UsuarioNoLogueado").style.display = "block";
	document.getElementById ("div_UsuarioLogueado").style.display = "none";

	document.getElementById ("txt_IdUsuario").value = "";
}

function fn_txt_Pwd_KeyPress (evento)
{
	if (!evento)
		var evento = window.event;

	if (evento.keyCode == 13)
		fn_RealizarLogin ();
}

function fn_BloquearBotonesLogin ()
{
	document.getElementById ("tablaLogin").style.cursor = "wait";

	document.getElementById ("btn_Ingresar").style.cursor = "wait";
	document.getElementById ("btn_Ingresar").disabled = true;
}	

function fn_HabilitarBotonesLogin ()
{
	document.getElementById ("tablaLogin").style.cursor = "default";

	document.getElementById ("btn_Ingresar").style.cursor = "pointer";
	document.getElementById ("btn_Ingresar").disabled = false;
}

function fn_IngresoSistemaExterno (NomCto)
{
	document.getElementById ("txt_DerivarSistema").value = NomCto;

	if (document.getElementById ("txt_IdUsuario").value == "")
	{
		// No hay usuario logueado. Abrimos la ventana de login.
		fn_AbrirVentanaLogin ();
	}
	else
	{
		// Hay usuario logueado. Hay que ver si tiene habilitado el sistema en cuestión.
		fn_VerificarSistemaExternoHabilitado ();
	}
}

function fn_VerificarSistemaExternoHabilitado ()
{
	fn_AbrirVentanaEsperaSistemaExterno ();

	fn_InvocarAjax_Post ("usuarios_ajax.php", "txt_VerificarSistemaExterno=-1&txt_NomCtoSistema=" + document.getElementById ("txt_DerivarSistema").value);
}

function fn_ResultadoVerificacionSistemaExterno (resultado, UsuLog, Pwd, URLPos, ArcPos)
{
	fn_CerrarVentanaEsperaSistemaExterno ();

	if (resultado == "2")	// 2 = Sistema asignado.
	{
		document.getElementById ("txt_DerivarSistema").value = "";

		document.frm_SistemaExterno.user.value = UsuLog;
		document.frm_SistemaExterno.pass.value = Pwd;

		document.frm_SistemaExterno.action = URLPos + ArcPos;
		document.frm_SistemaExterno.submit ();
	}
	else if (resultado == "1")	// 1 = Sistema no asignado.
	{
		document.getElementById ("txt_DerivarSistema").value = "";

		document.getElementById ("span_MensajeSistemaExterno").innerHTML = "Su cuenta de usuario no est&aacute; habilitada para acceder a esta secci&oacute;n.";
		fn_AbrirVentanaMensajeSistemaExterno ();
	}
	else	// 0 = Usuario no logueado (se deslogueó en otra ventana).
	{
		fn_SesionCerrada ();
		fn_AbrirVentanaLogin ();
	}
}


function fn_AbrirVentanaMensajeSistemaExterno ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_MensajeSistemaExterno").style.display = "block";

	// Seteamos el DIV del mensaje.
	ancho = 520;
	alto = document.getElementById ("div_MensajeSistemaExterno").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_MensajeSistemaExterno").style.width = ancho.toString () + "px";
	document.getElementById ("div_MensajeSistemaExterno").style.top = top.toString () + "px";
	document.getElementById ("div_MensajeSistemaExterno").style.left = left.toString () + "px";

	document.getElementById ("btn_MensajeSistemaExterno_Aceptar").focus ();
}

function fn_AbrirVentanaMensajeRegistracionOk ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_MensajeRegistracionOk").style.display = "block";

	// Seteamos el DIV del mensaje.
	ancho = 520;
	alto = document.getElementById ("div_MensajeRegistracionOk").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_MensajeRegistracionOk").style.width = ancho.toString () + "px";
	document.getElementById ("div_MensajeRegistracionOk").style.top = top.toString () + "px";
	document.getElementById ("div_MensajeRegistracionOk").style.left = left.toString () + "px";

	document.getElementById ("btn_MensajeRegistracionOk_Aceptar").focus ();
}

function fn_CerrarVentanaMensajeSistemaExterno ()
{
	document.getElementById ("div_MensajeSistemaExterno").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_CerrarVentanaMensajeRegistracionOk ()
{
	document.getElementById ("div_MensajeRegistracionOk").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_AbrirVentanaEsperaSistemaExterno ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_EsperaSistemaExterno").style.display = "block";

	// Seteamos el DIV del mensaje.
	ancho = 394;
	alto = document.getElementById ("div_EsperaSistemaExterno").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_EsperaSistemaExterno").style.width = ancho.toString () + "px";
	document.getElementById ("div_EsperaSistemaExterno").style.top = top.toString () + "px";
	document.getElementById ("div_EsperaSistemaExterno").style.left = left.toString () + "px";
}

function fn_CerrarVentanaEsperaSistemaExterno ()
{
	document.getElementById ("div_EsperaSistemaExterno").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_ClickLinkRegistracion ()
{
	fn_CerrarVentanaLogin ();
	fn_AbrirVentanaRegistracion ();
}

function fn_AbrirVentanaRegistracion ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	document.getElementById ("txt_Registro_UsuLog").value = "";
	document.getElementById ("txt_Registro_Pwd").value = "";
	document.getElementById ("txt_Registro_Pwd_2").value = "";	
	document.getElementById ("txt_Nom_Persona").value = "";
	document.getElementById ("txt_Ape").value = "";
	document.getElementById ("txt_Ema").value = "";
	document.getElementById ("txt_Tel").value = "";
	document.getElementById ("txt_Fax").value = "";
	document.getElementById ("txt_DirPai").value = "";
	document.getElementById ("txt_DirCiu").value = "";
	document.getElementById ("txt_DirCal").value = "";
	document.getElementById ("txt_DirNum").value = "";
	document.getElementById ("txt_Age").value = "";
	document.getElementById ("txt_RazSoc").value = "";
	document.getElementById ("txt_NroIdeTri").value = "";
	document.getElementById ("txt_ConIVA").value = "";
	document.getElementById ("txt_Leg").value = "";
	document.getElementById ("txt_ComAlt").value = "";

	fn_HabilitarBotonesRegistracion ();

	document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "none";

	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Registracion").style.display = "block";

	// Seteamos el DIV del login.
	ancho = 570;
	alto = document.getElementById ("div_Registracion").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);
	
	if (top < (document.body.scrollTop + 5))
		top = document.body.scrollTop + 5;
	
	document.getElementById ("div_Registracion").style.width = ancho.toString () + "px";
	document.getElementById ("div_Registracion").style.top = top.toString () + "px";
	document.getElementById ("div_Registracion").style.left = left.toString () + "px";

	document.getElementById ("txt_Registro_UsuLog").focus ();
}

function fn_CerrarVentanaRegistracion ()
{
	document.getElementById ("div_Registracion").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_VentanaRegistracion_Volver ()
{
	document.getElementById ("div_Registracion").style.display = "none";
	fn_AbrirVentanaLogin ();
}

function fn_RealizarRegistracion ()
{
	var control_UsuLog = document.getElementById ("txt_Registro_UsuLog");
	var control_Pwd = document.getElementById ("txt_Registro_Pwd");
	var control_Pwd_2 = document.getElementById ("txt_Registro_Pwd_2");
	var control_Nom = document.getElementById ("txt_Nom_Persona");
	var control_Ape = document.getElementById ("txt_Ape");
	var control_Ema = document.getElementById ("txt_Ema");
	var control_Tel = document.getElementById ("txt_Tel");
	var control_Fax = document.getElementById ("txt_Fax");
	var control_DirPai = document.getElementById ("txt_DirPai");
	var control_DirCiu = document.getElementById ("txt_DirCiu");
	var control_DirCal = document.getElementById ("txt_DirCal");
	var control_DirNum = document.getElementById ("txt_DirNum");
	var control_Age = document.getElementById ("txt_Age");
	var control_RazSoc = document.getElementById ("txt_RazSoc");
	var control_NroIdeTri = document.getElementById ("txt_NroIdeTri");
	var control_ConIVA = document.getElementById ("txt_ConIVA");
	var control_Leg = document.getElementById ("txt_Leg");
	var control_ComAlt = document.getElementById ("txt_ComAlt");

	var mensajeError = "";
	var tempPwd = trim (control_Pwd.value);
	var parametros = "";
	
	if (trim (control_UsuLog.value) == "")
	{
		mensajeError = "El usuario es un dato obligatorio.";
		control_UsuLog.focus ();
	} 
	else if (trim (control_Pwd.value) == "")
	{
		mensajeError = "La contraseña es un dato obligatorio.";
		control_Pwd.focus ();
	}
	else if (trim (control_Pwd_2.value) == "")
	{
		mensajeError = "El reingreso de la contraseña es obligatorio.";
		control_Pwd_2.focus ();
	}
	else if (tempPwd.length < 6)
	{
		mensajeError = "La contraseña no puede tener menos de seis caracteres.";
		control_Pwd.focus ();
	}
	else if (trim (control_Pwd.value) != trim (control_Pwd_2.value))
	{
		mensajeError = "Las contraseñas ingresadas no coinciden.";
		control_Pwd.focus ();
	}
	else if (trim (control_Nom.value) == "")
	{
		mensajeError = "El nombre es un dato obligatorio.";
		control_Nom.focus ();
	}	
	else if (trim (control_Ape.value) == "")
	{
		mensajeError = "El apellido es un dato obligatorio.";
		control_Ape.focus ();
	}	
	else if (trim (control_Ema.value) == "")
	{
		mensajeError = "El e-mail es un dato obligatorio.";
		control_Ema.focus ();
	}	
	else if (fn_ValidarUnEmailValido (trim (control_Ema.value)) == false)
	{		
		mensajeError = "El e-mail ingresado es incorrecto.";
		control_Ema.focus ();
	}
	else if (trim (control_Tel.value) == "")
	{
		mensajeError = "El tel" + String.fromCharCode (233) + "fono es un dato obligatorio.";
		control_Tel.focus ();
	}	
	else if (trim (control_DirCiu.value) == "")
	{
		mensajeError = "La ciudad es un dato obligatorio.";
		control_DirCiu.focus ();
	}	
	else if (trim (control_Age.value) == "")
	{
		mensajeError = "La agencia es un dato obligatorio.";
		control_Age.focus ();
	}	
	else if (trim (control_RazSoc.value) == "")
	{
		mensajeError = "La raz" + String.fromCharCode (243) + "n social es un dato obligatorio.";
		control_RazSoc.focus ();
	}
	else if (document.getElementById ("chk_TerminosYCondiciones").checked == false)
	{
		mensajeError = "Debe aceptar los términos y condiciones.";
		document.getElementById ("chk_TerminosYCondiciones").focus ();
	}
	
	if (mensajeError != "")
	{
		document.getElementById ("span_LeyendaProcesandoRegistracion").innerHTML = mensajeError;
		document.getElementById ("span_LeyendaProcesandoRegistracion").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "block"; }
	}
	else
	{
		fn_BloquearBotonesRegistracion ();

		document.getElementById ("span_LeyendaProcesandoRegistracion").innerHTML = "Procesando, por favor espere...";
		document.getElementById ("span_LeyendaProcesandoRegistracion").className = "textoLeyendaProcesandoMicrositios";
	
		try { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "block"; }
		
		parametros = parametros + "txt_HacerRegistracion=-1";
		parametros = parametros + "&txt_UsuLog=" + fn_Escape (trim (control_UsuLog.value));
		parametros = parametros + "&txt_Pwd=" + fn_Escape (trim (control_Pwd.value));
		parametros = parametros + "&txt_Nom_Persona=" + fn_Escape (trim (control_Nom.value));
		parametros = parametros + "&txt_Ape=" + fn_Escape (trim (control_Ape.value));
		parametros = parametros + "&txt_Ema=" + fn_Escape (trim (control_Ema.value));
		parametros = parametros + "&txt_Tel=" + fn_Escape (trim (control_Tel.value));
		parametros = parametros + "&txt_Fax=" + fn_Escape (trim (control_Fax.value));
		parametros = parametros + "&txt_DirPai=" + fn_Escape (trim (control_DirPai.value));
		parametros = parametros + "&txt_DirCiu=" + fn_Escape (trim (control_DirCiu.value));
		parametros = parametros + "&txt_DirCal=" + fn_Escape (trim (control_DirCal.value));
		parametros = parametros + "&txt_DirNum=" + fn_Escape (trim (control_DirNum.value));
		parametros = parametros + "&txt_Age=" + fn_Escape (trim (control_Age.value));
		parametros = parametros + "&txt_RazSoc=" + fn_Escape (trim (control_RazSoc.value));
		parametros = parametros + "&txt_NroIdeTri=" + fn_Escape (trim (control_NroIdeTri.value));
		parametros = parametros + "&txt_ConIVA=" + fn_Escape (trim (control_ConIVA.value));
		parametros = parametros + "&txt_Leg=" + fn_Escape (trim (control_Leg.value));
		parametros = parametros + "&txt_ComAlt=" + fn_Escape (trim (control_ComAlt.value));

		fn_InvocarAjax_Post ("usuarios_ajax.php", parametros);
	}
}

function fn_BloquearBotonesRegistracion ()
{
	document.getElementById ("tablaRegistracion").style.cursor = "wait";

	document.getElementById ("btn_Registracion_Aceptar").style.cursor = "wait";
	document.getElementById ("btn_Registracion_Aceptar").disabled = true;
}	

function fn_HabilitarBotonesRegistracion ()
{
	document.getElementById ("tablaRegistracion").style.cursor = "default";

	document.getElementById ("btn_Registracion_Aceptar").style.cursor = "pointer";
	document.getElementById ("btn_Registracion_Aceptar").disabled = false;
}

function fn_ResultadoRegistracion (mensajeError)
{
	if (mensajeError != "")
	{
		// Registración fallida.
		fn_HabilitarBotonesRegistracion ();

		document.getElementById ("span_LeyendaProcesandoRegistracion").innerHTML = mensajeError;
		document.getElementById ("span_LeyendaProcesandoRegistracion").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRegistracion").style.display = "block"; }
	}
	else
	{
		// Registración exitosa.
		fn_CerrarVentanaRegistracion ();
		fn_AbrirVentanaMensajeRegistracionOk ();
	}
}

function fn_ClickLinkRecuperacion ()
{
	fn_CerrarVentanaLogin ();
	fn_AbrirVentanaRecuperacion ();
}

function fn_AbrirVentanaRecuperacion ()
{
	var altoMinimo;
	var ancho, alto, top, left;

	// Inicializamos la pantalla.
	document.getElementById ("txt_Recuperacion_Ema").value = "";

	fn_HabilitarBotonesRecuperacion ();

	document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "none";

	// Seteamos el DIV del sombreado.
	document.getElementById ("div_Sombreado").style.height = document.body.scrollHeight;
	document.getElementById ("div_Sombreado").style.width = document.body.scrollWidth;

	// Mostramos los DIVs.
	document.getElementById ("div_Sombreado").style.display = "block";
	document.getElementById ("div_Recuperacion").style.display = "block";

	// Seteamos el DIV del login.
	ancho = 446;
	alto = document.getElementById ("div_Recuperacion").clientHeight;
	
	top = parseInt ((document.body.clientHeight - alto) / 2) + document.body.scrollTop;
	left = parseInt ((document.body.clientWidth - ancho) / 2);	

	document.getElementById ("div_Recuperacion").style.width = ancho.toString () + "px";
	document.getElementById ("div_Recuperacion").style.top = top.toString () + "px";
	document.getElementById ("div_Recuperacion").style.left = left.toString () + "px";

	document.getElementById ("txt_Recuperacion_Ema").focus ();
}

function fn_CerrarVentanaRecuperacion ()
{
	document.getElementById ("div_Recuperacion").style.display = "none";
	document.getElementById ("div_Sombreado").style.display = "none";
}

function fn_VentanaRecuperacion_Volver ()
{
	document.getElementById ("div_Recuperacion").style.display = "none";
	fn_AbrirVentanaLogin ();
}

function fn_RealizarRecuperacion ()
{
	var control_Ema = document.getElementById ("txt_Recuperacion_Ema");
	var mensajeError = "";

	if (trim (control_Ema.value) == "")
	{
		mensajeError = "Debe ingresar su e-mail.";
		control_Ema.focus ();
	}	
	else if (fn_ValidarUnEmailValido (trim (control_Ema.value)) == false)
	{		
		mensajeError = "El e-mail ingresado es incorrecto.";
		control_Ema.focus ();
	}

	if (mensajeError != "")
	{
		document.getElementById ("span_LeyendaProcesandoRecuperacion").innerHTML = mensajeError;
		document.getElementById ("span_LeyendaProcesandoRecuperacion").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "block"; }
	}
	else
	{
		fn_BloquearBotonesRecuperacion ();

		document.getElementById ("span_LeyendaProcesandoRecuperacion").innerHTML = "Procesando, por favor espere...";
		document.getElementById ("span_LeyendaProcesandoRecuperacion").className = "textoLeyendaProcesandoMicrositios";
	
		try { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "block"; }
		
		fn_InvocarAjax_Post ("usuarios_ajax.php", "txt_HacerRecuperacion=-1&txt_Ema=" + fn_Escape (trim (control_Ema.value)));
	}
}

function fn_BloquearBotonesRecuperacion ()
{
	document.getElementById ("tablaRecuperacion").style.cursor = "wait";

	document.getElementById ("btn_Recuperacion_Aceptar").style.cursor = "wait";
	document.getElementById ("btn_Recuperacion_Aceptar").disabled = true;
}	

function fn_HabilitarBotonesRecuperacion ()
{
	document.getElementById ("tablaRecuperacion").style.cursor = "default";

	document.getElementById ("btn_Recuperacion_Aceptar").style.cursor = "pointer";
	document.getElementById ("btn_Recuperacion_Aceptar").disabled = false;
}

function fn_ResultadoRecuperacion (mensajeError)
{
	if (mensajeError != "")
	{
		// Registración fallida.
		fn_HabilitarBotonesRecuperacion ();

		document.getElementById ("span_LeyendaProcesandoRecuperacion").innerHTML = mensajeError;
		document.getElementById ("span_LeyendaProcesandoRecuperacion").className = "textoErrorVentanaLogin";
	
		try { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "table-row"; }
		catch (err) { document.getElementById ("tr_LeyendaProcesandoRecuperacion").style.display = "block"; }
	}
	else
	{
		// Registración exitosa.
		fn_CerrarVentanaRecuperacion ();

		document.getElementById ("span_MensajeSistemaExterno").innerHTML = "Hemos enviado un e-mail con tu usuario y contraseña de acceso.<br /><br /><span class='textoFiltrosMicrositios'>Es posible que se demore unos minutos en llegar. Si no lo recib&iacute;s en tu bandeja de entrada, verific&aacute; la carpeta de 'Spam', ya que a veces los programas de correo identifican los e-mails como 'correo no deseado'.</span>";

		fn_AbrirVentanaMensajeSistemaExterno ();
	}
}

function fn_txt_Recuperacion_Ema_KeyPress (evento)
{
	if (!evento)
		var evento = window.event;

	if (evento.keyCode == 13)
		fn_RealizarRecuperacion ();
}

function fn_ClickVerTerminosYCondiciones ()
{
	var numWidth = 400;
	var numHeight = 300;
	var numLeft = ((screen.availWidth / 2) - (numWidth / 2));
	var numTop = ((screen.availHeight / 2) - (numHeight / 2));

	var ventana = window.open ("./terminosycondiciones.php", "terminosycondiciones", "scrollbars=yes,fullscreen=no,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,width=" + numWidth + ",height=" + numHeight + ",left=" + numLeft + ",top=" + numTop);

	if (!ventana.opener) {ventana.opener = self;}
	if (window.focus) {ventana.focus();}
}

function fn_ClickAceptoTerminos ()
{
	if (document.getElementById ("chk_TerminosYCondiciones").checked)
		document.getElementById ("chk_TerminosYCondiciones").checked = false;
	else
		document.getElementById ("chk_TerminosYCondiciones").checked = true;
}

/*
function fn_AbrirVentanaHoteles ()
{
	var ventana = window.open ("http://hoteles.juliatours.com.ar", "_blank");

	if (!ventana.opener) {ventana.opener = self;}
	if (window.focus) {ventana.focus();}
}
*/

function fn_AbrirVentanaSpecialTours ()
{
	var ventana = window.open ("http://www.specialtours.com/cotizaciones/buscador.asp?cli=1417&id=0", "_blank");

	if (!ventana.opener) {ventana.opener = self;}
	if (window.focus) {ventana.focus();}
}
