//
// QueryString
//

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();


//
// Answer
//
function Answer_WriteHTML()
{
	document.write('<INPUT type="radio" value="' + this.id + '" name="answers"> ');
	document.write('<span  class="quizText">' + this.text + '</span><br>');
}

function Answer(aID)
{
	this.text = "New Answer";
	this.id = aID;
	this.correct = false;
	
	this.WriteHTML = Answer_WriteHTML;
}

//
// AnswerList
//

function AnswerList_NewAnswer()
{
	var a = new Answer(this.sequenceID);
	this.sequenceID++;
	this.aList[this.aList.length] = a;

	// Optional Args: text, correct
	if (arguments.length > 0)
		a.text = arguments[0];

	if (arguments.length > 1)
		a.correct = arguments[1];

	if (this.editor)
		this.editor.AnswerSectionUpdate();
		
	return a;
}

function AnswerList_Remove(id)
{
	for (var i=0;i<this.aList.length;i++)
	{
		if (this.aList[i] && this.aList[i].id == id)
		{
			this.aList[i] = null;
			break;
		}
	}
}

function AnswerList_Find(id)
{
	var result = null;
	for (var i=0;i<this.aList.length;i++)
	{
		if (this.aList[i] && this.aList[i].id == id)
		{
			result = this.aList[i];
			break;
		}
	}
	return result;
}

function AnswerList_WriteHTML()
{
	for (var i=0;i<this.aList.length;i++)
		this.aList[i].WriteHTML();
}

function AnswerList(editor)
{
	this.editor = editor;
	this.sequenceID = 0;
	this.aList = new Array();
	
	this.NewAnswer = AnswerList_NewAnswer;
	this.Remove = AnswerList_Remove;
	this.Find = AnswerList_Find;
	this.WriteHTML = AnswerList_WriteHTML;
}

//
// Question
//

function Question_NewAnswer(text,correct)
{
	this.answerList.NewAnswer(text,correct);
}

function Question_WriteHTML()
{
	document.write('<p class="quizQuestion">Q: ' + this.text + '</p>');
	this.answerList.WriteHTML();
}

function Question_GetCorrectAnswer(text,correct)
{
	var result = "";
	for (var i=0;i<this.answerList.aList.length;i++)
	{
		if (this.answerList.aList[i] && this.answerList.aList[i].correct)
		{
			result = this.answerList.aList[i].text;
			break;
		}
	}
	return result;
}

function Question(qID,editor)
{
	this.text = "New Question";
	this.id = qID;
	this.editor = editor;
		
	this.answerList = new AnswerList(editor);
	
	this.NewAnswer = Question_NewAnswer;
	this.WriteHTML = Question_WriteHTML;
	this.GetCorrectAnswer = Question_GetCorrectAnswer;
}

//
// QuestionList
//

function QuestionList_NewQuestion()
{
	var q = new Question(this.sequenceID,this.editor);
	this.sequenceID++;
	this.qList[this.qList.length] = q;
	
	// Optional Args: text
	if (arguments.length > 0)
		q.text = arguments[0];
	
	if (this.editor)
		this.editor.QuestionItemsAdd(q);
		
	return q;
}

function QuestionList_Remove(id)
{
	for (var i=0;i<this.qList.length;i++)
	{
		if (this.qList[i] && this.qList[i].id == id)
		{
			this.qList[i] = null;
			break;
		}
	}
}

function QuestionList_Find(id)
{
	var result = null;
	for (var i=0;i<this.qList.length;i++)
	{
		if (this.qList[i] && (this.qList[i].id == id))
		{
			result = this.qList[i];
			break;
		}
	}
	return result;
}

