// To use this function you need to add three event handlers to the field
//	onKeyUp="SSNAutoFormat_AddDashes(this,event);"  
//	onClick="SSNAutoFormat_Select(this);"

// This function adds two dashes between the numerical digits of a SSN.
// This function also ensures that only digits will be accepted.
// This function will select on tabs (also on many control keys)
// Add the following element in the SSN field to use this function: 
//	onKeyUp="SSNAutoFormat_AddDashes(this,event);"
function SSNAutoFormat_AddDashes(field,e)
{
	if(e)
    { 
        e = e 
    } 
    else 
    {
        e = window.event 
    } 
    if(e.which) // If Mozilla based browser
    { 
        var keyCode = e.which 
    } 
    else // If IE
    {
        var keyCode = e.keyCode 
    }
	regEx = /\D/g; // String to remove any characters that are not numbers
	filteredField=field.value.replace(regEx,"") // text field numeric characters only
	ssnLength=filteredField.length
	if (keyCode == 9 || keyCode == 16 || keyCode == 19 || keyCode == 36 || keyCode == 37) 
	// If a tab, shift, pause/break, home, left arrow 
	{
		field.select();
	}
	else if (keyCode == 8)   // Is a backspace
	{ 
		ssnLength--;
	}
	else if(ssnLength==3) 
	{
		field.value=filteredField + " - "
	}
	else if(ssnLength>3&&ssnLength<5)
	{
		ssa=filteredField.slice(0,3)
		ssb=filteredField.slice(3,5)
		field.value=ssa+" - "+ssb 
	}
	else if(ssnLength==5)
	{
		ssa=filteredField.slice(0,3)
		ssb=filteredField.slice(3,5)
		field.value=ssa + " - " + ssb + " - "
	}
	else if(ssnLength>5)
	{
		ssa=filteredField.slice(0,3)
		ssb=filteredField.slice(3,5)
		ssc=filteredField.slice(5,9)
		field.value=ssa+" - "+ssb+" - "+ssc
	}
	else
	{
		field.value=filteredField
	}
}

// Simple function to select the field on any mouse click
// Add the following element in the SSN field to use this function: 
//	onClick="SSNAutoFormat_Select(this);"
function SSNAutoFormat_Select(field)
{
	field.select();
}



