/*	
	'##############################################################################
	'#####
	'						FORMAT US PHONE FUNCTION
	'	OVERVIEW  - This function will take a phone number. If it is a valid phone
	'				10 or 11 digit US number, it will reformat it into 
	'				(XXX) XXX-XXXX format
	'	
	'	PROTOTYPE - function formatUSPhone(sPhone)
	'	
	'   VARIABLE DEFINITIONS:
	'		Input  - 
	'				.sPhone = The string containing the phone number to
	'									format
	'		
	'		Output - 
	'	
	'	RETURNS   - A reformatted phone number
	'#####
	'##############################################################################
*/

function formatUSPhone(sPhone)
{
	sPhone = sPhone.toUpperCase();
	
	var phoneParts = sPhone.split(/\X/);
	
	var tempPhone = phoneParts[0].replace(/\D/g, "");

	if (tempPhone.substr(0,1) == "1")
		tempPhone = tempPhone.substr(1, tempPhone.length);
		
	if (tempPhone.length == 10)
	{
		tempPhone = "(" + tempPhone.substr(0, 3) + ") " + tempPhone.substr(3, 3) + "-" + tempPhone.substr(6, 4);
		if (phoneParts.length == 2)
			tempPhone += ", X" + phoneParts[1].replace(/\D/g, "");
	}
	else
		tempPhone = sPhone;
	
	
	return tempPhone;
	
}	
		