///////////////////////////////////////////////////////////////////
//                    Dawcons Asociados S.C.                     //
//              Funciones de Uso General en Página               //
//                        Octubre 2005                           //
///////////////////////////////////////////////////////////////////
function bckProcesa(pTipo)
{
	// Función que despliega una transparencia al momento de procesar una página.
	// Se utilizará en el 'onsubmit' de la o las formas de una página.
	// También se puede llamar antes de navegar a otra página (ver Navegar(pURL)).
	var pIsValid;
	// Se verifica la validación de la página...
	try{
		pIsValid = Page_IsValid;
	}
	catch(ex)
	{
		pIsValid = true;
	}
	if(pIsValid)
	{
		if(!pTipo) pTipo = 0;
		// Se crea el Div de Proceso en la página...
		if(pTipo == 0) // Ventana Normal...
		{
			var sHTML = '<div id="divProc" runat="server" style="Z-INDEX:10000;FILTER:Alpha(opacity=30);LEFT:0px;WIDTH:1024px;CURSOR:wait;POSITION:absolute;TOP:0px;HEIGHT:768px;BACKGROUND-COLOR:#cccccc"></div>';
			document.body.insertAdjacentHTML("beforeEnd", sHTML);
			// Se mueve la ventana a la posición 0,0. Esta línea puede omitirse si se requiere...
			window.moveTo(0,0);
		}
		if(pTipo == 1) // Ventana de 500x400...
		{
			var sHTML = '<div id="divProc" runat="server" style="Z-INDEX:10000;FILTER:Alpha(opacity=30);LEFT:0px;WIDTH:510px;CURSOR:wait;POSITION:absolute;TOP:0px;HEIGHT:450px;BACKGROUND-COLOR:#cccccc"></div>';
			document.body.insertAdjacentHTML("beforeEnd", sHTML);
		}
		if(pTipo == 2) // Ventana de 700x500...
		{
			var sHTML = '<div id="divProc" runat="server" style="Z-INDEX:10000;FILTER:Alpha(opacity=30);LEFT:0px;WIDTH:710px;CURSOR:wait;POSITION:absolute;TOP:0px;HEIGHT:550px;BACKGROUND-COLOR:#cccccc"></div>';
			document.body.insertAdjacentHTML("beforeEnd", sHTML);
		}
	}
}// bckProcesa
function EliminaEnter(pTipo)
{
	// Función de validaciones de Teclas.
	// Se implementa en el 'onkeydown' del BODY.
	if((event.keyCode == 116) || (event.keyCode == 122))
	{
		// Valida el F5 y evita su efecto...
		event.keyCode = 505;
		event.cancelBubble = true;
		event.returnValue = false;
		return false;
	}
	if(event.keyCode == 13)
	{
		// Valida el ENTER y evita su efecto a menos que sea en un TextArea...
		var sTag = event.srcElement.tagName
		var sAcc = event.srcElement.Accion
		if(sTag != "TEXTAREA")
		{
			if(pTipo)
			{
				var sTipo = event.srcElement.type;
				if((sTipo != "image") && (sTipo != ""))
				{
					event.keyCode = 9;
				}
			}
			else
			{
				event.cancelBubble = true;
				event.returnValue = false;
			}
		}
		if(sAcc != undefined)
		{
			eval("document.all." + sAcc + ".click()");
		}
	}
	if(event.keyCode == 8)
	{
		// Valida el BackSpace y evita su efecto a menos que sea en un TextArea o Text...
		var sTag = event.srcElement.tagName
		var sAcc = event.srcElement.Accion
		if((sTag != "TEXTAREA") && (sTag != "INPUT"))
		{
			event.keyCode = 505;
			event.cancelBubble = true;
			event.returnValue = false;
			return false;
		}
	}
	if(event.altKey)
	{
		if((event.keyCode == 37)||(event.keyCode == 39))
		{
			// Se evita navegar en histórico con flechas...
			event.keyCode = 505;
			event.cancelBubble = true;
			event.returnValue = false;
			alert("ERROR: Favor de utilizar las opciones del Sistema para navegar.");
			return false;
		}
	}
}// EliminaEnter
function EliminaSeleccion()
{
	// Función de Eliminación de selección.
	// Se utiliza en el 'onselectstart' del BODY.
	var sTag = event.srcElement.tagName
	// Elimina la selección a menos que se encuentre dentro de un INPUT o un TEXTAREA...
	if((sTag != "INPUT") &&
		(sTag != "TEXTAREA"))
	{
		event.cancelBubble = true;
		event.returnValue = false;
	}
}// EliminaSeleccion
function Navegar(pURL, pTipo)
{
	// Se ajustan los predefinidos...
	pURL = pURL.replace(/\[NIVEL\]/g, "../../");
	pURL = pURL.replace(/\[HOME\]/g, "comun/generales/pag_principal.aspx");
	pURL = pURL.replace(/\[LOGIN\]/g, "comun/generales/LogIn.aspx");
	pURL = pURL.replace(/\[LOGOUT\]/g, "comun/generales/LogOut.aspx");
	// Se inicia pantalla de proceso...
	bckProcesa(pTipo);
	// Se navega a la URL especificada...
	window.navigate(pURL);
}// Navegar
function Enviar(pForm)
{
	// Se ejecuta el onsubmit...
	pForm.fireEvent("onsubmit");
	// Se hace el submit...
	pForm.submit();
}// Navegar
function Ruta(pRut)
{
	if(!pRut)
	{
		if(document.all.hidRuta) pRut = document.all.hidRuta.value;
	}
	document.all.spnRuta.innerHTML = pRut;
}// Ruta
function EditaDato(pTipo, pTDato, pDato)
{
	// Se obtinene los Datos...
	var aDat = document.all.hidDatosCC.value.split('@');
	// Se cambia el Dato...
	aDat[pTDato] = pDato;
	// Se guardan de nuevo...
	var iCnt, sAux = "";
	for(iCnt = 0; iCnt < aDat.length; iCnt++)
	{
		if(iCnt > 0) sAux += "@";
		sAux += aDat[iCnt];
	}
	document.all.hidDatosCC.value = sAux;
	MsgCC(pTipo);
}// EditaDato
function ExpXLS()
{
	if(document.all.hidXLS)
	{
		if(document.all.hidXLS.value != "")
		{
			window.open(document.all.hidXLS.value, "", "");
		}
		document.all.hidXLS.value = "";
	}
}// ExpXLS
function Help()
{
	// Función para despliegue de ayuda contextual...
	var sCntx = "";
	if(document.all.hidHelp)
	{
		sCntx = document.all.hidHelp.value;
	}
	// Se abre la ventana con la ayuda dirigida...
	window.open("../../comun/ayuda/pag_help.aspx?cntx=" + sCntx, "", "status=no, width=500, height=600, resizable=yes, top=20, left=" + (window.screen.availWidth - 510) +  "");
}// Help
function EnVentanaNueva(sURL, iWidth, iHeight, iTipo)
{
	var iPosX = 0;
	var iPosY = 0;
	iPosX = window.screen.availWidth;
	iPosY = window.screen.availHeight;
	iPosX = (iPosX - iWidth) / 2;
	iPosY = (iPosY - iHeight) / 2;
	if(iTipo == 1)
	{
		try
		{
			_evn.close();
		}
		catch(ex)
		{}
	}
	if(iTipo == 2)
	{
		try
		{
			var sLoc = String(_evn.location)
			if(sLoc.indexOf(sURL.replace(/\.\.\//g,"")) >= 0)
			{
				_evn.focus();
			}
			else
			{
				_evn.close();
				_evn = window.open(sURL,"","status=yes, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, titlebar=no, toolbar=no, Width=" + iWidth + ", Height=" + iHeight + ", Top=" + iPosY + ", Left=" + iPosX);
			}
		}
		catch(ex)
		{
			_evn = window.open(sURL,"","status=yes, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, titlebar=no, toolbar=no, Width=" + iWidth + ", Height=" + iHeight + ", Top=" + iPosY + ", Left=" + iPosX);
		}
	}	
	else
	{
		_evn = window.open(sURL,"","status=yes, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, titlebar=no, toolbar=no, Width=" + iWidth + ", Height=" + iHeight + ", Top=" + iPosY + ", Left=" + iPosX);
	}
	opener.AgregarVentana(_evn);
}