<!--

//***************************************************************
//*****       VERIFICA CNPJ                *****
//***************************************************************
//	scgc = número do CNPJ

function verificaCGC(scgc) {  
	var cgc = trimtodigits(scgc);  
	if ((cgc.indexOf("-") != -1) || (cgc.indexOf(".") != -1) || (cgc.indexOf("/") != -1)){  
		return( false )  
	}  
	var df, resto, dac = ""  
	df = 5*cgc.charAt(0)+4*cgc.charAt(1)+3*cgc.charAt(2)+2*cgc.charAt(3)+9*cgc.charAt(4)+8*cgc.charAt(5)+7*cgc.charAt(6)+6*cgc.charAt(7)+5*cgc.charAt(8)+4*cgc.charAt(9)+3*cgc.charAt(10)+2*cgc.charAt(11)  
	resto = df % 11  
	dac += ( (resto <= 1) ? 0 : (11-resto) )  
	df = 6*cgc.charAt(0)+5*cgc.charAt(1)+4*cgc.charAt(2)+3*cgc.charAt(3)+2*cgc.charAt(4)+9*cgc.charAt(5)+8*cgc.charAt(6)+7*cgc.charAt(7)+6*cgc.charAt(8)+5*cgc.charAt(9)+4*cgc.charAt(10)+3*cgc.charAt(11)+2*parseInt(dac)  
	resto = df % 11  
	dac += ( (resto <= 1) ? 0 : (11-resto) )  
	return (dac == cgc.substring(cgc.length-2,cgc.length))  
}  

//***************************************************************
//*****       VERIFICA CPF                *****
//***************************************************************
//	scgc = número do CPF

function verificaCPF(scpf) {  
	var cpf = trimtodigits(scpf);  
	if ((cpf.indexOf("-") != -1) || (cpf.indexOf(".") != -1) || (cpf.indexOf("/") != -1)){  
		return( false )  
	}  
	var df, resto, dac = ""  
	df = 10*cpf.charAt(0)+9*cpf.charAt(1)+8*cpf.charAt(2)+7*cpf.charAt(3)+6*cpf.charAt(4)+5*cpf.charAt(5)+4*cpf.charAt(6)+3*cpf.charAt(7)+2*cpf.charAt(8) 
	resto = df % 11  
	dac += ( (resto <= 1) ? 0 : (11-resto) )  
	df = 11*cpf.charAt(0)+10*cpf.charAt(1)+9*cpf.charAt(2)+8*cpf.charAt(3)+7*cpf.charAt(4)+6*cpf.charAt(5)+5*cpf.charAt(6)+4*cpf.charAt(7)+3*cpf.charAt(8)+2*parseInt(dac)  
	resto = df % 11  
	dac += ( (resto <= 1) ? 0 : (11-resto) )  
	return (dac == cpf.substring(cpf.length-2,cpf.length))  
}  

//Remove todos os caracteres excetos 0-9  
function trimtodigits(tstring){  
	s="";  
	ts=new String(tstring);  
	for (x=0;x<ts.length;x++){  
		ch=ts.charAt(x);  
			if (asc(ch)>=48 && asc(ch)<=57){  
			s=s+ch;  
		}  
	}  
	return s;  
}  


// Retorna o código ASC do caracter passada por parâmetro  
function asc(achar){  
	var n=0;  
	var ascstr = makeCharsetString()  
	for(i=0;i<ascstr.length;i++){  
		if(achar==ascstr.substring(i,i+1)){  
			n=i;  
			break;  
		}  
	}  
	return n+32  
}  

// Gera uma string com os caracteres básicos na sequência de códigos ASC  
function makeCharsetString(){  
	var astr  
	astr = ' !"#$%&\'()*+,-./0123456789:;<=>?@'  
	astr+= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'  
	astr+= '[\]^_`abcdefghijklmnopqrstuvwxyz'  
	astr+= '{|}~'  
	return astr  
}  




//***************************************************************
//*****       MODIFICASTRING                *****
//***************************************************************
//	texto = texto a ser alterado
//  pos = posicao do tolken a ser alterado
//  novoTexto = texto a ser inserido no tolken pos
//  separador = caracter separador

