var gVersion = "CSSU System version 1.41";
var gTitle;
var gTitleInd;
var gFirstName;
var gLastName;
var gAddress1;
var gAddress2;
var gAddress3;
var gAddress4;
var gPostCode;
var gCountry;
var gCountryInd;
var gPhone;
var gEmail;
var gEcclesia;
var gPriority;
var gComment;
var gMailList;
var days = new Array(8);
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";
var months = new Array(13);
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";

document.write('<script type="text/javascript" src="pricelist.js"></script>');

//---------------------------------------------------------------------||
// FUNCTION:    AddMenu                                                ||
// PARAMETERS:  None                                                   ||
// PURPOSE:     Adds menu to a page                                    ||
//---------------------------------------------------------------------||
function AddMenu()
{
  strText = "";
//  alert ("AddMenu");
  strText += "<p><a href='http://www.cssu.org.uk/index.htm'>Home</a></p>" +
           "<p><img border='0' src='images/pubs2.gif' alt='Things to Order'><br>" +     // Be Equipped
           "<a href='download.htm'>Download Lessons</a></p>";

  if (RegisteredOK())
    strText +="<p><a href='howtotext.htm'>How to order things</a><br>" +
              "<a href='regform.htm'>About you</a></p>";
  else if (C13n())
    strText +="<p><a href='howtonotreg.htm'>How to order things</a><br>" +                  // How to order 
              "<a href='register.htm'>About you</a></p>";                                   // About you
	else
	  strText +="<p><a href='wantorder.htm'>Want some books?</a></p>";                        // Want some books?

  strText +="<p><a href='infant.htm'>for ages 3-6</a><br>" +                                // Infants
						"<a href='junior.htm'>for ages 7-10</a><br>" +											            // Juniors		
            "<a href='senior.htm'>for ages 11-14</a><br>" +									     			      // Seniors
            "<a href='study.htm'>for ages 14+</a><br>" +								    				        // Study Class	
            "<a href='leaflets.htm'>Leaflets</a><br>" +													    				// Leaflets
            "<a href='prizes.htm'>Prizes & gifts</a><br>" +											    				// Prizes & gifts	
            "<a href='support.htm'>Support</a></p>";														    				// Support	

  if (RegisteredOK())
    strText +="<p><a href='orderdisp.htm'>Checkout</a></p>";										    				// Checkout	

  strText +="<p><a href='magazines.htm'>Magazines</a></p>";											    				// Magazines

  if (C13n())
    strText +="<p><img border='0' src='images/info2.gif' alt='Information'><br>" +      // Be informed
	              "<a href='crb.htm'>CRB checks</a><br>" +											    					// CRB checks
    	          "<a href='syllabus.htm'>Why the Syllabus?</a><br>" +						    				// Why the Syllabus?	
        	      "<a href='aims.htm'>How we work</a><br>" +										    					// How we work
            	  "<a href='playdesc.htm'>Play Library</a><br>" +								    					// Play Library
	              "<a href='links.htm'>Useful web sites</a><br>" +								    				// Useful Web sites	
              "<p><img border='0' src='images/new2.gif' alt='New'><br>" +               // Be up to date
        	      "<a href='conf.htm'>Teachers' Gathering</a><br>" +										    				// Teachers' Gathering
            	  "<a href='news1.htm'>Cut price software</a><br>" +                          // Cut price software
	              "<a href='news2.htm'>Child Protection</a></p>";                             // Child protection

  strText +="<p><img border='0' src='images/contact2.gif' alt='Contact us'><br>" +      // Get in touch
    	          "<a href='mailto:" + GetDistributorEmail('GB') + "'>Send an email</a><br>" +
            	  "<a href='donate.htm'>Make a donation</a></p>";
  document.write(strText);
  var dateObj = new Date(document.lastModified);
  var wday = days[dateObj.getDay() + 1];
  var lmonth = months[dateObj.getMonth() + 1];
  var date = dateObj.getDate();
  var fyear = dateObj.getYear();
  if (fyear < 2000)
    fyear = fyear + 1900;
document.write("<p>&nbsp;</p><p class='changedOn'>Page updated on<br>" + lmonth + " " + date + ", " + fyear + "</p>");
document.write("<img border='0' src='images/menubase.jpg' alt=''>");
}


//---------------------------------------------------------------------||
// FUNCTION:    AddRegInfo                                             ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Records information about a registered person          ||
//---------------------------------------------------------------------||
function AddRegInfo(thisForm)
{
  var blnFormOK = FormOK(thisForm);
  if (blnFormOK)
  {
    AnalyseRegInfo();
    i = thisForm.Title.selectedIndex;
    strTitle = thisForm.Title.options[i].value;
    strTitleInd = i;

    if ( thisForm.FirstName == null )
      strFirstName  = "";
    else
      strFirstName  = thisForm.FirstName.value;

    if ( thisForm.LastName == null )
       strLastName     = "";
    else
       strLastName     = thisForm.LastName.value;

    if ( thisForm.Address1 == null )
       strAddress1      = "";
    else
       strAddress1      = thisForm.Address1.value;

    if ( thisForm.Address2 == null )
       strAddress2      = "";
    else
       strAddress2      = thisForm.Address2.value;

    if ( thisForm.Address3 == null )
       strAddress3      = "";
    else
       strAddress3      = thisForm.Address3.value;

    if ( thisForm.Address4 == null )
       strAddress4      = "";
    else
       strAddress4      = thisForm.Address4.value;

    if ( thisForm.PostCode == null )
       strPostCode      = "";
    else
       strPostCode      = thisForm.PostCode.value;

    if ( thisForm.Phone == null )
       strPhone         = "";
    else
       strPhone         = thisForm.Phone.value;

    if ( thisForm.Email == null )
       strEmail      = "";
    else
       strEmail      = thisForm.Email.value;
			 
    i = thisForm.Country.selectedIndex;
    strCountry = thisForm.Country.options[i].value;
    strCountryInd = i;

    if ( thisForm.Ecclesia == null )
       strEcclesia      = "";
    else
       strEcclesia      = thisForm.Ecclesia.value;

    if (thisForm.Priority[0].checked)
       strPriority = "Speed";
    else
       strPriority = "Economy";

    if ( thisForm.Comment == null )
       strComment       = "";
    else
       strComment       = thisForm.Comment.value;

    if (thisForm.MailList[0].checked)
       strMailList = "Yes";
    else
       strMailList = "No";

    strRegInfo     = strTitle         + "|" +
                     strTitleInd      + "|" +
                     strFirstName     + "|" +
                     strLastName      + "|" +
                     strAddress1      + "|" +
                     strAddress2      + "|" +
                     strAddress3      + "|" +
                     strAddress4      + "|" +
                     strPostCode      + "|" +
                     strCountry       + "|" +
                     strCountryInd    + "|" +
                     strPhone         + "|" +
                     strEmail         + "|" +
                     strEcclesia      + "|" +
                     strPriority      + "|" +
                     strComment       + "|" +
                     strMailList;
    strName = "RegInfo";
    SetCookie(strName, strRegInfo, true, "/");
    blnGetCookieOK = GetCookie(strName);
    if (!blnGetCookieOK)
      alert("In order to register you need to set up your browser to accept cookies.");
    else
    {
      strMessage = "Thank you - your details have been updated.";
      if (gMailList == "Yes" && strMailList == "No") strMessage += "\nYour name will be removed from the Mailing List";
      if (gMailList == "No" && strMailList == "Yes") strMessage += "\nYour name will be added to the Mailing List";
      alert(strMessage);
      document.body.style.cursor = 'wait';
    }
  }
  return blnFormOK;
}

