connect(window, 'onload', function(e){

	  connect('income-1', 'onkeyup', updateQuantity);
	  connect('income-2', 'onkeyup', updateQuantity);
	  updateQuantity();
	}
);


function toUnit(f, s){
  var ret = f(s.replace(/[^\d|.]/g, ''), 10);
  if(isNaN(ret)){
    ret = 0;
  }
  return ret;
}
toInt = partial(toUnit, parseInt);
toFloat = partial(toUnit, parseFloat)


function formatPrice(i){ 
        var s = new String(parseInt(i, 10));
	var a = [];
	while(s.length > 3)
	{
		a.unshift(s.substr(s.length-3));
		s = s.substr(0,s.length-3);
	}
	if(s.length > 0) { a.unshift(s); }
	return "€" + a.join(',');
}


function updateQuantity(e){

  var low = 4.5 * (toInt($('income-1').value) + toInt($('income-2').value));
  if(low == 0)
    { // hideElement('estimate');
    }
  else{
  //showElement('estimate');
  //replaceChildNodes('result-1', formatPrice(low));
  replaceChildNodes('result-2', formatPrice(6 * (toInt($('income-1').value) + toInt($('income-2').value))));
  }

}

