//3.01
function Spylog_Tracker(_sp_config){
	this.sp_config = _sp_config;
	var f = Math.floor(this.sp_config.counter / 100); 
	var s = this.sp_config.counter - f * 100; 
	this.dm = "u" + spylog_str_pad(f.toString(), 3, '0') + "." + spylog_str_pad(s.toString(), 2, '0') + ".spylog.com"; 
	
	this.c = 1;
	if( !document.cookie ) {
		document.cookie = "testCookie=1; path=/";
		this.c = document.cookie?1:0;
	}
	
	this.n = (navigator.appName.toLowerCase().substring(0, 2) == "mi") ? 0 : 1; 
	if (parent != window){
		this.r1 = document.referrer;
		this.r=parent.document.referrer;
	}
	else
	this.r= document.referrer;
	this.pg = window.location.href;
	this.fr = (self != top)?1:0;
	var js_version= '<scr'+'ipt language="javascr'+'ipt">spylog_js=1;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.1">spylog_js=1.1;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.2">spylog_js=1.2;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.3">spylog_js=1.3;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.4">spylog_js=1.4;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.5">spylog_js=1.5;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt1.6">spylog_js=1.6;</scr'+'ipt>';
	js_version += '<scr'+'ipt language="javascr'+'ipt"></script>';
	document.write(js_version);
	this.sl=(undefined==spylog_js)?1:spylog_js;
	this.fl = '';
	this.fix = function(){
		if (navigator.plugins && navigator.plugins.length) {
			for (var ii=0;ii<navigator.plugins.length;ii++) {
				if (navigator.plugins[ii].name.indexOf('Shockwave Flash')!=-1) {
					this.fl=navigator.plugins[ii].description.split('Shockwave Flash ')[1];
					break;
				}
			}
		} else if (window.ActiveXObject) {
			for (var ii=10;ii>=2;ii--) {
				try {
					var f=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');");
					if (f) { this.fl=ii + '.0'; break; }
				}
				catch(ee) {}
			}
			if((this.fl=="")&&!this.n&&(navigator.appVersion.indexOf("MSIE 5")>-1||navigator.appVersion.indexOf("MSIE 6")>-1))
			{
				FV=clientInformation.appMinorVersion;
				if(FV.indexOf('SP2') != -1)
				this.fl = '>=7';

			}
		}
	}
	this.fix();

	this.p = this.sp_config.p;
	this.ct=(undefined!=this.ct)?this.ct:'';
	switch (this.sl) {
		default:
		case '1.2':
		var Ms = screen;
		this.px = (this.n == 0) ? Ms.colorDepth : Ms.pixelDepth;
		this.s = "&wh=" + Ms.width + 'x' + Ms.height + "&px=" + this.px;
		case '1.1':
		Mpl = "";
		this.j = (navigator.javaEnabled()? "Y" : "N");
		case '1':
		case '1.0':

	}
	this.load = function(_title){
		
		this.a_url = "http://" + this.dm + "/cnt?cid=" + this.sp_config.counter + "&f=3&p=" + this.p + "&rn=" + Math.random(); //url 
		this.counter_url = "http" + (document.location.protocol == 'https:'?'s://sec01-hits.spylog.com/cnt.cgi':('://'+ this.dm + '/cnt'))
		+ "?cid=" + this.sp_config.counter
		+ "&p=" + this.p
		+ "&rn=" + Math.random()
		+ "&c=" + this.c
		+ "&t=" + (new Date()).getTimezoneOffset()
		+ '&title=' + escape(sp_substr(_title))
		+ "&sl=" + this.sl
		+ ((this.sp_config.part!=undefined && this.sp_config.part!='')?'&partname=' + spylog_escape(this.sp_config.part.replace(/^\s+/, '').replace(/\s+$/, '')):'')
		+ (this.fl!=undefined?('&fl=' + this.fl):'')
		+ (this.ct!=undefined?('&ct=' + this.ct):'')
		+ this.s
		+ '&j=' + this.j
		+ (this.r1?("&r1=" + escape(sp_substr(this.r1))):'')
		+ "&r=" +escape(sp_substr(this.r))
		+ "&fr=" + this.fr
		+ "&pg=" + escape(sp_substr(this.pg));
		switch(this.p){
			case 5:
			case 4:
			this.sp_img = new Image();
			this.sp_img.src = this.counter_url;
			break;
			case 3:
			this.sp_img = new Image();
			this.sp_img.src = this.counter_url;
			if(!this.n){
				if(this.t.getAttribute('target')!='_blank'){
				tmp_link = document.createElement('a');
				tmp_link.href = this.t.href;
				tmp_link.target = this.t.target;
				tmp_link.setAttribute("style","display: none;");
				tmp_link.setAttribute("sp_set_event","on");
				var n = this.t.parentElement;
				n.insertBefore(tmp_link,this.t);
			this.sp_img.onload = function (){     tmp_link.click();} 
				setTimeout("  tmp_link.click(); ",500);	
				}
			}else if(this.t.getAttribute('target')!='_blank')
			{	
				this.target = '';
				this.sp_img.onload = function (){  window.location.href = sp_tracker.pg};
				setTimeout("window.location.href = sp_tracker.pg; ",500);
			}
			break;
			case 0:
			default:
			My  = "<a id='sp_link' href='' style='display:none;' ></a><a href='" + this.a_url + "' target='_blank'>";
			My +=  "<img src='"+this.counter_url;
			My += "' border=0 alt='SpyLOG'>";
			My += "</a>";
			document.write(My);
			break;
		}
	}
	this.load(document.title);
	this.func_pro = function (){
		this.p = arguments[1];
		if(!this.n) {e= window.event;this.t = e.srcElement;
		if(this.p!=5)
			while(this.t.tagName.toString().toLowerCase()!='a')	this.t = this.t.parentElement;
			if(this.t.getAttribute('target')!='_blank') arguments[0].returnValue = false;
		}
		else {
			this.t = arguments[0].currentTarget;
			if(this.t.getAttribute('target')!='_blank')	arguments[0].preventDefault();
		}
		var sp_area_id = this.t.getAttribute('sp_area_id');
		if(sp_area_id != ''&& sp_area_id != null)
			var title = 'ADVID='+sp_area_id+';';
		else var title='';		
		if(this.p==4 || this.p==3){
			this.r = document.location.href;
			this.pg = this.t.href;
		}else if(this.p==5){
			this.r = document.location.href;
			this.pg = this.t.action;
		}
		this.load(title);
	}
	
	this.func1 = function(e){
		if( undefined==e ) btn=window.event.button;	else btn=e.which;
		if( undefined==btn ) btn=e.button;
		if( 1!=btn )  this.func_pro (e,4); else return true;
	}
	
	this.spylog_onunload = function (_look){
		var sp_links = document.links;
		var sp_size = sp_links.length;
		var sp_hostname = window.location.hostname;
		var sp_action = '';
		for(var i=0;i<sp_size; i++){
			var sp_set_event = sp_links[i].getAttribute('sp_set_event'); //add 20.10.06 
			if(sp_set_event == 'on') continue; ////add 20.10.06 
			var sp_area_id = sp_links[i].getAttribute('sp_area_id');
			if(sp_area_id!=undefined && sp_area_id != ''&& sp_area_id != null) plus=1; else plus=0;
			if(sp_links[i].id!='sp_link')
			if((sp_links[i].hostname!=sp_hostname && _look=='ext')||(_look=='all')||(plus==1)){				
				var sp_tracker = this;
				if(document.addEventListener)					
					sp_links[i].addEventListener('click',function(T)  {  sp_tracker.func_pro(T,3);  },false);
				else{
					sp_links[i].attachEvent('onclick',function(T)  { return sp_tracker.func_pro(T,3); });	}	
				if(document.addEventListener)
				sp_links[i].addEventListener('mousedown',function(T)  {sp_tracker.func1(T);},false);
				else
				sp_links[i].attachEvent('onmousedown',function(T)  {sp_tracker.func1(T); return false;});	
				sp_links[i].setAttribute('sp_set_event','on');  //add 20.10.06
			}
		}
	}
	
	this.spylog_onsubmit_form = function (){
		var sp_forms = document.forms;
		var sp_size = sp_forms.length;
		for(var i=0;i<sp_size; i++){
			var sp_set_event = sp_forms[i].getAttribute('sp_set_event'); //add 20.10.06 
			if(sp_set_event == 'on') continue; ////add 20.10.06 
			var sp_area_id = sp_forms[i].getAttribute('sp_area_id');
			if(sp_area_id!=undefined && sp_area_id != ''&& sp_area_id != null){
				var sp_tracker = this;
				if(document.addEventListener) sp_forms[i].addEventListener('submit',function(T)  {sp_tracker.func_pro(T,5);},false);
				else sp_forms[i].attachEvent('onsubmit',function(T)  {sp_tracker.func_pro(T,5);});	
				sp_forms[i].setAttribute('sp_set_event','on');  //add 20.10.06
			}
		}
	}

	

	this.spylog_parser_block = function (idd){var al = document.getElementById(idd);  if(al != null )	this.forTags(al,idd);}

	this.forTags = function (n,atr){
		if(n.nodeType==1){
			var tag = n.tagName.toString().toLowerCase();
			if(tag == 'a'  || tag == 'form') { n.setAttribute('sp_area_id',atr);}
		}
		var children = n.childNodes;
		for(var i=0;i < children.length; i++)  this.forTags(children[i],atr);
		return;
	}
	
	this.spylog_onload = function (){
		var c = this.sp_config.block_id.length;
		for(i=0;i<c;i++) {this.spylog_parser_block(this.sp_config.block_id[i]);}
		this.spylog_onunload(this.sp_config.fix_link); 
		this.spylog_onsubmit_form();
		var sp_tracker = this;
		if(!window.flag) // add 20.10.06
			setTimeout("sp_tracker.spylog_onload()",1000);
		 
	}
	
	

	window.flag = 0; //add 20.10.06 
	var sp_tracker = this;
	if(window.addEventListener)  window.addEventListener("load", function(){window.flag=1;sp_tracker.spylog_onload();}, false);
	else if (window.attachEvent) window.attachEvent("onload",function(){window.flag=1;sp_tracker.spylog_onload();});
	this.spylog_onload();
	//end 20.10.06
	
	
}



