/*	
	Format the site search
*/


$(document).ready(function(){
	
	$contactDetailsOpen = '<h2 id="contactDetails">Contact Details</h2>';
	$securityOpen = '<h2 id="security">Security</h2><p>This information will allow you to access the members area on the website.</p>';
	$medicalConditionsOpen = '<h2 id="medical">Medical Conditions</h2><p>In the event that you sustain an injury or need medical attention whilst playing rugby we ask that you complete the below so that we can ensure any pre-existing medical conditions are known.</p>';
	$occupationOpen = '<h2 id="occupation">Occupation</h2><p>If you would like your occupational details to be searchable by other members of the club for the purpose of obtaining work, please complete the fields below.</p>';
	$juniorsOpen = '<h2 id="juniors">Junior/Mini Player Details</h2><p>Please update your children\'s details below<br /><br /><strong>Photo Consent:</strong> Do you give Alton RFC Ltd permission to publish photographs of your children in Club publicity or press articles.</p>';
	$formSecurityOpen = '<h2 id="security">Form Security</h2><p>Please answer the security question below.</p>';
	$formConsent = '<h2 id="consent">Member confirmation</h2><p>I confirm that I have read, understood and completed the above form to the best of my knowledge</p>';
	
	$parenConsent = '<div class="paraFormRow"><p><strong>Medical Consent:</strong>  Do you  give permission for officials of Alton RFC Ltd to seek medical assistance in the event that you or your child/children are injured whilst playing rugby or training.</p></div>';
	
	$("#ctrl_title").parents(".formRow").before($contactDetailsOpen);
	$(".memTitle").parents(".formRow").before($contactDetailsOpen);
	$(".mod_personalData #ctrl_password").parents(".formRow").before($securityOpen);
	
	$("#ctrl_parentConsent").parents(".formRow").before($parenConsent);
	$("#ctrl_allergies").parents(".formRow").before($medicalConditionsOpen);

	$("#ctrl_password").siblings().append(' (min 8 characters long)');
	
	$("#ctrl_custOccName").parents(".formRow").before($occupationOpen);
	
	$('.mod_personalData .formActions').before('<h2 id="consent">Member confirmation</h2><p>I confirm that I have read, understood and completed the above form to the best of my knowledge</p>');
	//$("#ctrl_consent").parents(".formRow").before($formConsent);
	$('.mod_personalData .formActions').before($("#ctrl_consent").parents(".formRow"));
	$(".memPhoto").parents(".formRow").before($juniorsOpen);
	$("#ctrl_cldOneFirstname").parents(".formRow").before('<h3>First child</h3>');
	$(".memChildOne").parents(".formRow").before('<h3>First child</h3>');
	$("#ctrl_cldTwoFirstname").parents(".formRow").before('<h3>Second child</h3>');
	$(".memChildTwo").parents(".formRow").before('<h3>Second child</h3>');
	$("#ctrl_cldThreeFirstname").parents(".formRow").before('<h3>Third child</h3>');
	$(".memChildThree").parents(".formRow").before('<h3>Third child</h3>');
	$("#ctrl_registration").parents(".formRow").before($formSecurityOpen);

	$(".junior-1").prepend('<h3>First child</h3>');
	$(".junior-2").prepend('<h3>Second child</h3>');
	$(".junior-3").prepend('<h3>Third child</h3>');
	
	$("#allFees a").click(function() {
		var total;
		subTotal = $("#amount").val();
		total = parseInt(subTotal) + 70;
		$("#amount").val(total);
		return false;
	})
	
	
	$(".blank").hide();
	//$(".junior-1").removeClass('blank').show();
	$blankCount = $(".blank").length;
	if ($blankCount > 0) {
		$blankCounter = 0;
		//$(".junior-3.blank").after('<p class="addChild"><a class="textButton" href="#">Add a child</a></p>');
		
		//$(".junior-3.blank").after('<p class="addChild"><a class="textButton" href="#">Add a child</a></p>');
		$childTotal=$(".childTotal").val();
		if(!$childTotal){
			//alert($childTotal);
			$("#ctrl_photoConsent").parents(".formRow").hide();
			$("#juniors").hide();
		}
		else{
			$("#ctrl_photoConsent").parents(".formRow").before($juniorsOpen);
		}
		
		$(".addChild a").click(function() {
			if($blankCounter == 1){
				//alert($blankCounter);
				//$(".junior-3.blank").after('<p class="removeChild">Remove child</p>');
			}
			$(".blank:eq("+($blankCounter)+")").slideDown();
			$blankCounter++;
			if($blankCounter==$blankCount) {
				$(this).fadeOut();
			}
			return false;
		});
		
		
	}


});