// Variables used on most pages
var SelectQuote = 17;
var BibleID = new Array();var BibleQuote = new Array();var BibleRef = new Array();
var WiseID = new Array();var WiseQuote = new Array();var WiseAuth = new Array();
var numWiseQ =0;
var numBibleQ =0;
var ncollpics=9;

// used on Home Page ID 1
var Advert = new Array();
var AdvCat = new Array();
var AdvMve = new Array();
var nadverts = 0;
var advertPos = 0;
// used on Meetings page ID 2
var CalMonth = "";
var CalRowentry = "";

var Mtg_title = new Array(); var Mtg_here = new Array();
var Mtg_dateinfo = new Array(); var Mtg_desc = new Array(); var Mtg_speak = new Array();
var mtg2come = 0;
var nf_total = -1;
var nf_here = -1;
var nf_away = -1;
var n_h_away = 0;
var n_a_here = 0;
var awayhead = 0;
var nowdate = new Date();
var nowday = nowdate.getDate();
var nowmon = nowdate.getMonth()+1;
var nowyr = nowdate.getFullYear() - 2000;
var nowval = (nowyr * 10000)+(nowmon * 100)+nowday;
var code4here = "<h3>At Bulkington:</h3>";
var code4away ="";
// Used on Photo page ID 6
var SPhoto = new Array(); var SPCode = new Array();
var PhotoSub = new Array(); var Photo_name = new Array(); var PhotoTitle = new Array();
var PhotoHover = new Array(); var PhotoOrient = new Array(); var PhotoGroup = new Array();
// nPhotos = total photos  ngrppics = no of photos in group  MaxPdisp = max no to be displayed together
var photos = 0;
var nPhotos = 0;
var ngrppics = 0;
var MaxPdisp = 1;
// PFirst, PLast, PCurrent  = index of first, last and highlighted photo in group-list
var PFirst = 1;
var PLast = 5;
var PCurrent = 1;
var Pwas = 1;
// PGroup = index of current group  PGID = group code of current group  PGDesc = Description of Group
var PGroup = 0;
var PGID = "CX08";
var PGDesc = "";
// Indicators 0 - no change, 1 - set blank/end, 2 - set present/with code
var Uarrow = 1;
var Darrow = 1;
var	MaxPdisp = 5;

// used on Links page ID 7
var LCATc = new Array(); var LCATn = new Array();
var LINKg = new Array(); var LINKn = new Array(); var LINKr = new Array();
var LINKshown = "---";
var nlinks = 0;
var nlinkcats = 0;

// used on Sermons page ID 8
var SERdd = new Array(); var SERdm = new Array(); var SERdy = new Array();
var SERpr = new Array(); var SERtt = new Array(); var SERsz = new Array();
var SERln = new Array(); var SERfi = new Array(); var SERca = new Array();
var SERampm = new Array(); var SERtx = new Array();
var SDTfm = new Array(); var SDTfy = new Array(); var SDTtm = new Array();
var SDTty = new Array(); var SDTname = new Array();
var SPR = new Array(); var SPRname = new Array();
var SSE = new Array(); var SSEname = new Array();
var nsermons = 0;
var ndates = 0;
var nnames = 0;
var ncats = 0;

// used on QTAs page ID 9
var QnId = new Array(); var QnTxt = new Array(); 
var QnDate = new Array(); var QnDisp = new Array();
var xmlQuestions=null;
var AnsTXT = "Not Set";
var xmlANS;
var QuesText = "";
var Qasked = "--";
var AnswerEntry = "";
var nquestions = 0;
var text2use ="";
var firstpart ="";
var secondpart ="";
var moreleft = 0;

function MovedTo(opt){
  var x = "http://www.bulkingtoncongregational.org/";
  switch(opt){
	case 2:
		window.location = x+"Meetings.html";
	break;
	case 3:
		window.location = x+"Location.html";
	break;
	case 4:
		window.location = x+"Contact.html";
	break;
	case 5:
		window.location = x+"Beliefs.html";
	break;
	case 6:
		window.location = x+"Photos.html";
	break;
	case 7:
		window.location = x+"Links.html";
	break;
	case 8:
		window.location = x+"Sermons.html";
	break;
	case 9:
		window.location = x+"QTAs.html";
	break;
	default:
		window.location = x+"index.html";
  }
}

