// JavaScript: BibleFunctions.js
// Written by: Chris R Ford

// 08/13/2011: Add verse2 argument to Bible Reader.
// 03/21/2010: Add DayCalculator routines for Seventy-Weeks math page.
// 10/25/2009: Define first BibleReaderBox as 'root'.
//           : Handle directory 'x' to support move to new server.
// 08/22/2009: Change table background color to Light Gray.
// 08/01/2009: Add NewWin function (now removed)
// 05/29/2008: For Bible Search box, correct setting of Rev.
// 05/19/2008: References to Bible_Reader changed to Bible_Read.
// 02/16/2008: Implementation

// PageLastModified  - Displays Page Last Modified Date.
// BibleReaderBox    - Displays a standard form box for Bible Reader access.
// BibleSearchBox    - Displays a standard form box for Bible Search access.
// BibleSchedulerBox - Displays a standard form box for Bible Scheduler access.
// DayCalculator     - Scripts for days between dates - written by Steve Evans

// Define Global Variables

    var bgcolor = "#C8C8C8"; // Light Gray
    
    var books = new Array (
                "Gen", "Exo", "Lev", "Num", "Deu", "Jos", "Jdg", "Rth", "1Sa", "2Sa", "1Ki", "2Ki", "1Ch", "2Ch", 
                "Ezr", "Neh", "Est", "Job", "Psa", "Pro", "Ecc", "Son", "Isa", "Jer", "Lam", "Eze", "Dan", "Hos", 
                "Joe", "Amo", "Oba", "Jon", "Mic", "Nah", "Hab", "Zep", "Hag", "Zec", "Mal", 
                "Mat", "Mar", "Luk", "Joh", "Act", "Rom", "1Co", "2Co", "Gal", "Eph", "Php", "Col", "1Th", "2Th", 
                "1Ti", "2Ti", "Tit", "Phm", "Heb", "Jas", "1Pe", "2Pe", "1Jo", "2Jo", "3Jo", "Jud", "Rev");


    var df = 1; //date format mm/dd/yyyy
    
    //<<**Custom Date object
    //Thanks to Claus Tøndering for the Julian day algorithm
    //http://www.tondering.dk/claus/calendar.html
    var GREGORIAN = 0;
    var JULIAN = 1;
    var year = 0;
    var month = 0;
    var day = 0;
    var julianday = 0.0;
    var modifiedjulianday = 0.0;

//-------------------------------------------------------------------------------------------
function PageLastModified()
{
  document.write("Page last modified ");
  document.writeln(document.lastModified);
}
  
