var timeObjectCreationR1043R=(new Date()).getTime();
document["ACCommonVersion"]="1.0";
if(document["ACDebug"]==null){
document["ACDebug"]=false;
}
function ACCommon(){
}
ACCommon.prototype.isSupported=function(){
var _1=document.getElementById?true:false;
if(!_1){
this.info("This browser is not supported");
return false;
}
return true;
};
ACCommon.prototype.addScript=function(_2,_3){
if(_3){
_2=_2+"&_rnd="+Math.random();
}
ACCommon.prototype.info("Load URL: "+_2+", url length:"+_2.length);
var _4=document.getElementsByTagName("head")[0];
var _5=document.createElement("script");
_5.type="text/javascript";
_5.src=_2;
_4.appendChild(_5);
};
ACCommon.prototype.isDomReady=function(){
var _6=document.getElementsByTagName("body");
if(_6==null||_6.length==0){
this.info("DOM Body is not ready");
return false;
}
var _7=document.getElementsByTagName("head");
if(_7==null||_7.length==0){
this.info("DOM Head is not ready");
return false;
}
if(ACCommon.prototype.isIE()){
var rs=document.readyState;
if(rs=="loaded"){
return true;
}
}
var t=(new Date()).getTime()-timeObjectCreationR1043R;
if(t<300){
return false;
}
return true;
};
ACCommon.prototype.isIE=function(){
var ua=window.navigator.appName;
var _b=ua.indexOf("Microsoft Internet Explorer")>=0;
return _b;
};
ACCommon.prototype.info=function(_c){
if(!document["ACDebug"]||console==null){
return;
}
console.info(_c);
};

// ------------
// Library used to analyse keywords / C-2007 / Gabriel Klein / AdsClick
// ------------

//if (document["ACAnalyseVersion"] != "1.0") {
document["ACAnalyseVersion"] = "1.0";

//--
function ACKeyword(keyword) {
	this.canUnderline = false;
	this.count = 0;
	this.boost = 0;
	this.isProposed = false;
	this.keyword=keyword;
}

ACKeyword.prototype.add = function(boost) {
	this.count = this.count+1;
	this.boost = this.boost+boost;
}

// ------------

function ACAnalyse(proposedKeywords) {

	this.MINSIZE = 3;
	this.MAXSIZE = 50;
	this.bannedKeywords = new Array(
		"ki","kim","lakin","madem","mademki","meğer","meğerki","meğerse","ne ne","neyse","oysa","oysaki","şayet",
		"ve","velev","veya","veyahut","ya","ya ya","ya da","yahut","yalnız","yani","yok","yoksa","zira","bir","yada"
		);
	this.MAXDOMTIMEMS = 3000;
	this.proposedKeywords = proposedKeywords;
	this.proposedKeywordsMap = new Object();
	for (var i=0; i<this.proposedKeywords.length; i++) this.proposedKeywordsMap[this.proposedKeywords[i]]="*";
		
	this.debug = true;
	var o = new Object();
	o["a"] = o["h1"] = o["h2"] = o["h3"] = o["h4"] = o["h5"] = "*";
	this.noUnderline = o;
	o = new Object();
	o["script"] = o["noscript"] = o["textarea"] = o["embed"] = o["object"] = o["img"] = o["param"] = "*";
	this.noEnter = o;
	o = new Object();
	o["h1"] = 10; o["h2"] = 7; o["h3"] = 6; o["h4"] = o["h5"] = 5; o["a"] = 5; o["b"] = 4; o["i"] = 2; o["small"] = 0.5; 
	this.boost = o;
	this.boostTitleAndMeta = 10;
	this.regSplit = new RegExp("[\\|\\,\\.\\-\\;\\:\\!\\?\\'\\`\\^\\~\\+\\\"\\*\\/\\(\\)\\[\\]\\{\\} \\n\\r\\t\\_\\+\\%\\<\\>\\=]", ""); //g
	this.keywords = new Object();
		
	this.maxAnalyseNode = 10000;
	this.timeObjectCreation = (new Date()).getTime();
	
}

