
// PHP Path
var write_php = 'http://amaup.com/php/lapis/write.php';

// Domain
var domain = document.domain;

// Encode Exists
var encode = (window.encodeURIComponent) ? true : false;

// Set Event Tracking
window.onload = setEvent;

//////////////////////////////////////////////////////////////

function sendData(page)
{
	
	// Arguments
	var args = '';
	
	// RegExp Object
	var regExp = new RegExp(domain);
	
	// Referrer
	var referrer = parent.document.referrer;
	
	if(referrer.match(regExp)){referrer = '';}
	
	if(referrer){referrer = (encode) ? encodeURIComponent(referrer) : referrer.replace(/&/g,'::');}
	
	args += '&referrer=' + referrer;
	
	// Document Title
	var title = (!page && encode) ? encodeURIComponent(document.title) : '';
	
	args += '&title=' + title;
	
	// Document URL
	var url = (page && isNaN(page)) ? page : document.URL;
	
	url = (encode) ? encodeURIComponent(url) : url.replace(/&/g,'::');
	
	args += '&url=' + url;
	
	// Page No
	var pageNo = (!isNaN(page)) ? page : '';
	
	args += '&page_no=' + pageNo;
	
	// Color Depth
	args += '&color_depth=' + screen.colorDepth;
	
	// Screen Width
	args += '&screen_width=' + screen.width;
	
	// Screen Height
	args += '&screen_height=' + screen.height;
	
	// Client Width
	var client_width = (window.innerWidth) ? parent.window.innerWidth : '';
	
	if(!client_width){client_width = (document.documentElement.clientWidth) ? parent.document.documentElement.clientWidth : '';}
	if(!client_width){client_width = (document.body.clientWidth) ? parent.document.body.clientWidth : '';}
	
	args += '&client_width=' + client_width;
	
	// Client Height
	var client_height = (window.innerHeight) ? parent.window.innerHeight : '';
	
	if(!client_height){client_height = (document.documentElement.clientHeight) ? parent.document.documentElement.clientHeight : '';}
	if(!client_height){client_height = (document.body.clientHeight) ? parent.document.body.clientHeight : '';}
	
	args += '&client_height=' + client_height;
	
	// Cookie Enabled
	var cookie = (navigator.cookieEnabled) ? navigator.cookieEnabled : '';
	
	args += '&cookie=' + cookie;

	// Request URL
	var requestURL = write_php + '?act=img' + args + '&cache=' + (new Date()).getTime();
	
	// Img Tag Write
	document.write('<img src="' + requestURL + '" width="0" height="0" alt="tracker" />');
	
}

//////////////////////////////////////////////////////////////

function setEvent()
{
	
	var obj,link;
	
	var pageExt = /\.(htm|php|pl|cgi|jsp|asp)/i;
	var fileExt = /\.\w{2,4}$/i;
	
	var linksLength = document.getElementsByTagName('a').length;
	
	for(i = 0;i < linksLength;i++)
	{
		
		obj = document.getElementsByTagName('a')[i];
		
		link = obj.href;
		
		if(link.match('javascript')){continue;}
		
		else if(!link.match(domain)){obj.onmousedown = clickOutLink;}
		
		else if(!link.match(pageExt) && link.match(fileExt)){obj.onmousedown = clickFileLink;}
		
	}
	
}

//////////////////////////////////////////////////////////////

function clickOutLink()
{
	
	var outURL   = (encode) ? encodeURIComponent(this.href) : this.href;
	
	var outTitle = (encode) ? encodeURIComponent(this.innerHTML) : '';
	
	var requestURL = write_php + '?act=out_link&url=' + outURL + '&title=' + outTitle;
	
	requestLapis(requestURL);
	
}

//////////////////////////////////////////////////////////////

function clickFileLink()
{
	
	var fileURL = (encode) ? encodeURIComponent(this.href) : this.href;
	
	var requestURL = write_php + '?act=file_link&url=' + fileURL;
	
	requestLapis(requestURL);
	
}

//////////////////////////////////////////////////////////////

function requestLapis(requestURL)
{
	
	requestURL += '&cache=' + (new Date()).getTime();
	
	document.getElementById('tracker').innerHTML += '<img src="' + requestURL + '" />';
	
}


