// JavaScript Document

$titulo = document.title;

function cnpj_cpf($num,$objeto){
var $tblcnpj    = document.getElementById('tab_cnpj');
var $tbl_cpf    = document.getElementById('tabcliente');
var $titulocad  = document.getElementById('titulocad');
var $num       = limpar($num);

if($num.length > 11){ 
  $tblcnpj.style.display = 'inline';
  $titulocad.innerHTML = 'Dados da Empresa:';
  $tbl_cpf.style.display = 'none';
  cnpj($num,$objeto)
  }else{
  $tbl_cpf.style.display = 'inline';
  $tblcnpj.style.display = 'none';
  $titulocad.innerHTML = 'Dados do Cliente:';
  cpf($num,$objeto)
  }

if($num.length == 11){ $titulocad.innerHTML = 'Dados do Cliente:'; cpf($num,$objeto);
  }else{ 
   $titulocad.innerHTML = 'Dados da Empresa:';
  }
}

/////////////////////////////
function limpar($valor){

	var $total = $valor.length;
	//alert($total);
    for($i=0;$i <= $total; $i++ ) {
    $valor = $valor.replace('.','');
	$valor = $valor.replace('-','');
	$valor = $valor.replace('/','');
	
}
return $valor;
}
//////////////////////////
function cpf($txt,$campo){
var $final = '';
var $con = -1;
var $txt = limpar($txt);
var $total = $txt.length;
    for($i = 0;$i <= $total;$i++){
     $con++;
	 $final += $txt.substring($i - 1,$i);
	 if($i == 3){
	 $final += '.';
	 }if($i == 6){
	 $final += '.';
	 }
	 if($i == 9){
	 $final += '-';
	 }
	}
$campo.value = $final;
}
//////////////////////////
function cnpj($txt,$campo){
var $final = '';
var $con = -1;
var $txt = limpar($txt);
var $total = $txt.length;
    for($i = 0;$i <= $total;$i++){
     $con++;
	 $final += $txt.substring($i - 1,$i);
	 if($i == 2){
	 $final += '.';
	 }if($i == 5){
	 $final += '.';
	 }
	 if($i == 8){
	 $final += '/';
	 }
	 if($i == 12){
	 $final += '-';
	 }
	}
$campo.value = $final;
$campo.maxlength = 14;
}
///////////////////////////

function somente_numeros(e) { // acho que nem prescisa comentar né !
// uso: onkeypress="somente_numeros(event)";
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
	else {
		if (tecla != 8) // backspace
			event.keyCode = 0;
			//return false;
		else
			return true;
    }
}

function maskara(mask){ // FUNÇÃO para mascar campos ^^
// uso: maskara(this, '###.###.###-##');

    var    src   = document.getElementById("cnpj");
	limpar(src.value);
  	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);
	}

}

function CLT_estrelas($escolha){
$estrela1 = document.getElementById('e1');
$estrela2 = document.getElementById('e2');
$estrela3 = document.getElementById('e3');
$estrela4 = document.getElementById('e4');
$estrela5 = document.getElementById('e5');

$estrela1.style.display = 'none';
$estrela2.style.display = 'none';
$estrela3.style.display = 'none';
$estrela4.style.display = 'none';
$estrela5.style.display = 'none';

if($escolha == 1){ $estrela1.style.display = 'inline'; }
if($escolha == 2){ 
$estrela1.style.display = 'inline';
$estrela2.style.display = 'inline';
}
if($escolha == 3){ 
$estrela1.style.display = 'inline';
$estrela2.style.display = 'inline';
$estrela3.style.display = 'inline';
 
}
if($escolha == 4){ 
$estrela1.style.display = 'inline';
$estrela2.style.display = 'inline';
$estrela3.style.display = 'inline';
$estrela4.style.display = 'inline';

}
if($escolha == 5){ 
$estrela1.style.display = 'inline';
$estrela2.style.display = 'inline';
$estrela3.style.display = 'inline';
$estrela4.style.display = 'inline';
$estrela5.style.display = 'inline'; 
}
}




