//   Rutinas Generales

function fnIdentificaNavegador()
{
	//Esta función permite identificar los datos del navegador y del sistema operativo
	var strNombre, strVersion, strIdiomaNavegador, strIdiomaSistema;
	strNombre = navigator.appName;
	strVersion = navigator.appVersion;
	strIdiomaNavegador = navigator.browserLanguage;
	strIdiomaSistema = navigator.systemLanguage;
	alert("Nombre = " + strNombre + "\nVersion = " + strVersion + "\nIdioma Navegador = " + strIdiomaNavegador + "\nIdioma Sistema = " + strIdiomaSistema);
}

// Crea una Cookie con un nombre y valor especificados.
function fnCreaCookie(strNombre, strValor)
{
	document.cookie = strNombre + "=" + escape(strValor);
	// La cookie expirará en un mes
	var dtFecha = new Date();
	dtFecha.setMonth(dtFecha.getMonth()+1);
	document.cookie += ("; expires=" + dtFecha.toUTCString()); 
}


// Obtiene el valor de la cookie del nombre especificado
function fnObtieneCookie(strNombre)
{
	// Las cookies están separadas por PuntoyComa (;)
	var objCookie = document.cookie.split("; ");
	for (var intI=0; intI < objCookie.length; intI++)
	{
	// El nombre y el valor de las cookies estan separador por un signo de Igual (=)
	var objCrumb = objCookie[intI].split("=");
	if (strNombre == objCrumb[0]) 
	  return unescape(objCrumb[1]);
	}
	// Si una cookie no se encuentra regresa el valor (null)
	return null;
}


// Elimina la cookie con el nombre especificado.
function fnBorraCookie(strNombre)
{
	//Se le pone a la cookie una fecha de expiración pasada para que el sistema la borre
	document.cookie = strNombre + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function fnObjeto(strId)
{
	//Regresa un objeto específico de la colección de objetos del documento.
	var objResultado;
	if (document.getElementById)
		objResultado = document.getElementById(strId);
	else if (document.all)
		objResultado = document.all[strId];
	else if (document.layers)
		objResultado = document.layers[strId];
	else if (document.all[0])
		objResultado = document.all[strId];
	return objResultado;
}

function fnColeccionDeObjetos()
{
	//Regresa la colección de objetos del documento
	var objResultado;

	if (document.all)
		objResultado = document.all
	else if (document.layers)
		objResultado = document.layers;
	return objResultado;
}

function fnCualNavegador()
{
//OpenLayers.Util.getBrowserName = function() { 
	var browserName = ""; 

	var ua = navigator.userAgent.toLowerCase(); 
	if ( ua.indexOf( "opera" ) != -1 ) 
	{ 
		browserName = "opera"; 
	} 
	else if ( ua.indexOf( "msie" ) != -1 ) 
	{ 
		browserName = "msie"; 
	} 
	else if ( ua.indexOf( "mozilla" ) != -1 ) 
	{ 
		if ( ua.indexOf( "firefox" ) != -1 ) 
		{ 
			browserName = "firefox"; 
		} 
		else if (ua.indexOf( "chrome" ) != -1)
		{
			browserName = "chrome";
		}
		else if (ua.indexOf( "safari" ) != -1)
		{
			browserName = "safari";
		}
		else 
		{ 
			browserName = "mozilla"; 
		} 
	}
	return browserName; 
}

function fnExtraeTextoYContexto(strTextoCompleto, strTextoBuscar, intCaracteresAnteriores, intCaracteresPosteriores)
{

	/*
	fnExtraeTextoYContexto: De un string extrae el texto buscado mas algunos caracteres mas
	strTextoCompleto.- Texto donde se obtendrá el extracto
	strTextoBuscar.- Texto a buscar
	intCaracteresAnteriores.- Cantidad de caracteres a extraer antes del texto encontrado
	intCaracteresPosteriores.- Cantidad de caracteres a extraer despues del texto encontrado

	*/

	var strResultado = '';
	var intPosicion = 0;
	var intResultadoPosicionInicio = 0;
	var intResultadoCaracteres = 0;
	var intRemanenteAnterior = 0;
	var intRemanentePosterior = 0;

	var strAuxTexto;
	var strAuxBuscar;

	intCaracteresAnteriores = Number(intCaracteresAnteriores);
	intCaracteresPosteriores = Number(intCaracteresPosteriores);


	strAuxTexto = fnQuitaAcentos(strTextoCompleto).toUpperCase();
	strAuxBuscar = fnQuitaAcentos(strTextoBuscar).toUpperCase();

	intPosicion = strAuxTexto.search(strAuxBuscar);
	if (intPosicion != -1)
	{
		intResultadoPosicionInicio = intPosicion - intCaracteresAnteriores;
		if (intResultadoPosicionInicio < 0)
		{
			intRemanenteAnterior = Math.abs(intResultadoPosicionInicio);
			intResultadoPosicionInicio = 0;
		}
		intResultadoCaracteres = strTextoBuscar.length + intCaracteresPosteriores + (intCaracteresAnteriores - intRemanenteAnterior);
/*		
		if (intResultadoPosicionFinal > strTextoCompleto.length)
		{
			intRemanentePosterior = intResultadoPosicionFinal-strTextoCompleto.length;
			intResultadoPosicionFinal = strTextoCompleto.length;
		}
*/
		strResultado = strTextoCompleto.substr(intResultadoPosicionInicio,intResultadoCaracteres);
	}
	return strResultado;
}