ACAnalyse.prototype.processHeadBody = function(onlyUnderline, countKeywords) {

	ACCommon.prototype.info("Analyse document");
	var s = (new Date()).getTime();
	this.analyseHead();
	// Check if we have a special span
	var spans = document.getElementsByTagName("contextual");
	var isParsed = false;
	var result;
	for (var i=0; i<spans.length; i++) {
		var span = spans[i];
		result = this.analyseNode(s, span, false, 1);
		isParsed=true;
	}
	
	
	var tagNames = ["div","span"];
	for (var j =0;j<tagNames.length;j++)
	{
	
		var elements = document.getElementsByTagName(tagNames[j]);	
		for (var i=0; i<elements.length; i++) {
			var element = elements[i];
			if (element.id=="contextual" || element.name=="contextual") {
				result = this.analyseNode(s, element, false, 1);
				isParsed=true;
			}
		}
	
	}


	if (!isParsed) {
		result = this.analyseNode(s, document.getElementsByTagName("body")[0], false, 1);
	}
	var e = (new Date()).getTime();
	ACCommon.prototype.info("Analysed "+(result?"full":"partial")+" document in "+(e-s)+" ms");
}


// Analyse the DOM.
// Add "true" if you are only interested by keywords that could be underlined.
// Return a list of sorted keywords.
ACAnalyse.prototype.analyse = function(onlyUnderline, countKeywords) {

	var body  = document.getElementsByTagName("body")[0];
	if (body == null) {ACCommon.prototype.info("DOM Body is not ready");}
	var e1 = (new Date()).getTime();

	this.processHeadBody(onlyUnderline, countKeywords);
	
	var sortedList = this.sortKeywords(onlyUnderline, countKeywords);
	// Some cleanup
	this.proposedKeywords = null;
	this.proposedKeywordsMap = null;

	this.keywords = null;

	var e2 = (new Date()).getTime();
	ACCommon.prototype.info("Keywords sorted in "+(e2-e1)+" ms");
	
	return sortedList;
}

ACAnalyse._encode = function(string) {
	string = string.replace(/\r\n/g,"\n");
	return string;

	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}

ACAnalyse._cropText = function(text, length, seperator) {
	var limit = length;
	if (seperator) {
		// get last occurance of seperator character for given length
		limit = text.substring(0, length).lastIndexOf(seperator);
	} 
	return text.substring(0, limit);
}

ACAnalyse.prototype.analyseAndGetUrl = function(onlyUnderline, baseUrl, showWeight) {
	//var ua = window.navigator.appName;
	//var maxURL = ( ua==null || ua.indexOf( "Microsoft Internet Explorer" ) >= 0) ? 2000: 3800;
	//var maxURL = 1000;
	

	maxURL = 1300;
	countKeywords = Math.round((maxURL-baseUrl.length)/4);	

	
	var sortedList = this.analyse(onlyUnderline, countKeywords);
	
	var ctx = "&ctx=";
	var ctxsafe = "&ctxsafe=";
	for (var i=0; i<sortedList.length; i++) {
		var kw = sortedList[i];
		if (kw.isProposed)
			ctx=ctx+","+ACAnalyse._encode(kw['keyword'])+(showWeight?(":"+kw['boost']):"");
		else
			ctxsafe=ctxsafe+","+ACAnalyse._encode(kw['keyword'])+(showWeight?(":"+kw['boost']):"");
	}
	
	charSet="&enc=";
	if(/Firefox/.test(navigator.userAgent) || /Iceweasel/.test(navigator.userAgent)){
		charSet += document.characterSet;
	}
	else
		charSet += document.charset;
	
	// RETURN OF THIS FUNCTION SHOULD BE THIS LINE IF POST METHOD IS GOING TO BE USED
	//return {baseurl:baseUrl,ctx:ctx,ctxsafe:ctxsafe,charset:charSet};
	
	var nu = baseUrl+ctx+ctxsafe+charSet;	
	var ie_url_limit = 1900; // max url character length limit is 2048 for ie normally, but we need to keey place for extra params that'll be added afterwards, for ex. see ACCommon.addScript.
	if(/msie/.test(navigator.userAgent.toLowerCase()) && nu.length >= ie_url_limit) {
		var newlimit = ie_url_limit - (nu.length - ctx.length) - 1;
		if (newlimit > 0) {
			ctx = ACAnalyse._cropText(ctx, newlimit, ",")
		} else {
			newlimit = ie_url_limit - (nu.length - ctxsafe.length)
			ctxsafe = ACAnalyse._cropText(ctxsafe, newlimit, ",")
		}
		nu = baseUrl+ctx+ctxsafe+charSet;
	}
	return nu;

}

