// JavaScript Document
function abrirPagina(cUrl){
	if(document.all.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 trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}

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
		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 selOpcao(objSelect, cValOpcao)
{
	if(objSelect){
	nTamObj = parseInt(objSelect.length) - 1
	for(i=0;i<=nTamObj;i++)
	{
		if(objSelect.options[i].value == cValOpcao){
			objSelect.options[i].selected = true;
			break;}
	}}
}

function pulaTexto(obj1,obj2)
{
	var maximo = eval('document.forms[0].'+obj1+'.maxLength');
	var digitado = eval('document.forms[0].'+obj1+'.value.length');
				
	if (digitado == maximo) 
	{
		var foco = eval('document.forms[0].'+obj2);
		foco.focus();
	} 
}

function soNumero() 
{
	if (!(event.keyCode>47 && event.keyCode<58))
	{
		return event.keyCode=0
	}		
}

function CPF_OK(Numero_CPF)
{
	var Parcela;
	var Quociente;
	var Resto;
	var Soma;
	var Fator;
	var I;
	var C1;
	var C2;
	var dv1;
	var dv2;
	
	//Verificação dos dois digitos finais em relação ao número completo
	C1 = parseInt(Numero_CPF.substring(9, 10)); //10º caracter = primeiro dígito verificador
	C2 = parseInt(Numero_CPF.substring(10, 11)); //11º caracter = segundo dígito verificador
	
	//Verificação do primeiro dígito (C1)
	Soma = 0;
	Parcela = 0;
	Fator = 0;
	
	for(I=1; I<=9; I++)
	{
	Fator = I + 1;
	
	Parcela = Fator * parseInt(Numero_CPF.substring(9 - I, 9 - I + 1));
	Soma = Soma + Parcela;
	} //fechando o "for".
	
	dv1 = (Soma % 11);
	dv1 = 11 - dv1;
	
	if(dv1 >9 )
			dv1 = 0;
	
	
	if(C1 != dv1)
		 return false;
	
	
	//Verificação do segundo dígito (C2)
	Soma = 0;
	Parcela = 0;
	Fator = 0;
	
	for(I=1; I<=10; I++)
	{
	Fator = I + 1;
	
	Parcela = Fator * parseInt(Numero_CPF.substring(10 - I, 10 - I + 1));
	Soma = Soma + Parcela;
	}
	
	dv2 = (Soma % 11);
	dv2 = 11 - dv2;
	
	if(dv2 > 9)
			 dv2 = 0;
	
	
	if(C2 != dv2)
			return false;
	
	
	return (true);
}

function verificaQuantidadeCaracteres(objetoVerificar, MaximoCaracteres)
{
	if(objetoVerificar.value.length > MaximoCaracteres)
	{
		alert("Máximo de caracteres perimitidos: " + MaximoCaracteres)
		objetoVerificar.value = objetoVerificar.value.substr(0, MaximoCaracteres);
	}
}
