// functions in this file:
// 1)trimAllSpace(obj)
// 2)isDecimalNum(obj, msg)
// 3)isAlphabet(obj, msg)
// 4)isTelephoneNum(obj,msg)
// 5)isCapitalLetters(obj, msg)
// 6)contains(obj, list, msg)
// 7)stringContains(string, list)



// NOTE: seems to have problems with textareas.
function trimAllSpace(obj)
{
	if (obj.value.length == 0)
		return obj

	// find the first non-space character
	for (var startpos=0; 
	     (startpos <= obj.value.length-1) && (obj.value.substring(startpos, startpos+1) == " ");
		 startpos++) 
		     ;	
		
	// find the last non-space character.
	for (var endpos=obj.value.length-1; 
	     (endpos >= startpos) && (obj.value.substring(endpos, endpos+1)==" "); 
		 endpos--) 
		     ;
		 
	obj.value = obj.value.substring(startpos, endpos+1);
	//window.status = "<" + obj.value + ">"
	return obj;
}

// checks if obj only contains digits
function isDecimalNum(obj, msg)
{
	var digits="0123456789."
	
	return contains(obj, digits, msg)
}

// checks if obj only contains alphabets.
function isAlphabet(obj, msg)
{
	var alpah="abcdefghijklmnopqrstuvwxyz"

	return contains(obj, alpha, msg)
}

function isTelephoneNum(obj,msg)
{
	var tel="1234567890()"
	return contains(obj, tel, msg)
}

function isCapitalLetters(obj, msg)
{
	var caps="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	return contains(obj, caps,msg)
}

// checks that obj only contains characters in list.
function contains(obj, list, msg)
{
	for (var i=0;i<obj.value.length;i++)
	{
		temp=obj.value.substring(i,i+1)
		if (list.indexOf(temp)==-1)
		{
			alert(msg)			
			obj.focus()
			obj.select()
			return false
		}
    }
	return true;
}

// checks that obj only contains characters in list.
function stringContains(string, list)
{
	for (var i=0;i<string.length;i++)
	{
		temp=string.substring(i,i+1)
		if (list.indexOf(temp)==-1)
			return false
    }
	return true;
}
