var planningTotalApplicable = 0;
var carbonTotalApplicable = 0;
var biodiversityTotalApplicable = 0;
var livestockTotalApplicable = 0;
var heritageTotalApplicable = 0;
var visitorTotalApplicable = 0;
var minimumStandardsTotalApplicable = 0;
var enhancementStandardsTotalApplicable = 0;
var planningTotalAchieved = 0;
var carbonTotalAchieved = 0;
var heritageTotalAchieved = 0;
var biodiversityTotalAchieved = 0;
var livestockTotalAchieved = 0;
var visitorTotalAchieved = 0;
var minimumStandardsTotalAchieved = 0;
var enhancementStandardsTotalAchieved = 0;

var planningAudit = new Array();
planningAudit[0] = 1;
planningAudit[1] = 0;
planningAudit[2] = 0;
var planningMonitor = new Array();
planningMonitor[0] = 1;
planningMonitor[1] = 0;
planningMonitor[2] = 0;
var planningActions = new Array();
planningActions[0] = 1;
planningActions[1] = 0;
planningActions[2] = 0;
var planningConsult = new Array();
planningConsult[0] = 1;
planningConsult[1] = 0;
planningConsult[2] = 0;
var carbonWater = new Array();
carbonWater[0] = 1;
carbonWater[1] = 0;
carbonWater[2] = 0;
var carbonBurn = new Array();
carbonBurn[0] = 1;
carbonBurn[1] = 0;
carbonBurn[2] = 0;
var carbonPollute = new Array();
carbonPollute[0] = 1;
carbonPollute[1] = 0;
carbonPollute[2] = 0;
var biodiversityMaintain = new Array();
biodiversityMaintain[0] = 1;
biodiversityMaintain[1] = 0;
biodiversityMaintain[2] = 0;
var biodiversityHabitat = new Array();
biodiversityHabitat[0] = 1;
biodiversityHabitat[1] = 0;
biodiversityHabitat[2] = 0;
var biodiversitySpecies = new Array();
biodiversitySpecies[0] = 1;
biodiversitySpecies[1] = 0;
biodiversitySpecies[2] = 0;
var biodiversityRestructure = new Array();
biodiversityRestructure[0] = 1;
biodiversityRestructure[1] = 0;
biodiversityRestructure[2] = 0;
var biodiversityReintroduce = new Array();
biodiversityReintroduce[0] = 1;
biodiversityReintroduce[1] = 0;
biodiversityReintroduce[2] = 0;
var livestockDeer = new Array();
livestockDeer[0] = 1;
livestockDeer[1] = 0;
livestockDeer[2] = 0;
var livestockCarcass = new Array();
livestockCarcass[0] = 1;
livestockCarcass[1] = 0;
livestockCarcass[2] = 0;
var livestockImpact = new Array();
livestockImpact[0] = 1;
livestockImpact[1] = 0;
livestockImpact[2] = 0;
var heritageStaff = new Array();
heritageStaff[0] = 1;
heritageStaff[1] = 0;
heritageStaff[2] = 0;
var heritageMaintain = new Array();
heritageMaintain[0] = 1;
heritageMaintain[1] = 0;
heritageMaintain[2] = 0;
var heritageRecycle = new Array();
heritageRecycle[0] = 1;
heritageRecycle[1] = 0;
heritageRecycle[2] = 0;
var heritageCarbon = new Array();
heritageCarbon[0] = 1;
heritageCarbon[1] = 0;
heritageCarbon[2] = 0;
var heritageRenewable = new Array();
heritageRenewable[0] = 1;
heritageRenewable[1] = 0;
heritageRenewable[2] = 0;
var heritageRedundant = new Array();
heritageRedundant[0] = 1;
heritageRedundant[1] = 0;
heritageRedundant[2] = 0;
var heritageBuilding = new Array();
heritageBuilding[0] = 1;
heritageBuilding[1] = 0;
heritageBuilding[2] = 0;
var heritagePaths = new Array();
heritagePaths[0] = 1;
heritagePaths[1] = 0;
heritagePaths[2] = 0;
var visitorLocal = new Array();
visitorLocal[0] = 1;
visitorLocal[1] = 0;
visitorLocal[2] = 0;
var visitorAccess = new Array();
visitorAccess[0] = 1;
visitorAccess[1] = 0;
visitorAccess[2] = 0;
var va= new Array();
va[0] = 1;
va[1] = 0;
va[2] = 0;
var vb= new Array();
vb[0] = 1;
vb[1] = 0;
vb[2] = 0;
var vc= new Array();
vc[0] = 1;
vc[1] = 0;
vc[2] = 0;



