function Phone_onChange(pfField)
{
 var strInput = pfField.value;

	//remove any parens and spaces and dashes
	strInput = strInput.replace("(","");
	strInput = strInput.replace(")","");
	strInput = strInput.replace(/-/g,"");
	strInput = strInput.replace(/\s/g,"");

 	if(strInput.length > 0) 
 	{
  		checkit = Phone_Validate(strInput)
		if(checkit == false)
	    	{
				return "failed";		
    	    }
    	    else
    	    {
    	    		//good data
    	    		if(checkit == false)
    	    		{
    	    			//do nothing
    	    		}
    	    		else
    	    		{
    	    			//10 char needs new data
    	    			pfField.value = checkit;
    	    		}
    	    		   	    		
    	    }
	}
	return "ok";
}

function Phone_Validate(strInput)
{
	if(strInput.length == 0)
		return true;


	if(strInput.length != 10)
	{
		alert("Phone Number is Not Correct Length - Please Re-enter!");
		return false;
	}
	else
	{
		//loop through all digits to check validity
		for(y=0;y!=11;y++)
		{
			if(strInput.charCodeAt(y) < 48 || strInput.charCodeAt(y) > 57)
			{
				bmsg = "Phone/Fax # needs digit instead of '" + strInput.charAt(y) + "' - Please Re-enter!";
				alert(bmsg);
				return false;
			}
		}
		//made it out of the loop for validity so now add dashes and return true
		p1=strInput.substring(0,3);
		p2=strInput.substring(3,6);
		p3=strInput.substring(6,10);
		newreturn = p1 + "-" + p2 + "-" + p3;
		return newreturn;
	}
}

