var percentScore = 0;
var ans = "txx";
var vars = new Array();
var userName;
var textCols = 55;
var textRows = 10;
var myName = 'Dan';
var progTitle = 'Bible Quiz';
var scrip = new Array(" "," ","Genesis 4:8 tells us it was Abel.","Colossians 4:14 tells us it was Luke.","John 19:23 tells us it was Jesus.","Genesis 37:3 tells us it was Joseph.","1 Kings 4:30, 32 tells us it was Solomon.","Mark 11:12 tells us it was Jesus.","Genesis 4:17 tells us it was Cain.","Judges 15:4-5 tells us it was Samson.","1 Kings 11:1-3 tells us it was Solomon.","Genesis 25:9-10 tells us it was Abraham.","Genesis 18:6-8 tells us it was Abraham.","2 Samuel 13: tells us it was Absalom.","Ruth 4:7-9 tells us it was Boaz.","Deuteronomy 3:11 tells us it was Og.");
var ansOne = new Array("Next","Next","Cain","Paul","Jesus","Jacob","Solomon","Joseph","Cain","Paul","Job","Jacob","Abraham","David","Boaz","Enoch","Exit");
var ansTwo = new Array(" "," ","Abel","Jude","Joseph","David","David","Jesus","Goliath","Samuel","Matthew","Abraham","Lot","Saul","Lot","Og","");
var ansThree = new Array(" "," ","Goliath","Luke","Jacob","Joseph","Job","Abraham","Joshua","Samson","Solomon","Esau","Saul","Absalom","Og","Boaz","Exit");
var colors = new Array("red","tan","purple","green","silver","chartreuse","blue","pink","orange","gold","aqua","fuchsia","ivory","lightblue","magenta","navy","rosybrown","black");
var nextResponse = '\n (Click "Next" when you are ready to proceed.)';
var gradeOne = new Array(" "," ","W","W","R","W","R","W","R","W","W","W","R","W","R","W");
var gradeTwo = new Array(" "," ","R","W","W","W","W","R","W","W","W","R","W","W","W","R");
var gradeThree = new Array(" "," ","W","R","W","R","W","W","W","R","R","W","W","R","W","W");
// var c is a counter for the quest array
var c = -1;
// var endQuest will be the last question
var endQuest;
// var rtOnes number of correct responses
var rtOnes = 0;
// var progTitle (defined in inputFile)
// var fileText (defined in inputFile)
// var resizeWindow (defined in HTML file)
// var myName (defined in inputFile)
// var progTitle (defined in inputFile)
// var textCols (defined in inputFile)
// var textRows (defined in inputFile)

var windowWidth = 200;
var windowHeight = 264;

if (textCols * 9 + 100 > windowWidth)
{
 windowWidth = textCols * 9 + 100;
}
if ((((textRows + 2) * 17) + (6 * 22)) > windowHeight)
{
 windowHeight = (textRows + 2) * 17 + (6 * 22);
}
resizeWindow=false;
if (resizeWindow)
{
 window.resizeTo(windowWidth, windowHeight);
}

var tags, textToShow, thisLabel;
var programHistory = new Array();
var programHistoryLength = -1;
var backingUp = false;

function setupWindow()
{
 windowWidth = textCols * 9 + 100;
 windowHeight = 260;
 if ((textRows + 2) * 17 > windowHeight) windowHeight = (textRows + 2) * 17;
}

function Numget()
{
   endQuest='s';
   while (isNaN(endQuest))
   {
	endQuest=prompt('How many questions do you want to do? Please enter a number from 1 to 14',14);
   }
}

function programStart()
{
 document.location.replace('programrun.html');
}

function getUserName()
{
 if (myName == '')
 {
  userName = prompt('Hello, what is your name?', '');
 }
 else
 {
  userName = prompt('Hello, my name is ' + myName + '.\nWhat is your name?', '');
 }

 if ((userName == null) || (userName == '') || (userName == 'undefined'))
 {
  userName = 'friend';
 }
}
function getText()
{
return quest[c];
}
	
function resetText()
{
  document.frmRun.txtArea.value = textToShow;
}


function exit()
{
 close();
}

