var n=0
var score=0
var questionasked=false
var name=""
var email=""

var questions=new Array()
questions[0]=new question("1. When do you feel your best?\n\n\A) in the morning\nB) during the afternoon & early evening\nC) late at night",2,4,6,0,0,0)
questions[1]=new question("2. You usually walk\n\nA) fairly fast, with long steps\nB) fairly fast, with short, quick steps\nC) less fast head up, looking the world in the face\nD) less fast, head down\nE) very slowly",6,4,7,2,1,0)
questions[2]=new question("3. When talking to people you\n\nA) stand with your arms folded\nB) have your hands clasped\nC) have one or both your hands on your hips\nD) touch or push the person to whom you are talking\nE) play with your ear, touch your chin, or smooth your hair",4,2,5,7,6,0)
questions[3]=new question("4. When relaxing, you sit with\n\nA) your knees bent with your legs neatly side by side \nB) your legs crossed \nC) your legs stretched out or straight \nD) one leg curled under you",4,6,2,1,0,0)
questions[4]=new question("5. When something really amuses you, you react with\n\nA) a big, appreciative laugh\nB) a laugh, but not a loud one\nC) a quiet chuckle!\nD) a sheepish smile",6,4,3,2,0,0)
questions[5]=new question("6. When you go to a party or social gathering you\n\nA) make a loud entrance so everyone notices you\nB) make a quiet entrance, looking around for someone you know \nC) make the quietest entrance, trying to stay unnoticed",6,4,2,0,0,0)
questions[6]=new question("7. You're working very hard, concentrating hard, and you're interrupted. Do you\n\nA) welcome the break\nB) feel extremely irritated \nC) vary between these two extremes",6,2,4,0,0,0)
questions[7]=new question("8. Which of the following colors do you like most?\n\nA) red or orange \nB) black \nC) yellow or light blue\nD) green \nE) dark blue or purple \nF) white",6,7,5,4,3,2)
questions[8]=new question("9. When you are in bed at night, in those last few moments before going to sleep, you lie\n\nA) stretched out on your back \nB) stretched out face down on your stomach \nC) on your side, slightly curled \nD) with your head on one arm \nE) with your head under the covers ",7,6,4,2,1,0)
questions[9]=new question("10. You often dream that you are\n\nA) falling \nB) fighting or struggling\nC) searching for something or somebody \nD) flying or floating \nE) you usually have dreamless sleep \nF) your dreams are always pleasant",4,2,3,5,6,1)

result=new Array(5)
result[0]= "EVALUATION:\nUNDER 21 POINTS\nPeople think you are shy, nervous, and indecisive, someone who needs\nlooking after, who always wants someone else to make the decisions &\nwho doesn't want to get in involved with anyone or anything. They\nsee you as a worrier who always sees problems that don't exist. Some\npeople think you're boring. Only those who know you well know that\nyou aren't." 
result[1]= "EVALUATION:\n21 TO 30 POINTS\nYour friends see you as painstaking and fussy. They see you as very\ncautious, extremely careful, a slow and steady plodder. It'd really\nsurprise them if you ever did something impulsively or on the spur of\nthe moment, expecting you to examine everything carefully from every\nangle and then, usually decide against it. They think this reaction\nis caused partly by your careful nature." 
result[2]= "EVALUATION:\n31 TO 40 POINTS\nOthers see you as sensible, cautious, careful & practical. They see\nyou as clever, gifted, or talented, but modest..! Not a person who\nmakes friends too quickly or easily, but someone who's extremely\nloyal to friends you do make and who expect the same loyalty in\nreturn. Those who really get to know you realize it takes a lot to\nshake your trust in your friends, but equally that it takes you a\nlong time to get over it if that trust is ever broken."
result[3]= "EVALUATION:\n41 TO 50 POINTS\nOthers see you as fresh, lively, charming, amusing, practical, and\nalways interesting; someone who's constantly in the center of\nattention, but sufficiently well-balanced not to let it go to their\nhead. They also see you as kind, considerate, and understanding;\nsomeone who'll always cheer them up and help them out." 
result[4]= "EVALUATION:\n51 TO 60 POINTS\nOthers see you as an exciting, highly volatile, rather impulsive\npersonality; a natural leader, who's quick to make decisions, though\nnot always the right ones. They see you as bold and adventuresome,\nsomeone who will try anything once; someone who takes chances and\nenjoys an adventure. They enjoy being in your company because of the\nexcitement you radiate."
result[5]= "EVALUATION:\nOVER 60 POINTS\nOthers see you as someone they should 'handle with care'. You're\nseen as vain, self-centered, and who is extremely dominant. Others\nmay admire you, wishing they could be more like you, but don't always\ntrusty ou, hesitating to become too deeply involved with you." 

shortresult=new Array(5)
shortresult[0]= "People think I am shy, nervous, and indecisive, someone who needs looking after!"
shortresult[1]= "Your friends see you as painstaking and fussy!"
shortresult[2]= "Others see me as sensible, cautious, careful & practical!"
shortresult[3]= "Others see me as fresh, lively, charming, amusing, practical!"
shortresult[4]= "Others see me as an exciting, highly volatile, rather impulsive!"
shortresult[5]= "Others see me as someone they should 'handle with care'!."

function boxclear(){
document.test.text.value="";
document.result.score.value="";
name=""
email=""
n=0;
score=0;
questionasked=false;
}

function go(){
boxclear();
name=prompt("Welcome to the Personality Test. Please enter your full name","");
if (name=="" || name==null) go();
nextquestion();
}

function question(texto,scorea,scoreb,scorec,scored,scoree,scoref){
this.text=texto;
this.scorea=scorea;
this.scoreb=scoreb;
this.scorec=scorec;
this.scored=scored;
this.scoree=scoree;
this.scoref=scoref;
}

function nextquestion(){
document.test.text.value=questions[n].text;
questionasked=true;
}

function done(){
if (score <21)i=0;
if (score >=21 && score <31)i=1;
if (score >=31 && score <41)i=2;
if (score >=41 && score <51)i=3;
if (score >=51 && score <61)i=4;
if (score >=61)i=5;
index=i
document.result.score.value='Total for '+name+' = '+score
document.test.text.value=result[index];
alert("CONGRATULATIONS! YOU HAVE COMPLETED THE TEST - \n\n\tYOUR TOTAL SCORE WAS "+score);
}

function response(selection){
if (questionasked){
oldscore=score;
s=questions[n];
if (selection=="a")score=score+s.scorea;
if (selection=="b")score=score+s.scoreb;
if (selection=="c")score=score+s.scorec;
if (selection=="d")score=score+s.scored;
if (selection=="e")score=score+s.scoree;
if (selection=="f")score=score+s.scoref;
if (score==oldscore){
alert('Please chose a valid response option');
}else{
questionasked=false;
if (n==9){
done();
}else{
document.result.score.value=score;
n++;
nextquestion();
}
}
}
}

function mail(){
if (n!=9){
alert("Please complete the test first");
}else{
address=prompt("Enter the your friend's Email address","");
if (address==null || address.indexOf(" ")>0 || address.indexOf("@")<0 || address.indexOf(".")<0){
   alert("Please check Email address");
   mail();
}else{
email='mailto:'+address+'?subject=Personality Test'
email+='&body=Hi%0D%0A%0D%0ATry this Personality Test at http://www.begent.freeserve.co.uk/persontest.htm'
email+='%0D%0A%0D%0AMy score was '+score+' and it said%0D%0A"'+shortresult[index]
email+='"%0D%0A%0D%0ALet me know how you get on.'
email+='%0D%0A%0D%0AFrom '+name 
parent.location.href=email
}
}
}