// JavaScript Document
var objDivMenuD = null;

//document.oncontextmenu=menuBotaoDireito;
//document.onclick=escondeMenuBotaoDireito;

function menuBotaoDireito(e){
	if(!objDivMenuD){
		objDivMenuD = document.createElement('DIV');
		objDivMenuD.style.position = 'absolute'; 
		objDivMenuD.id = 'divMenuBotaoDireito';
		objDivMenuD.style.border = 'solid 1px';
		objDivMenuD.style.borderLeftColor = '#D4D0C8';
		objDivMenuD.style.borderTopColor = '#D4D0C8';
		objDivMenuD.style.borderRightColor = '#404040';
		objDivMenuD.style.borderBottomColor = '#404040';

		objTableBody = document.createElement('TBODY');
		
		objTD = document.createElement('TD');
		if(logGerado)
			objTD.style.display = 'none';
		else
			objTD.style.display = '';
		objTD.id = '_td_menu_ativarLog';
		objTD.style.paddingLeft = '18';
		objTD.style.paddingRight = '18';
		objTD.innerHTML = 'Ativar log';
		objTD.onmouseover = new Function('this.bgColor = "#0A246A"; this.style.color = "#FFFFFF"')
		objTD.onmouseout = new Function('this.bgColor = "#D4D0C8"; this.style.color = "#000000"')
		objTD.onclick = new Function('ativarLog(1)');
		
		objTR = document.createElement('TR');
		objTR.appendChild(objTD);
		objTableBody.appendChild(objTR);

		objTD = document.createElement('TD');
		objTD.id = '_td_menu_desativarLog';
		if(logGerado)
			objTD.style.display = '';
		else
			objTD.style.display = 'none';
		objTD.style.paddingLeft = '18';
		objTD.style.paddingRight = '18';
		objTD.innerHTML = 'Desativar log';
		objTD.onmouseover = new Function('this.bgColor = "#0A246A"; this.style.color = "#FFFFFF"');
		objTD.onmouseout = new Function('this.bgColor = "#D4D0C8"; this.style.color = "#000000"');
		objTD.onclick = new Function('ativarLog(0)');
		
		objTR = document.createElement('TR');
		objTR.appendChild(objTD);
		objTableBody.appendChild(objTR);

		objTable = document.createElement('TABLE');
		//objTable.style.width = '100px';
		objTable.style.cursor = 'default';
		objTable.style.border = 'solid 1px';
		objTable.style.borderLeftColor = '#FFFFFF';
		objTable.style.borderTopColor = '#FFFFFF';
		objTable.style.borderRightColor = '#808080';
		objTable.style.borderBottomColor = '#808080';
		objTable.style.backgroundColor = '#D4D0C8';
		objTable.style.fontFamily = 'Arial';
		objTable.style.fontSize = '11';

		objTable.appendChild(objTableBody);
		objDivMenuD.appendChild(objTable);
	}
	var ie5 = (navigator.appName == 'Microsoft Internet Explorer');
	//Find out how close the mouse is to the corner of the window
	var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX;
	var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY;
	
	//if the horizontal distance isn't enough to accomodate the width of the context menu
	if (rightedge<objDivMenuD.offsetWidth)
	//move the horizontal position of the menu to the left by it's width
	objDivMenuD.style.left=ie5? document.body.scrollLeft+event.clientX-objDivMenuD.offsetWidth : window.pageXOffset+e.clientX-objDivMenuD.offsetWidth
	else
	//position the horizontal position of the menu where the mouse was clicked
	objDivMenuD.style.left=ie5? document.body.scrollLeft+event.clientX : window.pageXOffset+e.clientX;
	
	//same concept with the vertical position
	if (bottomedge<objDivMenuD.offsetHeight)
	objDivMenuD.style.top=ie5? document.body.scrollTop+event.clientY-objDivMenuD.offsetHeight : window.pageYOffset+e.clientY-objDivMenuD.offsetHeight
	else
	objDivMenuD.style.top=ie5? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY;
	
	if(!document.getElementById('divMenuBotaoDireito')){
		document.body.appendChild(objDivMenuD);
	}
	else{
		if(logGerado) {
		document.getElementById('_td_menu_ativarLog').style.display = 'none';
		document.getElementById('_td_menu_desativarLog').style.display = '';
		} else {
		document.getElementById('_td_menu_ativarLog').style.display = '';
		document.getElementById('_td_menu_desativarLog').style.display = 'none';
		}
		document.getElementById('divMenuBotaoDireito').style.display = '';
	}
	
	
	return false;
}

function escondeMenuBotaoDireito(){
	if(document.getElementById('divMenuBotaoDireito')){
		document.getElementById('divMenuBotaoDireito').style.display = 'none';
	}
}