<!-- Hide from old browsers
// Unless otherwise noted, all JavaScript is copyright 
// (c) SilverDisc Ltd 1996-2002: all rights reserved. 

// Language constants:
var English = 1;
var NumLanguages = 1;

// Variables:
var timerID = null;
var timerRunning = false;

var months;
var days;

// Controls:
var language = English;
var twentyfourhour = false;

function MakeEmptyArray(n)
{
    var i;
    this.length = n;
    for(i = 1; i <= n; i++)
    {
        this[i] = null;
    }
    return this;
}

function MakeFilledArray()
{
    // Make an array of strings
    var i;

    this.length = MakeFilledArray.arguments.length;
    for(i = 1; i <= this.length; i++)
    {
        this[i] = MakeFilledArray.arguments[i - 1];
    }
    return this;
}


function showDate ()
{
    var now = new Date();
    var dow;
    var month;
    var date;
    var year;
    var timeValue;
    var suffix;
    var suffidx;

    // Initialise the arrays
    months = new MakeEmptyArray(NumLanguages);
    months[English] = new MakeFilledArray("January", "February", "March", "April", 
                                        "May", "June", "July", "August",
                                        "September", "October", "November", "December");

    days = new MakeEmptyArray(NumLanguages);
    days[English] = new MakeFilledArray("Sunday", "Monday", "Tuesday", "Wednesday",
                                     "Thursday", "Friday", "Saturday");
    dow = days[language][now.getDay() + 1];
    month = months[language][now.getMonth() + 1];

    date = now.getDate();
    // if(date < 10)
    // {
    //     date = "0" + date;
    // }

    year = now.getYear();
    // The following line required for 2 digit years in some browsers
    if (year.toString().length != 4 ) { year = year +1900 };

    timeValue = " " + dow;

    suffidx=(date % 10)
    if (suffidx == 0) suffix="th";
    if (suffidx == 1) suffix="st";
    if (suffidx == 2) suffix="nd";
    if (suffidx == 3) suffix="rd";
    if (suffidx > 3) suffix="th";
    if ((date > 10) && (date < 20)) suffix="th";
    timeValue += " " + date + "<sup>" + suffix + "</sup>" + " " + month + " " + year;
    document.write(timeValue);
}

function goPage(fname)
{
    dest=eval("document."+fname+"Navigator.root.value")+eval("document."+fname+"Navigator.doc.options[document."+fname+"Navigator.doc.selectedIndex].value");
    //alert("go page:"+dest);
    self.location.href = dest;
    //document.TOCNavigator.doc.selectedIndex = "0";
    return false;
}

function newWindow(name,url,width,height,controls) 
{
  var param="width="+width+",height="+height;
  var winref;
  param=param+",resizable";
  if (controls =="SCROLL")
  {
    param=param+",scrollbars";
  }
  if (controls =="ALL")
  {
    param=param+",menubar,toolbar,location,status,scrollbars";
  }
  if (controls =="PRINT")
  {
    param=param+",menubar,scrollbars";
  }
  winref=window.open(url,name,param);
}

// Handle screen redraw problems in Navigator
if (navigator.appName=="Netscape")
{
  window.captureEvents(Event.RESIZE);
  window.onresize=function (evt){location.reload(); };
}


// Check whether string is empty or all white-space
function IsEmptyString(s)
{
    var i;

    // Quick checks for complete emptiness
    if(s == null) return true;
    if(s.length == 0) return true;
    
    // Look for non-whitespace in the string
    for(i = 0; i < s.length; i++)
    {
        // Check next character isn't empty
        var c = s.charAt(i);
        if(c != " " || c != "\t" || c != "\n" || c != "\r")
        {
            // Non-white space found - it's non-empty
            return false;
        }
    }
    // No non-space characters found - string is empty
    return true;
}

// Check for valid email address. Expect to see something like
// [A-Za-z0-9.]@[A-Za-z0-9].[A-Za-z0-9.] (i.e. xxx@yyy.zzz will do
// fine). To check this quickly, walk through looking for an '@'.
// Once found, start looking for a '.'.
function IsValidEmail(s)
{
    var i;
    
    // Quick check - is it empty?
    if(IsEmptyString(s))
    {
        return false;
    }

    // Look for @ 
    for(i = 0; i < s.length; i++)
    {
        if(s.charAt(i) == "@") break;
    }
    // Then look for .
    for( ; i < s.length; i++)
    {
        if(s.charAt(i) == ".") return true;

    }
    // Off the end? Missed either @ or .
    return false;
}

