function writeSubmit(relPath, submit, image, name, caption)
{
  if (null == caption)
  {
    caption = "Share this on " + name;
  }
  document.write('<a href="' + submit + '" target="_blank" title="' + caption + '"><img src="' + relPath + '/images-v2/social/' + image + '" width="38" height="38" alt="' + name + '" /></a>\n');  
}

function myEscape(value)
{
  var fn = this.encodeURI || this.escape || function dummy(s) { return s; };
  var plusEscape = "%" + "+".charCodeAt(0).toString(16).toUpperCase();
  return fn(value).split("+").join(plusEscape);
}

function share(relPath, title)
{
  if (null == relPath)
  {
    relPath = "";
  }
  
  if (null == title)
  {
    title = document.title;
  }

  var url = document.location.href; 
  
  //url = 'http://www.webmama.com/search-marketing-resources/index.htm';
  
  title = myEscape(title);
  
  var submit;
  
  document.write('<div class="share">\n');

  document.write("<script type='text/javascript'>submit_url = '" + url + "';</script>" +
                 "<script type='text/javascript' src='http://sphinn.com/evb/button.php'></script>\n");
  
  document.write("<script type='text/javascript'>" +
                 "digg_url = '" + url + "';" +
                 "</script>" +
                 "<script src='http://digg.com/tools/diggthis.js' type='text/javascript'></script> ");

  document.write("<script type='text/javascript'>reddit_url='" + url + "'</script>" +
                 "<script type='text/javascript' src='http://www.reddit.com/r/technology/button.js?t=2'></script>");

  document.write("<div style='margin-top: 10px;'>");
  submit = ('http://www.webmama.com/search-marketing-resources/index.htm' == url) ? 'http://www.mixx.com/stories/5461505/free_online_resources_for_the_digital_enterprise' : 'http://www.mixx.com';
  document.write("<a href='" + submit + "'>" +
                 "<img src='http://www.mixx.com/images/buttons/mixx-button6.png' alt='Add to Mixx!' border='0' />" +
                 "</a>\n");
  document.write("</div>");

  document.write("<br />\n");

  submit = 'http://www.facebook.com/share.php?u=' + url + '&t=' + title;
  writeSubmit(relPath, submit, "facebook.png", "Facebook");

  submit = 'http://twitter.com/home/?status=' + title + ' ' + url + ' ';
  writeSubmit(relPath, submit, "twitter.png", "Twitter");

  submit = 'http://del.icio.us/post?url=' + url + '&title=' + title;
  writeSubmit(relPath, submit, "delicious.png", "Delicious");

  submit = ('http://www.webmama.com/search-marketing-resources/index.htm' == url) ? 'http://www.stumbleupon.com/url/www.webmama.com/search-marketing-resources/index.htm' : ('http://www.stumbleupon.com/submit?url=' + url + '&title=' + title);
  writeSubmit(relPath, submit, "stumbleupon.png", "StumbleUpon");

  submit = 'http://blog.webmama.com/rss.xml';
  writeSubmit(relPath, submit, "rss.png", "RSS", "Subscribe to WebMama's blog");

  submit = 'mailto:?subject=' + title + '&body=' + url;
  writeSubmit(relPath, submit, "email.jpg", "E-Mail", "E-Mail a link to this page to a friend");

  document.write('</div>\n');
}

