﻿function limitedString(control,strValidChars) {
	//  test control value consists of valid characters
	var strString = control.value;
	var strResult = "";
	var strChar;

	for (var i=0; i<strString.length; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) >= 0) {
			strResult = strResult + strChar;
		}
	}
	control.value = strResult;
}


function numericOnly(control) {
	limitedString(control,"0123456789.-");
}

function cardinalOnly(control) {
	limitedString(control,"0123456789");
}

function maxLimit(control,upperLimit) {
	//test control value is within acceptable limit
	var currentValue = parseInt(control.value);
	if (currentValue > upperLimit) {
		control.value = upperLimit;
		alert('There is insufficient stock.\nThe quantity has been reduced.');
	}
}
	