//-------------------------------------------------------------------------------------------
function BibleReaderBox(in_path, in_book, in_chap, in_verse, in_verse2, in_harmonyref)
{
    var versefav = new Array (
                "Joh 3 16", "Rom 10 8 10", "Psa 100", "Gal 5 22 23", "Gen 3 15", "Zec 2 8", "Pro 3 5 6", "Psa 37 3 6", "Psa 118 22 24",
                "Psa 119 103", "Isa 40 31", "Isa 55 11", "Mat 7 7", "Joh 3 3", "Joh 20 21", "Act 4 12", "Rev 3 20", 
                "Joh 14 6", "Act 17 11", "Rom 1 16", "Heb 11 6", "Rom 12 2", "Rom 11 33", "Rom 13 11", "1Co 1 18",
                "1Co 1 27", "1Co 2 14", "1Co 15 3", "2Co 2 14", "1Co 15 26", "1Co 15 57", "2Co 4 18", "2Co 5 17",
                "Gal 2 16", "Col 1 27", "Heb 13 15", "Eph 5 20", "Php 4 19", "Col 3 1", "Col 3 15", "1Th 2 13", "1Th 5 23",
                "Heb 10 36", "Jas 5 8", "1Pe 1 3", "1Pe 1 23", "2Co 10 5", "1Pe 5 6", "2Pe 1 16", "1Jo 3 2",
                "1Jo 4 4", "Psa 23");

// When no book/chapter/verse passed in, initially display a random favorite verse on the form.

if (in_book > "") {
    toc_ref = "#" + in_book + in_chap + ":1";
}
else {
    toc_ref = "";
    var versefav_tot = versefav.length;
    var rand = Math.random();
    rand = rand * versefav_tot;
    rand = Math.ceil(rand) - 1;
    var versefav_str  = versefav[rand];
    var versefav_word = versefav_str.split(" ");
    in_book   = versefav_word[0];
    in_chap   = versefav_word[1];
    in_verse  = versefav_word[2];
    in_verse2 = versefav_word[3];
}

// Write the box form.

    document.write("    <form method=\"post\" action=\"http://www.heavensmuse.com/x/cgi-bin/bible_read.cgi\">");
    document.write("    <table border=\"1\" cellpadding=\"2\" style=\"background-color:" + bgcolor + "\"");
    document.write("        cellspacing=\"2\" align=\"center\">");

    document.write("        <tr>");
    document.write("            <td colspan=\"7\" class=\"style12\" style=\"text-align: center\">");
    if (in_path == "href=\"x/") {
        document.write("                <a href=\"x/bible/reader.htm\" title=\"Bible Reader\"><span>Read</span></a> | ");
        document.write("                <a href=\"x/bible/search.htm\" title=\"Bible Search\"><span>Search</span></a> | ");
        document.write("                <a href=\"x/bible/toc.htm" + toc_ref + "\" title=\"Table of Contents\"><span>TOC</span></a>");
    }
    else {
        document.write("                <a href=\"../bible/reader.htm\" title=\"Bible Reader\"><span>Read</span></a> | ");
        document.write("                <a href=\"../bible/search.htm\" title=\"Bible Search\"><span>Search</span></a> | ");
        document.write("                <a href=\"../bible/toc.htm" + toc_ref + "\" title=\"Table of Contents\"><span>TOC</span></a>");
    }

// Include harmony reference link if passed in.

    if (in_harmonyref > "") {
        document.write("                | <a href=\"../bible/harmony.htm#" + in_harmonyref + "\" title=\"Gospel Harmony\"><span>Harmony</span></a>");
    }
    document.write("            </td>");
    document.write("        </tr>");
    document.write("        <tr>");

// Create the book list (and mark the selected book for initial display).

    document.write("            <td>");
    document.write("                <select name=\"book\">");

for( var i = 0; i < 66; i++) {
    select_flag = '';
    if (in_book == books[i]) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + books[i] + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");

// Create the chapter list (and mark the selected chapter for initial display).

    document.write("            <td>");
    document.write("                <select name=\"chap\">");

for( var i = 1; i <= 150; i++) {
    select_flag = '';
    if (in_chap == i) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + i + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                :");
    document.write("            </td>");

// Create the verse list (and mark the selected verse for initial display).

    document.write("            <td>");
    document.write("                <select name=\"verse\">");
    document.write("                    <option></option>");

for( var i = 1; i <= 176; i++) {
    select_flag = '';
    if (in_verse == i) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + i + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td style=\"text-align: center\">");
    document.write("                -");
    document.write("            </td>");

// Create the verse2 list (and mark the selected verse for initial display).

    document.write("            <td>");
    document.write("                <select name=\"verse2\">");
    document.write("                    <option></option>");

for( var i = 1; i <= 176; i++) {
    select_flag = '';
    if (in_verse2 == i) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + i + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");
    
    document.write("            <td style=\"text-align: right\">");
    document.write("                <input id=\"submit0\" type=\"submit\" value=\"Go\" />");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("");
    document.write("    </table>");
    document.write("    </form>");

  return;
}

//-------------------------------------------------------------------------------------------
function BibleSearchBox(in_opt1, in_opt2, in_opt3, in_opt4, in_opt5, in_opt6, in_opt7)
{

// Write the box form.

    document.write("    <form method=\"post\" action=\"http://www.heavensmuse.com/x/cgi-bin/bible_search.cgi\">");
    document.write("    <table border=\"1\" cellpadding=\"2\" style=\"background-color:" + bgcolor + "\"");
    document.write("        cellspacing=\"2\" align=\"center\">");

    document.write("        <tr>");

    document.write("            <td style=\"text-align: right\">");
    document.write("                Words:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td colspan=\"4\">");
    document.write("                <input type=text name=\"words\" size=\"60\" value=\"" + in_opt1 + "\">");
    document.write("            </td>");
    document.write("        </tr>");

    chk1 = '';
    chk2 = '';
    chk3 = '';
    switch(in_opt2) {
        case "1" : chk1 = 'checked'; break;
        case "2" : chk2 = 'checked'; break;
        case "3" : chk3 = 'checked'; break;
        default  : chk1 = 'checked';
    }
    
    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Match:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td colspan=\"4\">");
    document.write("                <input type=radio name=\"type\" value=\"all\" "   + chk1 + ">All words");
    document.write("                <input type=radio name=\"type\" value=\"any\" "   + chk2 + ">Any word");
    document.write("                <input type=radio name=\"type\" value=\"exact\" " + chk3 + ">Exact phrase"); 
    document.write("            </td>");
    document.write("        </tr>");

    chk1 = '';
    chk2 = '';
    switch(in_opt3) {
        case "1" : chk1 = 'checked'; break;
        case "2" : chk2 = 'checked'; break;
        default  : chk1 = 'checked';
    }

    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                ");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td colspan=\"4\">");
    document.write("                <input type=radio name=\"partial\" value=\"n\" " + chk1 + ">Complete words");
    document.write("                <input type=radio name=\"partial\" value=\"y\" " + chk2 + ">Partial words");
    document.write("            </td>");
    document.write("        </tr>");

    chk1 = '';
    chk2 = '';
    chk3 = '';
    switch(in_opt4) {
        case "1" : chk1 = 'checked'; break;
        case "2" : chk2 = 'checked'; break;
        case "3" : chk3 = 'checked'; break;
        default  : chk1 = 'checked';
    }

    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Search Range:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td colspan=\"4\">");
    document.write("                <input type=radio name=\"range\" value=\"all\" " + chk1 + ">Entire Bible");
    document.write("                <input type=radio name=\"range\" value=\"OT\" "  + chk2 + ">Old Testament");
    document.write("                <input type=radio name=\"range\" value=\"NT\" "  + chk3 + ">New Testament"); 
    document.write("            </td>");
    document.write("        </tr>");

    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Or:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Starting at:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"bookbeg\">");

