<!--
function Limpar(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 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()
{
	cnpj = Limpar(document.form.cnpj.value);
	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_Email(email)
{
	if(email.length < 6) {
		return false;
	}
	var x = 0;
	for (var c=0;c<email.length;c++) {
		if (email.substring(c,c+1) == '@') {
			x = c;
		}
	}
	var y = 0;
	if (x > 0) {
		for (c=x;c<email.length;c++) {
			if (email.substring(c,c+1)=='.') {
				y = c;
				var valida = 1;
			}
		}
		if (y > 0) {
			var dominio = '';
			for (c=x;c<y;c++) {
				dominio = dominio + email.substring(1,c);
			}
		}
	}
	else {
		return false;
	}					
	if (y <= x+2){
		return false;
	}				
	if (valida == 1){
		return true;
	}
}

function Mascarar_CNPJ(keypress, objeto)
{
	if (objeto == "*") {
		alert("*");
		event.returnValue = false;
	}
	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_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) ;			
		}
	}		
}

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 PopUp(arquivo,width,height,top,left,scrollbars,resizable)
{
	var yes = 1;
	var no = 0;

	var menubar = no;
	var locationbar = no;
	var directories = no;
	var statusbar = no;
	var toolbar = no;

	windowprops = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;

	windowprops += (menubar ? ",menubars" : "") +
	(scrollbars ? ",scrollbars" : "") +
	(locationbar ? ",location" : "") +
	(directories ? ",directories" : "") +
	(resizable ? ",resizable" : "") +
	(statusbar ? ",status" : "") +
	(toolbar ? ",toolbar" : "");

	window.open(arquivo, 'fullPopup', windowprops);
}
-->