ACAnalyse.prototype.sortKeywords = function(onlyUnderline, numberOfKeywords){
	var mapPerBoostNormal = new Array(101);
	var mapPerBoostProposed = new Array(101);
	var counter=1;
	for (var i=0; i<=100; i++)  {mapPerBoostNormal[i]=new Array();mapPerBoostProposed[i]=new Array();};
	for (keyword in this.keywords) {
		counter++;
		keyword = keyword+"";
		var stats =  this.keywords[keyword];
		if (!onlyUnderline || stats.canUnderline) {
			ACCommon.prototype.info(keyword+" ("+stats.keyword+") =  UL:" + stats.canUnderline+" CNT:"+stats.count+" Boost:"+stats.boost+" Proposed:"+stats.isProposed);
			
			var weight = Math.round(stats.boost);
			if (weight<0) weight=0;
			if (weight>100) weight=100;
			if (stats.isProposed) 
				mapPerBoostProposed[weight][mapPerBoostProposed[weight].length]=stats;
			else
				mapPerBoostNormal[weight][mapPerBoostNormal[weight].length]=stats;
		}
	}
	

	var res = new Array();
	for (var i=100; i>=0 &&res.length<numberOfKeywords; i--) {
		var e = mapPerBoostProposed[i];
		for (var j=0; j<e.length &&res.length<numberOfKeywords; j++) {
			res[res.length] = e[j];
		}
	}
	for (var i=100; i>=0&&res.length<numberOfKeywords; i--) {
		var e = mapPerBoostNormal[i];
		for (var j=0; j<e.length &&res.length<numberOfKeywords; j++) {
			res[res.length] = e[j];
		}
	}
	return res;
}

// Return 2 => no enter, 1 => no underling, 0 => 
ACAnalyse.prototype.getTagType = function(tagType){
	tagType = tagType;
	if (this.noEnter[tagType] == "*") return 2;
	if (this.noUnderline[tagType] == "*") return 1;
	return 0;
}

ACAnalyse.prototype.analyseNode = function(timeStarted, b, isNoUnderline, boost) {

	this.maxAnalyseNode=this.maxAnalyseNode-1;
	if (this.maxAnalyseNode<0) {ACCommon.prototype.info("Done maximum call of analyse node");return false;}
	if ( (new Date()).getTime()-timeStarted>this.MAXDOMTIMEMS) {
		ACCommon.prototype.info("Overtime on dom processing: "+( (new Date()).getTime()-timeStarted)+" ms");
		return false;
	}

	if (b.firstChild != null) {
		for (var i=0; i<b.childNodes.length;i++) {
		
			if (maxUnderlineCount<1)continue;
		
			if (b.childNodes[i].nodeType==3) {
				var v = b.childNodes[i].nodeValue;
				try {
					i+=this.addText(v, isNoUnderline, boost, false, b, b.childNodes[i], i);
				}
				catch(e) {
					ACCommon.prototype.info("Error changing dom: "+e);
				}
			}
			else {
				var nodeS = ""+b.childNodes[i].nodeName;
				var tagType = this.getTagType(nodeS.toLowerCase());
				if ( tagType == 0 || tagType == 1) {
					if (b.childNodes[i].nodeName=="span"
						&& b.childNodes[i].id == "adsclickad") {
							//
					}
					else {
						var nBoost = Math.round(this.boost[nodeS]);
						if ((""+nBoost)=='NaN') nBoost = 1; 
						if (!this.analyseNode(timeStarted, b.childNodes[i], isNoUnderline||(tagType == 1), nBoost)) {
							return false;
						}
					}
				}
				// else 2

			}
		}
	}
	return true;
}	