function updatePlanningAudit(index){
	calculatePlanning(index,planningAudit.copy());
	calculateMinimumStandards(index,planningAudit);
	}
	
function updatePlanningMonitor(index){
	calculatePlanning(index,planningMonitor.copy());
	calculateMinimumStandards(index,planningMonitor);	
	}
	
function updatePlanningActions(index){
	calculatePlanning(index,planningActions.copy());
	calculateMinimumStandards(index,planningActions);		
	}
	
function updatePlanningConsult(index){
	calculatePlanning(index,planningConsult.copy());
	calculateMinimumStandards(index,planningConsult);		
	}
	
function updateCarbonWater(index){
	calculateCarbon(index,carbonWater.copy());	
	calculateMinimumStandards(index,carbonWater);
	}
	
function updateCarbonBurn(index){
	calculateCarbon(index,carbonBurn.copy());
	calculateMinimumStandards(index,carbonBurn);	
	}
function updateCarbonPollute(index){
	calculateCarbon(index,carbonPollute.copy());	
	calculateMinimumStandards(index,carbonPollute);
	}
function updateBiodiversityMaintain(index){
	calculateBiodiversity(index,biodiversityMaintain.copy());
	calculateMinimumStandards(index,biodiversityMaintain);	
	}
function updateBiodiversityHabitat(index){
	calculateBiodiversity(index,biodiversityHabitat.copy());
	calculateMinimumStandards(index,biodiversityHabitat);	
	}
function updateBiodiversitySpecies(index){
	calculateBiodiversity(index,biodiversitySpecies.copy());
	calculateMinimumStandards(index,biodiversitySpecies);	
	}
function updateBiodiversityRestructure(index){
	calculateBiodiversity(index,biodiversityRestructure.copy());	
	calculateEnhancementStandards(index,biodiversityRestructure);
	}
function updateBiodiversityReintroduce(index){
	calculateBiodiversity(index,biodiversityReintroduce.copy());
	calculateEnhancementStandards(index,biodiversityReintroduce);	
	}
function updateLivestockDeer(index){
	calculateLivestock(index,livestockDeer.copy());	
	calculateMinimumStandards(index,livestockDeer);	
	}
function updateLivestockCarcass(index){
	calculateLivestock(index,livestockCarcass.copy());
	calculateEnhancementStandards(index,livestockCarcass);	
	}
function updateLivestockImpact(index){
	calculateLivestock(index,livestockImpact.copy());	
	calculateMinimumStandards(index,livestockImpact);
	}
function updateHeritageStaff(index){
	calculateHeritage(index,heritageStaff.copy());	
	calculateMinimumStandards(index,heritageStaff);
	}
function updateHeritageMaintain(index){
	calculateHeritage(index,heritageMaintain.copy());	
	calculateMinimumStandards(index,heritageMaintain);
	
	}
function updateHeritageRecycle(index){
	calculateHeritage(index,heritageRecycle.copy());
	calculateMinimumStandards(index,heritageRecycle);	
	}
function updateHeritageCarbon(index){
	calculateHeritage(index,heritageCarbon.copy());
	calculateMinimumStandards(index,heritageCarbon);		
	}
function updateHeritageRenewable(index){
	calculateHeritage(index,heritageRenewable.copy());	
	calculateEnhancementStandards(index,heritageRenewable);
	}
function updateHeritageRedundant(index){
	calculateHeritage(index,heritageRedundant.copy());
	calculateMinimumStandards(index,heritageRedundant);		
	}
function updateHeritageBuilding(index){
	calculateHeritage(index,heritageBuilding.copy());
	calculateEnhancementStandards(index,heritageBuilding);		
	}
function updateHeritagePaths(index){
	calculateHeritage(index,heritagePaths.copy());
	calculateEnhancementStandards(index,heritagePaths);	
	}
function updateVisitorAccess(index){
	calculateVisitor(index,visitorAccess.copy());
	calculateMinimumStandards(index,visitorAccess);		
	}
function updateVisitorLocal(index){
	calculateVisitor(index,visitorLocal.copy());
	calculateMinimumStandards(index,visitorLocal);		
	}
function updateVa(index){
	calculateVisitor(index,va.copy());	
	calculateEnhancementStandards(index,va);
	}
function updateVb(index){
	calculateVisitor(index,vb.copy());
	calculateMinimumStandards(index,vb);		
	}
function updateVc(index){
	calculateVisitor(index,vc.copy());	
	calculateEnhancementStandards(index,vc);
	}


