<!--
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' precisa conter um email válido.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é requerido.\n'; }
  } if (errors) alert('Todos os campos são obrigatórios:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var erros = '';
var er_plur = '';


function Errar(campo){
	if (erros != ''){
		erros = erros + ';'
		er_plur = 's'
	}
	erros = erros + '\n' + campo
	return false;
}


function Check(campo,n,v){
	if(campo.value.length < n)
		return Errar(v);
}

function ConsisteCPF(nu_cpf){
	nu_cpf = nu_cpf.replace('.','');
	nu_cpf = nu_cpf.replace('.','');
	nu_cpf = nu_cpf.replace('-','');
	if (nu_cpf == ''){
		return Errar('CPF');
 }
l = nu_cpf.length;
//se usuário não digitar os zeros na frente do CPF, completa sozinho
if ((l == 10) || (l == 9)){
            for (i = l ; i < 11; i++){
                        nu_cpf = '0' + nu_cpf
            }
}
 if (nu_cpf.length != 11){
		return Errar('CPF');
 }
 for (i=0;i<nu_cpf.length;i++){
      if (!((nu_cpf.substring(i,i+1) >= '0') && (nu_cpf.substring(i,i+1) <= '9'))){
		return Errar('CPF');
         }
     }
 nu_cpf_dv=nu_cpf.substring(9,11);
 nu_cpf = nu_cpf.substring(0,9);
 for (k=1;k<3;k++){
      soma = 0;
      multi = 1;
      for (i=nu_cpf.length-1;i>=0;i--){
          multi++;
          soma += (parseInt(nu_cpf.substring(i,i+1),10) * multi); 
           }
      resto = (soma % 11);
      dv =0;
      if (resto > 1){
          dv= 11 - resto;
         }
      nu_cpf +=dv; 
     }
if (nu_cpf_dv == nu_cpf.substring(9,11)){
return true
}else{
		return Errar('CPF');
}
}


function TestEmail(email){
	var str=email.value
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str) && str.indexOf('@')>0)
		emailresult=true
	else {
		return Errar('E-mail');
	}
	return (emailresult)
}


function NavEmail(email){
	if (email.value != ''){
		if (document.layers||document.all)
			return TestEmail(email)
			else
			return true
	}
}

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {		
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function ParseNumb(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
}

function Verify(CNUMB,CTYPE)
{
  CNUMB=ParseNumb(CNUMB)
  if(CNUMB == 0)
  {
    return Errar('CPF/CNPJ');
  }
  else
  {
    g=CNUMB.length-2;
    if(TestDigit(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(TestDigit(CNUMB,CTYPE,g))
      {	
        return(true);
      }
      else
      {
        return Errar('CNPJ');
      }
    }
    else
    {
      return Errar('CNPJ');
    }
  }
}

function TestDigit(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return Errar('CNPJ');
  }
  else
  {
    return(true);
  }
}

function TeclaNum(e){
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105)) // numeros de 0 a 9
		return true;
	else
		if (tecla != 8 && tecla != 9 && tecla != 46 && tecla != 13) // backspace tab delete e enter
			return false;
		else
			return true;
}


function TeclaNumProx(campo,pro_campo,num){
	if(campo.value.length == num){
		pro_campo.focus()
	}
}


function TeclaTexto(e){
	if(document.all) // Internet Explorer
	var tecla = event.keyCode;
	else if(document.layers) // Nestcape
	var tecla = e.which;
	if((tecla >= 65 && tecla <=90) || (tecla >= 97 && tecla <=122)) // A-Z e a-z
	return true;
	else
	if (tecla != 8 && tecla != 9 && tecla != 46 && tecla != 13) // backspace tab delete e enter
	return false;
	else
	return true;
}


function FormataCPF(el, e){ 
	vr = el.value; 
	tam = vr.length; 
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105)){ // numeros de 0 a 9
		if ( vr.indexOf(".") == -1 ){ 
			if ( tam <= 3 ) 
				el.value = vr; 
		}
		if ( tam == 3 ) 
			el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam ); 
		if ( tam == 7 ) 
			el.value = vr.substr( 0, 7 ) + '.' + vr.substr( 8, 3 ); 
		if ( tam == 11 ) 
			el.value = vr.substr( 0, 11 ) + '-' + vr.substr( 12, 2 ); 
		return true;
	}else
		if (tecla != 8 && tecla != 46 && tecla != 13) // backspace delete e enter
			return false;
		else
			return true;
} 


function FormataRG(el, e){ 
	vr = el.value; 
	tam = vr.length; 
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105)){ // numeros de 0 a 9
		if ( tam == 1 ) 
			el.value = vr.substr( 0, 1 ) + '.' + vr.substr( 2, 1 ); 
		if ( tam == 5 ) 
			el.value = vr.substr( 0, 5 ) + '.' + vr.substr( 6, 1 ); 
		if ( tam == 9 ) 
			el.value = vr.substr( 0, 9 ) + '-' + vr.substr( 10, 1 ); 
		return true;
	}else
		if (tecla != 8 && tecla != 46 && tecla != 13) // backspace delete e enter
			return false;
		else
			return true;
} 


