function ajustarFone(input, evento){
	var ie = (typeof window.ActiveXObject != 'undefined');  
	var tecla;  
	if (ie)
		tecla = evento.keyCode;
	else
		tecla = evento.which;
	valor = input.value;
	valor = valor.replace( "(", "" );
	valor = valor.replace( ")", "" );
	valor = valor.replace( " ", "" );
	valor = valor.replace( "-", "" );
	tamanhoMaximo = 10;
	tamanho = valor.length;
	if(!soNumero(evento)){
		return false;
	} else { 
		if (tamanho < tamanhoMaximo && tecla != 8) {
		tamanho = valor.length + 1 ;
		}
		if (tecla == 8 ) {
			tamanho = tamanho - 1 ;
		}
		if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
			if ( tamanho <= 4 ) { 
				input.value = valor ;
			}
			if ( (tamanho > 4) && (tamanho <= 8) ) {
				input.value = valor.substr(0,tamanho-4) + '-' + valor.substr( tamanho - 4, tamanho ) ;
			}
			if ( (tamanho >= 9) && (tamanho <= 10) ) {
				input.value = '(' + valor.substr(0,2) + ') ' + valor.substr(2,tamanho-6) + '-' + valor.substr(tamanho-4,tamanho) ;			
			}
		}
	}
	return true;
}

//Completa a data com as barras "/"
function ajustarData(input, evento){
	if(!soNumero(evento)){
		return false;
	} else { 
		if ((input.value.length == 2)||(input.value.length == 5)) {
		   input.value = input.value + "/" ;
		   }
	}
	return true;
}

function soNumero(evento){
	var BACKSPACE=  8; 
	var TAB= 9;
	var DEL=  46; 
	var FRENTE=  39; 
	var TRAS=  37; 
	var tecla= (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode)

	if (( tecla == BACKSPACE )||(tecla == DEL)||(tecla == FRENTE)||(tecla == TRAS)||(tecla == TAB)){
		 return true; 
	}
	if ( tecla == 13 )     return false; 

	if ((tecla >= 48 && tecla <= 57) || (tecla == 44)) {
		return true;
	}else{
		evento.returnValue = false; 
		return false;
	}
}


//Formata CPF / CNPJ
function ajustarCpf(input, evento){
	var ie = (typeof window.ActiveXObject != 'undefined');  

	if (ie)
		tecla = evento.keyCode;
	else
		tecla = evento.which; 

	//alert(tecla);
	if(!soNumero(evento)){
		return false;
	}else{
		if((tecla<48)||(tecla>57)){
			evento.returnValue =false;
			return false;
		}else{
			if ((input.value.length == 3)||(input.value.length == 7)) {
				input.value = input.value + "." ;
			}
			if (input.value.length == 11) {
				input.value = input.value + "-" ;
			}
			if(input.value.length == 15){
				input.value = input.value.replace('.','');
				input.value = input.value.replace('.','');
				input.value = input.value.replace('-','');
				input.value = input.value.substr(0, 2) + '.' + input.value.substr(2, 3) + '.' + input.value.substr(5, 3) + '/' + input.value.substr(8, 4);
				input.value = input.value + "-" ;
			}
		}
	}
	return true;
}

function buscaCPF(cpf){
	document.getElementById("name").value = "";
	document.getElementById("phone").value = "";
	
	if (cpf != ""){	
		document.getElementById("aguarde").style.display = "";
		var url = "buscaCPF.php?cpf="+cpf;
		window.open(url, 'ifr_update');
	}else{
		document.getElementById("aguarde").style.display = "none";
	}
}

function changeCustomer(id){
	if (id == 1 || id == "1"){
		document.getElementById("cpf").value = "";
		document.getElementById("reserves_customer").style.display = "none";		
	}else{
		document.getElementById("reserves_customer").style.display = "";
	}
}
