// default.js

function trim(str) {
	return trimmed = str.replace(/^\s+|\s+$/g, '');
}

function add(){
	
	if(trim(document.getElementById("motorwaysdualcarriageways").value) == ""){document.getElementById("motorwaysdualcarriageways").value ='0';}
	if(trim(document.getElementById("towncityroad").value) == ""){document.getElementById("towncityroad").value ='0';}
	if(trim(document.getElementById("ruralcountryroads").value) == ""){document.getElementById("ruralcountryroads").value ='0';}
	
	var motorwaysdualcarriageways = parseFloat(document.getElementById("motorwaysdualcarriageways").value);
	var towncityroad = parseFloat(document.getElementById("towncityroad").value);
	var ruralcountryroads = parseFloat(document.getElementById("ruralcountryroads").value);
	var total = motorwaysdualcarriageways + towncityroad + ruralcountryroads;
		
	if(total == 100){
		document.getElementById("totaltimemsg").style.visibility ='hidden';
	}else{
		document.getElementById("totaltimemsg").style.visibility ='visible';
	}
	
	document.getElementById("totaltimedrivingmustequal100").innerHTML = total + "%";
}
