﻿function slolad_createAd(zoneId, url, width, height) {
    var zone = document.getElementById('zone_' + zoneId);
    if (zone) {
        if (!document.getElementById(zoneId)) {
            zone.appendChild(slolad_createIframe(zoneId, url, width, height));
        }
    }
}

function slolad_createIframe(id, url, width, height) {
    var iframe = document.createElement('iframe');
    iframe.id = id;
    iframe.name = id;
    iframe.width = width;
    iframe.height = height;
    iframe.style.visibility = 'hidden';
    //iframe.style.position = 'absolute';
    iframe.marginWidth = 0;
    iframe.marginHeight = 0;
    iframe.frameBorder = 0;
    iframe.scrolling = "no";
    iframe.allowTransparency = 'true';
    iframe.src = url;
    return iframe;
}

function slolad_showAd(id) {
    if (document.getElementById(id)) {
        //document.getElementById(id).style.position = 'relative';
        document.getElementById(id).style.visibility = 'visible';
    }
}

function slolad_setAdSize(id, width, height) {
    var i = document.getElementById(id);
    if (i) {
        i.width = width;
        i.height = height;
    }
}

function getCenter() {
    var xMax = screen.width, yMax = self.screen.availHeight;
    if (document.body.clientWidth) {
        _cw = document.body.clientWidth
        _ch = document.body.clientHeight;
    }
    else {
        _cw = window.innerWidth;
        _ch = window.innerHeight;
    }
    return { x: _cw / 2, y: getPageHeight() / 2 };
}

function getPageHeight() {
    if (self.innerHeight) // all except Explorer
        h = self.innerHeight;
    else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
        h = document.documentElement.clientHeight;
    else if (document.body) // other Explorers
        h = document.body.clientHeight;
    return h;
}

function getPageWidth() {
    if (self.innerWidth) // all except Explorer
        w = self.innerWidth;
    else if (document.documentElement && document.documentElement.clientWidth) // Explorer 6 Strict Mode
        w = document.documentElement.clientWidth;
    else if (document.body) // other Explorers
        w = document.body.clientWidth;
    return w;
}

function getScrollTop() {
    if (window.opera) {
        offset = document.body.scrollTop;
    }
    else {
        offset = document.documentElement.scrollTop;
    }
    return offset;
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function createCookie(name, value, minutes) {
    if (minutes) {
        var date = new Date();
        //date.setTime(date.getTime()+(days*24*60*60*1000));
        date.setTime(date.getTime() + (minutes * 60 * 1000));
        //date.setTime(date.getTime()+(30*1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function loadFlyBanner() {
    if (!document.getElementById(objId)) return false;
    var obj = document.getElementById(objId);
    var cookie = readCookie('flyBanner');
    if (cookie == null) {
        createCookie('flyBanner', 0, 30);
    }
    cookie = readCookie('flyBanner');
    if (cookie == null) {
        cookie = dTime;
    }
    if (cookie < dTime) {
        cookie++;
        createCookie('flyBanner', cookie, 30);
        obj.style.visibility = 'visible';
        obj.style.zIndex = 100;
        loc();
    }
}

function loc() {
    if (!document.getElementById(objId)) return false;
    var obj = document.getElementById(objId);
    w = getPageWidth();
    h = getPageHeight();
    if (h >= obj.offsetHeight) {
        obj.style.top = (h / 2) - (obj.offsetHeight / 2) + getScrollTop() + 'px';
    }
    if (first == 0) {
        first++;
        if (w >= obj.offsetWidth) {
            flyTimer = setTimeout('move()', timeout);
        }
    }
}

function move() {
    var obj = document.getElementById(objId);
    if (distance + obj.offsetWidth <= getPageWidth()) {
        obj.style.left = distance + 'px';
        distance = distance + step;
        flyTimer = setTimeout('move()', timeout);
    }
    else {
        obj.style.visibility = 'hidden';
    }
}

function flyMouseOver() {
    clearTimeout(flyTimer);
}

function flyMouseOut() {
    flyTimer = setTimeout('move("' + objId + '")', timeout);
}

function getObj(name) {
    var el = new Object;
    if (document.getElementById) {
        el.obj = document.getElementById(name);
        el.style = document.getElementById(name).style;
    }
    else if (document.all) {
        el.obj = document.all[name];
        el.style = document.all[name].style;
    }
    else if (document.layers) {
        el.obj = document.layers[name];
        el.style = document.layers[name];
    }
    return el;
}
function getScrollXY() {
    var scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    }
    else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    }
    else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return scrOfY;
}

function pvStat(id) {
    var pvTmpImg = new Image();
    var n = new Date();
    //pvTmpImg.src = "http://www.ohtuleht.ee/inc/adt.aspx?id=" + id + "&d=" + n.getTime();
    pvTmpImg.src = "/" + id + "/d/" + n.getTime() + "/adt.gif";
}

