$(function(){
	
	$('div.date_select_container select').each(function(){
		$(this).change(function(){
			var objCont = $(this).parent();
			
			var date = $('select.date_select_year',objCont).val()+'-'+$('select.date_select_month',objCont).val()+'-'+$('select.date_select_day',objCont).val();
			$('input.date_select_hidden',objCont).val(date);
		});
	});
	
	$('.centerDiv').each(function(){
		centerDiv(this);
	});
	
	$('.userDelete').click(function(){
		return confirm('Are you sure you want to remove this?\n\Removing this will be permanent and cannot be undone');
	});
	
	
	if($.browser.safari){
		$('form input, form textarea, form select').css('padding','2px 0');
	}
	
	if($.browser.msie){
		$('form input').each(function(){
			if($(this).attr('type')=='radio' || $(this).attr('type')=='checkbox'){
				$(this).css('border','0');
			}
		});
	}
	
	$('#selPaymentMethod').change(function(){
		
		if($(this).val()=='card'){
			$('#card_wrap').show();
			$('#bacs_wrap').hide();
		}
		if($(this).val()=='bacs'){
			$('#card_wrap').hide();
			$('#bacs_wrap').show();
		}
		if($(this).val()=='cheque'){
			$('#card_wrap').hide();
			$('#bacs_wrap').hide();
		}
		
	});
	
	$('div.payment_date_wrap select').change(function(){
		
		objDiv = $(this).parent();
		
		$('input',objDiv).val($('select:eq(0)',objDiv).val()+'-'+$('select:eq(1)',objDiv).val());
		
	});
	
	
	$('input.chkDoB').click(function(){
		if($(this).attr('checked') == true){
			$('select',$(this).parent().parent()).attr('disabled','');
		}else{
			$('select',$(this).parent().parent()).attr('disabled','disabled').val('00');
			$('input.date_select_hidden',$(this).parent().parent()).val('0000-00-00');
		}
	});
	
	$('input.extra_input').keyup(function(){
		
		var extra_total = 0;
		
		$('input.extra_input').each(function(){
			
			var total = 0;
			
			var qty = $(this).val();
			
			if(qty==''){
				total = parseFloat(0.00);
			}else{
				if(qty > 0 && qty < 999999){
					var extra_price = parseFloat($('input.extra_hidden',$(this).parent()).val());
					total = parseFloat(roundNumber(parseInt(qty) * extra_price,2));
				}else{
					total = 0.00;
				}
			}
			
			extra_total = roundNumber(parseFloat(parseFloat(extra_total) + parseFloat(total)),2);
			
		});
		
		var book_total = parseFloat($('#total_book_cost').val());
		
		var deposit_total = parseFloat($('#deposit_cost').val());
		
		var grand_total = parseFloat(parseFloat(extra_total) + parseFloat(book_total) + parseFloat(deposit_total));
		
		$('#total_extras_span').text(roundNumber(extra_total,2));
		$('#total_due_span').text(roundNumber(grand_total,2));
		
		if($('#div3').length){
			
			var total_due_now = parseFloat(grand_total) / 3;
			
			$('#total_due_now_span').text(roundNumber(total_due_now,2));
			
		}else{
			$('#total_due_now_span').text(roundNumber(grand_total,2));
		}
		
	});
	
});