function QuestionList_WriteHTML()
{
	var index = 0;
	
	var lastQuestion = QueryString("lastQuestion");
	var ccount = QueryString("ccount");

	if (ccount == null)
		ccount = 0;
	else
		ccount = parseInt(ccount);

	document.write('<form name="quiz" method="GET" onsubmit="return QuestionListValidate(this)">');
		
	
	if (lastQuestion!=null)
	{
		lastQuestion = parseInt(lastQuestion);
		index = 1 + lastQuestion;
		var answerID = parseInt(QueryString("answers"));
		
		if (this.qList[lastQuestion].answerList.aList[answerID].correct)
		{
			document.write('<p class="quizRightWrong">Yes, that is a thyroid risk or symptom.</p>');
			ccount++;
		}
		else
		{
			var correctAnswer = this.qList[lastQuestion].GetCorrectAnswer();
			document.write('<p class="quizRightWrong">Your answer was less indicative of a thyroid risk or symptom.</p>');
			document.write('<p class="quizText">If you have a higher risk for or symptoms of thyroid disease, your answer to: </p>');
			document.write('<p class="quizIndent">' + this.qList[lastQuestion].text + '</p>');
			document.write('<p class="quizText">would be:</p>');
			document.write('<p class="quizIndent">' + correctAnswer + '</p>');
		}
		
		
	}
	
	if (index < this.qList.length)
	{
		document.write('<input type="hidden" name="lastQuestion" value="' + index + '">')
		
		this.qList[index].WriteHTML();
		document.write('<p><input type="submit" name="submit" value="Next Question >>"></p>')
	}
	else
	{
		var score = Math.round((ccount*100)/this.qList.length);
		var scoreResults = this.ScoreResults(Math.min(Math.floor(score/10),9));
		document.write('<p class="quizText">You answered ' + ccount + ' items out of ' +
			this.qList.length + ' in a way that indicates thyroid risks and symptoms.</p>');
		document.write('<p class="quizText">Your score is ' + score + '%. ' + scoreResults + '</p>');
	}
	
	document.write('<input type="hidden" name="ccount" value="' + ccount + '">')
	document.write('</form>');
	
}

function QuestionList_ScoreResults(index,text)
{
	// Optional Args: text
	if (arguments.length > 1)
	{
		this.scoreResults[index] = text;
	}
		
	return this.scoreResults[index];
}

function QuestionList(editor)
{
	this.sequenceID = 0;
	this.qList = new Array();
	this.scoreResults = new Array(10);
	this.editor = editor;
	
	this.NewQuestion = QuestionList_NewQuestion;
	this.Remove = QuestionList_Remove;
	this.Find = QuestionList_Find;
	this.WriteHTML = QuestionList_WriteHTML;
	this.ScoreResults = QuestionList_ScoreResults;
}

function QuestionListValidate(theForm)
{
	var validated = false;
	
	for (var i=0;i<theForm.answers.length;i++)
	{
		if (theForm.answers[i].checked == true)
		{
			validated = true;
			break;
		}
	}
	
	if (!validated)
		alert("Please select an answer before continuing.");
	
	return validated;
}

var gQuestionList = new QuestionList(null);

// Quiz Source Start (to edit with QuizEditor copy/paste between here and end
// -->

