var floatekk = false;
var floateidkk = '';

function showkk(){
	if(floate == true){
		clearTimeout(floateidkk);
		floatekk=false;
		}
	var oDIV = document.getElementById('calculator');
	oDIV.style.height = oDIV.style.height || '0px';
	var currh = parseInt(oDIV.style.height);
	if(currh>0){
		floatekk = true;
		floateupkk();
		}
	else{
		oDIV.style.display = 'block';
		floate=true;
		floatedownkk();
		}
	}
function floateupkk(){
	var oDIV = document.getElementById('calculator');
	var currh = parseInt(oDIV.style.height);
	var marg = parseInt(oDIV.style.marginTop);
	if(currh>0){
		currh-=5;
		marg -= 1;
		oDIV.style.height = currh+"px";
		oDIV.style.marginTop = marg+"px";
		floateidkk=setTimeout("floateupkk()",0);
		}
	else{
		floatekk=false;
		oDIV.style.display = 'none';
		}
	}
function floatedownkk(){
	var oDIV = document.getElementById('calculator');
	var currh = parseInt(oDIV.style.height);
	var marg = parseInt(oDIV.style.marginTop) || 0;
	if(currh<45){
		currh+=5;
		marg += 1;
		oDIV.style.height = currh+"px";
		oDIV.style.marginTop = marg+"px";
		floateidkk=setTimeout("floatedownkk()",0);
		}
	else{
		floatekk=false;
		}
	}
function setcalceavents(){
 	var el_arr = document.getElementsByName('calculate');
	for(var i=0;i<el_arr.length;i++){
		el_arr[i].onkeyup = calculate;
		el_arr[i].onchange = calculate;
		el_arr[i].onclick = calculate;
		}
	calc();
	}
function calculate(){
	var reg_num = /^\d+(.|,){1}\d+$/;
	var reg_int = /^\d+$/;
	if(reg_num.test(this.value) || reg_int.test(this.value)){
  		this.style.background = '#FFF';
  		if(this.id == 'kkfirstp'){
  			document.getElementById('kkfirst').value = Math.round(this.value/100 * document.getElementById('kkwhole').value);
  			}
  		calc();
  		}
  	else
  		this.style.background = '#E50304';
	}
function calc(){
	var princ = document.getElementById('kkwhole').value;
	var down = document.getElementById('kkfirst').value
	var term  = document.getElementById('kkyears').value*12;
	var intr   = document.getElementById('kkrate').value / 1200;
	document.getElementById('kkmonth').value = Math.round((princ - down) * intr / (1 - (Math.pow(1/(1 + intr), term))));
	}