//Variaveis
var thismenu = Array();
var _xmouse = 0;
var _ymouse = 0;
var _ascii = 0;
var _ultascii = 0;

/*---------------------
 Funcões Básicas
---------------------*/
function byId(id){
	return document.getElementById(id);
}

function newDiv(n,at){
	if (!at)at=document.body;
	nObj = document.createElement("DIV");
	nObj.id = n;
	nObj.name = n;
	at.appendChild(nObj);	
	return nObj;
}

function getLeft(obj){
	if (!obj)return false;
	_x=0;
	objtemp=obj;
	while (objtemp.parentNode){
		//objtemp.style.border='1px dashed blue';
		//alert(objtemp.tagName + ' = ' + objtemp.offsetLeft);
		if (objtemp.tagName != 'TR' && objtemp.tagName != 'TD' && objtemp.tagName != 'TBODY' && objtemp.tagName != 'TABLE'){
		   _x+=objtemp.offsetLeft;
		}
		objtemp=objtemp.parentNode;	
	}
	return _x;
}

function getTop(obj){
	if (!obj)return false;
	_y=0;
	objtemp=obj;
	while (objtemp.parentNode){
		if (objtemp.tagName != 'TR' && objtemp.tagName != 'TD' && objtemp.tagName != 'TBODY' && objtemp.tagName != 'TABLE'){
			//objtemp.style.border='1px dashed blue';
			//alert(objtemp.tagName + ' = ' + objtemp.offsetTop);
		   _y+=objtemp.offsetTop;
		}
		objtemp=objtemp.parentNode;	
	}
	return _y;
}

//Função de Transparencia num objeto
function setOpacity(obj,valor){
	obj.opacity=valor;
	if(document.all){
		obj.style.filter='alpha(opacity='+valor+')';
	}else{
		obj.style.opacity=(valor/100);
	}
}


/*-----------------------
 Funcões para os eventos
------------------------*/
function CaptMouse(e){
   _xmouse = ((document.all)?event.clientX:e.pageX)+document.body.scrollLeft;
   _ymouse  = ((document.all)?event.clientY:e.pageY)+document.body.scrollTop;
	//document.title='x='+_xmouse+' y='+_ymouse+ ' ascii='+_ascii+' Tecla='+ String.fromCharCode(_ascii);
	//return false;
}

function CaptTecla(e){
	_ultascii = _ascii;
	_ascii = (!document.all)?e.keyCode:event.keyCode	
	if(_ultascii == 17 || _ultascii == 18){
		for(i=0;i<thismenu.length;i++)thismenu[i].presskey(String.fromCharCode(_ascii));
	}
	if(_ascii==112)CaptHelp();
	//document.title='x='+_xmouse+' y='+_ymouse+ ' ascii='+_ascii+' Tecla='+ String.fromCharCode(_ascii);
	//return false;
}
function ContextMenu(){
	//alert('Você apertou o botão direito do mouse');
	return false;
}
function CaptHelp(){
	//alert('Você apertou o botão F1');
	return false;
}

/*função que inicia o Frame Work*/
function InitMyFrameWork(){
	if(!document.all){
		document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP | Event.CONTEXTMENU | Event.KEYDOWN | Event.KEYUP | Event.KEYPRESS |  Event.SELECTSTART)
	}	
	//document.oncontextmenu=ContextMenu;
	document.onmousemove=CaptMouse;
	document.onhelp=Function("return false");
	document.onkeydown=CaptTecla;
	document.onselectstart=new Function("return false;");
	//document.body.onscroll=PageScroll;
	//document.body.onclick = Function("for(im=0;im<thismenu.length;im++){thismenu[im].allvis=0;thismenu[im].hideall();}");
}

/*---------------------
 Funcões de testes
---------------------*/
function debug(txt){
	objdebug = byId('my_framework_div_debug')
	if(!objdebug){
		objdebug=new newDiv('my_framework_div_debug',null,'');
		objdebug.style.position='absolute';
		objdebug.style.width='99%';
		objdebug.style.height='150px';
		objdebug.style.overflow='auto';
		objdebug.style.left='0px';
		objdebug.style.bottom='0px';
		objdebug.style.border='1px solid red';
	}
	objdebug.innerHTML+=txt+'<br>';
}
