$(".form").each(function(i){                         
         $(this).val($(this).attr("valueDefault")); 
 });
selectTipoTabelaBd();
function selectTipoTabelaBd()
{
	
	switch($("#tipoTabela").val())
	{
		case "TINYINT":
			$("input[name*='tamanho']").val("1");
			$("input[name*='tamanho']").prop("readonly",true);
			$("#formatosData").attr( "hidden", "hidden" );
			$("#formatosTabela").attr( "hidden", "hidden" );
			$("#tamanhobd").prop("required","required");
		break;
		case "varchar":
			$("input[name*='mascara']").prop("readonly",false);
			$("input[name*='mascara']").val($("input[name*='mascara']").attr("valueDefault"));
			$("input[name*='tamanho']").val($("input[name*='tamanho']").attr("valueDefault"));
			$("input[name*='tamanho']").prop("readonly",false);
			$("#formatosData").attr( "hidden", "hidden" );
			$("#formatosTabela").attr( "hidden", "hidden" );
			$("#tamanhobd").prop("required","required");
		break;
		case "data":
			$("input[name*='tamanho']").prop("readonly",true);
			$("input[name*='tamanho']").val("");
			$("#formatosData").removeAttr( "hidden" );
			$("#formatosTabela").attr( "hidden", "hidden" );
			$("#tamanhobd").removeProp( "required" );
			$("#mascarabd").val("00/00/0000");
		break;
		case "tabela":
			$("input[name*='tamanho']").prop("readonly",true);
			$("input[name*='tamanho']").val("");
			$("#formatosTabela").removeAttr( "hidden" );
			$("#formatosData").attr( "hidden", "hidden" );
			if ($("#tabela").attr("valueDefault")  === undefined)
			{	
				$("#comboboxTabelas").load( "src/controller/Tabelas_bd.php?mod=combobox" );
			}	
			$("#tamanhobd").removeProp( "required" );
		break;
		case "tabela_n_pra_n":
			$("input[name*='tamanho']").prop("readonly",true);
			$("input[name*='tamanho']").val("");
			$("#formatosTabela").attr( "hidden", "hidden" );
			$("#formatosData").attr( "hidden", "hidden" );
			if ($("#tabela").attr("valueDefault")  === undefined)
			{	
				$("#comboboxListaTabelas").load( "src/controller/Tabelas_bd.php?mod=combobox" );
			}	
			$("#tamanhobd").removeProp( "required" );
		break;
		default:
			$("input[name*='tamanho']").val($("input[name*='tamanho']").attr("valueDefault"));
			$("input[name*='tamanho']").prop("readonly",false);
			$("input[name*='mascara']").prop("readonly",true);
			$("input[name*='mascara']").val("");
			$("#formatosData").attr( "hidden", "hidden" );
			$("#formatosTabela").attr( "hidden", "hidden" );
			$("#tamanhobd").prop("required","required");
		break;	
	}	
				
}	
function selectTabelaBd()
{
	$("#comboboxColunas").html("<select class=\"form\" name=\"campo\" ><option checked>Buscando colunas...</option></select>");
	$("#comboboxColunas").load( "src/controller/Colunas_bd.php?mod=combobox&idTabela="+$("#tabela").val()+"&nameSeletor=tipocoluna" );
	$("#comboboxColunasPrimarias").load( "src/controller/Colunas_bd.php?mod=combobox&idTabela="+$("#tabela").val()+"&indice=PRIMARY"+"&nameSeletor=tipocolunaprimaria" );
}	

function alteraMask(mask)
{
	$("input[name*='mascara']").val(mask);
}


/*$("#multiregistros").on("click", function(){
    if($("#multiregistros").is(':checked')) {
        $('#indice').val($("#multiregistros").val());
    } else {
         $('#indice').val('');
    }
}); */

$("#estrangeiracomposta").on("click", function(){
    if($("#estrangeiracomposta").is(':checked')) {
       $("#tipocolunaprimaria").attr("readonly",true);
    } else {
       $("#tipocolunaprimaria").attr("readonly",false);
    }
}); 

//retira espaço do campo couluna
var $t = document.getElementById('colunabd');
$t.addEventListener('paste', function(event) {
  setTimeout(function(){
    this.value = this.value.replace(/\s+/g, '');
  }.bind(this), 0)
});
$t.addEventListener('keyup', function(event) {
  setTimeout(function(){
    this.value = this.value.replace(/\s+/g, '');
  }.bind(this), 0)
});

