var grammarIndex = 1;

// creates an array of vocabulary objects
function vocabulary(かな, かんじ, english, section) {
	this.かんじ = かんじ;
	this.かな = かな;
	this.english = english;
	this.section = section;
}

var vocabs = new Array(new vocabulary("せんしゅう", "", "Next Week", "4-II"));
vocabs[grammarIndex++] = new vocabulary("とき", "時", "at the time", "4-II");
vocabs[grammarIndex++] = new vocabulary("あう", "会う", "to meet; to see (a person)", "4-II");
vocabs[grammarIndex++] = new vocabulary("ある", "", "there is...", "4-II");
vocabs[grammarIndex++] = new vocabulary("かう", "買う", "to buy", "4-II");
vocabs[grammarIndex++] = new vocabulary("かく", "書く", "to write", "4-II");
vocabs[grammarIndex++] = new vocabulary("とる", "撮る", "to take (pictures)", "4-II");
vocabs[grammarIndex++] = new vocabulary("まつ", "待つ", "to wait", "4-II");
vocabs[grammarIndex++] = new vocabulary("わかる", "", "to understand", "4-II");
vocabs[grammarIndex++] = new vocabulary("いる", "", "(a person) is in...; stays at (place に)", "4-II");
vocabs[grammarIndex++] = new vocabulary("ぐらい", "", "about (approximate measurement)", "4-II");
vocabs[grammarIndex++] = new vocabulary("ごめんなさい", "", "I&rsquo;m sorry.", "4-II");
vocabs[grammarIndex++] = new vocabulary("だかり", "", "so; therefore", "4-II");
vocabs[grammarIndex++] = new vocabulary("と", "", "together with (a person)", "4-II");
vocabs[grammarIndex++] = new vocabulary("たくさん", "", "many; a lot", "4-II");
vocabs[grammarIndex++] = new vocabulary("どうして", "", "why", "4-II");
vocabs[grammarIndex++] = new vocabulary("ひとりで", "一人で", "alone", "4-II");
vocabs[grammarIndex++] = new vocabulary("みぎ", "右", "right", "4-II");
vocabs[grammarIndex++] = new vocabulary("ひだり", "左", "left", "4-II");
vocabs[grammarIndex++] = new vocabulary("まえ", "前", "front", "4-II");
vocabs[grammarIndex++] = new vocabulary("うしろ", "後ろ", "back", "4-II");
vocabs[grammarIndex++] = new vocabulary("なか", "中", "inside", "4-II");
vocabs[grammarIndex++] = new vocabulary("うえ", "上", "on", "4-II");
vocabs[grammarIndex++] = new vocabulary("にちようび", "日曜日", "Sunday", "4-II");
vocabs[grammarIndex++] = new vocabulary("げつようび", "月曜日", "Monday", "4-II");
vocabs[grammarIndex++] = new vocabulary("かようび", "火曜日", "Tuesday", "4-II");
vocabs[grammarIndex++] = new vocabulary("すいようび", "水曜日", "Wednesday", "4-II");
vocabs[grammarIndex++] = new vocabulary("もくようび", "木曜日", "Thursday", "4-II");
vocabs[grammarIndex++] = new vocabulary("きんようび", "金曜日", "Friday", "4-II");
vocabs[grammarIndex++] = new vocabulary("どようび", "土曜日", "Saturday", "4-II");
vocabs[grammarIndex++] = new vocabulary("アルバイト", "", "Part-Time Job", "4-I");
vocabs[grammarIndex++] = new vocabulary("かいもの", "買い物", "shopping", "4-I");
vocabs[grammarIndex++] = new vocabulary("あなた", "", "you", "4-I");
vocabs[grammarIndex++] = new vocabulary("いぬ", "犬", "dog", "4-I");
vocabs[grammarIndex++] = new vocabulary("おみやげ", "お土産", "souvenir", "4-I");
vocabs[grammarIndex++] = new vocabulary("こども", "子供", "child", "4-I");
vocabs[grammarIndex++] = new vocabulary("ごはん", "御飯", "rice; meal", "4-I");
vocabs[grammarIndex++] = new vocabulary("しゃしん", "写真", "picture; photograph", "4-I");
vocabs[grammarIndex++] = new vocabulary("つくえ", "机", "desk", "4-I");
vocabs[grammarIndex++] = new vocabulary("てがみ", "手紙", "letter", "4-I");
vocabs[grammarIndex++] = new vocabulary("ねこ", "猫", "cat", "4-I");
vocabs[grammarIndex++] = new vocabulary("パン", "", "bread", "4-I");
vocabs[grammarIndex++] = new vocabulary("ひと", "人", "person", "4-I");
vocabs[grammarIndex++] = new vocabulary("おてら", "お寺", "temple", "4-I");
vocabs[grammarIndex++] = new vocabulary("こうえん", "公園", "park", "4-I");
vocabs[grammarIndex++] = new vocabulary("スーパー", "", "supermarket", "4-I");
vocabs[grammarIndex++] = new vocabulary("デパート", "", "department store", "4-I");
vocabs[grammarIndex++] = new vocabulary("バスでい", "", "bus stop", "4-I");
vocabs[grammarIndex++] = new vocabulary("びょういん", "病院", "hospital", "4-I");
vocabs[grammarIndex++] = new vocabulary("ホテル", "", "hotel", "4-I");
vocabs[grammarIndex++] = new vocabulary("ほんや", "本屋", "bookstore", "4-I");
vocabs[grammarIndex++] = new vocabulary("まち", "町", "town; city", "4-I");
vocabs[grammarIndex++] = new vocabulary("レストラン", "", "restaurant", "4-I");
vocabs[grammarIndex++] = new vocabulary("きのう", "昨日", "yesterday", "4-I");
vocabs[grammarIndex++] = new vocabulary("さっき", "", "a little while ago", "4-I");
vocabs[grammarIndex++] = new vocabulary("〜じかん", "〜時間", "hour", "4-I");
vocabs[grammarIndex++] = new vocabulary("いちじかん", "一時間", "one hour", "4-I");
vocabs[grammarIndex++] = new vocabulary("アメリカ", "", "U.S.A.", "1-II");
vocabs[grammarIndex++] = new vocabulary("イギリス", "", "Britain", "1-II");
vocabs[grammarIndex++] = new vocabulary("オーストラリア", "", "Australia", "1-II");
vocabs[grammarIndex++] = new vocabulary("かんこく", "", "Korea", "1-II");
vocabs[grammarIndex++] = new vocabulary("スウエーデん", "", "Sweden", "1-II");
vocabs[grammarIndex++] = new vocabulary("ちゅうごく", "", "China", "1-II");
vocabs[grammarIndex++] = new vocabulary("かがく", "", "science", "1-II");
vocabs[grammarIndex++] = new vocabulary("アジアけんきゅう", "", "Asian studies", "1-II");
vocabs[grammarIndex++] = new vocabulary("けいざい", "", "economics", "1-II");
vocabs[grammarIndex++] = new vocabulary("こくさいかんけい", "", "international relations", "1-II");
vocabs[grammarIndex++] = new vocabulary("コンピューター", "", "computer", "1-II");
vocabs[grammarIndex++] = new vocabulary("じんるいがく", "", "anthropology", "1-II");
vocabs[grammarIndex++] = new vocabulary("せいじ", "", "politics", "1-II");
vocabs[grammarIndex++] = new vocabulary("ビジネス", "", "business", "1-II");
vocabs[grammarIndex++] = new vocabulary("ぶんがく", "", "literature", "1-II");
vocabs[grammarIndex++] = new vocabulary("れきし", "", "history", "1-II");
vocabs[grammarIndex++] = new vocabulary("しごと", "", "job; work; occupation", "1-II");
vocabs[grammarIndex++] = new vocabulary("いしゃ", "", "doctor", "1-II");
vocabs[grammarIndex++] = new vocabulary("かいしゃいん", "", "office worker", "1-II");
vocabs[grammarIndex++] = new vocabulary("こうこうせい", "", "high school student", "1-II");
vocabs[grammarIndex++] = new vocabulary("しゅふ", "", "housewife", "1-II");
vocabs[grammarIndex++] = new vocabulary("だいがくいんせい", "", "graduate student", "1-II");
vocabs[grammarIndex++] = new vocabulary("だいがくせい", "", "college student", "1-II");
vocabs[grammarIndex++] = new vocabulary("べんごし", "", "lawyer", "1-II");
vocabs[grammarIndex++] = new vocabulary("おかあさん", "", "mother", "1-II");
vocabs[grammarIndex++] = new vocabulary("おとうさん", "", "father", "1-II");
vocabs[grammarIndex++] = new vocabulary("おねえさん", "", "older sister", "1-II");
vocabs[grammarIndex++] = new vocabulary("おにいさん", "", "older brother", "1-II");
vocabs[grammarIndex++] = new vocabulary("いもうと", "", "younger sister", "1-II");
vocabs[grammarIndex++] = new vocabulary("おとうと", "", "younger brother", "1-II");

