﻿moz = document.getElementById && !document.all;
var d = new Date();
var enterTime = d.getTime();
var cookieVal;
var ref = escape(document.referrer);
var url = escape(location.href);
var domain = document.domain;
CreateUniqueIdCookie();
TrackImpression();
var mouseX = 0;
var mouseY = 0;

function CreateUniqueIdCookie() {
    try {
        cookieVal = readCookie('uniqueID');
        if (cookieVal == null) {
            createCookie('uniqueID', ((!moz) ? document.uniqueID : '') + '~' + d.getTime(), 60);
            cookieVal = readCookie('uniqueID');
        }
        if (cookieVal == null)
            cookieVal = '';
    }
    catch (err) {
        (new Image).src = "http://www.clicksonlinks.com/Tracking.aspx?func=exception&domain=" + domain + "&url=" + url + "&errordescription=" + err + "&objInfo=" + "CreateUniqueIdCookie()" + "&d=" + enterTime;
    }
}
function TrackImpression() {
    try {
        var d2 = new Date();
        var _timeSpend = 0;
        var _postBack = null;

        _postBack = readCookie('postBack');
        if (readCookie("destinationUrl") != null) {
            if (readCookie("destinationUrl") == url) {
                //return;
                createCookie('postBack', escape(location.href), 60);
                var _idn = d2.getTime();
                (new Image).src = "http://www.clicksonlinks.com/Tracking.aspx?func=Impression&ref=" + ref + "&url=" + url + "&cookieVal=" + cookieVal + "&domain=" + domain + "&LinkRelated=1" + "&d=" + _idn;
                eraseCookie("destinationUrl");
                return;
            }
        }

        if (_postBack == null) {
            //alert(_postBack); 
            createCookie('postBack', escape(location.href), 60);
            var _idn = d2.getTime();
            (new Image).src = "http://www.clicksonlinks.com/Tracking.aspx?func=Impression&ref=" + ref + "&url=" + url + "&cookieVal=" + cookieVal + "&domain=" + domain + "&LinkRelated=0" + "&d=" + _idn;
        }
        else if (_postBack != escape(location.href)) {
            createCookie('postBack', escape(location.href), 60);
            var _idn = d2.getTime();
            (new Image).src = "http://www.clicksonlinks.com/Tracking.aspx?func=Impression&ref=" + ref + "&url=" + url + "&cookieVal=" + cookieVal + "&domain=" + domain + "&LinkRelated=2" + "&d=" + _idn;
        }
    }
    catch (err) {
        (new Image).src = "http://www.clicksonlinks.com/Tracking.aspx?func=exception&domain=" + domain + "&url=" + url + "&errordescription=" + err + "&objInfo=" + "TrackImpression()" + "&d=" + enterTime;
    }
}
function createCookie(name, value, min) {
    if (min) {
        var date = new Date();
        date.setTime(date.getTime() + (min * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ')
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}
function eraseCookie(name) {
    createCookie(name, "", -1);
}


