var ni = {
    cobrandId: null,
    eventId: null,
    previousEventId: null,
    userId: null,
    sessionId: null,
    clientLogUrl: null,
	currentEventId: 0,
    
    initialize: function() {
				
        //Set a default cobrand Id (should be overriden in the specific page)
        ni.cobrandId = "dgg"; //set this in specific page to override
 
        ni.userId = cookieId;
		if (ni.userId == null || ni.userId == "") {
            ni.userId = guid[ni.currentEventId++];
        }
		
        ni.sessionId = sessionId;
        if (ni.sessionId == null || ni.sessionId == "") {
            ni.sessionId = guid[ni.currentEventId++];
        }
		
		ni.previousEventId = prevActionId;
        if (ni.previousEventId == null) {
            ni.previousEventId = "";
        }
    },
 
	logClick: function(clickableObjectID, clickableObjectPosition, clickableObjectPaidFlag, clickableObjectPPCRate, clickUrl, linkTitle) {
		
		if(ni.currentEventId >= guid.length)
			return;
		
		//set a new event ID
		//ni.previousEventId = ni.eventId;
		ni.eventId = guid[ni.currentEventId++];
				
		//Make a call to log the page view
        var client = getXmlHttpObject();
        var logUrl = (this.clientLogUrl ? this.clientLogUrl : "logclick");
        
		logUrl += "?cobrandID=" + encodeURIComponent(this.cobrandId ? this.cobrandId : "");
		logUrl += "&sessionID=" + (this.sessionId ? this.sessionId : "");
		logUrl += "&cookieID=" + (this.userId ? ni.userId : "");
		logUrl += "&eventID=" + (this.eventId ? this.eventId : "");
		logUrl += "&parentEventID=" + (this.previousEventId ? this.previousEventId : "");
		
		logUrl += "&clickableObjectID=" + (clickableObjectID ? clickableObjectID : "");
		logUrl += "&clickableObjectPosition=" + (clickableObjectPosition ? clickableObjectPosition : "");
		logUrl += "&clickableObjectPaidFlag=" + (clickableObjectPaidFlag ? clickableObjectPaidFlag : "");
		logUrl += "&clickableObjectPPCRate=" + (clickableObjectPPCRate ? clickableObjectPPCRate : "");
		
		logUrl += "&clickUrl=" + encodeURIComponent(clickUrl ? clickUrl : "");
		logUrl += "&linkTitle=" + encodeURIComponent(linkTitle ? linkTitle : "");
 
		logUrl += "&userAgent=" + encodeURIComponent(userAgent ? userAgent : "unknown");
		logUrl += "&clientIP=" + (clientIP ? clientIP : "");
		logUrl += "&rand=" + Math.random();
		
        client.open("GET", logUrl, true);
        client.send(null);
    }
};
 
function getXmlHttpObject() {
    if (window.XMLHttpRequest)
        return new XMLHttpRequest();
    else if (window.ActiveXObject)
        return new ActiveXObject("Microsoft.XMLHTTP");
    else {
        return null;
    }
}