for( var i = 0; i < 66; i++) {
    if (books[i] == 'Gen') {
        select_flag = '';
        if (in_opt5 == 'x') {
            select_flag = ' selected';
        }
        document.write("                    <option" + select_flag + "> </option>");
    }
    select_flag = '';
    if (in_opt5 == books[i]) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + books[i] + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");

    document.write("            <td style=\"text-align: right\">");
    document.write("                Ending at:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"bookend\">");

for( var i = 0; i < 66; i++) {
    select_flag = '';
    if (in_opt6 == books[i]) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + books[i] + "</option>");
    if (books[i] == 'Rev') {
        select_flag = '';
        if (in_opt6 == 'x') {
            select_flag = ' selected';
        }
        document.write("                    <option" + select_flag + "> </option>");
    }
}
    document.write("                </select>");
    document.write("            </td>");
    document.write("        </tr>");

    chk1 = '';
    chk2 = '';
    chk3 = '';
    chk4 = '';
    chk5 = '';
    switch(in_opt7) {
        case "1" : chk1 = 'checked'; break;
        case "2" : chk2 = 'checked'; break;
        case "3" : chk3 = 'checked'; break;
        case "4" : chk4 = 'checked'; break;
        case "5" : chk5 = 'checked'; break;
        default  : chk4 = 'checked';
    }

    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Display Limit:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td colspan=\"4\">");
    document.write("                <input type=radio name=\"dispmax\" value=\"10\" "   + chk1 + ">10");
    document.write("                <input type=radio name=\"dispmax\" value=\"50\" "   + chk2 + ">50");
    document.write("                <input type=radio name=\"dispmax\" value=\"100\" "  + chk3 + ">100");
    document.write("                <input type=radio name=\"dispmax\" value=\"500\" "  + chk4 + ">500");
    document.write("                <input type=radio name=\"dispmax\" value=\"1000\" " + chk5 + ">1000 matches");
    document.write("            </td>");
    document.write("        </tr>");

    document.write("        <tr>");
    document.write("            <td style=\"text-align: center\" colspan=\"5\">");
    document.write("                <input id=\"submit\" type=\"submit\" value=\"Search\" />");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("    </table>");
    document.write("</form>");

  return;
}

