var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
var url = location.href.substring(dir.length,location.href.length+1);

/* if the page is blank, they have come 
into the domain, so populate the default page
*/

if(url=="") {url="index.html"}

var isOver18=getCookie("Isover18");

/*
OK, lets look at the logic here
If the user arrives at the initial page, the address
will either be the domain name, or domain&index.html

First of all, test if the cookie has been set to yes;
if they have previously indicated that they are over
18, bounce them on to the main.html page.

If the page is any other, then see if they have said
they are over 18. If they have, allow them through,
otherwise, bounce them back to the index page and
let them say they are over 18
*/

if(url=="index.html" || url=="entry.html")
{
  if(isOver18=="yes")
  {
    window.location = "main.html";
  }
}
else
{
  if(isOver18!="yes")
  {
     window.location = "index.html";
  }
}


/* Call function as setCookie("cookiename" , cookievalue, lifetime, cookiepath)
with the lifetime required in days, -1 to delete a cookie or zero
for a temporary cookie. The Cookie Path is optional.*/

function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
  var today = new Date()
  cookie_life=0; // force to be session cookie only
  var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
  if (cookie_value != null && cookie_value != ""){
    var cookie_string =cookie_name + "=" + escape(cookie_value)
    if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
    if(cookie_path){ cookie_string += "; path=" + cookie_path}
 	document.cookie = cookie_string
  }
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->

/* Call function as getCookie("cookiename") It returns the value of a cookie
if set or null. Beware of potential ambiguities in names of cookies -
getCookie is simple and will match the end of a string so xyname
will also be matched by yname and ame. */

function getCookie(name) {
  var index = document.cookie.indexOf(name + "=")
  if (index == -1) { return null}
  index = document.cookie.indexOf("=", index) + 1
  var end_string = document.cookie.indexOf(";", index)
  if (end_string == -1) { end_string = document.cookie.length }
  return unescape(document.cookie.substring(index, end_string))
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->


function setOver18(){
    setCookie("Isover18", "yes", 10000);
    return true;
  }
 
