var change_order_type = function( order_type ) {
	var vr = document.getElementById( 'fs_voucher_recipient' );
	var vc = document.getElementById( 'fs_voucher_code' );
	var td = document.getElementById( 'fs_trip_date' );
	if ( order_type == 'buy_ticket' ) {
		vr.className = 'checkout hidden';
		vc.className = 'checkout hidden';
		td.className = 'checkout';
	} else if ( order_type == 'buy_voucher' ) {
		vr.className = 'checkout';
		vc.className = 'checkout hidden';
		td.className = 'checkout hidden';
	} else if ( order_type == 'redeem_voucher' ) {
		vr.className = 'checkout hidden';
		vc.className = 'checkout';
		td.className = 'checkout';
	} else {
		// ignore ...
	}
};

var change_return_customer = function( c ) {
	var p = document.getElementById( 'p_return_customer' );
	if ( c == 1 ) {
		p.className = '';
	} else {
		p.className = 'hidden';
	}
};

var change_ticket_type = function( t, p ) {
	var scit = document.getElementById( 'shoppingcart_item_title' );
	var scip = document.getElementById( 'shoppingcart_item_price' );
	var sctp = document.getElementById( 'shoppingcart_total_price' );
	scit.innerHTML = t;
	scip.innerHTML = p;
	sctp.innerHTML = p;
};

var update_account_holder = function() {
    var fn = document.getElementById( 'firstname' );
    var ln = document.getElementById( 'lastname' );
    var ah = document.getElementById( 'account_holder' );

    ah.value = fn.value + ' ' + ln.value;
};

var hideSubmitButtons = function () {
    // suboptimal, but disabling seems to not send the submit ...
    $("input[type=submit]").hide();
};

var register_customer = function( id ) {
    var email = document.getElementById( "email" ).value;
    var password = document.getElementById( "password" ).value;
    var password_confirmation = document.getElementById( "password_confirmation" ).value;
    $.post(
        '/registrierung',
        { id: id, email: email, password: password, password_confirmation: password_confirmation },
        function( data ) {
            if ( data == "ok" ) {
                alert( unescape( "Bei der n%E4chsten Buchung k%F6nnen Sie sich nun mit Ihrer Emailadresse und dem gew%E4hlten Passwort einloggen." ) );
                $("#registration_form").hide();
            } else {
                alert( 'Bei der Registrierung ist ein Fehler aufgetreten: ' + data );
            }
        }
    );
};

var change_payment_type = function( payment_type ) {
	var bd = document.getElementById( 'fs_banking_data' );
	var af = document.getElementById( 'additional_fee' );
	if ( payment_type == 'direct_debit' ) {
		bd.className = 'checkout';
	} else if ( payment_type == 'cash_on_delivery' ) {
		bd.className = 'checkout hidden';
		if ( af.value == '' || af.value == '0,00' ) {
			af.value = '4,00';
		}
	} else {
		// ignore ...
	}
};

var show_code_form = function() {
    var cf = document.getElementById( 'code_form' );
    cf.className = '';
    return false;
};