function getVocab(x) {
	if(x < vocabs.length)
	{
		var madeWord = "<table>";
		madeWord += "<tr><td><font class = 'kanji'>" + vocabs[x].かんじ + "</font>";
		madeWord += "<br><font class = 'hiragana'>" + vocabs[x].かな + "</font></td>";
		madeWord += "<td>" + vocabs[x].english + "</td></tr>";
		madeWord += "</table>";
		return madeWord;
	}
	else return "No word for you!";
}

function get日本(x) {
	if(x < vocabs.length)
	{
		var 日本 = "<table><tr><td><font class = 'kanji'>" + vocabs[x].かんじ + "</font>";
		日本 += "<br><font class = 'hiragana'>" + vocabs[x].かな + "</font>";
		日本 += "<td>" + vocabs[x].english + "</td></tr>";
		return 日本;
	}
	else return "No word for you!";
}

function getEnglish(x) {
	if(x < vocabs.length)
	{
		return vocabs[x].english;
	}
	else return "No word for you!";
}

function randomVocab()
{
	var z = Math.floor(Math.random() * vocabs.length);
	return makeVocab(z);
}

function answerQuiz() {
	var button = document.getElementById('clicker').value;
	if(button == 'See Answer') {
		document.getElementById('answer').style.visibility = 'visible';
		document.getElementById('clicker').value = 'Next!';
	}
	if(button == 'Next!') {
		var z = Math.floor(Math.random() * vocabs.length);
		var notOK = true;
		
		while(notOK) {
			var noCheckedBox = true;
			if(document.getElementById('1a').checked) {
				noCheckedBox = false;
				if(vocabs[z].section == "1-I") notOK = false;
			}

			if(document.getElementById('1b').checked) {
				noCheckedBox = false;
				if(vocabs[z].section == "1-II") notOK = false;
			}
			
			if(document.getElementById('4a').checked) {
				noCheckedBox = false;
				if(vocabs[z].section == "4-I") notOK = false;
			}

			if(document.getElementById('4b').checked) {
				noCheckedBox = false;
				if(vocabs[z].section == "4-II") notOK = false;
			}
			
			if(notOK) z = Math.floor(Math.random() * vocabs.length);
			if(noCheckedBox) document.getElementById('4b').checked = true;
		}
		
		document.getElementById('qk').innerHTML = vocabs[z].かんじ;
		document.getElementById('qh').innerHTML = vocabs[z].かな;
		document.getElementById('answer').innerHTML = vocabs[z].english;
		
		document.getElementById('answer').style.visibility = 'hidden';
		document.getElementById('clicker').value = 'See Answer';
	}
}

