
// Copyright e-Business Systems Limited.    www.e-businesssystems.co.uk
function Valid_textbox(fname,fdescription){
	var test;
	var result;
	
	test = /[a-zA-Z]/;
	result = test.exec(fname);
	if ((result == null)){
		window.alert("Please fill in the '" + fdescription + "' field.");
		 
		return false;
	}
	return true;
}

function Valid_field(fname,fdescription,required,fmin,fmax,ftype){
	if (required == null) required = "";
	if ((required!="required")&&(fname.length==0)) return true;
	if ((fmin == 0) && (fname.length == 0)) return true;
	if ((required=="required")&&(fname.length==0)){
		window.alert("Please fill in the '" + fdescription + "' field."); 
		return false;
	}	
	if ((fmin!=null)&&(fmin!="")){
		if (fname.length < fmin) {
			window.alert(fdescription + " must be at least " + fmin + " characters long."); 
			return false;
		}
	}
	if ((fmax!=null)&&(fmax!="")){
		if (fname.length > fmax){
			window.alert(fdescription + " must not be more than " + fmax + " characters long.");
			return false;
		}
	}
	if ((ftype!=null)&&(ftype!="")){
		if (ftype == "num"){
			var numeric = /\d+/;
			var result = numeric.exec(fname);
			if (result == null){
				window.alert(fdescription + " must be a number.");
				return false;
			}
			if (result[0]!= fname){
				window.alert(fdescription + " must be a number.");
				return false;
			}	
		}
	}
	
	if ((ftype!=null)&&(ftype!="")){
		if (ftype.indexOf("curr")>=0){
			var curr1,result;
			if (ftype == "currnp") curr1 = /\d{1,6}\.\d{2}/;
			if (ftype == "currp") curr1 = /£\d{1,6}\.\d{2}/;
			if (ftype == "currpo") curr1 = /£?\d{1,6}\.\d{2}/;
			result = curr1.exec(fname);
			if ((result != null)&&(result[0]== fname))return true;
			if (ftype == "currnp") curr1 = /\d{1,3}\,\d{3}\.\d{2}/;
			if (ftype == "currp") curr1 = /£\d{1,3}\,\d{3}\.\d{2}/;
			if (ftype == "currpo") curr1 = /£?\d{1,3}\,\d{3}\.\d{2}/;
			result = curr1.exec(fname);
			if ((result != null)&&(result[0]== fname))return true;
			return false;	
		}
	}
	return true;
}

function Valid_range(fname,fdescription,fmin_range,fmax_range){
	if (fname=="") return true;
	fname = parseFloat(fname);
	if (fmin_range==null) fmin_range="";
	if ((fmin_range!="")&&(fname < fmin_range)){
		window.alert(fdescription + " must not be less than " + fmin_range);
		return false;
	}
	if (fmax_range==null) fmax_range="";
	if ((fmax_range!="")&&(fname > fmax_range)){
		window.alert(fdescription + " must not be greater than " + fmax_range);
		return false;
	}
	return true;	
}