function modificastring(texto,pos,novoTexto,separador)
{
    var ini,fim,i;
	i = 0;
	for(j=0;j<pos-1;j++){
		while (texto.charAt(i) != separador){
			i++;
		}
		i++;
	}
	ini = i;
	while ((i<=texto.length-1)&&(texto.charAt(i) != separador)){
		i++;
	}

	fim = i;

	texto = texto.substr(0,ini)+novoTexto+texto.substr(fim,texto.length-1);

	return texto;
}

//-------------------------------------------------------------------------------------------------------//
//Função que testa se a tecla digitada no teclado é de função, como SHIFT, CAPS LOCK, etc...
//pois neste caso devemos permitir que o browser a interprete. Esta função é utilizada dentro da
//função FormataInt, que não permite que caracteres de texto sejam enviados para o form.

function EstaNavegando(key){
	switch(key){
		case 8://backspace
			return true;
			break;
		case 9://tab
			return true;
			break;
		case 13://enter
			return true;
			break;
		case 37://seta esquerda
			return true;
			break;
		case 39://seta direita
			return true;
			break;
		case 16://shift
			return true;
			break;
		case 20://capslock
			return true;
			break;
		case 46://delete
			return true;
			break
		case 45://insert
			return true;
			break
		case 36://home
			return true;
			break
		case 35://end
			return true;
			break
		case 33://pg up
			return true;
			break
		case 34://pd down
			return true;
			break
		case 38://seta cima
			return true;
			break
		case 40://seta baixo
			return true;
			break
		case 144://num lock
			return true;
			break
		case 12: //5 com num lock desligado
			return true;
			break;
		default:
			return false;
		break
	}
}

//-------------------------------------------------------------------------------------------------------//
//Autor: Raphael Salgado Ferreira
//-------------------------------------------------------------------------------------------------------//
function FormataData(cCampo,teclapres){
	var tecla = teclapres.keyCode;
	dt = cCampo.value;
	if (dt.length != 10){
		dt = dt.replace( "/", "" );
		dt = dt.replace( "/", "" );
		tam = dt.length;

		if (tam < 10 && tecla != 8){ tam = dt.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam > 2 && tam < 5 )
				cCampo.value = dt.substr( 0, tam - 2  ) + '/' + dt.substr( tam - 2, tam );
			if ( tam >= 5 && tam <= 10)
				cCampo.value = dt.substr( 0, 2 ) + '/' + dt.substr( 2, 2 ) + '/' + dt.substr( 4, 4 );
		}
	}
}

//-------------------------------------------------------------------------------------------------------//
//function dateDifference(strDate1,strDate2)
//Autor: Hilton Finotti Neto
//função que recebe o valor de uma data inicial e uma data final e verifica se inicio é menor que o final
//strDate1 --> é a data/hora inicial
//strDate2 --> é a data/hora final
function dateDifference(strDate1,strDate2,msg){
	datDate1= Date.parse(strDate1);
	datDate2= Date.parse(strDate2);
	if((datDate2-datDate1)/(24*60*60*1000) < 0){
		alert(msg)
		return false;
	}

}

//-------------------------------------------------------------------------------------------------------//
//function Vld_Data(cCampo, cNome, bBranco)
//Autor: Raphael Salgado Ferreira
//função que recebe o valor de um campo de data e valida os valores infomados. Caso o dia, mes ou ano
//sejam valores inválidos, a função retorna uma mensagem de erro.
//bBranco --> se "true", o campo pode ser "NULL", caso contrário é obrigatório

function Vld_Data(cForm, cCampo, cNome, bBranco)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
	var dateStr = document.forms[cForm].elements[cCampo].value;
