function setcookie(NameOfCookie, value){
 cookiestring= NameOfCookie + "=" + escape(value) + "; path=/; domain=.fantasticfiction.co.uk;";
 document.cookie=cookiestring;
}

function setpermcookie(NameOfCookie, value){
 expire = new Date();
 today = new Date();
 expire.setTime(today.getTime() + 3600000*24*90);
 cookiestring = NameOfCookie + "=" + escape(value) + "; expires=" + expire.toGMTString() + "; path=/; domain=.fantasticfiction.co.uk;";
 document.cookie=cookiestring;
}

function getcookie(NameOfCookie) {
if (document.cookie.length > 0) { 
  begin = document.cookie.indexOf(NameOfCookie+"="); 
  if (begin != -1) { 
    begin += NameOfCookie.length+1; 
    end = document.cookie.indexOf(";", begin);
    if (end == -1) end = document.cookie.length;
      return unescape(document.cookie.substring(begin, end)); 
  } 
}
return ''; 
}

function delcookie(NameOfCookie) {
 expire = new Date();
 today = new Date();
 expire.setTime(today.getTime() - 1800000);
 cookiestring = NameOfCookie + "=x" + "; expires=" + expire.toGMTString() + "; domain=.fantasticfiction.co.uk;";
 document.cookie=cookiestring;
}

function writePageupdated() {
var dt=new Date(Date.parse(document.lastModified));
var m = new Array;
m[0]="Jan";m[1]="Feb";m[2]="Mar";m[3]="Apr";m[4]="May";m[5]="Jun";m[6]="Jul";m[7]="Aug";m[8]="Sep";m[9]="Oct";m[10]="Nov";m[11]="Dec";
document.write(dt.getDate()+'-'+m[dt.getMonth()]+'-20'+right(dt.getYear(),2));
}
function right(str, n) {
if (n <= 0)
  return "";
else if (n > String(str).length)
  return str;
else { 
  var iLen = String(str).length;
  return String(str).substring(iLen, iLen - n);
}
}

function writeBookshopsuk() {
if (typeof dwAuthorName == 'undefined') {dwAuthorName = ''}
if (typeof dwBookTitle == 'undefined') {dwBookTitle = ''}
document.write('<table>');
document.write('<tr align="center"><td>');
document.write('<form name=bookshopukform target="_blank" method="get" action="http://log.fantasticfiction.co.uk/cgi-bin/bookshops.cgi" onsubmit="if (document.bookshopukform.shop.options[document.bookshopukform.shop.selectedIndex].value==\'amazonuk\') {return counter(\'/outgoing/amazonuk\')} else if(document.bookshopukform.shop.options[document.bookshopukform.shop.selectedIndex].value==\'abeuk\') {return counter(\'/outgoing/abeuk\')} else {return true}">');
document.write('<input type=hidden name=from value="page">');
document.write('<input type=hidden name=author value="');
document.write(dwAuthorName);
document.write('">');
document.write('<input type=hidden name=book value="');
if (dwBookTitle != "") {
document.write(dwBookTitle); } else {
document.write(''); }
document.write('">');
document.write('<table class="box">');
document.write('<tr><th bgcolor="darkblue">');
document.write('<font size="+1">Search the<br>UK bookshops</font>');
document.write('</th></tr>');
document.write('<tr><td align="center">');
document.write('<select size=9 name="shop">');
document.write('<option value="abeuk">Abebooks UK&nbsp');
document.write('<option selected value="amazonuk">Amazon UK&nbsp');
document.write('<option value="blackwell">Blackwell&nbsp');
document.write('<option value="bookdepository">BookDepository');
document.write('<option value="ebayuk">eBay UK&nbsp');
document.write('<option value="pickabook">Pickabook&nbsp');
document.write('<option value="play">Play.com');
document.write('<option value="waterstones">Waterstones&nbsp');
document.write('<option value="whsmith">WHSmith');
document.write('</select>');
document.write('</td></tr>');
document.write('<tr><td align="center">');
document.write('<input type="text" name="keywords" SIZE=16 VALUE="');
document.write(dwAuthorName);
if (dwBookTitle != "") {
document.write(' ');
document.write(dwBookTitle);
}
document.write('"></td></tr><tr><td align="center"><input type="submit" border=0 value="Search" name="Search"></td></tr></table></form></td></tr></table>');
}

function writeBookshopsus() {
if (typeof dwAuthorName == 'undefined') {dwAuthorName = ''}
if (typeof dwBookTitle == 'undefined') {dwBookTitle = ''}
document.write('<table><tr align="center"><td><form name=bookshopform target="_blank" method="get" action="http://log.fantasticfiction.co.uk/cgi-bin/bookshops.cgi" onsubmit="if (document.bookshopform.shop.options[document.bookshopform.shop.selectedIndex].value==\'amazon\') {return counter(\'/outgoing/amazon\')} else if(document.bookshopform.shop.options[document.bookshopform.shop.selectedIndex].value==\'abe\') {return counter(\'/outgoing/abe\')} else {return true}"><input type=hidden name=author value="');
document.write(dwAuthorName);
document.write('"><input type=hidden name=book value="');
if (dwBookTitle != "") {
  document.write(dwBookTitle);
} else {
  document.write('');
}
document.write('"><table class="box"><tr><th bgcolor="darkblue"><font size="+1">Search the<br>US bookshops</font></th></tr><tr><td align="center"><select size=7 name="shop"><option value="abe">Abebooks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<option  value="alibris">Alibris<option selected value="amazon">Amazon<option value="bn">Barnes &amp; Noble<option value="ebayus">eBay US<option value="half">Half.com<option value="powells">Powells</select></td></tr><tr><td align="center"><input type="text" name="keywords" SIZE=16 VALUE="');
document.write(dwAuthorName);
if (dwBookTitle != "") {
  document.write(' ');
  document.write(dwBookTitle);
}
document.write('"></td></tr><tr><td align="center"><input type="submit" border=0 value="Search" name="Search"></td></tr></table></form></td></tr></table>');
}

