 
  var channel_code = __s2m_parse_url_param( "channel_code" );
  var product_code = __s2m_parse_url_param( "product_code" );
  var s2m_type = __s2m_parse_url_param( "s2m_type" );
  var s2m_promotion_id = __s2m_parse_url_param( "s2m_promotion_id" );
  var s2m_channel = __s2m_parse_url_param( "s2m_channel" );
  var s2m_medium = __s2m_parse_url_param( "s2m_medium" );
  var s2m_campaign = __s2m_parse_url_param( "s2m_campaign" );
  
  var shop_id = 121;
  var __s2m_ref_hosts = {};
  var __s2m_has_iframed_data = false;
  function setCookie( c_name, value, expire_minutes )
  {
      var exdate = new Date();
      exdate.setDate( exdate.getDate() + expire_minutes );
      document.cookie = c_name + "=" + escape( value ) + ( ( expire_minutes == null ) ? "" : ";expires=" + exdate.toGMTString( ) );
  }
  function __s2m_parse_url_param( strParamName )
  {
     var pattern = new RegExp( ".*" + strParamName + "\\\=([^&$]+).*" );
     var parsed_data = pattern.exec( location.href );
     return parsed_data != null && parsed_data.length == 2 ?  parsed_data[1] : "" ;
  }

  function ___getUUID( mixing_string )
  {
    return Math.round(new Date().getTime()/1000) + "" + mixing_string;
  }
  
  function removeCookie( c_name )
  {
      try
      {
        document.cookie = c_name + "=;expires=Fri, 02-Jan-1970 00:00:00 GMT";
      }catch(err){}
  }

  function getCookie( c_name )
  {
      try
      {
          if( document.cookie.length > 0 )
          {
              c_start = document.cookie.indexOf( c_name + "=" );
              if( c_start != -1 )
              {
                  c_start = c_start + c_name.length + 1;
                  c_end = document.cookie.indexOf( ";", c_start );
                  if( c_end==-1) c_end = document.cookie.length;
                  return unescape( document.cookie.substring( c_start,c_end ) );
              }
          }
      }catch(err){}
      return "";
  }

  try
  {
      var s2m_ref_host = document.referrer;
      try
      {
        var fake_anchor = document.createElement("A");
        fake_anchor.href = s2m_ref_host;
        if( !s2m_medium ){ s2m_medium = fake_anchor.host; }
      }catch(err){}

      if( !( ( channel_code && product_code ) || ( s2m_type && s2m_channel ) ) )
      {
        try
        {
          for( var s2m_ref_host_channel in __s2m_ref_hosts )
          {
            var host_regexp = new RegExp( __s2m_ref_hosts[ s2m_ref_host_channel ], "i" );
            if( s2m_ref_host.match( host_regexp ) != null )
            {
                s2m_type = 3;
                s2m_channel = s2m_ref_host_channel;
                s2m_campaign = "Untagged";
            }
          }
        }catch(err){}
      }
      if( ( channel_code && product_code ) || ( s2m_type && s2m_channel ) )
      {
          var host_prefix = (("https:" == document.location.protocol) ? "https://" : "http://");
          var coockie_value = getCookie("__s2m_vals_" + shop_id );
          if( coockie_value == null || coockie_value == "" )
          {
            coockie_value = ___getUUID( "" + shop_id );
          }
          setCookie( "__s2m_vals_" + shop_id, coockie_value, 20 );
          src = host_prefix + "track.shop2market.com/track_visit_image.gif?shop_code=" + shop_id
            + "&product_code=" + product_code  + "&channel_code=" + channel_code
            + "&stamp=" + Math.random() + "&coockie_uuid=" + coockie_value
            + "&s2m_type=" + s2m_type + "&s2m_promotion_id=" + s2m_promotion_id 
            + "&s2m_channel=" + s2m_channel + "&s2m_medium=" + s2m_medium 
            + "&s2m_campaign=" + s2m_campaign;
            
          __s2m_pixel = document.createElement('img');
          
          __s2m_pixel.src = src;
          __s2m_pixel.setAttribute('width', '1px');
          __s2m_pixel.setAttribute('height', '1px');
          
          var __s2m_script = document.getElementsByTagName('script')[0];
          
          if( __s2m_has_iframed_data )
          {
              var iframe_src = host_prefix + "track.shop2market.com/track_visit.html?shop_code=" + shop_id;
              __s2m_iframe = document.createElement('iframe');
              __s2m_iframe.src = iframe_src;
              __s2m_iframe.setAttribute('width', '1px');
              __s2m_iframe.setAttribute('height', '1px');
              __s2m_script.parentNode.insertBefore( __s2m_iframe, __s2m_script );
          }
         __s2m_script.parentNode.insertBefore( __s2m_pixel, __s2m_script );
      }
  }catch(err){ }
