// change the following to the place where you put the linktrack script.
linktrack = "http://www.queryus.com/clickstrack/clicksdbcall.php?url=http://www.nightlifegoa.com";
//linktrack = "dbcall.php";
referrer = "";

// make error proof
function trackClick( e ) {
	referrer=document.referrer;

	try {
    	getClickInfo(e);
  	} catch (err) {
     	//alert("error "+err);
     	return true;
  	}
  	return true;
}

function getClickInfo(e) {
	// this grabs the link and redirects it to the php site.
  	var link_target = null;
  	if (e != null) { 
     	link_target = e.target;
  	} else {
     	link_target = window.event.srcElement;
  	}	
  	// move on to our next site
  	if (link_target == null) 
		return true; // can't track a link that doesn't exist

	if (link_target.nodeName.toUpperCase() != 'A') 
		return true; // don't want to track anything but links.

  	if (link_target.href == null) 
		return true; // if we aren't going anywhere don't track
		
  	var link_href=link_target.href;
  	var link_atext = "";
	
  	if (link_target.innerText != null) {
     	link_atext = link_target.innerText;		
  	} 
	else if (link_target.innerHTML != null) {
     	link_atext = link_target.innerHTML;
  	} 
	else if (link_target.text != null) {
     	link_atext = link_target.text;
  	} 
  	else {
    	return true; // can't track a link with no description
  	}
	
  	if(link_href == null || link_atext == null) 
  		return true; // once more with feeling.
	
  	if(typeof(link_href) != 'string') 
  		return true;  // not sure what else it could be, except an image.
  // see if the link is off the page
  	var link_host = document.location.hostname.toLowerCase();	
	
  	if (link_host==null || link_host=="") 
  		link_host="hey hey";
	
	/*
  // if we want to track internal stuff, comment out this next line
  	if (link_href.toLowerCase().indexOf(link_host) >= 0) 
  		return true; // don't track in and around site.
	
  // use the next line to avoid tracking links to some other URL
  	if (link_href.toLowerCase().indexOf("anotherURL")>0) 
  		return true;
	*/
	/*
	link_href = escape(link_href);
	link_atext = escape(link_atext);
	link_from=escape(document.location);
	*/
  // we have a link. We have to mess with it.
  // it seems the best way to do this is to create a new image, but you can use an iframe
  
  // create the ref to the new image
  	try {
		pageName=document.location.pathname;
		
     	var link_newurl=linktrack+"&linkName="+link_href+"&linkText="+link_atext+"&referrer="+referrer+"&pageName="+pageName+"&linkFrom="+link_from; // sometimes this fails
  	} catch ( e ) {
     	var link_newurl=linktrack+"&linkName="+link_href+"&linkText="+link_atext+"&referrer="+referrer+"&pageName="+pageName;
  	}
  	try{ // put it in a try/next to avoid http errors
    	var link_image = new Image();
    	link_image.src = link_newurl;
  	}catch(err){ 
    	return true; 
  	}
// the pause that refreshes
  	var link_start = new Date().getTime();
  	var link_stop = link_start + 500;
	
  	while(link_start < link_stop){
    	link_start = new Date().getTime(); // nice tight loop - it might be needed on slow systems
  	}
	
  	return true; // let link do his job 
}

// direct code that is executed immediately
document.onclick=trackClick; // this directs links to our code