/*
  green.js
  JS file for Green Cars pages
*/
function get_models(section)
{
  if(section == "tax")
  {
    $('#taxOutput').html('');
  }

  $.ajax({
    url: '/ajax-html-green-cars.php',
    type: 'GET',
    dataType: 'html',
    data: 'retrieve=models&manufacturer=' + $('#' + section + 'Make').val() + '&section=' + section,
    success: function(html) {
      $('#' + section + 'Model').html(html);
    }
  });

  $.ajax({
    url: '/ajax-html-green-cars.php',
    type: 'GET',
    dataType: 'html',
    data: 'retrieve=derivatives&manufacturer=' + $('#' + section + 'Make').val() + '&model=',
    success: function(html) {
      $('#' + section + 'Derivative').html(html);
    }
  });
}

function get_derivatives(section)
{
  if(section == "tax")
  {
    $('#taxOutput').html('');
  }

  $.ajax({
    url: '/ajax-html-green-cars.php',
    type: 'GET',
    dataType: 'html',
    data: 'retrieve=derivatives&manufacturer=' + $('#' + section + 'Make').val() + '&model=' + $('#' + section + 'Model').val() + '&section=' + section,
    success: function(html) {
      $('#' + section + 'Derivative').html(html);
    }
  });
}

function get_tax_data()
{
  if($('#taxDerivative').val() != '')
  {
    $.ajax({
      url: '/ajax-html-green-cars.php',
      type: 'GET',
      dataType: 'html',
      data: 'retrieve=tax&capid=' + $('#taxDerivative').val(),
      success: function(html) {
        $('#taxOutput').html(html);

        switch($('#taxBand').val())
        {
          case "A":
            $('#slider').css('left','0%');
            break;
          case "B":
          case "C":
            $('#slider').css('left','14%');
            break;
          case "D":
          case "E":
            $('#slider').css('left','29%');
            break;
          case "F":
            $('#slider').css('left','43%');
            break;
          case "G":
            $('#slider').css('left','57%');
            break;
          case "H":
          case "I":
            $('#slider').css('left','72%');
            break;
          case "J":
          case "K":
            $('#slider').css('left','86%');
            break;
          case "L":
          case "M":
            $('#slider').css('left','100%');
            break;
          default:
            break;
        }
      }
    });
  }

  return false;
}

function get_running_costs()
{
  if($('#runDerivative').val() != '')
  {
    $.ajax({
      url: '/ajax-html-green-cars.php',
      type: 'GET',
      dataType: 'html',
      data: 'retrieve=running&capid=' + $('#runDerivative').val(),
      success: function(html) {
        $('#runOutput').html(html);
      }
    });
  }
}

function get_benefit_in_kind_data()
{
  if($('#benDerivative').val() != '')
  {
    $.ajax({
      url: '/ajax-html-green-cars.php',
      type: 'GET',
      dataType: 'html',
      data: 'retrieve=benefit&capid=' + $('#benDerivative').val(),
      success: function(html) {
        $('#benOutput').html(html);
      }
    });
  }
}

