﻿// JScript File
var http_request;
var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 

function AjaxRequest(method, params, responseFunction)
{
//alert(method + " " + params + "\n" + responseFunction);

    if( window.XMLHttpRequest ) {http_request = new XMLHttpRequest(); }
    else if( window.ActiveXObject ) { http_request = new ActiveXObject( 'Microsoft.XMLHTTP' ); }
    
    var par = "method=" + method + "&params=" + params;
    http_request.open( 'post', 'RCP/default.aspx', true );
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", par.length);
    http_request.setRequestHeader("Connection", "close");
    
    
    http_request.onreadystatechange = function()
    {
        if( http_request.readyState == 4 )
        {
            
            if( http_request.status == 200)
            {
                if(responseFunction != "")
                {
                    window.setTimeout(responseFunction + "('" + escape(http_request.responseText) + "')", 1);
                }
            }
            else { 
            alert(http_request.status);
            alert(http_request.responseText); 
            }
        }
    }
    http_request.send( par );
}

function SetAds(data)
{
    var datas = unescape(data).split("*");
    var context = document.getElementById("contextAds");
    
    for(i = 0; i < datas.length; i++)
    {
        if(datas[i] != "")
        {
            var parts = datas[i].split("=");
            var r = new RegExp(parts[0], "gi");
            var m = context.innerHTML.match(r);
            for(mm = 0; mm < m.length; mm++)
            {
                if(m.indexOf(m[mm]) >= mm)
                {
                var r1 = new RegExp(m[mm], "g");
                context.innerHTML = context.innerHTML.replace(r1, "<span style=\"text-decoration: underline;font-weight:bold;cursor:pointer;padding-bottom: 1px;color: #02BA0C;border-bottom: 1px solid #02BA0C;position:relative;\" onMouseOver=\"showAd(this, " + parts[1] + ")\">" + m[mm] + "</span>");
                }
            }
        }
        
    }
    context.innerHTML += "<div id=\"adCont\" style=\"display:none;position:absolute;\">" + 
    "<table width=16 border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
      "<tr>" +
        "<td width=\"3\"><img src=\"images/contextAds/ads_tl.gif\" width=\"3\" height=\"30\"></td>" +
        "<td width=100% background=\"images/contextAds/ads_bg_t.gif\" style=\"padding-left:10px;font-family:verdana;font-size:10px;font-weight:bold;color:#7E7E7E;\">Sponzorirani link</td>" +
        "<td width=\"3\"><img src=\"images/contextAds/ads_tr.gif\" width=\"3\" height=\"30\"></td>" +
      "</tr>" +
      "<tr>" +
        "<td colspan=\"3\" style=\"border-left:1px solid #CECECE; border-right:1px solid #CECECE; background-color:#F5F5F5;padding:10px 10px;\" valign=top id=\"adText\">&nbsp;</td>" +
      "</tr>" +
      "<tr>" +
        "<td><img src=\"images/contextAds/ads_bl.gif\" width=\"3\" height=\"3\"></td>" +
        "<td style=\"border-bottom:1px solid #CECECE;background-color:#F5F5F5;\"><img src=\"images/contextAds/spacer.gif\"></td>" +
        "<td><img src=\"images/contextAds/ads_br.gif\" width=\"3\" height=\"3\"></td>" +
      "</tr>" +
    "</table>" +

        "</div><div id=\"adContOver\" style=\"display:none;position:absolute;\" onMouseOut=\"hideAd()\"></div>";
}


function hideAd()
{
    showing=null;
    var adC = document.getElementById("adCont");
    var adCO = document.getElementById("adContOver");
    adCO.style.display = adC.style.display='none';
}

var showing;
function showAd(ad, id)
{

if(showing != ad)
{
    
    showing = ad;
    var adCT = document.getElementById("contextAds");
    var adC = document.getElementById("adCont");
    var adCO = document.getElementById("adContOver");
    adCO.style.display = adC.style.display = 'none';
    //adCO.style.left = adC.style.left = ad.offsetLeft;
    //adCO.style.top = adC.style.top = ad.offsetTop;
    
    
    
    opacity("adCont", 1, 0, 1);
    
    setTimeout("showAd2(" + id + ")",500); 
    }
}

function showAd2(id)
{
    AjaxRequest("showAd", id, "showAd3");
}

function showAd3(data)
{
    data = unescape(data);
    var tttt = data.split("*");
    
    //id*title*text(#imgonly#)*image*clickTag*dimenstions
    var adC = document.getElementById("adCont");
    var adCO = document.getElementById("adContOver");
    var adT = document.getElementById("adText");
    adCO.style.display = adC.style.display = '';
    
    if(tttt[2]=="image")
    {
        adT.innerHTML = "<img src=\"" + tttt[3] + "\">";
    }
    else if(tttt[2]=="flash")
    {
        html = "";
        
        var dim = tttt[5].split('x');
        html += "<OBJECT WIDTH=\"" + dim[0] + "\" HEIGHT=\"" + dim[1] + "\"  TYPE=\"application/x-shockwave-flash\" CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\">";
        html += "<PARAM NAME=\"movie\" VALUE=\"" + tttt[3] + "\" />";
        if(tttt[4] != "-")
                html += "<PARAM NAME=\"flashVars\" VALUE=\"" + tttt[4] + "=ads/click.aspx%3fbanner%3d" + tttt[0] + "\" />";

        html += "<EMBED WIDTH=\"" + dim[0] + "\" HEIGHT=\"" + dim[1] + "\" TYPE=\"application/x-shockwave-flash\" SRC=\"" + tttt[3] + "\" ";
        if (tttt[4] != "-")
                html += "FLASHVARS=\"" + tttt[4] + "=ads/click.aspx%3fbanner%3d" + tttt[0] + "\"";
        html += "></EMBED>";
        html += "</OBJECT>";
        
        
        adT.innerHTML=html;
    }
    else
    {
        //300x120 div
        html = "<div style=\"width:278px;\"><div style=\"font-weight:bold;padding-bottom:3px;\">" + tttt[1] + "</div>";
        if(tttt[3] != "")
            html += "<img src=\"" + tttt[3] + "\" align=left style=\"margin-right:3px;\">";
        html += tttt[2] + "</div>";
        
        adT.innerHTML=html;
    }
    
    
    adCO.innerHTML = "<a href=ads/click.aspx?banner=" + tttt[0] + " target=_blank><img border=0 src=images/contextAds/spacer.gif width=" + adC.offsetWidth + " height=" + adC.offsetHeight + "></a>";
    
    adCO.style.top = adC.style.top = (showing.offsetTop - adC.offsetHeight - 5) + "px";
    adCO.style.left = adC.style.left = (showing.offsetLeft + showing.offsetWidth / 2) + "px";

    opacity("adCont", 0, 100, 500);
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

if (!Array.prototype.indexOf){  Array.prototype.indexOf = function(elt /*, from*/)  {    var len = this.length;    var from = Number(arguments[1]) || 0;    from = (from < 0)         ? Math.ceil(from)         : Math.floor(from);    if (from < 0)      from += len;    for (; from < len; from++)    {      if (from in this &&          this[from] === elt)        return from;    }    return -1;  };}

AjaxRequest("getAds", escape(document.getElementById("contextAds").innerHTML), "SetAds");

