// Churches Together in Royston and District script library
// Written by Paul Brown, 2005

// Mail obfuscation functions ---------------------------------------------------

function mailTo (user, domain, subj)
{
   var addr = "mailto:"+user+"@"+domain;
   addr += subj?("?subject="+subj):"";
   return addr;
}

function mailToMe ( subj )
{
   return mailTo("webmaster", "ct-royston.org.uk", subj);
}

// Colour scheme ----------------------------------------------------------------------

var colourThisPage = '#ffaaaa';
var colourOtherPage = '#ffdddd';
var colourHilight = '#ddffdd';
var colourSelected = '#ffcccc';

// Page navigation column functions -----------------------------------------

function write_other_page(words,link,status)
{
	document.write( "<td class=\"menu\" bgcolor='"+ colourOtherPage + "' " +
		"onmouseover=\"this.style.background='" + colourHilight + "'; status='" + status + "'\" "+
		"onmouseout=\"this.style.background='"+ colourOtherPage + "'; status=' '\" "+
		"onmousedown=\"this.style.background='"+ colourSelected + "'\" "+
		"onclick=\"top.location.href='" + link + "'\">" );
	document.write(words + "</td></tr>\n");
}

function write_this_page(words,prefix)
{
	document.write("<td class='menu' bgcolor='"+colourThisPage+"'><img align=right src='"+prefix+"tinyleft.jpg' height=20 width=16>");
	document.write(words + "</td></tr>\n");
}

function ctNavMenu (current, folder)
{
   var curpage = Math.floor(current);
   var subpage = Math.floor((current-curpage)*10+0.5);

   var prefix=folder?folder:"";
   var words = new Array();
   var links = new Array();
   var status = new Array();
   var subs = new Array();

   words[0] = "Home";
		links[0] = prefix+"index.php";
		status[0] = "Churches Together home page";
   words[1] = "Contact";
		links[1] = prefix+"contact.php";
		status[1] = "Contact us";
   words[2] = "Events";
		links[2] = prefix+"events.php";
		status[2] = "Forthcoming and past events";
		subs[2] = new Array(0,6,7,8);
   words[3] = "Resources";
		links[3] = prefix+"resources.php";
		status[3] = "Forms and documents";
   words[4] = "Investing";
		links[4] = prefix+"invest.php";
		status[4] = "Investing in Churches Together";
   words[5] = "Links";
		links[5] = prefix+"links.php";
		status[5] = "Links to related sites";

   words[6] = "> Easter";
		links[6] = prefix+"easter.php";
		status[6] = "Details of Easter services";
   words[7] = "> Hope";
		links[7] = prefix+"hope/index.html";
		status[7] = "Hope 08";
   words[8] = "> Christmas";
		links[8] = prefix+"christmas.php";
		status[8] = "Summary of Christmas services";

// alert("Arg="+current+", Cur="+curpage+", Sub="+subpage);

   document.write("<table border=0 cellspacing=6 width=\"116px\">");
   for (var i = 0; i < 6; i++)
   {
      document.write("<tr>");
      if (curpage==i)
      {
	if (subpage>0)
	  write_other_page(words[i],links[i],status[i]);
	else
	  write_this_page(words[i],prefix);
	if (subs[i])
	  for (var j=1;j<subs[i].length; j++)
	  {
	    document.write("<tr>");
	    if (subpage==j)
	      write_this_page(words[subs[i][j]],prefix);
	    else
	      write_other_page(words[subs[i][j]],links[subs[i][j]],status[subs[i][j]]);
	  }
      }
      else
      {
	write_other_page(words[i],links[i],status[i]);
      }
   }
   document.write("</table>");
}

function ctNavFoot()
{
   document.write("<p><hr><address>" +
	"<font size=-1><a class='mailme' href='#' onmouseover='this.href=mailToMe()'>WebMaster</a></font></address>"  	);
}

// Header row ----------------------------------------------------------------

function ctHeadRow( subHeading, folder )
{
   var prefix=folder?folder:"";
   document.write( "<tr> <td class=\"header\">" );
   document.write( "<img align=right src=\""+prefix+"cross.jpg\"     height=85 style=\"position:absolute; right:175px\">" );
   document.write( "<img align=right src=\""+prefix+"jubilee2.jpg\" height=70 style=\"position:absolute; top:45px; right:40px\">" );
   document.write( "<img align=right src=\""+prefix+"kids.jpg\"       height=70 style=\"position:absolute; top:60px; right:110px\">" );
   document.write( '<h2>Churches Together in Royston and District</h2>' );
   document.write( "<h2>" + subHeading + "</h2> </td></tr>" );
}

// Forms Library functions ----------------------------------------------

function addUpForm()
{
   var formWin = parent.form;
   var amountCtls = formWin.document.getElementsByName("amount");
   var totalCtl = formWin.document.getElementById("total");

   var sum = 0.0;
   for (var i=0; i<amountCtls.length; i++)
   {
      var num = parseFloat(amountCtls[i].value);
      if (!isNaN(num)) sum += num;
   }

   totalCtl.value = sum.toString();
}

function shortDate()
{
   var now = new Date();
   var month = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec");
   return ( now.getDate().toString() + " " + month[now.getMonth()] + " " + now.getFullYear() );
}

function printForm()
{
   parent.form.focus();
   parent.form.print();
}