function makeQuiz() {
	var z = Math.floor(Math.random() * vocabs.length);

	var 日本 = "<div class = 'quiz'>";
	日本 += "<input type = 'button' value = 'See Answer' id = 'clicker' onClick = 'javascript:answerQuiz()' />";
	日本 += "<div>Sections: ";
	日本 += "<input type = 'checkbox' value = '1-I' checked = 'checked' id = '1a'>1-I ";
	日本 += "<input type = 'checkbox' value = '1-II' checked = 'checked' id = '1b'>1-II ";
	日本 += "<input type = 'checkbox' value = '4-I' checked = 'checked' id = '4a'>4-I ";
	日本 += "<input type = 'checkbox' value = '4-II' checked = 'checked' id = '4b'>4-II ";
	日本 += "</div>";
	日本 += "<div id = 'question' class = 'question'><font class = 'kanji' id = 'qk'>" + vocabs[z].かんじ + "</font>";
	日本 += "<br><font class = 'hiragana' id = 'qh'>" + vocabs[z].かな + "</font></div>";
	日本 += "<div id = 'answer' class = 'answer'>" + vocabs[z].english + "</div>"
	日本 += "</div>";
	
	return 日本;
}

function listAllVocab()
{
	var allvocab = "<table align = 'center'><tr><td align = 'left' width = '750'>";
	var wordCounter = 0;
	
	for(wordCounter; wordCounter < vocabs.length; wordCounter++)
	{
	allvocab += "<tr><td>" + getVocab(wordCounter) + "</td></tr>";
	}
	
	allvocab += "</td></tr></table>";
	
	return allvocab;
}