var b = navigator.appName;
if (b=="Netscape") b = "ns"
else if (b=="Microsoft Internet Explorer") b = "ie"

var wndEmissao;

document.onkeydown = function (keyStroke){
	var evento;
	if(navigator.appName == 'Microsoft Internet Explorer')
		evento = event;
	else
		evento = keyStroke;
	if(evento.keyCode==76 && evento.altKey && evento.ctrlKey && evento.shiftKey){
		frames['iFrmAuxiliar'].document.location.href = 'ativar_log.php';
	}
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function gerarCombo(objCombo, cPrimeiraOpcao, cValores, bMostrarCodigo, bSelQuandoApenasUmReg, cValorSelecionado)
{
	var newObj;
	var arrayVal;

	objCombo = document.getElementById(objCombo);
	objCombo.innerHTML = '';
	objCombo.value = '';

	if(newObj)
	{
		newObj = null;
	}
	
	arrayVal = cValores.split('||');
	
	if(cPrimeiraOpcao != '')
	{
		newObj = document.createElement('OPTION');
		newObj.value = '';
		if (b=="ie") newObj.innerText = cPrimeiraOpcao;
		if (b=="ns") newObj.text = cPrimeiraOpcao;
		objCombo.appendChild(newObj);
	}

	for(i=0; i<arrayVal.length; i++)
	{
		cVal = base64decode(arrayVal[i].substr(0, arrayVal[i].indexOf(';')));
		cDesc = base64decode(arrayVal[i].substr(arrayVal[i].indexOf(';') + 1));
		
		if(cVal != '')
		{
			if(newObj)
			{
				newObj = null;
			}
			newObj = document.createElement('OPTION');
			newObj.value = cVal;
			if(cValorSelecionado){
				if(cVal == base64decode(cValorSelecionado)){
					newObj.selected = 'selected';
				}
			}
			if(bMostrarCodigo)
			{
				if (b=="ie") newObj.innerText = cVal + ' - ' + cDesc
				if (b=="ns") newObj.text = cVal + ' - ' + cDesc
			}
			else
			{
				if (b=="ie") newObj.innerText = cDesc;
				if (b=="ns") newObj.text = cDesc;
			}
			objCombo.appendChild(newObj);
		}
	}
	//objCodigoCombo = document.getElementById('campoCodigoComboPadrao_' + objCombo.name);
	//if(objCodigoCombo && !bOnLoad) objCodigoCombo.value = '';
	//if(objCodigoCombo) objCodigoCombo.value = '';
}

function abreJanelaEmissao(url)
{
	if(screen)
	{
	  sHeight = screen.availHeight
	  sWidth = screen.availWidth
	  wHeight = 1     //new window height
	  wWidth = 1      //new window width
	  wLeft = 0  //left position
	  wTop = 0 //top position
	  if(wndEmissao){
			wndEmissao.close();
			wndEmissao= null;
	  }
	  wndEmissao= window.open(url,"","left=" + wLeft + ",top=" + wTop + ",width=" + wWidth + ",height=" + wHeight + ",scrollbars=yes, menubar=yes")
	  try{
		 	wndEmissao.resizeTo(sWidth, sHeight);
		}
		catch(e){
			alert("Atenção: existe um bloqueador de janelas pop-up ativo no seu navegador. Desative o bloqueador e tente novamente.");
		}
	}
}
