// define global variables

var question=new Array("Teenagers would be better off if they tried harder to understand and utilise the experience of older people","I enjoy driving fast","Generally I manage to keep a calm appearance even though I am all upset inside","Nowadays there are too few people with enough courage to stand up for what is right","People who tend to be &#034;bossy&#034; actually lack self-confidence, although they may not realise this","I don't like it when people aren't clear about what I say and ask me to repeat","An effective leader enables people to give the best of themselves rather than seek the best for themselves","There is too much sex and violence on TV nowadays","In my opinion it is healthy to freely discuss sex, intimacy, etc.","I find it difficult to stick to a diet, stop smoking etc.","In my opinion speed limits should be strongly enforced","Parents tend to be too permissive nowadays","I believe that absolute openness and honesty with others is possible","In my opinion 95% of the important decisions are based on feelings","Too many people allow others to push them around","I seem to be quite comfortable with a long period of silence, although most people are not","I can recall situations where, as a child, older people made me feel ashamed","Sometimes children need to be smacked for their own good","We need more rather than less censorship on the television, films and magazines etc.","I seldom feel bored, impatient or lonely, even with strangers","I know that sometimes I ought to eat and drink less than I do","The good opinion of others is important to me","My parents encouraged me to explore and learn things for myself","I am uncomfortable when something unexpected happens","No-one is justified in committing suicide, even when one feels life is not worth living ","I try to attend many courses, lectures, etc.","Sometimes I tell myself &#034;Shut-up, you are talking to much&#034;","A remedy for the modem divorce situation would be to make the conditions for divorce more stringent so that marriage would be considered in a more serious light","I seldom if ever blush","Most mistakes result from misunderstanding rather than carelessness","Tense situations can make me feel so uncomfortable that I must do something about them","Most youngsters would benefit from obligatory military service","I have had to change my strong convictions many times as a result of new information","Humility is one of the virtues, perhaps the greatest one","Long hair seems to compensate for small brains nowadays","Experience is useful, but in most instances, it needs to be modified by new facts and information","Marriage between people from different races or countries can cause trouble","All work and no play add up to a dull life, and that is not the way I want to live","Sometimes I hear myself say &#034;I do not make the rules, I just follow them&#034;","You cannot change the human nature","I do not believe that there has to be a natural and irresolvable conflict between organisations and individuals","Sometimes I get so discouraged that I want to run away","Capital punishment should never be completely done away with","People should attend church more often","Most discussions carry some consequences and I like to evaluate these as closely as possible before making a decision","I am concerned about the approval of others","I like to run things; be &#034;boss of the situation&#034;, take charge","Even at social gatherings I find myself discussing business or seeking information","Being a subordinate is not that easy, but it is better than being the boss","I quickly become bored with a situation","I believe that society would be better off if the laws were more rigorously enforced","I am not ashamed of my tears when I am sad enough to cry, even when others are around","When I think people are wrong or stupid I say so","I envy people who quit their career in order to start a new life-style","I just cannot trust people like others seem to","Even though there may be a standard approach to a situation, I like to work out new ways","I put things off until they can&#039;t be put off any longer","I am inclined to be enquiring, challenging and aggressive","Most persons are capable of sustained self-direction and control","Forms of physical activity make me feel good","I get angry or disturbed with someone I think is submissive and compromising");
var answer=new Array("prnn","chld","adlt","prnn","prnn","chld","adlt","prnn","adlt","chld","prnn","prnn","adlt","chld","prnn","adlt","chld","prnn","prnn","adlt","chld","prnn","adlt","chld","prnn","adlt","chld","prnn","adlt","adlt","chld","prnc","adlt","chld","prnc","adlt","prnc","adlt","chld","prnc","adlt","chld","prnc","prnc","adlt","chld","prnc","adlt","chld","prnc","prnc","adlt","prnc","chld","prnc","adlt","chld","prnc","adlt","chld","prnc");

var counter=0;
var prnn=0;
var prnc=0;
var prnt=0;
var adlt=0;
var chld=0;

var parentPercent = 100;
var parentCriticalPercent = 100;
var parentCriticalWidth = 93;
var parentNurturingPercent = 100;
var parentNurturingWidth = 93;
var adultPercent = 100;
var childPercent = 100;

var questionTotal = question.length;

var elQuestion;
var elQuestionNumber;
var elQuestionTotal;
var elQuestionText;
var elQuestionYes;

var elParentBar;
var elAdultBar;
var elChildBar;

var elParentCriticalBar;
var elParentNurturingBar;

var elParentPercent;
var elAdultPercent;
var elChildPercent;

var elParentCriticalPercent;
var elParentNurturingPercent;

var elResult;





// find all placeholder elements on the page and hide results

function fnPrepPage() {
	elQuestion = document.getElementById("question");
	elQuestionNumber = elQuestion.getElementsByTagName("span")[0];
	elQuestionTotal = elQuestion.getElementsByTagName("span")[1];
	elQuestionText = elQuestion.getElementsByTagName("p")[0];
	elQuestionYes = elQuestion.getElementsByTagName("span")[2];

	elParentBar = document.getElementById("parentBar");
	elAdultBar = document.getElementById("adultBar");
	elChildBar = document.getElementById("childBar");

	elParentCriticalBar = document.getElementById("parentCriticalBar");
	elParentNurturingBar = document.getElementById("parentNurturingBar");

	elParentPercent = document.getElementById("parentPercent");
	elAdultPercent = document.getElementById("adultPercent");
	elChildPercent = document.getElementById("childPercent");

	elParentCriticalPercent = document.getElementById("parentCriticalPercent");
	elParentNurturingPercent = document.getElementById("parentNurturingPercent");

	elResult = document.getElementById("result");

	elQuestionTotal.innerHTML = questionTotal;

	fnAskQuestion();
}





