// JavaScript Document

$(function(){

	if ($(".pergunta").length >= 1) {
		$(".faq").click(function(){
			if ($(this).find(".resposta").css("display") == "block") {
				$(this).find(".resposta").hide("fast")
			} else {
				$(this).find(".resposta").show("fast")
			}
			return false;
		})
	}
	
	if ($('#link-destaques .cotacao').length == 1) {
		date = new Date();
		$.get('/index.php/remote/cotacao/' + date.getTime(), function(resp){
			$('.cotacao').html(resp)
		})
	}

    /*---------------------
        botoes pagina contato
    -----------------------*/
    if ($('#formContato').length >= 1) {
        $('.botao-enviar').click(function(){
            $('#formContato').submit()
        })

        $('.botao-cadastrar').click(function(){
            $(this).parent().parent().parent().submit()
        })
    }

    /*---------------------------
        form solicite resgate
    ----------------------------*/
    if ($('#formResgate').length >= 1) {

    	//if ($.browser.msie) {
    		$("input:radio").addClass("radio-button")
    		$("label").addClass("resgate")
    	//}

        $('#total').click(function(){
            disabled(true)
        })
        $('#parcial').click(function(){
            disabled(false)
            Mask.financier(document.getElementById('valor'), true)
        })
        $('#cotas').click(function(){
            disabled(false)
        })
        $('#valor').keyup(function(){
            if ($('#parcial').attr('checked'))
			    Mask.financier(document.getElementById('valor'), true)
        })
        
	    $('#motivo').change(function(){
	        if ($(this).val()=='Outros')
	            $('#especificar').show()
            else
                $('#especificar').hide()
        })

        $('#tipo_pf').click(function(){
            exibe('pf')
        })
        
        $('#tipo_pj').click(function(){
            exibe('pj')
        })
        
        $('.botao-enviar').click(function(){
            $('#formResgate').submit()
        })
        
        function exibe(t){
            if (t=='pf'){
                $('#li_pf').show()
                $('#li_pj').hide()
            } else {
                $('#li_pj').show()
                $('#li_pf').hide()
            }
        }

        function disabled(state){
		    $('#valor').attr('disabled', state)
	    }
    
	    /*-- funcoes ao entrar na tela --*/
	    if ($('#tipo_pf').attr('checked'))
	        exibe('pf')
        else
            exibe('pj')

	    if ($('#motivo').val()=='Outros')
	        $('#especificar').show()
        
        if ($('#total').attr('checked'))
            disabled(true)
        else
            disabled(false)
        
    }
    
    /*-------------
        Confirmacao de dados do resgate
    -------------*/
    if ($('#formInfo').length >= 1) {
        $('.botao-enviar').click(function(){
            $('#formInfo').submit()
        })
    }
    
    
    
    /*------------------
        Histórico de Cotas
    ---------------------*/   
    if ($('#formHistoricoCotas').length >= 1) {
    
        $("#loading").ajaxStart(function(){
           $(this).show();
         });  
        $("#loading").ajaxStop(function(){
           $(this).hide();
         });

        $('#formHistoricoCotas').submit(function()
        {  
          $.ajax({
            type: "POST",
            dataType: "html",
            url: "/index.php/sparta/performanceBusca/"+id,
            data: $(this).serialize(),
            success: function(response){
              $('#resultado').html(response);
            }
          });
          
          return false;
        });

        $('#dt_inicial').focus(function(){
            $(this).mask('99/99/9999')
            $(this).css('background-color', '#eee')
        })
        $('#dt_inicial').blur(function(){
            $(this).css('background-color', '#fff')
        })
        $('#dt_final').focus(function(){
            $(this).mask('99/99/9999')
            $(this).css('background-color', '#eee')
        })
        $('#dt_final').blur(function(){
            $(this).css('background-color', '#fff')
        })
    }

    /*-----------------------
        Altura dos itens das caracteristicas
    -----------------------*/
    if ($('.caract-caixa').length > 0) {
        $('.caract-caixa').each(function(){
            if ($(this).find('.caract-dir').height() < $(this).find('.caract-esq').height())
                $(this).find('.caract-dir').css('height', $(this).find('.caract-esq').height() + 'px' )
        })
    }
})
