
function removeInputs() {
	//Removes all the inputs within the form which are based on the method of delivery.
	
	var emailElement = document.getElementById("emailSection");
	emailElement.style.display="none";
	
	var addressElement = document.getElementById("addressSection");
	addressElement.style.display="none";
	
	var formatElement = document.getElementById("formatSection");
	formatElement.style.display="none";
}

var brochuresCount = 0;

function removeInputs2() {
	//If any brochures are selected, run checkPost
	
	//Count all the brochures selected
	var formElement = document.getElementById("dossier");
	
	for (var i = 0; i<formElement.brochures.length; i++) {
		if(formElement.brochures[i].checked) {
			brochuresCount++;
		}
	}
	
	//alert(brochuresCount);
	
	if(brochuresCount>0) {
		markPost();
	}
	
}






function checkPost(checkedElement) {
	//Displays the address section if 1 or more brochures are selected.
	
	if(checkedElement.checked) {
		brochuresCount++;
	} else {
		brochuresCount--;
	}
	
	//alert(brochuresCount);
	markPost();

}

function markPost() {
	//Decide whether to display the address section
	var addressElement = document.getElementById("addressSection");
	var postElement = document.getElementById("despatchViaPost");
	
	//alert(!addressElement.checked);
	
	if(brochuresCount>0) {
		addressElement.style.display="block";
		//postElement.checked = true;
	} else if(brochuresCount==0 && !postElement.checked) {
		addressElement.style.display="none";
		//postElement.checked = false;
	}
}


function toggleSection(elementId, checkedElement) {
	//Enables a section (based on the tick status of thisElement
	
	var thisElement = document.getElementById(elementId);
	
	//alert(elementId);
	
	if(elementId=='addressSection') {
	
		if(checkedElement.checked) {
			thisElement.style.display="block";
		} else if(brochuresCount==0) {
			thisElement.style.display="none";
		}
	
	} else if(elementId=='formatSection') {
		
		var thisDisplay = "none";
		
		if (document.getElementById("despatchViaEmail").checked) {
			thisDisplay = "block";
		}
		
		if (document.getElementById("despatchOnline").checked) {
			thisDisplay = "block";
		}
		
		thisElement.style.display=thisDisplay;
		
	}
}

window.onload = function() {
	removeInputs2();
}
