function _$( id ) {
	return document.getElementById( id ) ? document.getElementById( id ) : null; 
}

function disable( id ) {
	
	if ( _$(id).disabled ) {
		_$(id).disabled = false;
	} else {
		_$(id).value = '';
		_$(id).disabled = true;
	}

}

var hidden = true;
function calculate( obj ) {

	var result = 0;

	var a = parseInt( obj.a.value );
	if (isNaN(a)) { 
		_$('calc-answer').style.display = 'none';
		if (hidden) {
			alert( calc_error ); 
		}
		hidden = true;
		return false; 
	}
	var b = parseInt( obj.b.value );
	if (isNaN(b)) { b = 0; }
	var c = parseInt( obj.c.value );
	if (isNaN(c)) { c = 0; }
	var d = parseInt( obj.d.value );
	if (isNaN(d)) { d = 0; }
	var e = parseInt( obj.e.value );
	if (isNaN(e)) { e = 0; }
	var f = parseInt( obj.f.value );
	if (isNaN(f)) { f = 0; }
	var g = parseInt( obj.g.value );
	if (isNaN(g)) { g = 0; }
	var h = parseInt( obj.h.value );
	if (isNaN(h)) { h = 0; }

	result += 11*(a-b) + 16*b + c*5 + d*4 + e*f*5 + g*30 + h;

	if (isNaN(result)) { 
		_$('calc-answer').style.display = 'none';
		hidden = true;
		alert("Error");
	} else {
		_$('calc_min').innerHTML = Math.round(result*0.95);
		_$('calc_max').innerHTML = Math.round(result*1.05);
		_$('calc-answer').style.display = 'block';
		hidden = false;
	}
	return false;
}

function checkInt( obj ) {
	
	var val = parseInt( obj.value );
	if (isNaN(val)) {
		obj.value = '';
	}
	
	if (!hidden) {
		calculate(_$('calc-form'));
	}
	
}