function Spylog_Config()
{
	var sp_prop = document.getElementById('spylog_code');
	this.counter = sp_prop.getAttribute('counter');
	this.part = sp_prop.getAttribute('part');
	this.part = (this.part==null|| this.part=='')?'':this.part;
	this.p = sp_prop.getAttribute('page_level');
	this.p = (this.p==null|| this.p=='')?0:this.p;
	if(this.p>1 && this.p!=254) this.p = 0;
	this.fix_link = sp_prop.getAttribute('track_links');
	//set default fix_link
	if( null==this.fix_link ) this.fix_link ='';
	this.block_id = new Array();
	this.spylog_add_parser_block = function(){
		var l = arguments.length;
		var t = this.block_id.length;
		for(var i=0; i<l; i++)	this.block_id[t+i] = arguments[i];

	}

}

function spylog_escape(str)
{	
    var unicod = '';
    var len = str.length;
    for (var i = 0; i < len; i++) {
	var cod = str.charCodeAt(i);
	if (cod < 255) {unicod += str.charAt(i);continue;}
	cod = cod.toString(16);
	unicod += '%u' + spylog_str_pad(cod.toLowerCase(), 4, '0');	
    }
    return unicod;
}

function spylog_str_pad(str, len, pad)
{
	var length = str.length;
	if (length >= len)	return str;
	var count = len - length;
	for (var i = 0; i < count; i++)	str = pad + str;
	return str;
}

function sp_substr(_href)
{
	if(_href.length>250){
//		var end_str = _href.indexOf('%3F')
		var end_str = _href.indexOf('?')
		if(end_str!=-1)			
			_href = _href.slice(0,end_str);
	}
	if(_href.length>250)
		_href = _href.substring(0,250);
	return _href; 		
}

var undefined;
sp_config = new Spylog_Config();
sp_tracker = new Spylog_Tracker(sp_config);