//****************************************************************
// Copyright notice:
// 2000-2002 Logient Corporation. All rights reserved.
// This copy of the script is the property of Logient.
// Do not download the script's files from here.
//
// $Id: t.js,v 1.13 2002/04/11 18:26:34 mycroft Exp $
//****************************************************************

var visitorId = null;
var queryString = null;

//set the expiration date to one year from now
var expires = new Date();
var oneYear = expires.getTime() + ( 365 * 24 * 60 * 60 * 1000 );
expires.setTime( oneYear );

//get url, page referer, document title
var url = window.document.URL;
var referer = window.document.referrer;
var title = window.document.title;
//userAgent
var userAgent = navigator.userAgent;

//build the query string
var queryString = "referer=" + escape( referer ) + "&url=" + escape( url ) + 
                  "&title=" + escape( title ) + "&userAgent=" + escape( userAgent )

//check if there is a query string and if so, get the visitor id
var urlquery = url.split( "?" );
if ( urlquery[1] ) {
    var urlterms = urlquery[1].split( "&" );
    for ( var i = 0; i < urlterms.length; i++ ) {
        if ( urlterms[i].indexOf( "visitorId" ) != -1 ) {
            visitorId = urlterms[i].substring( urlterms[i].indexOf( "=" )+1, urlterms[i].length );
            setCookie( "visitorId", visitorId, expires, "/" );
            break;
        }
    }
}

//if there is no visitorId param, get the visitor id in the cookie
if ( visitorId == null && getCookie( "visitorId" ) ) {
   visitorId = getCookie( "visitorId" );
   queryString += "&cookie=true"
}
 

//log the visitor if he is from a mailing list (ie. visitorId not null)
if ( visitorId != null )
//    document.write( "<img src='http://mailer.logient.net/t?id=" + visitorId + "&" + queryString + "' heigth=1 width=1 border=0>" );
    document.write( "<img src='http://mailer.equipeparent.com/t?id=" + visitorId + "&" + queryString + "' heigth=1 width=1 border=0>" );


//function use to set a cookie
function setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape( value ) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

//function use to retrieve the user's cookie
function getCookie ( name ) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while ( i < clen ) {
        var j = i + alen;
        if ( document.cookie.substring( i, j ) == arg )
            return getCookieVal( j );
        i = document.cookie.indexOf( " ", i ) + 1;
        if ( i == 0 )
            break;
    }
    return null;
}

//function use to get the cookie value (called by getCookie function)
function getCookieVal( offset ) {
    var endstr = document.cookie.indexOf( ";", offset );
    if ( endstr == -1 ) endstr = document.cookie.length;
    return unescape( document.cookie.substring( offset, endstr ) );
}
