function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function leadingzero(nr) {
  if (nr < 10) nr = '0' + nr;
  return nr;
}

function displaymonth(month) {
  year = month.substr(0, 4);
  mm = month.substr(4);
  if (mm == '01') {dmon = 'January ' + year}
  else if (mm == '02') {dmon = 'February ' + year}
  else if (mm == '03') {dmon = 'March ' + year}
  else if (mm == '04') {dmon = 'April ' + year}
  else if (mm == '05') {dmon = 'May ' + year}
  else if (mm == '06') {dmon = 'June ' + year}
  else if (mm == '07') {dmon = 'July ' + year}
  else if (mm == '08') {dmon = 'August ' + year}
  else if (mm == '09') {dmon = 'September ' + year}
  else if (mm == '10') {dmon = 'October ' + year}
  else if (mm == '11') {dmon = 'November ' + year}
  else if (mm == '12') {dmon = 'December ' + year}
  return dmon;
}

function writegotopage(page, matchcount, resultsperpage) {
  if (matchcount > resultsperpage) {
    document.write('<table width="100%"><tr><td>');
    document.write('</td><td align="center">');

    document.write('&nbsp;&nbsp;&nbsp;Go to page: ');
    if (page < 5) {

      pen = 6;
      if (pen > Math.ceil(matchcount/resultsperpage)) {
        pen = (Math.ceil(matchcount/resultsperpage)+1);
      }
 
      for (pcnt=1; pcnt<pen; pcnt++) {
       if (pcnt != page) {
          document.write('<a href="' + geturl(pcnt) + '" rel="nofollow"><b>' + pcnt + '</b></a>&nbsp;&nbsp;');
        } else {
          document.write('<b>[' + pcnt + ']</b>&nbsp;&nbsp;');
        }
      }
      if (pcnt < Math.ceil(matchcount/resultsperpage)) {
        document.write('<b>. . .</b> &nbsp;');
        document.write('<a href="' + geturl(Math.ceil(matchcount/resultsperpage)) + '" rel="nofollow"><b>' + Math.ceil(matchcount/resultsperpage) + '</b></a>&nbsp;&nbsp;');
      }

    } else if (page > (Math.ceil(matchcount/resultsperpage)-3)) {
      document.write('<a href="' + geturl(1) + '" rel="nofollow"><b>1</b></a>&nbsp;&nbsp;');
      document.write('<b>. . .</b> &nbsp;'); 
      pst = page-2;
      if (pst > (Math.ceil(matchcount/resultsperpage)-5)) {
        pst = (Math.ceil(matchcount/resultsperpage)-4);
      }
      for (pcnt=pst; pcnt<(Math.ceil(matchcount/resultsperpage)+1); pcnt++) {
        if (pcnt != page) {
          document.write('<a href="' + geturl(pcnt) + '" rel="nofollow"><b>' + pcnt + '</b></a>&nbsp;&nbsp;');
        } else {
          document.write('<b>[' + pcnt + ']</b>&nbsp;&nbsp;');
        }
      }
      if (pcnt < Math.ceil(matchcount/resultsperpage)) {
        document.write(' <b>. . .</b> &nbsp;');
        document.write('<a href="' + geturl(Math.ceil(matchcount/resultsperpage)) + '" rel="nofollow"><b>' + Math.ceil(matchcount/resultsperpage) + '</b></a>&nbsp;&nbsp;');
      }

    } else {
      document.write('<a href="' + geturl(1) + '" rel="nofollow"><b>1</b></a>&nbsp;&nbsp;');
      document.write(' <b>. . .</b> &nbsp;'); 
      st = page-2;
      for (pcnt=st; pcnt<(st+5); pcnt++) {
        if (pcnt != page) {
          document.write('<a href="' + geturl(pcnt) + '" rel="nofollow"><b>' + pcnt + '</b></a>&nbsp;&nbsp;');
        } else {
          document.write('<b>[' + pcnt + ']</b>&nbsp;&nbsp;');
        }
      }
      document.write(' <b>. . .</b> &nbsp;');
      document.write('<a href="' + geturl(Math.ceil(matchcount/resultsperpage)) + '" rel="nofollow"><b>' + Math.ceil(matchcount/resultsperpage) + '</b></a>&nbsp;&nbsp;');
    }
  }
  document.write('</td><td align="right">');
  document.write('</td></tr></table>');
}

function writebook(b, bid, bdt) {
  if (typeof b != 'undefined') {
    document.write('<table width="95%"><tr><td>');
    document.write('<iframe width="100%" height="110" scrolling="no" frameborder=0 src="/info/' + bid + '.htm?' + b + '&' + bdt +'" allowtransparency="true"></iframe>');
    document.write('</td><td align="right">');
    writebuttons(bid);
    document.write('</td></tr></table>');
  }
}

function writebuttons(bid) {
  if (ffuser.isLoggedOn) {
    if (ffuser.isEditor == false) {
    if (ffuser.isCoverEditor == false) {
      ffmb = getcookie('ffmb');
      ffwl = getcookie('ffwl');
      if (bid.indexOf('/') != -1) {
        arr = bid.split('\/');
        bid = arr[1];
      }
      if (ffmb.indexOf(bid) != -1) {
        document.write('<strong>Book added<br/>to my books</strong>');
      } else if (ffwl.indexOf(bid) != -1) {
        document.write('<strong>Book added<br/>to my wish list</strong>');
      } else {
        document.write('<button onclick="addbook(1, \'' + bid + '\');">Add to my books</button><br><button onclick="addbook(2, \'' + bid + '\');">Add to wish list</button>');
      }
    }
  }
  }
}
