$(document).ready( function() {
	
	$('#producten input').click( function(){
		totalPrice();
	});
	
	$('#naam2').blur( function() {	
		persoon2();
		if( $('#adres2').attr('disabled') == false )
		{
			$('#adres2').focus();
		}
	});
	
	
	$("input[name='keuze']").click( function() {				 
			checkReqOrg();
	});
	$("input[name='keuze2']").click( function() {				 
			checkReqOrg();
	});
	
	checkReqOrg();
	
	persoon2();
	
});

function checkReqOrg()
{
	var k1 = $("input[name='keuze']:checked").val();
	var k2 = $("input[name='keuze2']:checked").val();
	
	if( k1 == 'vertegenwoordiger' || k1 == 'Representative of a VPE church' || k2 == 'vertegenwoordiger' || k2 == 'Representative of a VPE church' || k1 == 'anders' || k1 == 'Other' || k2 == 'anders' || k2 == 'Other' )
	{
		$('#reqOrg').css('display', 'inline');
	}
	else
	{
		$('#reqOrg').css('display', 'none');
	}	
}

function totalPrice() {
	var total = 0;
	var surcharge = 0;
	
	$('#producten input').each( function(){ 
		if( $(this).attr('checked') )
		{
			myPriceTag = '#price'+$(this).attr('id');
			myPrice = parseFloat(  $(myPriceTag).html() );
			total = total + myPrice;
			
			if($('#naam2').attr('value') == '')
			{
				mySurchargeTag = '#surcharge1'+$(this).attr('id');
				mySurcharge = parseFloat(  $(mySurchargeTag).attr('value') );
				if(mySurcharge > 0)
				{
					surcharge = surcharge + mySurcharge;
					total = total + mySurcharge;
				}
			}
		}
	});
	
	if( $('#naam2').attr('value') != '' )
	{
		total = total * 2;
	}
	
	var totaaltekst = 'EUR '+total.toFixed(2);
	
	if(surcharge > 0)
	{
		if( $('#formlang').attr('value') == 'en' )
		{
			totaaltekst = totaaltekst + ' including EUR '+surcharge.toFixed(2)+' for a single hotel room';
		}
		else
		{
			totaaltekst = totaaltekst + ' inclusief EUR '+surcharge.toFixed(2)+' toeslag voor gebruik hotelkamer door 1 persoon';
		}
	}
	
	$('#totaal').html(totaaltekst);
}

function persoon2() {
	if( $('#naam2').attr('value') == '' )
	{
		$('#persoon2 input').attr('disabled', true);
		$('#persoon2 textarea').attr('disabled', true);
		$('#naam2').attr('disabled', false);
	}
	else
	{
		$('#persoon2 input').attr('disabled', false);
		$('#persoon2 textarea').attr('disabled', false);
	}
	
	totalPrice();
}