//	alert(dateStr);
	if(bBranco)
	{
		if(dateStr == '') return true;
	}
	if(dateStr == '')
	{
		alert('Obrigatório entrar com dados em: ' + cNome);
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) 
	{
		alert('Campo: ' + cNome + ' não contém uma data válida!');
		//cCampo.value = '';
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	day = matchArray[1]; // parse date into variables
	month = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12)
	{ // check month range
		alert('O mês do campo ' + cNome + ' deve estar entre 01 e 12!');
		//cCampo.value = '';
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert('O dia do campo ' + cNome + ' deve estar entre 01 e 31!');
		//cCampo.value == '';
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert('O mês do campo ' + cNome + ' não possui 31 dias!');
		//cCampo.value = '';
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	if (month == 2) 
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap))
		{
			alert('Fevereiro de ' + year + ' não possui ' + day + ' dias!');
			//cCampo.value = '';
			document.forms[cForm].elements[cCampo].focus();
			return false;
		}
	}
	if (year < 1900)
	{
		alert('O ano do campo ' + cNome + ' deve ser maior que 1900.')
		document.forms[cForm].elements[cCampo].focus();
		return false;
	}
	return true;
}

//-------------------------------------------------------------------------------------------------------//
//function ativatxtchk(nomeform,nomecampo,chknome,chkvalue)
//função que, de acordo com o valor passado em chkvalue, ativa ou desativa o campo nomecampo
//esta função deve ser utilizada quando temos checkboxes e desejamos que se um em especial estiver
//checkado um campo de texto seja ativado ou desativado
//onClick="javascript:ativatxtchk('FRM_Curriculum','TXT_CUR_AreasInteresse','CHK_CUR_AreasInteresse','OutraArea');"

