/**
* Handles chart changes during mouseover event in header quotebar.
*/
function showOverviewChart(id, isDelayed) {
    var chartHtml = '<img src="/cache/img/trendinvest-marketoverview' + id;

    chartHtml += '.png" border="0"/>';

    if (typeof isDelayed == 'undefined') isDelayed = true;

    chartHtml = '<span class="quotebarchart_' + (isDelayed ? 'delayed' : 'realtime') + '">' + (isDelayed ? '15 Min. delayed' : 'Realtime') + '</span><br/>' + chartHtml;

    return overlib(chartHtml, CSSCLASS, FGCLASS, 'overlibChartFgClass', BGCLASS, 'overlibChartBgClass', BGCOLOR, 'transparent');
}

/**
* Handles chart changes during mouseover event in marketoverview.
*/
function changeMarketOverviewChart(id, exchange) {
    var chartImg    = document.getElementById('marketOverviewChart');
    var chartLnk    = document.getElementById('marketOverviewChartLnk')
    var imgSrc      = '';

    imgSrc = '/cache/img/trendinvest-marketoverview' + id;

    // L&SAX
    if (id == 133962 && exchange == 22) {
        imgSrc += '-22';
    }

    imgSrc += '.png';
    chartImg.src = imgSrc;
    chartLnk.href = 'http://www.godmode-trader.de/front/index.php?p=detailchart&intv=86400&id=' + id;
}

/**
* Open a profichart in a new window.
*/
function openProfichart(instrumentId, configuration) {
    var windowOpenParams = 'width=750,height=640';

    if (instrumentId != null && typeof instrumentId != 'undefined') {
        window.open('http://profichart.trendinvest.net/chart/id/' + instrumentId, '_blank', windowOpenParams);
    } else if (configuration != null && configuration != 'undefined') {
        window.open('http://profichart.trendinvest.net/chart/' + configuration, '_blank', windowOpenParams);
    } else {
        window.open('http://profichart.trendinvest.net/', '_blank', windowOpenParams);
    }
    return false;
}

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
            curleft += obj.offsetLeft;
            if(!obj.offsetParent)
                break;

            obj = obj.offsetParent;
        }

    else if(obj.x)
        curleft += obj.x;

    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;

          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;

    return curtop;
}

function findPos(obj) {
   return {left:findPosX(obj),top:findPosY(obj)};
}

function adjustDeployedAd( identifier ) {
    if( identifier == 'background' ) {
        return false;
    }

    var placeholder = document.getElementById('adDeployPH_'+identifier);

    pos = findPos(placeholder)
    realItem = document.getElementById('adDeployReal_'+identifier)

    leftCorr = 0;
    realItem.style.zIndex = 10;

    if( identifier == 'sky' && abnSkyFound ) {
        leftCorr = -200;
        realItem.style.zIndex = 9;
    }

    // align banners to the right
    pos.left = placeholder.offsetWidth - 728 + pos.left;

    realItem.style.left = leftCorr + pos.left + 'px';
    realItem.style.top = pos.top+'px';
    realItem.style.display = 'block';

    realItem.style.position = 'absolute';
}
