function format(oObj,masking){
    try{
        // trapping shift or tab keys
        if((window.event.keyCode==9) || (window.event.keyCode==16)){
            return;
        }
        switch(masking){
            case 'phonenumber':{
                var sValue = oObj.value;
                sValue = sValue.replace(/[^0-9]/ig,"");	//remove non numeric values
                var sLength = sValue.length;
                switch (sLength){
                    case 0:{
                        oObj.value = sValue;
                        break;}
                    case 1:{
                        oObj.value = sValue;
                        break;}
                    case 2:{
                        oObj.value = Left(sValue,1) + Right(sValue,1);
                        break;}
                    case 3:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 4:{
                        oObj.value =  Left(sValue,1) + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + '-' + Right(sValue,1);
                        break;}
                    case 5:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + '-' + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 6:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,5),1) + Left(Right(sValue,4),1) + '-' + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 7:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,6),1) + Left(Right(sValue,5),1) + '-' + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + '-' + Right(sValue,1);
                        break;}
                    case 8:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,7),1) + Left(Right(sValue,6),1) + '-' + Left(Right(sValue,5),1) + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + '-' + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 9:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,8),1) + Left(Right(sValue,7),1) + '-' + Left(Right(sValue,6),1) + Left(Right(sValue,5),1) + Left(Right(sValue,4),1) + '-' + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 10:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,9),1) + Left(Right(sValue,8),1) + '-' + Left(Right(sValue,7),1) + Left(Right(sValue,6),1) + Left(Right(sValue,5),1) + '-' + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    default:{
                        oObj.value = Left(oObj.value,12);
                        break;}
                }
                break;
            }
            case 'ssn':{
                var sValue = oObj.value;
                sValue = sValue.replace(/[^0-9]/ig,"");	//remove non numeric values
                var sLength = sValue.length;
                
                switch (sLength){
                    case 0:{
                        oObj.value = sValue;
                        break;}
                    case 1:{
                        oObj.value = sValue;
                        break;}
                    case 2:{
                        oObj.value = Left(sValue,1) + Right(sValue,1);
                        break;}
                    case 3:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 4:{
                        oObj.value =  Left(sValue,1) + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + '-' + Right(sValue,1);
                        break;}
                    case 5:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + '-' + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 6:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,5),1) + Left(Right(sValue,4),1) + '-' + Left(Right(sValue,3),1) + Left(Right(sValue,2),1)+ '-' + Right(sValue,1);
                        break;}
                    case 7:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,6),1) + Left(Right(sValue,5),1) + '-' + Left(Right(sValue,4),1) + Left(Right(sValue,3),1)+ '-' + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 8:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,7),1) + Left(Right(sValue,6),1) + '-' + Left(Right(sValue,5),1) + Left(Right(sValue,4),1)+ '-' + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    case 9:{
                        oObj.value = Left(sValue,1) + Left(Right(sValue,8),1) + Left(Right(sValue,7),1) + '-' + Left(Right(sValue,6),1) + Left(Right(sValue,5),1)+ '-' + Left(Right(sValue,4),1) + Left(Right(sValue,3),1) + Left(Right(sValue,2),1) + Right(sValue,1);
                        break;}
                    default:{
                        oObj.value = Left(oObj.value,11);
                        break;}
                }
                break;
            }
        }
    }catch(exception){
        //do nothing
    }
}

function Left(str, n){ 
    if (n <= 0) 
        return ""; 
    else if (n > String(str).length) 
        return str; 
    else 
        return String(str).substring(0,n); 
} 
function Right(str, n){ 
    if (n <= 0) 
       return ""; 
    else if (n > String(str).length) 
       return str; 
    else { 
       var iLen = String(str).length; 
       return String(str).substring(iLen, iLen - n); 
    } 
}