
/* global Variables */
var activity_page = 0; /*pages through exercises*/
var secret = false;
var help_counter = 0; /*increments when "check answer" is clicked, resets on "continue"*/
	/*looks like help functions are supposed to give away the answer after x wrong guesses*/
var current_activity = false; /*holds selected activity*/
var current_vocab = false; /*holds selected vocab category*/
var temp_vocab = new Array(); /*list of vocab categories, holds to format as table*/
var current_vocab_list = new Array(); /*actual vocab list*/
var written;
var can_continue;






function main_interface()
{

/*if no activity is selected, prompt for one*/
if(current_activity === false)
{
if(!written)
{
write_activity();
written = 1;
return;
}
pick_activity();
written = 0;
}

/*if no vocab category is selected, prompt for one*/
while(current_vocab === false || current_vocab_list.length < 1 )
{
	if(!written)
	{
		if (activity.vocab[current_activity] == 0)
		/*activity.vocab property is set in data.js
		tells whether an activity type has associated vocab lists*/
		{
			current_vocab = "none";
		} else {
			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;

}

/*moves to the next page (word) when can_continue is 1.
can_continue is set to 1 on the individual vocab pages
when a question is answered correctly.*/
if(can_continue && !secret)
{
	activity_page++;
	can_continue = 0;
	help_counter = 0;
}

/*Displays the current question*/
if(!(current_activity === false) && !(current_vocab === false))
	{
	if(activity_page < current_vocab_list.length)
	{
	activity.function_run[current_activity]();
	}
	else
	done();
	}
	if(secret)
	activity_page++;
	
}

/*look up the answer after x wrong guesses*/
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]();
}
}

/*build list of questions*/
function make_active_list()
{
temp_2 = 0;

if( current_vocab == "none" )
  {
  for(temp = 0; temp < word.vocab.length; temp++)
    {
      if((word.activity[temp].search(activity.definition[current_activity]) + 1) > 0)
      {
        current_vocab_list[temp_2] = temp;
       temp_2++;
     }
    }
  } else {
    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++;
      }
    }
  }
}

/*displays prompt for activity
activity lists set up in data.js*/
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();
}

/*sets current_activity var to selected activity (selected in write_activity)*/
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;
}
}

/*displays prompt for vocab category - pick_again shows "no words in this list" message
vocab lists set up in data.js*/
function write_vocab(pick_again)
{
var temp_counter = 0;

for(temp = 0; temp < word.vocab.length; temp++)
{
var different = 1;
for(temp_2 = 0; temp_2 < temp; temp_2++)
{
if(word.vocab[temp] == word.vocab[temp_2])
different = 0;
}
if(different)
{
temp_vocab[temp_counter] = word.vocab[temp];
temp_counter++;
}
}
/*----------------start html---------------------*/

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();
}


/*sets current_vocab var to selected vocab category (selected in write_vocab)*/
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];
}

/*fixes var names & data for display, gets rid of characters like _*/
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;
}

/*checks answer
each category has its own check function
set in data.js*/
function check()
{
if(!(current_activity === false) && !(current_vocab === false) && current_vocab_list.length > 0)
{
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>");
}



}