//-------------------------------------------------------------------------------------------
function BibleSchedulerBox()
{
    var months = new Array (
                "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
                
    var now = new Date();
    var dd  = now.getDate();
    var mm  = now.getMonth();
    mm      = months[mm];

// Write the box form.

    document.write("    <form method=\"post\" action=\"http://www.heavensmuse.com/x/cgi-bin/bible_scheduler.cgi\">");
    document.write("    <table border=\"1\" cellpadding=\"2\" style=\"background-color:" + bgcolor + "\"");
    document.write("        cellspacing=\"2\" align=\"center\">");

    document.write("        <tr>");

    document.write("            <td style=\"text-align: right\">");
    document.write("                Starting On:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Month:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"mon\">");

for( var i = 0; i < 12; i++) {
    select_flag = '';
    if (mm == months[i]) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + months[i] + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");
            
// Create the book list.

    document.write("            <td style=\"text-align: right\">");
    document.write("                Book:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"book\">");

for( var i = 0; i < 66; i++) {
    document.write("                    <option>" + books[i] + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");

    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td>");
    document.write("            </td>");

    document.write("            <td style=\"text-align: right\">");
    document.write("                Day:");
    document.write("            </td>");
    document.write(" ");
    document.write("            <td>");
    document.write("                <select name=\"day\">");

for( var i = 1; i <= 31; i++) {
    select_flag = '';
    if (dd == i) {
        select_flag = ' selected';
    }
    document.write("                    <option" + select_flag + ">" + i + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");

// Create the chapter list.

    document.write("            <td style=\"text-align: right\">");
    document.write("                Chapter:");
    document.write("            </td>");

    document.write("            <td>");
    document.write("                <select name=\"chap\">");

for( var i = 1; i <= 150; i++) {
    document.write("                    <option>" + i + "</option>");
}
    document.write("                </select>");
    document.write("            </td>");

    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td>");
    document.write("            </td>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Year:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"year\">");
    document.write("                    <option></option>");
    document.write("                    <option value=\"0\">This Year</option>");
    document.write("                    <option value=\"1\">Next Year</option>");
    document.write("                    <option value=\"-1\">Last Year</option>");
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td colspan=\"2\">");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\" colspan=\"2\">");
    document.write("                Display Day-of-Week:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"dofw\">");
    document.write("                    <option value=\"1\">Yes</option>");
    document.write("                    <option value=\"0\">No</option>");
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td colspan=\"2\">");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\" colspan=\"2\">");
    document.write("                Schedule Format:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"fmt\">");
    document.write("                    <option value=\"C\">Calendar</option>");
    document.write("                    <option value=\"L\">Listing</option>");
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td style=\"text-align: right\">");
    document.write("                Font Size:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"size\">");
    document.write("                    <option value=\"-2\">Small</option>");
    document.write("                    <option value=\"-1\">Medium</option>");
    document.write("                    <option value=\"+1\">Large</option>");
    document.write("                </select>");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td style=\"text-align: right\" colspan=\"2\">");
    document.write("                Week Starts On:");
    document.write("            </td>");
    document.write("            <td>");
    document.write("                <select name=\"begd\">");
    document.write("                    <option value=\"0\">Sun</option>");
    document.write("                    <option value=\"1\">Mon</option>");
    document.write("                </select>");
    document.write("            </td>");
    document.write("            <td colspan=\"2\">");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("        <tr>");
    document.write("            <td style=\"text-align: center\" colspan=\"5\">");
    document.write("                <input id=\"submit\" type=\"submit\" value=\"Generate Reading Schedule\" />");
    document.write("            </td>");
    document.write("        </tr>");
    document.write("    </table>");
    document.write("</form>");

  return;
}

//-------------------------------------------------------------------------------------------

// Scripts for days between dates
// The Javascript Date object is buggy, so a custom date object is included.

// written by Steve Evans - www.msevans.com

function ipart(r){ return Math.round(r - 0.5) }
function getJulianDay(){ return this.julianday } 
function getModifiedJulianDay(){ return this.modifiedjulianday }

function CustomDate(yr, mo, da, type){
  year = yr * 1.0;  //convert string to float
  if (year < -4713 || year > 3268){
    alert("Year out of range");
	document.datainput.dateerr.value="??"
    return;
  }
  month = mo * 1.0;
  day = da * 1.0;
  if (year == 1582 && month == 10 && day > 4 && day < 15){
    alert("Invalid date: 15 Oct immediately followed 4 Oct in the year 1582")
	document.datainput.dateerr.value="??"
    return;
  }
  if (year < 0) year = year + 1; //B.C. date correction
  var a = ipart((14 - month) / 12);
  var y = year + 4800 -a;
  var m = month + 12 * a - 3;
  if (type == GREGORIAN){
    julianday = day + ipart((153*m + 2)/5) + y*365 + ipart(y/4) - ipart(y/100) + ipart(y/400) - 32045;
 }
  if (type == JULIAN){
    julianday = day + ipart((153*m + 2)/5) + y*365 + ipart(y/4) - 32083;
  }
  modifiedjulianday = julianday - 2400000.5; //Zero at 17 Nov 1858 00:00:00 UTC
  this.getJulianDay = getJulianDay();
  this.getModifiedJulianDay = getModifiedJulianDay();
}
//CustomDate**>>

function fix2DigitDate(dateval){
  var date = dateval + "" //dateval must be a string
  if (date.length < 3){ 
    date = 1900 + date * 1.0
	date = date + ""  //to string
  }
  return date
}

