
function openAdvert(id, tag)
{
	window.open(tag.href);
	
	try
	{
		var url = "/adclick.php";
		var params = {
			id: id
		}
		var http;
		http = Ajax.Request(url, params, true, true, true);
	}
	catch(e) {}
	
	return false;
}



// XMLHTTPRequest support for older IE versions:
if(typeof XMLHttpRequest == "undefined")
{
	XMLHttpRequest = function()
	{
		try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e){}
		try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e){}
		try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){}
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){}
		throw new Error("This browser does not support XMLHttpRequest or XMLHTTP.")
	}
}

// AJAX-related functions
var Ajax = {
	/**
	 * Perform a request and return the responseText
	 * @param {string} location The URL to request
	 * @param {Object} params (optional) Any parameters to pass as a JSON object in a POST variable called "params"
	 * @param {bool} useGet (optional) If this is true any parameters will be passed as GET variables instead of 
	 *                      as a single JSON object via POST.
	 *                      If this is false it will use a POST request if there are some parameters, otherwise GET.
	 * @param {bool} async (optional) If true then perform the request asynchronously
	 * @param {Function} callback (optional) The onReadyStateChange callback function to use
	 * @param {bool} noCache If true then add the current date to the URL to force reloading
	 * @return {mixed} In synchronous mode this contains the responseText returned by the request.
	 *                 In asynchronous mode it returns true on success.
	 *                 In both cases it returns false if there was an error.
	 */
	Request: function(location, params, useGet, async, noCache, callback)
	{
		async = async ? true : false;
		
		var url = location;
		var method = "GET";
		var postData = null;
		
		if(noCache)
		{
			if(! params) params = {}
			params.x = new Date().getTime();
		}
		
		if(params)
		{
			if(useGet)
			{
				// build the URL if using GET mode
				if(typeof params == "string") url += params;
				else if(typeof params == "object")
				{
					if(url.indexOf("?") == -1) url += "?";
					else if(url.substring(url.length - 1, url.length) != "&") url += "&";
					var i = 0;
					for(var key in params)
					{
						if(i > 0) url += "&";
						url += escape(key) + "=" + escape(params[key]);
						i++;
					}
				}
			}
			else
			{
				postData = "params=" + escape(JSON.stringify(params));
				method = "POST";
			}
		}

		// perform the request
		var http = new XMLHttpRequest();
		if(callback) http.onreadystatechange = callback;
		http.open(method, url, async);
		if(method == "POST")
		{
			http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", postData.length);
			http.setRequestHeader("Connection", "close");		
			http.send(postData);
		}
		else http.send(null);
		
		// return the request object if in async mode
		if(async) return http;

		// process results if in sync mode
		if(http.status != 200)
		{
			//alert("Error loading url " + url + ".\nResponse status=" + http.status);
			return false;
		}
		
		return http.responseText;
	}
}