// Cursor control:
// auto         Browser determines which cursor to display based on the current context
// crosshair    Simple cross hair
// default      Platform-dependent default cursor (usually an arrow)
// hand         Hand
// move         Crossed arrows indicating something is to be moved
// dir-resize   Arrow indicating edge is to be moved (dir may be n, ne, nw, s, se, sw, e, or w)
// text         Editable text (usually an I-bar)
// wait         Hourglass or watch indicating that the program is busy and the user should wait
// help         Arrow with question mark indicating help is available


//---------------------------------------------------------------------------------||
// FUNCTION:    AddOrderForm                                                       ||
// PARAMETERS:  title:       The publication title                                 ||
//              price:       The unit price of the publication                     ||
//              code:        The product code of the publication                   ||
//              codes:       Optional array of codes for options                   ||
//              texts:       Optional array of texts for options                   ||
//              syllabus: Optional array of codes to be preselected in each year   ||
// RETURNS:     Null                                                               ||
// PURPOSE:     For browsers that support scripts, adds order form                 ||
//---------------------------------------------------------------------------------||

function AddOrderForm ( booktitle, code, codes, texts, syllabus )
{
if (RegisteredOK())
  {
    var strCountry = GetCountry();
    var strPrice = GetPrice(code, strCountry);
    var strText = "";
    if (strPrice == "*")
	strText = "<p align='right'>Not currently available in " + GetCountryName() +
                ". To order contact the CSSU secretary in the UK.</p>";
    else
    {
      strText += "<FORM NAME=order ACTION='orderdisp.htm' onSubmit='return AddToCart(this);'>";
      strText += "<div align='right'>";
      strText += "<table border='0'>";
      strText += "<tr><td colspan=4>";
      strText += "<p align='right'><b>" + booktitle + "</b>" + GetPriceInfo(code) + "&nbsp;&nbsp;</p></td></tr><tr>";
      if (codes != null)
      {
        strText += "<td><p align='right'><select name='ADDITIONALINFO' size='1'>";
        for (i in codes)
        {
          strText += "<option value='" + codes[i] + "'";
          if (syllabus != null)
          {
            if (codes[i] == syllabus[GetSyllabusYear()-1])
            {
              strText += " selected";
            }
          }
  	    strText += ">" + texts[i] + "</option>";
        }
        strText += "</select></p></td>";
      }
      strText += "<td><p align='right'>&nbsp;Quantity:&nbsp;</p></td>";
      strText += "<td><input type='text' size='2' maxlength='2' name=QUANTITY ";
      strText += "onChange='this.value=CKquantity(this.value)' value='1'></td>";
      strText += "<td width='100'><input type='image' src='images/addtocart.jpg' width='100' height='30'";
      strText += "alt='Select " + booktitle + "' border=0 align=top></td></tr></table>";
      strText += "<input type=hidden name=PRICE value='" + strPrice + "'>";
      strText += "<input type=hidden name=NAME value='" + booktitle + "'>";
      strText += "<input type=hidden name=ID_NUM value='" + code + "'>";
      if (codes != null)
      {
        strText += "<input type=hidden name=ADDTEXTS value='" + texts.join("~") + "'>";
        strText += "<input type=hidden name=ADDCODES value='" + codes.join("~") + "'>";
      }
      else
      {
        strText += "<input type=hidden name=ADDTEXTS value=''>";
        strText += "<input type=hidden name=ADDCODES value=''>";
      }
      strText += "</FORM>";
    }
    document.write(strText);
    document.close();
  }
}


//---------------------------------------------------------------------------------||
// FUNCTION:    AddRegFormHeader                                                   ||
// PARAMETERS:  none                                                               ||
// RETURNS:     Null                                                               ||
// PURPOSE:     For browsers that support scripts, adds registration form          ||
//---------------------------------------------------------------------------------||

function AddRegFormHeader()
{
  var strText = "";
  if (C13n())
  {
    strText += "<FORM name='RegForm' action='http://www.cssu.org.uk/cgi-bin/listmail123.cgi' method='get' onSubmit='return AddRegInfo(this);'>";
    strText += "<input name='subject' type='hidden' value='CSSU Mailing List Update'>";
    strText += "<input name='recipient' type='hidden' value='maillist@cssu.org.uk'>";
    strText += "<input name='redirect' type='hidden' value='../howtotext.htm'>";
    strText += "<input type='hidden' name='print_blank_fields' value='1'>";
    strText += "<input name='env_report' type='hidden' value='REMOTE_ADDR, HTTP_USER_AGENT'>";
  }
  else
  {
    strText += "<FORM name='RegForm' action='mailto:noaddress' method='get' onSubmit='return AddRegInfo(this);'>";
    strText += "<input name='subject' type='hidden' value='novalue'>";
    strText += "<input name='recipient' type='hidden' value='noaddress'>";
    strText += "<input name='redirect' type='hidden' value=''>";
    strText += "<input type='hidden' name='print_blank_fields' value='1'>";
    strText += "<input name='env_report' type='hidden' value='REMOTE_ADDR, HTTP_USER_AGENT'>";
  }
  document.write(strText);
  document.close();
}


//---------------------------------------------------------------------------------||
// FUNCTION:    AddRomanCartForm                                                   ||
// PARAMETERS:  title:       The publication title                                 ||
//              price:       The unit price of the publication                     ||
//              code:        The product code of the publication                   ||
//              codes:       Optional array of codes for options                   ||
//              texts:       Optional array of texts for options                   ||
//              syllabus: Optional array of codes to be preselected in each year   ||
// RETURNS:     Null                                                               ||
// PURPOSE:     For browsers that support scripts, adds order form                 ||
//---------------------------------------------------------------------------------||

function AddRomanCartForm ( booktitle, code, codes, texts, syllabus )
{
    var strText = "<form action=http://www.romancart.com/cart.asp method=post>" +
                  "<input type=hidden name=price value=1.99>" +
                  "<input type=hidden name=storeid value=10000>" +
                  "<input type=hidden name=quantity value=1>"
                  "<input type=hidden name=itemname value='A Great Product'>" +
                  "A Great Product in: <select name=itemname2>" +
                  "<option value='Green'>Green</option>" +
                  "<option value='Blue'>Blue</option>" +
                  "<option value='Orange'>Orange</option>" +
                  "</select>" +
                  "<input type=submit value='Add to Basket'>" +
                  "</form>";
    alert(strText);
    document.write(strText);
    document.close();
}


