/*
 * $Author: dbibbens $
 * $Revision: 1.10 $
 * $Date: 2007/06/08 03:24:05 $ 
 * $Source: /home/cvs/conversiontrac.com/local/lib/001.js,v $
 */

var pixel = "001";

if(get_cookie(pixel) != pixel) {
  set_cookie(pixel, pixel);
  var aid = value('aid');
  var subid = value('sub-id');
  var state = value('state');

  if(subid && subid != '') {
    aid = aid + '-' + subid;
  }

  if(state && state == 'MA') {
    aid = "YMA" + pixel;
  }

  document.write('<img src="http://conversiontrac.com/' + pixel + '/?aid=' + aid + '" alt="" width="1" height="1"/>');
}

function get_cookie(name)
{
  var cookies = document.cookie.split(';');
  name = name + "=";
  for(var i = 0; i < cookies.length; i++) {
    var cookie = cookies[i];
    
    while(cookie.charAt(0) == ' ') {
      cookie = cookie.substring(1, cookie.length);
    }
    
    if(cookie.indexOf(name) == 0) {
      return cookie.substring(name.length, cookie.length);
    }
  }

  return false;
}

function set_cookie(name, value) 
{
  document.cookie = name + "=" + value + "; path=/";
}

function value(key)
{
  keys = new Array();
  values = new Array();

  var query = window.location.search.substring(1);
  var pairs = query.split("&");

  for (var i=0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if (pos >= 0) {
      var argname = pairs[i].substring(0, pos);
      var value = pairs[i].substring(pos + 1);
      keys[keys.length] = argname;
      values[values.length] = value;
    }
  }

  for (var i=0; i < keys.length; i++) {
    if (keys[i] == key) {
      return values[i];
    }
  }
}

