//see Javascript: the Complete Reference p 496


function isNumeric(field, event)
{
	var key, keychar;
	if (window.event)
		key = window.event.keyCode;
	else if (event)
		key = event.which;
	else
		return true;

	keychar = String.fromCharCode(key);

	//check for special characters like backspace, then check for numbers
	if ( (key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
		return true;
	else if (("0123456789.").indexOf(keychar) > -1)
	{
		window.status = "";
		return true;
	}
	else
	{
		window.status = "Digits only please";
		return false;
	}
}//isNumeric()

//scan through all form fields with name=fieldInput in form formName.
//and add up their total value.
//store result in form field totalField
//return numPrints
//args: formName duh
//		fieldInput: one or more fields with same name = eg 'qty'
//		fieldTotal: the name of the field where total will be stored
function calcNumPrints(formName, fieldInput, fieldTotal)
{
	var numPrints;	//no of prints ordered by user
	var numQtyFields;	//no. of fields in form with name = fieldName
	var i;				//index to loop
	var numericValue;
	var qtyFields;

	numPrints = 0;	//initialize. Will store calculated total.

	qtyFields = document.getElementsByName(fieldInput); //a NodeList, which can be treated like an Array (see Rhino book p 773)
	numQtyFields = qtyFields.length;
	if (DEBUG) alert("numQtyFields=" + numQtyFields);

	for (i = 0; i <numQtyFields ; i++)
	{
		//I tested here for null and undefined, but they did not show up
		numericValue = Number(qtyFields[i].value);
		numericValue = numericValue - 0;	//convert from Number object to number simple type. See Rhino p 165
		numPrints += numericValue;
	}//for
	return numPrints;
}//calcNumPrints()

//return totalCost based on orderQty 
function calcTotalCost(formName, totalField, orderQty, unitPrice)
{
	var totCost;
	totCost = orderQty * unitPrice;
	if (DEBUG) alert("totCost=" + totCost);
	if (totCost == 0)
	{
		totCost = null;
	}
	else if (totCost.toFixed)
	{
		totCost = "£" + totCost.toFixed(2);	//2 d.p.
	}
	else
		totCost = "£" + totCost;

	return totCost;
}//calcTotalCost()