ACAnalyse.prototype.analyseHead = function() {

	this.addText(document.title, true, this.boostTitleAndMeta, false, null, null,0);

	var metas  = document.getElementsByTagName("meta");
	for (var i=0; i<metas.length; i++) {
		var meta=metas[i];
		var name=(""+metas[i].name);
		if (name=="keywords" || name=="description") {
			this.addText(meta.content, true, this.boostTitleAndMeta, name=="keywords",null,null,0);
		}
	}

}


	if(!Array.prototype.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}


ACAnalyse.prototype.addText = function(text, isNoUnderline, boost, onlyKeywords, parentNode, node, posChild) {
	
	if (text == null) return 0;
	
	text = (""+text.replace(/^\s+|\s+$/, '')); // trim!
	
	text = (text+"");
	if (text.length == 0) return 0;
	
	var tax = (text+"").split(this.regSplit);
	var previousKeyword = null;
	var keyword = null;
	
	if (this.proposedKeywords!=null) {
		for (var i=0; i<this.proposedKeywords.length; i++) {
			var kw = (""+this.proposedKeywords[i]);
			var p = text.indexOf(kw);
			if (p!=-1) {

	            var s=(p<=0?" ":text[p-1]);
        		var e=(p>=text.length?" ":text[p+kw.length]);
        		if (s==null || s.length==0) s=" ";
        		if (e==null || e.length==0) e=" ";
        		if (this.regSplit.test(s) && this.regSplit.test(e)) {
					keyword = this.keywords[kw];
					if (keyword == null) {
						keyword = new ACKeyword(kw);
					}
					keyword.isProposed = true;
					if (!isNoUnderline)
						keyword.canUnderline = true;
					keyword.add(boost);
					this.keywords[kw] = keyword;
	        	}			
			}
		}
	}
	
	for (var t=0; t<tax.length;t++) {
		var txt = tax[t]+"";
		if (this.bannedKeywords.indexOf(txt)>0)
		continue;
		
		if (txt.length>=this.MINSIZE && txt.length<=this.MAXSIZE) {
		
			// Add the keyword, not best perfo
			if (this.proposedKeywordsMap[txt] == null) {
				keyword = this.keywords[txt];
				if (keyword == null) {
					keyword = new ACKeyword(txt);
				}
				if (!isNoUnderline)
					keyword.canUnderline = true;
				keyword.add(boost);
				this.keywords[txt] = keyword;
			}
			
			/*
			// Add keyword + keyword before
			if (!onlyKeywords && previousKeyword!=null && previousKeyword!=txt) {
				var kw = previousKeyword+" "+txt;
				var p = text.indexOf(kw);
				if (p==-1) {
					kw = previousKeyword+"-"+txt;
					p = text.indexOf(kw);
				}
				if (p!=-1 && this.proposedKeywordsMap[kw] == null) {
					keyword = this.keywords[kw];
					if (keyword == null) {
						keyword = new ACKeyword(kw);
					}
					if (!isNoUnderline)
						keyword.canUnderline = true;
					keyword.add(boost);
					this.keywords[kw] = keyword;
				}
			}
			
			previousKeyword = txt;
			*/
		}
	}
	return 0;
}

