﻿		function populateBookDropdown(book, ch) {
			if (texts == '') return;
			var index = 0
			var select = document.getElementById('books-select')
			//while (select.length - 1) select.remove(select.length - 1)
			for (var i = 2; i < texts[0].length; i++) {
				var option = document.createElement('option')
				option.value = texts[0][i][0].substr(0, texts[0][i][0].indexOf('-') - 1)
				option.text = texts[0][i][0]
				try {
					select.add(option, null)
				} catch (x) {
					select.add(option, -1) //IE
				}
				//if (option.text.substr(0, option.text.indexOf('-') - 1).toLowerCase() == book.toLowerCase())
				if (option.value.toLowerCase() == book.toLowerCase())
					index = i - 1
			}
			select.disabled = false
			
			if (index > 0) {
				select.selectedIndex = index
				populateChapterDropdown(select, ch)
			} else if (select.length == 2) {
				select.selectedIndex = 1
				populateChapterDropdown(select, 0)
			} else {
				select = document.getElementById('chapters-select')
				select.selectedIndex = 0
				select.disabled = true
			}
		}
		function populateChapterDropdown(element, ch) {
			var select = document.getElementById('chapters-select')
			while (select.length - 1) select.remove(select.length - 1)
			for (var i = 1; i <= texts[0][element.selectedIndex + 1][1]; i++) {
				var option = document.createElement('option')
				option.text = (i >= 10 ? i : "0" + i)
				try {
					select.add(option, null)
				} catch (x) {
					select.add(option, -1) //IE
				}
			}
			select.selectedIndex = ch //(flag ? (<?php echo ($_GET['ch'] ? $_GET['ch'] : 0);?>) : 0)
			select.disabled = (select.length == 1)
		}
		function selectChapter(element, text) {
			//var text = "<?php echo $_GET['text'];?>"
			select = document.getElementById('books-select')
			var book = select.value
			window.location = window.location.toString().replace(/[&]book=[^&]*/, '').replace(/[&]ch=[^&]*/, '').replace(/text=[^&]*/, 'text=' + text + '&book=' + book + '&ch=' + element.selectedIndex)
		}

