
// PHP Path
var w_php = 'http://www.sotobo-ie.net/acs/lapis/w.php';

// Domain
var domain = document.domain;

// Domain Check
var domainFlag = (w_php.match(domain)) ? true : false;

// Ajax Object
var xmlhttp = createXMLHttp();

// Encode Exists
var encode = (window.encodeURIComponent) ? true : false;

// Mode
var args = (xmlhttp) ? '?mode=ajax' : '?mode=js';

// Referrer
var ref = parent.document.referrer;

if(ref.match(domain)){ref = '';}

if(ref){ref = (encode) ? encodeURIComponent(ref) : ref.replace(/&/g,"::");}

args += '&ref=' + ref;

// Document Title
var title = (encode) ? encodeURIComponent(document.title) : '';

args += '&title=' + title;

// Document URL
var url = (encode) ? encodeURIComponent(document.URL) : document.URL.replace(/&/g,"::");

args += '&url=' + url;

// Color Depth
args += '&cd=' + screen.colorDepth;

// Screen Width
args += '&sw=' + screen.width;

// Screen Height
args += '&sh=' + screen.height;

// Client Width
var cw = (window.innerWidth) ? parent.window.innerWidth : '';

if(!cw){cw = (document.documentElement.clientWidth) ? parent.document.documentElement.clientWidth : '';}
if(!cw){cw = (document.body.clientWidth) ? parent.document.body.clientWidth : '';}

args += '&cw=' + cw;

// Client Height
var ch = (window.innerHeight) ? parent.window.innerHeight : '';

if(!ch){ch = (document.documentElement.clientHeight) ? parent.document.documentElement.clientHeight : '';}
if(!ch){ch = (document.body.clientHeight) ? parent.document.body.clientHeight : '';}

args += '&ch=' + ch;

// Cookie Enabled
var co = (navigator.cookieEnabled) ? navigator.cookieEnabled : '';

args += '&co=' + co;

// Request URL
var request = w_php + args;

// Ajax Mode
if(xmlhttp && domainFlag)
{
	
	// Ajax Request
	requestLapis(request);
	
	////////////////////////////////////////////////////////////
	
	// Set Out Links Event
	var obj,link;
	
	var linksLength = document.getElementsByTagName('a').length;
	
	for(i = 0;i < linksLength;i++)
	{
		
		obj = document.getElementsByTagName('a')[i];
		
		link = obj.href;
		
		if(link.match(domain)){continue;}
		
		obj.onclick = jumpOutLink;
		
		
	}
	
}

// <img> Mode
else{document.write('<img width="0" height="0" src="' + request + '" style="visibility:hidden;">');}

//////////////////////////////////////////////////////////////

function jumpOutLink()
{
	
	var url = encodeURIComponent(this.href);
	
	var word = encodeURIComponent(this.innerHTML);
	
	var requestOut = w_php + '?mode=out&url=' + url + '&word=' + word;
	
	requestLapis(requestOut);
	
}

//////////////////////////////////////////////////////////////

function createXMLHttp()
{
	
	var obj = (window.XMLHttpRequest) ? new XMLHttpRequest() : '';
	
	if(!obj){obj = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : '';}
	
	return obj;
	
}

//////////////////////////////////////////////////////////////

function requestLapis(requestURL)
{
	
	xmlhttp.open('GET', requestURL);
	xmlhttp.send(null);
	
}