function parseDate(dateval,eraval){
	//split is a Javascript 1.2 function
	var dary=dateval.split("/")
  var era;
	eraval > 0 ? era = -1: era = 1
	var y = fix2DigitDate(dary[2]) * era
	switch (df){
	  case 1: { m = dary[0]; d = dary[1] } // mm/dd/yyyy
	  break;
	  case 2: { m = dary[1]; d = dary[0] } // dd/mm/yyyy
	  break;
	  default: { m = dary[0]; d = dary[1] }
	}
	var calendar
	if (y > 1582) calendar = GREGORIAN
	  else if (y < 1582) calendar = JULIAN
	     else if (m < 10 | (m == 10 && d < 15)) calendar = JULIAN
	        else calendar = GREGORIAN 
	i=new CustomDate(y,m,d,calendar)
	return i
	}//dateval

//Calculate days between dates	
function calcDBD(){
  var err
	var era1 = document.datainput.era1.selectedIndex
	var era2 = document.datainput.era2.selectedIndex
	var date1 = document.datainput.firstdate.value
	var date2 = document.datainput.seconddate.value
	err = checkdate(date1,era1)
	if (err == 1) return
    err = checkdate(date2,era2)
	if (err == 1) return
	firstdate=parseDate(date1,era1)
	seconddate=parseDate(date2,era2)
	dbd = seconddate.getJulianDay-firstdate.getJulianDay
	document.datainput.result.value=dbd.toString() + " days"
	}//calcDBD

//Date format is either mm/dd/yyyy or dd/mm/yyyy
function dateFormat(f){
   df = f;
   }//dateFormat
	
//Validate the dates
//Heavily modified from a script by Mattias Sjsberg 11-28-96
function checkdate(date,era) {
  var err = 0
	var valid = "0123456789/"
	//var ok = "yes"
	var temp;
	if (date == null || date.length < 1) err = 1 //is there a date?
	//check for invalid characters
	for (var i=0; i< date.length; i++) {
	  temp = "" + date.substring(i, i+1)
	  if (valid.indexOf(temp) == "-1") err = 1
	  }
	//split is Javascript 1.2
	dary=date.split("/")
	if (df == 1){
	  b=dary[0] //month
	  d=dary[1] //day
    }
	if (df == 2){
	  b=dary[1] //month
	  d=dary[0] //day
	}
	f=dary[2] //year
    if (err != 1 && f.length < 3) { //one or two digit date
	  f = fix2DigitDate(f) //20th century
	  if (era != null && era == 1) { 
	    err = 1;  //BC years must be 4 digits
		date = date + " B.C." }
	  }
	if (b<1 || b>12) err = 1
	if (d<1 || d>31) err = 1
	if (f<0 || f>9999) err = 1
	if (b==4 || b==6 || b==9 || b==11){
	  if (d==31) err=1
	  }
	if (b==2){  //leap year checking
	  var g=parseInt(f/4)
	  if (isNaN(g)) err=1
	  if (d>29) err=1
	  if (d==29){
	    //leap years are always divisible by 4
	    if ( (f/4)!= parseInt(f/4)) err = 1 
		//in the Gregorian calendar century years are not leap years unless divisible by 400
        if (f > 1582) {
		  if (((f/100) == parseInt(f/100)) && (f/400 != parseInt(f/400))) err = 1 
		  }
	    }
	  }
	if (err==1) {
	  alert('Is this date ('+date+') correct?')
	  document.datainput.dateerr.value="??"
	  }
	else {
	  //alert('Valid date!');
	  document.datainput.dateerr.value=""
  	  }
	return err
	}//checkdate

//Get today's date. Date object works ok here.
function enterToday() {
	var today=""
	var time=new Date()
	var month=time.getMonth() + 1
	var date=time.getDate()
	var year=time.getYear()
	// Y2K Fix by Isaac Powell
	// http://onyx.idbsu.edu/~ipowell
	if ((navigator.appName == "Microsoft Internet Explorer") && (year < 2000))		
	  year="19" + year
	if (navigator.appName == "Netscape")
	  year=1900 + year
	if (date<10) {date="0"+date}
	if (month<10) {month="0"+month}
	//select American or European date format
	df == 1 ? today=month+"/"+date+"/"+year : today=date+"/"+month+"/"+year 
	document.datainput.seconddate.value=today
	document.datainput.era2.selectedIndex=0
    }//enterToday

function firstDateAssist(){
  var dfstr = "MM/DD/YYYY"
  if (df == 2) dfstr = "DD/MM/YYYY";
  var textbox = 'datainput.firstdate'
  show_calendar(textbox,"","",dfstr)
}
function secondDateAssist(){
  var dfstr = "MM/DD/YYYY"
  if (df == 2) dfstr = "DD/MM/YYYY";
  var textbox = 'datainput.seconddate'
  show_calendar(textbox,"","",dfstr)
}


