/* global Variables */
var activity_page = 0;
var secret = false;
var help_counter = 0;
var current_activity = false;
var current_vocab = false;
var temp_vocab = new Array();
var current_vocab_list = new Array();
var written;
var can_continue;


function main_interface()
{
 if(current_activity === false)
  {
   if(!written)
    {
    write_activity();
    written = 1;
    return;
    }
   pick_activity();
   written = 0;
  }

 if(!current_vocab && activity.vocab[current_activity])
  {
  current_vocab = activity.vocab[current_activity];
  make_active_list();
  }

 while((current_vocab === false || current_vocab_list.length < 1) && activity.vocab[current_activity] != "none")
  {
  if(!written)
   {
   if(current_vocab_list.length < 1 && current_vocab)
   write_vocab(true);
   else
   write_vocab(false);
   written = 1;
   return;
   }
  pick_vocab();
  make_active_list();
  written = 0;
  }

 if(can_continue && !secret)
  {
  activity_page++;
  can_continue = 0;
  help_counter = 0;
  }

 if(secret)
  activity_page++;


 if(!(current_activity === false) && !(current_vocab === false))
  {
  if(activity_page < current_vocab_list.length || current_vocab == "none")
   {
   activity.function_run[current_activity]();
   }
  else
   done();
  }
}


function help_check()
{
if(!(current_activity === false) && !(current_vocab === false) && current_vocab_list.length > 0)
{
if(activity.function_help[current_activity] && help_counter > 4)
activity.function_help[current_activity]();
}
}


function make_active_list()
{
temp_2 = 0;
for(temp = 0; temp < word.vocab.length; temp++)
{
if(word.vocab[temp] == current_vocab && (word.activity[temp].search(activity.definition[current_activity]) + 1) > 0)
{
current_vocab_list[temp_2] = temp;
temp_2++;
}
}
}


function write_activity()
{
parent.frames[1].document.open();
parent.frames[1].document.write("<html><head></head><body></body></html>");
parent.frames[1].document.write("<form name='select_activity'><P align=center><FONT face=Verdana size=4>Please Choose An Activity:</FONT><BR></P>");
parent.frames[1].document.write("<hr align='CENTER' size='1' width='90%' color='Gray'>");
parent.frames[1].document.write("<CENTER><SELECT name='activity' size='1'>");
for (temp = 0; temp < activity.name.length; temp++)
{
parent.frames[1].document.write("<OPTION value='none'>" + format_print(activity.name[temp]));
}
parent.frames[1].document.write("</SELECT></form></CENTER>");
parent.frames[1].document.write("</body></html>");
parent.frames[1].document.close();
}

function pick_activity(pick_again)
{
for (temp = 0; temp < activity.name.length; temp++)
{
if(parent.frames[1].document.select_activity.activity[temp].selected)
current_activity = temp;
}
}

function write_vocab(pick_again)
{
// enter array of different vocab words into temp_vocab[]
parent.frames[1].document.open();
parent.frames[1].document.write("<P align='center'><font face='times' size='4' color='navy'><BR><BR>Please wait a moment - building vocabulary database.<BR><blink>(-)</blink></font>");
parent.frames[1].document.close();
var equal;
for (temp = 0; word.vocab[temp]; temp++)
{
equal = true;
for (counter = 0; temp_vocab[counter]; counter++)
{
if(word.vocab[temp] == temp_vocab[counter])
equal = false;
}
if (equal == true)
{
temp_vocab[temp_vocab.length] = word.vocab[temp]
}
}
/*------------------------------------------------*/

parent.frames[1].document.open();
if(pick_again)
parent.frames[1].document.write("<form name = 'select_vocab'><P align=center><FONT face=Verdana size=2 color='red'>There are no vocabulary words in the activity/vocabulary catagory you selected!</FONT><BR>");
else
parent.frames[1].document.write("<form name = 'select_vocab'><P align=center>");
parent.frames[1].document.write("<FONT face=Verdana size=4>Please Choose A Vocabulary Group:</FONT></P>");
parent.frames[1].document.write("<table width = '80%' border='0' cellspacing = '0' cellpadding = '5'>");
var rows = Math.ceil(temp_vocab.length/4);
var temp_text;
for(row = 0; row < rows; row++)
{
parent.frames[1].document.write("<tr>");
for(column = 0; column < 4; column++)
{
temp_text = temp_vocab[(row * 4)+column];
if(temp_text != null)
{
if(column == 0 && row == 0)
parent.frames[1].document.write("<td><input type='Radio' name='vocab' checked>");
else
parent.frames[1].document.write("<td><input type='Radio' name='vocab'>");
parent.frames[1].document.write(format_print(temp_text) + "</td>");
}
else
parent.frames[1].document.write(" ");
}
parent.frames[1].document.write("</tr>");
}
parent.frames[1].document.write("</table></form>");
parent.frames[1].document.close();
}

function pick_vocab()
{
for(temp = 0; temp < temp_vocab.length; temp++)
if(parent.frames[1].document.select_vocab.vocab[temp].checked)
current_vocab = temp_vocab[temp];
}

function format_print(input_text)
{
input_text = input_text.replace(/ae/g,"&auml;");
input_text = input_text.replace(/oe/g,"&ouml;");
input_text = input_text.replace(/ue/g,"&uuml;");
input_text = input_text.replace(/Ae/g,"&Auml;");
input_text = input_text.replace(/Oe/g,"&Ouml;");
input_text = input_text.replace(/Ue/g,"&Uuml;");
input_text = input_text.replace(/_/g," ");
input_text = input_text.replace(/-/g,"_");
input_text = input_text.replace(/=/g,"-");

return input_text;
}

function check()
{
if(!(current_activity === false) && !(current_vocab === false) && (current_vocab_list.length > 0 || current_vocab == "none"))
{
activity.function_check[current_activity]();
help_counter++
}
}

function done()
{
parent.frames[1].document.location = "main.html"
parent.frames[2].document.location = "control.html"
parent.frames[3].document.location = "feedback.html"
}

function write_feedback(message, picture)
{
var feedback =
"<html><head><title>Feedback Form</title></head><body>" +
"<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr>" +
"<tr><td width='10%' align='middle'><IMG alt=Feedback_Image border=0 height=75 src=" +
picture +
"></td><td width='90%'><FONT face='Times' size=4 color=#330066><STRONG>Feedback: </FONT></STRONG><FONT face='times' size=3>" +
format_print(message) +
"</font>" +
"</td></tr></table></body></html>";

parent.frames[3].document.open();
parent.frames[3].document.write(feedback);
parent.frames[3].document.close();
}

function instructions(type)
{
parent.frames[1].document.write("<hr align='CENTER' width='80%' color='Green'>");
if(type == "select")
{
parent.frames[1].document.write("<P align='center'><font face='times' size='2' color='navy'><UL><LI type='circle'>Select the correct answer from the choices, and then click 'check answer' to see if it is correct.</UL></font></p>");
}
if(type == "fill_in")
{
parent.frames[1].document.write("<P align='center'><font face='times' size='2' color='navy'><UL><LI type='circle'>Fill in the blanks and click 'check answer' to see if you are correct.<LI type='circle'>Use an e following a vowel for an umlaut: ue = &uuml;<LI type='circle'>Use tab to move between fields<LI type='circle'>Help button activates after 5 tries in case you get stuck!</UL></font></p>");
}
}