2; // Cambiar entre 1 y 9 - Version del archivo (utilizar números enteros)
// Version = 'v1.0.2';

/*===================================================================
 function: AnchorLink
 	Agrega un anchor a los elementos del id que equivale al href, esto sirve
 	para el HistoryBack button
 Devuelve:
	false
 Parametros:
 	id		->	Id del atributo que contiene los A (si se omite, son todos los A)
=====================================================================*/
function AnchorLink(id)
{
	$(id).each(function() {
		if($(this).attr('id') != "ingles" && $(this).attr('id') != "espanol")
		if( $(this).attr('href') ) {
			var aHREF = $(this).attr('href').split('?');
	 		if(aHREF.length > 1) {
				$(this).attr('href', $(this).attr('href') + "#" + aHREF[1]);
				$(this).click(function(){
					$.historyLoad(aHREF[1]);
					return false;
				});
			}
			else
			{
				$(this).click(function(){
					location.href = this.getAttribute('href');
					return false;
				});
			}
		}
	});
}

/*===================================================================
 function: BigPhoto
 	Repite Hace un efecto de poner una imagen en otro. El uso logico es
 	pasar de una imagen chica a una grande
 Devuelve:
	El string resultado.
 Parametros:
 	id		->	Id del la imagen donde se va a poner.
 	arch	->	path del archivo nuevo (relativo o absoluto).
=====================================================================*/

function BigPhoto(id, arch) {
	if( $(id).attr('src')!= arch ) {
		$(id).stop();
		$(id).stop().fadeTo(300, 0, function() {  //fade image out
	            $(id).attr('src','');  //give new image a src attribute
	            $(id).attr('src',arch);  //give new image a src attribute
	        }).fadeTo("slow", 1);
  }
	return false;
}

/*===================================================================
 function: repetir
 	Repite sTexto hasta llegar a iRepetir.
 Devuelve:
	El string resultado.
 Parametros:
 	sTexto		->	El texto a repetir.
 	iRepetir	->	La cantidad de veces.
=====================================================================*/

function repetir(sTexto, iRepetir)
{
	try
	{
		var sCompletar = '';

		if (sTexto.length != 1 ) return false;

		for(iPos = 0; iPos < iRepetir; iPos++)
			sCompletar += sTexto;

		return sCompletar;
	}
	catch(oError)
	{
		return null;
	}
}
/*===================================================================
 function: completar
 	Completa el value de oInput, con sTexto hasta llegar al máximo.
 Devuelve:
	True si todo OK, false en caso que los datos no concuerden,
	null en caso de error.
 Parametros:
 	oInput			 ->	Objeto Input de tipo.
 	sTexto			 ->	El texto a repetir.
 	bCompletarVacios ->	Completar aún si está vacio.
=====================================================================*/

function completar(oInput, sTexto, bCompletarVacios)
{
	try
	{
		if (!oInput || !sTexto		) return false;
		if (sTexto.length != 1		) return false;
		if (oInput.type   != 'text'	) return false;
		if (!bCompletarVacios && oInput.value == '') return true;

		var iMax = parseInt(oInput.getAttribute('maxLength'));
		var iRepetir = 0;
		var sCompletar = '';

		if (!isNaN(iMax) && iMax != oInput.value.length)
			iRepetir = (iMax - oInput.value.length);

		sCompletar = repetir(sTexto, iRepetir) + oInput.value;

		oInput.value = sCompletar;
		return true;
	}
	catch(oError)
	{
		return null;
	}
}

/*===================================================================
 function: seleccionar
 	Selecciona un valor de un SELECT, o el primero si no encontró
 	el valor y bPrimero es TRUE.
 Devuelve:
	No retorna ningún valor.
 Parametros:
 	oSelect	->	El objeto SELECT en el cual debe buscarse sDato.
 	Datos	->	Cadena o Array de cadenas a buscar en value del
 				SELECT.
=====================================================================*/

function seleccionar(oSelect, Datos, bPrimero)
{
	try
	{
		var sDato = null;

		if (typeof(Datos) == 'string')
			Datos = new Array(Datos);

		oSelect.selectedIndex = -1;
		for(j = 0; j < Datos.length; j++)
		{
			sDato = Datos[j];
			for(i = 0; i < oSelect.options.length; i++)
			{
				if (oSelect.options[i].value == sDato)
				{
					if (oSelect.multiple)
						oSelect.options[i].selected = true;
					else
					{
						oSelect.selectedIndex = i;
						break;
					}
				}
			}
		}

		if (bPrimero && oSelect.selectedIndex == -1 && oSelect.options.length)
			oSelect.selectedIndex = 0;

		return oSelect.selectedIndex;
	}
	catch(oError)
	{
		return false;
	}
}

/*********************************************************************
Funcion: mostrarOcultarHasta
Motivo:
	Muestra u oculta los campos, se utiliza usualmente para manejo
	de filtros DESDE - HASTA y Operacion.
Parametros:
	oSelect		->	Es SELECT que actua como filtro.
	sObjID		->	Es ID del objeto a ocultar/mostrar.
	iNoLimpiar	->	Si TRUE no inicializa el valor del INPUT encerrado
					en sObjID.
Devuelve:
	True si todo OK, false si no existe el select.
**********************************************************************/
function  mostrarOcultarHasta(oSelect, sObjID, iNoLimpiar)
{
	if (!oSelect) return false;

	if (oSelect.value != 'between')
		$('#' + sObjID).hide();
	else
		$('#' + sObjID).show();

	if (!iNoLimpiar)
	{
		$('#' + sObjID).find('*:input').each(
			function(iPos, oInput)
			{
				oInput.value = '';
			});
	}

	return true;
}

/*********************************************************************
Funcion: trim
Motivo:
	Elimina los espacios al principio y al final.
Parametros:
	cadena	->	La cadena a la que se le quiere aplicar la funcion.
Devuelve:
	La cadena resultado.
**********************************************************************/
function trim(cadena)
{
  cadena = cadena.replace(/^\s*|\s*$/g,"");
  return cadena;
}
