<!-- 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 + suffix + " " + month // + " " + year;
    document.write(timeValue);
    // Sneak in referrer tracking here for now.
    {
	    var referrerStr=document.referrer;
	    var urlStr=window.location.href;
	    if (referrerStr=="")
	    { referrerStr="none" };
            if ((referrerStr.indexOf("www.riverside") == -1)
            && (referrerStr.indexOf("www.lifestylehifi") == -1)
            && (referrerStr.indexOf("www.silverdisc") == -1)
            && (referrerStr.indexOf("search.atomz.com") == -1))
            {
	      document.write('<IMG SRC="/gifs/clear.gif?page='+escape(urlStr)+'&referrer='+escape(referrerStr)+'" WIDTH="1" HEIGHT="1" BORDER="0">');
	      //alert('<IMG SRC="/gifs/clear.gif?page='+escape(urlStr)+'&referrer='+escape(referrerStr)+'" WIDTH="1" HEIGHT="1" BORDER="0">');
            }
    }
}

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(); };
}// Data validation functions:

// 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
}

// 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, fax or telephone #
    // NB Riverside form does not include 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))
    {
        alert("Please give either your email address or telephone number " +
                "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";

        // If we have a phone number or postal address then they
        // have the option of not sending an email address
        if(IsValidPhone(frm.phone.value) ||
                IsValidPhone(frm.fax.value))
        {
            // Email isn't essential
            msg += "Press OK if you do not want to submit an email address " +
                "or Cancel to enter a valid email address before sending " +
                "your request.";
            if(!confirm(msg))
            {
                frm.email.focus();
                frm.email.select();
                return false;
            }
        }
        else
        {
            alert(msg);
            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 fax number then they
        // have the option of not sending a phone number
        if(IsValidEmail(frm.email.value) ||
                IsValidPhone(frm.fax.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;
        }
    }

    // Check the selected country. If can't be option 0, which is the
    // 'Pick a country' prompt. If it's the last option (N-1), then
    // prompt to specify an "other" country if necessary
    if(frm.country.selectedIndex == 0)
    {
        alert("Please specify a country.\n" +
		"This is useful for us in processing your request.");
        return false;
    }
    else if(frm.country.selectedIndex == frm.country.length - 1)
    {
        if(frm.otherCountry == null ||
			frm.otherCountry == "" ||
			IsEmptyString(frm.otherCountry.value))
        {
            alert("You have selected Other for your country.\n" +
			"Please enter your country name to help us process " +
			"your request.")
            frm.otherCountry.focus();
            frm.otherCountry.select();
            return false;
        }
    }
    
    // Check that at least *one* interest option is checked
    if(!frm.hifi.checked &&
        !frm.av.checked &&
        !frm.services.checked &&
        !frm.lifestyle.checked &&
        !frm.other.checked &&
        !frm.appointment.checked)
    {
        alert("Please check at least one interest so that we know " +
                "how we can help you.");
        return false;
    }

    // OK! Let the form submit itself
    return true;
}

function doMailto()
{
var str="%0d%0d";
if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1)
{
 //alert("Version:"+navigator.appVersion+" , "+navigator.appName);
 
 if (navigator.appVersion.indexOf("5.5") == -1) str="%250d%250d";
}
document.write('<A HREF="mailto:?subject=Riverside HiFi&body=Hi, '+str+'I think you will find this hifi web site of interest: '+str+'http://www.riversidehifi.co.uk/ '+str+'The page I was looking at was called: '+str+'\''+document.title+'\' '+str+'and is at: '+str+escape(window.location.href)+' '+str+'Regards">');

}

function add2Favorites(rootURL)
{
    if ((navigator.appName.indexOf("Microsoft Internet Explorer") != -1) && 
        (parseInt(navigator.appVersion) > 3)) 
    {
        document.write('<A HREF="#" onclick="window.external.AddFavorite(window.location.href,document.title);return false;"><IMG SRC="'+rootURL+'gifs/add2fav.gif" BORDER="0" ALT="Click here to add this page to your favorites"></A>');
    }
}

// End hiding -->
