function setbook(){if(location.hash==""){return;}var bk=location.hash;if(bk.length>1){bk=bk.substring(1,bk.length);var id=0;document.navi.book.selectedIndex=id;while(document.navi.book.options[document.navi.book.selectedIndex].value!=bk&&id<39){id++;document.navi.book.selectedIndex=id;}if(id<39){return;}id++;document.navi.book.selectedIndex=id;while(document.navi.book.options[document.navi.book.selectedIndex].value!=bk&&id<67){id++;document.navi.book.selectedIndex=id;}if(id<67){return;}document.navi.book.selectedIndex=0;}return;}

function linkto(text){if(""+document.navi.book.options[document.navi.book.selectedIndex].value+""=="none"){return;};var temp=new Array();var error=0;if(text.indexOf('-')>=0){temp=text.split('-');text=temp[0];};if(text.indexOf(':')>=0){temp=text.split(':');var chapter=temp[0];var verse=temp[1];if(!(verse>=1)||!(chapter>=1)||Math.floor(verse)!=verse||Math.floor(chapter)!=chapter){error=1;};}else{if(text>=1){var chapter=text;var verse=0;error=5;if(Math.floor(text)!=text){error=1;};};};text=""+text+"";text=removeSpaces(text);if(chapter==undefined&&text.length>0){error=1;};var bk=""+document.navi.book.options[document.navi.book.selectedIndex].value+"";temp=bk.split('.');bk=temp[0];var ind=-1;while(bk.indexOf("_")!=-1){ind=bk.indexOf("_");bk=bk.substring(0,ind)+" "+bk.substring(ind+1,bk.length);};if(chapter==undefined&&text.length==0){error=4;};if(error==0 || error==5){var err=new Array();err=checkcv(bk,chapter);if(err[0]!=0){error=2};var maxch=err[1];};
	
	switch(error)
	{	case 0:			/*CV ACTION*/
		var url="http://www.plainbible.com/"+document.navi.book.options[document.navi.book.selectedIndex].value+"#C"+chapter+"V"+verse+"";
		var place=""+bk+" "+chapter+":"+verse;
		var html="<a href="+'"'+url+'">'+place+"</a>";
		var dhtml="&lt;a href=&quot;"+url+"&quot;&gt;"+place+"&lt;/a&gt;";
		break;
		/*****************************************************************/
		case 1:			/*format error*/
		alert("FORMAT ERROR.  \n \nInstructions:\n\n1. Select from the drop down menu the book of the Bible you would like to link to. \n\n2. In the textbox, type either: \n\n    - nothing, to link to the book you selected. \n\n    - a number, to link to a chapter. [type 3 to link to chapter 3] \n\n    - number:number, to link to a certain verse. [type 3:16 to link to chapter 3 verse 16] \n\n3. Click the Create Link button.");
		return;
		break;
		case 2:			/*chapter error*/
		if(maxch>1)
			{alert("NOTE: \n"+bk+" has "+maxch+" chapters.  \n"+bk+" "+chapter+" doesn't exist.");}
		else{alert("NOTE: \n"+bk+" has 1 chapter.  \n"+bk+" "+chapter+" doesn't exist.");};
		return;
		break;
		case 4:			/*nothing entered*/
		var url="http://www.plainbible.com/"+document.navi.book.options[document.navi.book.selectedIndex].value+"";
		var place=""+bk+"";
		var html="<a href="+'"'+url+'">'+place+"</a>";
		var dhtml="&lt;a href=&quot;"+url+"&quot;&gt;"+place+"&lt;/a&gt;";
		break;
		case 5:			/*only chapter entered*/
		var url="http://www.plainbible.com/"+document.navi.book.options[document.navi.book.selectedIndex].value+"#C"+chapter+"V"+verse+"";
		var place=""+bk+" "+text;
		var html="<a href="+'"'+url+'">'+place+"</a>";
		var dhtml="&lt;a href=&quot;"+url+"&quot;&gt;"+place+"&lt;/a&gt;";
		break;
	;};
	document.write("<html><head><title>plainBIBLE.com | Link to "+place+"</title></head><body link=blue vlink=blue alink=blue>");
	document.write("<p>&nbsp;</p>");
	document.write("<p align='center'><font size=6 face='Georgia' color=#243969><b>Link Creation Results</b></font></p>");
	document.write("<p>&nbsp;</p>");
	document.write("<table bgcolor=#D3DEF5 align='center' cellpadding='10' cellspacing='0' style='font-family:verdana;font-size:12; border-width:1; border-color:rgb(95,123,184); border-style:solid;'><td style='border-bottom-width:1; border-bottom-color:rgb(95,123,184); border-right-style:none; border-bottom-style:solid;'><b><font color=#243969>LINK:</font></b></td><td style='border-bottom-width:1; border-bottom-color:rgb(95,123,184); border-right-style:none; border-bottom-style:solid;'>"+html+"&nbsp;&nbsp&nbsp;(Click to test verse existence.)</td style='border-bottom-width:1; border-bottom-color:rgb(95,123,184); border-right-style:none; border-bottom-style:solid;'></tr>");
	document.write("<tr><td style='border-bottom-width:1; border-bottom-color:rgb(95,123,184); border-right-style:none; border-bottom-style:solid;'><b><font color=#243969>URL:</font></b></td><td style='border-bottom-width:1; border-bottom-color:rgb(95,123,184); border-right-style:none; border-bottom-style:solid;'>"+url+"</td></tr>");
	document.write("<tr><td><b><font color=#243969>HTML:</font></b></td><td>"+dhtml+"</td></tr></table>");
	document.write("<p>&nbsp;</p>");
	document.write("<p align='center'><font face='Georgia'>Thank you.</font></p>");
	document.write("</body></html>");
;};

