
var verses = new Array(
	"Romans 14:18/For he that in these things serveth Christ is /acceptable to God/, and approved of men.",
 	"Romans 15:4/For whatsoever things were written aforetime were /written for our learning/, that we through patience and comfort of the scriptures might have hope.",
 	"Romans 15:5-6/Now the God of patience and consolation grant you to /be likeminded one toward another/ according to Christ Jesus: That ye may with one mind and one mouth glorify God, even the Father of our Lord Jesus Christ.",
 	"Romans 16:25-27/Now to him that is of power to stablish you according to my gospel, and the preaching of Jesus Christ, according to the revelation of the mystery, which was kept secret since the world began,<br> But now is made manifest, and by the scriptures of the prophets, /according to the commandment of the everlasting God/, made known to all nations for the obedience of faith:<br> To God only wise, be glory through Jesus Christ for ever. Amen.",
	"I Corinthians 1:4-8//I thank my God always on your behalf/, for the grace of God which is given you by Jesus Christ;<br> That in every thing ye are enriched by him, in all utterance, and in all knowledge;<br> Even as the testimony of Christ was confirmed in you:<br> So that ye come behind in no gift; waiting for the coming of our Lord Jesus Christ:<br> Who shall also confirm you unto the end, that ye may be blameless in the day of our Lord Jesus Christ.",

	"I Corinthians 1:9//God is faithful/, by whom ye were called unto the fellowship of his Son Jesus Christ our Lord.",
	"I Corinthians 1:18/For the preaching of the cross is to them that perish /foolishness/; but unto us which are saved it is the power of God.",
	"I Corinthians 1:21/For after that in the wisdom of God /the world by wisdom knew not God/, it pleased God by the foolishness of preaching to save them that believe.",
	"I Corinthians 1:23-24/But /we preach Christ crucified/, unto the Jews a stumblingblock, and unto the Greeks foolishness; But unto them which are called, both Jews and Greeks, Christ the power of God, and the wisdom of God.",
	"I Corinthians 1:25/Because /the foolishness of God is wiser than men/; and the weakness of God is stronger than men.",

	"I Corinthians 1:27-29/But God hath chosen the foolish things of the world to confound the wise; and God hath chosen the weak things of the world to confound the things which are mighty; And base things of the world, and things which are despised, hath God chosen, yea, and things which are not, to bring to nought things that are: /That no flesh should glory in his presence/.",
	"I Corinthians 1:30-31//But of him are ye in Christ Jesus/, who of God is made unto us wisdom, and righteousness, and sanctification, and redemption: That, according as it is written, He that glorieth, let him glory in the Lord.",
	"I Corinthians 2:1-2/And I, brethren, when I came to you, came /not with excellency of speech or of wisdom/, declaring unto you the testimony of God. For I determined not to know any thing among you, save Jesus Christ, and him crucified.",
	"I Corinthians 2:4-5/And my speech and my preaching was /not with enticing words of man&#146;s wisdom/, but in demonstration of the Spirit and of power: That your faith should not stand in the wisdom of men, but in the power of God.",
	"I Corinthians 2:12/Now we have received, not the spirit of the world, but the spirit which is of God; /that we might know/ the things that are freely given to us of God.",

	"I Corinthians 2:14/But the natural man receiveth not the things of the Spirit of God: for they are foolishness unto him: neither can he know them, because /they are spiritually discerned/.",
	"I Corinthians 3:11/For /other foundation can no man lay/ than that is laid, which is Jesus Christ.",
	"I Corinthians 3:12-15/Now if any man build upon this foundation /gold, silver, precious stones, wood, hay, stubble/; Every man&#146;s work shall be made manifest: for the day shall declare it, because it shall be revealed by fire; and the fire shall try every man&#146;s work of what sort it is. If any man&#146;s work abide which he hath built thereupon, he shall receive a reward. If any man&#146;s work shall be burned, he shall suffer loss: but he himself shall be saved; yet so as by fire.",
	"I Corinthians 3:18-20//Let no man deceive himself/. If any man among you seemeth to be wise in this world, let him become a fool, that he may be wise. For the wisdom of this world is foolishness with God. For it is written, He taketh the wise in their own craftiness. And again, The Lord knoweth the thoughts of the wise, that they are vain.",
	"I Corinthians 4:2/Moreover /it is required in stewards/, that a man be found faithful.",

	"I Corinthians 6:9-11/Know ye not that /the unrighteous shall not inherit the kingdom of God/? Be not deceived: neither fornicators, nor idolaters, nor adulterers, nor effeminate, nor abusers of themselves with mankind, Nor thieves, nor covetous, nor drunkards, nor revilers, nor extortioners, shall inherit the kingdom of God. And such were some of you: but ye are washed, but ye are sanctified, but ye are justified in the name of the Lord Jesus, and by the Spirit of our God.",
	"I Corinthians 6:12/All things are lawful unto me, but all things are not expedient: /all things are lawful for me/, but I will not be brought under the power of any.",
	"I Corinthians 6:19-20/What? know ye not that /your body is the temple of the Holy Ghost/ which is in you, which ye have of God, and ye are not your own? For ye are bought with a price: therefore glorify God in your body, and in your spirit, which are God&#146;s.",
	"I Corinthians 8:5-6/For though there be that are called gods, whether in heaven or in earth, (as there be gods many, and lords many,) But to us /there is but one God/, the Father, of whom are all things, and we in him; and one Lord Jesus Christ, by whom are all things, and we by him.",
	"I Corinthians 9:24-27/Know ye not that they which run in a race run all, but one receiveth the prize? So run, that ye may obtain. And every man that striveth for the mastery is temperate in all things. Now they do it to obtain a corruptible crown; but we an incorruptible. I therefore so run, not as uncertainly; so fight I, /not as one that beateth the air/: But I keep under my body, and bring it into subjection: lest that by any means, when I have preached to others, I myself should be a castaway.",

	"I Corinthians 10:11-12/Now all these things happened unto them for ensamples: and they are written for our admonition, upon whom the ends of the world are come. Wherefore /let him that thinketh he standeth take heed lest he fall/.",
	"I Corinthians 10:13/There hath no temptation taken you but such as is common to man: but God is faithful, who will not suffer you to be tempted above that ye are able; but will with the temptation also make /a way to escape/, that ye may be able to bear it.",
	"I Corinthians 10:20/But I say, that the things which the Gentiles sacrifice, /they sacrifice to devils/, and not to God: and I would not that ye should have fellowship with devils.",
	"I Corinthians 10:23-24/All things are lawful for me, but all things are not expedient: /all things are lawful for me/, but all things edify not. Let no man seek his own, but every man another&#146;s wealth.",
	"I Corinthians 10:31/Whether therefore ye eat, or drink, or whatsoever ye do, /do all to the glory of God/.",

	"I Corinthians 11:23-26/For I have received of the Lord that which also I delivered unto you, That the Lord Jesus the same night in which he was betrayed took bread: And when he had given thanks, he brake it, and said, /Take, eat: this is my body/, which is broken for you: this do in remembrance of me. After the same manner also he took the cup, when he had supped, saying, This cup is the new testament in my blood: this do ye, as oft as ye drink it, in remembrance of me. For as often as ye eat this bread, and drink this cup, ye do shew the Lord&#146;s death till he come."
);

