//
// QueryString
//

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}

QueryString_Parse();


//
// Answer
//
function Answer_WriteHTML()
{
	document.write('<INPUT type="radio" value="' + this.id + '" name="answers"> ');
	document.write('<span  class="quizText">' + this.text + '</span><br>');
}

function Answer(aID)
{
	this.text = "New Answer";
	this.id = aID;
	this.correct = false;
	
	this.WriteHTML = Answer_WriteHTML;
}

//
// AnswerList
//

function AnswerList_NewAnswer()
{
	var a = new Answer(this.sequenceID);
	this.sequenceID++;
	this.aList[this.aList.length] = a;

	// Optional Args: text, correct
	if (arguments.length > 0)
		a.text = arguments[0];

	if (arguments.length > 1)
		a.correct = arguments[1];

	if (this.editor)
		this.editor.AnswerSectionUpdate();
		
	return a;
}

function AnswerList_Remove(id)
{
	for (var i=0;i<this.aList.length;i++)
	{
		if (this.aList[i] && this.aList[i].id == id)
		{
			this.aList[i] = null;
			break;
		}
	}
}

function AnswerList_Find(id)
{
	var result = null;
	for (var i=0;i<this.aList.length;i++)
	{
		if (this.aList[i] && this.aList[i].id == id)
		{
			result = this.aList[i];
			break;
		}
	}
	return result;
}

function AnswerList_WriteHTML()
{
	for (var i=0;i<this.aList.length;i++)
		this.aList[i].WriteHTML();
}

function AnswerList(editor)
{
	this.editor = editor;
	this.sequenceID = 0;
	this.aList = new Array();
	
	this.NewAnswer = AnswerList_NewAnswer;
	this.Remove = AnswerList_Remove;
	this.Find = AnswerList_Find;
	this.WriteHTML = AnswerList_WriteHTML;
}

//
// Question
//

function Question_NewAnswer(text,correct)
{
	this.answerList.NewAnswer(text,correct);
}

function Question_WriteHTML()
{
	document.write('<p class="quizQuestion">Question: ' + this.text + '</p>');
	this.answerList.WriteHTML();
}

function Question_GetCorrectAnswer(text,correct)
{
	var result = "";
	for (var i=0;i<this.answerList.aList.length;i++)
	{
		if (this.answerList.aList[i] && this.answerList.aList[i].correct)
		{
			result = this.answerList.aList[i].text;
			break;
		}
	}
	return result;
}

function Question(qID,editor)
{
	this.text = "New Question";
	this.id = qID;
	this.editor = editor;
		
	this.answerList = new AnswerList(editor);
	
	this.NewAnswer = Question_NewAnswer;
	this.WriteHTML = Question_WriteHTML;
	this.GetCorrectAnswer = Question_GetCorrectAnswer;
}

//
// QuestionList
//

function QuestionList_NewQuestion()
{
	var q = new Question(this.sequenceID,this.editor);
	this.sequenceID++;
	this.qList[this.qList.length] = q;
	
	// Optional Args: text
	if (arguments.length > 0)
		q.text = arguments[0];
	
	if (this.editor)
		this.editor.QuestionItemsAdd(q);
		
	return q;
}

function QuestionList_Remove(id)
{
	for (var i=0;i<this.qList.length;i++)
	{
		if (this.qList[i] && this.qList[i].id == id)
		{
			this.qList[i] = null;
			break;
		}
	}
}

function QuestionList_Find(id)
{
	var result = null;
	for (var i=0;i<this.qList.length;i++)
	{
		if (this.qList[i] && (this.qList[i].id == id))
		{
			result = this.qList[i];
			break;
		}
	}
	return result;
}

