function switchLanguage() {
        if (document.output.authorLanguage.selectedIndex == 0) {
                document.output.authorVersion.options.length = 0;
                document.output.authorVersion.options[0] = new Option ("KJV","KJV");
                document.output.authorVersion.options[0].selected = true;
                document.output.authorVersion.options[1] = new Option ("NLT","NLT");
                document.output.authorVersion.options[2] = new Option ("KJ21","KJ21");
                document.output.authorVersion.options[3] = new Option ("NKJV","NKJV");
                document.output.authorVersion.options[4] = new Option ("NIV","NIV");
                document.output.authorVersion.options[5] = new Option ("NIV-IBS","NIVI-IBS");
                document.output.authorVersion.options[6] = new Option ("NASB","NASB");
                document.output.authorVersion.options[7] = new Option ("Darby","Darby");
                document.output.authorVersion.options[8] = new Option ("RSV","RSV");
                document.output.authorVersion.options[9] = new Option ("YLT","YLT");
                document.output.authorVersion.options[10] = new Option ("WE","WE");
                document.output.authorVersion.options[11] = new Option ("ALL","ALL");
        }
        else {
                document.output.authorVersion.options.length = 0;
                document.output.authorVersion.options[0] = new Option ("RVA","RVA");
                document.output.authorVersion.options[0].selected = true;
                document.output.authorVersion.options[1] = new Option ("NVI","NVI");
                document.output.authorVersion.options[2] = new Option ("All","All");
        }
}
function getFront(mainStr,searchStr) {
        foundOffset = mainStr.indexOf(searchStr);
        if (foundOffset == -1) {
                return null;
        }
        return mainStr.substring(0,foundOffset);
}
function getEnd(mainStr,searchStr) {
        foundOffset == mainStr.indexOf(searchStr);
        if (foundOffset == -1) {
                return null;
        }
        return mainStr.substring(foundOffset+searchStr.length,mainStr.length);
}
function insertString(mainStr,searchStr,insertStr) {
        var front = getFront(mainStr,searchStr);
        var end = getEnd(mainStr,searchStr);
        if (front != null && end != null) {
                return front + insertStr + searchStr + end;
        }
        return null;
}
function deleteString(mainStr,deleteStr) {
        return replaceString(mainStr,deleteStr,"");
}
function replaceString(mainStr,searchStr,replaceStr) {
        var front = getFront(mainStr,searchStr);
        var end = getEnd(mainStr,searchStr);
        if (front != null && end != null) {
                return front + replaceStr + end;
        }
        return null;
}
var preferredLanguage = "English";
var preferredVersion  = "KJV";
var theLink;
function makeArray(n) {
        this.length = n;
        return this;
}
/*
function Versions (num,v1,v2,v3,v4,v5,v6,v7,v8) {
        this.num     = num;
        this.v1 = v1;
        this.v2 = v2;
        this.v3 = v3;
        this.v4 = v4;
        this.v5 = v5;
        this.v6 = v6;
        this.v7 = v7;
        this.v8 = v8
}
function Books (Genesis,Exodus,Leviticus) {
        this.Genesis   = Genesis;
        this.Exodus    = Exodus;
        this.Leviticus = Leviticus;
}
*/
//function Languages (Language,num,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33,b34,b35,b36,b37,b38,b39,b40,b41,b42,b43,b44,b45,b46,b47,b48,b49,b50,b51,b52,b53,b54,b55,b56,b57,b58,b59,b60,b61,b62,b63,b64,b65,b66) {
function Languages (Language,num,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31,b32,b33,b34,b35,b36,b37,b38,b39,b40,b41,b42,b43,b44,b45,b46,b47,b48,b49,b50,b51,b52,b53,b54,b55,b56,b57,b58,b59,b60,b61,b62,b63,b64,b65,b66) {
        this.Language   = Language;
        this.num        = num;
        //this.Version    = new Versions(Version);
        this.Version    = new makeArray(parseInt(num));
        for (i=0;i<num;i++) {
                this.Version[i] = eval("v" + (i + 1));
        }
        this.Genesis     = b1;
        this.Exodus      = b2;
        this.Leviticus   = b3;
        this.Numbers     = b4;
        this.Deuteronomy = b5;
        this.Joshua      = b6;
        this.Judges      = b7;
        this.Ruth        = b8;
        this.Samuel1     = b9;
        this.Samuel2     = b10;
        this.Kings1      = b11;
        this.Kings2      = b12;
        this.Chronicles1 = b13;
        this.Chronicles2 = b14;
        this.Ezra        = b15;
        this.Nehemiah    = b16;
        this.Esther      = b17;
        this.Job         = b18;
        this.Psalms      = b19;
        this.Proverbs    = b20;
        this.Ecclesiastes = b21;
        this.SongofSolomon = b22;
        this.Isaiah        = b23;
        this.Jeremiah      = b24;
        this.Lamentations  = b25;
        this.Ezekiel       = b26;
        this.Daniel        = b27;
        this.Hosea         = b28;
        this.Joel          = b29;
        this.Amos          = b30;
        this.Obadiah       = b31;
        this.Jonah         = b32;
        this.Micah         = b33;
        this.Nahum         = b34;
        this.Habakkuk      = b35;
        this.Zephaniah     = b36;
        this.Haggai        = b37;
        this.Zechariah     = b38;
        this.Malachi       = b39;
        this.Matthew       = b40;
        this.Mark          = b41;
        this.Luke          = b42;
        this.John          = b43;
        this.Acts          = b44;
        this.Romans        = b45;
        this.Corinthians1  = b46;
        this.Corinthians2  = b47;
        this.Galatians     = b48;
        this.Ephesians     = b49;
        this.Philippians   = b50;
        this.Collossians   = b51;
        this.Thessalonians1 = b52;
        this.Thessalonians2 = b53;
        this.Timothy1       = b54;
        this.Timothy2       = b55;
        this.Titus          = b56;
        this.Philemon       = b57;
        this.Hebrews        = b58;
        this.James          = b59;
        this.Peter1         = b60;
        this.Peter2         = b61;
        this.John1          = b62;
        this.John2          = b63;
        this.John3          = b64;
        this.Jude           = b65;
        this.Revelation     = b66;
}
var languageTBL = new makeArray(2);
//languageTBL[0] = new Languages("English","8","NIV","NASB","RSV","KJV","Darby","YLT","WE","All","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","Habakkuk","Zephaniah","Haggai","Zechariah","Malachi","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");
//languageTBL[0] = new Languages("English","12","KJV","KJ21","NKJV","NIV","NIV-IBS","NASB","RSV","Darby","RSV","YLT","WE","All","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","Habakkuk","Zephaniah","Haggai","Zechariah","Malachi","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");
languageTBL[0] = new Languages("English","12","KJV","NLT","KJ21","NKJV","NIV","NIV-IBS","NASB","RSV","Darby","RSV","YLT","WE","All","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","Habakkuk","Zephaniah","Haggai","Zechariah","Malachi","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");
//----------------
languageTBL[1] = new Languages("Español","3","RVA","NVI","All","","","","","","","","","","Génesis","Exodo","Levítico","Números","Deuteronomio","Josué","Jueces","Rut","1 Samuel","2 Samuel","1 Reyes","2 Reyes","1 Crónicas","2 Crónicas","Esdras","Nehemías","Ester","Job","Salmos","Proverbios","Eclesiastés","Cantares","Isaías","Jeremías","Lamentaciones","Ezequiel","Daniel","Oseas","Joel","Amós","Abdías","Jonás","Miqueas","Nahúm","Habacuc","Sofonías","Hageo","Zacarías","Malaquías","Mateo","Marcos","Lucas","Juan","Hechos","Romanos","1 Corintios","2 Corintios","Gálatas","Efesios","Filipenses","Colosenses","1 Tesalonicenses","2 Tesalonicenses","1 Timoteo","2 Timoteo","Tito","Filemón","Hebreos","Santiago","1 Pedro","2 Pedro","1 Juan","2 Juan","3 Juan","Judas","Apocalipsis");
function selectOptions(L,V,B,T) { //Language,Version,Book,Text
        if (L <= "") L = preferredLanguage;
        if (V <= "") V = preferredVersion;
        for (i=0;i<languageTBL.length;i++) {
                if (languageTBL[i].Language == L) break;
        }
        for (j=0;j<languageTBL[i].num;j++) {
                if (languageTBL[i].Version[j] == V) break;
        }
        theLink = "<a href='http://bible.gospelcom.net/bible?language=" + languageTBL[i].Language + "&version=" + languageTBL[i].Version[j] + "&passage=" + eval("languageTBL[i]." + B) + "+" + T + "'>" + eval("languageTBL[i]." + B) + " " + T + "</a>";
//alert(theLink);
document.output.field.value = theLink;
//document.execCommand("Paste",false,temp);
}
//function showThis(v) {
function showThis(L,V,B,T) {
        L = "";
        V = "";
        //B = document.output.elements[v].value;
        //T = document.output.elements[v+1].value;
        if (L <= "") L = preferredLanguage;
        if (V <= "") V = preferredVersion;
        for (i=0;i<languageTBL.length;i++) {
                if (languageTBL[i].Language == L) break;
        }
        for (j=0;j<languageTBL[i].num;j++) {
                if (languageTBL[i].Version[j] == V) break;
        }
        //theLink = '<a href="http://bible.gospelcom.net/bible?language=' + languageTBL[i].Language + '&version=' + languageTBL[i].Version[j] + '&passage=' + eval("languageTBL[i]." + B) + '+' + T + '">' + eval("languageTBL[i]." + B) + ' ' + T + '</a>';
        //document.theForm.url.value = eval("languageTBL[i]." + B);
        theLink = "<a href=\"http://bible.gospelcom.net/bible?language=" + languageTBL[i].Language + "&version=" + languageTBL[i].Version[j] + "&passage=" + eval("languageTBL[i]." + B) + "+" + T + "\">" + eval("languageTBL[i]." + B) + " " + T + "</a>";
        
        //theLink = escape(theLink); //July 2001
//document.execCommand("Paste",false,theLink);
//bareLink = "http://bible.gospelcom.net/bible?language=" + languageTBL[i].Language + "&version=" + languageTBL[i].Version[j] + "&passage=" + eval("languageTBL[i]." + B) + "+" + T 
//document.execCommand("CreateLink",false,bareLink);
//document.execCommand("Paste",false,document.output.displayText.value);
/*document.execCommand("CreateLink",false,bareLink);*/
//alert(theLink);
//--------------;

aL = document.output.authorLanguage[document.output.authorLanguage.selectedIndex].value;
aV = document.output.authorVersion[document.output.authorVersion.selectedIndex].value;

//aL = preferredLanguage;
//aV = preferredVersion;
//L = "";
//V = "";
if (aL != preferredLanguage) L = aL;
if (aV != preferredVersion)  V = aV;
if (L > "" || V > "") {
        if (L <= "") L = preferredLanguage;
        if (V <= "") V = preferredVersion;
        for (i=0;i<languageTBL.length;i++) {
                if (languageTBL[i].Language == L) break;
        }
        for (j=0;j<languageTBL[i].num;j++) {
                if (languageTBL[i].Version[j] == V) break;
        }
        aLink = "<a href='http://bible.gospelcom.net/bible?language=" + languageTBL[i].Language + "&version=" + languageTBL[i].Version[j] + "&passage=" + eval("languageTBL[i]." + B) + "+" + T + "'>" + languageTBL[i].Version[j] + "</a>";
theLink = theLink + " (" + aLink + ")";
}
//document.output.displayLink.value = theLink;
//document.execCommand("Paste",false,temp);
}
function setBook(v) {
        document.output.elements[v].value = document.output.book[document.output.book.selectedIndex].value;
}
function testLink() {
        theLink = document.output.field.value;
        theLink = theLink.substring(9,theLink.length);
        pos     = theLink.indexOf("'>");
        theLink = theLink.substring(0,pos);
        window.location = theLink;
        //document.output.field.value = theLink;
}
function testAuthorLink() {
        theLink = document.output.field.value;
        //theLink = theLink.substring(9,theLink.length);
        pos     = theLink.indexOf("</a>");
        theLink = theLink.substring(pos + 6,theLink.length);
        theLink = theLink.substring(9,theLink.length);
        pos     = theLink.indexOf("'>");
        theLink = theLink.substring(0,pos);
        document.output.displayLink.value = theLink;
        //window.location = theLink;
}
function process() {
        //theFile = document.output.inText.value;
        //theFile = document.output.displayText.value;
        theFile = edit.innerHTML;
        //theFile = edit.document.selection.createRange();
        //BibleSpos = theFile.indexOf("<bible>");
        BibleSpos = theFile.indexOf("[bible]");
        //BibleSpos = 0;
        //BibleSpos = theFile.indexOf("<b>");
        //document.write ("Pos:" + BibleSpos + "<br>");
        //while (BibleSpos > 0) {
        while (BibleSpos > 0) {
                //pos = BibleSpos + 7;
                pos = BibleSpos + 3;
                pos = BibleSpos + 7;
                pos1 = pos;
                //pos = BibleSpos
                theString = theFile.substring(pos,theFile.length);
                //document.output.displayText.value = theString;
//              pos = theString.indexOf("</bible>");
                pos = theString.indexOf("[/bible]");
//              pos = theString.length;
                //pos = theString.indexOf(";") - 1;
                //pos = theString.indexOf("</b>");
                pos2 = pos;
                //BibleEpos = pos + 8 + BibleSpos + 7;
                //BibleEpos = pos + 4 + BibleSpos + 3;
                BibleEpos = pos + 8 + BibleSpos + 7;
                //BibleEpos = pos + 1;
                //BibleEPos = pos;
                theString = theString.substring(0,pos);
                //document.output.displayText.value = theString;
                pos = theString.indexOf(" ");
                B = theString.substring(0,pos);
                T = theString.substring(pos + 1,theString.length);
                if (B == "1" || B == "2" || B == "3") { // section added July 2001
                        pos = T.indexOf(" ");
                        B = T.substring(0,pos) + B;
                        T = T.substring(pos + 1,T.length);
                }
                showThis("","",B,T);
                theLink = "&nbsp;" + theLink + "&nbsp;";
                //theString = theFile.substring(BibleSpos,BibleEpos);
                //theString = theFile.substring(pos1,pos2);
                longString = theFile.substring(BibleSpos,BibleEpos);
                //theLink = replaceString(theLink,longString,theString);
                //document.output.displayText.value = theString;
                //theFile = replaceString(theFile,theString,theLink);
                theFile = replaceString(theFile,longString,theLink);
                //document.write (theFile);
                //BibleSpos = theFile.indexOf("<bible>");
                //BibleSpos = theFile.indexOf("<b>");
                BibleSpos = theFile.indexOf("[bible]");
        }
        BibleSpos = theFile.indexOf("\r\n\r\n");
        //BibleSpos = theFile.indexOf("%0D%0A");
        while (BibleSpos > 0) {
                //theFile = replaceString(theFile,"%0D%0A","<p>");
                //BibleSpos = theFile.indexOf("%0D%0A");
                theFile = replaceString(theFile,"\r\n\r\n","<br> <p>");
                BibleSpos = theFile.indexOf("\r\n\r\n");
        }
        BibleSpos = theFile.indexOf("\n");
        //BibleSpos = theFile.indexOf("%0D%0A");
        while (BibleSpos > 0) {
                //theFile = replaceString(theFile,"%0D%0A","<br>");
                //BibleSpos = theFile.indexOf("%0D%0A");
                theFile = replaceString(theFile,"\n","<br>");
                BibleSpos = theFile.indexOf("\n");
        }
/*      BibleSpos = theFile.indexOf("  ");
        while (BibleSpos > 0) {
                theFile = replaceString(theFile,"  ","&nbsp;&nbsp;");
                BibleSpos = theFile.indexOf("  ");
        }*/
        //document.output.out2Text.value = theFile;
        edit.innerHTML = theFile;
        /*document.output.submit(); */
                
}
function insertBook() {
        temp = "<bible>" + document.output.book[document.output.book.selectedIndex].value + " </bible>";
        temp = "[bible]" + document.output.book[document.output.book.selectedIndex].value + " [/bible]";
        //temp = document.output.book[document.output.book.selectedIndex].value; + ";"

        /*document.output.inText.value = document.output.inText.value + temp;*/
        //document.output.inText.value = temp;
        //document.output.displayText.value = temp;
        document.execCommand("Paste",false,temp);
        //edit.innerHTML = temp;
        
}

