
function orderhelper_init() {
  $('form').click(evaluatecontrols);


  $(':checked').each(function(idx,x){$(x).click();$(x).change();});
}


function evaluatecontrols() {
  var regular_group = $('#id_group_0').attr('checked');
  var student_group = $('#id_group_1').attr('checked');
  var sample_group  = $('#id_group_2').attr('checked');

  if(regular_group) {
    currentprices = regularprices;
    displayprices();
    showsplits();
    showduration();
    showpayment();
  } else if(student_group) {
    currentprices = studentprices;
    displayprices();
    showsplits();
    showduration();
    showpayment();
  } else if(sample_group) {
    hidepayment();
    hidesplits();
    hideduration();
    return;
  }




  var duration = 12;

  if($('#id_duration_1').attr('checked')) {
    duration = 6;
  } else if ($('#id_duration_2').attr('checked')) {
    duration = 3;
  }

  if(duration == 12) {
    showsplits();
  } else {
    hidesplits();
  }


  var splits = 1;

 if($('#id_splits_1').attr('checked')) {
    splits = 2;
  } else if ($('#id_splits_2').attr('checked')) {
    splits = 4;
  }


  if(splits == 1) {
    enablepayment();
  } else {
    disablepayment();
  }

}


function hidepayment() {
  $("#id_payment_0").parent().parent().parent().parent().parent().hide();
}

function showpayment() {
  $("#id_payment_0").parent().parent().parent().parent().parent().show();
}



function enablepayment() {
  $("#id_payment_1").attr('disabled',false);
  $("#id_payment_2").attr('disabled',false);

}


function disablepayment() {
  if(!($('#id_payment_0').attr('checked'))){
    $("#id_payment_0").click();
  }

  $("#id_payment_1").attr('disabled',true);
  $("#id_payment_2").attr('disabled',true);
}


function hidesplits() {
  if(!($('#id_splits_0').attr('checked'))){
     $("#id_splits_0").click();
  }
  $("#id_splits_0").parent().parent().parent().parent().parent().hide();
}

function showsplits() {
  $("#id_splits_0").parent().parent().parent().parent().parent().show();
}

function hideduration() {
  $("#id_duration_0").parent().parent().parent().parent().parent().hide();
}

function showduration() {
  $("#id_duration_0").parent().parent().parent().parent().parent().show();
}



var regularprices = [75, 42, 25];
var studentprices = [55, 32, 20];
var duration = ["12 kk", "6 kk", "3 kk"];
var currentprices = regularprices;




function displayprices() {
  disp(0);
  disp(1);
  disp(2);
}

function disp(idx) {
  var radio = $('#id_duration_' + idx);
  var par = radio.parent();
  par.html("");
  par.append(radio);


  par.append(duration[idx] + " "  + currentprices[idx] + "€");
}


$(document).ready(orderhelper_init);