/*
// configuration
var iMinHeight = 333; // Minimale Hoehe ohne Inhalt.
var sBKPDomain = 'https://portal.nord-energie.de'; // Url zum Iframe BKP.
var sWebsiteIframeBKPId = 'siv_bkp'; // Id zum Iframe BKP.
var sNKPDomain = 'https://portal.nord-energie.de'; // Url zum Iframe NKP.
var sWebsiteIframeNKPId = 'siv_zmo'; // Id zum Iframe NKP.

// function
window.onload = function() {
	var bBKP = ( 0 < jQuery('#'+sWebsiteIframeBKPId).length );
	var bZMO = ( 0 < jQuery('#'+sWebsiteIframeNKPId).length );

	if ( bBKP ) {
		jQuery('#'+sWebsiteIframeBKPId).css('min-height', iMinHeight+'px');
		function receiveSizeBKP(e) {
			var data = JSON.parse(e.data);
			if ( e.origin === sBKPDomain ) {
				jQuery('#'+sWebsiteIframeBKPId).attr('height', data);
			}
			var iIframeHeight = jQuery('#'+sWebsiteIframeBKPId).height();
			if ( iIframeHeight <= data ) {
				jQuery('#'+sWebsiteIframeBKPId).height(data);
			}
		}
		if ( window.addEventListener ) {
			window.addEventListener('message', receiveSizeBKP, false);
		}
		else {
			window.attachEvent('onmessage', receiveSizeBKP);
		}
	}

	if ( bZMO ) {
		jQuery('#'+sWebsiteIframeNKPId).css('min-height', iMinHeight+'px');
		function receiveSizeZMO(e) {
			var data = JSON.parse(e.data) - 50;
			if ( e.origin === sNKPDomain ) {
				jQuery('#'+sWebsiteIframeNKPId).attr('height', data);
			}
			var iIframeHeight = jQuery('#'+sWebsiteIframeNKPId).height();
			if ( iIframeHeight <= data ) {
				jQuery('#'+sWebsiteIframeNKPId).height(data);
			}
		}
		if ( window.addEventListener ) {
			window.addEventListener('message', receiveSizeZMO, false);
		}
		else {
			window.attachEvent('onmessage', receiveSizeZMO);
		}
	}
}
*/


window.onload = function() {
	function receiveSize(e) {
		if (e.origin === "https://likra.de/") {
			var data = JSON.parse(e.data);
			var iframeSelector = '';
			
			for (var key in data) {
			    if (data.hasOwnProperty(key)) {
			        //console.log(key + " -> " + data[key]);
			        
			        switch(key) {
				        case 'nkp_plugin':
				        	iframeSelector = '#siv_nkp';
				        	break;
				        case 'bkp_plugin':
				        	iframeSelector = '#siv_bkp';
				        	break;
				        default:
				        	iframeSelector = '';
			        		break;
			        }
			        
			        if(0 < iframeSelector.length) {
						jQuery(iframeSelector).attr('height', data[key]);
						jQuery(iframeSelector).height(data[key]);
			        }
			    }
			}
		} else if (e.origin === "https://portal.likra.de") {
			var data = JSON.parse(e.data);
			jQuery("#siv_zmo").attr('height', data - 50);
			jQuery("#siv_zmo").height(data - 50);
			
			jQuery("#siv_bkp").attr('height', data);
			jQuery("#siv_bkp").height(data);
		}
	}
	if (window.addEventListener){
		window.addEventListener("message", receiveSize, false);
	} else {
		window.attachEvent("onmessage", receiveSize);
	}
}