/**
 * @author lezha
 */
$(document).ready(function() {
   $('#form_refinance').ajaxForm({
       beforeSubmit: function() { $('#btn_getquote').hide(); $('#loader').show(); },
       dataType: 'json',
       success: processJson
   });
   $('#form_purchase').ajaxForm({
       beforeSubmit: function() { $('#btn_getquote').hide(); $('#loader').show(); },
       dataType: 'json',
       success: processJson
   });
   $('#form_download').ajaxForm({
      beforeSubmit: function() { $('#btn_submit').hide(); $('#loader').show(); },
      dataType: 'json',
      success: processJsonDl
   });
   $('#form_limits').ajaxForm({
      beforeSubmit: function() { $('#response').hide(); $('#btn_getlimits').hide(); $('#loader').show(); },
      dataType: 'json',
      success: processJsonLimits
   });
   $('#form_calculator').ajaxForm({
      beforeSubmit: function() { $('#response').hide(); $('#btn_calculate').hide(); $('#loader').show(); },
      dataType: 'json',
      success: processJsonCalc
   });
});
function processJson(data) {
  $('#loader').hide();
  $('#btn_getquote').show(); 
  alert(data.message);
}
function processJsonDl(data) {
  if (data.status == 'error') {
     $('#loader').hide();
     $('#btn_submit').show(); 
     alert(data.message);
  }
  if (data.status == 'success') {
     if (data.code != null) {
        $('#form_body').html(data.message);
     }
  }
}
function processJsonLimits(data) {
  if (data.status == 'error') {
     $('#loader').hide();
     $('#btn_getlimits').show(); 
     alert(data.message);
  }
  if (data.status == 'success') {
        $('#response').html(data.message);
        $('#response').slideDown('slow');
        $('#loader').hide();
        $('#btn_getlimits').show(); 
  }
}
function processJsonCalc(data) {
  if (data.status == 'error') {
     $('#loader').hide();
     $('#btn_calculate').show(); 
     alert(data.message);
  }
  if (data.status == 'success') {
        $('#response').html(data.message);
        $('#response').slideDown('slow');
        $('#loader').hide();
        $('#btn_calculate').show(); 
  }
}
function show_hide (item,caller) {
   if($(item).css('display')=='none' || $(item).css('display')==null) {
      $(item).slideDown('fast');
      $(caller).html('Hide');
   }
   else {
      $(item).slideUp('fast');
      $(caller).html('Show');
   }
   
}
