// JavaScript Document
function abrirPagina(cUrl){
	if(document.forms[0].Logado.value == 'false'){
		alert('Você precisa logar antes de acessar os serviços.'); document.forms[0].txtUsuario.focus(); return false;}
	document.location.href = cUrl;}

function abreJanela(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(newWindow)
	  {
		newWindow.close();
		newWindow = null;
	  }
	  newWindow = window.open(url,"","left=" + wLeft + ",top=" + wTop + ",width=" + wWidth + ",height=" + wHeight + ",scrollbars=yes, menubar=yes")
	  newWindow.resizeTo(sWidth, sHeight);
	}
}

var newWindow;

function abreJanelaCentro(url, nHeight, nWidth, cAdicional){
	if(screen){
		sHeight = screen.height
		sWidth = screen.width
		wHeight = nHeight    //new window height
		wWidth = nWidth     //new window width
		wLeft = (sWidth - wWidth) / 2  //left position
		wTop = (sHeight - wHeight) / 2 //top position
		
		newWindow = window.open(url,"","left=" + wLeft + ",top=" + wTop + ",width=" + wWidth + ",height=" + wHeight +  cAdicional);
		if(!newWindow){
			newWindow.close();
			newWindow = null;}
	}
}
		
function VerificaNumerico(checkStr,valInteger)
{
	var allValid = true;
	if(valInteger)
		var checkOK = "0123456789"
	else
		var checkOK = "0123456789.,";
	var decPoints = 0;
	var allNum = "";
	for (k = 0; k < checkStr.length; k++)
	{
		ch = checkStr.charAt(k);
		for (j = 0; j < checkOK.length; j++)
			 if (ch == checkOK.charAt(j))
				 break;
		 if (j == checkOK.length)
		  {
			  allValid = false;
			  break;
			}
		allNum += ch;
	}
	return (allValid);
}

//funcao que habilita ou desabilita campo de pesquisa
var valorMinimoChar = 3;
function atualizaHabilitaCampoOPT(){
	campo1 = document.getElementById('Texto1');
	campo2 = document.getElementById('Texto2');
	campo3 = document.getElementById('Texto3');
	
	radio1A = document.getElementById('E_OU_1A');
	radio1B = document.getElementById('E_OU_1B');
	radio2A = document.getElementById('E_OU_2A');
	radio2B = document.getElementById('E_OU_2B');
	
	if(campo1.value.length >= valorMinimoChar){	
			
		radio1A.disabled = false;		
		radio1B.disabled = false;
		
		liberaCampoTexto(radio1A,campo2);
		liberaCampoTexto(radio1B,campo2);
	}
	if(campo2.value.length >= valorMinimoChar){
				
		radio2A.disabled = false;		
		radio2B.disabled = false;
		
		liberaCampoTexto(radio2A,campo3);
		liberaCampoTexto(radio2B,campo3);
	}
	
	if(campo1.value.length < valorMinimoChar){
		campo2.readOnly = true;
		campo2.style.backgroundColor = "#e9e9e9";
		campo2.value = '';
				
		radio1A.disabled = true;
		radio1B.disabled = true;

		radio2A.disabled = true;
		radio2B.disabled = true;		
		
		campo3.readOnly = true;
		campo3.style.backgroundColor = "#e9e9e9";
		campo3.value = '';
	}
	
	if(campo2.value.length < valorMinimoChar){
		campo3.readOnly = true;
		campo3.style.backgroundColor = "#e9e9e9";
		campo3.value = '';
		
		radio2A.disabled = true;
		radio2B.disabled = true;
	}	
}

function liberaCampoTexto(objRadio, campoLiberar){	
	if(objRadio.checked)
	{
		campoLiberar.readOnly = false;
		campoLiberar.style.backgroundColor = "#ffffff";
	}	
}

function retornaObj(idObj){
	return document.getElementById(idObj);
}