var valid = '0123456789.'; // define valid characters
var oldvalue = "";

function snmod(di,bas) {
	return Number(Math.round(di - (Math.floor(di/bas)*bas)));
}


function isValid(string,allowed) {
    for (var i=0; i < string.length; i++) {
        if (allowed.indexOf(string.charAt(i)) == -1) {
            return false;
        }
    }
    return true;
}



function calForint(val) {

    if (isValid(val,valid)) {
		
		oldvalue = val;
		
		if (Number(val)) {
			document.getElementById("calto").style.color = "";
		} else {
			document.getElementById("calto").style.color = "#f00";
			document.getElementById("calto").value = "####";
		}
		
		val = Math.round(Number(val));
		
		if (Number(val) > 0) {
			if (snmod(val,5) < 3) {
				document.getElementById("calto").value = val-snmod(val,5);
			} else {
				document.getElementById("calto").value = val+5-snmod(val,5);
			}
			
		}
	
	} else {
		document.getElementById("calfrom").value = oldvalue;		
	}
}