function right()
{
  rtOnes = ++rtOnes;
  c = --c;
  document.bgColor = "yellow";
if (c != endQuest)
  {
   textToShow = 'Congratulations, ' + userName + ', You are correct! ' + scrip[c] + nextResponse;
  } 
   c=++c;
if (c == endQuest)
 {
   c=c-2;
   c=rtOnes/c;
   c=c*100;
   c=Math.round(c);
   document.bgColor = "tan";
   endQuest=--endQuest;
   textToShow = "Congratulations " + userName + ", you are correct! \n" + scrip[endQuest] +
"\n Your Score is " + c + "%!" +
' I hope you have enjoyed my quiz. \n I would like to study the ' +
'Bible with you. \n If you are interested, you can contact me\n ' +
'by E-mail at dskaggs6404@sbcglobal.net, or by phone at \n (906) 482-8704. ' +
'My thanks to Ian Worden whose \n programming skills have made this ' +
'personalized \n interactive quiz work on the web! ' +
'This concludes the \n quiz. If you wish to try it again, ' +
'click "Next"';
rtOnes=0;
c=2;
resetText();
}
document.frmRun.elements[2].value = "Next";
document.frmRun.elements[3].value = " ";
document.frmRun.elements[4].value = " ";
document.frmRun.elements[2].name = "X";
document.frmRun.elements[3].name = "X";
document.frmRun.elements[4].name = "X";
c=--c;
resetText();
}

function wrong()
{
   c=--c;
   document.bgColor="tan";
if (c != endQuest)
 {
   textToShow = "Sorry, " + userName + ", " + scrip[c] + nextResponse;
 }
   c=++c;
if (c == endQuest)
 {
   c=c-2;
   c=rtOnes/c;
   c=c*100;
   c=Math.round(c);
   document.bgColor = "tan";
   endQuest=--endQuest;
   textToShow = "Sorry, " + userName + ", " + scrip[endQuest] + "\n Your Score is " + c + "%!" +
'\n I hope you have enjoyed my quiz. I would like to \n study ' +
'the Bible with you. If you are interested, you \n can contact me ' +
'by E-mail at dskaggs6404@sbcglobal.net,\n or by phone at (906) 482-8704. ' +
'My thanks to Ian \n Worden whose programming skills have made this ' +
'\n personalized interactive quiz work on the web! ' +
'This \n concludes the quiz. If you wish to try it again,\n ' +
'click "Next"';
rtOnes=0;
c=2;
resetText();
 }
   document.frmRun.elements[2].value = "Next";
   document.frmRun.elements[3].value = " ";
   document.frmRun.elements[4].value = " ";
   document.frmRun.elements[2].name = "X";
   document.frmRun.elements[3].name = "X";
   document.frmRun.elements[4].name = "X";
   c=--c;
   resetText();
 }

function answer(ans)
{
if (c == 1) 
{   
   Numget();
   if ((endQuest>14)||(endQuest<1)) Numget(); 
   endQuest=++endQuest;
   endQuest=++endQuest; 
}
   c = ++c;
if (ans.toUpperCase() == 'R')
 {
   right();
 }
 else if (ans.toUpperCase() == 'W')
 {
   wrong();
 }
 else if (ans.toUpperCase() == 'BACK')
 {
  backUp();
 }
 else if (ans.toUpperCase() == 'RESET')
 {
  resetText();
 }
 else if (ans.toUpperCase() == 'SAVE')
 {
  save();
 }
 else if (ans.toUpperCase() == 'EXIT')
 {
  exit();
 }
else if (ans != '')
 {
  {
   programHistoryLength = programHistoryLength + 1;
   programHistory[programHistoryLength] = ans;
  }
  backingUp = false;
  var quest = new Array("Glad to meet you, " + userName + "!" + nextResponse,"Say " + userName + ", I am so happy that you are interested in " +
"\n my Bible Quiz! This is how the quiz works. There are " +
"\n fourteen possible questions. The difficulty increases " +
"\n with the number you choose to take. The questions are " +
"\n multiple choice, so you will have a one in three " +
"\n chances of being correct. You will be told whether \n your " +
"answer is correct, and a scripture reference \n will be " +
"given." + nextResponse,"Who was the first person killed in the Bible?",userName + ", What physician was an author?","Who had a seamless coat, " + userName + "?",userName + ", What boy had a many colored coat?","What Song Composer, " + userName + ", is credited with writing 1005 songs?",userName + ", What hungry man cursed a fruitless fig tree?","Who was the first city builder, " + userName + "?","Who set fire to three hundred foxes tails, " + userName + "?",userName + ", Who had three hundred concubines?","Who was buried in a cave with his wife, " + userName + "?",userName + ", What Hebrew served a quick lunch under a tree?","Who killed his brother for humbling his sister, " + userName + "?",userName + ", Who took off his shoe to bind a contract?","Who slept on an iron bedstead over 13 feet long, " + userName + "?");

  document.bgColor = colors[c];
  textToShow=quest[c];  

document.frmRun.elements[2].value = ansOne[c];
document.frmRun.elements[3].value = ansTwo[c];
document.frmRun.elements[4].value = ansThree[c];
document.frmRun.elements[2].name = gradeOne[c];
document.frmRun.elements[3].name = gradeTwo[c];
document.frmRun.elements[4].name = gradeThree[c];
  resetText();
 }
}