function ativatxtchk(nomeform,nomecampo,chknome,chkvalue)
{
var tamvet;
tamvet = document.forms[nomeform].elements[chknome].length;
if (tamvet != false)
	{
	for (var i = 0; i < tamvet; i++)
	 {
	if (document.forms[nomeform].elements[chknome][i].value == chkvalue)
		{
		if (document.forms[nomeform].elements[chknome][i].status)
			{
				document.forms[nomeform].elements[nomecampo].disabled = false;
			}
			else 
				{
					document.forms[nomeform].elements[nomecampo].disabled = true;
				}
		}
		else
			{
				document.forms[nomeform].elements[nomecampo].disabled = true;
			}
	 }
	}
	else
	{
		if (document.forms[nomeform].elements[chknome].value == chkvalue)
		{
		if (document.forms[nomeform].elements[chknome].status)
			{
				document.forms[nomeform].elements[nomecampo].disabled = false;
			}
			else 
				{
					document.forms[nomeform].elements[nomecampo].disabled = true;
				}
		}
		else
			{
				document.forms[nomeform].elements[nomecampo].disabled = true;
			}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function verifica_checked(nomeform,chknome)
//função que, de acordo com o nome do controle(checkbox) passado em chknome
// verifica se algum checkbox esta checado(true)

function verifica_checked(nomeform,chknome) {

	var tamvet;
	
	tamvet = document.forms[nomeform].elements[chknome].length;
	
	if (tamvet) {
		
		for (var i = 0; i < tamvet; i++) {
			if (document.forms[nomeform].elements[chknome][i].checked) {
				return true;
			}
		}
		return false;
	}
	else {
		return (document.forms[nomeform].elements[chknome].checked);
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataHora(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataHora('nomeForm', 'nomeCampo',12,event);"
function FormataHora(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vh = document.forms[nomeForm].elements[nomeCampo].value;
	if (vh.length != tammax)	{
		vh = vh.replace( ":", "" );
		tam = vh.length;

		if (tam < tammax && tecla != 8){ tam = vh.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				document.forms[nomeForm].elements[nomeCampo].value = ':' + vh.substr( tam - 2, tam ) ; }
			if ( (tam > 2) && (tam <= 5) ){
				document.forms[nomeForm].elements[nomeCampo].value = vh.substr( 0, tam - 2 ) + ':' + vh.substr( tam - 2, tam ) ; }
		}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function  FormataValorMultip(nomeForm, nomeCampo,tammax,teclapres,indice)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// indice --> indice do array do campo
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event,document.nomeForm.nomeCampo.index);"
function FormataValorMultip(nomeForm, nomeCampo,tammax,teclapres,indice) {
	var tecla = teclapres.keyCode;
	vrm = document.forms[nomeForm].elements[nomeCampo][indice].value;
	if (vrm.length != tammax){
		vrm = vrm.replace( ",", "" );
		vrm = vrm.replace( ".", "" );
		tam = vrm.length;

		if (tam < tammax && tecla != 8){ tam = vrm.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				document.forms[nomeForm].elements[nomeCampo][indice].value = '.' + vrm.substr( tam - 2, tam ) ; }
			if ( (tam > 2) && (tam <= 5) ){
				document.forms[nomeForm].elements[nomeCampo][indice].value = vrm.substr( 0, tam - 2 ) + '.' + vrm.substr( tam - 2, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
				document.forms[nomeForm].elements[nomeCampo][indice].value = vrm.substr( 0, tam - 5 ) + '' + vrm.substr( tam - 5, 3 ) + '.' + vrm.substr( tam - 2, tam ) ; }
			if ( (tam >= 9) && (tam <= 11) ){
				document.forms[nomeForm].elements[nomeCampo][indice].value = vrm.substr( 0, tam - 8 ) + '' + vrm.substr( tam - 8, 3 ) + '' + vrm.substr( tam - 5, 3 ) + '.' + vrm.substr( tam - 2, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
				document.forms[nomeForm].elements[nomeCampo][indice].value = vrm.substr( 0, tam - 11 ) + '' + vrm.substr( tam - 11, 3 ) + '' + vrm.substr( tam - 8, 3 ) + '' + vrm.substr( tam - 5, 3 ) + '.' + vrm.substr( tam - 2, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
				document.forms[nomeForm].elements[nomeCampo][indice].value = vrm.substr( 0, tam - 14 ) + '' + vrm.substr( tam - 14, 3 ) + '' + vrm.substr( tam - 11, 3 ) + '' + vrm.substr( tam - 8, 3 ) + '' + vrm.substr( tam - 5, 3 ) + '.' + vrm.substr( tam - 2, tam ) ;}
		}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataValor1(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataValor1(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr1 = document.forms[nomeForm].elements[nomeCampo].value;
	if (vr1.length != tammax){
		vr1 = vr1.replace( ",", "" );
		vr1 = vr1.replace( ".", "" );
		tam = vr1.length;

		if (tam < tammax && tecla != 8){ tam = vr1.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				document.forms[nomeForm].elements[nomeCampo].value = '.' + vr1.substr( tam - 2, tam ) ; }
			if ( (tam > 2) && (tam <= 5) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr1.substr( 0, tam - 2 ) + '.' + vr1.substr( tam - 2, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr1.substr( 0, tam - 5 ) + '' + vr1.substr( tam - 5, 3 ) + '.' + vr1.substr( tam - 2, tam ) ; }
			if ( (tam >= 9) && (tam <= 11) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr1.substr( 0, tam - 8 ) + '' + vr1.substr( tam - 8, 3 ) + '' + vr1.substr( tam - 5, 3 ) + '.' + vr1.substr( tam - 2, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr1.substr( 0, tam - 11 ) + '' + vr1.substr( tam - 11, 3 ) + '' + vr1.substr( tam - 8, 3 ) + '' + vr1.substr( tam - 5, 3 ) + '.' + vr1.substr( tam - 2, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr1.substr( 0, tam - 14 ) + '' + vr1.substr( tam - 14, 3 ) + '' + vr1.substr( tam - 11, 3 ) + '' + vr1.substr( tam - 8, 3 ) + '' + vr1.substr( tam - 5, 3 ) + '.' + vr1.substr( tam - 2, tam ) ;}
		}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataValor(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataValor(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[nomeForm].elements[nomeCampo].value;
	if (vr.length != tammax){
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		tam = vr.length;

		if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 2 ){ 
				document.forms[nomeForm].elements[nomeCampo].value = ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam > 2) && (tam <= 5) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 6) && (tam <= 8) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 9) && (tam <= 11) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 12) && (tam <= 14) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
			if ( (tam >= 15) && (tam <= 17) ){
				document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
		}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataValor3c(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataValor3c(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[nomeForm].elements[nomeCampo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 3 ){ 
	 		document.forms[nomeForm].elements[nomeCampo].value = vr ; }
	 	if ( (tam > 3) && (tam <= 6) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 15) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + ',' + vr.substr( tam - 3, tam ) ; }
	 	if ( (tam >= 16) && (tam <= 18) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 15 ) + '.' + vr.substr( tam - 15, 3 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + ',' + vr.substr( tam - 3, tam ) ;}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataValor1c(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataValor1c(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.forms[nomeForm].elements[nomeCampo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 1 ){ 
	 		document.forms[nomeForm].elements[nomeCampo].value = vr ; }
	 	if ( (tam > 1) && (tam <= 4) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 1 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 5) && (tam <= 7) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 4 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 8) && (tam <= 10) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 11) && (tam <= 13) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 10 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ; }
	 	if ( (tam >= 14) && (tam <= 16) ){
	 		document.forms[nomeForm].elements[nomeCampo].value = vr.substr( 0, tam - 13 ) + '.' + vr.substr( tam - 13, 3 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + ',' + vr.substr( tam - 1, tam ) ;}
	}
}


//-------------------------------------------------------------------------------------------------------//
//function FormataQtd(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico não decimal a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataValor3C(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	cp = document.forms[nomeForm].elements[nomeCampo].value;
	if (cp.length != tammax){
		cp = cp.replace( ",", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		tam = cp.length;

		if (tam < tammax && tecla != 8){ tam = cp.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 3 ){ 
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( tam - 3, tam ) ; }
			if ( (tam > 3) && (tam <= 6) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 3 ) + ',' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 7) && (tam <= 9) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 6 ) + '.' + cp.substr( tam - 6, 3 ) + ',' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 10) && (tam <= 12) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 9 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + ',' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 13) && (tam <= 15) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 12 ) + '.' + cp.substr( tam - 12, 3 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + ',' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 16) && (tam <= 18) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 15 ) + '.' + cp.substr( tam - 15, 3 ) + '.' + cp.substr( tam - 12, 3 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + ',' + cp.substr( tam - 3, tam ) ;}
		}
	}
}

//-------------------------------------------------------------------------------------------------------//
//function FormataQtd(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico não decimal a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataValor('nomeForm', 'nomeCampo',12,event);"
function FormataQtd(nomeForm, nomeCampo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	cp = document.forms[nomeForm].elements[nomeCampo].value;
	if (cp.length != tammax){
		cp = cp.replace( ",", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		cp = cp.replace( ".", "" );
		tam = cp.length;

		if (tam < tammax && tecla != 8){ tam = cp.length + 1 ; }

		if (tecla == 8 ){	tam = tam - 1 ; }
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if ( tam <= 3 ){ 
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( tam - 3, tam ) ; }
			if ( (tam > 3) && (tam <= 6) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 3 ) + '.' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 7) && (tam <= 9) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 6 ) + '.' + cp.substr( tam - 6, 3 ) + '.' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 10) && (tam <= 12) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 9 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + '.' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 13) && (tam <= 15) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 12 ) + '.' + cp.substr( tam - 12, 3 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + '.' + cp.substr( tam - 3, tam ) ; }
			if ( (tam >= 16) && (tam <= 18) ){
				document.forms[nomeForm].elements[nomeCampo].value = cp.substr( 0, tam - 15 ) + '.' + cp.substr( tam - 15, 3 ) + '.' + cp.substr( tam - 12, 3 ) + '.' + cp.substr( tam - 9, 3 ) + '.' + cp.substr( tam - 6, 3 ) + '.' + cp.substr( tam - 3, tam ) ;}
		}
	}
}

