$(document).ready(function() {

	if($('#billing_details').css('display') == 'none') {
		$('input.forward').each(function(){
			if ($(this).val() == 'Laskuta tilaus') {
				$(this).css('display', 'none');
			}
		});
	}

	$('#delivery_billing_differ').click(function() {
		if ( $('#delivery_billing_differ').prop('checked') == true) {
			$("input[id^='billing_']").each(function () {
				if ($(this).prop('id') != 'billing_customer_reference') {
					$(this).parent().prev('td').text('*');
				}
			});
		}
	});


	$('.forward.continue').click(function() {
		if ( $('#delivery_billing_differ').prop('checked') == true) {
			var missing = '';
			$("input[id^='billing_']").each(function () {
				if ($(this).prop('id') != 'billing_customer_reference') {
					if ($(this).val() == '') {
						missing += '- ' + $(this).parent().prev('td').prev('td').text() + '\n';
					}
				}
			});
			if (missing) {
				alert("Lomakkeen tietoja ei lähetetty. Maksutiedot-osiosta puuttuu kentät:\n" + missing);
				return false;
			}
		}
	});
	
	if($('#billing_details').css('display') == 'none') {
		$('input.forward').each(function(){
			if ($(this).val() == 'Laskuta tilaus') {
				$(this).css('display', 'none');				
			}
		});
	}
})


