
function cBrowser() {
    var ua = navigator.userAgent;
    var bName = function () {
        if (ua.search(/MSIE/) > -1) return "ie";
        }();
        
    var version = function (bName) {
        switch (bName) {
            case "ie" : return (ua.split("MSIE ")[1]).split(";")[0];break;
    }}(bName);
    return [bName];
}
function loadScript_DF9lg(url, callback,id_script)
{
    
        // adding the script tag to the head as suggested before
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = url;
        script.id = id_script;
		
		if(cBrowser()=='ie'){
            setTimeout(callback, 100);
                    }else{
            script.onreadystatechange = callback;
            script.onload = callback;
		}
        head.appendChild(script);
}

loadScript_DF9lg((document.location.protocol==='https:'?'https:':'http:')+'//evp.mos.ru//bitrix/templates/.default/static/js/postmessage.js', init_event_banner_DF9lg, 'script_postmessage');

function randomString(len){
    charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var randomString = '';
    for(var i = 0; i < len; i++){
        var randomPoz = Math.floor(Math.random() * charSet.length);
        randomString += charSet.substring(randomPoz, randomPoz+1);
    }
    return randomString;
} 

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function init_event_banner_DF9lg(){	
	pm.bind("resize_frame_banner_DF9lg", function(data) {
			
			data = JSON.parse(data);
			
			if(data['param_h']>0){
                var frameElement;
				frameElement = document.getElementById('banner_frame_DF9lg'); 
                frameElement.style.height = data['param_h'] + 'px'; 
				frameElement = document.getElementById('evp_adv_banner_container_DF9lg');
                frameElement.style.height = data['param_h'] + 'px'; 
            }
            
            if(data['param_w']>0){
                var frameElement;
				frameElement = document.getElementById('banner_frame_DF9lg'); 
                frameElement.style.width = data['param_w'] + 'px'; 
				frameElement = document.getElementById('evp_adv_banner_container_DF9lg'); 
                frameElement.style.width = data['param_w'] + 'px'; 
            }
            return data;
    }); 

    pm.bind("add_new_from_DF9lg", function(data){
		
		data = JSON.parse(data);
	
        var el = document.createElement("iframe");
        el.id = 'iframe_';
        el.src = data['param_url']+'&rand_id=DF9lg';
        el.style.top = '0';
        el.style.left = '0';
        el.style.width = '100%';
        el.style.height = '100%';
        el.style.border = 'medium none';
        el.style.zIndex = 9999;
        el.style.overflow = 'hidden';
        el.style.position = 'fixed';
        el.style.backgroundColor = 'transparent';
        document.body.appendChild(el);
    });

    pm.bind('remove_adver_video_frame_DF9lg', function(){
        document.body.removeChild(document.getElementById("iframe_"));
    });
	
	pm.bind('remove_adver_frame_DF9lg', function(){
		(elem=document.getElementById("evp_adv_banner_container_DF9lg")).parentNode.removeChild(elem);
		(elem=document.getElementById("evp_adv_banner_240x115_DF9lg")).parentNode.removeChild(elem);
    });
	
	
	pm.bind('next_frame_load_DF9lg', function(){
		if ((typeof(window.addBanners) != 'undefined') && (window.addBanners.length > 0))
		{			
			var func_name = window.addBanners.shift();
			eval(func_name);
		}
    });
}


var scripts = document.getElementsByTagName("script");
var id = 'evp_adv_banner_240x115_DF9lg';
for(var i = 0; i < scripts.length; i++ )
{
	e = scripts[i].className;
	if(e == 'evp_adv_240x115_ru_n')
	{
		scripts[i].setAttribute('id', id);
		scripts[i].removeAttribute('class');
		break;
	}
}

var n = document.getElementById(id);
if(typeof(n) != 'undefined' && n !== null)
{
	s = document.createElement("div"),
	s.id = "evp_adv_banner_container_DF9lg";
	s.style.position = "relative";
	s.style.height = "400px";
	s.style.width = "240px";
	//s.style.cssFloat = "left";
	s.style.display = "inline-block";
		
	if(typeof(window.firstLoad) == 'undefined')
	{
		s.innerHTML = '<iframe style="height: 400px; width: 240px; border: none; z-index: 1; overflow: hidden; position: absolute; background-color:transparent" scrolling="no" frameborder="0" allowtransparency="true"  name="banner_frame_DF9lg" id="banner_frame_DF9lg" src="'+(document.location.protocol==='https:'?'https:':'http:')+'//evp.mos.ru/exposition/evp_exposition.php?rand_id=DF9lg&type=240x115&cecutient=N&lang=ru&ref_url='+encodeURIComponent(document.location.href)+'&uid="></iframe>';
		window.firstLoad = 'DF9lg';
		window.addBanners = [];
	}
	else
	{		
		window.addBanners.push('show_banner_DF9lg()');
		
		function show_banner_DF9lg () {			
			id = "evp_adv_banner_container_DF9lg";			
			var s = document.getElementById(id);
			
			s.innerHTML = '<iframe style="height: 400px; width: 240px; border: none; z-index: 1; overflow: hidden; position: absolute; background-color:transparent" scrolling="no" frameborder="0" allowtransparency="true"  name="banner_frame_DF9lg" id="banner_frame_DF9lg" src="'+(document.location.protocol==='https:'?'https:':'http:')+'//evp.mos.ru/exposition/evp_exposition.php?rand_id=DF9lg&type=240x115&cecutient=N&lang=ru&ref_url='+encodeURIComponent(document.location.href)+'&uid="></iframe>';
		}
	}
	n.parentNode.insertBefore(s, n);
}