//-------------------------------------------------------------------------------------------------------//
//function FormataPercentual(nomeForm, nomeCampo,tammax,teclapres)
//função que formata um valor numérico a medida que o usuário vai digitando
// nomeForm --> nome do formulário onde o campo se encontra
// nomeCampo --> nome do campo (case sensitive)
// tammax --> tamanho máximo do campo
// teclapres --> evento do teclado (passar apenas "event")
// chamada da função: onKeyress="JavaScript:FormataPercentual('nomeForm', 'nomeCampo',12,event);"
function FormataPercentual(nomeForm, nomeCampo,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	pc = document.forms[nomeForm].elements[nomeCampo].value;
	if (pc.length != tammax){
		pc = pc.replace( ",", "" );
		pc = pc.replace( ".", "" );
		tam = pc.length;

		if (tam < tammax && tecla != 8){
			tam = vr.length + 1 ; 
		}

		if (tecla == 8 ){
			tam = tam - 1;
		}
			
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
			if (tam <= 3){ 
				document.forms[nomeForm].elements[nomeCampo].value = pc ;
			}
			if ((tam > 3) && (tam <= 6)){
				document.forms[nomeForm].elements[nomeCampo].value = pc.substr( 0, tam - 3 ) + ',' + pc.substr( tam - 3, tam); 
			}
		}	
	}
}

