﻿function ReadCookie(cookieName) {
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf(cookieName);
    if (ind == -1 || cookieName == "") return "";
    var ind1 = theCookie.indexOf(';', ind);
    if (ind1 == -1) ind1 = theCookie.length;
    return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}

function SetCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays == null || nDays == 0) nDays = 1;
    expire.setTime(today.getTime() + 3600000 * 24 * nDays);
    document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
}

var testValue = Math.floor(1000 * Math.random());
var cookies = false;
SetCookie('AreCookiesEnabled', testValue);
var value = ReadCookie('AreCookiesEnabled');
if (value != '')
    cookies = true;
else
    cookies = false;
var pageTitle = document.title;
var referrer = document.referrer;

function PageView(user, externalSystem) {
    var url = "/Tracking/Tracking.aspx?action=PageView&"
    + "user=" + escape(user)
    + "&externalSystem=" + escape(externalSystem)
    + "&cookiesEnabled=" + escape(cookies)
    + "&pageTitle=" + escape(pageTitle)
    + "&referrer=" + escape(referrer)
    + "&cb=" + parseInt(Math.random() * 99999999); // cache buster
    loadXMLDoc(url);
}
function Goal(user, externalSystem, goal) {
    //return this._invoke(this._get_path(), 'Goal', true, { user: user, externalSystem: externalSystem, cookiesEnabled: cookiesEnabled, pageTitle: pageTitle, referrer: referrer, goal: goal }, succeededCallback, failedCallback, userContext);
    var url = "/Tracking/Tracking.aspx?action=Goal&"
    + "user=" + escape(user)
    + "&externalSystem=" + escape(externalSystem)
    + "&cookiesEnabled=" + escape(cookies)
    + "&pageTitle=" + escape(pageTitle)
    + "&referrer=" + escape(referrer)
    + "&goal=" + escape(goal)
    + "&cb=" + parseInt(Math.random() * 99999999); // cache buster
    loadXMLDoc(url);
}

var xmlhttp;
function loadXMLDoc(url) {
    //document.write("Loading <a href='" + url + "'>This</a>");
    xmlhttp = null;
    if (window.XMLHttpRequest) {// code for all new browsers
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {// code for IE5 and IE6
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (xmlhttp != null) {
        xmlhttp.onreadystatechange = state_Change;
        xmlhttp.open("GET", url, true);
        xmlhttp.send(null);
    }
    else {
        //alert("Your browser does not support XMLHTTP.");
    }
    //alert("sent: " + url);
}

function state_Change() {
    if (xmlhttp.readyState == 4) {// 4 = "loaded"
        if (xmlhttp.status == 200) {// 200 = OK
            // ...our code here...
            //alert("DONE");
        }
        else {
            //alert("Problem retrieving XML data");
        }
    }
}
