function addParticipant(evt)
{
var index = parseInt($('#participants dl:last').attr('id').replace('participant-', '')) + 1;
var html = '
';
html += ' ';
html += ' -
';
html += ' ';
html += ' -
';
html += ' - *
';
html += ' - ';
html += ' ';
html += ' ';
html += '
';
html += ' ';
html += ' -
';
html += ' ';
html += ' -
';
html += ' ';
html += ' -
';
html += ' ';
html += ' - ';
html += ' ';
html += '
';
html += ' ';
html += ' - ';
html += ' ';
html += '
';
html += ' - Delete
';
html += '
';
// append
$('#participants').append(html);
// bind remove-links
$('.remove-participant').click(function(e) {
var id = $(this).attr('rel')
$('#'+ id).remove();
recalculatePrice();
e.preventDefault();
e.stopPropagation();
});
$('#participants .input-text').change(function(e) { recalculatePrice(e) });
recalculatePrice();
// break event
evt.preventDefault();
evt.stopPropagation();
}
function enableInvoiceFields(bool)
{
var status = '';
if(!bool) status = 'disabled';
$('#invoice_company').attr('disabled', status)
$('#invoice_street').attr('disabled', status)
$('#invoice_nr').attr('disabled', status)
$('#invoice_bus').attr('disabled', status)
$('#invoice_zip').attr('disabled', status)
$('#invoice_place').attr('disabled', status)
$('#invoice_country').attr('disabled', status)
}
function copyToInvoice()
{
if(!$('#invoice_address').attr('checked'))
{
$('#invoice_company').val($('#company').val());
$('#invoice_street').val($('#street').val());
$('#invoice_nr').val($('#nr').val());
$('#invoice_bus').val($('#bus').val());
$('#invoice_zip').val($('#zip').val());
$('#invoice_place').val($('#place').val());
$('#invoice_country').val($('#country').val());
}
}
function recalculatePrice()
{
if(typeof(aPrices) != "undefined")
{
// get selected id
var id = $('#event').val();
// get price
var price = parseFloat(aPrices[id]);
var fields = $('#participants .input-text');
var count = 0;
// loop
fields.each(function() {
if($(this).val() != '') count++;
});
// set number of participants
var participants = 1;
// add extra elements
participants += Math.floor(count/5);
// set price
$('#event_price').html(price);
// set participants
$('#number_of_participants').html(participants);
// set total
$('#event_total').html(participants * price);
}
}
jQuery(function($){
// enable or disable fields
if($('#invoice_address').attr('checked')) enableInvoiceFields(true);
else
{
enableInvoiceFields(false);
copyToInvoice();
}
// bind click
$('#invoice_address').bind('click', function(e) {
if($('#invoice_address').attr('checked')) enableInvoiceFields(true);
else
{
enableInvoiceFields(false);
copyToInvoice();
}
});
// bind click
$('#add-another-participant').click(function(e) { addParticipant(e) });
// bind remove-links
$('.remove-participant').click(function(e) {
var id = $(this).attr('rel')
$('#'+ id).remove();
recalculatePrice();
e.preventDefault();
e.stopPropagation();
});
// bind change
$('#company').change(function(e) { copyToInvoice(); });
$('#street').change(function(e) { copyToInvoice(); });
$('#nr').change(function(e) { copyToInvoice(); });
$('#bus').change(function(e) { copyToInvoice(); });
$('#zip').change(function(e) { copyToInvoice(); });
$('#place').change(function(e) { copyToInvoice(); });
$('#country').change(function(e) { copyToInvoice(); });
$('#event').change(function(e) { recalculatePrice(e) });
$('#participants .input-text').change(function(e) { recalculatePrice(e) });
recalculatePrice();
});