// charcode constants

var code_a=65;
var code_b=66;
var code_c=67;
var code_d=68;
var code_e=69;
var code_f=70;
var code_g=71;
var code_h=72;
var code_i=73;
var code_j=74;
var code_k=75;
var code_l=76;
var code_m=77;
var code_n=78;
var code_o=79;
var code_p=80;
var code_q=81;
var code_r=82;
var code_s=83;
var code_t=84;
var code_u=85;
var code_v=86;
var code_w=87;
var code_x=88;
var code_y=89;
var code_z=90;


max_flow_rate = 300;




// pseudoRound takes a number and rounds it to the given number of decimal places

function pseudoRound (value, decimals) {
	value=value*Math.pow(10,decimals);
	value=Math.round(value);
	value=value/Math.pow(10,decimals);
	
	return value;
}

//

function lbsToKg (pounds) {
	return Math.round (pounds/2.2);
}

// 

function disableItem(item) {
	item.disabled=true;
	if (!(item.className.match(/disabled/g))) {
		item.className=item.className+="disabled";
	}
	item.checked=false;
}

function disableLabel(item) {
	if (!(item.className.match(/disabled/g))) {
		item.className=item.className+="disabled";
	}
}

// 

function enableItem(item) {
	item.disabled=false;
	item.className=item.className.replace(/disabled/g, "");
}

function enableLabel (item) {
	item.className=item.className.replace(/disabled/g, "");
}


// processKeystroke accepts a restriction string and, if the keystroke the description of the restriction string, returns true
// if the keystroke doesn't match, the function calls processCharCode to see if it is a legitimate shortcut and the function
// returns false to prevent the keystroke from being entered into a field


function processKeystroke(restriction,theevent) {
	evt = (theevent) ? theevent : event;
	if (evt.metaKey) {  return true; }
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	var keyCode = evt.keyCode;
	if ((restriction=="integer") && (((charCode >= 48) && (charCode <= 57)) || (charCode <= 31))) {
			return true;
	}
	else if ((restriction=="number") && (((charCode >= 48) && (charCode <= 57)) || (charCode <= 31) || (charCode==46))) {
		return true;
	}
	else if (restriction=="all") {
		return true;
	}
	else if (restriction=="stray"){
		processKey (keyCode);
		return true;
	}	
	else {
		return false;
	}
}

function validate_feedback() {
	var email = document.getElementById("your_email");
	var atposition = email.value.indexOf("@");
	var lastdotposition = email.value.indexOf(".");
	
	if (atposition<1||lastdotposition<1||lastdotposition-atposition<2) {
		alert("You must enter a valid email address.");
		email.focus();
		return false;
	}
	else {return true;}
}