// Check for valid phone number. First character can be "+" (for
// international dialling). After that we only allow [0-9()[]- ]
function IsValidPhone(s)
{
    var i;

    // Quick check...
    if(IsEmptyString(s)) return false;  // Can't be empty

    // Check first character...
    i = 0;
    if(s.charAt(i) == "+")
    {
        i = 1;      // That's OK, don't check it again
    }

    // Check the rest...
    var validChars = "0123456789 -()[]";
    for( ; i < s.length; i++)
    {
        var c = s.charAt(i);
        if(validChars.indexOf(c) == -1)
        {
            return false;       // Invalid character
        }       
    }

    return true;    // If we get here the number is OK
}

function ValidatePhone(number, prompt, item)
{
    if(!IsValidPhone(number))
    {
        // Get the user to confirm he has no such number
        var msg;
        msg = "You have not entered a valid " + 
                    prompt + " number. ";
        msg += "Press 'Cancel' if you want to " +
                    (IsEmptyString(number) ? "enter" : "edit") +
                    " the number " +
                    "before submitting your details " +
                    "or 'OK' if you do not.";

        if(!confirm(msg))
        {
            if(item != null)
            {
                item.focus();
                item.select();
            }
            return false;
        }
    }
    return true;    // OK if we get out here
}

// Validate the "Response" form. User must supply certain bits
// of info.
function ValidateForm(frm)
{
    // Check that some sensible data has been entered
    // in key fields. Use must enter the following:
    // - contact name
    // - one or more of email, telephone #, postal address
    if(IsEmptyString(frm.contact.value))
    {
        alert("Please specify a contact name.");
        frm.contact.focus();
        frm.contact.select();
        return false;
    }

    if(IsEmptyString(frm.email.value) &&
            IsEmptyString(frm.phone.value) &&
            IsEmptyString(frm.postal.value))
    {
        alert("Please give either your email address, telephone number " +
                "or postal address, so that we can contact you.");
        frm.email.focus();
        frm.email.select();
        return false;
    }

    // If we have email or phone number check that they are valid
    if(!IsEmptyString(frm.email.value) &&
            !IsValidEmail(frm.email.value))
    {
        var msg;
        msg = "You have not entered a valid email address.\n";

	alert(msg);
	frm.email.focus();
	frm.email.select();
	return false;
    }

    if(frm.newsletter.checked)
    {
      if(!IsValidEmail(frm.email.value))
      {
        alert("Please specify a valid email address for newsletter");
        frm.email.focus();
        frm.email.select();
        return false;
      }
    }

    if(!IsEmptyString(frm.phone.value) &&
            !IsValidPhone(frm.phone.value))
    {
        var msg;
        msg = "You have not entered a valid phone number.\n";

        // If we have a valid email or postal address then they
        // have the option of not sending a phone number
        if(IsValidEmail(frm.email.value) ||
                !IsEmptyString(frm.postal.value))
        {
            // Phone no isn't essential
            msg += "Press OK if you do not want to submit a telephone " +
                "number or Cancel to enter a valid number before sending " +
                "your request.";
            if(!confirm(msg))
            {
                frm.phone.focus();
                frm.phone.select();
                return false;
            }
        }
        else
        {
            alert(msg);
            frm.phone.focus();
            frm.phone.select();
            return false;
        }
    }

    // OK! Let the form submit itself
    return true;
}

function doEm(name, addytext, addyurl)
{
  var addy="";

  if (addyurl == "")
  {
    addyurl='cleigh' + '.com';
  }

  addy= name + '\@' + addyurl;

  if (addytext=="ADDRESS")
  {
    addytext=addy;
  }
  document.write('<A HREF=\"mail' + 'to:' + addy + '?subject=Enquiry from Charlwood Leigh web site\">' + addytext + '</a>');
}


function aday(doc)
{
  var months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  var yr = "2006";
  var m = 4;
  var d = "1";
  var today = new Date();
  var year = today.getYear();
  var todaym = today.getMonth();
  var todayd = today.getDate();
  var todaystring = "";
  var futurestring = months[m-1]+" "+d+", "+yr;
  var numDays = 0;

  // alert("A Day: "+numDays);
  if (year < 1000)
  {
   year += 1900;
  }

  doc.write('<b>Pension A-Day: <a href="/mag/postaday.htm" title="Your Pension after A Day 2006">Guide to Your Pension</a>,&nbsp;<a href="/files/A-Day-brochure.pdf" title="Pension A Day April 2006 Guide">Free A-Day Guide</a></b>');
}
// End hiding -->
