<!--
function Limpa(S)
{
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	for (var i=0; i<S.length; i++){
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0) {
			temp = temp + digito;
		}
	}
	return temp;
}

function Inverte(S)
{
	var temp = "";
	for (var i=0; i<S.length; i++) {
		temp = S.charAt(i) + temp;
	}
    return temp;
}

function Resto(S)
{
	var invertido = Inverte(Limpa(S));
	var soma = 0;
	for (var i=0; i<invertido.length; i++) {
		soma = soma + (i+2) * eval(invertido.charAt(i));
	}
	soma *= 10;
	return ((soma % 11) % 10);
}

function Testar_Cnpj(cnpj,g)
{
	var vercnpj = 0;
	var ind = 2;
	var tam;
	for(f=g;f>0;f--) {
		vercnpj += parseInt(cnpj.charAt(f-1))*ind;
		if(ind>8) {
			ind = 2;
		}
		else {
			ind++;
		}
	}
	vercnpj %= 11;
	if(vercnpj == 0 || vercnpj == 1) {
		vercnpj = 0;
	}
	else {
		vercnpj = 11 - vercnpj;
	}
	if(vercnpj != parseInt(cnpj.charAt(g))) {
		return(0);
	}
	else {
		return(1);
	}
}

function Validar_CNPJ(nr_cnpj)
{
	cnpj = Limpa(nr_cnpj);
	if(cnpj == 0) {
		return (false);
	}
	else {
		g = cnpj.length-2;
		if(Testar_Cnpj(cnpj,g) == 1) {
			g = cnpj.length-1;
			if(Testar_Cnpj(cnpj,g) == 1) {	
				return (true);
			}
			else {
				return (false);
			}
		}
		else {
			return (false);
		}
	}
}

function Validar_Numero(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
}

function Mascarar_CEP(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '-';
		}
	}
}


function Mascarar_CNPJ(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 6 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '.';
		}
		if (campo.value.length == 10 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '/';
		}
		if (campo.value.length == 15 ) { 
			campo.value = campo.value;
			campo.value = campo.value + '-';
		}
	}
}

function Mascarar_Data(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
		if (campo.value.length == 5 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
	}
}

function Mascarar_Data_(keypress, objeto)
{
	campo = eval (objeto);
	caracteres = '1234567890';
	if ((caracteres.search(String.fromCharCode (keypress)) == -1) || (keypress == 36) || (keypress == 41) || (keypress == 46) || (keypress == 94) || (keypress == 124)) {
		event.returnValue = false;
	}
	else {
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
		if (campo.value.length == 2 ) { 
	 		campo.value = campo.value;
	 		campo.value = campo.value + '/';
		}
	}
}

function Mascarar_Telefone(objeto,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = objeto.value;
	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 <= 4 ) { 
	 		objeto.value = vr ;
		}
	 	if ( (tam > 4) && (tam <= 8) ) {
	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
		}
	 	if ( (tam >= 9) && (tam <= 10) ) {
			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			
		}
	}		
}
-->