$(document).ready(function(){

    $('.formrow input').focusin(function(){
        $(this).parents('.formrow').find('.formrow_balloon').show('fast');
        
    });
    
    $('.formrow input').focusout(function(){
        $(this).parents('.formrow').find('.formrow_balloon').hide();
    });

    $('#generate').click(function() {
        
        var url = CI.base_url + "firma/generate";
        var data = $("#generateform").serialize();
        
        $('#result textarea').text('');
        $('#loader').show();
        
        $.ajax({
          type: 'POST',
          url: url,
          data: data,
          success: function(res) {
            
            var text = res.signature;
            
            //$('#resultplaceholder').load( CI.base_url + "firma/see" );
            $('#resultplaceholder').hide();
            $('#resultimage').attr('src',  CI.base_url + 'output/' + res.filename  );
            
            $('#loader').hide();            
          },
          dataType: 'json'
        });
        return false;
    });

    $('#result textarea').autoResize({
        // On resize:
        onResize : function() {
            $(this).css({opacity:0.9});
        },
        // After resize:
        animateCallback : function() {
            $(this).css({opacity:1});
        },
        // Quite slow animation:
        animateDuration : 200,
        // More extra space:
        extraSpace : 40
    });

});
  
