var _dcsrc="http://ad.e-kolay.net/mdcV2.a2";
var _d=document,_w=window,_s=window.screen,_n=navigator;

var LogBt__         =1;
var bLogReferrer	=1;
var bLogTime		=1;
var bLogTitle		=0;
var bLogSearchWords	=0;
var bStripNumeric	=0;
var bCampaignView  	=1;
var childbit__      =1;
var secs=0;
setInterval("secs++",200);
var _hasrun=0;

var brHelper={
	init:function(){
		this.browser=this.searchString(this.dataBrowser)||"0";
		this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"0";
		this.OS=this.searchString(this.dataOS)||"0";
	},
	searchString:function(data){
		for(var i=0;data&&i<data.length;i++)
		{
			var dataString=data[i].string;
			var dataProp=data[i].prop;
			this.versionSearchString=data[i].versionSearch||data[i].identity;
			if (dataString)
			{
				if (dataString.indexOf(data[i].subString)>-1)
					return data[i].identity;
			}
			else if(dataProp)	return data[i].identity;
		}
	},
	searchVersion:function(dataString)
	{
		var index=dataString.indexOf(this.versionSearchString);
		if (index<0) return;
		return dataString.substr(index+this.versionSearchString.length+1,1);
	},
	dataBrowser: [{string:_n.userAgent,subString:"MSIE",identity:"1",versionSearch:"MSIE"},
				{string:_n.userAgent,subString:"Firefox",identity:"2",versionSearch:"Firefox"},
				{string:_n.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"3"},
				{string:_n.vendor,subString:"Apple",identity:"4"},
				{prop: window.opera,identity:"5"},
				{string:_n.vendor,subString:"iCab",identity:"6"},
				{string:_n.vendor,subString:"KDE",identity:"7"},
				{string:_n.vendor,subString:"Camino",identity:"8"},
				{string:_n.userAgent,subString:"Netscape",identity:"9"},
				{string:_n.userAgent,subString:"Gecko",identity:"10",versionSearch:"rv"},
				{string:_n.userAgent,subString:"Mozilla",identity:"11",versionSearch:"Mozilla"}],
	dataOS : [{string:_n.platform,subString:"Win",identity:"1"},
				{string:_n.platform,subString:"Mac",identity:"2"},
				{string:_n.platform,subString:"Linux",identity:"3"}]
};
brHelper.init();
function _gsr()
{
    var _srs = new Array("1920x1440","1920x1200","1856x1392","1792x1344","1680x1050","1600x1200","1440x900","1400x1050","1280x1024","1280x960","1280x854","1280x800","1280x768","1200x800","1152x864","1152x768","1024x768","800x600","640x480");
    var _x = f("{0}x{1}",_s.width,_s.height);
    for (var i=0;i<_srs.length;i++)
        if (_srs[i]==_x)return i+1;
    return 0;
}
function g(id){return _d.getElementById?_d.getElementById(id):_d.all(id);}
function f()
{
	var a=arguments;
	for(var i=0;i<a.length-1;i++)
		while(a[0].indexOf("{"+i+"}")>=0)
			a[0]=a[0].replace("{"+i+"}",a[i+1]);
	return (a&&a.length)>0?trim(a[0].replace("null","").replace("undefined","")):"";
}
function nn(o)	{return o!=null&&(""+o)!="";}
function _app(n,v){return f("&{0}={1}",n,v);}
function _bos(){return;}
function trim(s) {
  if(!s||s=="")return "";
  while((s.charAt(0)==' ')||(s.charAt(0)=='\n')||(s.charAt(0,1)=='\r'))s=s.substring(1,s.length);
  while((s.charAt(s.length-1)==' ')||(s.charAt(s.length-1)=='\n')||(s.charAt(s.length-1)=='\r'))s=s.substring(0,s.length-1);
  return s;
}
function stripnumeric(__s)
{
	if (!nn(__s))return "";
	var _nums="0123456789";
	var _sep="_",_sepp="__";
	for(var i=0;i<_nums.length;i++)
		while(__s.indexOf(_nums.substr(i,1))>=0)
			__s=__s.replace(_nums.substr(i,1),_sep);
	while(__s.indexOf(_sepp)>=0)
		__s=__s.replace(_sepp,_sep);
	return (__s);
}

