
/*
 *
 * Entireweb SpeedyAds feeder
 * Copyright (C) 2004-2006 by Entireweb, WorldLight.com AB
 *
 * This file is only to be used in accordance with the
 * licensing terms under which SpeedyAds is provided.
 * Specifically, this file may NOT be modified
 * or replaced with a user-provided version.
 *
 *
 *
 */

if (typeof sa_offset=='undefined' || sa_offset==null) {
  sa_offset = 0;
  var sa_rdate = new Date();
  var sa_rsdrand = sa_rdate.getTime();
  sa_rsd = sa_rsdrand;
}

function speedyadsentireweb_verify_color(sa_lcolor) {
  if (sa_lcolor.length != 6)
    return false;
  var sa_matches = sa_lcolor.match(/[0123456789abcdef]{6}/gi);
  if (!sa_matches.length)
    return false;
  return true;
}

function speedyadsentireweb_fixup_variables() {
  if (sa_maxads < 1) sa_maxads = 1;
  else if (sa_maxads > 8) sa_maxads = 8;
  if (sa_pline < 0) sa_pline = 0;
  else if (sa_pline > 5) sa_pline = 5;

  if (typeof sa_orient == 'undefined' || sa_orient == null ||
      sa_orient == 'h' || sa_orient == 'H')
    sa_orient = 'h';
  else
    sa_orient = 'v';

  if (!speedyadsentireweb_verify_color(sa_superbordercolor))
    sa_superbordercolor = 'ffffff';
  if (!speedyadsentireweb_verify_color(sa_bgcolor))
    sa_bgcolor = 'dddddd';
  if (!speedyadsentireweb_verify_color(sa_linkcolor))
    sa_linkcolor = '000000';
  if (!speedyadsentireweb_verify_color(sa_desccolor))
    sa_desccolor = '000000';
  if (!speedyadsentireweb_verify_color(sa_urlcolor))
    sa_urlcolor = '008000';

  if (sa_b != '1')
    sa_b = 0;

  if (typeof sa_client=='undefined' || sa_client==null)
    sa_client = "0";

  if (typeof sa_format=='undefined' || sa_format==null)
    sa_format = "banner_728x90_4";

  if (typeof sa_offset=='undefined' || sa_offset==null)
    sa_offset = 0;
  if (sa_offset > 8)
    sa_offset = 8;
  if (sa_offset < 0)
    sa_offset = 0;
}

function speedyadsentireweb_cleanup_url(sa_inurl) {
  if (sa_inurl.substr(0,7).toLowerCase() == 'http://')
    sa_inurl = sa_inurl.slice(7, sa_inurl.length);
  var sa_tandstallning = sa_inurl.indexOf('#');
  if (sa_tandstallning != -1)
    sa_inurl = sa_inurl.slice(0, sa_tandstallning-1);
  if (sa_inurl.length <= 3)
    sa_inurl = "";
  return sa_inurl;
}

function speedyadsentireweb_get_bot_target() {
  var sa_dl = speedyadsentireweb_cleanup_url( new String(document.location) );
  var sa_ref = speedyadsentireweb_cleanup_url( new String(document.referrer) );
  var sa_pu = null; //
  
  if (sa_pu == null || !sa_pu.length) {
    sa_pu = sa_dl;
    if (sa_pu == null || sa_pu.length <= 3)
      sa_pu = sa_ref;
  }

  var sa_bt = sa_pu;
  return escape(sa_bt);
}

function speedyadsentireweb_patch_classic() {
  if (sa_format == 'classic') {
    if (sa_orient == 'h') {
      if (sa_maxads <= 2) {
	sa_format = 'banner_468x60';
	sa_width = 468;
	sa_height = 60;
      }
      else if (sa_maxads == 3) {
        sa_format = 'banner_728x90_3';
        sa_width = 728;
        sa_height = 90;
      }
      else {
        sa_format = 'banner_728x90_4';
        sa_width = 728;
        sa_height = 90;
      }
    }
    else {
      sa_format = 'column_120x240';
      sa_width = 120;
      sa_height = 240;
    }
  }
}

function speedyadsentireweb_show_sads() {
  speedyadsentireweb_fixup_variables();
  speedyadsentireweb_patch_classic();

  var sa_rdate = new Date();
  var sa_rand = sa_rdate.getTime();

  var sa_spl = speedyadsentireweb_get_bot_target();
  var sa_l = "http://s" + "a.enti" + "rewe" + "b.com" +
    "/sasen" +
    "se?nc=" + sa_rand +
    "&cl=" + sa_client +
    "&pl=" + sa_pline +
    "&bgc=" + sa_bgcolor +
    "&sbc=" + sa_superbordercolor +
    "&lc=" + sa_linkcolor +
    "&dc=" + sa_desccolor +
    "&uc=" + sa_urlcolor +
    "&b=" + sa_b +
    "&m=" + sa_maxads +
    "&o=" + sa_orient +
    "&w=" + sa_width +
    "&h=" + sa_height +
    "&f=" + sa_format +
    "&s=" + sa_offset +
    "&rsd=" + sa_rsd +
    "&r=" + sa_spl;

  var sa_html = "<i" + "fr" +
    "ame name=\"speedya" + "dsframe\" marginwidth=\"0\" marginheight=\"0\" " +
    "frameborder=\"0\" vspace=\"0\" hspace=\"0\" scrolling=\"no\" width=\"" +
    sa_width +
    "\" height=\"" +
    sa_height +
    "\" src=\"" +
    sa_l +
    "\"></ifr" +
    "ame>";
  
  document.write(sa_html);

  sa_mytag = null;
  sa_html = null;
  sa_affid = null;
  sa_client = null;
  sa_pline = null;
  sa_maxads = null;
  sa_bgcolor = null;
  sa_orient = null;
  sa_superbordercolor = null;
  sa_linkcolor = null;
  sa_desccolor = null;
  sa_urlcolor = null;
  sa_b = null;
  sa_width = null;
  sa_height = null;
  sa_format = null;
  sa_l = null;
  sa_spl = null;

  sa_offset += sa_maxads;
}

speedyadsentireweb_show_sads();

/* --EOF-- */
