
/*
 *
 * Entireweb SpeedyAds feeder
 * Copyright (C) 2004-2009 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.
 *
 *
 *
 */

(function() {
  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_cleanup_url(sa_inurl) {
		sa_inurl = sa_inurl.toLowerCase();
    if (sa_inurl.substr(0,7) == '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 = "";
		sa_inurl = escape(sa_inurl);
		sa_inurl = sa_inurl.toLowerCase();
    var sa_utf = sa_inurl.indexOf('%e0%');
    if (sa_utf != -1)
      sa_inurl = sa_inurl.slice(0, sa_utf-1);
    var sa_utf = sa_inurl.indexOf('%u0e');
    if (sa_utf != -1)
      sa_inurl = sa_inurl.slice(0, sa_utf-1);
    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 sa_bt;
  };
  function speedyadsentireweb_get_top() {
  	if (window && window.top && window.top.location && typeof window.top.location != 'undefined')
				return speedyadsentireweb_cleanup_url( new String(window.top.location) );
		return "";
  };
  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;
      }
    }
		else if (sa_format == 'banner_728x90_3_t') {
      sa_format = 'banner_728x90_3';
    }
		else if (sa_format == 'billboard_468x90') {
      sa_format = 'banner_468x90';
    }
		else if (sa_format == 'billboard_728x90') {
      sa_format = 'banner_728x90_1';
    }
		else if (sa_format == 'banner_728x90') {
      sa_format = 'banner_728x90_3';
    }
  };
  function speedyadsentireweb_show_sads() {
    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 (sa_location < 0) sa_location = 0;
    else if (sa_location > 9) sa_location = 9;

    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 (typeof sa_bordercolor=='undefined' || sa_bordercolor==null)
      sa_bordercolor = sa_superbordercolor;
    if (!speedyadsentireweb_verify_color(sa_bordercolor))
      sa_bordercolor = 'dddddd';
    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 (typeof sa_b=='undefined' || sa_b==null || sa_b != '1')
      sa_b = "0";
    if (typeof sa_font=='undefined' || sa_font==null)
      sa_font = "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_location=='undefined' || sa_location==null)
      sa_location = 0;
    if (typeof sa_location=='undefined' || sa_location==null)
      sa_location = 0;
    if (typeof sa_borderwidth=='undefined' || sa_borderwidth==null)
      sa_borderwidth = 1;
    if (typeof sa_radius=='undefined' || sa_radius==null)
      sa_radius = 0;
    if (typeof sa_ap=='undefined' || sa_ap==null)
      sa_ap = 0;
		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 + "" + Math.floor(Math.random()*2000000000);
		}

    if (sa_offset > 8)
      sa_offset = 8;
    if (sa_offset < 0)
      sa_offset = 0;

    speedyadsentireweb_patch_classic();

    var sa_rdate = new Date();
    var sa_rand = sa_rdate.getTime();
    var sa_spl = speedyadsentireweb_get_bot_target();
    var sa_top = speedyadsentireweb_get_top();

    var sa_l = "http://s" + "a.enti" + "rewe" + "b.com" +
      "/sasen" + "se?nc=" + sa_rand + "&cl=" + sa_client;
    if (typeof sa_affid != 'undefined' && sa_affid != null)  // Backwards compatibility
      sa_l += "&affid=" + sa_affid;
    sa_l +=
				"&pl=" + sa_pline +
				"&bgc=" + sa_bgcolor +
				"&sbc=" + sa_superbordercolor +
				"&bc=" + sa_bordercolor +
				"&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 +
				"&lo=" + sa_location +
				"&s=" + sa_offset +
				"&rsd=" + sa_rsd +
				"&bw=" + sa_borderwidth +
				"&font=" + sa_font +
				"&rd=" + sa_radius +
				"&ap=" + sa_ap;
		if (typeof sa_code != 'undefined' && sa_code != null)
				sa_l += "&cd=" + sa_code;
    sa_l += "&r=" + sa_spl;
		if (sa_top != sa_spl)
		  sa_l += "&rt=" + sa_top;

    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_location = null;
	  sa_borderwidth = null;
    sa_radius = null;
		sa_font = null;
		sa_ap = null;
		sa_code = null;

    sa_offset += sa_maxads;
  };
  speedyadsentireweb_show_sads();
})();

/* --EOF-- */

