
// Formats the field value the first letter or first letter of all words to uppercase
// If restlower, then all other will be cast to lowercase
// Words are separated bij a space or - or .

function formatName(field,allwords,restlower)
{	
	if(field!=null && field.value != null && field.value.length > 0)
	{
		// loop
		var sValue = field.value;
		var bNextToUpper = true; 
		var sResult="";

		for (i = 0; i < sValue.length; i++)
		{   
			c = sValue.charAt(i);
			if (bNextToUpper)
			{
				sResult = sResult + c.toUpperCase();
			}
			else
			{
				if (restlower)
				{
					sResult = sResult + c.toLowerCase();
				}
				else
				{
					sResult = sResult + c;
				}
			}
			bNextToUpper = false;
			if (allwords)
			{
				if (c==' ' || c=='.' || c=='-' )
				{
					bNextToUpper = true;
				}
			}
		}

		field.value=sResult;
	}
}

function formatZip(field, format)
{
	if(field!=null && field.value != null && field.value.length > 0)
	{
		if (format=='' || format==undefined)
		{
			format = '0000 XX';
		}
		s = field.value;
		if (format.length >= s.length) {
			for (i = 0; i < s.length; i++) {   
	
				if (format.substr(i,1)==' ' && s.indexOf(' ')==-1)
				{
					s = s.substr(0,i)+' '+s.substr(i);
				}
				if (format.substr(i,1)=='X')
				{
					s = s.substr(0,i)+s.substr(i,1).toUpperCase()+s.substr(i+1);
				}
			}
			field.value = s;
		}
	}
}

function formatlowercase(field)
{
	if(field!=null && field.value != null && field.value.length > 0)
	{
		field.value = field.value.toLowerCase();
	}	
}

