EnergyCalculator = Class.create({

    initialize: function(baseUrl) {
        this.baseUrl = baseUrl;
        this.activeDomain = null;
    },

    start: function() {
        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];
        }
        iframeSource = 'http://energierechner.' + this.getTopLevelDomain(this.baseUrl) + 'cgi-bin/calc.asp';
        window.frames['energierechnerIframe'].location = iframeSource;
    },

    close: function() {
        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 = (energyIframe.contentWindow.document.body.scrollHeight + 30) + "px";
}