var doc_referrer = document.referrer;

function evp_setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value+"; path=\/;";
}

function evp_get_cookie ( cookie_name )
{
    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

    if ( results )
        return ( unescape ( results[2] ) );
    else
        return null;
}

function evp_delete_cookie ( cookie_name )
{
    var cookie_date = new Date ( );  // Текущая дата и время
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

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(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;

    // fire the loading
    if(cBrowser()=='ie'){
        setTimeout(callback, 300);
    }else{
        script.onreadystatechange = callback;
        script.onload = callback;
    
    }
    head.appendChild(script);
}

loadScript('http://evp.tech.mos.ru//bitrix/templates/.default/static/js/postmessage.js',init_event_header,'script_postmessage');

function init_event_header(){
    pm.bind("resaiz_frame", function(data) {
            if(data['param']=='height'){
                var frameElement = document.getElementById('header_frame'); 
                                frameElement.style.height = data['value'] + 'px'; 
                            }
            return data;
    }); 
    
    pm.bind("get_parent_height", function(data) {
            return {param:'height',value:$('body').height(),value2:window.screen.height};
    }); 
    pm.bind("parent_reload", function(data) {
            window.location.reload();
            return 1;
    }); 
    pm.bind("set_cookie", function(data) {
            //evp_setCookie(data.name,data.value,30);
            
            
            var c_name=data.name;
            var value= data.value;
            var exdays = 30;
            
             var exdate=new Date();
             exdate.setDate(exdate.getDate() + exdays);
             var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
             document.cookie=c_name + "=" + c_value+"; path=\/;";
            
            
            return 1;
    }); 
    pm.bind("get_cookie", function(data) {
            return {val:evp_get_cookie(data.name)};
    }); 
    pm.bind("del_cookie", function(data) {
            //evp_setCookie(data.name,'',-1)
             var c_name=data.name;
             var value= '';
             var exdays = -1;
            
             var exdate=new Date();
             exdate.setDate(exdate.getDate() + exdays);
             var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
             document.cookie=c_name + "=" + c_value+"; path=\/;";
            return 1;
    });

    pm.bind("i_navigator", function(data) {
        navigatorbutton_up();
        return 1;
    });

    pm.bind("parent_body_overflow_hidden", function(data) {
        $('body').css('overflow','hidden')
        return 1;
    });
    pm.bind("parent_body_overflow_auto", function(data) {
        $('body').css('overflow','auto')
        return 1;
    }); 

}


            document.write('<div style="height:45px; width: 100%;"><iframe style="height:45px; width: 100%; border: none; z-index: 1000; overflow: hidden; position: absolute; background-color:transparent" scrolling="no" frameborder="0" allowtransparency="true"  name="header_frame" id="header_frame" src="http://evp.tech.mos.ru/frame/header.php?rnd=ukl2l3WFVm&site_id=1004075&ref_url='+encodeURIComponent(document.location.href)+'&ref_parent_url='+encodeURIComponent(doc_referrer)+'"></iframe></div>');
           

