function mostrar_elemento(id,valor_elemento,valor) {
  document.getElementById(id).style.display = (valor_elemento == valor)?"inherit":"none";
}

function elemento_seleccionado(id) {
  elemento = document.getElementById(id);
  return elemento.options[elemento.selectedIndex].value;
}

function formatea_rut(id){
  rut = document.getElementById(id).value;
	if(rut.length > 1 && rut.length <= 12){
		var ultimo_digito = rut.substr(rut.length - 1, 1);
		rut = rut.replace(/\W/g, '');
		rut = rut.replace(/\D/g, '');
		var dv = rut.substr(rut.length - 1, 1);
		if(!(ultimo_digito.toUpperCase() == 'K')){
			rut = rut.substr(0, rut.length - 1);
		}else{
			dv= 'K';
		}
		if(rut && dv){
			document.getElementById(id).value = formatear_millones(rut) + '-' + dv;
		}
	}
	function formatear_millones(numero){
		var rut = '';
		for (var j = 0, i = numero.length - 1; i >= 0; i--, j++){
			rut = numero.charAt(i) + ((j > 0) && (j % 3 == 0)? "." : "") + rut;
		}
		return rut;
    }
}

