function bulkDeleteSystems(){
  if(confirm('Are you sure that you want to delete chosen systems?')){
    url = "bulk-delete-systems";
    $.post(url,
      $("#systemListForm").serialize(),
      function(data){
        if(data.OK){
          alert('Systems successfully deleted');
        } else{
          alert(data.error);
        }
      },
      'json'
    );
  }
}

function changeInstallerPageState(){
  state = $('[name=installerPageState]').val();
  if(state != ''){
    document.location = state + '-' + 'solar-installers';
  }
}

function showAddNewOwnerForm(){
  $('#profile-container').slideDown('slow');
}

function installerChooseOwner(){
  ownerId = $('[name=ownerId]').val();

  if(ownerId != ''){
    document.location = 'system?ownid=' + ownerId + '&exist=1';
  }
}

function switchMeterReadingType(type){
  types = ['choose', 'actual', 'meter'];

  $.each(types, function(k, v){
    if(v != type){
      $('tr.reading-' + v).hide();
      $('tbody.reading-' + v).hide();
    }
  });

  $('tr.reading-' + type).show();
  $('tbody.reading-' + type).show();

  $('#generationType').val(type);

  if(type == 'choose'){
    $('#submitMeterReading').hide();
  } else{
    $('#submitMeterReading').show();
  }
}

function showContractUploadForm(){
  $('#uploadContractFormContainer').show();
}

function showReferInstallerForm(){
  $('#referInstallerFormContainer').show();
}

function showSellSrecForm(){
  $(".manage-srecs-subform").hide();
  $("#sellSrecsFormContainer").show();
}

function toggleEstimatedSrecSaleFields(){
  $('.actual-srec-sale-field').toggle();
}

function showBulkPaySrecForm(){
  $(".manage-srecs-subform").hide();
  $("#bulkPaySrecsFormContainer").show();
}

function showBulkSellSrecForm(){
  $(".manage-srecs-subform").hide();
  $("#bulkSellSrecsFormContainer").show();
}

function showLoadPortfolioPlansForm(){
  $(".manage-srecs-subform").hide();
  $("#loadPortfolioPlansFormContainer").show();
}

function showGetSrecSalesSheetForm(){
  $(".manage-srecs-subform").hide();
  $("#getSrecSalesSheetFormContainer").show();
}

function selectAllCheckboxes(form){
  $('#' + form + ' input:checkbox').attr('checked', 'checked');
}

function unselectAllCheckboxes(form){
  $('#' + form + ' input:checkbox').attr('checked', '');
}

function setUpDashboardToggle(divsToHide){
  $('h2').click(function(event) {
    var $target = $(event.target);
    $target.next().toggle();
  });

  $.each(divsToHide, function(i, div){
    $('#' + div).hide();
  });
}