function checkcv(bk,chapter){var err=new Array();var error2=0;var maxch=0;switch(bk){case"Genesis":maxch=50;break;case"Exodus":maxch=40;break;case"Leviticus":maxch=27;break;case"Numbers":maxch=36;break;case"Deuteronomy":maxch=34;break;case"Joshua":maxch=24;break;case"Judges":maxch=21;break;case"Ruth":maxch=4;break;case"1 Samuel":maxch=31;break;case"2 Samuel":maxch=24;break;case"1 Kings":maxch=22;break;case"2 Kings":maxch=25;break;case"1 Chronicles":maxch=29;break;case"2 Chronicles":maxch=36;break;case"Ezra":maxch=10;break;case"Nehemiah":maxch=13;break;case"Esther":maxch=10;break;case"Job":maxch=42;break;case"Psalms":maxch=150;break;case"Proverbs":maxch=31;break;case"Ecclesiastes":maxch=12;break;case"Song of Solomon":maxch=8;break;case"Isaiah":maxch=6;break;case"Jeremiah":maxch=52;break;case"Lamentations":maxch=5;break;case"Ezekiel":maxch=48;break;case"Daniel":maxch=12;break;case"Hosea":maxch=14;break;case"Joel":maxch=3;break;case"Amos":maxch=9;break;case"Obadiah":maxch=1;break;case"Jonah":maxch=4;break;case"Micah":maxch=7;break;case"Nahum":maxch=3;break;case"Habakkuk":maxch=3;break;case"Zephaniah":maxch=3;break;case"Haggai":maxch=2;break;case"Zechariah":maxch=14;break;case"Malachi":maxch=4;break;case"Matthew":maxch=28;break;case"Mark":maxch=16;break;case"Luke":maxch=24;break;case"John":maxch=21;break;case"Acts":maxch=28;break;case"Romans":maxch=16;break;case"1 Corinthians":maxch=16;break;case"2 Corinthians":maxch=13;break;case"Galatians":maxch=6;break;case"Ephesians":maxch=6;break;case"Philippians":maxch=4;break;case"Colossians":maxch=4;break;case"1 Thessalonians":maxch=5;break;case"2 Thessalonians":maxch=3;break;case"1 Timothy":maxch=6;break;case"2 Timothy":maxch=4;break;case"Titus":maxch=3;break;case"Philemon":maxch=1;break;case"Hebrews":maxch=13;break;case"James":maxch=5;break;case"1 Peter":maxch=5;break;case"2 Peter":maxch=3;break;case"1 John":maxch=5;break;case"2 John":maxch=1;break;case"3 John":maxch=1;break;case"Jude":maxch=1;break;case"Revelation":maxch=22;break;};if(chapter>maxch){error2=2;};err[0]=error2;err[1]=maxch;return err;};function removeSpaces(string){var tstring="";string=''+string;splitstring=string.split(" ");for(i=0;i<splitstring.length;i++)tstring+=splitstring[i];return tstring;};

	