$(function() {
	$('input[name=size]').click(function() {
		updatePrice();
	});
	$('#form_licence').change(function() {
		updatePrice();
	});
	$('#postcode').keyup(function() {
		updatePrice();
	});
});

swfobject.embedSWF("/swf/slideshow.swf","panel","800","184","8.0.0",null,{
	xml_path : '/xml/slideshow.xml'
},{
	menu : false
});

function updatePrice() {
	var selectedSize = $('input[name=size]:checked').val(),
		skip = skips[selectedSize],
		postcode = $('#postcode').val(),
		selectedLicence = $('#form_licence').val(),
		str;

	$('#selectedSkip').html(selectedSize.replace(' (','<br /><span>(')+'</span>');

	if (selectedSize === 'Grab and Tip Lorry') {
		$('#form_licence').val('').attr('disabled',true);
		selectedLicence = '';
	} else {
		$('#form_licence').attr('disabled',false);
	}

	if (postcode.match(/^[A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2}$/i) && selectedSize) {

		var regex = new RegExp("^("+postcodes.join('|')+")","i");
		
		if (skip === 0 || !$('#postcode').val().match(regex)) {
			str = ' POA';
		} else {
			if (selectedLicence !== '') {
				str = (skip + licences[selectedLicence]).toFixed(2);
			} else {
				str = skip.toFixed(2);
			}
		}
	} else {
		str = ' - - -';
	}
	$('#skipPrice').html('&pound;'+str);
}