//FUCTION CHECKS THAT VALUE IS DIGIT
// return shortened value if leading white space;
// return -1 = character is not a digit
// return origvalue
function isDigit(digit)
{
	//alert("in isDigit = "+digin);
	digin = new String(digit);
	len = digin.length;
	var hold;
	cnt = 0;
	var c;
	usehold = 0;
	while(cnt < len)
	{
		c = digin.charAt(cnt);
		if(usehold){ hold = hold+c; }
		if(cnt == 0)
		{
			if(c.match(/\s/))
			{
				//remove any leading white space
				c = digin.charAt(cnt);
				while(c.match(/\s/) && cnt < len){ c = digin.charAt(++cnt); }
				usehold = 1;
				hold = c;
			}
		}
		if(c.match(/\D/))
		{
			// character is not a digit
			//alert("leaving isDigit -1");
			return -1;
		}
		cnt++;
	}
	//alert("leaving isDigit");
	if(usehold) return hold;
	return digin;
}

//FUNCTION CHECKS THAT VALUE CONTAINS NON DIGITS
// return shortened value if leading white space;
// return value if ok
// return -1 = no chars found only digits
function containsNonDigits(word)
{
	//alert("in containsNonDigits = "+word);
	w = new String(word);
	//alert("w = "+w);
	var len = w.length;
	//alert("len = "+len);
	var hold;
	cnt = 0;
	usehold = 0;
	ok = 0;
	while(cnt < len)
	{
		c = w.charAt(cnt);
		//alert(" c = "+c);
		if(usehold){ hold = hold+c; }
		if(cnt == 0)
		{
			if(c.match(/\s/))
			{
				//alert("did match a space");
				//remove any leading white space
				c = w.charAt(cnt);
				while(c.match(/\s/) && cnt < len){ c = w.charAt(++cnt); }	
				usehold = 1;
				hold = c;
			}
		}
		if(c.match(/\D/))
		{
			//alert("did match non digit");
			ok = 1;
		}
		cnt++;
	}
	//alert("leaving containsNonDigits = ");
	if(!ok) return -1;
	if(usehold) return hold;
	return word;
}

//FUNCTION CHECKS FOR BEGINING WHITE SPACE
// return shortened value if leading white space;
function trimWhiteSpace(wrd)
{
//alert("in trimWhiteSpace"+wrd);
	word = new String(wrd);	
	len = word.length;
	if(len == 0){ return; }
	var hold;
	var c;
	cnt = 0;
	usehold = 0;
	while(cnt < len)
	{
		c = word.charAt(cnt);
		if(usehold){ hold = hold+c; }
		if(cnt == 0)
		{
			if(c.match(/\s/))
			{
				//remove any leading white space
				c = word.charAt(cnt);
				while(c.match(/\s/) && cnt < len){ c = word.charAt(++cnt); }
				usehold = 1;
				hold = c;
			}
		}
		cnt++;
	}
	//alert("leaving trimWhiteSpace");
	if(usehold) return hold;
	return word;
}

//FUNCTION CHECKS FOR BEGINING WHITE SPACE
// return shortened value if leading white space;
function containsSpace(wrd)
{
	//alert("In containsSpace"+wrd);	
	word = new String(wrd);
	var word = trimWhiteSpace(word);
	var c;
	len = word.length;
	cnt = 0;

	while(cnt < len)
	{
		c = word.charAt(cnt);

		if(c.match(/\s/))
		{
			//SPACE CONTAINED IN WORD
			return -1;
		}
		cnt++;
	}
	//alert("leaving containsSpace");
	return 1;
}

function checkBadChar(chkstring)
 {
	//alert("In checkBadChar "+chkstring);
	if(chkstring.indexOf('*') != -1 ||
		chkstring.indexOf('.')  != -1 ||
		chkstring.indexOf('\"')  != -1 ||
		chkstring.indexOf(';')  != -1 ||
		chkstring.indexOf('%')  != -1 ||
		chkstring.indexOf(':')  != -1 ||
		chkstring.indexOf('>')  != -1 ||
		chkstring.indexOf('<')  != -1 ||		
		chkstring.indexOf('\'')  != -1 
		)
 	{
		//alert("leaving  checkBadChar with 1");
		return 1; 
	}else {
		//alert("leavaing checkBadChar with 0");		
		return 0;
	}
}

