	$(document).ready(function() {
		$('.secondform').addClass('greyed');
		$('#secondformsubmit').attr("disabled", true);

		$('.secondform').addClass('greyed');
		$('.secondform').attr("disabled", true);
		$('.secondform input').attr("disabled", true);
		$('#youtubeform input').attr("disabled", true);
		
		$("#firstformsubmit").bind("click", function(e){
			//first form disable
			$('.firstform').addClass('greyed');
			$('.firstform').attr("disabled", true);
			$('.firstform select').attr("disabled", true);

			$('.firstform .checkbox').attr("disabled", true);
			$('.firstform .radio').attr("disabled", true);
			$('.firstform .textfield').attr("disabled", true);
			$('#youtubeform input').attr("disabled", false);

			//second form enable
			$('.secondform').removeClass('greyed');
			$('.secondform').attr("disabled", false);
			$('.secondform input').attr("disabled", false);

		});
		$("#secondformsubmit").bind("click", function(e){
			$('.secondform').addClass('greyed');
			$('.secondform').attr("disabled", true);
			
			//third form enable
			$('.secondform').removeClass('greyed');
			$('.secondform').attr("disabled", false);
			$('.secondform input').attr("disabled", false);
		});

		$("#secondformsubmit").bind("click", function(e){
			
				var firstname =        $('.firstform input[name=firstname]').val();
				var lastname =         $('.firstform input[name=lastname]').val();
				var emailaddr =        $('.firstform input[name=emailaddr]').val();
				var emailaddr2 =       $('.firstform input[name=emailaddr2]').val();
				var gender =           $('.firstform input[name=gender]:checked').val();

				var dayofbirth   =     $("select[name=dayofbirth]").val(); 
				var monthofbirth =     $("select[name=monthofbirth]").val(); 
				var yearofbirth  =     $("select[name=yearofbirth]").val(); 

				var country      =     $("select[name=country]").val();

				var marketingconsent = $("input[name=marketingconsent]:checked").val();
				var parentconsent =    $("input[name=parentconsent]:checked").val();


				$.post("index.php", { 
					firstname: firstname,
					lastname: lastname,
					emailaddr: emailaddr,
					emailaddr2: emailaddr2,
					gender: gender,
					dayofbirth: dayofbirth,
					monthofbirth: monthofbirth,
					yearofbirth: yearofbirth,
					country: country,
					marketingconsent: marketingconsent,
					parentconsent: parentconsent
					}, function(data) { 
						obj = eval('(' + data + ')');
						if (obj.status=='-1') {
							//form contained errors
							$('#errors').html(obj.msg);
							$('html, body').animate({scrollTop:400}, 'fast');

							$('.firstform select').attr("disabled", false);
							$('.firstform .checkbox').attr("disabled", false);
							$('.firstform .radio').attr("disabled", false);
							$('.firstform .textfield').attr("disabled", false);

							$('.firstform').removeClass('greyed');
							$('.firstform').attr("disabled", false);
							$('.firstform input').attr("disabled", false);
							$('.secondform').removeClass('greyed');
							$('.secondform').attr("disabled", false);
							$('.secondform input').attr("disabled", false);
							$('.thirdform').removeClass('greyed');
							$('.thirdform').attr("disabled", false);
							$('.thirdform input').attr("disabled", false);
						}
						else { 
							//form was ok
							$("#youtubeform").submit();
						}
							
						});
		});
		
});