/*************************************************/
/*****           TROCA CARACTERES            *****/
/*************************************************/
//	texto 	-> Texto a ser editado.
//	carac1 	-> Caracter a ser substituído.
//	carac2 	-> Caracter ao qual será substituído.

function TrocaCaracter(texto, carac1, carac2)
{
	var i = 0;

	while(i < texto.length)
	{
		if(texto.charCodeAt(i) == carac1.charCodeAt(0))
		{
			texto = texto.substr(0,i) + carac2 + texto.substr(i+1);
		}
		i++;
	}
	return texto;
}

/***************************************************************/
/*****       VALIDA CAMPOS COM DIGITOS DECIMAIS            *****/
/***************************************************************/
//	campo 	-> Objeto desejado para validar casas decimais.
//  decimal -> Numero de casas decimais que o campo deve conter.


function ValidarDecimal(campo,decimal){
		
	var str = campo.value;
	var tamanho = campo.value.length;
	var tamanhoMax = campo.maxLength;
	var tamDec = 0;
	var i = 0;
	var j = 0;
	
			
	
	for(i=0;i<=tamanho;i++) {
		if ((str.substr(i,1) == ",") || (str.substr(i,1) == ".")){
				tamDec =(tamanho - i - 1);
				str = str.substr(0,i) + "Å" + str.substr(i+1);
				str = TrocaCaracter(str, ".", "");
				str = TrocaCaracter(str, ",", "");
				str = TrocaCaracter(str, "Å", ".");
											
				if(tamanho - tamDec > tamanhoMax - decimal) {
					alert('Numero pode ter no máximo '+ (tamanhoMax - decimal - 1) + ' dígitos inteiros'); 
					campo.focus();
					return false;
				}
				
				if(tamDec <= decimal) {
					for(j=tamDec;((j<decimal)&&(str.length<tamanhoMax));j++)
						str = str + 0;
				}
				else
				{
				alert('Campo pode ter no máximo '+ decimal + ' dígitos decimais');
				campo.focus();
				return false;
				}
				
				campo.value = str;
				return true;
		}
	}
	
	if(tamanho > (tamanhoMax - decimal - 1)) {
		alert('Numero pode ter no máximo '+ (tamanhoMax - decimal - 1) + ' dígitos inteiros'); 
		campo.focus();
		return false;
	}				
	return true;
							
}

/****************************************************************/
/***************** Aceita numeros e pontos **********************/
/****************************************************************/
// se o caracter digitado não for um numero ou um ponto será
// ignorado.

function NumeroPonto(){
	tecla = window.event.keyCode;
	
	if (tecla != 46 &&(tecla < 48 || tecla > 57))
		window.event.keyCode = 0;
}

/****************************************************************/
/***************** Aceita numeros e virgula *********************/
/****************************************************************/
// se o caracter digitado não for um numero ou uma vírgula será
// ignorado.
function NumeroVirgula(){
	tecla = window.event.keyCode;
	
	if (tecla != 44 &&(tecla < 48 || tecla > 57))
		window.event.keyCode = 0;
}

/****************************************************************/
/***************** Aceita apenas numeros ************************/
/****************************************************************/
// se o caracter digitado não for um numero será ignorado.

