function printWaitMessage()
{
  // write the text in grey (from within the HTML doc) so it is not visible 
  
  // <P><FONT COLOR="#EEEEEE"><B ID="pleasewait">This page may take a few seconds to
  // load. Please wait ...</B></FONT><SCRIPT>printWaitMessage();</SCRIPT></P>
    
  e = document.getElementById('pleasewait');	// use W3C DOM, global e
  if (!e) e = document.all['pleasewait'];	// Use IE4 DOM
  if (e)
  // if browser is compliant, make the text visible
  {
    e.style.color = '#FF0000';
  }
}

function hideWaitMessage()
{
  if (e)
  // if browser is compliant, make the text invisible and over-writable
  {
    e.style.position = 'absolute';	// ie allow text to be overprinted
    e.style.color = '#EEEEEE';		// belt and braces
    e.style.visibility='hidden';	// hide the 'please wait' text
  }
}

function timeToLive()
{
  cookietime = parseInt(document.cookie.substr(document.cookie.indexOf('login=')+6));
  
  timeNow = new Date();
  seconds = Math.floor(timeNow.getTime()/1000);
  
  timeZero = new Date('11 Nov 2007');
  zeroOffset = Math.floor(timeZero.getTime()/1000);
  
  return (-(-cookietime - zeroOffset - duration) - seconds);
}



function displayCookie()
{
  document.form3.cookie.value = document.cookie;
  document.form3.ttl.value = timeToLive() ;
  //document.form3.timenow.value = seconds;  
  timerID = setTimeout('displayCookie()', 1000);
  //document.form3.duration.value = duration;
}



function makeWindow(w,h,url,name)
// Open a new window resize it and focus on it. 
// Return the window object, which will be false if the window could not be 
// created - e.g. if pop-ups prevented it
{
  aw = w * screen.width;
  ah = h * screen.height;
  // window.alert('aw = ' + aw + '; ah = ' + ah);
  ax = (screen.width-aw)/2;
  ay = (screen.height-ah)/2;
  as = 'height='+ah+',width='+aw+',left='+ax+',screenX='+ax+',top='+ay+',screenY='+ay;
  a = window.open(url, name, as + ',status=yes,resizable=yes,scrollbars=yes');
  a.focus(); 
  return a;  // return the window object
}



function openURL(s)
/* This function is called from within the PHP-generated anchor tags, which are of the form:
   <A href="../../nojscript.html" 
   ONMOUSEOVER="this.href='downloads.html?f=06701'" 
   ONCLICK="return openURL(this.href);">
*/
{
  if (document.cookie.indexOf('test=123') == -1)
  {
    q = window.confirm ('Your browser is reporting that Cookies\n' +
    			'are not available, so you cannot view \n' +
    			'the online content. Do you wish to view\n' +
    			'further information about this problem?');
    if (q) location.href = '../../nocookies.html';
    return false;
  }
  
  if (timeToLive() < 0)
  { 
    q = window.confirm ('You are not logged in. To view online content \n' +
			'you must login as a member of BCRA or a Guest.\n\n' + 
			'Login now?')
    if (!q) return false;  // i.e. dont follow link 
    
    // User wants to login, so attempt to open a new window
    // makeWindow() returns window object. 
    // If window object exists, return false so that the <A> tag link is NOT followed
    // If window object was not created, return true so that we follow the link
    
    usewidth = 5/8; useheight = 4/8;
    q = !makeWindow(usewidth, useheight, s, 'BCRAdownloads');
    
    if (q) { window.alert('DEBUG info: window not created\n\nPlease tell David Gibson'); }
    
    // 20-jan-2008: What's that about?  When is window not created?
        
    return q;
  }
  else 
  // we are logged in, so return true so that the link is followed. However, this 
  // will not result in a page being displayed because the PDF's "do you want to run or save" box
  // will appear instead.
  {
  return true;
  }
}