function QuestionList_WriteHTML()
{
	var index = 0;
	
	var lastQuestion = QueryString("lastQuestion");
	var ccount = QueryString("ccount");

	if (ccount == null)
		ccount = 0;
	else
		ccount = parseInt(ccount);

	document.write('<form name="quiz" method="GET" onsubmit="return QuestionListValidate(this)">');
		
	
	if (lastQuestion!=null)
	{
		lastQuestion = parseInt(lastQuestion);
		index = 1 + lastQuestion;
		var answerID = parseInt(QueryString("answers"));
		
		if (this.qList[lastQuestion].answerList.aList[answerID].correct)
		{
			document.write('<p class="quizRightWrong">Correct!</p>');
			ccount++;
		}
		else
		{
			var correctAnswer = this.qList[lastQuestion].GetCorrectAnswer();
			document.write('<p class="quizRightWrong">That answer was not correct.</p>');
			document.write('<p class="quizText">The correct answer to:</p>');
			document.write('<p class="quizIndent">' + this.qList[lastQuestion].text + '</p>');
			document.write('<p class="quizText">is:</p>');
			document.write('<p class="quizIndent">' + correctAnswer + '</p>');
		}
		
		
	}
	
	if (index < this.qList.length)
	{
		document.write('<input type="hidden" name="lastQuestion" value="' + index + '">')
		
		this.qList[index].WriteHTML();
		document.write('<p><input type="submit" name="submit" value="Next Question >>"></p>')
	}
	else
	{
		var score = Math.round((ccount*100)/this.qList.length);
		var scoreResults = this.ScoreResults(Math.min(Math.floor(score/10),9));
		document.write('<p class="quizText">You answered ' + ccount + ' items out of ' +
			this.qList.length + ' correctly.</p>');
		document.write('<p class="quizText">Your score is ' + score + '%. ' + scoreResults + '</p>');
	}
	
	document.write('<input type="hidden" name="ccount" value="' + ccount + '">')
	document.write('</form>');
	
}

function QuestionList_ScoreResults(index,text)
{
	// Optional Args: text
	if (arguments.length > 1)
	{
		this.scoreResults[index] = text;
	}
		
	return this.scoreResults[index];
}

function QuestionList(editor)
{
	this.sequenceID = 0;
	this.qList = new Array();
	this.scoreResults = new Array(10);
	this.editor = editor;
	
	this.NewQuestion = QuestionList_NewQuestion;
	this.Remove = QuestionList_Remove;
	this.Find = QuestionList_Find;
	this.WriteHTML = QuestionList_WriteHTML;
	this.ScoreResults = QuestionList_ScoreResults;
}

function QuestionListValidate(theForm)
{
	var validated = false;
	
	for (var i=0;i<theForm.answers.length;i++)
	{
		if (theForm.answers[i].checked == true)
		{
			validated = true;
			break;
		}
	}
	
	if (!validated)
		alert("Please select an answer before continuing.");
	
	return validated;
}

var gQuestionList = new QuestionList(null);

// Quiz Source Start (to edit with QuizEditor copy/paste between here and end
// -->