function soNumeros(){
	tecla = window.event.keyCode;

	if (tecla < 48 || tecla > 57)
		window.event.keyCode = 0;
}

/***************************************************/
/*****  VALIDA O CAMPO NUMÉRICO SEM MENSAGEM   *****/
/***************************************************/
//	campo 	-> Objeto desejado.
//Verifica se é numerico admitindo no máximo 1 virgula. Nao envia mensagens ao usuário.

function VerificarNumSMsg(campo)
{
	var conteudo = campo.value;
	var i = 0;
	var flag = 0;	

	while(i < conteudo.length)
	{
		if(conteudo.charCodeAt(i) == 44)
		{
			if(flag == 1) 
			{
				return false;
			}
			flag = 1;
		}
		if(((conteudo.charCodeAt(i) < 48) || (conteudo.charCodeAt(i) > 57)) && (conteudo.charCodeAt(i) != 44) && (conteudo.charCodeAt(i) != 46))
		{
			return false;
		}
		i++
	}
	return true;
}

/****************************************************************/
/***************** Não Aceita aspas (simples ou duplas) *********/
/****************************************************************/
// se o caracter digitado for aspas (simples ou duplas) sera ignorado.

function semAspas(){
	tecla = window.event.keyCode;
	if (tecla == 34 || tecla == 39){
		window.event.keyCode = 0;}
}


/****************************************************************/
/***** RETIRA OS ESPAÇOS EM BRANCO DA DIREITA E DA ESQUERDA *****/
/****************************************************************/
//	strValue-> Texto para serem retirados os espaços a esquerda e a direita.
//Verifica se é numerico admitindo no máximo 1 virgula. Nao envia mensagens ao usuário.

function trim (strValue)
	{
	while (strValue.substr (0,1) == " ")
		{
		strValue = strValue.substr (1);
		}
	while (strValue.substr (strValue.length - 1, 1) == " ")
		{
		strValue = strValue.substr (0, strValue.length - 1);
		}
		
	return (strValue);
}


//-------------------------------------------------------------------------------------------------------//
//maxchar(nomeform,nomecampo,maxcaracteres)
//função que verifica se um determinado campo possui mais elementos que "maxcaracteres. Em caso afirmativo,
//cancela o envio de dados e exibe uma mensagem para o usuário.
//maxcaracteres --> máximo de caracteres permitidos no campo
//msg ------------> nome do campo que será exibido na mensagem para o usuário
//nometxt---------> opcional: caso deseje criar um campo que vai exibindo ao usuário quantos caracteres ele já exibiu
//                  crie um txtbox e passe o nome neste parâmetro para melhor resultado ver função pegamaximo
//-------------------------------------------------------------------------------------------------------//
function maxchar(nomeform,nomecampo,maxcaracteres,nometxt,msg)
{
	var tecla = event.keyCode;
	if (nometxt != '')
	 {
		 document.forms[nomeform].elements[nometxt].value = (maxcaracteres-1) - document.forms[nomeform].elements[nomecampo].value.length;
//		 document.forms[nomeform].elements[nometxt].value = document.forms[nomeform].elements[nomecampo].value.length;
	 }
	if(document.forms[nomeform].elements[nomecampo].value.length >= maxcaracteres)
		{
		 if(EstaNavegando(tecla)) return;
	  	{
	 		alert('O campo ' + msg + ' possui atualmente ' + document.forms[nomeform].elements[nomecampo].value.length + ' caracteres. Este é o valor máximo permitido!');
			pegamaximo(nomeform,nomecampo,maxcaracteres,nometxt,msg)
	 		event.returnValue = false;
	 		}
		}
} 

