function getGlutenTotal() {
	var textID, textVal, grandTotal, gTotal;
	gTotal = 0;
	var surveyTable = document.getElementById('this-survey');
	grandTotal = document.getElementById('grandTotal');
	var answers = surveyTable.getElementsByTagName('select');
	for (var i=0; i < answers.length; i++) {
		selectID = answers[i].getAttribute("id");
		if (selectID.indexOf("q") >= 0) {
			selectVal = answers[i].options[answers[i].selectedIndex].value;				
			gTotal = gTotal + parseInt(selectVal);
		}
	}
	grandTotal.value = gTotal;
}

function recalcMedical(qID) {
	var selectID, selectVal, qTotal;
	qTotal = 0;
	var surveyTable = document.getElementById('this-survey');
	var questionTotal = document.getElementById('total_'+qID);
	var questionMoreInfo = document.getElementById('moreinfo_'+qID);
	var answers = surveyTable.getElementsByTagName('select');
	for (var i=0; i < answers.length; i++) {
		selectID = answers[i].getAttribute("id");
		if (selectID.indexOf(qID + "_") >= 0) {
			selectVal = answers[i].options[answers[i].selectedIndex].value;				
			qTotal = qTotal + parseInt(selectVal);
		}
	}
	questionTotal.value = qTotal;
	if (qTotal > 3) {
		questionMoreInfo.style.display = '';
	} else {
		questionMoreInfo.style.display = 'none';
	}
	
	getMedicalTotal();
}

function getMedicalTotal() {
	var textID, textVal, grandTotal, gTotal;
	gTotal = 0;
	var surveyTable = document.getElementById('this-survey');
	grandTotal = document.getElementById('grandTotal');
	var totals = surveyTable.getElementsByTagName('input');
	for (var i=0; i < totals.length; i++) {
		textID = totals[i].getAttribute("id");
		if (textID.indexOf("total_") >= 0) {
			textVal = totals[i].value;				
			gTotal = gTotal + parseInt(textVal);
		}
	}
	grandTotal.value = gTotal;
}

function getStressTotal() {
	var selectID, selectVal, grandTotal, gTotal;
	var feelingGood, stressSolutions;
	feelingGood = document.getElementById('resultsFeelingGood');
	stressSolutions = document.getElementById('resultsStressSolutions');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	grandTotal = document.getElementById('grandTotal');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		if (selectID.indexOf("q_") >= 0) {
			selectVal = questions[i].options[questions[i].selectedIndex].value;	
			if (selectVal == 'Yes') {			
				gTotal = gTotal + 1;
			}
		}
	}
	grandTotal.value = gTotal;
	if (gTotal >= 4) {
		//feelingGood.style.display = 'none';
		//stressSolutions.style.display = '';	
	} else {
		//feelingGood.style.display = '';
		//stressSolutions.style.display = 'none';	
	}
}

function getInsulinTotal() {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getHormoneTotal() {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getLeakyGutTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal != '') {
			gTotal = gTotal + parseInt(selectVal);
		}
	}
	thisTotal.value = gTotal;
}

function getToxicOverloadTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getAdultParasiteTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total');
	gTotal = 0;
	var survey = document.getElementById('this-survey');
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getAdultDentalTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total'+surveyID);
	gTotal = 0;
	var survey = document.getElementById('this-survey' + surveyID);
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getChildDentalTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total'+surveyID);
	gTotal = 0;
	var survey = document.getElementById('this-survey' + surveyID);
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function getChildParasiteTotal(surveyID) {
	var selectID, selectVal, gTotal;
	var thisTotal = document.getElementById('total'+surveyID);
	gTotal = 0;
	var survey = document.getElementById('this-survey' + surveyID);
	var questions = survey.getElementsByTagName('select');
	for (var i=0; i < questions.length; i++) {
		selectID = questions[i].getAttribute("id");
		selectVal = questions[i].options[questions[i].selectedIndex].value;	
		if (selectVal == 'Yes') {			
			gTotal = gTotal + 1;
		}
	}
	thisTotal.value = gTotal;
}

function calcHipWaist() {
	var waist, hips, total, displayValue;
	waist = document.getElementById('waist');
	hips = document.getElementById('hips');
	total = document.getElementById('total');
	
	displayValue = waist.value / hips.value;
	
	if (!isNaN(displayValue) && displayValue != 'Infinity') {
		total.value = Math.round(displayValue * 100) / 100; 
	} else {
		total.value = '';
	}
}