function calculatePlanning(index, stateArray){
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			planningTotalApplicable = planningTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			planningTotalApplicable = planningTotalApplicable + 1;
			planningTotalAchieved = planningTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			planningTotalApplicable = planningTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			planningTotalApplicable = planningTotalApplicable + 1;
			planningTotalAchieved = planningTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			planningTotalApplicable = planningTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			planningTotalAchieved = planningTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			planningTotalApplicable = planningTotalApplicable - 1;
			planningTotalAchieved = planningTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			planningTotalAchieved = planningTotalAchieved -1;
			
		}
	}
	
if (planningTotalApplicable > 0){
		percentageAchieved = (100/planningTotalApplicable) * planningTotalAchieved;
		document.getElementById('planningTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('planningTotal').innerHTML='N/A';
	}
	
}

function calculateCarbon(index, stateArray){
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			carbonTotalApplicable = carbonTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			carbonTotalApplicable = carbonTotalApplicable + 1;
			carbonTotalAchieved = carbonTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			carbonTotalApplicable = carbonTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			carbonTotalApplicable = carbonTotalApplicable + 1;
			carbonTotalAchieved = carbonTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			carbonTotalApplicable = carbonTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			carbonTotalAchieved = carbonTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			carbonTotalApplicable = carbonTotalApplicable - 1;
			carbonTotalAchieved = carbonTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			carbonTotalAchieved = carbonTotalAchieved -1;
			
		}
	}
	
if (carbonTotalApplicable > 0){
		percentageAchieved = (100/carbonTotalApplicable) * carbonTotalAchieved;
		document.getElementById('carbonTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('carbonTotal').innerHTML='N/A';
	}
	
}

function calculateBiodiversity(index, stateArray){
	
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			biodiversityTotalApplicable = biodiversityTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			biodiversityTotalApplicable = biodiversityTotalApplicable + 1;
			biodiversityTotalAchieved = biodiversityTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			biodiversityTotalApplicable = biodiversityTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			biodiversityTotalApplicable = biodiversityTotalApplicable + 1;
			biodiversityTotalAchieved = biodiversityTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			biodiversityTotalApplicable = biodiversityTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			biodiversityTotalAchieved = biodiversityTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			biodiversityTotalApplicable = biodiversityTotalApplicable - 1;
			biodiversityTotalAchieved = biodiversityTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			biodiversityTotalAchieved = biodiversityTotalAchieved -1;
			
		}
	}
	
if (biodiversityTotalApplicable > 0){
		percentageAchieved = (100/biodiversityTotalApplicable) * biodiversityTotalAchieved;
		document.getElementById('biodiversityTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('biodiversityTotal').innerHTML='N/A';
	}
	
}
function calculateLivestock(index, stateArray){
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			livestockTotalApplicable = livestockTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			livestockTotalApplicable = livestockTotalApplicable + 1;
			livestockTotalAchieved = livestockTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			livestockTotalApplicable = livestockTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			livestockTotalApplicable = livestockTotalApplicable + 1;
			livestockTotalAchieved = livestockTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			livestockTotalApplicable = livestockTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			livestockTotalAchieved = livestockTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			livestockTotalApplicable = livestockTotalApplicable - 1;
			livestockTotalAchieved = livestockTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			livestockTotalAchieved = livestockTotalAchieved -1;
			
		}
	}
	
if (livestockTotalApplicable > 0){
		percentageAchieved = (100/livestockTotalApplicable) * livestockTotalAchieved;
		document.getElementById('livestockTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('livestockTotal').innerHTML='N/A';
	}
	
}

function calculateHeritage(index, stateArray){
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			heritageTotalApplicable = heritageTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			heritageTotalApplicable = heritageTotalApplicable + 1;
			heritageTotalAchieved = heritageTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			heritageTotalApplicable = heritageTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			heritageTotalApplicable = heritageTotalApplicable + 1;
			heritageTotalAchieved = heritageTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			heritageTotalApplicable = heritageTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			heritageTotalAchieved = heritageTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			heritageTotalApplicable = heritageTotalApplicable - 1;
			heritageTotalAchieved = heritageTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			heritageTotalAchieved = heritageTotalAchieved -1;
			
		}
	}
	
if (heritageTotalApplicable > 0){
		percentageAchieved = (100/heritageTotalApplicable) * heritageTotalAchieved;
		document.getElementById('heritageTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('heritageTotal').innerHTML='N/A';
	}
	
}

function calculateVisitor(index, stateArray){
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			visitorTotalApplicable = visitorTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			visitorTotalApplicable = visitorTotalApplicable + 1;
			visitorTotalAchieved = visitorTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			visitorTotalApplicable = visitorTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			visitorTotalApplicable = visitorTotalApplicable + 1;
			visitorTotalAchieved = visitorTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			visitorTotalApplicable = visitorTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			visitorTotalAchieved = visitorTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			visitorTotalApplicable = visitorTotalApplicable - 1;
			visitorTotalAchieved = visitorTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			visitorTotalAchieved = visitorTotalAchieved -1;
			
		}
	}
	