/*
{
if (RegisteredOK())
  {
    var strCountry = GetCountry();
    var strPrice = GetPrice(code, strCountry);
    var strText = "";
    if (strPrice == "*")
	strText = "<p align='right'>Not currently available in " + GetCountryName() +
                ". To order contact the CSSU secretary in the UK.</p>";
    else
    {
      strText += "<form action=http://www.romancart.com/cart.asp method=post>";
      strText += "<input type=hidden name=storeid value=52953>";
      strText += "<div align='right'>";
      strText += "<table border='0'>";
      strText += "<tr><td colspan=4>";
      strText += "<p align='right'><b>" + booktitle + "</b>" + GetPriceInfo(code) + "&nbsp;&nbsp;</p></td></tr><tr>";
      if (codes != null)
      {
        strText += "<td><p align='right'><select name='ADDITIONALINFO' size='1'>";
        for (i in codes)
        {
          strText += "<option value='" + codes[i] + "'";
          if (syllabus != null)
          {
            if (codes[i] == syllabus[GetSyllabusYear()-1])
            {
              strText += " selected";
            }
          }
  	    strText += ">" + texts[i] + "</option>";
        }
        strText += "</select></p></td>";
      }
      strText += "<td><p align='right'>&nbsp;Quantity:&nbsp;</p></td>";
      strText += "<td><input type='text' size='2' maxlength='2' name=quantity ";
      strText += "onChange='this.value=CKquantity(this.value)' value='1'></td>";
      strText += "<td width='100'><input type='image' src='images/addtocart.jpg' width='100' height='30'";
      strText += "alt='Select " + booktitle + "' border=0 align=top></td></tr></table>";
      strText += "<input type=hidden name=price value='" + strPrice + "'>";
      strText += "<input type=hidden name=name value='" + booktitle + "'>";
      strText += "<input type=hidden name=ID_NUM value='" + code + "'>";
      if (codes != null)
      {
        strText += "<input type=hidden name=ADDTEXTS value='" + texts.join("~") + "'>";
        strText += "<input type=hidden name=ADDCODES value='" + codes.join("~") + "'>";
      }
      else
      {
        strText += "<input type=hidden name=ADDTEXTS value=''>";
        strText += "<input type=hidden name=ADDCODES value=''>";
      }
      strText += "</FORM>";
    }
    document.write(strText);
    document.close();
  }
}
*/

