var nav4 = window.Event ? true : false;

/*
 *	Es para evitar que se ingresen caracteres especiales en el input del buscador
 *	Para que me permita ingresar solo estos caracteres:    abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ0123456789-_@.,:áéíóúäëïöüÄËÏÖÜÁÉÍÓÚ()
 */
function acceptCar(evt)
{
	var key = nav4 ? evt.which : evt.keyCode;
	return (
			(key <= 32) || (key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122)|| (key == 209)|| (key == 241)||
			(key == 225)|| (key == 233)|| (key == 237)|| (key == 243)|| (key == 250)|| (key == 193)|| (key == 201)|| (key == 205)||
			(key == 211)|| (key == 218)|| (key == 64)|| (key == 58)|| (key == 46)|| (key == 45)|| (key == 44)|| (key == 40)||
			(key == 41)|| (key == 95)|| (key == 196)|| (key == 203)|| (key == 207)|| (key == 214)|| (key == 220)|| (key == 228)||
			(key == 235)|| (key == 239)|| (key == 246)|| (key == 252)
		);
}
/*
 *	Cambia el estado de Visibilidad de un Elemento
 */
function cambiaVisibilidad(id)
{
  if (elemento = document.getElementById(id))
  {
	if (elemento.style.display == 'none')
	{
	  elemento.style.display = 'block';
	}
	else
	{
	  elemento.style.display = 'none';
	}
	delete(elemento);
  }
  return(true);
}
/*
 *	Quita los espacios al comienzo y al final de una cadena
 */
function trim(text)
{
	var start = 0;
	var end = text.length - 1;
	while ((text.charCodeAt(start) == 32) && (start < end))
	{
		start++;
	}
	while ((text.charCodeAt(end) == 32) && (end > start))
	{
		end--;
	}
	text = text.substring(start, end + 1);
	if (text == ' ')
	{
		text = '';
	}
	return(text);
}
/*
 *	Valida que una cadena contenga sólo Caracteres alfanuméricos
 */
function validaCadena(campo, largoMinimo, largoMaximo, nombre)
{
	if (largoMinimo > 0)
	{
		if (campo.value.length < largoMinimo)
		{
			alert("Escriba por lo menos " + largoMinimo + " caracteres en el campo \"" + nombre  +"\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	if (largoMaximo > 0)
	{
		if (campo.value.length > largoMaximo)
		{
			alert("El campo \"" + nombre + "\" debe contener " + largoMaximo + " carateres como máximo.");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ01234567890. \t\r\n\f";
	for (i = 0;  i < campo.value.length;  i++)
	{
		ch = campo.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
			{
				break;
			}
		}
		if (j == checkOK.length)
		{
			alert("Escriba sólo letras, números, espacios en blanco y \".\" en el campo \"" + nombre + "\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			setTimeout('document.getElementById("' + campo.id + '").select();', 1);
			return(false);
		}
	}
	return(true);
}
/*
 *	Valida que una cadena contenga Caracteres Válidos para una Dirección de Correo Electrónico
 */
function validaCorreo(campo, largoMinimo, largoMaximo, nombre)
{
	if (largoMinimo > 0)
	{
		if (campo.value.length < largoMinimo)
		{
			alert("Escriba por lo menos " + largoMinimo + " caracteres en el campo \"" + nombre  +"\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	if (largoMaximo > 0)
	{
		if (campo.value.length > largoMaximo)
		{
			alert("El campo \"" + nombre + "\" debe contener " + largoMaximo + " carateres como máximo.");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@.-_";
	for (i = 0;  i < campo.value.length;  i++)
	{
		ch = campo.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
			{
				break;
			}
		}
		if (j == checkOK.length)
		{
			alert("Escriba sólo letras, números, \"@\", \"-\", \"_\" y \".\" en el campo \"" + nombre + "\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			setTimeout('document.getElementById("' + campo.id + '").select();', 1);
			return(false);
		}
	}
	return(true);
}
/*
 *	Verifica que una Cadena esté compuesta sólo por Caracteres Numéricos
 */
function validaNumero(campo, largoMinimo, largoMaximo, nombre)
{
	if (largoMinimo > 0)
	{
		if (campo.value.length < largoMinimo)
		{
			alert("Escriba por lo menos " + largoMinimo + " caracteres en el campo \"" + nombre  +"\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	if (largoMaximo > 0)
	{
		if (campo.value.length > largoMaximo)
		{
			alert("El campo \"" + nombre + "\" debe contener " + largoMaximo + " carateres como máximo.");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			return(false);
		}
	}
	var checkOK = "0123456789";
	for (i = 0;  i < campo.value.length;  i++)
	{
		ch = campo.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
			{
				break;
			}
		}
		if (j == checkOK.length)
		{
			alert("Ingrese solo números en el campo \"" + nombre + "\".");
			setTimeout('document.getElementById("' + campo.id + '").focus();', 1);
			setTimeout('document.getElementById("' + campo.id + '").select();', 1);
			return(false);
		}
	}
	return(true);
}
/*
 *	Verifica que se haya ingresado un valor en el buscador antes de realizar la Búsqueda
 */
function verificarBuscador()
{
	if (buscar = document.getElementById('inpBuscar'))
	{
		buscar.value = trim(buscar.value);
		if (!validaCadena(buscar, 1, 0, 'Buscar'))
		{
			return(false);
		}
	}
	delete(buscar);
	return(true);
}
/*
 *	Valida el Formulario de Asesoramiento
 */
function validarFormularioAsesoramiento()
{
	if (nombre = document.getElementById('nombre'))
	{
		nombre.value = trim(nombre.value);
		if (!validaCadena(nombre, 1, 0, 'Nombre y apellido'))
		{
			return(false);
		}
	}
	delete(nombre);
	if (telefono = document.getElementById('telefono_1'))
	{
		telefono.value = trim(telefono.value);
		if (!validaNumero(telefono, 1, 0, 'Teléfono 1'))
		{
			return(false);
		}
	}
	delete(telefono);
	if (correo = document.getElementById('correo'))
	{
		correo.value = trim(correo.value);
		if (!validaCorreo(correo, 0, 0, 'Correo electrónico'))
		{
			return(false);
		}
	}
	delete(correo);
	return(true);
}