function GetKeywords(r)
{
	if(!nn(r))return "";
	var _se=new Array(	"google","yahoo","msn","aol","aol",
						"lycos","ask","altavista","search","netscape",
						"cnn","looksmart","about","mamma","alltheweb",
						"gigablast","voila","virgilio","live","baidu",
						"alice","seznam","yandex","najdi");
	var _kw=new Array(	"q","p","q","query","encquery",
						"query","q","q","q","s",
						"query","qt","terms","query","q",
						"q","kw","qs","q","wd",
						"qs","w","text","q");
	for (var i=0;i<_se.length;i++)
	{
		if (r.indexOf(f(".{0}.",_se[i]))>0&&(r.indexOf(f("?{0}=",_kw[i]))>0||r.indexOf(f("&{0}=",_kw[i]))>0))
		{
			var s=r.substring(r.toLowerCase().indexOf("&"+_kw[i])+_kw[i].length+2,r.length);
			return nn(s)?s:r.substring(r.toLowerCase().indexOf("?"+_kw[i])+_kw[i].length+2, r.length);
		}
	}
	return "";
}

var _referrer=_d.referrer,
	_dl=String(_d.location),
	_sr=_gsr(),
	_browser=brHelper.browser;
	_ver=isNaN(brHelper.version)?0:brHelper.version;
	_os=brHelper.OS,
	_query=GetKeywords(unescape(_referrer)),
	_title=_d.title;		
var _du="",_dd="",_qs="";

_referrer=_referrer.replace("http://","").replace("www.","");
if(_referrer.indexOf("/")>0)
	_referrer=_referrer.substring(0,_referrer.indexOf("/"));

_dl=_dl.replace("http://","").replace("www.","");
if (_dl.indexOf("file://")>0)_dl="";
if (_dl.indexOf(":\\")>0)_dl="";
if (_dl.indexOf(":/")>0)_dl="";

if (_dl.indexOf("#")>0)_dl=_dl.substring(0, _dl.indexOf("#"));
if (_dl.indexOf("/")>0)
{
	_du=_dl.substring(1+_dl.indexOf("/"));
	_dd=_dl.substring(0,_dl.indexOf("/"));
}
else
{   _dd = dl;   _du="";}

_dd = String(_dd + "__fgt").replace(".__fgt","").replace("/fgt","").replace("__fgt","");
_du = String(_du + "__fgt").replace(".__fgt","").replace("/fgt","").replace("__fgt","");
if (bStripNumeric)
	_du=stripnumeric(_du);
_dd=escape(_dd);
if (_du.indexOf("SSO_")>0)_du=_du.substring(0, _du.indexOf("SSO_"));

if (_du.indexOf("?")>0)
{
	_qs=_du.substring(1+_du.indexOf("?"));
	_du=_du.substring(0,_du.indexOf("?"));
}
_du=escape(_du);
_qs=escape(_qs);

//***************************************
if (!bLogTime)
	___log();
else
{
	if (window.attachEvent) {
		window.attachEvent('onbeforeunload', ___log);
	} else if (window.addEventListener) {
		window.addEventListener('beforeunload', ___log, false);
	} else {
		var __onunload = window.onunload;
		window.onunload = function() {
			___log();
			__onunload();
		};
	}
}

function getCookie__(strName) 
{
	var arrCookie = _d.cookie.split(";");
	for (var i=0; i < arrCookie.length; i++) {
		var cookie = arrCookie[i].split("=");
		while(cookie[0].indexOf(" ")==0) cookie[0]=cookie[0].substr(1);
		if (strName == cookie[0]) return unescape(cookie[1]);
	}
	return "";
}
function setCookie__(strName, strValue){_d.cookie = strName + "=" + escape(strValue);}

function CheckCookie()
{
	var returnobj = false;
	var isCookie = document.cookie!=null && document.cookie !="" ?true:false;
	if(isCookie)
	{
		setCookie__("bttest__","123");
		var objcook = getCookie__("bttest__");
		if(objcook!=null)
			returnobj = true;
	}
	return returnobj;
	
}

function ___log()
{
    if(LogBt__)
    {
	    if (_hasrun==1)return;
	    _hasrun=1;
	    secs=Math.round(secs/5);
	    var __r=Math.round(Math.random()*45345342374);
   	    var cenabled= CheckCookie();
   	    if(typeof(_TargetCampaign) != "undefined" && _TargetCampaign!=null && _TargetCampaign!="")
   	    	_TargetCampaign = bCampaignView ? _TargetCampaign : "";
   	    else
   	    	_TargetCampaign = "";
	    var src =_dcsrc+f("?TargetCampaign={0}&Browser={1}&Version={2}&Os={3}&Sr={4}&Domain={5}&URL={6}&Qs={7}&Duration={8}&CookieEnabled={9}&r={10}",
		    _TargetCampaign,_browser,_ver,_os,_sr,_dd,_du,_qs,secs,cenabled,__r);
		    	    
		if (bLogReferrer)	src+=_app("Referrer",_referrer);
	    if (bLogTitle)		src+=_app("Title",_title);
	    if (bLogSearchWords)src+=_app("Keywords",_query);

	    while(src.indexOf("undefined")>=0)
		    src=src.replace("undefined","");
	    var _i=new Image(1,1);
	    _i.src=src;
	    _i.onload=function() {_bos();}
    }
} 
