//INICIALIZA TAXAS
//document.onready = function() {
//    // TIPO DO EMPRÉSTIMO, MES INICIAL, MES FINAL, VALOR
//    defineTaxa('credito_24',    1,  12,     1.69);
//    defineTaxa('credito_24',    13,  24,     1.69);
//    defineTaxa('credito_24',    25,  36,     1.99);
//    defineTaxa('credito_24',    37,  48,     1.99);
//    
//    defineTaxa('extra',    1,  48,     4.50);
//}
//
////MATRIZ TAXA/MÊS
//val = [[]];
//
////INICIALIZADOR DE TAXAS
//function defineTaxa(tipo_emprestimo,inicio,fim,valor) {
//    switch (tipo_emprestimo) {
//        case 'credito_24':
//            t = 0;
//            break;
//        default:
//            t = 0;
//            break;
//    }
//    for(n = inicio; n<= fim; n++) {
//        top.val[t][n] = valor;
//    }
//}
//
////RETORNA TAXA EM MÊS DEFINIDO
//function taxa(tipo_emprestimo,meses) {
//    switch (tipo_emprestimo) {
//        case 'credito_24':
//            t = 0;
//            break;
//        default:
//            t = 0;
//            break;
//    }
//    return top.val[t][meses];
//}
//
//
//function selecionaTipo(valor) {
//    switch (valor) {
//        case "13_salario":
//            
//            break;
//        case "credito_24":
//        
//            break;
//        case "credito_48":
//        
//            break;
//        case "extra":
//        
//            break;
//        case "financiamento":
//        
//            break;
//        case "ir":
//        
//            break;
//    }
//}

function mudaParcelas(){
	var valor = $("input[name=emprestimo]").val();//document.getElementById('emprestimo').value;
    valor = valor.replace(".","");
	valor = valor.replace(",","");
	valor = parseFloat(valor);
	var qtd_parcela = 48;
	if (valor == ''){
		alert('Por favor preencha o campo valor para escolher um tipo de emprestimo');
		$('#tipo').find('option[value=""]').attr('selected', true);
	}else{	
	    var tipo = $('#tipo option:selected').val();//document.getElementById('tipo').value;
	    var option = '';
	    
	    switch(tipo){
	    	case 'financiamentos':
	    		if (valor > 2000000){
		    		qtd_parcela = 60;
		    	}else{
		    		qtd_parcela = 48;
		    	}
	    		break;
	    	case 'credito_pessoal':
	    		qtd_parcela = 48;
	    		break;
	    }
	    for(n = 1; n <= qtd_parcela; n++){
            option = option + '<option value="'+n+'">'+n+'</option>';
        }
	    $('#num-parcelas').html(option);
	}
}

function enviaForm(){
    var emprestimo = $("input[name=emprestimo]").val(); //document.getElementById('emprestimo').value;
    var tipo = $('#tipo option:selected').val();//document.getElementById('tipo').value;
    var parcelas = $('#num-parcelas option:selected').val();//document.getElementById('num-parcelas').value;
    if((emprestimo != '')&&(tipo != '')){
        $('#result').html('<img id="preloader" src="imagens/preloader.gif" />');
        $.ajax({
           type: "GET",
           url: "calculaemprestimo.php",
           data: "parcelas="+parcelas+"&tipo="+tipo+"&emprestimo="+emprestimo,
           success: function(msg){
             $('#result').html(msg);
           }
         });   
    }else{
        $('#result').html('<span style="color: red">Para simular o empr&eacute;stimo &eacute; necess&aacute;rio especificar o valor e o tipo de empr&eacute;stimo.</span>');
    }
}
