function editType()
{
	if( $( "select[name='groep_of_prive']" ).val() == "Groep" )
	{
		$( "#groupselected" ).slideDown();
	}
	else
	{
		$( "#groupselected" ).slideUp();
	}
}

$( function() 
{
	$( "#paymethod input" ).change( function() 
	{
		if( $( "#paymethod input[name='method']:checked" ).val() == 1 )
		{
			$( "#bank" ).slideDown();
		}
		else
		{
			$( "#bank" ).slideUp();
		}
	} );

	$( "select[name='groep_of_prive']" ).change( editType ).keypress( editType );

	$( "#aanmeld_formulier form" ).validate( { meta: "validate" } );

	$( "#aanmelden, #informatie .aanmelden" ).fancybox( {
		opacity:		true,
		width:			920,
		height:			500,
		scrolling:		'auto',
		titleShow:		false,
		autoDimensions:	false,
		onComplete:		function()
		{
			$( '#fancybox-wrap' ).css( 'top', 120 );
			$( '#fancybox-bg-n' ).attr( 'id', 'fancybox-bg-n_aanmelden' );
		}
	} );

	$( '#aanmeld_formulier form' ).submit( function() 
	{
		if( $( this ).find( 'input[name="voorwaarden"]' ).is( ':checked' ) == false )
		{
			alert( "Lees eerst de voorwaarden en ga hiermee akkoord." );
			return false;
		}

		if( $( "#aanmeld_formulier form" ).valid() )
		{
			$.fancybox.showActivity();
		
			$.ajax( {
				type:		'POST',
				cache:		false,
				url:		'http://www.hbocolleges.nl/v1/index.php',
				data:		$( this ).serializeArray(),
				success:	function( data )
				{
					if( data != 'false' )
					{
						$( '#aanmeld_formulier form input[type="text"], #aanmeld_formulier form textarea' ).val( '' );

						$.fancybox( '<div id="success" style="width: 920px;">Uw aanmelding is verzonden. Er zal spoedig met u contact opgenomen worden. Wanneer u voor een groepsles gekozen heeft en uw heeft aangegeven via iDeal te willen betalen zult u doorverwezen worden.</div>' );
						$.fancybox.resize();

						if( data != 'true' )
						{
							window.location = data;
						}
					}

					$.fancybox.hideActivity();
				}
			} );
		}

		return false;
	} );

	$( "#contact_formulier form" ).validate( { meta: "validate" } );

	$( "#contact, #studiepartners" ).fancybox( {
		opacity:		true,
		width:			500,
		height:			'auto',
		scrolling:		'no',
		titleShow:		false,
		onComplete:		function()
		{
			$( '#fancybox-bg-n' ).attr( 'id', 'fancybox-bg-n_contact' );
		}
	} );

	$( '#contact_formulier form' ).submit( function() 
	{
		if( $( "#contact_formulier form" ).valid() )
		{
			$.fancybox.showActivity();
		
			$.ajax( {
				type:		'POST',
				cache:		false,
				url:		'http://www.hbocolleges.nl/v1/index.php',
				data:		$( this ).serializeArray(),
				success:	function( data )
				{
					if( data == 'true' )
					{
						$( '#contact_formulier form input[type="text"], #contact_formulier form textarea' ).val( '' );
						$.fancybox( '<div style="width: 400px;">Het formulier is verzonden. Er zal spoedig met u contact opgenomen worden.</div>' );
						$.fancybox.resize();
					}

					$.fancybox.hideActivity();
				}
			} );
		}

		return false;
	} );
} );
