  if (!styleSheet) var styleSheet="main.css";

// @@@@@ adding a favourite @@@@@

function addBookmark() {
  if (window.external)
    external.AddFavorite("http://www."+mainDomain+"/",siteName)
  else
    alert("We're sorry, your browser does not support this feature.\n\nPlease manually add our site to your Bookmarks\n(typically, keystroke Ctrl+D), thank you.");
}

function drawAddFav(linkText) {
  if (!linkText) var linkText="Add us to your Favourites";
  document.write('<a href="javascript:addBookmark();" target="_self" title="Click now to add us to your Favourites">'+linkText+'</a>');
}


// @@@@@ generating a spam-safe e-mail address @@@@@

function drawEmail(alias,text,dn,title) {
  var at = '&#064;'; // at symbol encoded
  var p1 = '&#109;&#097;&#105;&#108;'; // protocol name encoded part 1
  var p2 = '&#116;&#111;&#58;'; // protocol name encoded part 2
  if (!dn) dn=mainDomain;
  if (title) title=' title="'+title+'"'
    else title='';
  if (!text) text=alias+at+dn;
  document.write('<a href="'+p1+p2+alias+at+dn+'"'+title+'>'+text+'</a>');
}


// @@@@@ popup window to Image size and wrap in HTML @@@@@

function popupImg(img,addH,addW,caption) {
  var w = ((addW) ? addW : 0);
  var h = ((addH) ? addH : 0);
  var c = ((caption) ? ('<p align="center">' + caption + '</p>') : '');
  remoteWin = window.open("","photo","resizable=1,width=200,height=200,status=1,scrollbars="+(((h<0)||(w<0)) ? "1" : "0"));
  with (remoteWin.document) {
    open('text/html', 'replace');
    write('<html><head><meta http-equiv="imagetoolbar" content="no"><title>'+siteName+'</title><link rel="stylesheet" type="text/css" href="http://www.'+mainDomain+'/'+styleSheet+'"></head><body style="margin:20px;font-size:11px;" onload="resizeTo(document.popupImg.width+60+'+w+',document.popupImg.height+190+'+h+'); window.focus()"><p align="center"><img border="0" src="' + img + '" name="popupImg"></p>' + c + '<p align="center">[<a href="javascript:window.close()">close window</a>]</p></body></html>');
    close();
  }
}

function popupTxt(txt,s,w,h,r) {
  remoteWin=window.open("","text","scrollbars=" + s + ",width=" + w + ",height=" + h + ",resizable=" + r);
  with (remoteWin.document) {
    open('text/html', 'replace');
    write('<html><head><title>'+siteName+'</title><link rel="stylesheet" type="text/css" href="http://www.'+mainDomain+'/'+styleSheet+'"></head><body style="margin:10px;">'+txt+'<p>[<a href="javascript:window.close()">close window</a>]</p></body></html>');
    close();
  }
}

// @@@@@ generic popup window @@@@@

function popup(doc,name,scroll,width,height,resize,status,toolbar,locbar,menubar,dirs) {
  var scr = ((scroll) ? ",scrollbars="+scroll : "");
  var wid = ((width) ? ",width="+width : "");
  var hei = ((height) ? ",height="+height : "");
  var res = ((resize) ? ",resizable="+resize : "");
  var sta = ((status) ? ",status="+status : "");
  var too = ((toolbar) ? ",toolbar="+toolbar : "");
  var loc = ((locbar) ? ",location="+locbar : "");
  var men = ((menubar) ? ",menubar="+menubar : "");
  var dir = ((dirs) ? ",directories="+dirs : "");
  remoteWin=window.open(doc,name,scr+wid+hei+res+sta+too+loc+men+dir);
  remoteWin.focus();
}


function drawDate() {
    var now = new Date();
    now.setTime(now.getTime() - 0);
    var day = now.getDay();
    var date = now.getDate();
    var month = now.getMonth();
    var year = now.getFullYear();
    year += (year < 1900) ? 1900 : 0;
    var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    document.write(days[day] + ", " + date + " " + months[month] + " " + year);
}


// @@@@@ DirectMe @@@@@

var validPC=true;
function isPC(pc) {
  if (validPC) popup('http://www.google.co.uk/local?f=d&hl=en&q=from%3A+'+pc+'+to%3A+'+postcode,'glocal','1','795','580','1')
    else alert("Invalid post code.\nPlease try again.");
}
// 'http://www.mapquest.co.uk/cgi-bin/mqtrip?link=btwn/twn-ddir_options_jumppage&print.x=1&LangOpt=1&CC_0=GB&CC_1=GB&CITY_1=AYLESBURY&ZIP_1='+postcode+'&ZIP_0='+pc


// @@@@@ PrintPage @@@@@

function drawPrintLink(text,title,conf) {
  if (title) title=' title="'+title+'"'
    else title=' title="Print this page"';
  if (!text) text='print';
  if (conf)
  document.write('<a href="javascript:window.print();" onclick="return confirm(\'Conserve our environment.  \\n\\nOnly print this page if you\\nneed to. Continue?\');"'+title+'>'+text+'</a>');
}function daysFromNow(days) {
  delete now;
  now = new Date();
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    now.setTime(now.getTime() - skew);
  // above 'fix' from DocJS.com, for older browsers I think :S
  now.setTime(now.getTime() + days * 24 * 60 * 60 * 1000);
  return now;
}

function generate(x, y) { // creates a random number between two given integers

  var range = y - x + 1;
  return (Math.floor(Math.random() * range) + x);

}; // END generate()
