/*
 * Tracks click on an element by sending OpenX an Ajax request crafted specially
 * for that.
 * 
 * @author Jean-Philippe Côté
 * @version 1.0
 * 
 * @param {Number} bannerId The OpenX id of the banner
 * @param {Number} zoneId The OpenX id of the zone
 * @param {String} oxPath The path to the click tracking url (usually ck.php)
 * @return {Boolean}
 */
function trackClick(bannerId, zoneId, oxUrl) 
{
	
	// Detect FF or IE
	if(window.XMLHttpRequest)
	   xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject)
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	
	// Prepare OpenX tracking url
	var cacheBuster = Math.floor(Math.random()*99999999999);		
	var requestUrl = oxUrl + '?oaparams=2__bannerid=' + bannerId + 
		'__zoneid=' + zoneId + '__cb=' + cacheBuster;

	// Check if the request worked (for debugging purposes)
	xhr_object.onreadystatechange = function() {
	   //if(xhr_object.readyState == 4) alert(xhr_object.responseText + 'It worked! (' + requestUrl + ')' );
	}

	// Execute request asynchronously
	xhr_object.open("GET", requestUrl, true);
	xhr_object.send(null);
	
	// Return true so the link is actually followed
	return false;
}



/*
 
	The click tracking file usually is at that address:
	
		/openx-x.x.x/www/delivery/ck.php
	
	The parameters are passed in non-standard way :
	
		?oaparams=2__bannerid=1__zoneid=1__cb=6b81d59d15
	
	The structure is: 
	
		oaparams=X__var1=val1__var2=val2 
	
	where "X" is the length of the delimiter (by default 2) followed by said 
	delimiter (double underscore by default).
	
		bannerid 			= OpenX id of the banner
		zoneid	 			= OpenX id of the zone
		cb (cacheBuster)	= random number to bypass proxies

*/