function writeebayheader(a, b) {
if (typeof country == 'undefined') {country = 'US'};

sc = getcookie('ffsc');
if (sc != '') {
 country = sc;
} 

var t = a + "'s " + b;

if (country == 'GB') {
  document.write('Current eBay UK auctions for ');
} else if (country == 'CA') {
  document.write('Current eBay CA auctions for ');
} else if (country == 'AU') {
  document.write('Current eBay AU auctions for ');
} else if (country == 'FR') {
  document.write('Current eBay FR auctions for ');
} else {
  document.write('Current eBay US auctions for ');
}
document.write(t);
}

function writeebay(a, b) {
if (typeof country == 'undefined') {country = 'US'};

sc = getcookie('ffsc');
if (sc != '') {
 country = sc;
} 

var s = a + ' ' + b;
s.replace(/ /g, '+');

if (country == 'GB') {
  document.write('<scr' + 'ipt language="JavaScript" src="http://ilapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=fyvlyklq%7B%7Eq%7Blqwv%28%29%21%21&bdrcolor=000000&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=y&fbgcolor=00008B&fntcolor=FFFFFF&fs=0&hdrcolor=000000&hdrimage=1&hdrsrch=y&img=y&lnkcolor=00FFFF&logo=3&num=6&numbid=y&paypal=n&popup=n&prvd=9&query=' + s + '&r0=1&shipcost=n&siteid=3&sort=MetaLowestPriceSort&sortby=price&sortdir=asc&srchdesc=n&tbgcolor=00008B&title=&tlecolor=000000&tlefs=0&tlfcolor=FFFFFF&toolid=10004&track=5335903573&width=740"></scr' + 'ipt>');

} else if (country == 'CA') {
  document.write('<scr' + 'ipt language="JavaScript" src="http://ilapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=fyvlyklq%7B%7Eq%7Blqwv%28%29%21%21&bdrcolor=000000&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=y&fbgcolor=00008B&fntcolor=FFFFFF&fs=0&hdrcolor=000000&hdrimage=1&hdrsrch=n&img=y&lnkcolor=00FFFF&logo=3&num=6&numbid=y&paypal=n&popup=n&prvd=9&query=' + s + '&r0=1&shipcost=n&siteid=2&sort=MetaLowestPriceSort&sortby=price&sortdir=asc&srchdesc=n&tbgcolor=00008B&title=&tlecolor=000000&tlefs=0&tlfcolor=FFFFFF&toolid=10004&track=5335903573&width=740"></scr' + 'ipt>');

} else if (country == 'AU') {
  document.write('<scr' + 'ipt language="JavaScript" src="http://ilapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=fyvlyklq%7B%7Eq%7Blqwv%28%29%21%21&bdrcolor=000000&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=y&fbgcolor=00008B&fntcolor=FFFFFF&fs=0&hdrcolor=000000&hdrimage=1&hdrsrch=n&img=y&lnkcolor=00FFFF&logo=3&num=6&numbid=y&paypal=n&popup=n&prvd=9&query=' + s + '&r0=1&shipcost=n&siteid=15&sort=MetaLowestPriceSort&sortby=price&sortdir=asc&srchdesc=n&tbgcolor=00008B&title=&tlecolor=000000&tlefs=0&tlfcolor=FFFFFF&toolid=10004&track=5335903573&width=740"></scr' + 'ipt>');

} else if (country == 'FR') {
  document.write('<scr' + 'ipt language="JavaScript" src="http://ilapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=fyvlyklq%7B%7Eq%7Blqwv%28%29%21%21&bdrcolor=000000&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=y&fbgcolor=00008B&fntcolor=FFFFFF&fs=0&hdrcolor=000000&hdrimage=1&hdrsrch=n&img=y&lnkcolor=00FFFF&logo=3&num=6&numbid=y&paypal=n&popup=n&prvd=9&query=' + s + '&r0=1&shipcost=n&siteid=71&sort=MetaLowestPriceSort&sortby=price&sortdir=asc&srchdesc=n&tbgcolor=00008B&title=&tlecolor=000000&tlefs=0&tlfcolor=FFFFFF&toolid=10004&track=5335903573&width=740"></scr' + 'ipt>');

} else {
  document.write('<scr' + 'ipt language="JavaScript" src="http://lapi.ebay.com/ws/eBayISAPI.dll?EKServer&ai=dm%7Bt%7Ei%2B%28%29&bdrcolor=000000&cid=0&eksize=1&encode=UTF-8&endcolor=FF0000&endtime=y&fbgcolor=00008B&fntcolor=FFFFFF&fs=0&hdrcolor=000000&hdrimage=1&hdrsrch=y&img=y&lnkcolor=00FFFF&logo=3&num=6&numbid=y&paypal=n&popup=n&prvd=9&query=' + s + '&r0=1&shipcost=n&siteid=0&sort=MetaLowestPriceSort&sortby=price&sortdir=asc&srchdesc=n&tbgcolor=00008B&title=&tlecolor=000000&tlefs=0&tlfcolor=FFFFFF&toolid=10004&track=5335903573&width=740"></scr' + 'ipt>');
}
}

function resizeiframe(f) {
  f.style.height = (f.contentWindow.document.body.scrollHeight) + "px";
}

document.domain = 'fantasticfiction.co.uk';
