// JavaScript function library
// Include on all pages with order forms

// Validate quantity on Order.asp, WebSpecials.asp, product pages, vf() below
function vq(field) {
	if (!(/^\s*\d*\s*$/.test(field.value))) {
		alert('Quantities can only contain the digits 0-9.');
		field.focus();
		return false;
	} else return true;
}

// Validate all quantity fields on oder form.
// Used by Order.asp, WebSpecials.asp, product pages, sb2() below.
function vf(f) {
	var value_prefix = f.prefix.value;
	for (var i=0; i<f.elements.length; i++) {
		var ctl = f.elements[i];
		if ((ctl.type == 'text') && (ctl.name.indexOf(value_prefix) == 0) && !vq(ctl)) return false;
	}
	return true;
}

// Validates and submits order form
// Called from: Nav buttons and links on Order Forms:
//   formsDirectory.asp, formsFooter.asp, Order.asp, WebSpecials.asp, product pages
// Returns false to prevent hyperlink activation

function sb2(url) {
	var f = document.forms.orderForm;
	if (vf(f)) {
		f.destination.value = url;		// This will be a fully-qualified URL
		f.submit();
	}
	return false;
}

