// ---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U
// FUNCIONES UTILITARIAS
//
// 	function FormatearNumConPrecision(nNum, nPrecision)  --> strNumFormat
//	function ColorNum2Hexa(strColorRGB) 				 --> strRGB_formato_HTML
//	function FormatNumCon2Dec(nNum)     				 --> nNum (formateado a 2 decimales)
//	function DeptoPorLetra(strLetra)                     --> strNombreDepto
//	function DeptoPorNombre(strNomDepto)                 --> strLetraDepto
//	function GenerarArrayPorSeparador(strOrigen, strSeparador) --> array de strings.
//  function IncluirStatusBusq(strDatosFinalesCalculo, objMaestro) --> string incluyendo padrones excepcionales.
//	function MostrarSimbologiaStatusBusq(winVentana, objInfoMaestro) --> nada.
//  function MostrarLogoFechaHora(winVentana)            --> nada.
//  function MostrarAclaracionOficial(winVentana)        --> nada.
// ---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U---U


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// FormatearNumConPrecision(nNum, nPrecision)
//
// DESCRIPCION: Dado un numero decimal, retornar un string con el numero formateado a N decimales
//				segun el parametro nPrecision.
//				Se usa para mostrar las superficies catastrales en hectareas (estan en metros en la
//				tabla CONEATMAESTRO), y para mostrar porcentajes, etc.
//
//  				Ej.: FormatearNumConPrecision(2.3, 4) --> "2.3000"
//						 FormatearNumConPrecision(2.3, 2) --> "2.30"
//
// PARAMETROS: nNum - numero a formatear
//			   nPrecision - cantidad de decimales que se desean en la salida formateada.
//
// RETORNO:    strNumFormateado (string) - el numero en formato string con la cantidad de cifras decimales
//										   indicadas segun nPrecision.
// 		EXCEPCIONES: Si nNum no puede ser tratado como numero, se retorna nNum en formato string.
//
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function FormatearNumConPrecision(nNum, nPrecision) {
	var strNum = nNum.toString();
	var strParteEntera;
	var strParteDecimal = "";

	// PARCHE (6/12/2001): para poder usar la funcion con parametro nNum en formato string.
	// Validar que nNum tenga un formato numerico (en el caso de que nNum pueda ser un string no transformable a number).
	if (isNaN(parseFloat(strNum))) {
		return strNum;
	}
	// FIN_PARCHE

	if (strNum.indexOf(".") == -1) {
		// Formato "nnn" (sin decimales).
		strParteEntera  = strNum;
	} else {
		// Formato "nnn.nnnn" (con decimales).
		strParteEntera = strNum.split(".")[0];
		strParteDecimal = strNum.split(".")[1];
	}
	// Ajustar a 4 cifras decimales.
	strParteDecimal += "00000000000000000000";		// agregar un chorro de ceros a la izquierda.

	// Retornar el numero como string formateado a N decimales segun nPrecision.
	return (strParteEntera + "." + strParteDecimal.slice(0, nPrecision)).toString();
}

// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// ColorNum2Hexa(strColorRGB)
//
// DESCRIPCION: Para usar en los atributos xxxCOLOR de los tags HTML
//				que requieren un string hexadecimal del estilo "#C06549".
//
// PARAMETROS: strColorRGB debe ser un string del estilo "127,54,223"
//
// RETORNO: string del estilo "#8B4513" (para atributos de color en HTML).
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function ColorNum2Hexa(strColorRGB)
{
	var nR = parseInt(strColorRGB.split(",")[0]);
	var nG = parseInt(strColorRGB.split(",")[1]);
	var nB = parseInt(strColorRGB.split(",")[2]);

	return "#" + (nR.toString(16) == 0 ? "00" : nR.toString(16)) +
		         (nG.toString(16) == 0 ? "00" : nG.toString(16)) +
		         (nB.toString(16) == 0 ? "00" : nB.toString(16)) ;
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// FormatNumCon2Dec(nNum)
//
// DESCRIPCION: Dado un numero con n decimales, formatearlo (redondeado) a 2 decimales.
//				Ejemplo: dado 15.5876666 se obtiene 15.59
//
// PARAMETROS: nNum - numero con decimales
//
// RETORNO: (numero) formateado y redondeado a 2 decimales.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function FormatNumCon2Dec(nNum)
{
	// Explicacion - ejemplo:
	// 15.5876666 (x 100) -> 1558.766666
	// Math.round(1558.766666) -> 1559
	// 1559 / 100 -> 15.59

	return Math.round(nNum * 100) / 100;
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// DeptoPorLetra(strLetra)
//
// DESCRIPCION: obtener nombre de departamento segun letra strLetra.
//
// PARAMETROS: strLetra (string) - string del estilo "E", "R", etc, etc...
//
// RETORNO: string con nombre de departamento.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function DeptoPorLetra(strLetra) {
	var objNomDeptos = new Object();

	objNomDeptos.A = "Canelones";
	objNomDeptos.B = "Maldonado";
	objNomDeptos.C = "Rocha";
	objNomDeptos.D = "Treinta y Tres";
	objNomDeptos.E = "Cerro Largo";
	objNomDeptos.F = "Rivera";
	objNomDeptos.G = "Artigas";
	objNomDeptos.H = "Salto";
	objNomDeptos.I = "Paysandu";
	objNomDeptos.J = "Rio Negro";
	objNomDeptos.K = "Soriano";
	objNomDeptos.L = "Colonia";
	objNomDeptos.M = "San Jose";
	objNomDeptos.N = "Flores";
	objNomDeptos.O = "Florida";
	objNomDeptos.P = "Lavalleja";
	objNomDeptos.Q = "Durazno";
	objNomDeptos.R = "Tacuarembo";
	objNomDeptos.V = "Montevideo";

	return objNomDeptos[strLetra.toUpperCase()];
}

// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// DeptoPorNombre(strNomDepto)
//
// DESCRIPCION: obtener letra de departamento dado strNomDepto.
//
// PARAMETROS: strNomDepto (string) - string de nombre de departamento.
//
// RETORNO: string de letra de departamento.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function DeptoPorNombre(strNomDepto) {
	var arrLetras = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
							  'M', 'N', 'O', 'P', 'Q', 'R', 'V');

	for (var i = 0; i < arrLetras.length; i++) {
		if (DeptoPorLetra(arrLetras[i]) == strNomDepto) {
			return arrLetras[i];
		}
	}

	return "indeterminado";
}

// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// GenerarArrayPorSeparador(strOrigen, strSeparador)
//
// DESCRIPCION: Dado un string de etiquetas de padrones que puedan tener el siguiente formato:
//					 "614", "325<BR>780", "3311"
//				Se devuelve un array 'normalizado' con los siguientes formatos respectivamente:
//					 ["614"], ["325", "780"], ["3311"]
// MODIFICACION 29/11/2001 - se extendio la funcion para separar el string usando cualquier cadena como
//							 elemento separador, para trabajar con otros strings que puedan contener
//							 areas, etc.
//
// NOTAS: Esta funcion es para trabajar con ciertos arrays de padrones en aimsMio.js en donde
//		  pueden aparecer padrones que esten en un mismo bolson para los cuales se mantienen en un unico
//		  elemento con el formato "325<BR>780" (el <BR> es para hacer saltos de linea en el codigo HTML).
//		  Ver uso de la funcion en aimsMio.js, funcion calculoIndProdTodosArr(). Se trabaja con padronArr.
//
// PARAMETROS: strOrigen    (string) - cadena para desdoblar en un array.
//			   strSeparador (string) - cadena a usar como separador.
//
// RETORNO: (array de strings) con numeros de padron.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function GenerarArrayPorSeparador(strOrigen, strSeparador)
{
	var arrRetorno  = new Array();
	var arrSubArray = new Array();
	var rePatron    = new RegExp("\s*" + strSeparador + "\s*");

	arrSubArray = strOrigen.split(rePatron); // Se separa usando una expresion regular.

	if (arrSubArray.length == 0) {
		// Caso que strOrigen tenga solo un elemento.
		arrRetorno[0] = strOrigen;
	} else {
		// Caso de padrones que estan en el mismo bolson.
		for (var i = 0; i < arrSubArray.length; i++) {
			arrRetorno[i] = arrSubArray[i];
		}
	}

	return arrRetorno;
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// IncluirStatusBusq(strDatosFinalesCalculo, objMaestro, objPorcSue)
//
// DESCRIPCION: dado el clasico string resultado devuelto por calculoIndProdTodosArr, se regenera el mismo
//				string pero incluyendo pistas sobre los padrones que estan en situacion excepcional luego
//				de las busquedas en CONEATMAESTRO y CATCON. O sea: se incluyen datos segun el campo
//				StatusBusq para informar en cada padron si fue encontrado en Maestro, en Catcon, etc.
//
// AGREGADO 15/4/2002: calculo de IVR.
//
// strDatosFinalesCalculo se interpreta asi (la coma es el separador de elementos):
//  Letra Padron(para reportes HTML) SecJud SupCat IndProd(calculado) Padron(para etiquetar JPG) NomDepto
// " R,     6090<BR>6570,              5,   45.7890,      83,             6090 - 6570             Tacua,
//  'X' , 2b, 3b, 4b, 5b, 6b, 7b, ... "
//
// (En el ejemplo anterior se muestra el caso particular de 2 padrones que comparten el mismo bolson).
//
// NOTA: strDatosFinalesCalculo solo incluye a los padrones encontrados en CATCON; entonces, se agregan
//		  los padrones NO encontrados, al string de reporte, de modo de que el usuario sepa de este hecho.
//
// NOTA: Significado de las 'estrellas' que se anteponen a los padrones que cumplen ciertas condiciones:
//
//			Estrellas  StatusBusq  Significado
//			   *           1        NO maestro. SI catcon.
//			  **           2        SI maestro. NO catcon.
//			 ***           0        NO maestro. NO catcon.
//
//
// PARAMETROS: strDatosFinalesCalculo (string) -
//			   objMaestro - referencia al objeto InfoMaestro global.
//			   objPorcSue - referencia al objeto PorcentajesSuelos global.
//
// RETORNO: (string) - nuevo string con igual 'formato' strDatosFinalesCalculo pero incluyendo los datos
//					   de los padrones excepcionales luego de las busquedas en CONEATMAESTRO y CATCON.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function IncluirStatusBusq(strDatosFinalesCalculo, objMaestro, objPorcSue) {
	var strDatosFinalesConExcepciones = "";
	var arrElem       = new Array(); // array basico al separar strDatosFinalesCalculo segun la coma.
	var arrLetraDepto = new Array();
	var arrPadronHTML = new Array(); // Modificar segun StatusBusq en InfoMaestro por padron.
	var arrSecJud     = new Array(); // Modificar segun StatusBusq en InfoMaestro por padron.
	var arrSupCat     = new Array(); // Modificar segun StatusBusq en InfoMaestro por padron.
	var arrIndProd    = new Array(); // Modificar segun StatusBusq en InfoMaestro por padron.
	var arrPadronGRAF = new Array();
	var arrNomDepto   = new Array();
	var arrIVR        = new Array(); // AGREGADO 15/4/2002: calculo del IVR.
	var arrLamina     = new Array(); // AGREGADO 24/6/2004: reporte de notificacion.
	var arrCoord      = new Array(); // AGREGADO 24/6/2004: reporte de notificacion.

	arrElem = strDatosFinalesCalculo.split(',');

	// Organizar el string strDatosFinalesCalculo en 7 arrays paralelos para hacerlo mas manejable.
	var x = 0;
	for (var i = 0; i < arrElem.length; i++) {
		arrLetraDepto[x] = arrElem[i++];
		arrPadronHTML[x] = arrElem[i++];
		arrSecJud[x]     = arrElem[i++];
		arrSupCat[x]     = arrElem[i++];
		arrLamina[x]     = arrElem[i++];  // 24/6/2004: para reporte de notificacion.
		arrCoord[x]      = arrElem[i++];  // 24/6/2004: para reporte de notificacion.
		arrIndProd[x]    = arrElem[i++];
		arrPadronGRAF[x] = arrElem[i++];
		arrNomDepto[x]   = arrElem[i];
		arrIVR[x]        = 'S/D';       // 15/4/2002: S/D sin datos, por ahora.
		x++;
	}

	delete arrElem; // liberar un poco de memoria.

	// ANEXAR la info de padrones que no se encontraron en el layer CATCON.
	var arrNoCatcon = new Array();
	var nUltElem = arrLetraDepto.length;

	arrNoCatcon = objMaestro.PadronesNoEnLayer();  // Padrones NO en catcon (pero pueden tener info del Maestro).

	for (var i = 0; i < arrNoCatcon.length; i++) {
		var objPadMae = new PadMaestro();

		objPadMae = objMaestro.InfoPorPadron(arrNoCatcon[i]);
		// Anexar a los arrays paralelos.
		arrLetraDepto[nUltElem] = objPadMae.Depto;
		arrPadronHTML[nUltElem] = '' + objPadMae.Padron;		// Forzar a string.
		arrSecJud[nUltElem]     = '' + objPadMae.SeccJudic;		// Forzar a string.
		arrSupCat[nUltElem]     = '' + objPadMae.SupCat;		// Forzar a string.

		//MODIF_NOTIF 24/6/2004: para reporte de notificaciones.
		arrLamina[nUltElem]     = '' + objPadMae.Lamina;
		arrCoord[nUltElem]      = '' + objPadMae.Coord;
		//FIN_MODIF_NOTIF

		arrIndProd[nUltElem]    = 'S/D';	// Si no esta en CATCON, no debe tener indice calculado.
		arrPadronGRAF[nUltElem] = objPadMae.Padron;
		arrNomDepto[nUltElem]   = DeptoPorLetra(objPadMae.Depto);
		arrIVR[nUltElem]        = 'S/D';       // 15/4/2002: S/D sin datos, por ahora.

		nUltElem++;
	}
	delete arrNoCatcon;  // liberar un poco de memoria.
	// FIN_ANEXAR los casos que no estan en el layer CATCON.


	// INCLUSION DE INFO SEGUN LOS StatusBusq.
	for (var i = 0; i < arrLetraDepto.length; i++) {
		var arrSubPadron = new Array();
		var arrSubSupCat = new Array();
		var arrSubLamina = new Array();  // AGREGADO 24/6/2004.
		var arrSubCoord  = new Array();  // AGREGADO 24/6/2004.
		var arrSubIVR    = new Array();  // AGREGADO 15/4/2002.

		var strPadronHTML = "";
		var strSupCat  = "";
		var strSecJud  = "";
		var strIndProd = "";
		var strIVR     = "";	// AGREGADO 15/4/2002.
		var strLamina  = "";	// AGREGADO 24/6/2004.
		var strCoord   = "";	// AGREGADO 24/6/2004.

		// DESARMAR arrPadronHTML en sub-elementos.
		// Ej: dado '6570<BR>6090', obtener array { '6570', '6090' } para poder trabajar
		// por padrones que puedan estar en el mismo bolson.
		arrSubPadron  = GenerarArrayPorSeparador(arrPadronHTML[i], '<BR>');
		arrSubSupCat  = GenerarArrayPorSeparador(arrSupCat[i], '<BR>');

		//MODIF_NOTIF 24/6/2004: p/ reporte de notificaciones.
		arrSubLamina  = GenerarArrayPorSeparador(arrLamina[i], '<BR>');
		arrSubCoord   = GenerarArrayPorSeparador(arrCoord[i], '<BR>');
		//FIN_MODIF_NOTIF

		for (var x = 0; x < arrSubPadron.length; x++) {
			var nStatusBusq;  // Status de busqueda de un padron dado.
			var nCodFicto;    // Codigo de ficto: (0 = normal, 1 = ficto, 2 = INC).
			var nIPF;		  //AGREGADO 15/4/2002.

			nStatusBusq = objMaestro.ObtenerStatusPorPadron(arrSubPadron[x]);
			nCodFicto = objMaestro.ObtenerCodFictoPorPadron(arrSubPadron[x]);

			switch (nStatusBusq) {
				case 0:
					// NO en maestro. NO en CATCON.
					strPadronHTML += '***&nbsp;' + arrSubPadron[x];	// Tres estrellas.
					strSupCat     += 'S/D';							// Sin datos de superficie catastral.
					strSecJud     += (x > 0) ? '<BR>S/D' : 'S/D';	// Sin datos de seccion judicial.
					strIndProd    += arrIndProd[i];					// S/D.
					//AGREGADO 15/4/2002
					strIVR        += 'S/D';
					//FIN_AGREGADO
					//MODIF_NOTIF 24/6/2004: para notificaciones.
					strLamina     += '&nbsp;';
					strCoord      += '&nbsp;';
					//FIN_MODIF_NOTIF
					break;
				case 1:
					// NO en maestro. SI en CATCON.
					strPadronHTML += '*&nbsp;' + arrSubPadron[x];			// Una estrella :P
					strSupCat     += 'S/D';							// Sin datos de superficie catastral.
					strSecJud     += 'S/D';							// Sin datos de seccion judicial.
					strIndProd    += ('*&nbsp;' + arrIndProd[i]).toString();

					//AGREGADO 17/4/2002
					strIVR        += 'S/D';  // No se calcula IVR porque solo se obtiene el indice promedio.
					//FIN_AGREGADO
					//MODIF_NOTIF 24/6/2004: para notificaciones.
					strLamina     += '&nbsp;';
					strCoord      += '&nbsp;';
					//FIN_MODIF_NOTIF
					break;
				case 2:
					// SI en maestro. NO en CATCON.
					// NOTA 17/4/2002: el dato de IVR se pone fijo segun sea al caso.

					strPadronHTML += '**&nbsp;' + arrSubPadron[x];		// Dos estrellas.
					strSupCat     += arrSubSupCat[x];
					strSecJud     += arrSecJud[i];

					//MODIF_NOTIF 24/6/2004: para notificaciones.
					strLamina     += arrSubLamina[x];
					strCoord      += arrSubCoord[x];
					//FIN_MODIF_NOTIF

					// Contemplar los casos de fictos/INC en el reporte de Indice de Productividad.
					switch (nCodFicto) {
						case 1:
							// Fictos no en lamina, llevan indice = 100 (consultado ADR 6/12/2001)
							strIndProd += '100';
							strIVR += '100';   //AGREGADO 15/4/2002
							break;
						case 2:
							// I.N.C. no en lamina, llevan indice = 0 (consultado ADR 6/12/2001)
							strIndProd += '0';
							strIVR += '0';   //AGREGADO 15/4/2002
							break;
						default:
							strIndProd += arrIndProd[i];			// S/D.
							strIVR += 'S/D';   //AGREGADO 15/4/2002
							break;
					}
					break;
				default:
					// SI en maestro. SI en CATCON. (no lleva ningun simbolo especial).
					strPadronHTML += arrSubPadron[x];
					strSupCat     += arrSubSupCat[x];

					//MODIF_NOTIF 24/6/2004: para notificaciones.
					strLamina     += arrSubLamina[x];
					strCoord      += arrSubCoord[x];
					//FIN_MODIF_NOTIF

					strSecJud     += arrSecJud[i];
					strIndProd    += arrIndProd[i];

					//AGREGADO 15/4/2002: calculo de IVR
					var strId2 = arrLetraDepto[i] + "-" + arrSubPadron[x];
					var nAfec_ruta = objMaestro.InfoPorId2(strId2).AfRuta;
					var nAfec_cp   = objMaestro.InfoPorId2(strId2).AfecCP;
					var nIVR = objPorcSue.CalcularIVR(arrIndProd[i], nAfec_ruta, nAfec_cp);
					strIVR += nIVR;
					//FIN_AGREGADO
					break;
			}

			// FICTOS/INC Incluir status segun CodFicto (Fictos o I.N.C.).
			switch (nCodFicto) {
				case 1:
					// FICTO: incluir superindice F.
					strPadronHTML = '<SUP>F&nbsp;</SUP>' + strPadronHTML;
					break;
				case 2:
					// I.N.C. (colonizacion): incluir superindice C.
					strPadronHTML = '<SUP>C&nbsp;</SUP>' + strPadronHTML;
					break;
				default:
					// Normal. (no hacer nada).
					break;
			}

			// Anexar los tags salto de linea, si corresponde.
			strPadronHTML += ((x + 1) == arrSubPadron.length) ? '' : '<BR>';
			strSupCat     += ((x + 1) == arrSubPadron.length) ? '' : '<BR>';
			strSecJud     += ((x + 1) == arrSubPadron.length) ? '' : '<BR>';

			//MODIF_NOTIF 24/6/2004: para notificaciones.
			//NO_VA: strLamina     += ((x + 1) == arrSubPadron.length) ? '&nbsp;' : '<BR>';
			strCoord      += ((x + 1) == arrSubPadron.length) ? '' : '<BR>&nbsp;';
			//FIN_MODIF_NOTIF

			strIndProd    += ((x + 1) == arrSubPadron.length) ? '' : '<BR>';
			strIVR        += ((x + 1) == arrSubPadron.length) ? '' : '<BR>';   //AGREGADO 15/4/2002.
		} // FIN_for procesar sub elementos.

		// REARMAR los strings.
		arrPadronHTML[i] = strPadronHTML;
		arrSupCat[i]     = strSupCat;
		arrSecJud[i]     = strSecJud;
		arrIndProd[i]    = strIndProd;
		arrIVR[i]        = strIVR;      //AGREGADO 15/4/2002.

		//MODIF_NOTIF 24/6/2004: notificaciones.
		arrLamina[i]     = strLamina;
		arrCoord[i]      = strCoord;
		//FIN_MODIF_NOTIF

	} // FIN_for procesar los arrays paralelos de campos.


	// Rearmar el string de retorno en base a los arrays paralelos.
	for (var i = 0; i < arrLetraDepto.length; i++) {
		strDatosFinalesConExcepciones += arrLetraDepto[i] + ',';
		strDatosFinalesConExcepciones += arrPadronHTML[i] + ',';
		strDatosFinalesConExcepciones += arrSecJud[i] + ',';
		strDatosFinalesConExcepciones += arrSupCat[i] + ',';

		strDatosFinalesConExcepciones += arrLamina[i] + ',';	//MODIF_NOTIF 24/6/2004
		strDatosFinalesConExcepciones += arrCoord[i] + ',';     //MODIF_NOTIF 24/6/2004

		strDatosFinalesConExcepciones += arrIndProd[i] + ',';
		strDatosFinalesConExcepciones += arrIVR[i] + ',';       //AGREGADO 15/4/2002.
		strDatosFinalesConExcepciones += arrPadronGRAF[i] + ',';
		strDatosFinalesConExcepciones += arrNomDepto[i];
		strDatosFinalesConExcepciones += ((i + 1) ==  arrLetraDepto.length) ? '' : ',';
	}

	return strDatosFinalesConExcepciones;
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// MostrarSimbologiaStatusBusq(winVentana, objInfoMaestro)
//
// DESCRIPCION: generar el codigo html para mostrar el significado de los simbolos para los diferentes
//				status de busqueda en winVentana, para el objeto ibjInfoMaestro.
//				La simbologia se muestra en formato tabla para.
//
// PARAMETROS: winVentana   (objeto window) - ventana del browser donde se incluira la descripcion de la
//											  simbologia de los diferente status de busqueda.
//			   objInfoMaestro (objeto InfoMaestro) - objeto InfoMaestro el cual se supone ya ha sido actualizado
//													 luego de pasar por las diferentes etapas de busqueda.
//
// RETORNO: nada.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function MostrarSimbologiaStatusBusq(winVentana, objInfoMaestro)
{
	arrStatus    = new Array();
	arrCodFictos = new Array();
	strFuenteDescrip = '<FONT FACE="Arial" SIZE="-2" COLOR="black">';
	strFuenteSimbolo = '<FONT FACE="Arial" SIZE="2" COLOR="black">';

	arrStatus = objInfoMaestro.ReportarStatusBusq().sort();
	arrCodFictos = objInfoMaestro.ReportarCodFictos().sort();

	// Validar que haya por lo menos algun caso excepcional.
	if (((arrStatus.length == 1) && (arrStatus[0] == 3)) && ((arrCodFictos.length == 1) && (arrCodFictos[0] == 0))) {
		// StatusBusq == 3. Caso normal: SI en MAESTRO. SI en CATCON.
		// CodFicto   == 0. Caso normal: no ficto, no INC.
		// Salir sin mostrar nada. (Son todos casos normales).
		return null;
	}

	winVentana.document.writeln('<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="White">');
	winVentana.document.writeln('<TR><TD BGCOLOR="#CCCCCC" COLSPAN="2"><FONT FACE="Arial" SIZE="-1" COLOR="black"><I><B> Simbología </B></I></FONT></TD></TR>');

	for (var i = 0; i < arrStatus.length; i++) {
		switch (arrStatus[i]) {
			case 0:
				// NO en MAESTRO. NO en CATCON.
				// Simbolo: (***)
				winVentana.document.writeln('<TR>');
				winVentana.document.writeln('<TD WITDH="20%" ALIGN="right">');
				winVentana.document.writeln(strFuenteSimbolo + '<B> *** </B></FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('<TD ALIGN="left">');
				winVentana.document.writeln(strFuenteDescrip + 'Sin datos en el archivo maestro. </FONT>');
				winVentana.document.writeln('<BR>');
				winVentana.document.writeln(strFuenteDescrip + 'Sin ubicación geográfica. </FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('</TR>');
				break;
			case 1:
				// NO en MAESTRO. SI en CATCON.
				// Simbolo: (*)
				winVentana.document.writeln('<TR>');
				winVentana.document.writeln('<TD WITDH="20%" ALIGN="right">');
				winVentana.document.writeln(strFuenteSimbolo + '<B> &nbsp;&nbsp;* </B></FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('<TD ALIGN="left">');
				winVentana.document.writeln(strFuenteDescrip + 'Sin datos en el archivo maestro. </FONT>');
				winVentana.document.writeln('<BR>');
				winVentana.document.writeln(strFuenteDescrip + 'Indice calculado = Indice promedio.</FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('</TR>');
				break;
			case 2:
				// SI en MAESTRO. NO en CATCON.
				// Simbolo: (**)
				winVentana.document.writeln('<TR>');
				winVentana.document.writeln('<TD WITDH="20%" ALIGN="right">');
				winVentana.document.writeln(strFuenteSimbolo + '<B> &nbsp;** </B></FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('<TD ALIGN="left">');
				winVentana.document.writeln(strFuenteDescrip + 'Sin ubicación geográfica. </FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('</TR>');
				break;
			case 3:
				// Nada.
				// Caso normal. SI en MAESTRO. SI en CATCON.
				break;
			default:
				// Nada.
				break;
		}
	}

	for (var i = 0; i < arrCodFictos.length; i++) {
		switch (arrCodFictos[i]) {
			case 1:
				// Ficto.
				// Simbolo: (F) superindice.
				winVentana.document.writeln('<TR>');
				winVentana.document.writeln('<TD WITDH="20%" ALIGN="right">');
				winVentana.document.writeln(strFuenteDescrip + '&nbsp;&nbsp;<SUP><B> F </B></SUP></FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('<TD ALIGN="left">');
				winVentana.document.writeln(strFuenteDescrip + 'Padrón ficto. </FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('</TR>');
				break;
			case 2:
				// I.N.C. (colonizacion).
				// Simbolo: (C) superindice.
				winVentana.document.writeln('<TR>');
				winVentana.document.writeln('<TD WITDH="20%" ALIGN="right">');
				winVentana.document.writeln(strFuenteDescrip + '&nbsp;&nbsp;<SUP><B> C </B></SUP></FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('<TD ALIGN="left">');
				winVentana.document.writeln(strFuenteDescrip + 'Instituto Nacional de Colonización. </FONT>');
				winVentana.document.writeln('</TD>');
				winVentana.document.writeln('</TR>');
				break;
			default:
				// Nada.
				// Caso normal. SI en MAESTRO. SI en CATCON.
				break;
		}
	}

	winVentana.document.writeln('</TABLE>');
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// MostrarLogoFechaHora(winVentana)
//
// DESCRIPCION: generar el codigo html para mostrar el logo del MGAP la fecha y la hora actual.
//				Se usa en la generacion de paginas de Croquis CONEAT y Porcentajes de Suelos.
//
// PARAMETROS: winVentana   (objeto window) - ventana del browser para incluir el logo, fecha y hora.
//
//
// RETORNO: nada.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function MostrarLogoFechaHora(winVentana)
{
	var fechaHoy = new Date();
	var nMes = 1 + fechaHoy.getMonth();
	var strFecha = fechaHoy.getDate() + '/' + nMes + '/' + fechaHoy.getFullYear();
	var strMinutos = (fechaHoy.getUTCMinutes() < 10) ? ("0" + fechaHoy.getUTCMinutes()) : ("" + fechaHoy.getUTCMinutes());
	var strHora = fechaHoy.getHours() + ':' + strMinutos;

	// Logo del MGAP.
	winVentana.document.writeln('<TABLE WIDTH="100%" CELLSPACING="10">');
	winVentana.document.writeln('<TR>');
	winVentana.document.writeln('<TD ALIGN="Left" VALIGN="Bottom">');
	winVentana.document.writeln('<A HREF="http://www.mgap.gub.uy/" TARGET="_blank">');
    winVentana.document.writeln('<IMG BORDER="0" ALT="Ministerio de Ganaderia, Agricultura y Pesca" SRC="http://www.prenader.gub.uy/website/coneat/images/logomgap.jpg">');
    winVentana.document.writeln('</A>');
	winVentana.document.writeln('</TD>');
	// Aclaracion oficial.
	winVentana.document.writeln('<TD ALIGN="Right" VALIGN="Bottom">');
	MostrarAclaracionOficial(winVentana);
	winVentana.document.writeln('</TD>');
	// Fecha y hora.
	winVentana.document.writeln('<TD ALIGN="Right" VALIGN="Bottom">');
	//winVentana.document.writeln('<BR>');
	winVentana.document.writeln('<FONT FACE="Arial" SIZE="1" COLOR="black">' + strFecha + ' - ' + strHora + '</FONT>');
	winVentana.document.writeln('</TD>');
	winVentana.document.writeln('</TR>');
	winVentana.document.writeln('</TABLE>');
}


// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// MostrarLogoFechaHora(winV)
//
// DESCRIPCION: generar el codigo html para mostrar la aclaracion de informacion no oficial al pie de las
//				paginas correspondientes.
//
// PARAMETROS: winV   (objeto window) - ventana del browser.
//
// RETORNO: nada.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function MostrarAclaracionOficial(winV)
{
	strComunicado = "De acuerdo a las normas vigentes, esta información, para tener validez legal, " +
	                "deberá contar con sello y firma autorizada.";

	winV.document.writeln('<TABLE WIDTH="100%" CELLSPACING="1">');
	winV.document.writeln('<TR>');
	winV.document.writeln('<TD BGCOLOR="white" ALIGN="Left" VALIGN="Bottom">');
	winV.document.writeln('<FONT FACE="Arial" SIZE="1" COLOR="black"><I>' + strComunicado + '</I></FONT>');
	winV.document.writeln('</TD>');
	winV.document.writeln('</TR>');
	winV.document.writeln('</TABLE>');
}

// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
// _DebugWin(strTexto)
//
// DESCRIPCION: para ayudar con los debugs. Se abre un nuevo browser mostrando strTexto.
//
//
// PARAMETROS: strTexto (string) - texto a mostrar.
//
// RETORNO: nada.
// ---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F
function _DebugWin(strTexto)
{
	nHasta = (strTexto.length <= 40) ? 40 : strTexto.length;

	var winV = open("","_blank");
	winV.document.writeln('<HTML>');
	winV.document.writeln('<TITLE>Debug - '+ strTexto.substr(0, nHasta)+ '</TITLE>');
	winV.document.writeln('<BODY BGCOLOR="White" TEXT="Black" LEFTMARGIN="0" TOPMARGIN="0">');

	// Reemplazar los < y > para que no se interpreten como html.
	//var rePatron    = new RegExp("\s*" + strSeparador + "\s*");
	var reMenor = /</g;
	var reMayor = />/g;

	var strTextoLimpio = strTexto.replace(reMenor, "&lt;");
	strTextoLimpio = strTextoLimpio.replace(reMayor, "&gt;");

	winV.document.writeln('<CODE>');
	winV.document.writeln(strTextoLimpio);
	winV.document.writeln('</CODE>');

	winV.document.writeln('</BODY>');
	winV.document.writeln('</HTML>');
	winV.document.close();
	winV = null;
}

