// JavaScript Document
// 00i-SpecificLanguage.js

	function BPDF(ISO, ROD_Code, BookFilename) {
		url = "00i-DownloadPDF.php"+"?T=B&ISO="+ISO+"&ROD_Code="+ROD_Code+"&BookFilename="+BookFilename;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function SPDF(ISO, ROD_Code, BookFilename) {
		url = "00i-DownloadPDF.php"+"?T=S&ISO="+ISO+"&ROD_Code="+ROD_Code+"&BookFilename="+BookFilename;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function OTPDF(ISO, ROD_Code, BookFilename) {
		url = "00i-DownloadPDF.php"+"?T=OT&ISO="+ISO+"&ROD_Code="+ROD_Code+"&BookFilename="+BookFilename;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function CellPhoneModule(ISO, ROD_Code, CellPhoneFile) {
		url = "00i-CellPhoneModule.php"+"?T=OT&ISO="+ISO+"&ROD_Code="+ROD_Code+"&CellPhoneFile="+CellPhoneFile;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function OTAudio(ISO, ROD_Code) {
		OT = "";
		// 0 - 38 books
		for (a = 0; a < 39; a++) {
			a_index = 'OT_audio_'+a.toString();
			if (document.getElementById(a_index) != null) {
				//alert(a_index + "     " + document.getElementById(a_index).value);
				if (document.getElementById(a_index).checked == true) {
					//alert(a_index);
					OT = OT + a_index.substring(a_index.lastIndexOf('_')+1) + ",";
				}
			}
		}
		url = "00i-AudioSaveZip.php"+"?T=OT&ISO="+ISO+"&ROD_Code="+ROD_Code+"&Books="+OT.substring(0, OT.length-1);
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		// This won't work because it writes to the new window.
		//w.document.write("<title>Save Audio Zip</title>")
		//w.document.write("<h1 style='color: white; background-color: brown; text-align: center; '>Creating the zip file. Please wait...</h1>")
		return false; //cancels href action 
	}
	function NTPDF(ISO, ROD_Code, BookFilename) {
		url = "00i-DownloadPDF.php"+"?T=NT&ISO="+ISO+"&ROD_Code="+ROD_Code+"&BookFilename="+BookFilename;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function Study(ISO, ROD_Code, URL) {
		url = "00i-DownloadStudy.php?ISO="+ISO+"&ROD_Code="+ROD_Code+"&URL="+URL;
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		return false; //cancels href action 
	}
	function NTAudio(ISO, ROD_Code) {
		NT = "";
		// 0 - 26 books
		for (a = 0; a < 27; a++) {
			a_index = 'NT_audio_'+a.toString();
			if (document.getElementById(a_index) != null) {
				//alert(a_index + "     " + document.getElementById(a_index).value);
				if (document.getElementById(a_index).checked == true) {
					//alert(a_index);
					NT = NT + a_index.substring(a_index.lastIndexOf('_')+1) + ",";
				}
			}
		}
		//alert("?T=NT&ISO="+ISO+"&Books="+NT.substring(0, NT.length-1));
		url = "00i-AudioSaveZip.php"+"?T=NT&ISO="+ISO+"&ROD_Code="+ROD_Code+"&Books="+NT.substring(0, NT.length-1);
		var w = window.open(url, "_normal", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=400, height=320");
		// This won't work because it writes to the new window.
		//w.document.write("<title>Save Audio Zip</title>")
		//w.document.write("<h1 style='color: white; background-color: brown; text-align: center; '>Creating the zip file. Please wait...</h1>")
		return false; //cancels href action 
	}

var Eng_NT_array = [
"Matthew",
"Mark",
"Luke",
"John",
"Acts",
"Romans",
"1 Corinthians",
"2 Corinthians",
"Galatians",
"Ephesians",
"Philippians",
"Colossians",
"1 Thessalonians",
"2 Thessalonians",
"1 Timothy",
"2 Timothy",
"Titus",
"Philemon",
"Hebrews",
"James",
"1 Peter",
"2 Peter",
"1 John",
"2 John",
"3 John",
"Jude",
"Revelation"
];

var Eng_OT_array = [
"Genesis",
"Exodus",
"Leviticus",
"Numbers",
"Deuteronomy",
"Joshua",
"Judges",
"Ruth",
"1 Samuel",
"2 Samuel",
"1 Kings",
"2 Kings",
"1 Chronicles",
"2 Chronicles",
"Ezra",
"Nehemiah",
"Esther",
"Job",
"Psalms",
"Proverbs",
"Ecclesiastes",
"Song of Solomon",
"Isaiah",
"Jeremiah",
"Lamentations",
"Ezekiel",
"Daniel",
"Hosea",
"Joel",
"Amos",
"Obadiah",
"Jonah",
"Micah",
"Nahum",
"Habukkuk",
"Zephaniah",
"Haggai",
"Zechariah",
"Malachi"
];

function AudioChangeChapters(WhichTestament, ISO, ROD_Code, BookNumber) {			// The array NumberOfChapters won't work. Hmmm...
	var Testament = "NT_Chapters_mp3";
	if (WhichTestament == "OT") {
		Testament = "OT_Chapters_mp3";
	}
	var elSel = document.getElementById(Testament);
	var i = 0;
	for (i = elSel.length - 1; i >= 0; i--) {
		//if (elSel.options[i].selected) {
		  elSel.remove(i);								// first, delete all the 'option's
		//}
	}
	var Chapters = new Array();
	Chapters = BookNumber.split(',');					// Split the BookNumber into an array where the ',' are separators
	var BookNumber = Chapters[0];						// The number of the Book of the Bible
	var Book = Eng_NT_array[BookNumber];
	if (WhichTestament == "OT") {
		Book = Eng_OT_array[BookNumber];
	}
	/*
		This is not neccessary EXCEPT if the audio was not complete. I.e., if the books of the Bible
		did not have all of the chapters. However, the chapter audio filenames have to be there.
	*/
	for (i=1; i < Chapters.length; i=i+2) {
		var eNew = document.createElement('option');	// The 'var' needs to be there!
		eNew.text = Chapters[i];
		eNew.value = Book + "^data/" + ISO + "/audio/" + Chapters[i+1];
		try {
			elSel.add(eNew, null);						// standards compliant; doesn't work in IE
		}
		catch (ex) {
			elSel.add(eNew);							// IE only
		}
	}
}

function ListenAudio(mp3Info, autostart, whichListenTo) {
	whichListenTo = typeof(whichListenTo) != 'undefined' ? whichListenTo : "";
	var AudioFileName = new Array();
	AudioFileName = mp3Info.value.split('^');				// Split the mp3Info into an array where the '^' are separators
	var listenBook = AudioFileName[0];						// The number of the Book of the Bible 
	var listenFilename = AudioFileName[1];					// Audio Filename
	var divHeight = 0;
/*
	I want to be able to print out
		alert ("The mp3 file does not exists.");
	but javascript does not have 'if filename exists' but only in AJAX.
*/
	var listenChapter =  mp3Info.options[mp3Info.selectedIndex].text;
	var newHTML = "<div id='" + whichListenTo + "' class='ourListenNow' style='display: block; margin-top: 0px; '>";
	newHTML = newHTML + "<div class='ourFlashPlayer' >";
	newHTML = newHTML + "<span style='vertical-align: top; '>" + listenBook + " " + listenChapter + "</span> &nbsp;&nbsp; ";
	newHTML = newHTML + '<embed src="player.swf" bgcolor="#ffffff" ';
	newHTML = newHTML + 'width="320" height="18" name="player1" flashvars="file='+listenFilename+'&autostart='+autostart+'&volume=50 "';
	newHTML = newHTML + 'allowScriptAccess="always"';
	newHTML = newHTML + 'type="application/x-shockwave-flash"';
	newHTML = newHTML + 'pluginspage="http://get.adobe.com/flashplayer"></embed>';
	newHTML = newHTML + '</div></div>';
	if (whichListenTo == 'OTListenNow') {
		document.getElementById('OTListenNow').innerHTML = newHTML;
		if (document.getElementById('OTListenNow').style.display != "block") {
			document.getElementById('OTListenNow').style.marginLeft = "0px";
			document.getElementById('OTListenNow').style.display = "block";
			divHeight = 41;
		}
		else
			divHeight = -2;
		$(document).ready(function() {
			divHeight += document.getElementById("container").offsetHeight;
			document.getElementById("container").style.height = divHeight + "px";
			// if the table is long enough IE goes to dark black (blur and opacity). I don't know why.
			$("#container").redrawShadow({left: 5, top: 5, blur: 2, opacity: 0.5, color: "black", swap: false});
		});
	}
	else if (whichListenTo == 'NTListenNow') {
		document.getElementById('NTListenNow').innerHTML = newHTML;
		if (document.getElementById('NTListenNow').style.display != "block") {
			document.getElementById('NTListenNow').style.marginLeft = "0px";
			document.getElementById('NTListenNow').style.display = "block";
			divHeight = 39;
		}
		else
			divHeight = -2;
		$(document).ready(function() {
			divHeight += document.getElementById("container").offsetHeight;
			document.getElementById("container").style.height = divHeight + "px";
			// if the table is long enough IE goes to dark black (blur and opacity). I don't know why.
			$("#container").redrawShadow({left: 5, top: 5, blur: 2, opacity: 0.5, color: "black", swap: false});
		});
	}
	else {
		document.getElementById('ListenNow').style.marginLeft = "0px";
		document.getElementById('ListenNow').style.display = "block";
		document.getElementById('ListenNow').innerHTML = newHTML;
	}
}

