EnergyCalculator = Class.create(DivPopup, {

    initialize: function($super, baseUrl) {
        $super(baseUrl);
        this.activeDomain = null;
    },

    startEnergyCalculation: function() {

        this.showDialog($('energierechnerStartDialog'));

        if (! location.hostname.match(/^localhost/)) {
            //korrekte Domain retten
            this.activeDomain = document.domain;

            host=location.hostname.split('.');
            document.domain = host[host.length - 2] + '.' + host[host.length - 1];
        }
    },

    showEnergyCalculatorDialog: function() {
        iframeSource = 'http://energierechner.' + this.getTopLevelDomain(this.baseUrl) + 'cgi-bin/calc.asp';
        window.frames['energierechnerIframe'].location = iframeSource;
        this.showDialog($('energierechnerRunDialog'));
    },

    closeEnergyCalculator: function() {

        this.close();

        window.frames['energierechnerIframe'].location = 'about:blank';
        energyIframe = $('energierechnerIframe');
        energyIframe.style.height = '0px';

        window.location.href = 'http://' + this.activeDomain + window.location.pathname;
    },

    getTopLevelDomain: function(url) {
        var domain = url.toString().replace(/^http:\/\/(www\.){0,1}/, '');
        var domainParts = domain.split('.');
        topLevelDomain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
        return topLevelDomain;
    }
});

function onBnuIframeLoaded() {
    var energyIframe = document.getElementById('energierechnerIframe');
    energyIframe.style.height = '0px';
    energyIframe.style.height = (energyIframe.contentWindow.document.body.scrollHeight + 30) + "px";

    resizePageInactive(energyIframe.contentWindow.document.body.scrollHeight + 200);

    scrollUp();
}