//-------------------------------------------------------------------------------------------------------//
//pegamaximo(nomeform,nomecampo,maxcaracteres, nometxt, msg)
//função que verifica se um determinado campo possui mais elementos que "maxcaracteres. Em caso afirmativo,
//deleta os caracteres que ultrapassam o máximo e retorna o foco para o campo.
//maxcaracteres --> máximo de caracteres permitidos no campo
//msg --> nome do campo que será exibido na mensagem para o usuário
//para melhor resultado fer função maxchar
function pegamaximo(nomeform,nomecampo,maxcaracteres,nometxt,msg)		
{
	if (document.forms[nomeform].elements[nomecampo].value.length > maxcaracteres){
		document.forms[nomeform].elements[nomecampo].value = (document.forms[nomeform].elements[nomecampo].value.slice(0,maxcaracteres));
		document.forms[nomeform].elements[nomecampo].focus();
		alert('O número máximo de caracteres do campo ' + msg + ' foi ultrapassado!\nAs palavras excedentes serão descartadas.');
	}
}

//---------------------------------------------------//
// Formatação para qualquer mascara
//---------------------------------------------------//
function formatar(src, mask) {
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)

	if (texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

/***************************************************************/
/*****************       MONTACALEND       *********************/
/***************************************************************/
// layer - nome da layer do calendario
// input - nome da caixa de texto (input)
// valorinicial - valor inicial selecionado
// posX - posicao X do calendario
// posY - posicao Y do calendario
// formulario - nome do formulario onde este componente se encontra inserido
function montacalend(layer,input,valorInicial,formulario) {
	document.write("<div id=\""+layer+"\" style=\"z-index: 1; position: absolute\" width=\"20%\" onClick=\""+"javascript:dropdownOff('',document."+formulario+"."+layer+",'"+layer+"');\"></div>");
	document.write("<input class=\"cxform\" style=\" left: 3px; width: 75px; top: 1px; height: 17px;\" maxlength=\"10\" size=\"15\" name=\""+input+"\" value=\""+valorInicial+"\" readonly>&nbsp;");
	document.write("<a href=\""+"javascript:dropdownOn(0,document."+formulario+",document."+formulario+"."+input+","+0+","+0+",'"+layer+"');"+"\" ><img style=\"width: 18px; TOP: 2px; height: 17px; align: right\" height=17 hspace=0 src=\"images/calendar.gif\" width=18 align=top border=0></a>");
	document.write(" <a href=\""+"javascript:limpaData(document."+formulario+"."+input+"); "+"\"><img style=\"width: 18px; TOP: 2px; height: 17px; align: right\" height=17 hspace=0 src=\"images/limpa_data.gif\" width=18 align=top border=0></a>");
	//document.write("<A class=txVd9Az onclick=\""+"javascript:dropdownOn(0,document."+formulario+",document."+formulario+"."+input+","+0+","+0+",'"+layer+"');"+"\" href=\"#\"><img style=\"width: 18px; TOP: 2px; height: 17px; align: right\" height=17 hspace=0 src=\"images/calendar.gif\" width=18 align=top border=0></a>");
}

//***************************************************************/
//                      VALIDA HORA		                         /
//***************************************************************/
// obj - valor do campo a ser testado                            /
function verificaHora(obj) {
	campo = obj.value;
	Hora = campo
	var hm = -1;
	var hora = Array(2);
	var ch = Hora.charAt(0); 
	for(i=0; i < Hora.length && (( ch >= '0' && ch <= '9' ) || ( ch == ':' && i != 0 ) ); ){
		hora[++hm] = '';
		if(ch!=':' && i != 0){
			alert('A Hora deve ser válida !')
			obj.focus();
			return false;
		}
    
		if(i != 0 ) ch = Hora.charAt(++i);
		if(ch=='0') ch = Hora.charAt(++i);

		while( ch >= '0' && ch <= '9' ){
			hora[hm] += ch;
			ch = Hora.charAt(++i);
		} 
	}
   
	if(ch!=''){
		alert('Digite uma Hora Válida')
		obj.focus();
	   return false; 
	}
   
	if(hora[0] == '' || isNaN(hora[0]) || parseInt(hora[0]) < 0 || parseInt(hora[0]) > 23) {
		alert('A Hora deve ser válida !')
		obj.focus();
		return false;
	}
   
	if(hora[1] == '' || isNaN(hora[1]) || parseInt(hora[1]) < 0 || parseInt(hora[1]) > 59) {
		alert('O minuto deve ser válido !')
		obj.focus();
		return false;
	}
	return true;
 }
-->