// ------------
// Class used to replace keywords
// ------------
function AKeywordsReplace(proposedKeywords, functionReplaceHTML, maxUnterlineTime, maxSameKeywordUnderline) {

	this.myACAnalyse = new ACAnalyse(proposedKeywords);
	// Maximum number of element we underline
	this.myACAnalyse.maxUnderlineTime = maxUnterlineTime;
	// Maximum time we could underline the same keyword
	this.myACAnalyse.maxSameKeywordUnderline = maxSameKeywordUnderline;
	this.myACAnalyse.countByKeywords = new Object();
	this.myACAnalyse.countTotal = 0;
	this.myACAnalyse.replaceHTML = functionReplaceHTML;
	this.myACAnalyse.myReplacedSpan = this.myReplacedSpan = new Object();
	this.myACAnalyse.insertAfter = function(parent, newnode, referenceNode) {
		if (referenceNode.nextSibling == null) {
			parent.appendChild(newnode);
		}
		else {
			parent.insertBefore(newnode, referenceNode.nextSibling);
		}
	}
	this.myACAnalyse.addText = function(text, isNoUnderline, boost, onlyKeywords, parentNode, node, posChild) {	
		if(isNoUnderline || node == null || parentNode == null)
			return 0;
		if (this.countTotal>this.maxUnderlineTime)
			return 0;
		var text2 = text;
		
		if (text2=="")return 0;
		
		for (var i=0; i<this.proposedKeywords.length; i++) {
			kw = (""+this.proposedKeywords[i])+"";
			var count = this.countByKeywords[kw];
			if (count == null) count=0;
			if (count<this.maxSameKeywordUnderline) {
				var p = text2.indexOf(kw);
				
				if (p<0)continue;
				
				
				
				
			//** CHECKING IF THERE IS AN AD IN THE SAME SENTENCE
				//console.log("-----------");
				//console.log("current keyword:"+kw);
				var nstop= text2.indexOf(".",p);
				if (nstop<0)
				{
					//console.log("exit:1");
					continue;
				}

				var pstop=text2.indexOf(".",0);
				if ( pstop==nstop)
				{
					if (posChild >0 && parentNode.childNodes[posChild-1]!=null)
						if (parentNode.childNodes[posChild-1].nodeName.toLowerCase()=="span" &&parentNode.childNodes[posChild-1].id!=null&& parentNode.childNodes[posChild-1].id.toLowerCase()=="adsclickad")		
							{
								//console.log("exit:2");
								continue;
							}
					
					if ( nstop<0 && parentNode.childNodes[posChild+1]!=null)
						if (parentNode.childNodes[posChild+1].nodeName.toLowerCase()=="span" &&parentNode.childNodes[posChild+1].id!=null&& parentNode.childNodes[posChild+1].id.toLowerCase()=="adsclickad")		
							{
								//console.log("exit:2");
								continue;
							}
							
					
				}
			//** END OF CHECK
				
				
				
				
				
				
				while (p>=0) {

		            var s=(p<=0?" ":text2.substring(p-1,p));
	        		var e=(p>=text2.length?" ":text2.substring(p+kw.length,p+kw.length+1));
	        		if (s==null || s.length==0) s=" ";
   		     		if (e==null || e.length==0) e=" ";   	
   		     		
    	    		if (this.regSplit.test(s) && this.regSplit.test(e)) {
    	    	    	    		
						this.countByKeywords[kw] = count+1;
						this.countTotal = this.countTotal+1;
						if (this.countTotal>this.maxUnderlineTime)
							return 0;
						var kwWithCase = text.substring(p,p+kw.length);
						var before = document.createTextNode(text.substring(0,p));
						var span = document.createElement('span');
						span.innerHTML = this.replaceHTML(kwWithCase);
						span.id="adsclickad";
						var after = document.createTextNode(text.substring(p+kw.length));
												
						this.insertAfter(parentNode, after, node);
						this.insertAfter(parentNode, span, node);
						this.insertAfter(parentNode, before, node);
						parentNode.removeChild(node);
						maxUnderlineCount-=1;
						
						node = before;
						nodeChanged = 1;
						return -1;

						if (this.myReplacedSpan[kw]==null) this.myReplacedSpan[kw]=new Array();
						this.myReplacedSpan[kw][this.myReplacedSpan[kw].length]=span;
						p=-1;
					}
					else {
						p = text2.indexOf(kw, p+1);
					}
				}
			}
		}

		return 0;
	}
}