if (visitorTotalApplicable > 0){
		percentageAchieved = (100/visitorTotalApplicable) * visitorTotalAchieved;
		document.getElementById('visitorTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('visitorTotal').innerHTML='N/A';
	}
	
}

function calculateMinimumStandards(index, stateArray){
	
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable + 1;
			minimumStandardsTotalAchieved = minimumStandardsTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable + 1;
			minimumStandardsTotalAchieved = minimumStandardsTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			minimumStandardsTotalAchieved = minimumStandardsTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			minimumStandardsTotalApplicable = minimumStandardsTotalApplicable - 1;
			minimumStandardsTotalAchieved = minimumStandardsTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			minimumStandardsTotalAchieved = minimumStandardsTotalAchieved -1;
			
		}
	}
	
if (minimumStandardsTotalApplicable > 0){
		percentageAchieved = (100/minimumStandardsTotalApplicable) * minimumStandardsTotalAchieved;
		document.getElementById('minimumStandardsTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('minimumStandardsTotal').innerHTML='N/A';
	}
	calculateTotalValue();
}

function calculateEnhancementStandards(index, stateArray){
	
	// check current status of the radio buttons
	var whichButtonSelected = 0;
	if (stateArray[0] == 1){
		whichButtonSelected = 1; // outwith selected 
	}
	else if (stateArray[1] == 1){
		whichButtonSelected = 2; // not achieved selected
	}
	else if (stateArray[2] == 1){
		whichButtonSelected = 3; // achieved selected
	}
	
	// now update state of array
	stateArray[0] = 0;
	stateArray[1] = 0;
	stateArray[2] = 0;
	
	stateArray[index] = 1;

	// if nothing selected then just update values
	if (whichButtonSelected == 0){
		
		if (index == 0){
			// don't do anything nothing was previously selected, and user has chosen 'outwith'
		}	
		else if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was unselected
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable + 1;
		}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now, add 1 to totalAchieved
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable + 1;
			enhancementStandardsTotalAchieved = enhancementStandardsTotalAchieved +1;
		}
	}
	else if (whichButtonSelected == 1){ // previously the button was set to outwith
			// index can't be 0 because it's a radio button and 0 (outwith) was previously selected
		 if (index == 1){
			// add 1 to totalApplicable value, as is applicable now, but don't worry about totalAchieved as previously was 'outwith'
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable + 1;
					}
		else if (index == 2){
			// add 1 to totalApplicable value, as is applicable now but wasn't before, add 1 to totalAchieved
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable + 1;
			enhancementStandardsTotalAchieved = enhancementStandardsTotalAchieved +1;
					}
	}
	else if (whichButtonSelected == 2){ // previously the button was set to not achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, leave totalAcheived alone as it wasn't previously acheived anyway
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable - 1;
			
		}// index can't be 1 as was 1 previously and is a radio button		
		else if (index == 2){
			// leave totalApplicable alone as was applicable before, but add 1 to totalAchieved as is now achieved.			
			enhancementStandardsTotalAchieved = enhancementStandardsTotalAchieved +1;
			
		}
	}
	else if (whichButtonSelected == 3){ //previously button set to achieved
		if (index == 0){
			// remove 1 from totalApplicable, as now no longer applicable, subtract 1 from totalAcheived
			enhancementStandardsTotalApplicable = enhancementStandardsTotalApplicable - 1;
			enhancementStandardsTotalAchieved = enhancementStandardsTotalAchieved -1;
					}
		else if (index == 1){
			// leave totalApplicable alone as was applicable before, but subtract 1 from totalAchieved as is not now achieved.			
			enhancementStandardsTotalAchieved = enhancementStandardsTotalAchieved -1;
			
		}
	}
	
if (enhancementStandardsTotalApplicable > 0){
		percentageAchieved = (100/enhancementStandardsTotalApplicable) * enhancementStandardsTotalAchieved;
		document.getElementById('enhancementStandardsTotal').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('enhancementStandardsTotal').innerHTML='N/A';
	}
	calculateTotalValue();
	
}

function calculateTotalValue(){
	var totalApplicable = enhancementStandardsTotalApplicable + minimumStandardsTotalApplicable;
	var totalAchieved = enhancementStandardsTotalAchieved + minimumStandardsTotalAchieved;
	if (totalApplicable > 0){
		percentageAchieved = (100/totalApplicable) * totalAchieved;
		document.getElementById('total').innerHTML=Math.ceil((percentageAchieved*100)/100) +'%';
	}
	else {
		document.getElementById('total').innerHTML='N/A';
	}
}

function display(){

alert(planningTotalApplicable);
}