var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

var thisDate= new Date();
var theMonth=thisDate.getMonth();	// 0...11
var theDay=thisDate.getDate();		// 1...31
var theYear=thisDate.getFullYear();	// 2003, etc.
var theDOW = thisDate.getDay();		// 0...6
var verseIndex = theDay - 1;		// 0...30


function getRef(d)
{
	var verse = verses[d].split("/");
	
	return verse[0];
}

function formTease(t)
{
	var firstchar = t.charAt(0);
	var lastchar = t.slice(-1);
	var leftdots = (firstchar >= "A" && firstchar <= "Z") ? "" : "..."
	var rightdots = (lastchar == "." || lastchar == "?") ? "" : "...";
	return leftdots + t + rightdots;
}

function getTease(d)
{
	var verse = verses[d].split("/");
	
	// There should be 4 or 6 elements in the array.
	// 4: reference/leftpart/tease/right
	// 6: reference/left/tease1/middle/tease2/right
	
	tease = formTease(verse[2]);
	if (verse.length == 6) {
		tease += "<br>" + formTease(verse[4]);
	} 
	else if (verse.length != 4) {
		tease = "???";
	}
	return tease;
}

function getVerse(d)
{
	var verse = verses[d].split("/");
	var strout = verse[1];
	for (var i=2; i<verse.length; i++) {
		strout += verse[i];
	}
	return strout;
}

function doHeading(head, str)
{
	document.writeln("<h" + head + " align='center'>" + str + "</h" + head + ">");
}

function doVerse()
{
	doHeading(3, dayNames[theDOW]);
	document.writeln("<h3 align='center'>" + theDay + " " + monthNames[theMonth] + " " + theYear + "</h3>");
	document.writeln(getVerse(verseIndex));
	gatewayURL(getRef(verseIndex));
}
function verseOTD()
{
	document.writeln(getTease(verseIndex) + "<br><a href='javascript:showVerse();'>" + getRef(verseIndex) + "</a>");
}

var showingVerse = false;

function showVerse()
{
	votdElem = false;
	if (document.getElementById) {
		votdElem = document.getElementById("verse-here");
	}
	if (votdElem) {
		if (!showingVerse) {
			vod = "<table style='background-color:#ffeedd; padding: 5px; border: 1px solid #cccccc;'>";
			vod += "<tr><th align='center'>"
			vod += "Verse of the Day";
			vod += "<tr><th align='center'>" + dayNames[theDOW] + ", " + monthNames[theMonth] + " " + theDay + ", " + theYear;
			vod += "<tr><td>" + getVerse(verseIndex);
			vod += "<tr><td align=\"right\">" + "<a href=\"http://www.biblegateway.com/bible?language=english&version=KJV&passage=";
			vod += escape(getRef(verseIndex));
			vod += "\" target=\"_new\">";
			vod += getRef(verseIndex);
			vod += "</a>";
			votdElem.innerHTML = vod;
			showingVerse = true;
		} else {
			votdElem.innerHTML = "&nbsp;";
			showingVerse = false;
		}
	} else {
		len = getVerse(verseIndex).length;
		width = len > 200 ? 400 : 300;
		height = len > 350 ? 400 : 300;
		window.open("verse.html", "_votd_", "width=" + width + ", height=" + height + ", resizable=yes");
	}
}

function gatewayURL(reference)
{
	ref = "<a href=\"http://www.biblegateway.com/bible?language=english&version=KJV&passage=";
	// replace spaces with plusses
	plussedRef = reference.replace(/[ ]/g, "+");
	ref += plussedRef;
	ref += "\" target=\"_new\">";
	document.write(ref);
	doHeading(3, reference);
	document.writeln("</a>");
}

function testVerse(d)
{
	document.write("<br><br>");
	document.writeln((d+1) + " -- " + getTease(d) + "<br><a href='javascript:showVerse();'>" + getRef(d) + "</a>");
	document.write("<br>" + getVerse(d));
}

function testVerses()
{
	for (var j=0; j<verses.length; j++) {
		testVerse(j);
	}
}
