// JavaScript Document
var local_domain ="thameswatch.com";
function tracker()
{
    var all_links = document.getElementsByTagName('a');
	var number_of_links = all_links.length;
	for(var i=0;i<number_of_links;i++)
	    {
			var current_link = all_links[i];
			current_link.onclick = function() {register_click(this.href);};
			//current_link.setAttribute('onClick', 'register_click(this.href)');
		}
}
function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
    }
    return false;
}

function register_click(destination){
	//Check if link contains http url(external)
var extnl=destination.indexOf("http");
var mosthead=destination.indexOf("leboat");
	//check if link is local link(domain)
	var local=destination.indexOf(local_domain);
	//if link is contains http and not local then pass urls to php script
	if (extnl> -1 && local <= -1 || mosthead > -1){
		
 
		var xmlhttp;
	    xmlhttp = getHTTPObject();

				var referring_page = location.href;
				//Create Post string and 
				var string = ""; 
				string +="referring_page="+referring_page;
				string +="&destination="+destination;
		
				//url of php file to process data
				var url = "/clicktracker/click.php";
				
				var post_content = string;	//Get the data that is to be posted
				xmlhttp.open("POST",url,true);
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", post_content.length);
				xmlhttp.setRequestHeader("Connection", "close");
				//xmlhttp.onreadystatechange = state_changed;	//Function defined below to be used if required for debugging
				xmlhttp.send(post_content);
		}
		function state_changed()	//Called when xmlhttp state changes e.g. when the server returns something
			{
				if (xmlhttp.readyState == 4)
				{
					//Put the returned text inside the tag with id "ajax_data"
					document.getElementById('ajax_data').innerHTML = xmlhttp.responseText;
				}
			}
	}
