﻿// Redirige la solicitud para el nivel superior relativo a la ubicacion actual
IrAPrincipal = function ()
{
	location = '../';
}


// Limpia el valor de un campo
Limpiar = function (strFieldID)
{
	var txtField;
	
	
	txtField = document.getElementById (strFieldID);
	
	txtField.value = '';
	
	txtField.focus ();
}


// Muestra una division de texto flotante sobre un elemento
MostrarToolTip = function (strElementID)
{ 			
	var objElement;
	var divTooltip;

	
	objElement = document.getElementById (strElementID); 
	divTooltip = document.getElementById ("divTooltip");
		
	if (objElement.selectedIndex == -1) { return; }
		
	if (objElement.options [objElement.selectedIndex].value != "") 
	{
		divTooltip.innerHTML = objElement.options [objElement.selectedIndex].text;
		
		//Formato Tooltip 
 		divTooltip.style.zIndex = "1000"; 
  		divTooltip.style.display = "inline"; 
  		divTooltip.style.position = "absolute"; 
 		divTooltip.style.border =  "ActiveBorder 1px solid"; 
		divTooltip.style.padding =   "3px";  
		divTooltip.style.fontSize =  "10px"; 
		divTooltip.style.fontFamily = "Arial, Helvetica"; 
		divTooltip.style.backgroundColor = "LemonChiffon";
		divTooltip.style.top = MouseManager.Y + "px";
		divTooltip.style.left =	1 + MouseManager.X + "px";
		divTooltip.style.filter = "filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135,Strength=2);";		
	}
} 


// Oculta una division de texto
OcultarToolTip = function ()
{ 
	var divTooltip;
	
	
	divTooltip = document.getElementById ("divTooltip");	
	divTooltip.style.display = "none"; 
}




// Manejo de errores en JS
NoErrorMessages = function  () 
{
	return true; 
}


// Limpia el contenido del iframe que muestra al reporte
LimpiarIframeReporte = function ()
{
	MostrarReporte ('');
}


// Muestra una URL en el area del iframe del reporte
MostrarReporte = function (strUrl)
{
	var ifrReporte;
	
	var divReporte;
	
	//if (strUrl.length > 300) { alert ("La solicitud al servidor de reportes no es admitida\npor la longitud resultante de caracteres de consulta.\n\nPruebe disminuyendo la cantidad de parametros diligenciados."); return; }
		
	divReporte = document.getElementById ("divReporte");
	
	if (strUrl.length == 0) { divReporte.innerHTML = ""; return; }
	
	divReporte.innerHTML = "<fieldset><legend>Resultado</legend><iframe id='ifrReporte' frameborder='no'></iframe></fieldset>";
	
	ifrReporte = document.frames ("ifrReporte");
	
	var strFormulario =
		'<style>	body { font-size: 12px;	margin: 8px 0px 0px 0px;	font-family: helvetica,arial,sans-serif; }	.tdMensaje { font-size: 14px;	margin: 8px 0px 0px 0px;	font-family: helvetica,arial,sans-serif; } </style>' +
		'<table width="100%" height="100%"><tr valign="top"><td align="center"><table width="305"><tr><td class="tdMensaje"><br/><br/><br/><br/><br/><br/>Procesando el reporte, espere un momento...</td></tr></table></td></tr></table>';
	
	ifrReporte.document.write (strFormulario);
	
	ifrReporte.document.location = strUrl;
}


CopiarSeleccionados = function (ddlSource, ddlDestination)
{
	var currentOption;
	var newOption;
	

	for (var i in ddlSource.options)	
	{
		currentOption = ddlSource.options [i];
		
		if (typeof (currentOption.value) != "undefined" && !esanchezfo.js.IsThereOptionByValue (ddlDestination, currentOption.value))
		{
			newOption = document.createElement ('OPTION');
			newOption.text = currentOption.text;
			newOption.value = currentOption.value;
			
			ddlDestination.options.add (newOption, ddlDestination.options.length);
		}
	}
}


IsNull = function (pobj)
{
	return (pobj == null || typeof (pobj) == "undefined");
}


IfIsNull = function (pobj, pobjReplace)
{
	if (IsNull (pobj)) { return pobjReplace; }
	return pobj;
}


Hide = function (pobj)
{
	pobj = document.getElementById (pobj.id);

	pobj.style.display = 'none';
	pobj.style.visibility = 'hidden';
}


Show = function (pobj)
{
	pobj = document.getElementById (pobj.id);
	
	pobj.style.display = '';
	pobj.style.visibility = 'visible';
}


IsVisible = function (pobj)
{
	var pbln = true;
	
	if (typeof (pobj.style.visibility) != "undefined") { pbln = pbln && (pobj.style.visibility != "hidden"); }
	
	if (typeof (pobj.style.display) != "undefined") { pbln = pbln && (pobj.style.display != "none"); }
	
	return pbln;
}


IfHideShow = function (pobj, pbln)
{
	if (pbln) { return Show (pobj); }

	return Hide (pobj);
}



// Permite acceder a las propiedades del puntero (mouse) del cliente (navegador)
// utilizado generalmente para posicionar un elemento en la ubicacion de la selección actual del usuario
MouseManager = 
{
	X : 0,
	
	Y : 0,
		
	OnMouseMove : function (objEvent)
	{
		objEvent = objEvent || window.event;
		
		MouseManager.X = objEvent.clientX;
		MouseManager.Y = objEvent.clientY;
	}
}

// Eventos
// Al mover el raton se delega su manejo a la clase MouseManager
document.onmousemove = MouseManager.OnMouseMove;
// No mostrar excepciones de JS eventuales
window.onerror = NoErrorMessages;
// Mensaje por defecto
window.defaultStatus = "Listo";





/****************/
/* Código ... */
/****************/

function ObtenerElementoSimilarId(a, pItemId) {
	for (var i=0; i<a.length; i++)
		if (a[i].id.indexOf(pItemId) > -1)
			return (a[i]);
	return null;
}


function SeleccionarTodos(pChecked, pItemName) 
{
	var f = document.forms[0];
	var i = 0;
	
	for (i=0; i<f.elements.length; i++)
	{
		if ((f.elements[i].type == 'checkbox') && (f.elements[i].name.indexOf(pItemName) > -1))
		{
			f.elements[i].checked = pChecked;
			f.elements[i].fireEvent("onclick");
		}
	}
}

	
function ActivarBotones(pItemName)
{
	var f = document.forms[0];
	var i = 0;
	var blnActivar = false;
	var blnActivarTodos = true;
	var chkHdSeleccionar;
	var ibtnEliminar;


	for (i=0; i<f.elements.length; i++)
	{
		try
		{
			if ((f.elements[i].type == 'checkbox') && (f.elements[i].name.indexOf('chkTodos') > -1))
			chkHdSeleccionar = f.elements[i];

			else if ((f.elements[i].type == 'submit') && (f.elements[i].name.indexOf('btnEliminar') > -1))
			ibtnEliminar = f.elements[i];

			if ((f.elements[i].type == 'checkbox') && (f.elements[i].name.indexOf(pItemName) > -1))
			{
				blnActivar = (blnActivar || f.elements[i].checked);
				blnActivarTodos = (blnActivarTodos && f.elements[i].checked);
			}
		}catch (ex) {}
	}

	chkHdSeleccionar.checked = (blnActivarTodos);
	ibtnEliminar.disabled = (!blnActivar);
}
