// Some generic functions for checking fields

function checkRequired(thisField)
// This function will check to see if a field is empty.  If it
// is false will be returned.  Otherwise true will be returned.
	{
	thisField = removeSpaces(thisField);
	if (thisField == "")
	   { return false; }
	return true;
	}

function checkLength(thisField, maxl)
// This function will check the length of the field passed in.
// If it exceeds the max length passed, the false will be returned.
	{   
	ll = thisField.length;
	if (ll > maxl)
	   { return false; }
	return true;
	}
	
function removeSpaces(somestr)
// remove all the spaces in case the value is just spaces
	{somestr = somestr.replace(/[ ]/g, "");
	return somestr;
	}
	
function checkPassword(thisPassword)
// This function will make sure only letters and numbers are in the field
	{
	ll = thisPassword.length;
	for (ii=0; ii < ll; ii++)
		{
		 lcode = thisPassword.charCodeAt(ii);
		 if (lcode < 48 || lcode > 122 )
		     return false;
		 if (lcode > 57 && lcode < 65 )
		     return false;
		 if (lcode > 90 && lcode < 97 )
		     return false;
		}
	return true;
	}
	
function checkNumber(numval, maxval, dec, neg)
// This functions will take a value passed in and check to see if
// it is numeric.  It will also do other checks:
//	maxval: the maximum the value is allowed to be
//			smallint: 32,767
//			integer: 2,147,483,647
//	dec: The number of decimal places allowed
//	neg: Y negative allowed, N negative not allowed
//
//	returns: 0 - Everything is OK
//			-1 - Not a number
//		    -2 - Out of range
//		    -3 - Too many decimal places
	{
	if (numval == "") { return 0 }
	if (neg == "Y")
	   { minval = maxval * -1; }
	else
	   { minval = 0; }
	if (numval == "")
	   { numval = 0; }
	else
	   { if (isNaN(numval) == true) 
		   { return -1; }
		 if (numval > maxval || numval < minval)
		   { return -2; }	
		}
	 var cc = numval.indexOf(".");
	 if (cc > -1)
	    { chk = numval.slice(cc + 1);
		  if (chk.length > dec )
		    { return -3;}	
		}
	return 0;
	}
