// April 25, 2006

//*******************************************************************************'
// format a phone number as it is being typed
// this version is design for onKeyUp="formatPhoneTyping(this);" in the elements tag
// it fails if the users types too fast

function formatPhoneTyping(elementObj)
{
	// make sure the element is of the right object type
	if (elementObj.type == "text")
	{

		// get the current length of the element's value
		var intLength = elementObj.value.length;
		var strTmp = "";
		
		// if this is the first character and it is not the opening area code bracket...
		if(intLength == 1 && elementObj.value.substring(0, 1) != "(")
		{
			// save the current value
			strTmp = elementObj.value;
			
			// prepend the opening area code bracket
			elementObj.value = "(" + strTmp;
		}
		
		// if they have finished entering the 3 digit area code...
		// i.e. "(902" = 4 characters
		if(intLength == 4)
		{
			// append the closing area code bracket and a space
			elementObj.value = elementObj.value + ") ";
		}
		
		// if they have finished entering the prefix
		// i.e. "(902) 454" = 9 characters
		if(intLength == 9)
		{
			// add the seperator dash
			elementObj.value = elementObj.value + "-";
		}
		
		// else leave the end open to add extensions and such
		
	}
	else
	{
		// do nothing
	}
}

//-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -'
// syntax version

function formatphonetyping(elementObj)
{
	formatPhoneTyping(elementObj)
}	

//-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -'
// syntax version

function FormatPhoneTyping(elementObj)
{
	formatPhoneTyping(elementObj)
}