<!--
function valida() {	
	//validacao form cadastro maha djin
	//Leonardo 14/09/2002

	//valida nome
	if (document.form.nomec.value=="") {
		document.form.nomec.focus();
		alert("Campo Nome está vazio.");
		return false;
	}

	//valida endereço de email
	if (document.form.email.value=="") {
		document.form.email.focus();
		alert("Campo E-mail está vazio.");
		return false;
	}else{
		if(ValidaEmail(document.form.email.value)==false){
			alert('E-Mail inválido!!!');
			document.form.email.select();
			document.form.email.focus();
			return false;
		}								
//		checkemail();
//		return;
	}


	// validate month
	var month = parseInt(document.form.mesnasc.value,10);
	/* if (month.length!=2 || isNaN(month) || month<1 || month>12) {
			document.form.mesnasc.focus();
			alert("Campo mês inválido(Ex: 01)");
			return false;
	}
*/
	// validate year
	var year = parseInt(document.form.anonasc.value,10);
	if (isNaN(year) || year<1900 || year>2100) {
			document.form.anonasc.focus();
			alert("Campo ano inválido (1900-2100)");
			return false;
	}

	// validate day
	//
	// !!! USE AFTER YEAR VALIDATION
	//
	var daytable = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	var day = parseInt(document.form.dianasc.value,10);
	// leap year
	if ((year%4==0 && year%100!=0) || year%400==0)
			daytable[1] = 29;
	if (isNaN(day) || day<1 || day>daytable[month-1]) {
			document.form.dianasc.focus();
			alert("Campo dia inválido (1-"+daytable[month-1]+")");
			return false;
	}

	// validate hour
	var hour = parseInt(document.form.horanasc.value,10);
	if (isNaN(hour) || hour<0 || hour>23) {
			document.form.horanasc.focus();
			alert("Campo hora inválido (0-23)");
			return false;
	}

	// validate minute
	var minute = parseInt(document.form.minnasc.value,10);
	if (isNaN(minute) || minute<0 || minute>59) {
			document.form.minnasc.focus();
			alert("Campo minuto inválido (0-59)");
			return false;
	}

	// validate second
	/*
	var second = parseInt(document.form.segundo_nasc.value,10);
	if (isNaN(second) || second<0 || second>59) {
			document.form.segundo_nasc.focus();
			alert("Campo segundo inválido (0-59)");
			return;
	}
	*/

	//valida cidade de nascimento
	if (document.form.cidadenasc.value=="") {
		document.form.cidadenasc.focus();
		alert("Campo Cidade está vazio.");
		return false;
	}

	//document.form.submit();
}
//fim validação


function h_nasc() {
	if (document.form.hora_incerta.checked) {
		document.form.h_horanasc.value = document.form.horanasc.value;
		document.form.h_minnasc.value = document.form.minnasc.value;
		document.form.horanasc.value='12';
		document.form.minnasc.value='00';
	}else{
		document.form.horanasc.value=document.form.h_horanasc.value;
		document.form.minnasc.value=document.form.h_minnasc.value;
	}
}




function checkcity(pais,cidade) {
	var xlen;
	eval ("xlen = document.form."+cidade+".value.length")
	if (xlen<3) {
		alert("Cidade deve possuir pelo menos 3 letras");
		return;
	}
	var xcidade,xpais;
	eval ("xcidade = document.form."+cidade+".value")
	eval ("xpais = document.form."+pais+".value")

//	var winTop = (screen.height / 2) - 150;
	var winTop = 100;

//	var winLeft = (screen.width / 2) - 225;
	var winLeft = 100;

	var winF = "width=350,height=300,scrollbars=no,directories=no,status=no,location=no,toolbar=no,";

	winF = winF + "top=" + winTop + ",left=" + winLeft;

	//alert("checkcity.asp?pais="+xpais+"&cidade="+xcidade+"&campo="+cidade,"cidade",winF);
	window.open("checkcity.asp?pais="+xpais+"&cidade="+xcidade+"&campo="+cidade,"cidade",winF);
}



function checkemail() {
	var winTop = (screen.height / 2) - 100;
	var winLeft = (screen.width / 2) - 225;
	var winF = "width=350,height=200,scrollbars=no,directories=no,status=no,location=no,toolbar=no,";
	winF = winF + "top=" + winTop + ",left=" + winLeft;

	window.open("checkemail.asp?email="+document.form.email.value,"email",winF);
}



function mesmacidade() {
	if (document.form.selfcity.checked) {
		document.form.cidaderes.value = document.form.cidadenasc.value;
		document.form.cidaderesinfo.value = document.form.cidadenascinfo.value;
		document.form.paisres.value = document.form.paisnasc.value;
		document.form.procurar2.disabled = true;
		document.form.paisres.disabled = true;
		document.form.cidaderes.disabled = true;
	} else {
		document.form.cidaderes.value = "";
		document.form.cidaderesinfo.value = "";
		document.form.procurar2.disabled = false;
		document.form.paisres.disabled = false;
		document.form.cidaderes.disabled = false;

	}
}



function semcpf() {
	if (document.form.naotenho.checked) {
		document.form.old_cpf.value = document.form.cpf.value;
		document.form.cpf.value = "000.000.000-00";
        } else {
		document.form.cpf.value = document.form.old_cpf.value;
	}
}



function MascaraCEP(formato, keypress, objeto) {
campo = eval (objeto);
if (formato=='CEP')	{
	caracteres = '01234567890';
	separacoes = 1;
	separacao1 = '-';
	conjuntos = 2;
	conjunto1 = 5;
	conjunto2 = 3;
	if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
	(conjunto1 + conjunto2 + 1))
		{
		if (campo.value.length == conjunto1) 
		   campo.value = campo.value + separacao1;
		}
	else 
		event.returnValue = false;
	}
}



function ValidaEmail(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 Formatar_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 FormataCpf(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form.cpf.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	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 <= 2 ){ 
	 		document.form.cpf.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form.cpf.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form.cpf.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form.cpf.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.form.cpf.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.form.cpf.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 ) ;}

	}		
}



/////// VALIDA CPF  ////////
function Limpa(S){
//
// Deixa so' os digitos no numero
//
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){
//
// Inverte o string S
//
var temp="";
    for (var i=0; i<S.length; i++){
        temp=S.charAt(i)+temp
    }
    return temp
}

function Resto(S){
//
// Retorna o digito verificador (entrar com S "limpo")
//
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 Confere(cpfnum){
//
// Confere se o CPF dado esta' OK
//
var result = "";
var OK = false;
var temp = Limpa(document.form.cpf.value);
    if (temp.length>10){
       var work=temp.substring(0,(temp.length)-2)
       var resto = Resto(work);
       OK = (resto==eval(temp.charAt((temp.length)-2)));
       if (OK){
          work=work+resto;
          resto= Resto(work);
          OK = (resto==eval(temp.charAt((temp.length)-1)));
       }
    }


    if (OK){
		//alert("CPF OK!")
		//SetHelp("<img src='ok.gif'>")
    }else{
		document.form.cpf.focus();
		alert("CPF INVALIDO!")
		//SetHelp("<img src='nok.gif'>")
	}
}
//-->
