function checkform(thisform,action){

	switch(action){
		case 'add': return addcheck(thisform); break;
		case 'recalculate': return recalculatecheck(thisform); break;
		default: { alert('Form type not found'); return false;}
	}
}

function addcheck(thisform){
	var invalid=/[^0-9]/;
	if(thisform.Quantity.value.search(invalid) != -1 || thisform.Quantity.value == 0){
		thisform.Quantity.focus();
		alert('The quantity must be a number.');
		return false;
	}
    return true;
} 
function recalculatecheck(thisform){
	var invalid=/[^0-9]/;	
	for(i=1;i<=thisform.bagitems.value;i++){
		var thisbagitem=eval("thisform.bagitem"+i);
		if(thisbagitem.value.search(invalid) != -1){
			thisbagitem.focus();
			alert('Please check the values of the quantity fields. There are invalid entries.');
			return false;
		}
	}
    return true;
} 