gQuestionList.ScoreResults(0,"You have almost no risk factors or symptoms of a thyroid condition. But remember, you can only rule out a thyroid problem after a thorough evaluation by your practitioner. For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(1,"You have very few risks and symptoms for thyroid disease. You may want to watch for more signs, however. And remember, you can only rule out a thyroid problem after a thorough evaluation by your practitioner. For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(2,"You have a handful of risks and symptoms. You'l want to talk to your doctor about a thyroid evaluation. For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(3,"You have enough risks and symptoms that you should pay attention to this, talk to your doctor . For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(4,"You have enough risks and symptoms that you probably should have your thyroid evaluated.  For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(5,"You have enough risks and symptoms that you should have your thyroid evaluated.  For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(6,"You definitely have some thyroid risk factors and symptoms. You should have this checked out fairly soon.  For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(7,"There's a good chance you have a thyroid problem. See the doctor soon. For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(8,"You have a number of thyroid risks and symptoms and should be evaluated as soon as possible. For more information, read Thyroid Hormone Breakthrough.");
gQuestionList.ScoreResults(9,"You have many risk factors and symptoms of thyroid disease. Yshould be evaluated as soon as possible. For more information, read Thyroid Hormone Breakthrough.");
q = gQuestionList.NewQuestion("Are you experiencing changes in your menstrual cycle, as in the cycle is too short or long, your periods are painful, or your period has become very heavy or very light?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have you experienced infertility or recurrent miscarriage?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
 q = gQuestionList.NewQuestion("Are you pregnant now?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have or have you recently been diagnosed with any of the following conditions? Struma Ovarii, Pituitary Adenoma, Molar Pregnancy, Choriocarcinoma, Celiac Disease/Gluten Intolerance");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have you recently had a miscarriage or terminated a pregnancy?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have you had a baby in the last 12 months?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you or did you have difficulty breastfeeding?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you now -- or have you in the past -- had bad morning sickness?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you now -- or did you -- gain excessive weight during pregnancy?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have your periods stopped, but you are not menopausal?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have a low or nonexistent sex drive?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are your perimenopause or menopause symptoms particularly debilitating?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have you been exposed to radiation, such as occurred after the Chernobyl nuclear plant accident?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you regularly consume soy foods and soy products, such as soy protein, soy capsules, soy powders?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you take iodine, a vitamin with iodine, or iodine-containing herbs, such as kelp and bladderwrack?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Have you ever had radiation treatment to the head, neck or chest, as a treatment for tonsils, adenoids, lymph nodes, thymus gland problems, or acne?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Did you ever have \"Nasal Radium Therapy,\" back in the 40s to 60s as a treatment for tonsillitis, colds and other ailments, or as a military submariner and/or pilot who had trouble with drastic changes in pressure?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you regularly eat significant amounts of uncooked \"goitrogenic\" foods, such as brussels sprouts, broccoli, rutabaga, turnips, kohlrabi, radishes, cauliflower, African cassava, millet, babassu (a palm-tree coconut fruit popular in Brazil and Africa), cabbage and kale?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you aware of any significant exposure to chemicals in your water, such as fluoride or perchlorate?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you aware of any excessive exposure you have to metals, such as mercury?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have a personal history of having thyroid disease in the past?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you now or have you in the past had another autoimmune disease?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have any immediate family members -- parents, grandparents, siblings, children -- who have thyroid conditions?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have any immediate family members -- parents, grandparents, siblings, children -- who have, or in the past have had, an autoimmune disease?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have fatigue, exhaustion, tiredness? ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you experiencing mood changes, such as depression or anxiety?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you having difficulty concentrating or remembering things?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you finding yourself particularly sensitive to hot or cold weather (i.e., wearing a sweater in the summer, or overheated in the winter?) ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you having inappropriate weight changes, as in sudden weight gain or loss, without a change in diet or exercise, or is it impossible to gain or lose weight, even when you change your diet? ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have unusual heart rhythms, such as palpitations, or a rapid or very slow heartbeat?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you losing hair in the outer part of your eyebrow?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have unusual heart rhythms, such as palpitations, or a rapid or very slow heartbeat?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are your nails brittle, breaking easily, growing slowly?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have muscle and joint pains and aches? ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you suffering from a change in your sex drive?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you suffering from constipation or diarrhea regularly?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Do you have a full or sensitive feeling in the neck, or find that neckties, collars, scarves or turtlenecks are uncomfortable?  ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Has your voice become raspy or hoarse?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you having sleep changes, i.e., insomnia, difficulty falling asleep, difficulty staying asleep, or waking up unrefreshed? ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are you experiencing nervousness, irritability, or even panic attacks?");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);
q = gQuestionList.NewQuestion("Are your eyes dry, scratchy, sensitive to light, or even having double vision, or bulging? ");
q.NewAnswer("Yes",true);
q.NewAnswer("No",false);

// <-- Quiz Source End 
