$(function(){
	$('#nav li:last').css('border-bottom','1px solid #fff');
	
	$('td.fees_cell input').click(function(){
		
		var total_cost = 0;
		
		var fee_type = $(this).attr('class').replace('radio_input fee_input_','');
		
		$('input.fee_input_'+fee_type).each(function(){
			if($(this).attr('checked')==true){
				
				var id = $(this).attr('id').replace('chkFee','');
				
				var cost = $('#feePrice'+id).html().replace('&pound;','').replace('£','').replace(',','');
				
				total_cost += parseFloat(cost);
			}
		});
		
		$('#fee_total_'+fee_type).val(total_cost);
		
		calculateTotal();
		
	});
	
	$('#cc_type').change(function(){
		calculateTotal();
	});
	
	
	if($.browser.msie && $.browser.version < 7){
		$('#sidebar_bg').css('position','absolute');
		
		var wHeight = $(window).height();
		var dHeight = $(document).height();
		
		if(dHeight > wHeight){
			$('#sidebar_bg').height(dHeight);
		}
	}
});

function calculateTotal(){
	
	var cc_fee;
	var reg_fee = 0;
	
	$('input.fee_total').each(function(){
		if($(this).val() != undefined && $(this).val() != ''){
			reg_fee += parseFloat($(this).val());
		}
	});
	
	if($('#cc_type').val() != 'Debit Card' && $('#cc_type').val() != ''){
		cc_total = parseFloat(reg_fee*0.02);
		cc_total = Math.round(cc_total*100)/100;
		$('#cc_fee').val(cc_total);
	}else{
		$('#cc_fee').val('');
	}
	
	if($('#cc_fee').val() != undefined && $('#cc_fee').val() != ''){
		cc_fee = parseFloat($('#cc_fee').val());
	}else{
		cc_fee = 0;
	}
	
	var total = parseFloat(reg_fee+cc_fee);
	
	//alert(total+' '+meeting_fee+' '+del_total+' '+cc_fee);
	
	$('#total').val(total);
}