//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm)
{
  blnDuplicate = false;
  iNumberOrdered = 0;
  iNumberOrdered = GetCookie("NumberOrdered");
  if ( iNumberOrdered > 15 )
  {
    strText = "Sorry, but it's only possible to order 16 different publications at once.\n" +
              "Please complete this order and start a new one.";
    alert(strText);
    window.location.href="orderdisp.htm";
  }
  else
  {
    if ( thisForm.ID_NUM == null )
      strCODE      = "";
    else
      strCODE      = thisForm.ID_NUM.value;

    if ( thisForm.QUANTITY == null )
      strQUANTITY  = "1";
    else
      strQUANTITY  = thisForm.QUANTITY.value;

    if ( thisForm.PRICE == null )
      strPRICE     = "0.00";
    else
      strPRICE     = thisForm.PRICE.value;

    if ( thisForm.NAME == null )
      strNAME      = "";
    else
      strNAME      = thisForm.NAME.value;

    strADDTEXT = "";
    if ( thisForm.ADDITIONALINFO == null )
      strADDCODE = "";
    else
    {
      strADDCODE = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
      texts = thisForm.ADDTEXTS.value.split("~");
      codes = thisForm.ADDCODES.value.split("~");
      for (i in codes)
      {
        if (strADDCODE == codes[i])
          strADDTEXT = texts[i];
      }
    }
    if ( iNumberOrdered > 0 )
    {
      for ( i = 1; i <= iNumberOrdered; i++ )
      {
        database = "";
        database = GetCookie("Order." + i);
        Token0 = database.indexOf("|", 0);
        Token1 = database.indexOf("|", Token0+1);
        Token2 = database.indexOf("|", Token1+1);
        Token3 = database.indexOf("|", Token2+1);
        Token4 = database.indexOf("|", Token3+1);
        strXCode = database.substring( 0, Token0 );                   // Product Code
        strXQnty = database.substring( Token0+1, Token1 );            // Quantity
        strXPrce = database.substring( Token1+1, Token2 );            // Unit Price
        strXDesc = database.substring( Token2+1, Token3 );            // Description
        strXTxtA = database.substring( Token3+1, Token4 );            // Additional Text
        strXCdeA = database.substring( Token4+1, database.length );   // Additional Code
        if ((strXCode == strCODE) && (strXTxtA == strADDTEXT))
        {
           blnDuplicate = true;
           break;
        }
      }  // for ( i = 1; i <= iNumberOrdered; i++ )
    }
    if (blnDuplicate)
    {
      if (strQUANTITY == strXQnty)
      {
        strMessage = "You have already selected " + strXQnty + " of " + strXDesc;
        if (strXTxtA != "") strMessage += ": " + strXTxtA;
        alert(strMessage);
      }
      else
      {
        strMessage = "You have selected " + strXQnty + " of " + strXDesc;
        if (strXTxtA != "") strMessage += ": " + strXTxtA;
        strMessage += "\nDo you want " + strQUANTITY + " instead?";
        if (window.confirm(strMessage))
        {
          dbUpdatedOrder = strCODE      + "|" +
                           strQUANTITY  + "|" +
                           strPRICE     + "|" +
                           strNAME      + "|" +
                           strADDTEXT   + "|" +
                           strADDCODE;
          strNewOrder = "Order." + i
          SetCookie(strNewOrder, dbUpdatedOrder, false, "/");
          blnDuplicate = false;
        }
      }
    }
    else
    {
      if (strQUANTITY == 1)
        strMessage = "1 copy of '" + strNAME;
      else
        strMessage = strQUANTITY + " copies of '" + strNAME;
      if (strADDTEXT != "") strMessage += ": " + strADDTEXT;

      strMessage += "' selected."
      strMessage += "\n\nWhen you have everything you need, click on 'Checkout' in the menu on the left.";
      if (window.confirm(strMessage))
      {
        iNumberOrdered++;
        dbUpdatedOrder = strCODE      + "|" +
                         strQUANTITY  + "|" +
                         strPRICE     + "|" +
                         strNAME      + "|" +
                         strADDTEXT   + "|" +
                         strADDCODE;
        strNewOrder = "Order." + iNumberOrdered;
        SetCookie(strNewOrder, dbUpdatedOrder, false, "/");
        SetCookie("NumberOrdered", iNumberOrdered, false, "/");
      }
    }  // if (!blnDuplicate)
  }
  return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    AnalyseRegInfo                                         ||
// PARAMETERS:  None                                                   ||
// RETURNS:     None                                                   ||
// PURPOSE:     Stores the components of RegInfo in global variables   ||
//---------------------------------------------------------------------||
function AnalyseRegInfo()
{
  database = GetCookie( "RegInfo" );
  var arg = "RegInfo=";
  var alen = arg.length;
  var clen = document.cookie.length;
  if ( ! ( alen > clen ) )
  {
    Token0 = database.indexOf( "|", 0);
    Token1 = database.indexOf( "|", Token0+1 );
    Token2 = database.indexOf( "|", Token1+1 );
    Token3 = database.indexOf( "|", Token2+1 );
    Token4 = database.indexOf( "|", Token3+1 );
    Token5 = database.indexOf( "|", Token4+1 );
    Token6 = database.indexOf( "|", Token5+1 );
    Token7 = database.indexOf( "|", Token6+1 );
    Token8 = database.indexOf( "|", Token7+1 );
    Token9 = database.indexOf( "|", Token8+1 );
    Token10 = database.indexOf( "|", Token9+1 );
    Token11 = database.indexOf( "|", Token10+1 );
    Token12 = database.indexOf( "|", Token11+1 );
    Token13 = database.indexOf( "|", Token12+1 );
    Token14 = database.indexOf( "|", Token13+1 );
    Token15 = database.indexOf( "|", Token14+1 );
    gTitle = database.substring( 0, Token0 );
    gTitleInd = database.substring( Token0+1, Token1 );
    gFirstName = database.substring( Token1+1, Token2 );
    gLastName = database.substring( Token2+1, Token3 );
    gAddress1 = database.substring( Token3+1, Token4 );
    gAddress2 = database.substring( Token4+1, Token5 );
    gAddress3 = database.substring( Token5+1, Token6 );
    gAddress4 = database.substring( Token6+1, Token7 );
    gPostCode = database.substring( Token7+1, Token8 );
    gCountry = database.substring( Token8+1, Token9 );
    gCountryInd = database.substring( Token9+1, Token10 );
    gPhone = database.substring( Token10+1, Token11 );
    gEmail = database.substring( Token11+1, Token12 );
    gEcclesia = database.substring( Token12+1, Token13 );
    gPriority = database.substring( Token13+1, Token14 );
// The MailList option was added after the system went live, so we need to allow for people who haven't got this item in the cookie
    if ( Token15 > 0 )
    {
      gComment = database.substring( Token14+1, Token15 );
      gMailList = database.substring( Token15+1, database.length );
    }
    else
    {
      gComment = database.substring( Token14+1, database.length );
      gMailList = "No";
    }
  }
  else
  {
    gTitle = "";
    gTitleInd = "";
    gFirstName = "";
    gLastName = "";
    gAddress1 = "";
    gAddress2 = "";
    gAddress3 = "";
    gAddress4 = "";
    gPostCode = "";
    gCountry = "";
    gCountryInd = "";
    gPhone = "";
    gEmail = "";
    gEcclesia = "";
    gPriority = "";
    gComment = "";
    gMailList = "";
  }
}


//---------------------------------------------------------------------||
// FUNCTION:    C13n                                                   ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function C13n()
{
  blnOK = false;
  if ( GetCookie( "RegInfo" ))
    blnOK = true;
  return blnOK
}



//---------------------------------------------------------------------||
// FUNCTION:    CheckElpis                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CheckElpis(checkString)
{
  if (checkString.toLowerCase() == "israel")
  {
    strName = "RegInfo";
    SetCookie(strName, "||||||||||||||||", true, "/");
    blnGetCookieOK = GetCookie(strName)
    if (!blnGetCookieOK)
      alert("To use this site to the full you need to set up your browser to accept cookies.\n" +
            "In Windows Explorer 6, go Tools -> Internet Options -> Security, then click on 'Custom Level',\n" +
            "look down for 'Cookies' and enable 'Cookies that are stored on your computer'.\n\n" +
            "In Netscape 6, go Edit -> Preferences -> Privacy & Security -> Cookies, and select\n" +
            "'Enable cookies for the originating Web site only'");
    else
    {
      alert("Thank you. The page will now reload, giving you full access.");
      opener.location.reload();
    }
  }
  window.close();
}


//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString)
{
   strNewQuantity = "";
   for ( i = 0; i < checkString.length; i++ )
   {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain)
{
  var ExpDate = new Date();
  ExpDate.setTime(ExpDate.getTime() + 1500*24*60*60*1000); // expire in 4 years 40 days
   if ( GetCookie(name) )
   {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=" + ExpDate.toGMTString();
//    alert("Deleted - " + unescape(document.cookie));
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    EmptyCart                                              ||
// PARAMETERS:  None                                                   ||
// RETURNS:     None                                                   ||
// PURPOSE:     Deletes all the cookies for the current order          ||
//---------------------------------------------------------------------||
function EmptyCart()
{
  iNumberOrdered = 0;
  iNumberOrdered = GetCookie("NumberOrdered");
  if ( iNumberOrdered > 0 )
  {
    for ( i = iNumberOrdered; i >=1; i-- )
    {
      strOrder = "Order." + i;
      DeleteCookie(strOrder, "/");
      SetCookie ("NumberOrdered", i-1, false, "/");
    }
  strName = "RegInfo";
  strRegInfo = GetCookie(strName);  // recreate this cookie to get the expiry date right
  SetCookie(strName, strRegInfo, true, "/");
  }
}



//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date)
{
   var base = new Date(0);
   var skew = base.getTime();
   date.setTime (date.getTime() - skew);
}



//---------------------------------------------------------------------||
// FUNCTION:    FormOK                                                 ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Boolean value indicating whether the form is OK        ||
// PURPOSE:     Check whether the registation information is valid.    ||
//---------------------------------------------------------------------||
function FormOK(thisForm) {
  var strErrors = "The following field[s] need to be completed or corrected: ";
  var blnFormOK = true;
  if (thisForm.FirstName.value == "") {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.FirstName.focus();
	blnFormOK = false;
	strErrors += "First Name";
  }
  if (thisForm.LastName.value == "") {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.LastName.focus();
	blnFormOK = false;
	strErrors += "Last Name";
  }
  if (thisForm.Address1.value == "") {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.Address1.focus();
	blnFormOK = false;
	strErrors += "Address Line 1";
  }
  if (thisForm.Address2.value == "") {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.Address2.focus();
	blnFormOK = false;
	strErrors += "Address Line 2";
  }
  if (thisForm.Country.selectedIndex == 0) {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.Country.focus();
	blnFormOK = false;
	strErrors += "Country";
  }
  strEmail = thisForm.Email.value;
  iAt = strEmail.indexOf("@")
  if (!((iAt > 0) && (strEmail.indexOf(".",iAt) > iAt+1))) {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.Email.focus();
	blnFormOK = false;
	strErrors += "Email Address";
  }
  if (thisForm.Ecclesia.value == "") {
      if (blnFormOK == false) strErrors += ", ";
	else thisForm.Ecclesia.focus();
	blnFormOK = false;
	strErrors += "Ecclesia";
  }
  if (!blnFormOK) alert(strErrors);
  return blnFormOK;
}



//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name)
{
   var browser = gVersion + ": " + navigator.appCodeName + "; " + navigator.appName + "; " + navigator.appVersion + "; " + navigator.userAgent + "; " + navigator.language + "; " + navigator.platform;
   WriteStatusBar(browser);
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(GetCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }
   return(null);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function GetCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if ( endstr == -1 )
      endstr = document.cookie.length;
//   alert("getcookie " + offset + " " + unescape(document.cookie.substring(offset, endstr)));
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCountry                                             ||
// PARAMETERS:  None                                                   ||
// RETURNS:     Country Code (if there is one) from Address Info       ||
// PURPOSE:     Find out where someone lives for document.writes       ||
//---------------------------------------------------------------------||
function GetCountry()
  {
  database = GetCookie( "RegInfo" );
  var arg = "RegInfo=";
  var alen = arg.length;
  var clen = document.cookie.length;
  if ( ! ( alen > clen ) )
    {
    strItems = database.split("|");
    return strItems[9];
    }
  else return "";
  }



//------------------------------------------------------------------------||
// FUNCTION:    GetCountryName                                            ||
// PARAMETERS:  None                                                      ||
// RETURNS:     Name of Country for CountryCode                           ||
//------------------------------------------------------------------------||
function GetCountryName()
{
   var strCountry = GetCountry();
   switch (strCountry)
   {
     case "GB" :
       strCountryName = "the UK"; break;
     case "CA" :
       strCountryName = "Canada"; break;
     case "AU" :
       strCountryName = "Australia"; break;
     case "US" :
       strCountryName = "the USA"; break;
     case "NZ" :
       strCountryName = "New Zealand"; break;
     default :
       strCountryName = "the country you live in";
   }
   return(strCountryName);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetCurrencyName                                        ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     Array with (Local Currency,Invoice Currency)           ||
//---------------------------------------------------------------------||
function GetCurrencyName(strCountry)
{
   switch (strCountry)
   {
     case "GB" :
       arrCurrency = new Array("Sterling", "Sterling"); break;
     case "CA" :
       arrCurrency = new Array("Canadian dollars", "Canadian dollars"); break;
     case "NZ" :
       arrCurrency = new Array("NZ dollars", "NZ dollars"); break;
     case "US" :
       arrCurrency = new Array("US dollars", "US dollars"); break;
     case "AU" :
       arrCurrency = new Array("Australian dollars", "Australian dollars"); break;
     default :
       arrCurrency = new Array("your local currency", "Sterling"); break;
   }
   return(arrCurrency);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetCurrencySymbol                                      ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     Currency Symbol for Prices                             ||
// PURPOSE:     Finds the Currency Symbol for a Country (default "£")  ||
//---------------------------------------------------------------------||
function GetCurrencySymbol (strCountry)
{
   switch (strCountry)
   {
     case "GB" :
       strSymbol = "£"; break;
     case "CA" :
       strSymbol = "$"; break;
     case "NZ" :
       strSymbol = "$"; break;
     case "US" :
       strSymbol = "$"; break;
     case "AU" :
       strSymbol = "$"; break;
     default :
       strSymbol = "£";
   }
   return(strSymbol);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetDistributorAddress                                  ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     Address(es) of local distributor(s)                    ||
//---------------------------------------------------------------------||
function GetDistributorAddress(strCountry)
{
   switch (strCountry)
   {
     case "treasurer" :
       arrDistInfo = new Array("33 Saxon Wood Road<br>Cheswick Green<br>Solihull<br>B90 4JR"); break;
     case "GB" :
       arrDistInfo = new Array("1400 Warwick Road<br>Knowle<br>West Midlands<br>B93 9LG"); break;
     case "CA" :
       arrDistInfo = new Array("Box 347<br>COALDALE<br>Alberta<br>T1M 1M4",
                               "519 Arrowhead Road<br>MISSISSAUGA<br>Ontario<br>L5H 1V5"); break;
     case "NZ" :
       arrDistInfo = new Array("PO Box 13-164<br>Johnsonville<br>WELLINGTON"); break;
     case "US" :
       arrDistInfo = new Array("16880 NE Herd Road<br>Newberg<br>OR 97132"); break;
     case "AU" :
       arrDistInfo = new Array("20 Downing Street<br>Blackburn<br>Victoria 3130"); break;
     default :
       arrDistInfo = new Array("1400 Warwick Road<br>Knowle<br>West Midlands<br>B93 9LG<br>United Kingdom"); break;
   }
   return(arrDistInfo);
}



//------------------------------------------------------------------------||
// FUNCTION:    GetDistributorDesc                                        ||
// PARAMETERS:  Country Code                                              ||
// RETURNS:     Array: (local method, local distributor, Web distributor) ||
//------------------------------------------------------------------------||
function GetDistributorDesc (strCountry)
{
   switch (strCountry)
   {
     case "GB" :
       arrDistributor = new Array("By post or email to ", "the CSSU secretary", "the CSSU secretary"); break;
     case "CA" :
       arrDistributor = new Array("By post or email to ", "your local distributors", "your local distributors"); break;
     case "AU" :
       arrDistributor = new Array("By post or email to ", "your local distributor", "your local distributor"); break;
     case "US" :
       arrDistributor = new Array("By post or email to ", "your local distributor", "your local distributor"); break;
     case "NZ" :
       arrDistributor = new Array("By post or email to ", "your local distributor", "your local distributor"); break;
     default :
       arrDistributor = new Array("By post or email to ", "the CSSU secretary", "the CSSU secretary in the UK"); break;
   }
   return(arrDistributor);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetDistributorEmail                                    ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     Array with email address(es) of local distributor(s)   ||
//---------------------------------------------------------------------||
function GetDistributorEmail(strCountry)
{
var at = "@";
   switch (strCountry)
   {
     case "treasurer" :
       arrDistInfo = new Array("rog.abi" + at + "virginmedia." + "com"); break;
     case "mark" :
       arrDistInfo = new Array("mark" + at + "cssu.org" + ".uk"); break;
     case "plays" :
       arrDistInfo = new Array("atropica" + at + "ho" + "tmail.c" + "o.uk"); break;
     case "GB" :
       arrDistInfo = new Array("christine" + at + "cssu.org.uk"); break;
     case "CA" :
       arrDistInfo = new Array("edle" + at + "telusplanet.net","ghents" + at + "sympatic" + "o.ca"); break;
     case "NZ" :
       arrDistInfo = new Array("full.house" + at + "xtra.co.nz"); break;
     case "US" :
       arrDistInfo = new Array("karencssuorders" + at + "yahoo.com"); break;
//       arrDistInfo = new Array("andrew.j.walker@blueyonder.co.uk"); break;
     case "AU" :
       arrDistInfo = new Array("marktmorgan" + at + "gmail.com"); break;
//       arrDistInfo = new Array("francaudery" + at + "optusnet.com.au"); break;
//       arrDistInfo = new Array("andrew.j.walker" + at + "blueyonder.co.uk"); break;
     default :
       arrDistInfo = new Array("christine" + at + "cssu.org.uk");
   }
   return(arrDistInfo);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetWebOrdersAddress                                    ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     String with name(s) of local distributor(s)            ||
//---------------------------------------------------------------------||
function GetWebOrdersAddress(strCountry)
{
var at = "@";
   switch (strCountry)
   {
     case "GB" :
       strAddress = "christine" + at + "cssu.org.uk"; break;

     case "CA" :
       strAddress = "edle" + at + "telusplanet.net,ghents" + "@" + "sympatico.ca"; break;
     case "NZ" :
       strAddress = "full.house" + at + "xtra.co.nz"; break;
     case "US" :
       strAddress = "karencssuorders" + at + "yahoo.com"; break;
//       strAddress = "andrew.j.walker" + at + "blueyonder.co.uk"; break;
     case "AU" :
       strAddress = "marktmorgan" + at + "gmail.com"; break;
//       strAddress = "francaudery" + at + "optusnet.com.au"; break;
//       strAddress = "andrew.j.walker" + at + "blueyonder.co.uk"; break;
     default :
       strAddress = "christine" + at + "cssu.org.uk";
   }
   return(strAddress);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetDistributorName                                     ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     Array with name(s) of local distributor(s)             ||
//---------------------------------------------------------------------||
function GetDistributorName(strCountry)
{
   switch (strCountry)
   {
     case "treasurer" :
       arrDistInfo = new Array("Roger Varley"); break;
     case "GB" :
       arrDistInfo = new Array("Christine Walker"); break;
     case "CA" :
       arrDistInfo = new Array("Peggy Hansaeme", "Alan Ghent"); break;
     case "NZ" :
       arrDistInfo = new Array("Angela Marsden"); break;
     case "US" :
       arrDistInfo = new Array("Karen Phillips"); break;
     case "AU" :
//       arrDistInfo = new Array("Fran Caudery"); break;
       arrDistInfo = new Array("Ruth Morgan"); break;
     default :
       arrDistInfo = new Array("Christine Walker");
   }
   return(arrDistInfo);
}



//---------------------------------------------------------------------||
// FUNCTION:    GetPrice                                               ||
// PARAMETERS:  Product Code, Country Code                             ||
// RETURNS:     Text to go in Price List                               ||
// PURPOSE:     Finds the price for an item, error message if missing  ||
//---------------------------------------------------------------------||
function GetPrice (strProduct, strCountry)
{
  switch (strCountry)
  {
    case "GB" :
      intPriceSet = 1; break;
    case "CA" :
      intPriceSet = 2; break;
    case "US" :
      intPriceSet = 3; break;
    case "AU" :
      intPriceSet = 4; break;
    case "NZ" :
      intPriceSet = 5; break;
    default :
      intPriceSet = 1;
  }
  blnFound = false;
  for (i in arrProds)
  {
    if (arrProds[i][0] == strProduct)
    {
      blnFound = true;
      break;
    }
  }
  if (blnFound)
    return(arrProds[i][intPriceSet]);
  else
  {
    alert(strProduct + " needs to have a price list set up for it.");
    return(-1);
  }
}



//---------------------------------------------------------------------||
// FUNCTION:    GetPriceInfo                                           ||
// PARAMETERS:  Product Code                                           ||
// RETURNS:     Writes text into order form                            ||
// PURPOSE:     Assembles price information item.                      ||
//---------------------------------------------------------------------||
function GetPriceInfo (strProduct) {
   var strCountry = GetCountry();
   var strText = "";
   if (strCountry != "")
   {
     strText += " - each " + GetSalesUnit(strProduct) + " costs ";
     strText += GetCurrencySymbol(strCountry) + moneyFormat(GetPrice(strProduct,strCountry));
   }
   else
     strText = "No price available";
   return strText;
}



//---------------------------------------------------------------------||
// FUNCTION:    GetSalesUnit                                           ||
// PARAMETERS:  Product Code                                           ||
// RETURNS:     Text to go in Price List                               ||
// PURPOSE:     Finds the unit of sale for a product - eg 'book'       ||
//---------------------------------------------------------------------||
function GetSalesUnit (strProduct)
{
  blnFound = false;
  for (i in arrProds)
  {
    if (arrProds[i][0] == strProduct)
    {
      blnFound = true;
      break;
    }
  }
  if (blnFound)
    return(arrProds[i][6]);
  else
    return("");
}


//---------------------------------------------------------------------||
// FUNCTION:    GetSyllabusYear                                        ||
// PARAMETERS:  None                                                   ||
// RETURNS:     The current Year Number (1-4) in the Syllabus          ||
//---------------------------------------------------------------------||
function GetSyllabusYear()
{
   var now = new Date();
   var thisYear = now.getFullYear()
// Change to the following year at the end of May
   if (now.getMonth() <= 4) thisYear = thisYear - 1;
// Turn the year into a number between 1 and 4.  Math.floor rounds down.
   return(thisYear - ((Math.floor(thisYear/4))*4) + 1);
}


//---------------------------------------------------------------------||
// FUNCTION:    InsertRegInfo                                          ||
// PARAMETERS:  Form Name                                              ||
// RETURNS:     Name/Address inserted into current form                ||
// PURPOSE:     Completed registration form with current information   ||
//---------------------------------------------------------------------||
function InsertRegInfo(thisForm)
{
  AnalyseRegInfo();
  document.RegForm.Title.options.selectedIndex = gTitleInd;
  document.RegForm.FirstName.value = gFirstName;
  document.RegForm.LastName.value = gLastName;
  document.RegForm.Address1.value = gAddress1;
  document.RegForm.Address2.value = gAddress2;
  document.RegForm.Address3.value = gAddress3;
  document.RegForm.Address4.value = gAddress4;
  document.RegForm.PostCode.value = gPostCode;
  document.RegForm.Phone.value = gPhone;
  document.RegForm.Email.value = gEmail;
  document.RegForm.Ecclesia.value = gEcclesia;
  document.RegForm.Country.value = gCountry;
  document.RegForm.Country.options.selectedIndex = gCountryInd;
  if (gPriority == "Speed")
     document.RegForm.Priority[0].click();
  else
     document.RegForm.Priority[1].click();
  if (gMailList == "Yes")
     document.RegForm.MailList[0].click();
  else
     document.RegForm.MailList[1].click();
}



//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input)
{
  var dollars = Math.floor(input);
  var tmp = new String(input);
  for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ )
  {
    if ( tmp.charAt(decimalAt)=="." ) break;
  }
  var cents  = "" + Math.round(input * 100);
  cents = cents.substring(cents.length-2, cents.length);
  dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;
  if ( cents.length == 1 ) cents = "0" + cents;
  return(dollars + "." + cents);
}



//---------------------------------------------------------------------||
// FUNCTION:    RegisteredOK                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     True if user has been registered, else false           ||
// PURPOSE:     Enables display to vary etc depending on registration  ||
//---------------------------------------------------------------------||
function RegisteredOK()
{
  blnOK = false;
  if ( GetCookie( "RegInfo" ))
  {
    database = GetCookie( "RegInfo" );
    if (database != "||||||||||||||||")        // Christadelphian but not registered
    {
      strItems = database.split("|");
      if (strItems[2] != "") blnOK = true;    // Check to see if first name is there
    }
  }
return blnOK
}



//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, false, "/");
      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, false, "/");
      DeleteCookie(NewOrder, "/");
      location.href=location.href;
	return false;
}



//---------------------------------------------------------------------||
// FUNCTION:    ReplaceAll                                             ||
// PARAMETERS:  strFull: The string to be worked on                    ||
//              strFrom: The string to be removed                      ||
//              strTo:   The string to replace what is removed         ||
// RETURNS:     New string in which each strFrom is now strTo          ||
// PURPOSE:     Replace characters in a string                         ||
//---------------------------------------------------------------------||
function ReplaceAll (strFull, strFrom, strTo)
{ var st = strFull;
  if (strFrom.length == 0)
     return st;
  var idx = st.indexOf(strFrom);
  while (idx >= 0)
  {  st = st.substring(0,idx) + strTo + st.substr(idx+strFrom.length);
     idx = st.indexOf(strFrom);
  }
  return st;
}



//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expires(boolean), path, domain, security  ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
  var ExpDate = new Date();
  ExpDate.setTime(ExpDate.getTime() + 1500*24*60*60*1000); // expire in 4 years 40 days
  document.cookie = name + "=" + escape (value) +
                   ((expires) ? "; expires=" + ExpDate.toGMTString() : "") +
                   ((path) ? "; path=" + path : "") +
                   ((domain) ? "; domain=" + domain : "") +
                   ((secure) ? "; secure" : "");
// alert("setcookie " + name + " " + unescape(document.cookie));
}



//---------------------------------------------------------------------||
// FUNCTION:    SetCountry                                             ||
// PARAMETERS:  Country Code                                           ||
// RETURNS:     None                                                   ||
// PURPOSE:     Updates RegInfo cookie with Country Code               ||
//---------------------------------------------------------------------||
function SetCountry(strCode, strNumber)
  {
  if (RegisteredOK())
    {
    strItems = database.split("|");
    strItems[9] = strCode;
    strItems[10] = strNumber;
    strRegInfo = strItems.join("|");
    }
  else
    {
    strRegInfo = ("|||||||||" + strCode + "|" + strNumber + "||||||");
    }
  strName = "RegInfo";
  DeleteCookie(strName, "/");
  SetCookie(strName, strRegInfo, true, "/");
  }


//---------------------------------------------------------------------||
// FUNCTION:    WriteFootnote                                          ||
// PARAMETERS:  AddSendNote                                                   ||
// PURPOSE:     Writes a footnote at the bottom of a page              ||
//---------------------------------------------------------------------||
function WriteFootnote(AddSendNote) {
    strCountry = GetCountry()
	if (RegisteredOK())
      {
        switch(strCountry)
        {
          case 'GB' :
            strFootNote = '<p>Prices of publications cover only the cost of printing.&nbsp;&nbsp;' +
                          'When orders are despatched, an invoice is enclosed which includes, in addition, any postage costs.</p>'
            break;
          case 'US' :
            strFootNote = '<p>Prices are in US dollars, and cover the cost of printing ' +
                          'and bulk delivery from the UK.&nbsp;&nbsp;' +
                          'When orders are delivered within the USA, any local delivery charges will be added.</p>';
            break;
          case 'AU' :
            strFootNote = '<p>Prices are in Australian dollars, and cover the cost of printing ' +
                          'and bulk delivery from the UK.&nbsp;&nbsp;' +
                          'When orders are delivered within Australia, any local delivery charges will be added.</p>';
            break;
          case 'CA' :
            strFootNote = '<p>Prices are in Canadian dollars, and cover the cost of printing ' +
                          'and bulk delivery from the UK.&nbsp;&nbsp;' +
                          'When orders are delivered within Canada, any local delivery charges will be added.</p>';
            break;
          case 'NZ' :
            strFootNote = '<p>Prices are in NZ dollars, and cover the cost of printing ' +
                          'and bulk delivery from the UK.&nbsp;&nbsp;' +
                          'When orders are delivered within NZ, any local delivery charges will be added.</p>';
            break;
          default :
            strFootNote = '<p>Prices are in sterling, and cover only the cost of printing.&nbsp;&nbsp;' +
                          'When orders are despatched, an invoice is enclosed which includes any shipping charges.</p>';
        }

       if ( AddSendNote == "Y" )
         {
          strFootNote += "<p>When you have finished your selection, click on 'Send', and these details will be forwarded to " +
                      GetDistributorName(strCountry).join(' or '); +".</p>";
         }
       document.write(strFootNote);
      }
}



//---------------------------------------------------------------------||
// FUNCTION:    WriteOrder                                             ||
// PARAMETERS:  bEnable - true means add 'remove' buttons              ||
// RETURNS:     Product hidden fields written to Document              ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function WriteOrder( bEnable ) {
   iNumberOrdered = 0;
   fTotal         = 0;
   strTotal       = "";
   strOutput      = "";
   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == 0 || iNumberOrdered == null )
   strOutput += "<p align='center'><strong>You have not yet selected any items.</strong></p>";
   else
	{
       strOutput +=   "<TABLE align='center' border='0' cellspacing='0' cellpadding='1' width='90%'>" +
          		"<TR>" +
                  "<TD><h3>Description</h3></TD>" +
                  "<TD><h3>Quantity</h3></TD>" +
                  "<TD align='right'><h3>Each</h3></TD>" +
                  "<TD align='right'><h3>Total</h3></TD>";
       if ( bEnable )
       strOutput +=   "<TD align='center'><h3>Remove</h3></TD>";
       else
       strOutput +=   "<TD></TD></TR>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);
      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);
      strCode = database.substring( 0, Token0 );                   // Product Code
      strQnty = database.substring( Token0+1, Token1 );            // Quantity
      strPrce = database.substring( Token1+1, Token2 );            // Unit Price
      strDesc = database.substring( Token2+1, Token3 );            // Description
      strTxtA = database.substring( Token3+1, Token4 );            // Additional Text
      strCdeA = database.substring( Token4+1, database.length );   // Additional Code
      fLine   = (parseInt(strQnty) * parseFloat(strPrce) );        // Line Price
      fTotal += fLine;
      strTotal = moneyFormat(fTotal);
      var strCountry = GetCountry();
      var strCurrSymb =

      strOutput += "<TR>"
      if ( strTxtA == "" ) strFullDesc = strDesc;                  // Description
        else               strFullDesc = strDesc + ": " + strTxtA;
      strOutput += "<TD  align='left'><p>"  + strFullDesc + "</p></TD>" +                    // Full Description
                   "<TD  align='center'><p>"  + strQnty + "</p></TD>" +                    // Quantity
                   "<TD  align='right'><p>" + GetCurrencySymbol(GetCountry()) +  moneyFormat(strPrce) +
                   "</p></TD>" +        // Unit Price
                   "<TD  align='right'><p>" + GetCurrencySymbol(GetCountry()) + moneyFormat(fLine) +
                   "</p></TD>";           // Line Price
      if ( bEnable )
        strOutput += "<TD align=\'center\'>" +
                     "<a href=\'orderdisp.htm\' onClick='fnRemove("+i+")'>" +
                     "<img src=\'images/removedot.gif\' alt=\'Remove " + strFullDesc + "\' border=\'0\'></a>" +
                     "</TD></TR>";
      else
        strOutput += "<TD></TD></TR>";
      strOutput += "<input type=hidden name='NAME_"     + i + "' value='" + strDesc + "'>";
      strOutput += "<input type=hidden name='ADDTEXT_"+ i + "' value='" + strTxtA + "'>";
      strOutput += "<input type=hidden name='QUANTITY_" + i + "' value='" + strQnty + "'>";
      strOutput += "<input type=hidden name='PRICE_"    + i + "' value='" +
                     GetCurrencySymbol(GetCountry()) +  moneyFormat(strPrce)  + "'>";
      strOutput += "<input type=hidden name='CODE_"       + i + "' value='" + strCode + "'>";
      strOutput += "<input type=hidden name='ADDCODE_"+ i + "' value='" + strCdeA + "'>";
      }

      strOutput += "<TR>"
      strOutput += "<TD><p><br><b>TOTAL (excluding postage) </b></p></TD>"
      strOutput += "<TD></TD>";
      strOutput += "<TD></TD>";
      strOutput += "<TD align='right'><p><br><b>" + GetCurrencySymbol(GetCountry())  + moneyFormat((fTotal)) +
                   "</b></p></TD>";
      if ( bEnable )
        strOutput += "<TD align=\'center\'>" +
                     "<a href=\'orderdisp.htm\' onClick='fnClear()'>" +
                     "<img src=\'images/clear.gif\' alt=\'Remove all items from this order\' " +
                     "align=\'top\' border=\'0\'></a>" +
                     "</TD></TR>";
      else
        strOutput += "<TD></TD></TR>";
      strOutput += "</TABLE>";

      strOutput += "<input type=hidden name='TOTAL' value='£" + moneyFormat((fTotal)) + "'>";
	}
   document.write(strOutput);
   document.close();
}



//---------------------------------------------------------------------||
// FUNCTION:    WriteRegInfo                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Name/Address hidden fields written to Document         ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function WriteRegInfo( )
{
  AnalyseRegInfo()
  strOutput  = "";
  if ( gTitle == "" )
    strOutput = "<p>You need to complete the section 'About You'</p>";
  else
  {
    if ( gTitle == "Mr." )
      strOutput += "<p><strong>bro " + gFirstName + " " + gLastName + "<br>";
    else
      strOutput += "<p><strong>sis (" + gTitle + ") " + gFirstName + " " + gLastName + "<br>";
    if ( gAddress1 != "" ) strOutput += gAddress1 + ", ";
    if ( gAddress2 != "" ) strOutput += gAddress2 + ", ";
    if ( gAddress3 != "" ) strOutput += gAddress3 + ", ";
    if ( gAddress4 != "" ) strOutput += gAddress4 + ", ";
    if ( gPostCode != "" ) strOutput += gPostCode + ", ";
    if ( gCountry != "" )  strOutput += gCountry + "</strong><br>";
    if ( gPhone != "" )  strOutput += "Phone: <strong>" + gPhone + "</strong><br>";
    if ( gEmail != "" )  strOutput += "Email: <strong>" + gEmail + "</strong><br>";
    if ( gEcclesia != "" )  strOutput += "Ecclesia: <strong>" + gEcclesia + "</strong><br>";
    if ( gPriority != "" )  strOutput += "Delivery priority: <strong>" + gPriority + "</strong><br>";
    if ( gMailList != "" )  strOutput += "MailingList: <strong>" + gMailList + "</strong><br>";
    if (gComment != "")
      strOutput += "Comment: <strong>" + gComment + "</strong></p>";
    else
      strOutput += "</p>";
    strOutput += "<input type=hidden name='TITLE' value='" + gTitle + "'>";
    strOutput += "<input type=hidden name='FIRSTNAME' value='" + gFirstName + "'>";
    strOutput += "<input type=hidden name='LASTNAME' value='" + gLastName + "'>";
    strOutput += "<input type=hidden name='ADDRESS1' value='" + gAddress1 + "'>";
    strOutput += "<input type=hidden name='ADDRESS2' value='" + gAddress2 + "'>";
    strOutput += "<input type=hidden name='ADDRESS3' value='" + gAddress3 + "'>";
    strOutput += "<input type=hidden name='ADDRESS4' value='" + gAddress4 + "'>";
    strOutput += "<input type=hidden name='POSTCODE' value='" + gPostCode + "'>";
    strOutput += "<input type=hidden name='COUNTRY' value='" + gCountry + "'>";
    strOutput += "<input type=hidden name='PHONE' value='" + gPhone + "'>";
    strOutput += "<input type=hidden name='email' value='" + gEmail + " (" + gFirstName + " " + gLastName + ")'>";
    strOutput += "<input type=hidden name='ECCLESIA' value='" + gEcclesia + "'>";
    strOutput += "<input type=hidden name='PRIORITY' value='" + gPriority + "'>";
    strOutput += "<input type=hidden name='COMMENT' value='" + gComment + "'>";
    strOutput += "<input type=hidden name='MAILLIST' value='" + gMailList + "'>";
  }
  document.write(strOutput);
  document.close();
}


//---------------------------------------------------------------------||
// FUNCTION:    WriteRegAddress                                        ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Name/Address hidden fields written to Document         ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function WriteRegAddress( )
{
  AnalyseRegInfo()
  strOutput  = "";
  if ( gTitle == "" )
    strOutput = "<p>You need to complete the section 'About You'</p>";
  else
  {
    if ( gTitle == "Mr." )
      strOutput += "<p>bro " + gFirstName + " " + gLastName + "<br>";
    else
      strOutput += "<p>sis (" + gTitle + ") " + gFirstName + " " + gLastName + "<br>";
    if ( gAddress1 != "" ) strOutput += gAddress1 + "<br>";
    if ( gAddress2 != "" ) strOutput += gAddress2 + "<br>";
    if ( gAddress3 != "" ) strOutput += gAddress3 + "<br>";
    if ( gAddress4 != "" ) strOutput += gAddress4 + "<br>";
    if ( gPostCode != "" ) strOutput += gPostCode + "<br>";
    if ( gCountry != "" )  strOutput += gCountry + "<br>";
    if ( gPhone != "" )  strOutput += "Phone: " + gPhone + "<br>";
    if ( gEmail != "" )  strOutput += "Email: " + gEmail + "<br>";
    if ( gEcclesia != "" )  strOutput += "Ecclesia: " + gEcclesia + "<br>";
  }
  document.write(strOutput);
  document.close();
}


//---------------------------------------------------------------------||
// FUNCTION:    GiftAidDetails                                         ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Name/Address hidden fields written to Document         ||
// PURPOSE:     Draws current cart product hidden fields on HTML form  ||
//              if bDisplay == true, shows cart output as HTML table   ||
//---------------------------------------------------------------------||
function GiftAidDetails( )
{
  AnalyseRegInfo()
  strOutput  = "";
  if ( gTitle == "" )
  {
    strOutput += "<p class='fixedwidth'>Full name: ...................................................................</p>"
    strOutput += "<p class='fixedwidth'>Full address: ................................................................</p>"
    strOutput += "<p class='fixedwidth'>..............................................................................</p>"
    strOutput += "<p class='fixedwidth'>..............................................................................</p>"
    strOutput += "<p class='fixedwidth'>..............................................................................</p>"
    strOutput += "<p class='fixedwidth'>Amount: ......................Date:...........................................</p>"
    strOutput += "<p class='fixedwidth'>Signature: ...................................................................</p>"
  }
	else  
  {
    strOutput += gTitle + " " + gFirstName + " " + gLastName + "<br>";
    if ( gAddress1 != "" ) strOutput += gAddress1 + "<br>";
    if ( gAddress2 != "" ) strOutput += gAddress2 + "<br>";
    if ( gAddress3 != "" ) strOutput += gAddress3 + "<br>";
    if ( gAddress4 != "" ) strOutput += gAddress4 + "<br>";
    if ( gPostCode != "" ) strOutput += gPostCode + "<br>";
    if ( gCountry != "" )  strOutput += gCountry + "<br>";
    if ( gPhone != "" )  strOutput += "Phone: " + gPhone + "<br>";
    if ( gEmail != "" )  strOutput += "Email: " + gEmail + "<br>";
    if ( gEcclesia != "" )  strOutput += "Ecclesia: " + gEcclesia + "<br>";
    strOutput += "<p class='fixedwidth'>Amount: ......................Date:...........................................</p>"
    strOutput += "<p class='fixedwidth'>Signature: ...................................................................</p>"
  }
  document.write(strOutput);
  document.close();
}


//---------------------------------------------------------------------||
// FUNCTION:    WriteStatusBar                                         ||
// PARAMETERS:  text to display in the window's status bar             ||
// RETURNS:     true to keep the display there                         ||
// PURPOSE:     Displays text in the status bar                        ||
//---------------------------------------------------------------------||
function WriteStatusBar(strText)
{
  window.status = strText;
  return true;
}


