function _7search_trackConversion()
{
    var url = "";
    var text = "";
    var target = _7search_getEventTarget();
    
    // Find an element in the target hierarchy (at most 20 parents) that has an href property
    for (var i=0; target && i<=20; i++)
    {
        if (target.href && target.src != target.href) { break; }
        target = target.parentNode;
    }
    
    if (target && target.href)
    {
        url = target.href;
        
        // Find the text
        if (target.innerHTML) { text = target.innerHTML; }
        else if (target.innerText) { text = target.innerText; }
        else if (target.text) { text = target.text; }
        else { text = ""; }
    }
    
    _7search_conversion_miscdata = _7search_removeHtmlTags(text) + "|" + _7search_removeHtmlTags(url);
    
    _7search_handle_conversion();
    
    return true;
}

function _7search_handle_conversion()
{
    var w = window;
    var currentPageUrl = document.location + "";
    var widthHeight = 'width="1" height="1"';
    
    if (w._7search_conversion_snippets)
        w._7search_conversion_snippets++;
    else
        w._7search_conversion_snippets = 1;
        
    if (w._7search_conversion_advid)
    {
        var proto = w.location.protocol.toLowerCase();
        if (proto != 'http:' && proto != 'https:')
            proto = 'http:';
        
        var url = proto + "//conversion.7search.com/conversion/v1/?rnd=" + (new Date()).getTime();
        
        url += "&advid=" + escape(w._7search_conversion_advid);
        
        if (w._7search_conversion_urlid)
            url += "&urlid=" + escape(w._7search_conversion_urlid);

        if (!w._7search_conversion_type)
            w._7search_conversion_type = 'default';
          
        url += "&type=" + escape(w._7search_conversion_type);
        
        url += "&num=" + escape(w._7search_conversion_snippets);
        
        if (w._7search_conversion_value)
            url += "&value=" + escape(w._7search_conversion_value);
            
        if (w._7search_conversion_miscdata)
            url += "&miscdata=" + escape(w._7search_conversion_miscdata);
        
        url += "&ref=" + escape(document.referrer);
        
        // Debug flag is set based on the query string parameter "_7search_conversion_debug"
        if (_7search_get_param(currentPageUrl,"_7search_conversion_debug") == "1")
        {
            url += "&debug=1";
            widthHeight = "";
        }
        
        if (w._7search_conversion_tracking_method && w._7search_conversion_tracking_method == 101)
        {
            // Function call
            var img = new Image(1,1);
            img.src = url;
            img.onload = function() { _7search_void(); }
        }
        else
        {
            // Default: Page load
            document.write('<i' + 'mg ' + widthHeight + ' border="0" src="' + url + '" />');
        }
    }
    
    w._7search_conversion_advid = null;
    w._7search_conversion_urlid = null;
    w._7search_conversion_type = null;
    w._7search_conversion_value = null;
    w._7search_conversion_miscdata = null;   
}

// ====================================================================================================
// Helper Functions
// ====================================================================================================
function _7search_get_param(url, param)
{
  var i;
  var val;
  if ((i = url.indexOf("?" + param + "=")) > -1 ||
      (i = url.indexOf("?" + param.toUpperCase() + "=")) > -1 ||
      (i = url.indexOf("&" + param + "=")) > -1 ||
      (i = url.indexOf("&" + param.toUpperCase() + "=")) > -1)
  {
        val = url.substring(i + param.length + 2, url.length);
        if ((i = val.indexOf("&")) > -1)
            val = val.substring(0, i);
  }
  return val;
}

function _7search_void()
{
    return;
}

function _7search_removeHtmlTags (s)
{
    if (!s) return "";
    
    var strInput = s.replace(/&(lt|gt);/g, function (strMatch, p1) {return (p1 == "lt") ? "<" : ">";} );
    var strTagStrippedText = strInput.replace(/<\/?[^>]+(>|$)/g, "");
    strTagStrippedText = strTagStrippedText.replace(/^\s+|\s+$/g,"");   // trim
    return strTagStrippedText;
}

function _7search_attachEvent(obj, evType, fn, useCapture)
{
    if (!useCapture)
        var useCapture = true;
    
    if (obj.addEventListener)
    {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (obj.attachEvent)
    {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    }
    else
        return false;
}

function _7search_getEvent(e)
{
    if (!e) var e = window.event;
    
    return e;
}

function _7search_event()
{
    if (window.event)
        return window.event;
    else
        return _7search_global_event;
}

function _7search_getEventTarget()
{
    var target = null;
    if (_7search_event().target) target = _7search_event().target;
    else if (_7search_event().srcElement) target = _7search_event().srcElement;
    
    // Defeat Safari bug
    if (target.nodeType == 3)
        target = target.parentNode;
    
    return target;
}

function _7search_clickEventHandler(e)
{
    // Declare a global variable to trap events in FireFox and IE
    _7search_global_event = null;
    _7search_global_event = _7search_getEvent(e);
}

// ==================================================================================
// Globals
// ==================================================================================                                                          
if (window._7search_conversion_tracking_method && window._7search_conversion_tracking_method == 101)
{
    // Function call
    
    // Setup globab variable to trap events in FireFox and IE
    _7search_attachEvent(document, "click", _7search_clickEventHandler);
}
else
{
    // Default: Page load
    _7search_handle_conversion();
}