// 2008 Ruby Diversified Industries
// 

//check to see if value is numerical
function check(field)
{
    	var number = field.value;
	if (((number / number) != 1) && (number != 0)) {
		alert('Please enter only numbers here.');
		field.focus();
		return;
	}
}

// calcuate ramp incline or length based on form input
function calculate(form)
{

var rise = form.rise.value;
var angle = form.angle.value;
var length = form.length.value;

if (rise == 0) {
alert('Please enter a value for rise.');
return;
}

if ((angle == 0) && (length == 0)) {
alert('Please enter a value for either angle or length.');
return;
}

if ((angle > 0) && (length > 0)) {
alert('You have values in both angle and length.');
return;
}

if (angle > 0) {	// calculate length
	length = rise / Math.sin(angle * 3.142 / 180);
	length = length / 12;
	length = Math.round(length*10)/10;
	form.length.value = length;
	return;
}

if (length > 0) {	//calculate angle
	angle = Math.asin(rise/12/length);
	angle = angle * 180 / 3.142;
	angle = Math.round(angle*10)/10;
	form.angle.value = angle;
	return;
}
}	// end function


// calculate ramp length to clear 2 stairs
function clear2stairs(form)
{

var a = parseFloat(form.a.value);
var b = parseFloat(form.b.value);
var c = parseFloat(form.c.value);

	var d = (a+c) / a * b;
	d = d*d + (a+c) * (a+c);
	d = Math.sqrt(d);
	d = ( d +3 )/ 12;		// convert to ft, lose 3 inches for ramp lip
	d = Math.round(d*10)/10;	// round up to 1 decimal place
	form.d.value = d;
	return;

}	// end function

// calculate ramp length to clear 3 stairs
function clear3stairs(form)
{

var a = parseFloat(form.a.value);
var b = parseFloat(form.b.value);
var c = parseFloat(form.c.value);
var d = parseFloat(form.d.value);
var e = parseFloat(form.e.value);

	var L = (a+c+e)/a * b;
	var L1 = (a+c+e)/(a+c) * (b+d);
	if (L < L1) { L = L1;}
	L = L * L + (a+c+e) * (a+c+e);
	L = Math.sqrt(L);
	L = ( L +3 )/ 12;		// convert to ft, lose 3 inches for ramp lip
	L = Math.round(L*10)/10;	// round up to 1 decimal place
	form.L.value = L;
	return;

}	// end function
