/*** Copyright (c) 2000-2009 by WebCollage Inc. All rights reserved.  ***/
/*** Protected by US Patent 6,865,593 and pending patent applications ***/
try
{
  

function getCpiFromQueryParameterValue (query, cpiName)
{
  var lcCpiName = cpiName.toLowerCase();
  var params = query.split("&");
  for (var i=0; i < params.length; ++i)
  {
    var pair = params[i].split("=");
    if (typeof(pair[0]) != typeof(undefined) &&
        (unescape(pair[0])).toLowerCase() == lcCpiName   &&
        typeof(pair[1]) != typeof(undefined))
    return unescape(pair[1]);
  }
  return "";
}

function getCpiFromUrlPath (path)
{
  var segments = path.split("/");
  return unescape(segments[segments.length - 1]);
}

function wcsbGetCpi()
{
  var cpi = "";
  
  var urlParts = document.location.href.split("?");
  var urlParts2 = document.location.href.split(".htm");
  
  if (typeof(urlParts[1]) != typeof(undefined))
  {
     cpi = getCpiFromQueryParameterValue(urlParts[1], "ProductCode");
      
  }
  
  else 
  {
     cpi = getCpiFromUrlPath(urlParts2[0]);
  }

  return cpi.toUpperCase();
}

  
  function wcsbCallProductButton()
  {
    var s = document.createElement("script");
    s.id = "wcsb-auto";
    s.src = "http://content.webcollage.net/hometheaterstore/smart-button?ird=true&channel-product-id=" + escape(wcsbGetCpi());;
    document.getElementsByTagName("head").item(0).appendChild(s);
  }
  if (typeof(wcsbAvoidDoubleResponse)=='undefined')
  {
    wcsbAvoidDoubleResponse = true;
    setTimeout(wcsbCallProductButton, 1);
  }
}
catch (e) {}