function FormataCEP(el, e){ 
	vr = el.value; 
	tam = vr.length; 
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105)){ // numeros de 0 a 9
		if ( tam == 2 ) 
			el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 3, 1 ); 
		if ( tam == 6 ) 
			el.value = vr.substr( 0, 6 ) + '-' + vr.substr( 7, 1 ); 
		return true;
	}else
		if (tecla != 8 && tecla != 46 && tecla != 13) // backspace delete e enter
			return false;
		else
			return true;
} 


function FormataData(el, e){ 
	vr = el.value; 
	tam = vr.length; 
	if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105)){ // numeros de 0 a 9
		if ( tam == 2 ) 
			el.value = vr.substr( 0, 2 ) + '/' + vr.substr( 3, 1 ); 
		if ( tam == 5 ) 
			el.value = vr.substr( 0, 5 ) + '/' + vr.substr( 6, 1 ); 
		return true;
	}else
		if (tecla != 8 && tecla != 46 && tecla != 13) // backspace delete e enter
			return false;
		else
			return true;
} 


function FormataValor(el, e){ 
	vr = el.value; 
	if(vr.indexOf('0,')==0)
		vr = vr.replace('0,','');
	vr = vr.replace(',','');
	while(vr.indexOf('.')!= -1){
		vr = vr.replace('.','');
	}
	while(vr.indexOf(' ')!= -1){
		vr = vr.replace(' ','');
	}
	tam = vr.length;
if(document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
	if(tecla > 47 && tecla < 58 || (tecla >= 96 && tecla <= 105) || tecla == 8 || tecla == 46){ // numeros de 0 a 9, teclado numérico, setas backspace delete
		if ( tam < 3 )
			el.value = '0,' + vr; 
		if ( tam >= 3 && tam < 6 )
			el.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, 2 ); 
		if ( tam >= 6 ){
			t = tam;
			str = vr.substr( 0, t - 2 );
			str2 = '';
			saida = '';
			while(t > 5){
			saida = str.substr( 0, t - 5 );
			str2 = '.' + str.substr( t - 5, 3 ) + str2;
			t = t - 3;
			}
//vr.substr( 0, tam - 4 ) + '.' + vr.substr( tam - 4, 3 )
			el.value = saida + str2 + ',' + vr.substr( tam - 2, 2 ); 
		}
		return true;
	}else
		if (tecla != 13 && (tecla < 37 || tecla > 40)) //  e enter
			return false;
		else
			return true;
} 


function ValidaFormParc(){
	NavEmail(document.MeuForm.email);
	Check(document.MeuForm.email,1,'E-Mail');
	Check(document.MeuForm.senha,2,'Senha');
	Check(document.MeuForm.c_senha,1,'Confirmar Senha');
//	Check(document.MeuForm.razao,1,'Razão Social');
//	Check(document.MeuForm.fantasia,1,'Fantasia');
/*
	if(Verify(document.MeuForm.cpf_cnpj.value,'CNPJ') == false){
		if(ConsisteCPF(document.MeuForm.cpf_cnpj.value) == true){
			erros = erros.replace('\nCPF/CNPJ;','');
			erros = erros.replace('\nCPF/CNPJ','');
		}
	}
*/
	ConsisteCPF(document.MeuForm.cpf.value);
	if(document.MeuForm.cnpj.value.length > 0)
		Verify(document.MeuForm.cnpj.value,'CNPJ');
	Check(document.MeuForm.contato,1,'Nome do Responsável');
	Check(document.MeuForm.cargo,1,'Profissão');
	Check(document.MeuForm.endereco,1,'Endereço');
	Check(document.MeuForm.bairro,1,'Bairro');
	Check(document.MeuForm.complemento,1,'Complemento');
	Check(document.MeuForm.cidade,1,'Cidade');
	Check(document.MeuForm.cep,10,'CEP');
	Check(document.MeuForm.estado,2,'Estado');
	Check(document.MeuForm.fone,9,'Telefone Comercial');
	Check(document.MeuForm.tel_residencial,9,'Telefone Residencial');
	Check(document.MeuForm.celular,9,'Celular');
	Check(document.MeuForm.banco,1,'Banco');
	Check(document.MeuForm.agencia,2,'Agência');
	Check(document.MeuForm.conta,2,'Nº da conta');
//	Check(document.MeuForm.comissao,1,'Comissao');
	ChecaSenha(document.MeuForm.senha,document.MeuForm.c_senha,'Senha');	
	Check(document.MeuForm.nasc_dia,1,'Dia de nascimento');
	Check(document.MeuForm.nasc_mes,1,'Mês de nascimento');
	Check(document.MeuForm.nasc_ano,1,'Ano de nascimento');

	if (erros != ''){
		tracos = (er_plur!='')?'---':'';
		alert('Por favor, preencha corretamente o' + er_plur + ' campo' + er_plur + ':\n----------------------------------------------------' + tracos + erros + '.');
		er_plur = '';
		erros = '';
		return false
	}else{
		return true
	}
}

function ChecaSenha(campo1,campo2,v){
	if(campo1.value != campo2.value)
		return Errar(v);
}

function show( n, Elem ){
	if( document.MeuForm.tipo[n].checked == true ){
		document.getElementById(Elem).style.display = "";
	}else{
		document.getElementById(Elem).style.display = "none";
	}
}
function hide(){
		document.getElementById('p1').style.display = "none";
		document.getElementById('p2').style.display = "none";
		document.getElementById('p2a').style.display = "none";
		document.getElementById('p3').style.display = "none";
		document.getElementById('p3a').style.display = "none";
}

//-->