AKeywordsReplace.prototype.replaceKeywords = function() {
	this.myACAnalyse.processHeadBody(true, 100000);
}


//--
//}
// Smartlink first call - Copyright (c) 2007 www.ads-click.com
var parsedR1043R = false;

var ackwiR1043R=new Array("");
var ackwR1043R =new Array();
var mapR1043R={};


{
	var anaR1043R = new ACAnalyse(ackwR1043R, ackwiR1043R);
	
	function doItR1043R() {
		if (ACCommon.prototype.isDomReady()) {
			
			var r = anaR1043R.analyseAndGetUrl(true, "http://ads1.adklik.com.tr/AdServer/?&format=a_smartlink2b&id=359190_7332&&rndid=R1043R&uts=1265750445258&AC&", false);
			
			//THIS SCRIPT MAY BE USED FOR USING POST METHOD INSTEAD OF GET METHOD BUT 'analyseAndGetUrl' SHOULD BE MODIFIED AS WELL
			/*
			var adklikKeywordsFrame = document.createElement("iframe");
			adklikKeywordsFrame.id ="adklikSmartlinkKeywords";
			adklikKeywordsFrame.style.display = "none";

			
			var keywordsPostForm = document.createElement("form");
			keywordsPostForm.method="POST";
			keywordsPostForm.action=r.baseurl;
			

			var bodyElement = document.getElementsByTagName("body")[0];
			bodyElement.appendChild(adklikKeywordsFrame);
			
			window.setTimeout(function(){adklikKeywordsFrame.contentWindow.document.body.appendChild(keywordsPostForm);},100);
			
			
			var hiddenCtx =  document.createElement("input");
			hiddenCtx.type= "hidden";
			hiddenCtx.name = "ctx";
			hiddenCtx.value = r.ctx;
			
			
			var hiddenCtxSafe =  document.createElement("input");
			hiddenCtxSafe.type= "hidden";
			hiddenCtxSafe.name = "ctxsafe";
			hiddenCtxSafe.value = r.ctxsafe;
			
			
			var hiddenCharSet =  document.createElement("input");
			hiddenCharSet.type= "hidden";
			hiddenCharSet.name = "charSet";
			hiddenCharSet.value = r.charset;
			
			var hiddenPageUrl =  document.createElement("input");
			hiddenCharSet.type= "hidden";
			hiddenCharSet.name = "u";
			hiddenCharSet.value = window.location;
			
			
			keywordsPostForm.appendChild(hiddenCtx);
			keywordsPostForm.appendChild(hiddenCtxSafe);
			keywordsPostForm.appendChild(hiddenCharSet);
			keywordsPostForm.appendChild(hiddenPageUrl);
			
			window.setTimeout(function(){keywordsPostForm.submit();},300);			
			//window.setTimeout(function(){bodyElement.removeChild(adklikKeywordsFrame)},500);
			*/
			
			
			ACCommon.prototype.addScript(r, true);
			anaR1043R = null;
		}
		else {
			ACCommon.prototype.info("Dom is not yet ready yet");
			setTimeout("doItR1043R()",100);
		}
	}
	
	
	if (ACCommon.prototype.isSupported()) {
		doItR1043R();
	}
}
var maxUnderlineCount=10;