// @@@@@ 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) {
  remoteWin = window.open("","photo","resizable=1,width=200,height=200,status=1,scrollbars=1");
  with (remoteWin.document) {
    open('text/html', 'replace');
    write('<html style="overflow-y:auto;"><head><meta http-equiv="imagetoolbar" content="no"><title>'+siteName+'</title><link rel="stylesheet" type="text/css" href="http://www.'+mainDomain+'/css/default-1.css"><!--[if IE]><style type="text/css">body{overflow-y:auto;}</style><![endif]--></head><body style="margin:15px 0;font-size:11px;" onload="var iW=document.popupImg.width+40, iH=document.popupImg.height+120; if (iW > screen.width) iW=screen.width-100; if (iH > screen.height) iH=screen.height-100; resizeTo(iW,iH); window.focus();"><div align="center"><img border="0" src="' + img + '" name="popupImg"><br><br>[<a href="javascript:window.close()">close window</a>]</div></body></html>');
    close();
  }
}


// @@@@@ generic popup window @@@@@

function popup(doc,name,s,w,h,r) {
  remoteWin=window.open(doc,name,"scrollbars=" + s + ",width=" + w + ",height=" + h + ",resizable=" + r);
  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.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,'mapquest','1','795','580','1')
    else alert("Invalid post code.\nPlease try again.");
}


// @@@@@ 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>');
}