gQuestionList.ScoreResults(0,"We are as speechless about your performance as you guessed questions right");
gQuestionList.ScoreResults(1,"Wow, you better come over and see, because your knowledge on Russia needs a bit of an impulse");
gQuestionList.ScoreResults(2,"Around a quarter of your answers were right. It seems like we have a persistant A, B, C or D gambler?!");
gQuestionList.ScoreResults(3,"Not bad, but could use some improvement. Should have Central Russia on the holiday calendar for next season.");
gQuestionList.ScoreResults(4,"Not bad, but could use some improvement. Should have Central Russia on the holiday calendar for next season.");
gQuestionList.ScoreResults(5,"More than half! Been to Russia before?");
gQuestionList.ScoreResults(6,"More than half! Been to Russia before?");
gQuestionList.ScoreResults(7,"Just a fine fine score, what else can we say?! VISIT THE URALS!");
gQuestionList.ScoreResults(8,"Sure you don't want to apply for group leader of our tourist company?");
gQuestionList.ScoreResults(9,"Wow, an EXPERT score! Probably you ARE Russian or you just cheated...?!");
q = gQuestionList.NewQuestion("Which is the right chronological order (from old to new) of leaders of Russia?");
q.NewAnswer("Lenin - Stalin - Gorbachov - Khrutshev - Putin",false);
q.NewAnswer("Stalin - Breznyev - Lenin - Putin",false);
q.NewAnswer("Lenin - Breznyev - Khrutchev - Gorbachov",false);
q.NewAnswer("Stalin - Khrutchev - Gorbachov - Putin",true);
q = gQuestionList.NewQuestion("Mount Elbrus, the highest mountain of Europe, lies in");
q.NewAnswer("Czech Republic",false);
q.NewAnswer("Russia",true);
q.NewAnswer("Georgia",false);
q.NewAnswer("France",false);
q = gQuestionList.NewQuestion("Russia is the biggest country in the world, _____ the size of the USA (approximately)");
q.NewAnswer("sliiiiightly bigger than",false);
q.NewAnswer("2 times",true);
q.NewAnswer("3 times",false);
q.NewAnswer("4 times",false);
q = gQuestionList.NewQuestion("Russia's 3 biggest cities are:");
q.NewAnswer("Moscow, St.Petersburg, Minsk",false);
q.NewAnswer("Moscow, Irkutsk, Volgograd",false);
q.NewAnswer("Moscow, St. Petersburg, Novosibirsk",true);
q.NewAnswer("Moscow, Rostov, Murmansk",false);
q = gQuestionList.NewQuestion("The colors of the Russian flag are:");
q.NewAnswer("White and blue",false);
q.NewAnswer("Red with yellow",false);
q.NewAnswer("White, blue and red",true);
q.NewAnswer("Yellow, red and dark-red",false);
q = gQuestionList.NewQuestion("Russia has around _____ million inhabitants");
q.NewAnswer("144",true);
q.NewAnswer("190",false);
q.NewAnswer("264",false);
q.NewAnswer("332",false);
q = gQuestionList.NewQuestion("What is the capital of the Russian republic of Tatarstan?");
q.NewAnswer("Kirov",false);
q.NewAnswer("Kazan",true);
q.NewAnswer("Perm",false);
q.NewAnswer("Ufa",false);
q = gQuestionList.NewQuestion("Which are former Soviet Union Republics?");
q.NewAnswer("Kazakhstan, Afghanistan, Estonia, Uzbekistan",false);
q.NewAnswer("Latvia, Turkmenistan, Kirgistan, Armenia",true);
q.NewAnswer("Tadzjikistan, Latvia, Kaliningrad, Ukraine",false);
q.NewAnswer("Ukraine, Belarussia, Mongolia, Lithuania",false);
q = gQuestionList.NewQuestion("Russia's largest peninsula is called:");
q.NewAnswer("Krimea (Krim)",false);
q.NewAnswer("Nova Zemlya",false);
q.NewAnswer("Kamchatka",true);
q.NewAnswer("Baikal",false);
q = gQuestionList.NewQuestion("In Russia, the first language is _____, which is a _____ language and uses the _____ aphabet");
q.NewAnswer("Soviet, Siberian, Cyrillic",false);
q.NewAnswer("Russian, German, Cyrillic",false);
q.NewAnswer("Ukranian, German, Latin",false);
q.NewAnswer("Russian, Slavic, Cyrillic",true);
q.NewAnswer("Russian, Baltic, Latin",true);
q = gQuestionList.NewQuestion("Which mountain range does NOT lie in Russia");
q.NewAnswer("Altai",false);
q.NewAnswer("Urals",false);
q.NewAnswer("Karpats",true);
q.NewAnswer("Caucasians",false);
q = gQuestionList.NewQuestion("Vodka is one of the biggest Russian stereotypes. Although Russia is the biggest producer of vodka, it is not the biggest consumer, this place is taken by _____. Famous Russian vodka brands are: _____, _____ and _____");
q.NewAnswer("Poland, Dubrovka-Smirnoff-Moskovskaya-",false);
q.NewAnswer("Ukraine, Absolut-Smirnoff-Dubrovka",false);
q.NewAnswer("Finland, Finlandia-Moskovskaya-Absolut",false);
q.NewAnswer("Finland, Stolichnaya-Absolut-Flagman",false);
q.NewAnswer("Poland, Stolichnaya-Smirnoff-Moskovskaya",true);
q = gQuestionList.NewQuestion("What is NOT a typical ingredient for Russian dishes?");
q.NewAnswer("Cauliflower",true);
q.NewAnswer("Cabbage",false);
q.NewAnswer("Potato",false);
q.NewAnswer("Beetroot",false);
q.NewAnswer("Red meat",false);
q = gQuestionList.NewQuestion("Which rivers can all be found in Russia?");
q.NewAnswer("Volga, Kama, Yenissey",true);
q.NewAnswer("Dnjepr, Lena, Ob",false);
q.NewAnswer("Volga, Ob, Aral",false);
q.NewAnswer("Amur, Baikal, Donau",false);
q = gQuestionList.NewQuestion("Many cities in Russia used to have a different name during certain periods in Soviet-era then they have now. Which old-new name combination is NOT correct?");
q.NewAnswer("Leningrad - St. Petersburg",false);
q.NewAnswer("Molotov - Perm",false);
q.NewAnswer("Vyatka - Kirov",false);
q.NewAnswer("Stalingrad - Rostov",true);
q.NewAnswer("Gorki - Nizhny Novgorod",false);
q = gQuestionList.NewQuestion("Which cars are Russian?");
q.NewAnswer("Tchaika, Volga, Lada",true);
q.NewAnswer("Zhiguli, Audi, Volga",false);
q.NewAnswer("Lada, Skoda, Moskvitch",false);
q.NewAnswer("Tatra, Moskvitch, Volga",false);
q = gQuestionList.NewQuestion("The natural border between Europe and Asia is formed by:");
q.NewAnswer("the Kama river",false);
q.NewAnswer("the Volga river",false);
q.NewAnswer("the Ural mountain range",true);
q.NewAnswer("the Caucasion mountain range",false);
q = gQuestionList.NewQuestion("Russian names. If the man Vladimir Alekseyevitch Romanov marries a woman Elena Ivanovna Popova and they get a daughter called Marina, what would the full name of the daughter be?");
q.NewAnswer("Marina Ivanovna Romanova",false);
q.NewAnswer("Marina Vladimirovna Romanova",true);
q.NewAnswer("Marina Alekseyevitch Romanov",false);
q.NewAnswer("Marina Vladimirovitch Romanov",false);
q = gQuestionList.NewQuestion("Which of following films is originally NOT Russian?");
q.NewAnswer("The Idiot",false);
q.NewAnswer("Amphibian Man",false);
q.NewAnswer("From Russia with love",true);
q.NewAnswer("October",false);
q = gQuestionList.NewQuestion("What is the name of the Russian Tsar who (as the rest of his family) was murdered in the Ural region?");
q.NewAnswer("Ivanov",false);
q.NewAnswer("Romanov",true);
q.NewAnswer("Peter 1st",false);
q.NewAnswer("Peter 2nd",false);
q = gQuestionList.NewQuestion("Which Russian aircraft should not be part of below list?");
q.NewAnswer("MiG",true);
q.NewAnswer("Tupolev",false);
q.NewAnswer("Antonov",false);
q.NewAnswer("Ilyushin",false);
q.NewAnswer("Yakovlev",false);
q = gQuestionList.NewQuestion("What is Russia's most adored sport?");
q.NewAnswer("Football",false);
q.NewAnswer("Basketball",false);
q.NewAnswer("Icehockey",true);
q.NewAnswer("Athletics",false);
q = gQuestionList.NewQuestion("Which sea does Russia NOT border?");
q.NewAnswer("Egian Sea",true);
q.NewAnswer("White Sea",false);
q.NewAnswer("Sea of Okhotsk",false);
q.NewAnswer("Black Sea",false);
q.NewAnswer("Barentz Sea",false);
q.NewAnswer("Caspian Sea",false);
q = gQuestionList.NewQuestion("Which is NOT a Russian export product?");
q.NewAnswer("Kaviar",false);
q.NewAnswer("Oil",false);
q.NewAnswer("Steel",false);
q.NewAnswer("Fish",false);
q.NewAnswer("Wine",true);
q = gQuestionList.NewQuestion("In which city does the world famous Trans Siberian Express NOT stop?");
q.NewAnswer("Moscow",false);
q.NewAnswer("St. Petersburg",true);
q.NewAnswer("Perm",false);
q.NewAnswer("Omsk",false);
q = gQuestionList.NewQuestion("The last one. What will be your next original holiday?");
q.NewAnswer("Diving in search of Atlantis",false);
q.NewAnswer("Orbitting the Earth in a space shuttle",false);
q.NewAnswer("A hell of an adventure - in the Russian Ural Mountains",true);
q.NewAnswer("Studying pinguins on the North Pole",false);

// <-- Quiz Source End 
