/*Zeropixel functions*/
if(typeof(ml_zp_utils) == 'undefined') {
	var ml_zp_utils = {
		cookie_enabled : function (ph) {
			var is_enabled = false;

			if (!ph.window.opera && !navigator.cookieEnabled){
				return is_enabled;
			}
			if (typeof ph.document.cookie == 'string'){
				if (ph.document.cookie.length==0) {
					ph.document.cookie = "test";
					is_enabled = ph.document.cookie == 'test';
					ph.document.cookie = '';
				} else {
					is_enabled = true;
				}
			}
			
			return is_enabled;
		},
		
		callevent : function(z, rand_url, ph) {
			var imgHandle;
			
			if(!this.cookie_enabled(ph)){
				return;
			}
			
			for (var i in z) {
				if (!z.hasOwnProperty(i)) continue;
				if(z[i].toUpperCase().indexOf("HTTP://") == 0) {
					imgHandle = ph.document.createElement("img");
					imgHandle.style.display = "none";
					imgHandle.style.width = "0px";
					imgHandle.style.height = "0px";
					if(typeof(rand_url) != 'undefined') {
						imgHandle.src = (z[i].indexOf('?') > 0) ? z[i] + '&' + rand_url : z[i] + '?' + rand_url;
					}
					else {
						imgHandle.src = z[i];
					}

					ph.placeholder.appendChild(imgHandle);		
				}
			}	
		}
	};
}

/*Cut text functions*/
function toHtmlEnteties1155(text) {
	 var new_text = "";
	 var str_len = text.length;
	 for (i=0; i < str_len; i++) {
		 iCode = text.charCodeAt(i);
		 new_text += (iCode > 256? "&#" + iCode + ";": text.charAt(i));
	 }
	 return new_text;
} 

function toHtmlEntetiesBack1155(text) {
	 var new_text = "";
	 var str_len = text.length;
	 for (i=0; i < str_len; i++) {
		if(text.substr(i,2) == "&#" && (uni_val = parseInt(text.substr(i+2,4)))){
			new_text += String.fromCharCode(uni_val);
			i += 6;
		}
		else{
			new_text += text.charAt(i);
		}
	 }
	 
	 return new_text;
}
 
function teaserTextCut1155(text, n) {
	var str_len = text.length;
	var new_text = "";
	for (i=0; ((i < str_len) && n); i++) {
               if(text.substr(i,4) == "<br>") {
			new_text += "<br style='display:block'/>";
			i += 3;
		}
		else if(text.substr(i,5) == "<br/>") {
			new_text += "<br style='display:block'/>";
			i += 4;
		}
		else if(text.substr(i,5) == "&shy;") {
			new_text += "&shy;";
			i += 4;
		}
		else{
			new_text += text.charAt(i);
			n--;
		}
	}
	
	return new_text;
}

/*For title color check*/
function checkColor1155(c){ // make sure color is exactly in #XXXXXX form
	if ((typeof(c) == 'undefined') || (c.indexOf('#') != 0)) return '#FF0000'; // default color is red
	while (c.length < 7) c = c + '0';
	var nc = parseInt(c.substring(1),16);
	if (isNaN(nc)) return '#FF0000';
	nc = nc.toString(16);
	while (nc.length < 6) nc = '0' + nc;
	return '#'+nc;
}

/*Banner*/
if (typeof(mlpH1155) == 'undefined') var mlpH1155=null;
if (typeof(mlpd1155) == 'undefined') var mlpd1155=null;
if (typeof(mlnc1155) == 'undefined') var mlnc1155=null;
if (typeof(mlpw1155) == 'undefined') var mlpw1155=null;

