// $Id: locale.js,v 1.4 2009/02/06 02:21:46 dtiberio Exp $

function media_server()
{
  var visitortime = new Date();

  if(visitortime) 
  {
    var tz = visitortime.getTimezoneOffset() / 60;
    if (tz < 5) {tz = 5;}
    if (tz > 8) {tz = 8;}

    return "media-tz" + tz + ".cheapbooks.com";
    }
  return "media.cheapbooks.com";
  }

function image(object, width, height, href)
{
// does not support relative images (no preceding backslash)
  var tag_width;
  var tag_height;
  var tag_href;

  if (width > 0)
  {
    tag_width = "width=" + width;
    }

  if (height > 0)
  {
    tag_height = "height=" + height;
    }

  var regex = RegExp("http:\/\/");
  var url = object;
  if (! regex.exec(object))
  {
    var domain = media_server();
    url = "http://" + domain + object;
    }

    var tag = ("<img src='" + url + "' " + tag_width + " " + tag_height + " border=0>");
    
    if (href) {document.write("<a href='" + href + "'>");}
    document.write(tag);
    if (href) {document.write("</a>");}
  }

function image_redundant(object, width, height, href)
{
  document.write("<table align=left background='http://media-backup.cheapbooks.com" + object + "' cellspacing=0 cellpadding=0 width=" + width + " height=" + height + "><tr><td width=" + width + " height=" + height + ">");
  image(object, width, height, href);
  document.write("</td></tr></table>");
  }

