// <script>

// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.

// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/php-scripts/click-tracker.php
// (3) Use this code as a part of another product.
//     If you want to do so you should receive my permission.
//
// YOU MAY
// (1) Use this code on your website.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.


// ----- Click Tracker ---------------------------------------------------------

function clicktracker_domain(url)
{
  var reg   = new RegExp("^\\w+://((-|\\w)+(\\.(-|\\w)+)*)");
  var match = reg.exec(url);
  return match ? match[1] : "";
}

function clicktracker_extension(url)
{
  var reg   = new RegExp("^\\w+://(?:(?:-|\\w|\\.)+/)+((?:-|\\w|\\.)*)");
  var match = reg.exec(url);
  if (!match) return "";
  match = match[1].split(".");
  return (match.length >= 2) ? match[match.length-1] : "";
}

function clicktracker_inarray(arr, val)
{
  for (var i in arr) if (arr[i] == val) return true;
  return false;
}

function clicktracker_track(url, title)
{
  var img = new Image();
  img.src = clicktracker_url+"?url="+url+"&title="+title;
}

function clicktracker(e)
{
  var ie  = navigator.appName == "Microsoft Internet Explorer";
  var src = ie ? window.event.srcElement : e.target;
  var tag = (src.tagName != "A") ? src.parentNode : src;

  if (!tag || tag.tagName != "A") return;

  domain    = clicktracker_domain   (tag.href);
  extension = clicktracker_extension(tag.href);

  if ( clicktracker_inarray(clicktracker_domains,    domain   ) &&
      !clicktracker_inarray(clicktracker_extensions, extension)) return;

  url   = escape(tag.href.substr(0, 150));
  title = (src.tagName == "A") ? src.innerHTML :
            (src.tagName == "IMG" && src.alt) ? src.alt : "Image";
  title = escape(title.substr(0, 150));

  setTimeout("clicktracker_track('"+url+"', '"+title+"')", 10);
  return;
}

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onclick', clicktracker);
else document.addEventListener('click', clicktracker, false);