function FileXMLload(XMLfilename){
var xmlDoc=null;
if (window.ActiveXObject)
	{
// code for IE
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
//		alert("IE Entered");
	}
else 
	{
		if (document.implementation.createDocument)
		{
//		alert("Mozilla Entered");

// code for Mozilla, Firefox, Opera, etc.
		xmlDoc=document.implementation.createDocument("","",null);
		}
		else { alert('Your browser cannot handle this script');	}
	}
if (xmlDoc!=null)
	{ 
	xmlDoc.async=false;
	xmlDoc.validateOnParse="false";
// check whether errors created by use of Chrome and Safari
	var cerr = "";
	try {xmlDoc.load(XMLfilename);}
	catch(e)
 		{
		  try //using XMLHttpRequest instead
		  {
		   var xmlhttp = new window.XMLHttpRequest();
		   xmlhttp.open("GET",XMLfilename,false);
		   xmlhttp.send(null);
		   xmlDoc = xmlhttp.responseXML.documentElement;
		  }
		  catch(e) { cerr=e.message; }
		}
    }
  return xmlDoc;
}
function LoadXMLdata(windid){
// load up quote info - each page
var xmlQuotes=FileXMLload("QuoteList.xml");

	var Bible_texts=xmlQuotes.getElementsByTagName("BIBLE");
	numBibleQ = Bible_texts.length;
	if (numBibleQ>0){
	for (i=0;i<numBibleQ;i++)
	 { 
	  BibleID[i]=Bible_texts[i].getElementsByTagName("BIBID")[0].childNodes[0].nodeValue;
	  BibleQuote[i]=Bible_texts[i].getElementsByTagName("BTEXT")[0].childNodes[0].nodeValue;
	  BibleRef[i]=Bible_texts[i].getElementsByTagName("BVERSE")[0].childNodes[0].nodeValue;
	 }

	var Wise_texts=xmlQuotes.getElementsByTagName("WISDOM");
	numWiseQ = Wise_texts.length;
	for (i=0;i<numWiseQ;i++)
	 { 
	  WiseID[i]=Wise_texts[i].getElementsByTagName("WTXID")[0].childNodes[0].nodeValue;
	  WiseQuote[i]=Wise_texts[i].getElementsByTagName("WTEXT")[0].childNodes[0].nodeValue;
	  WiseAuth[i]=Wise_texts[i].getElementsByTagName("WAUTH")[0].childNodes[0].nodeValue;
	 }

	}
else
	{
	alert('An external document containing some details is either missing or unavailable.Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}
if (windid == 1){
var xmlDates=FileXMLload("DateList.xml");
var adv_entries=xmlDates.getElementsByTagName("ADVERT");
var mtg2come = adv_entries.length;
	if (mtg2come>0){
	for (i=0;i<mtg2come;i++)
	 { 
	  j = adv_entries[i].getElementsByTagName("ADFY")[0].childNodes[0].nodeValue;
	  if (j > 2000) {j -= 2000;}
	  fromdate = j * 10000;
	  j = adv_entries[i].getElementsByTagName("ADFM")[0].childNodes[0].nodeValue;
	  fromdate += (j * 100);
	  j = adv_entries[i].getElementsByTagName("ADFD")[0].childNodes[0].nodeValue;
	  fromdate += (j * 1);
	  if (fromdate <= nowval)
		{
		j = adv_entries[i].getElementsByTagName("ADTY")[0].childNodes[0].nodeValue;
		if (j > 2000){j -= 2000;}
		todate = j * 10000;
		j = adv_entries[i].getElementsByTagName("ADTM")[0].childNodes[0].nodeValue;
		todate += (j * 100);
		j = adv_entries[i].getElementsByTagName("ADTD")[0].childNodes[0].nodeValue;
		todate += (j * 1);
		if (todate >= nowval)
		  {
		  nadverts += 1;
          AdvCat[nadverts] = adv_entries[i].getElementsByTagName("ADGRP")[0].childNodes[0].nodeValue;
          AdvMve[nadverts] = adv_entries[i].getElementsByTagName("ADMVE")[0].childNodes[0].nodeValue;
          j = adv_entries[i].getElementsByTagName("ADICON")[0].childNodes[0].nodeValue;
          code2put = "<table><tr><td><img src='"+j+"' alt='*'/></td><td class='padleft'>";
          j = adv_entries[i].getElementsByTagName("ADTEXT")[0].childNodes[0].nodeValue;
          Advert[nadverts] = code2put+j+"</td></tr></table>";
		  }
// next bracket closes fromdate vs nowval comparison
		}
// next  bracket closes for loop
	 }
	}
else
	{
    Advert[1]="<table><tr><td><img src='images/headphones2b.png' alt='headphones'/></td><td class='padleft'>Listen to a sermon or lecture from our archive.<br/>Search our <a href='Sermons.html'>Access Sermons</a> page.</td></tr></table>";
    AdvCat[1]="P";AdvMve[1]="L";
    Advert[2]="<table><tr><td><img src='images/calendar_searchb.png' alt='calendar'/></td><td class='padleft'>Details of other meetings along with the current diary<br/>can be found on our <a href='Meetings.html'>Meetings</a> page.</td></tr></table>";
    AdvCat[2]="P";AdvMve[2]="L";
    nadverts=2;
	}

}
if (windid == 2){

var xmlDates=FileXMLload("DateList.xml");
	var Diaryentries=xmlDates.getElementsByTagName("DIARY");
	CalMonth = Diaryentries[0].getElementsByTagName("DIMONTH")[0].childNodes[0].nodeValue;
	var CalDayents=xmlDates.getElementsByTagName("DIDAY");
	var CDaynum = CalDayents.length;
	if (CDaynum>0){
		CalRowentry = '';
		var CalwkDay = 0;
		for (i=0;i<CDaynum;i++)
		 {
			if (CalwkDay == 0){ CalRowentry = CalRowentry+'<tr  class="calwcell"><td><b>';}
			x=CalDayents[i].getElementsByTagName("DIDATE")[0].childNodes[0].nodeValue;
			if (x=="*") {x=" ";}
//alert("Date="+x);
			CalRowentry = CalRowentry + x + "</b><br />";
			x=CalDayents[i].getElementsByTagName("DITEXT")[0].childNodes[0].nodeValue;
			if (x=="*") {x=" ";}
			CalRowentry = CalRowentry + x + "</td>";
			if (CalwkDay == 6){ CalRowentry = CalRowentry + "</tr>";}
			else             { CalRowentry = CalRowentry + "<td><b>";}
			
			CalwkDay += 1;
			if (CalwkDay == 7){CalwkDay = 0;}
	 	}
	 	if (CalwkDay > 0) {
	 	 x=7-CalwkDay;
	 	 for (i=1;i<=x;i++){
            if (i==x) {CalRowentry = CalRowentry + "<td></td></tr>";}
            else      {CalRowentry = CalRowentry + "<td></td>";}
	 	 }
	 	}
	}


	var mtg_entries=xmlDates.getElementsByTagName("FORTH");
	var mtg2come = mtg_entries.length;
// alert ("No of Forthcoming events  "+mtg2come+" Date val="+nowval);
	if (mtg2come>0){
	for (i=0;i<mtg2come;i++)
	 { 
	  ishere = mtg_entries[i].getElementsByTagName("MHERE")[0].childNodes[0].nodeValue;
	  j = mtg_entries[i].getElementsByTagName("MFY")[0].childNodes[0].nodeValue;
	  if (j > 2000) {j -= 2000;}
	  fromdate = j * 10000;
	  j = mtg_entries[i].getElementsByTagName("MFM")[0].childNodes[0].nodeValue;
	  fromdate += (j * 100);
	  j = mtg_entries[i].getElementsByTagName("MFD")[0].childNodes[0].nodeValue;
	  fromdate += (j * 1);
	  if (fromdate <= nowval)
		{
		j = mtg_entries[i].getElementsByTagName("MTY")[0].childNodes[0].nodeValue;
		if (j > 2000){j -= 2000;}
		todate = j * 10000;
		j = mtg_entries[i].getElementsByTagName("MTM")[0].childNodes[0].nodeValue;
		todate += (j * 100);
		j = mtg_entries[i].getElementsByTagName("MTD")[0].childNodes[0].nodeValue;
		todate += (j * 1);
		if (todate >= nowval)
		  {
			nf_total += 1;
			Mtg_here[nf_total] = ishere;
			Mtg_title[nf_total] = mtg_entries[i].getElementsByTagName("MTITLE")[0].childNodes[0].nodeValue;
			Mtg_dateinfo[nf_total] = mtg_entries[i].getElementsByTagName("MDATE")[0].childNodes[0].nodeValue;
			Mtg_desc[nf_total] = mtg_entries[i].getElementsByTagName("MDESC")[0].childNodes[0].nodeValue;
			Mtg_speak[nf_total] = mtg_entries[i].getElementsByTagName("MSPEAK")[0].childNodes[0].nodeValue;
			if (ishere == 1){nf_here += 1;}
			else		{nf_away +=1;}
		  }
// next bracket closes fromdate vs nowval comparison
		}
// next  bracket closes for loop
	 }
	}
else
	{
	alert('A file containing details of forthcoming events is either missing or unavailable. You will not be able to access this information until this fault is rectified. Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}

// calculate the overflow to balance columns if one list is at least 2 greater than the other
j = Math.floor((Math.abs(nf_here - nf_away))/2);
if (j > 0)
	{
	awayhead = 0;
	if (nf_here > nf_away)
		{ nf_hmax = nf_here - j;
		  nf_afirst = -1;
		  code4away ="<h3><i>At Bulkington (continued):</i></h3>";
		}
	else
		{ nf_afirst = j-1;
		  nf_hmax = nf_here;
		  code4away ="<h3><i>Elsewhere (continued):</i></h3>";
		}
	}
else
	{
	nf_hmax = nf_here;
	nf_afirst = -1;
	}

// PROCESS HOME EVENTS ..............................
if (nf_here < 0)
  {code4here = code4here + "<p><i>None to display at present.</i></p>";}
if (nf_total >= 0)
 {
// scan through for local events
var nf_curr = -1;
for (i=0;i<=nf_total;i++)
  {
	j = Mtg_here[i];
	if (j == 1)
	{
	  var mtg_details = "<p><strong>"+Mtg_title[i]+"</strong><br />"+Mtg_dateinfo[i]+"<br /><strong><i>";
	  mtg_details = mtg_details + Mtg_desc[i]+"</i></strong><br />"+Mtg_speak[i];

	  nf_curr += 1;
	  if (nf_curr <= nf_hmax){code4here = code4here + mtg_details;}
	  else	  {code4away = code4away + mtg_details;}
	}
  }
// PROCESS AWAY EVENTS ..............................
var nf_curr = -1;
for (i=0;i<=nf_total;i++)
  {
	j = Mtg_here[i];
	if (j != 1)
	{
	  var mtg_details = "<p><strong>"+Mtg_title[i]+"</strong><br />"+Mtg_dateinfo[i]+"<br /><strong><i>";
	  mtg_details = mtg_details + Mtg_desc[i]+"</i></strong><br />"+Mtg_speak[i];

	  nf_curr += 1;
	  if (nf_curr > nf_afirst)
	  {
		if (awayhead == 0)
		{
			code4away = code4away + "<h3>Elsewhere:</h3>";
			awayhead = 1;
		}
		code4away = code4away + mtg_details;
	  }
	  else
	  {
		if (awayhead == 0)
		{
			code4here = code4here + "<h3>Elsewhere:</h3>";
			awayhead = 1;
		}
		code4here = code4here + mtg_details;
	  }
	}
  }
 }
if (awayhead == 0)
{
	code4away = code4away + "<h3>Elsewhere:</h3><p><i>None to display at present.</i></p>";
}

}
if (windid == 6){
var xmlPhotos=FileXMLload("PhotoList.xml");

	var pg_entries=xmlPhotos.getElementsByTagName("PGROUP");
	photos = pg_entries.length;
// alert ("No of Photo Collections  "+ndates);
	if (photos>0){
	for (i=0;i<photos;i++)
	 { 
	  SPCode[i]=pg_entries[i].getElementsByTagName("GCODE")[0].childNodes[0].nodeValue;
	  SPhoto[i]=pg_entries[i].getElementsByTagName("GDESC")[0].childNodes[0].nodeValue;
	 }

	var ph_entries=xmlPhotos.getElementsByTagName("PHOTO");
	nPhotos = ph_entries.length;
// alert ("No of Photographs  "+nPhotos);
	for (i=0;i<nPhotos;i++)
	 { 
	  PhotoSub[i]=ph_entries[i].getElementsByTagName("PHOTODIR")[0].childNodes[0].nodeValue;
	  PhotoGroup[i]=ph_entries[i].getElementsByTagName("PCATEGORY")[0].childNodes[0].nodeValue;
	  Photo_name[i]=ph_entries[i].getElementsByTagName("PHOTOFNAME")[0].childNodes[0].nodeValue;
	  PhotoTitle[i]=ph_entries[i].getElementsByTagName("COMMENT")[0].childNodes[0].nodeValue;
	  PhotoOrient[i]=ph_entries[i].getElementsByTagName("ORIENTATION")[0].childNodes[0].nodeValue;
	  PhotoHover[i]=ph_entries[i].getElementsByTagName("EXTRADESC")[0].childNodes[0].nodeValue;
	 }

	}
else
	{
	alert('A file containing photo details is either missing or unavailable. You will not be able to access photos until this fault is rectified. Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}


 }
if (windid == 7){
var xmlLinks=FileXMLload("LinkList.xml");

	var dat_entries=xmlLinks.getElementsByTagName("LLINK");
	nlinks = dat_entries.length;
// alert ("No of Links  "+nlinks);
	if (nlinks>0){
	for (i=0;i<nlinks;i++)
	 { 
	  LINKg[i]=dat_entries[i].getElementsByTagName("LLISTS")[0].childNodes[0].nodeValue;
	  LINKn[i]=dat_entries[i].getElementsByTagName("LNAME")[0].childNodes[0].nodeValue;
	  LINKr[i]=dat_entries[i].getElementsByTagName("LREF")[0].childNodes[0].nodeValue;
	 }

	var cat_entries=xmlLinks.getElementsByTagName("LCAT");
	nlinkcats = cat_entries.length;
// alert ("No of Menus  "+nlinkcats);
	for (i=0;i<nlinkcats;i++)
	 { 
	  LCATc[i]=cat_entries[i].getElementsByTagName("LCODE")[0].childNodes[0].nodeValue;
	  LCATn[i]=cat_entries[i].getElementsByTagName("LTEXT")[0].childNodes[0].nodeValue;
	 }
	}
else
	{
	alert('A file containing link details is either missing or unavailable. You will not be able to access links until this fault is rectified. Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}
 }
 
if (windid == 8){
var xmlSermons=FileXMLload("SermonList.xml");

	var dat_entries=xmlSermons.getElementsByTagName("DATERG");
	ndates = dat_entries.length;
// alert ("No of Date Ranges  "+ndates);
	if (ndates>0){
	for (i=0;i<ndates;i++)
	 { 
	  SDTfm[i]=dat_entries[i].getElementsByTagName("FM")[0].childNodes[0].nodeValue;
	  SDTfy[i]=dat_entries[i].getElementsByTagName("FY")[0].childNodes[0].nodeValue;
	  SDTtm[i]=dat_entries[i].getElementsByTagName("TM")[0].childNodes[0].nodeValue;
	  SDTty[i]=dat_entries[i].getElementsByTagName("TY")[0].childNodes[0].nodeValue;
	  SDTname[i]=dat_entries[i].getElementsByTagName("DRDESC")[0].childNodes[0].nodeValue;
	 }

	var cat_entries=xmlSermons.getElementsByTagName("SERIES");
	ncats = cat_entries.length;
// alert ("No of Series  "+ncats);
	for (i=0;i<ncats;i++)
	 { 
	  SSE[i]=cat_entries[i].getElementsByTagName("SCODE")[0].childNodes[0].nodeValue;
	  SSEname[i]=cat_entries[i].getElementsByTagName("SDESC")[0].childNodes[0].nodeValue;
	 }

	var spk_entries=xmlSermons.getElementsByTagName("SPEAKER");
	nnames = spk_entries.length;
// alert ("No of Speakers  "+nnames);
	for (i=0;i<nnames;i++)
	 { 
	  SPR[i]=spk_entries[i].getElementsByTagName("PCODE")[0].childNodes[0].nodeValue;
	  SPRname[i]=spk_entries[i].getElementsByTagName("PNAME")[0].childNodes[0].nodeValue;
	 }

	var ser_entries=xmlSermons.getElementsByTagName("SERMON");
	nsermons = ser_entries.length;
// alert ("No of sermons  "+nsermons);
	for (i=0;i<nsermons;i++)
	 { 
	  SERdd[i]=ser_entries[i].getElementsByTagName("DATE_D")[0].childNodes[0].nodeValue;
	  SERdm[i]=ser_entries[i].getElementsByTagName("DATE_M")[0].childNodes[0].nodeValue;
	  SERdy[i]=ser_entries[i].getElementsByTagName("DATE_Y")[0].childNodes[0].nodeValue;
	  SERampm[i]=ser_entries[i].getElementsByTagName("AMPM")[0].childNodes[0].nodeValue;
	  SERpr[i]=ser_entries[i].getElementsByTagName("PREACHER")[0].childNodes[0].nodeValue;
	  SERtx[i]=ser_entries[i].getElementsByTagName("BTEXT")[0].childNodes[0].nodeValue;
	  SERtt[i]=ser_entries[i].getElementsByTagName("DESCPN")[0].childNodes[0].nodeValue;
	  SERsz[i]=ser_entries[i].getElementsByTagName("F_SIZE")[0].childNodes[0].nodeValue;
	  SERln[i]=ser_entries[i].getElementsByTagName("HOWLONG")[0].childNodes[0].nodeValue;
	  SERca[i]=ser_entries[i].getElementsByTagName("CATGRY")[0].childNodes[0].nodeValue;
	  SERfi[i]=ser_entries[i].getElementsByTagName("F_NAME")[0].childNodes[0].nodeValue;
	 }

	}
else
	{
	alert('Afile containing sermon details is either missing or unavailable. You will not be able to access sermons until this fault is rectified. Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}

}

if (windid == 9){
var xmlQuestions=FileXMLload("QnList.xml");

	var qn_entries=xmlQuestions.getElementsByTagName("QUN");
	nquestions = qn_entries.length;
// alert ("No of Date Ranges  "+nquestions);
	if (nquestions>0){
	for (i=0;i<nquestions;i++)
	 { 
	  QnId[i]=qn_entries[i].getElementsByTagName("QID")[0].childNodes[0].nodeValue;
	  QnDate[i]=qn_entries[i].getElementsByTagName("QMO")[0].childNodes[0].nodeValue;
	  QnTxt[i]=qn_entries[i].getElementsByTagName("QTX")[0].childNodes[0].nodeValue;
	  QnDisp[i]=qn_entries[i].getElementsByTagName("QAR")[0].childNodes[0].nodeValue;
	 }
	}
else
	{
	alert('A file containing question details is either missing or unavailable. Please go to our Contacts page www.bulkingtoncongregational.org/Contact.html and report the problem via e-mail.Thank you, and many apologies for any inconvenience caused.');
	}
}

}
// end of function LoadXMLdata - start of general functions

function dlmodd(){
var docdate = new Date(document.lastModified);
var modded ="Not Set";
var dmday = docdate.getDate();
var dmmon = docdate.getMonth();
var dmyr = docdate.getFullYear();
var dmhr = docdate.getHours();
var dmmin = docdate.getMinutes();
dmmon = ++dmmon;
if (isNaN(dmday)){var modded="No Date Set";}
else {var modded =dmday+"/"+dmmon+"/"+dmyr+" at "+dmhr+":"+dmmin;}
return (modded);
}

function ScrollToElement(theElement){
  var selectedPosX = 0;
  var selectedPosY = 0;
              
  while(theElement != null){
    selectedPosX += theElement.offsetLeft;
    selectedPosY += theElement.offsetTop;
    theElement = theElement.offsetParent;
  }
 window.scrollTo(selectedPosX,selectedPosY);

}
// Change class of element
function chgclass(idcode,nclass){
code2run='document.getElementById("'+idcode+'").setAttribute("class","'+nclass+'");';
eval(code2run);
code2run='document.getElementById("'+idcode+'").setAttribute("className","'+nclass+'");';
eval(code2run);
}
// Change left position of element
function chgpos(idcode,cpos){
//code2run='document.getElementById("'+idcode+'").style.left= '+cpos+'em;';
code2run='document.getElementById("'+idcode+'").style.left= -10em;';
//alert(code2run);
eval(code2run);
alert("Ran Code: "+code2run);
}
// Set email address from components
function mailit(mailname)
{
var maildom = "bulkingtoncongregational.org";
document.write('<a href=\"mailto:' + mailname + '@' + maildom + '\" style=\"color:blue; text-decoration:underline;\">');
document.write(mailname + '@' + maildom + '</a><br />(Click to mail)');
}

function splittwo(look4){
var lensrch = look4.length;
moreleft = 1;
fstop = text2use.indexOf(look4);
lenend = fstop + lensrch;
if (fstop < 0)
  {
  firstpart = text2use;
  secondpart = "";
  moreleft = 0;
  }
else
  {
  x=text2use.length;
  if (fstop == 0)
    {
	firstpart = "";
	secondpart = text2use.substr(lensrch,x-lensrch);
    }
  else
    {
	  firstpart = text2use.substr(0,fstop);
	  x-=fstop;
	  x-=lensrch;
	  if (x>0)
	    {
	    secondpart = text2use.substr(fstop+lensrch,x);
	    }
	  else
	    {
	    secondpart = "";
	    moreleft = 0;
	    }
    }
  }
}

function splitone(look4){
moreleft = 1;
fstop = text2use.indexOf(look4);
 if (fstop < 0)
 {
  firstpart = text2use;
  secondpart = "";
  moreleft = 0;
 }
 else
 {
  firstpart = text2use.substr(0,fstop);
  x=text2use.length - 1;
  x-=fstop;

  if (x > 0) {secondpart = text2use.substr(fstop+1,x);}
  else
  {
    secondpart = "";
    moreleft = 0;
  }
 }
text2use = secondpart;
}

// objid-objectname opinc-start and end increment
// opadd- extra inc for mid 60pct optime-wait time
// copac-current opacity tmark-timeout marker name
function fade2(objid,opinc,opadd,optime,copac,tmark){
if(opinc < 0 && copac == 0) {clearTimeout(tmark);}
else
 { if(opinc>0 && copac==100)  {clearTimeout(tmark);}
 else
   {
    var ffopinc = opinc /100;
    var ffopadd = opadd /100;
    var ffcopac = copac/100;
    copac += opinc;
    ffcopac += ffopinc;
    if (copac < 85 && copac > 15) {copac += opadd; ffcopac += ffopadd;}
    if (opinc >= 0) {
        if (copac > 97) {copac=100;
                        ffcopac=1.0;}
    }
    else {
        if (copac < 3){ copac=0;
                        ffcopac=0.0;}
         }
    opacode = 'document.getElementById("'+objid+'").style.opacity='+ffcopac+';';
    eval(opacode);
    opacode = 'document.getElementById("'+objid+'").style.filter="alpha(opacity='+copac+')";';
    eval(opacode);
    opacode = tmark+'=setTimeout("fade2(\''+objid+'\','+opinc+','+opadd+','+optime+','+copac+',\''+tmark+'\')",'+optime+');';
    eval(opacode);
   }
 }
return copac;
}

function findBible(bibref)
{
  j=-1;
  for (i=0;i<numBibleQ;i++)
  {
	x = BibleID[i];
	if (x == bibref)
	{ j = i;
	  i = numBibleQ + 1;}
  } 
 return j;
}

function findWise(wisref)
{
  j=-1;
  for (i=0;i<numWiseQ;i++)
  {
	x = WiseID[i];
	if (x == wisref)
	{ j = i;
	  i = numWiseQ + 1;	}
  } 
 return j;
}

function giveWinwidth()
{
if (window.innerWidth)
 	theWidth=window.innerWidth;
else if (document.documentElement && document.documentElement.clientWidth)
	 theWidth=document.documentElement.clientWidth;
else if (document.body)
 	theWidth=document.body.clientWidth;
return (theWidth);
}

function giveWinheight()
{
if (window.innerHeight)
 	theHeight=window.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight)
	 theHeight=document.documentElement.clientHeight;
else if (document.body)
	 theHeight=document.body.clientHeight;
return (theHeight);
}

function showcollcn(opt,picno){
code2put= '<img src="Collection'+picno+'.png" alt="Bulkington"/>';
if (opt==0){document.write(code2put);}
else {document.getElementById("BCCLogo").innerHTML = code2put;}
}
function showlogo(opt,picno){
code2put= '<img src="BCC_Logo1.png" alt="Congregational Church"/>';
if (opt==0){document.write(code2put);}
else {document.getElementById("pictures").innerHTML = code2put;}
}
// Change class of menu item
function mcc(m1,copt){
//alert("menu "+m1);

if (copt==1){chgclass(m1,"tmenuh");}
else {  chgclass(m1,"tmenud");    }
return;
}
// Put up top menu part 1
function showMenuT1(cmenu){
var tabint='<td> </td>';
menucode=tabint;
menuch1a = '<td class="tmenud" id="';
menuch1b = '<td class="tmenut" id="';
menuch2 = '" onmouseover="mcc(\'';
menuch3 = '\',1);" onmouseOut="mcc(\'';
menuch4 = '\',0);"><a href=';

for (i=1;i<6;i++){
  if (i==cmenu){
    switch(i) {
    case 1:
    menuid = "men1";
    menutext = '">Sunday<br />Services</td>';
    break;
    case 2:
    menuid = "men2";
    menutext = '">Meetings<br />and Diary</td>';
    break;
    case 3:
    menuid = "men3";
    menutext = '">How to<br />Find Us</td>';
    break;
    case 4:
    menuid = "men4";
    menutext = '">Contact<br />Us</td>';
    break;
    case 5:
    menuid = "men5";
    menutext = '">What We<br />Believe</td>';
    break;
    }
    menucode = menucode+menuch1b+menuid+menutext;
  }
  else {
    switch(i) {
    case 1:
    menuid = "men1";
    menutext = '"index.html" alt="Home" class="menct">Sunday<br />Services</a></td>';
    break;
    case 2:
    menuid = "men2";
    menutext = '"Meetings.html" alt="Meetings" class="menct">Meetings<br />and Diary</a></td>';
    break;
    case 3:
    menuid = "men3";
    menutext = '"Location.html" alt="Location" class="menct">How to<br />Find Us</a></td>';
    break;
    case 4:
    menuid = "men4";
    menutext = '"Contact.html" alt="Contact" class="menct">Contact<br />Us</a></td>';
    break;
    case 5:
    menuid = "men5";
    menutext = '"Beliefs.html" alt="Beliefs" class="menct">What We<br />Believe</a></td>';
    break;
    }
    menucode = menucode+menuch1a+menuid+menuch2+menuid+menuch3+menuid+menuch4+menutext;
  }
 }
menucode = menucode+'<td> </td>';
document.write(menucode);
}
// Put up top menu part 2
function showMenuT2(cmenu){
var tabint='<td> </td>';
menucode=tabint;
menuch1a = '<td class="tmenud" id="';
menuch1b = '<td class="tmenut" id="';
menuch2 = '" onmouseover="mcc(\'';
menuch3 = '\',1);" onmouseOut="mcc(\'';
menuch4 = '\',0);"><a href=';


for (i=6;i<10;i++){
  if (i==cmenu){
    switch(i) {
    case 6:
    menuid = "men6";
    menutext = '">Photo<br />Gallery</td>';
    break;
    case 7:
    menuid = "men7";
    menutext = '">Links<br />Elsewhere</td>';
    break;
    case 8:
    menuid = "men8";
    menutext = '">Access<br />Sermons</td>';
    break;
    case 9:
    menuid = "men9";
    menutext = '">QTAs<br />not FAQs</td>';
    break;
    }
    menucode = menucode+menuch1b+menuid+menutext;
  }
  else {
    switch(i) {
    case 6:
    menuid = "men6";
    menutext = '"Photos.html" alt="Photos" class="menct">Photo<br />Gallery</a></td>';
    break;
    case 7:
    menuid = "men7";
    menutext = '"Links.html" alt="Links" class="menct">Links<br />Elsewhere</a></td>';
    break;
    case 8:
    menuid = "men8";
    menutext = '"Sermons.html" alt="Sermons" class="menct">Access<br />Sermons</a></td>';
    break;
    case 9:
    menuid = "men9";
    menutext = '"QTAs.html" alt="QTAs" class="menct">QTAs<br />not FAQs</a></td>';
    break;
    }
    menucode = menucode+menuch1a+menuid+menuch2+menuid+menuch3+menuid+menuch4+menutext;
  }
 }
menucode = menucode+'<td> </td>';
document.write(menucode);
}
// Display bottom menu
function putupmenuB(){
document.write('<a href="index.html">Home</a> | '+
 '<a href="Meetings.html">Meetings</a> | '+
 '<a href="Location.html">Location</a> | '+
 '<a href="Contact.html">Contact</a> | '+
 '<a href="Beliefs.html">Beliefs</a> | '+
 '<a href="Sermons.html">Sermons</a> | '+
 '<a href="Links.html">Links</a> | '+
 '<a href="Photos.html">Photos</a> | '+
 '<a href="QTAs.html">QTAs</a><p id="smallitalic">Copyright Bulkington Congregational Church         '+
 'last modified '+dlmodd()+'</p>');
}


// Set Scripture Text displayed centrally 
// options are 0 - first display, 1 - random, 2 - reset, 3-pause, 8 - fwd, 9-back
function showtext(Quoteopt) {
 if (Quoteopt == 0 ) {SelectQuote = 0;}
 else 
    {
    if (Quoteopt == 1 ) {SelectQuote = Math.round(Math.random()*(numBibleQ-1));}
    else
     {
     if (Quoteopt == 8)
       { SelectQuote += 1;
         if (SelectQuote == numBibleQ) {SelectQuote = 0;} }
     else
       {
         if (Quoteopt == 9)
          { SelectQuote -= 1;
            if (SelectQuote < 0) {SelectQuote = numBibleQ - 1;} }
       }
     }
    }

    nbquote = BibleQuote[SelectQuote]+BibleRef[SelectQuote];
    nbql = nbquote.length;
    nfsz = "1.85";
    if (nbql >= 170)
	{
	   if (nbql >= 200) {nfsz = "1.4";}
	   else	   {nfsz = "1.7";}
	}

    nextbible = '<div id="bqscroll" style="visibility:hidden;"><img src="images/scrollbk.png" alt="Go back" align="left" onclick="showtext(9)"/><img src="images/scrollfwd.png" alt="Go fwd" align="right" onclick="showtext(8)"/></div><br /><span style="font-size:'+nfsz+'em; font-weight:bold;">'+BibleQuote[SelectQuote]+'<i><br />'+BibleRef[SelectQuote]+'</i></span>';

    if (Quoteopt == 0)
      { document.write(nextbible);
        t=setTimeout("showtext(1)",14000); }
    if (Quoteopt == 1)
      { document.getElementById("renewquote").innerHTML = nextbible;
        t=setTimeout("showtext(1)",14000); }
    if (Quoteopt == 2)
      { document.getElementById('bqscroll').style.visibility="hidden";
        t=setTimeout("showtext(1)",14000); }
     if (Quoteopt == 3)
      { clearTimeout(t); }
     if (Quoteopt > 3)
      { clearTimeout(t);
        nbquote = BibleQuote[SelectQuote]+BibleRef[SelectQuote];
        nbql = nbquote.length;
        nfsz = "1.85";
        if (nbql >= 150)
	       {
	           if (nbql >= 200) {nfsz = "1.4";}
	           else	   {nfsz = "1.7";}
	       }
    nextbible = '<div id="bqscroll" style="visibility:visible;"><img src="images/scrollbk.png" alt="Go back" align="left" onclick="showtext(9)"/><img src="images/scrollfwd.png" alt="Go fwd" align="right" onclick="showtext(8)"/></div><br /><span style="font-size:'+nfsz+'em; font-weight:bold;">'+BibleQuote[SelectQuote]+'<i><br />'+BibleRef[SelectQuote]+'</i></span>';
        document.getElementById("renewquote").innerHTML = nextbible;
        t=setTimeout("showtext(2)",8000);
      }
}

// Set wise quote displayed top right
function show_wisdom(Quoteopt) {
    if (Quoteopt == 0 ) {SelWQuote = Math.round(Math.random()*(numWiseQ-1));}
    if (Quoteopt == 1 ) {SelWQuote = Math.round(Math.random()*(numWiseQ-1));}
    else
     {
     if (Quoteopt == 8)
       { SelWQuote += 1;
         if (SelWQuote == numWiseQ) {SelWQuote = 0;} }
     else
       {
         if (Quoteopt == 9)
          { SelWQuote -= 1;
            if (SelWQuote < 0) {SelWQuote = numWiseQ - 1;} }
       }
     }

    nextbible = '<div id="wqscroll" style="visibility:hidden;"><img src="images/scrollbk.png" alt="Go back" align="left" onclick="show_wisdom(9)"/><img src="images/scrollfwd.png" alt="Go fwd" align="right" onclick="show_wisdom(8)"/></div><br /><i>'+WiseQuote[SelWQuote]+'</i> ... <strong>'+WiseAuth[SelWQuote]+'</strong>';
    if (Quoteopt == 0) {
        document.write(nextbible);
        tw=setTimeout("show_wisdom(1)",14000);
      }
    if (Quoteopt == 1) {
        document.getElementById("renewisdom").innerHTML = nextbible;
        tw=setTimeout("show_wisdom(1)",14000);
      }
    if (Quoteopt == 2) {
        document.getElementById('wqscroll').style.visibility="hidden";
        tw=setTimeout("show_wisdom(1)",14000);
      }
     if (Quoteopt == 3){
        clearTimeout(tw);
      }
     if (Quoteopt > 3) {
    clearTimeout(tw);
    nextbible = '<div id="wqscroll" style="visibility:visible;"><img src="images/scrollbk.png" alt="Go back" align="left" onclick="show_wisdom(9)"/><img src="images/scrollfwd.png" alt="Go fwd" align="right" onclick="show_wisdom(8)"/></div><br/><i>'+WiseQuote[SelWQuote]+'</i> ... <strong>'+WiseAuth[SelWQuote]+'</strong>';
        document.getElementById("renewisdom").innerHTML = nextbible;
        tw=setTimeout("show_wisdom(2)",8000);
      }
}

function MoveIt(opt,idname,cpos,endpos,cinc,cunit,nextcode){
var moving = '';
var code2run = 'moving = document.getElementById("'+idname+'");';
eval(code2run);
cpos += cinc;
if (cpos < endpos) {cpos=endpos;}
x = cpos+cunit;

if (opt == "H") { this.moving.style.left=x;}
else {this.moving.style.top=x;}

if (cpos == endpos) {code2run='clearTimeout('+idname+'time);';}
else {code2run='setTimeout("MoveIt('+"'"+opt+"','"+idname+"',"+cpos+","+endpos+","+cinc+",'"+cunit+"','"+nextcode+"')"+'",20);';}

eval(code2run);
if (cpos==endpos){eval(nextcode);}
return cpos;
}
function DispAdvert(opt,AdNum,AdSet,AdWidth,AdHght){
code2use="No items to display";
AdFound=0;
AdUse=AdNum;
i=0;
// repeat block to find matching entry
while (i==0){
    j=AdvCat[AdUse];
    fstop = AdSet.indexOf(j);
    if (fstop<0)
    {AdUse +=1;
        if (AdUse>nadverts){AdUse=0;}
        else {if (AdUse==AdNum){i=1;}}
    }
    else {i=1; AdFound=1;}
   }
if (AdFound == 1){AdNum=AdUse;
     code2use="<table id='AdvTab' class='AdvT' style='width:"+AdWidth+"em; min-width:"+AdWidth+"em; height:"+AdHght+"em; min-height:"+AdHght+"'><tr><td>" +Advert[AdNum]+"</tr></td></table>";
    }
if (opt==0){document.write(code2use);}
else{document.getElementById("AdvTab").innerHTML = code2use;}   
}

function ShowAdvert(opt,AdvWidth,AdvertA,AdvertB,AdSet){
AdTw = AdvWidth*2;
AdChop = (AdvWidth -0.5)*-1;
if (opt==0){
      var codeAL="<table id='AdvTab' class='AdvT' style='width:"+AdTw+"em; min-width:"+AdTw+"em;'><tr><td id='AdvL' class='AdvS' style='width:"+AdvWidth+"em; min-width:"+AdvWidth+"em;'>";
      var codeAR="</td><td id='AdvR' class='AdvS' style='width:"+AdvWidth+"em; min-width:"+AdvWidth+"em;'>";
      var codend = "</td></tr></table>";
      var code2put = codeAL+Advert[AdvertA]+codeAR+Advert[AdvertB]+codend;
      document.write(code2put);
      code2put =  'tmadvert=setTimeout("ShowAdvert(1,'+AdvWidth+",1,2,'"+AdSet+"')"+'",7000);';
      eval(code2put);
  }
else {
      var codeAL = 'document.getElementById("AdvL").innerHTML ="';
      var codeAR = 'document.getElementById("AdvR").innerHTML ="';
      var codend = '";';
      if (advertPos == 0){
        code2put=codeAR+Advert[AdvertB]+codend;
        eval(code2put);
      }
      if (advertPos > AdChop){
        advertPos -= 0.2;
        a2chg=document.getElementById("AdvTab");
        x=advertPos + 'em';
        this.a2chg.style.left=x;
        code2put='tmadvert=setTimeout("ShowAdvert(1,'+AdvWidth+','+AdvertA+','+AdvertB+",'"+AdSet+"')"+'",20);';
        eval(code2put);}
      else {clearTimeout(tmadvert);
      var code2put = codeAL+Advert[AdvertB]+codend;
      eval(code2put);
      advertPos=0;
      a2chg=document.getElementById("AdvTab");
      this.a2chg.style.left="0em";
      var code2put = codeAR+Advert[AdvertB]+codend;
      eval(code2put);
      var nxtadv = AdvertB+1;
      if (nxtadv > nadverts){nxtadv=1;}
      code2put='tmadvert=setTimeout("ShowAdvert(1,'+AdvWidth+','+AdvertB+','+nxtadv+",'"+AdSet+"')"+'",7000);';
      eval(code2put);
      }
   }   
}


function dispcalndr(){
 document.write('<table width="100%" border="1" cellspacing="0" cellpadding="2px"><tr><td colspan="7" class="caltcell">');
 document.write(CalMonth);
 document.write('</td></tr><tr class="caldcell"><td>Sunday</td><td>Monday</td><td>Tuesday</td><td>Wednesday</td><td>Thursday</td><td>Friday</td><td>Saturday</td></tr>');
 document.write(CalRowentry);
 document.write('</table>');
}

function LinkMenus(){
// constructs <h3 id="linkXXX" onclick="LMshow('XXX',n);">text</h3>

	for (i=0;i<nlinkcats;i++)
	{
	 x = '<p class="bigbold" id="link'+LCATc[i]+'" onmouseover="chgclass('+"'link"+LCATc[i]+"','lwbg')"+'" onmouseout="chgclass('+"'link"+LCATc[i]+"','lbbg')"+'" onclick="LMshow('+"'"+LCATc[i]+"'," + i+');">' + LCATn[i] + '</p>';
	 document.write(x);
	}
}

function GetLinkentr(lcatid,lcatno){
	var y='<h2>Selected links<br/>shown below:</h2><p><strong><i>(Click on a link to open the WEB site in a new browser window)</i></strong></p><h3>'+LCATn[lcatno]+'</h3>';
	for (i=0;i<nlinks;i++)
	{
	  z=LINKg[i];
	  j=z.indexOf(lcatid);
	  if (j >= 0)
		{
		y=y+'<p><a href="http://'+LINKr[i]+'" target="_blank">'+LINKn[i]+'</a></p>';
		}
	}
return y;
}

function LinkPanel(){
	var y=LCATc[0];
	var x=GetLinkentr(y,0);
	document.write(x);
	x="link"+y;	
	var lnkmenuid = document.getElementById(x);
	lnkmenuid.style.color = "#FF0808";
	LINKshown=y;
}

function LMshow(lmenuno,lno){
	var x2="link"+lmenuno;
	var lnkmenuid = document.getElementById(x2);
	lnkmenuid.style.color = "#FF0808";
	if (LINKshown != "---")
	  {
	   x="link"+LINKshown;
	   if (x != x2)
		{
		lnkmenuid = document.getElementById(x);
		lnkmenuid.style.color ="#000000";
		}
	  }
	LINKshown = lmenuno;
	y=GetLinkentr(lmenuno,lno);
	document.getElementById("displayScol2").innerHTML = y;

}

function PhotoGrpHead(ThisPicSet)
{
var code2put = "<span class='largert'><strong>Currently displaying:   "+PGDesc+" - Photo "+PCurrent+" of "+ngrppics+"</strong></span>";
document.getElementById("pgdescell").innerHTML = code2put;

j= ThisPicSet[PCurrent];
mainpic = '<img src="photos/'+PhotoSub[j]+'/album/medium/'+Photo_name[j]+'"/>';
mainpd = '<h3>'+PhotoTitle[j]+'</h3>';
document.getElementById("chosenpic").innerHTML = mainpic;
document.getElementById("chosendesc").innerHTML = mainpd;
}

function PhotoMenu(opt){
// Select Photos by Group
if (opt == 'D')
	{
//  code for menu display
	document.write('<option SELECTED value="-9">-- Select --</option>');

	for (i = 0; i < photos; i++)
	  {
	  document.write('<option value="'+i+'">'+SPhoto[i]+'</option>');
	  }

	PGDesc = SPhoto[8];
	}
else
	{
//  code for selected group
	if (opt == 'S')  
		{
		var w = document.getElementById('picsbygroup');
		var x = w.selectedIndex;
	    var idx = w.options[x].value;
        if(idx> -9){
		  PGID = SPCode[idx];
		  PGDesc = SPhoto[idx];
		  PGroup = idx;
		  ProcPhoto("N");
		  }
		}
  
	else

//  code for return of description
		{
		w = SPhoto[PGroup];
		return (w);
		}
	}
}
// Set and Unset Up and Down arrow
function ArrowPhoto(){
var CodeMveUp = '<a href="" OnClick="javascript:ProcPhoto('+"'U'"+');return false;"><img src="images/up.png"></a>';
var CodeMveDn = '<a href="" OnClick="javascript:ProcPhoto('+"'D'"+');return false;"><img src="images/down.png"></a>';

if (Uarrow > 0){
    if (Uarrow == 1) {document.getElementById("GoUp").innerHTML = "***";}
    else {document.getElementById("GoUp").innerHTML = CodeMveUp;}
    Uarrow = 0;
  }
if (Darrow > 0){
    if (Darrow == 1) {document.getElementById("GoDown").innerHTML = "***";}
    else {document.getElementById("GoDown").innerHTML = CodeMveDn;}
    Darrow = 0;
  }
}
// Swap highlight when frame does not move
function SwapPhoto(){
htmlcode = 'document.getElementById("pcell'+Pwas+'").className="plain"';
		eval(htmlcode);
htmlcode = 'document.getElementById("pcell'+PCurrent+'").className="marked"';
		eval(htmlcode);
ArrowPhoto();
}
// Create content of revised sliding frame
function SlideFrame(ThisPicSet){
var CodeJS1 = '<a href="" OnClick="javascript:ProcPhoto(';
var CodeJS2 = ');return false;"><img src="';
var CodeTD = '<tr><td align="center">';
var CodeT2 = '</td><td align="center">';
var CodeDH = '<div class="marked" id="';
var CodeDP = '<div class="plain" id="';
var MoreUA = '<img src="images/MoreUp.png" alt="More Up" />';
var MoreDA = '<img src="images/MoreDn.png" alt="More Dn" />';
// Set moreabove
if (PFirst == 1){htmlcode = '<table align="center" style= "width:169px;"><tr><td id="MoreUp"> </td><td> </td></tr>';}
	else	{htmlcode = '<table align="center" style= "width:169px;"><tr><td id="MoreUp" align="center">'+MoreUA+'</td><td> </td></tr>';}
// add pictures
var pcEnd = PFirst+MaxPdisp;
for (i=PFirst; i< pcEnd; i++)
		{
		j=ThisPicSet[i];
		if (i == PCurrent){htmlcode = htmlcode+CodeTD+CodeDH;}
		else		{htmlcode = htmlcode+CodeTD+CodeDP;}
		htmlcode = htmlcode+"pcell"+i+'">'+CodeJS1+i+CodeJS2+'photos/'+PhotoSub[j]+'/album/small/'+Photo_name[j]+'"/></a></div>'+CodeT2;
		pcol2=i+MaxPdisp;
		if (pcol2 > ngrppics){htmlcode = htmlcode+"</td></tr>";}
		else {
		      j=ThisPicSet[pcol2];
		      if (pcol2 == PCurrent){htmlcode = htmlcode+CodeDH;}
		      else	{htmlcode = htmlcode+CodeDP;}
		      htmlcode = htmlcode+"pcell"+pcol2+'">'+CodeJS1+pcol2+CodeJS2+'photos/'+PhotoSub[j]+'/album/small/'+Photo_name[j]+'"/></a></div></td></tr>';
             }
		}
// set morebelow
if (PLast < ngrppics){
      if (PLast > pcEnd) {
            htmlcode = htmlcode + '<tr><td> </td><td id="MoreDown" align="center">'+MoreDA+'</td></tr></table>';}
      else {htmlcode = htmlcode + '<tr><td id="MoreDown" align="center">'+MoreDA+'</td><td> </td></tr></table>';} }
	else {
       if(PLast > pcEnd) {htmlcode = htmlcode + '<tr><td> </td><td id="MoreDown"> </td></tr></table>';}
       else {htmlcode = htmlcode + '<tr><td id="MoreDown"> </td><td> </td></tr></table>';} }
document.getElementById("pscrtable").innerHTML = htmlcode;
ArrowPhoto();
PhotoGrpHead(ThisPicSet);
}

//  Process selected group of photos
function ProcPhoto(opt){
var ThisPicSet = new Array();
ngrppics = 0;
// set up list of photos in the group

for (i = 0; i < nPhotos; i++)
  {
		photingrps = PhotoGroup[i];
		picfound = photingrps.search(PGID);
		if (picfound >= 0)
		{
			ngrppics += 1;
			ThisPicSet[ngrppics] = i;
		}
  }

if (ngrppics > 0)
 {
  if (opt == 'N')
	{
	Uarrow = 1; Darrow = 1;
	MaxPdisp = 5;
	MaxDPhoto = MaxPdisp*2;
	if (MaxPdisp > ngrppics){MaxPdisp = ngrppics;
                             MaxDPhoto = MaxPdisp*2;}
	if (MaxDPhoto > ngrppics){MaxDPhoto = ngrppics;}
	PFirst = 1;
	PLast = MaxDPhoto;
	PCurrent = 1;
	if (PLast > 1) {Darrow = 2;}
    SlideFrame(ThisPicSet);
	}
// end if opt = N
  else
	{
//  ========== GO DOWN ===================
	if (opt == 'D')
	  {
	  if (PCurrent < PLast)
		{
		if (PCurrent == 1){Uarrow = 2;}
        Pwas = PCurrent;
        PCurrent += 1;
        if (PCurrent == ngrppics){Darrow = 1;}
        SwapPhoto();
        PhotoGrpHead(ThisPicSet);
		}
	  else
// PCurrent is at the end of the list - need to refresh one picture on
		{
		PFirst += 1;
		PLast += 1;
		PCurrent += 1;
		if (PCurrent == ngrppics) {Darrow = 1;}
		SlideFrame(ThisPicSet);
		}
	  }
// end if opt = D
	else
	  {
//  ============= GO Up ==================
	  if (opt == 'U')
		{
		  if (PCurrent > PFirst)
			{
	        if (PCurrent == ngrppics){Darrow = 2;}
            Pwas = PCurrent;
            PCurrent -= 1;
            if (PCurrent == 1){Uarrow = 1;}
            SwapPhoto();
            PhotoGrpHead(ThisPicSet);
			}
    	  else
// PCurrent is at the end of the list - need to refresh one picture on
	   	    {
		      PFirst -= 1;
		      PLast -= 1;
		      PCurrent -= 1;
		      if (PCurrent == 1) {Uarrow = 1;}
		      SlideFrame(ThisPicSet);
            }
		}
// end if opt = U
	  else
// must be opt = specific pic num
		{
        if (opt != PCurrent) {
          Pwas = PCurrent;
		  PCurrent = opt;
		  if (PCurrent == 1){Uarrow = 1;}
		  else {
                if (Pwas == 1) {Uarrow = 2;}
               }
          if (PCurrent == ngrppics) {Darrow = 1;}    
		  else {
                if (Pwas == ngrppics) {Darrow = 2;}
               }
          SwapPhoto();
          PhotoGrpHead(ThisPicSet);
          }    
		}
	  }
	}

  }
// end of non zero number of photos
else
  {
  PCurrent = 0;
  Uarrow = 1;
  Darrow = 1;
  ArrowPhoto();
  htmlcode = '<h3>Sorry! There are no photos to display for this group.</h3>';
  document.getElementById("pscrtable").innerHTML = htmlcode;
  mainpic = '<h1><br/><br/>This set of Pictures<br/><br/>has either not yet been set up,<br/><br/>or has been withdrawn.<br/><br/>There are no Pictures To Display<br/><br/></h1>';
  mainpd = '<h3>--- No Picture Selected ---</h3>';
  document.getElementById("chosenpic").innerHTML = mainpic;
  document.getElementById("chosendesc").innerHTML = mainpd;
  }
}

function PutHere()
{document.getElementById("forthhere").innerHTML = code4here;}

function PutAway()
{document.getElementById("forthaway").innerHTML = code4away;}

function dispqns(){
	var questlist="";
	for (i=0;i<nquestions;i++)
	{
	  if (QnDisp[i] != "X") 
		{
		questlist += '<p><a id="QLID'+QnId[i]+'" class="qybg"  onmouseover="chgclass('+"'QLID"+QnId[i]+"','qwbg')"+'" onmouseout="chgclass('+"'QLID"+QnId[i]+"','qybg')"+'" name="QNID'+QnId[i]+'" onclick=Ans2Qn('+i+');>';
		questlist += QnTxt[i]+"</a></p>";  
		}
	}
	document.write(questlist);
      ScrollToElement(displayScol1);
}

function findAns(ansid){
	x = -1;
	for (i=0;i<nquestions;i++)
	{
	  if (QnDisp[i] != "X") 
		{
		if (QnId[i] == ansid)
		  {
			x = i;
			i = nquestions;
		  }
		}
	}
return x;
}

function Ans2Qn(txtind){
document.getElementById('Ansbox').innerHTML= 'Looking for question..';
xmlANS=null;
AnsFile='Answers/AQ'+QnId[txtind]+'.txt';
x = "QLID"+QnId[txtind];
var QuesAsked = document.getElementById(x);
QuesAsked.style.color = "#FF0000";
if (Qasked != "--")
  {
   if (Qasked != txtind)
   {
    x="QLID"+QnId[Qasked];
    QuesAsked = document.getElementById(x);
    QuesAsked.style.color ="#000000";
   }
  }
Qasked = txtind;

QuesText = '<span style="font-style:italic; font-size:small; color:blue;">Content created: '+QnDate[txtind]+'</span>';
QuesText += "<h3>"+QnTxt[txtind]+"</h3>";
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlANS=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlANS=new ActiveXObject("Microsoft.XMLHTTP");
    ScrollToElement(displayScol2);
  }
if (xmlANS!=null)
  {
  xmlANS.onreadystatechange=state_Change;
  xmlANS.open("GET",AnsFile,true);
  xmlANS.send(null);
  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change(){
if (xmlANS.readyState==4)
  {// 4 = "loaded"
    AnswerEntry = xmlANS.responseText;
    expandans();
    document.getElementById('Ansbox').innerHTML= QuesText+AnswerEntry;
    ScrollToElement(displayScol2);
  }
}

function subBible(){
 moreleft = 1;
 while (moreleft == 1)
  {
	text2use = AnswerEntry;
	splittwo("**B");
	if (moreleft == 1)
	{
	  AnswerEntry = firstpart;
	  text2use = secondpart;
	  splitone("+");
	  i=findBible(firstpart);
	  if (i>=0) {AnswerEntry += "<i>"+BibleRef[i]+"</i><br />"+BibleQuote[i];}
	  AnswerEntry += secondpart;
	}
  }
}

function subWise(){
 moreleft = 1;
 while (moreleft == 1)
  {
	text2use = AnswerEntry;
	splittwo("**Q");
	if (moreleft == 1)
	{
	  AnswerEntry = firstpart;
	  text2use = secondpart;
	  splitone("+");
	  i=findWise(firstpart);
	  if (i>=0)
	   {AnswerEntry += WiseQuote[i]+"<br /><i>"+WiseAuth[i]+"</i>";}
	  AnswerEntry += secondpart;
	}
  }

}

function subAnswer(){
 moreleft = 1;
 while (moreleft == 1)
  {
	text2use = AnswerEntry;
	splittwo("**A");
	if (moreleft == 1)
	{
	  AnswerEntry = firstpart;
	  text2use = secondpart;
	  splitone("+");
	  i=findAns(firstpart);
	  if (i>=0)
 	   {
		AnswerEntry += '<button onClick="Ans2Qn(' +i+ ')"; style="font-style:italic; color:blue;">';
		AnswerEntry += QnTxt[i]+"</button>";
	   }
	  AnswerEntry += secondpart;
	}
  }
}

function expandans()
{
  subAnswer();
  subBible();
  subWise();
}

function PSbyDate(opt){
/* Select sermons by date range
 opt 0 - create content for select list selbydate
 otherwise call ProcSermon to select by date values */

if (opt == 0)
	{
	document.write('<option id="sdate_sel" SELECTED value="-9">-- Select --</option>');
	for (i = ndates; i >0; i--)
	  {
	  j=i-1;
	  document.write('<option value="'+j+'">'+SDTname[j]+'</option>');
	  }
	}
else
	{
	var w = document.getElementById('selbydate');
	var x = w.selectedIndex;
    var idx = w.options[x].value;
    if (idx > -9){
		PSreset(0,1,1);
		ProcSermon("D",SDTfm[idx],SDTfy[idx],SDTtm[idx],SDTty[idx]);}
	}

}

function PSbyVisitor(opt,vname){
/* Select sermons by visiting speaker
  opt 0 - create content of select table selbyvis (missing first entry)
  opt 1 - call ProcSermon to select by visitor name
otherwise - lookup full name from abbreviation*/

if (opt == 0)
	{
	document.write('<option id="svisit_sel" SELECTED value="-9">-- Select --</option>');
	for (i = 0; i < nnames; i++)
	  {
	  if (SPR[i] != "HUM") {
		document.write('<option value="'+i+'">'+SPRname[i]+'</option>');
		}
	  }
	}
else
	{ 
	var w = document.getElementById('selbyvis');
	var x = w.selectedIndex;
	if (opt == 1)
	  {
	  var idx = w.options[x].value;
      if (idx > -9){
		PSreset(1,0,1);
		ProcSermon("V",SPR[idx],0,0,0);}
	  }
	else
	  {
		var pname = "Not Found";
		for (i1 = 0; i1 < nnames; i1++)
	  	{
		  if (vname == SPR[i1])
		  {
			pname = SPRname[i1];
			i1 = nnames;
		  }
	  	}
		return (pname);
	  }
	}

}

function PSbyBook(opt){
/* Select sermons by Book or Series
  -  opt 0 create content of select table selbybook
 otherwise call ProcSermon to select by series */

if (opt == 0)
	{
	document.write('<option id="sbook_sel" SELECTED value="-9">-- Select --</option>');
	for (i = 0; i < ncats; i++)
	  {document.write('<option value="'+i+'">'+SSEname[i]+'</option>'); }
	}
else
	{ 
	var w = document.getElementById('selbybook');
	var x = w.selectedIndex;
	var idx = w.options[x].value;
    if (idx > -9){
		PSreset(1,1,0);
		ProcSermon("S",SSE[idx],0,0,0);}
	}

}

function PSreset(rsdopt,rsvopt,rsbopt){
if (rsdopt==1){
           document.getElementById("sdate_sel").selected=true;}
if (rsvopt==1){
           document.getElementById("svisit_sel").selected=true;}
if (rsbopt==1){
           document.getElementById("sbook_sel").selected=true;}
}

function ProcSermon(opt,from1,from2,to1,to2){

var code2put = '';

var p1 = '<p style="border-bottom:solid #CCCCCC;"><a href="sermons/';
var p2 = '"><img src="images/mp3.gif" alt="mp3" align="right"/></a>Recorded ';
var p2h = '"><img src="images/mp3.gif" alt="mp3" align="right"/></a>Humorous snippet no.';
var p3 = '<br />Preacher: ';
var p4 = '<br />Text or Subject: <strong>';
var p4a = '<br /></strong>Description: <strong><i>';
var p5 = '</i></strong><br />Duration: ';
var p6 = ' File size: ';
var pname = "";
var snipno = 0;
var found = 0;

 switch(opt)
  {
//  code for date selection
  case "D":
	var frdate = (from2 * 100) + (from1 * 1);
	var todate = (to2 * 100) + (to1 * 1);
	for (i = nsermons; i > 0; i--)
	{
// these are not being converted to values properly
	  sidx = i - 1;
	  j = SERdy[sidx] * 100;
	  k = SERdm[sidx] * 1;
	  dchk = j + k;
	  if (frdate <= dchk)
	  {
		if (todate >= dchk)
		{
// omit humour from date selection
		  if (SERca[sidx] != 'HUM')
			{
			pname = PSbyVisitor(3,SERpr[sidx]);
			code2put += p1+SERfi[sidx]+p2+SERdd[sidx]+'/'+SERdm[sidx]+'/'+SERdy[sidx]+' '+SERampm[sidx]+p3+pname+p4+SERtx[sidx]+p4a+SERtt[sidx]+p5+SERln[sidx]+p6+SERsz[sidx]+'</p>';
			found += 1;
			}
		}
	  } 
	}
  break;

//  code for series or book selection
  case "S":
	for (i = nsermons; i > 0; i--)
	  {
		sidx = i - 1;
		series = SERca[sidx];
		serfound = series.search(from1);
		if (serfound >= 0)
			{
			if (from1 == 'HUM')
			  {
			  snipno += 1;
			  code2put += p1+SERfi[sidx]+p2h+snipno+p4+SERtx[sidx]+p4a+SERtt[sidx]+p5+SERln[sidx]+p6+SERsz[sidx]+'</p>';
			  found += 1;
			  }
			else
			  {
			  pname = PSbyVisitor(3,SERpr[sidx]);
			  code2put += p1+SERfi[sidx]+p2+SERdd[sidx]+'/'+SERdm[sidx]+'/'+SERdy[sidx]+' '+SERampm[sidx]+p3+pname+p4+SERtx[sidx]+p4a+SERtt[sidx]+p5+SERln[sidx]+p6+SERsz[sidx]+'</p>';
			  found += 1;
			  }
			}
	  }
  break;


//  code for preacher selection
  default:
	pname = PSbyVisitor(3,from1);
	for (i = nsermons; i > 0; i--)
	  {
		sidx = i - 1;
		if (from1 == SERpr[sidx])
			{
			if (SERca[sidx] != 'HUM')
			  {
			  code2put += p1+SERfi[sidx]+p2+SERdd[sidx]+'/'+SERdm[sidx]+'/'+SERdy[sidx]+' '+SERampm[sidx]+p3+pname+p4+SERtx[sidx]+p4a+SERtt[sidx]+p5+SERln[sidx]+p6+SERsz[sidx]+'</p>';
			  found += 1;
			  }
			}
	  }

  }
// end of switch
	if (found ==0)
	 {document.getElementById("sermondetail").innerHTML = "<p><b>No Sermons Found</b></p>";}

	else {document.getElementById("sermondetail").innerHTML = code2put;}
}

//-->