mlnc1155 = 0; 
mlpd1155 = parent.document;
if (mlpd1155 != document) 
{
 	mlpH1155 = mlpd1155.getElementById('mlph1155'); //search for placeholder in parent document
 	mlnc1155 = mlpH1155 ? 1 : 0;
	mlpw1155 = (mlpw1155 == null ? parent : mlpw1155);
}
if (!mlnc1155) 
{
	mlpH1155 = document.getElementById('mlph1155'); 
	mlpd1155 = document;
	mlpw1155 = (mlpw1155 == null ? parent : mlpw1155);
} // old code, search in current document
if (!mlpH1155) 
{
	document.write('<div id="mlph1155"></div>');
	mlpH1155 = document.getElementById('mlph1155');
} // not found, create and take handle
	
mlpH1155.style.overflow = "hidden";
mlpH1155.style.width = "149px";
/*mlpH1155.style.height = "68px";*/
mlpH1155.style.display = "block";

mlpH1155.style.font = "12px Verdana,Arial,Helvetica,sans-serif";
mlpH1155.style.fontSize = "10px";
mlpH1155.style.lineHeight = "14px";
mlpH1155.style.textAlign = "left";

var title = ""
var title_color = checkColor1155("");
var text = '&#1046;&#1091;&#1088;&shy;&#1085;&#1072;&#1083; "DAS." &#1059;&#1074;&#1083;&#1077;&shy;&#1082;&#1072;&shy;&#1090;&#1077;&#1083;&#1100;&shy;&#1085;&#1086; &#1086;&#1073; &#1080;&#1085;&shy;&#1085;&#1086;&shy;&#1074;&#1072;&shy;&#1094;&#1080;&shy;&#1103;&#1093; Volkswagen';
var max_letters = isNaN(parseInt("")) ? 60 : parseInt("");

var place_dir = "rbc.ru/rbc.ru-rbcfreenews-top.rbc.ru-quote.rbc.ru-sport.rbc.ru-style.rbc.ru-realty.rbc.ru-turist.rbc.ru-rbctv.rbc.ru-tv.rbc.ru-lf.rbc.ru-rating.rbc.ru-seminar.rbc.ru-marketing.rbc.ru-rbcdaily.ru-utro.ru-autonews.ru-biztorg.ru-tata.ru-cnews.ru/";
var _defaultPlaceDir = 'global';
var	_clickServerUrl = 'http://content.rbc.medialand.ru/';
var link = "http://engine.rbc.medialand.ru/reference?gid=2&pid=1155&bid=13697&rid=1187300859";

place_dir = ((typeof(place_dir) != 'undefined' && place_dir.length) ? escape(place_dir) : _defaultPlaceDir);
link = _clickServerUrl + place_dir + '/?' + escape(link);

//Cut text
/*
	Format : max 60 letters - 12 letters in first three lines, 24 letters in the last line
*/
var cut_text = teaserTextCut1155(toHtmlEntetiesBack1155(text) , max_letters);
text = toHtmlEnteties1155(cut_text);


//Make font color
var dark_bg_sites = ["www.autonews.ru", "www.tata.ru", "rbctv.rbc.ru"];
var text_color = "#333333";
for(i in dark_bg_sites){
	if(dark_bg_sites[i] == mlpw1155.location.host) {
		title_color = text_color = "#FFFFFF";
		break;
	}
}

var mlstr = '<div style="clear: both;">';
mlstr += '<a style="color: ' + text_color + ';text-decoration: none;display:block;" href="'+link+'" target=_blank>';
mlstr += '<img style="border:0;float:left;margin:0 5px 0 0;padding:0px;width:60px;height:40px" src="http://content.rbc.medialand.ru/t17/a2184/ru_60-40_mb.jpg" alt="" />';
if(title.length){
	//mlstr += '<span style="color:'+title_color+'">'+title+'</span><br/>';
}
mlstr += text;
mlstr += '<div style="clear:both"></div>';
mlstr += '</a>';
mlstr += '</div>';
mlpH1155.innerHTML += mlstr;


var z = ["", ""];
var rand_url = ""; 

var ph = {
	document : mlpd1155,
	placeholder : mlpH1155,
	window : mlpw1155
};

ml_zp_utils.callevent(z, rand_url, ph);

if (mlnc1155) {
	//close document for async code
	document.close();
}