function strip_add_load_event(handler) {
    if (window.addEventListener) {
        window.addEventListener('load', handler, false);
    }
    else if (document.addEventListener) {
        document.addEventListener('load', handler, false);
    }
    else if (window.attachEvent) {
        window.attachEvent('onload', handler);
    }
}

function strip_escapeHTML(s) {
    s = s.replace('<', '&lt;');
    s = s.replace('>', '&gt;');
    s = s.replace('&', '&amp;');
    s = s.replace('"', '&quot;');
    return s;
}

function strip_get_style() {
    if (navigator.userAgent.search('MSIE') != -1) {
        /* MSIE-specific hacks (eww!) */
        var iestyle =
      "z-index: 32701; height: 35px; width: 100%;\n" +
      "overflow: hidden;\n" +
      "position: absolute;\n" +
      "right: auto;\n" +
      "bottom: auto;\n" +
      "left: 0 !important;\n" +
      "top: expression( ( -0 - strip_overlay.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' ) !important;\n"
      ;

        var styleSheetObj = document.createStyleSheet();
        styleObj = styleSheetObj.owningElement || styleSheetObj.ownerNode;
        styleObj.setAttribute("type", "text/css");
        styleSheetObj.addRule("#strip_overlay", iestyle);

        return "";
    }
    else {
        return "z-index: 32701; position: fixed; bottom: 0px; width: 100%; height: 35px; overflow: hidden";
    }
}

function strip_init() {
    var style = strip_get_style();

    var div = document.createElement('div');
    div.id = 'strip_overlay';
    div.setAttribute('class', 'strip_overlay');

    html = '<div id="strip_inner" style="position: relative; height: 35px; white-space: nowrap" onmouseover="strip_scroll_enabled = 0" onmouseout="strip_scroll_enabled = 1">';
    html += '<a href="' + strip_escapeHTML(strip_clickurl) + '" style="white-space: nowrap" target="_blank">';
    for (var i = 0; i < 4; i++) {
        html += '<img border="0" width="' + strip_width + '" height="' + strip_height + '" src="' + strip_escapeHTML(strip_image) + '" />';
    }
    html += '</a>';
    html += '</div>';

    div.innerHTML = html;
    div.setAttribute('style', style);

    document.body.appendChild(div);
    setInterval('strip_scroll()', 50);
}

function strip_scroll() {
    if (strip_scroll_enabled) {
        if (strip_scroll_offset >= strip_width)
            strip_scroll_offset = 0;
        else
            strip_scroll_offset += 2;

        div = document.getElementById('strip_inner');
        div.style.left = -strip_scroll_offset + 'px';
    }
}

function strip_clear() {
    var div = document.getElementById('strip_overlay');
    if (div != null) {
        document.body.removeChild(div);
    }
}

function set_pos() {
    var obj = getObj("bannerside");
    var obj2 = getObj("dynb");
    var sh = getScrollXY();
    var dh = document.getElementById('bannerside_s').offsetHeight + document.getElementById('side-advert-links').offsetHeight + document.getElementById('side-advert-links2').offsetHeight + document.getElementById('topbar').offsetHeight;
    //var dh = document.getElementById('bannerside_s').offsetHeight + document.getElementById('topbar').offsetHeight;
    
    var gh = document.getElementById('content').offsetHeight;
    var tervikkorgus = document.getElementsByTagName('body')[0].clientHeight; /* IE<7 rahuldamiseks*/
    /* = kogukõrgus - kõik sidebannerid k.a liikuv element - alumised elemendid */
    var liikumispiirkond = tervikkorgus - document.getElementById('bannerside').offsetHeight - document.getElementById('jalus').offsetHeight;
    obj.style.position = 'relative';
    /*obj.style.top = '6px';*/
    if (sh <= dh) { ch = 0; } else ch = sh - dh;
    var oldch = parseInt(obj2.style.top);
    obj2.style.position = 'relative';
    if (ch != oldch) {
        if (ch > oldch) { oldch = oldch + Math.round((ch - oldch) / 3); }
        else if (ch < oldch) { oldch = oldch - Math.round((oldch - ch) / 3); }
        /*ülemine piir:*/
        if (Math.abs(ch - oldch) <= 1) { oldch = ch; }
        /*if (sh > gh) oldch = gh - dh;*/
        if ((liikumispiirkond - oldch) <= 1) { oldch = liikumispiirkond; }
        obj2.style.top = oldch + "px";
        setTimeout("set_pos()", 40);
    }
    else { setTimeout("set_pos()", 300); }
}

function gup(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "/index.aspx";
    else
        return results[1];
}