// JavaScript Document
function abrirPagina(cUrl){
	objLogado = document.getElementById('Logado');
	if(objLogado.value == 'false'){
		alert('Você precisa logar antes de acessar os serviços.'); document.forms[0].txtUsuario.focus(); return false;}
	document.location.href = cUrl;}

function blockInvalidChars(objTexto)
{
	cBlockedChars = "\"&?';=!*:><\\";
	for(i=0;i<objTexto.value.length;i++){
		for(j=0;j<=cBlockedChars.length;j++){
			if(objTexto.value.substr(i,1)==cBlockedChars.substr(j,1)){
				alert("Os caracteres " + cBlockedChars + " não podem ser digitados neste campo!");
				objTexto.focus();
				return false;}}}
}

function abreJanela(url)
{
	objLogado = document.getElementById('Logado');
	if(objLogado.value == 'false'){
		alert('Você precisa logar antes de acessar os serviços.'); document.forms[0].txtUsuario.focus(); return false;}
	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
		if(newWindow){
			newWindow.close();
			newWindow = null;}
		newWindow = window.open(url,"","left=" + wLeft + ",top=" + wTop + ",width=" + wWidth + ",height=" + wHeight +  cAdicional)}}
		
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);
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function gerarCombo(objCombo, cPrimeiraOpcao, cValores, bMostrarCodigo)
{
	var newObj;
	var arrayVal;
	
	objCombo.innerHTML = '';

	if(newObj)
	{
		newObj = null;
	}
	
	arrayVal = cValores.split('//');
	
	if(cPrimeiraOpcao != '')
	{
		newObj = document.createElement('OPTION');
		newObj.value = '';
		newObj.innerText = cPrimeiraOpcao;
		objCombo.appendChild(newObj);
	}

	for(i=0; i<arrayVal.length; i++)
	{
		cVal = arrayVal[i].substr(0, arrayVal[i].indexOf(';'));
		cDesc = arrayVal[i].substr(arrayVal[i].indexOf(';') + 1);
		
		if(cVal != '')
		{
			if(newObj)
			{
				newObj = null;
			}
			newObj = document.createElement('OPTION');
			newObj.value = cVal;
			if(bMostrarCodigo)
				newObj.innerText = cVal + ' - ' + cDesc
			else
				newObj.innerText = cDesc;
			objCombo.appendChild(newObj);
		}
	}
}