// ask next question and set up click handling

function fnAskQuestion() {

	if (counter <= (questionTotal-1)) {

		elQuestionNumber.innerHTML = counter + 1;
		elQuestionText.innerHTML = question[counter];

		elQuestionYes.onclick = function() {
			fnAskQuestion();
			eval(answer[counter]+"++;");
		}
	counter++;
	}
	else {
		fnTallyResults();
	}
}





// hide question and populate results and graphs

function fnTallyResults() {

	prnt = prnc + prnn;
	parentCriticalPercent = Math.round(prnc / prnt * 100);
	parentNurturingPercent = 100 - parentCriticalPercent;
	parentCriticalWidth = Math.round(parentCriticalPercent * 1.86);
	parentNurturingWidth = 186 - parentCriticalWidth;

	switch (prnt) {
		case 0: parentPercent = 1;break;
		case 1: parentPercent = 1;break;
		case 2: parentPercent = 1;break;
		case 3: parentPercent = 1;break;
		case 4: parentPercent = 3;break;
		case 5: parentPercent = 5;break;
		case 6: parentPercent = 10;break;
		case 7: parentPercent = 20;break;
		case 8: parentPercent = 25;break;
		case 9: parentPercent = 32;break;
		case 10: parentPercent = 43;break;
		case 11: parentPercent = 52;break;
		case 12: parentPercent = 65;break;
		case 13: parentPercent = 77;break;
		case 14: parentPercent = 85;break;
		case 15: parentPercent = 92;break;
		case 16: parentPercent = 96;break;
		default: break;
		}

	switch (adlt) {
		case 0: adultPercent = 1;break;
		case 1: adultPercent = 1;break;
		case 2: adultPercent = 1;break;
		case 3: adultPercent = 1;break;
		case 4: adultPercent = 1;break;
		case 5: adultPercent = 1;break;
		case 6: adultPercent = 2;break;
		case 7: adultPercent = 5;break;
		case 8: adultPercent = 10;break;
		case 9: adultPercent = 20;break;
		case 10: adultPercent = 24;break;
		case 11: adultPercent = 42;break;
		case 12: adultPercent = 55;break;
		case 13: adultPercent = 72;break;
		case 14: adultPercent = 75;break;
		case 15: adultPercent = 92;break;
		case 16: adultPercent = 96;break;
		default: break;
		}

	switch (chld) {
		case 0: childPercent = 1;break;
		case 1: childPercent = 1;break;
		case 2: childPercent = 1;break;
		case 3: childPercent = 2;break;
		case 4: childPercent = 5;break;
		case 5: childPercent = 10;break;
		case 6: childPercent = 24;break;
		case 7: childPercent = 42;break;
		case 8: childPercent = 55;break;
		case 9: childPercent = 68;break;
		case 10: childPercent = 75;break;
		case 11: childPercent = 92;break;
		case 12: childPercent = 96;break;
		default: break;
		}



// toggle result descriptions
	if (parentPercent <= 40 ) {
		document.getElementById("parentLow").style.display = "block";
		}
	else if (parentPercent >= 75 ){
		document.getElementById("parentHigh").style.display = "block";
		}
	else {
		document.getElementById("parentMid").style.display = "block";
	}

	if (adultPercent <= 40 ) {
		document.getElementById("adultLow").style.display = "block";
		}
	else if (adultPercent >= 75 ){
		document.getElementById("adultHigh").style.display = "block";
		}
	else {
		document.getElementById("adultMid").style.display = "block";
	}

	if (childPercent <= 40 ) {
		document.getElementById("childLow").style.display = "block";
		}
	else if (childPercent >= 75 ){
		document.getElementById("childHigh").style.display = "block";
		}
	else {
		document.getElementById("childMid").style.display = "block";
	}

	if (parentNurturingPercent <= 40 ) {
		document.getElementById("parentCritical").style.display = "block";
		}
	else if (parentNurturingPercent >= 60 ){
		document.getElementById("parentNurturing").style.display = "block";
		}
	else {
		document.getElementById("parentEven").style.display = "block";
	}



// render the bar graphs
	elParentBar.style.height = parentPercent*2+"px";
	elAdultBar.style.height = adultPercent*2+"px";
	elChildBar.style.height = childPercent*2+"px";

	elParentCriticalBar.style.width = parentCriticalWidth+"px";
	elParentNurturingBar.style.width = parentNurturingWidth+"px";



// populate the actual figures
	elParentPercent.innerHTML = " - "+parentPercent+"%";
	elAdultPercent.innerHTML = " - "+adultPercent+"%";
	elChildPercent.innerHTML = " - "+childPercent+"%";

	elParentNurturingPercent.innerHTML = parentNurturingPercent+"%";
	elParentCriticalPercent.innerHTML = parentCriticalPercent+"%";



// switch content visibility
	elQuestion.style.display = "none";
	elResult.style.display = "block";
}
