window.document.onhelp 		= returnFalse;
window.document.onkeydown = proccesEvtHandler;
window.onbeforeunload			= onBeforeUnloadHandler;
window.onunload						= onDesconnetSession;

function onDesconnetSession(){
		closeApp();
}

function onBeforeUnloadHandler(){	
		//alert("¿ Esta seguro de salir ?");
}

function WpGetFrameset() {
	par = (window.opener)?window.opener:parent;
	while(1){
		if(par && par.theApp){
			theApp = par.theApp;
			break;
		}
		else if(!par.parent)
			break;
		else if(par != par.parent)
			par = par.parent;
		else
			break;
	}
	return par;
}
//Manejador de las teclas de funcion
function proccesEvtHandler(e)
{
	//Suprimir: 46
	//Intro: 13
	
	var evt = (e)? e: ((event) ? event: null);
	if( evt )
	{
		var tar = (e)?evt.target:evt.srcElement;
		var kCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : evt.which);
		
		/*
		var oRegExp = new RegExp(/112|113|114|115|116|117|118|119|120|121|122|123|124/);
		if( oRegExp.test( kCode ))
		{	
			if( evt.returnValue )
				evt.returnValue = false;
			else if( evt.preventDefault )
				document.onkeypress = function() { evt.preventDefault(); }
			else
				returnFalse(evt);
		}
		*/
		
		var oRegExp = new RegExp(/13|46|112|113|114|115|116|117|118|119|120|121|122|123|124/);
		if( oRegExp.test( kCode ))
		{	
					if( evt.preventDefault ) {
						document.onkeypress = function() { return false; }
						//document.onkeypress = function(evt) { evt.preventDefault();  }
					}else {
						returnFalse();
					}
					
					var _top = window.top;
					
					if( kCode == 13)//INTRO
					{
						/* procesar el intro en el form de acceso */
						if(tar && (tar.name == "user" || tar.name == "pass")){
							var oForm = tar.form;
							if(oForm){
								oForm.submit();
							}
						}
						/*
						if(window.name=="f0")
						{
							var evtElem = window.event?evt.srcElement:evt.target;
							if( evtElem.tagName == "INPUT")
								openAlbala();
						}
						else//INTRO
						{
							/ * solo debo procesar el INTRO en caso de ser un tipo especial de campo * /
							if(tar && (tar.name == "TI73" || tar.name == "TI75" || tar.name == "TI76" || tar.name == "TI78" || 
							tar.name == "TI80" || tar.name == "TI81" || tar.name == "TI84" || tar.name == "TI95" || tar.name == "TI98" || 
							tar.name == "T102" || tar.name == "T104" || tar.name == "T105" || tar.name == "T106" || tar.name == "T108" ||
							tar.name == "T109" || tar.name == "TI85" || tar.name == "TI86" || tar.name == "TI92" || tar.name == "TI94" ||
							tar.name == "TI97" || tar.name == "T103")){
								addElementToInputIntro(tar);
							}else{*/
								document.onkeypress = function() { return true; }
							/*}
							//var evtElem = window.event?evt.srcElement:evt.target;
							//if( evtElem.tagName != "TEXTAREA" )
							//	enviado();
						}
						*/
					}
					if( kCode == 46 ) //---> SUPR:	En ciertos campos debe eliminar el contenido del select-multiple
					{
						/*
							/ * solo debo procesar el SUPR en caso de ser un tipo especial de campo * /
							if(tar && (tar.name == "TI16_LST" || tar.name == "TI10_LST" || tar.name == "DESC_LST" ||
							   tar.name == "TI48_LST" || tar.name == "TI49_LST" || tar.name == "TI50_LST" || tar.name == "TI51_LST" ||
								 tar.name == "TI34_LST" || tar.name == "TI35_LST" || tar.name == "TI73_LST" || tar.name == "TI75_LST" ||
				    		 tar.name == "TI76_LST" || tar.name == "TI78_LST" || tar.name == "TI80_LST" || tar.name == "TI81_LST" ||
								 tar.name == "TI84_LST" || tar.name == "TI95_LST" || tar.name == "TI98_LST" || tar.name == "T102_LST" || 
								 tar.name == "T104_LST" || tar.name == "T105_LST" || tar.name == "T106_LST" || tar.name == "T108_LST" ||
								 tar.name == "T109_LST" || tar.name == "TI85_LST" || tar.name == "TI86_LST" || tar.name == "TI97_LST" ||
								 tar.name == "T103_LST" || tar.name == "TI92_LST" || tar.name == "TI94_LST" || tar.name == "TI74_LST" ||
								 tar.name == "TI90_LST" || tar.name == "TI93_LST" || tar.name == "T116_LST" || tar.name == "T117_LST" || 
								 tar.name == "T118_LST")){
								delElementFromSelect(tar);
							}else{*/
								document.onkeypress = function() { return true; }
							//}
					}					
					if( kCode == 112 )//---> F1 : Ayuda del Navegador
					{
						if(_top.msgFunciones != "undefined")
							alert(_top.msgFunciones);
					}
					//Fuentes pequeñas
					if( kCode == 113 )//---> F2 : Fuentes pequeñas
					{
						//_top.changeStyle(_top.wCGI, 1, "FINICIO");
					}
					//Fuentes normales
					if( kCode == 114 )//---> F3 : Foco al menu superior
					{
						//_top.changeStyle(_top.wCGI, 2, "FINICIO");
					}
					//Fuentes grandes
					if( kCode == 115 )//---> F4 : Foco al menu inferior
					{
						//_top.changeStyle(_top.wCGI, 3, "FINICIO");
					}
					if( kCode == 116 ) // F5 ( Recarga el marco actual )
					{
						//var oForm = _top.f11.document.BUSQLIBRE;
						//var oForm = _top.f11.document.forms[0];
						//formFocus(oForm);
						//oCont.location.reload();
					}
					//Alto contraste
					if( kCode == 117 ) // F6
					{
						//_top.changeStyle(_top.wCGI, 4, "FINICIO");
					}
					//Tecla F7:  Ocultar menu lateral
					if( kCode == 118 ) // F7
					{
						//_top.OnOcultarFrame(_top.wIMG);
					}
					if( kCode == 119 ) // F8 : Cambiar de contraseña /usuario
					{
						//_top.OpenWindow(_top.wCGI,"","CHANGE_USER",30,30);
						//_top.OpenWindow(_top.wCGI, "", "PASSWORD",30,30);
					}		
					if( kCode == 120 ) // F9 : Cambiar Idioma
					{
						//_top.OpenWindow(_top.wCGI, "", "LANG",50,40);
					}
					if( kCode == 121 ) // F10 : Ver COF
					{
						//_top.OpenWindow(_top.wCGI, "COF", "IMPRIMIR",50,80);
					}
					if( kCode == 122 ) // F11 : Ayuda
					{
						//_top.OnAbrirAyuda(_top.wCGI);
					}
					if( kCode == 123 ) // F12 : Salir
					{
						//_top.OnSalir(_top.wCGI);
					}
		} else {
			document.onkeypress = function() { return true; }
		}
		
		
		//alert(parent.top.document.body.innerHTML);
	}
}
function returnFalse()
{
	try{event.keyCode = 0;} catch(e){}
	event.cancelBubble = true;
	event.returnValue = false;
	return false;
}
