function ScaleDivs()
{
	hh=parseInt(document.getElementById('inhoud_inner_bottom').offsetTop);
	if (hh<100){hh=parseInt(document.getElementById('inhoud_inner').scrollHeight);}

	document.getElementById('inhoud').style.height=Math.max(parseInt(document.getElementById('hoofdmenu_bottom').offsetTop)-parseInt(document.getElementById('zoeken').offsetHeight)-parseInt(document.getElementById('onder_zoeken').offsetHeight),hh)+'px';
	document.getElementById('hoofdmenu').style.height=(parseInt(document.getElementById('inhoud').offsetHeight)+parseInt(document.getElementById('zoeken').offsetHeight)+parseInt(document.getElementById('menu').offsetHeight)+25-parseInt(document.getElementById('hoofdmenu_bottom').offsetHeight))+'px';
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(ScaleDivs);



// fase
vorigfasenummer=0;

function verander_fase(fasenummer)
{
document.getElementById("inhoud_"+vorigfasenummer).style.display='none';
document.getElementById("inhoud_"+fasenummer).style.display='block';
vorigfasenummer=fasenummer;
}

vorigsubfasenummer=11;

function verander_subfase(subfasenummer)
{
document.getElementById("inhoud_"+vorigsubfasenummer).style.display='none';
document.getElementById("inhoud_"+subfasenummer).style.display='block';
vorigsubfasenummer=subfasenummer;
  ScaleDivs();
}
// einde fase

function euro_format(v)
{
  var v_str=Math.floor(v)+'.';
  v_rem=Math.round(100*(v-Math.floor(v)));
  if (v_rem=0){return v_str+'00';}
  else if(v_rem<10){return v_str+'0'+v_rem;}
  else {return v_str+v_rem;}
}


function bereken_voordeel() 
{

	var aantal_lampen = document.getElementById('aantal_lampen').value;
	aantal_lampen=Math.abs(parseInt(aantal_lampen));
	
	if (!isFinite(aantal_lampen)){aantal_lampen=5;}
	document.getElementById('aantal_lampen').value=aantal_lampen;
	var aantal_uren_per_dag = document.getElementById('aantal_branduren_per_dag').value; //aantal uren per dag
	var aantal_dagen = 5*365; //aantal jaren*365
	var wattage = document.getElementById('input_wattage').value;

	var vergelijkbaar_wattage=Math.round(wattage*(100-80)/100);

	// Aantal lampen * (Watt * Aantal uren/dag * dagen  * prijs/kwh)
	var verbruik_gloei =  aantal_lampen * (wattage * aantal_uren_per_dag * aantal_dagen * 0.21/1000);
	var verbruik_led =  aantal_lampen * (vergelijkbaar_wattage * aantal_uren_per_dag * aantal_dagen * 0.21/1000);

	//Aantal nieuwe lampen * prijs per lamp 
	var aanschafkosten_gloei =  aantal_lampen * Math.ceil(((aantal_uren_per_dag * aantal_dagen)/1000)) * 0.50;
	var aanschafkosten_led =  aantal_lampen * Math.ceil(((aantal_uren_per_dag * aantal_dagen)/50000)) * 20;

	//overall kosten
	var totale_kosten = Math.round(((aanschafkosten_gloei+verbruik_gloei)-(verbruik_led+aanschafkosten_led))* 100)/100;
	var jaarlijkse_kosten=Math.round(100*totale_kosten*365/aantal_dagen)/100;

	//overall kosten
	var uitstoot_gloei = Math.round(422.5*verbruik_gloei* 100/1000)/100;
	var uitstoot_led = Math.round(422.5*verbruik_led* 100/1000)/100;



	//zet output velden
	document.getElementById("besparing").innerHTML= "&euro; "+euro_format(totale_kosten);
	document.getElementById("besparing_per_jaar").innerHTML= "&euro; "+euro_format(jaarlijkse_kosten);
	document.getElementById("wattage").innerHTML= wattage;
	document.getElementById("vergelijkbaar_wattage").innerHTML= vergelijkbaar_wattage;
	document.getElementById("aanschafkosten_gloei").innerHTML= "&euro; "+euro_format(aanschafkosten_gloei);
	document.getElementById("aanschafkosten_led").innerHTML= "&euro; "+euro_format(aanschafkosten_led);
	document.getElementById("verbruik_gloei").innerHTML= "&euro; "+euro_format(verbruik_gloei);
	document.getElementById("verbruik_led").innerHTML= "&euro; "+euro_format(verbruik_led);
	document.getElementById("totale_kosten_gloei").innerHTML= "&euro; "+euro_format(aanschafkosten_gloei+verbruik_gloei);
	document.getElementById("totale_kosten_led").innerHTML= "&euro; "+euro_format(aanschafkosten_led+verbruik_led);
	document.getElementById("uitstoot_gloei").innerHTML= uitstoot_gloei;
	document.getElementById("uitstoot_led").innerHTML= uitstoot_led;
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var WindowObjectReference = null; // global variable
var PreviousUrl=null; /* global variable which will store the url currently in the secondary window */

function openPopup(strUrl)
{
  if(WindowObjectReference == null || WindowObjectReference.closed)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
         "resizable=no,scrollbars=bo,status=no,width=400,height=400");
   WindowObjectReference.focus();
  }
  else
  if(PreviousUrl != strUrl)
  {
   WindowObjectReference = window.open(strUrl, "SingleSecondaryWindowName",
      "resizable=no,scrollbars=bo,status=no,width=400,height=400");
    /* if the resource to load is different,
       then we load it in the already opened secondary window and then
       we bring such window back on top/in front of its parent window. */
   WindowObjectReference.focus();
  }
  else
  {
    WindowObjectReference.focus();
  };
  PreviousUrl = strUrl;
  /* explanation: we store the current url in order to compare url
     in the event of another call of this function. */
}

