Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] == value) {  //i want similar
            return true;
        }
    }
    return false;
};


/* The scripts on this page was produced by mordechai Sandhaus - 52action.com,
 and is copyrighted . If you like this script, we encourage you to use it,
 provided that  include this note, and link to 52action.com. */

/* script explanation for dummies */

/* NOTE: THE FIRST 2 ARGUMENTS SHOULD ALWAYS REMAIN THE SAME - this.value, this */
// the first argument in the function, accepts the "value" of the textbox to be masked
// the second argument is the name of the textbox
        //although the first 2 could have been done in 1 argument I did it in 2
        // to make it easier to understand

//the third argument holds the locations of the separator,
// each location should be separated by a comma - (going from lower numbers to higher)

//the fourth holds the delimiter (or separator) character.

/* nothing in the function should be edited,
        to change a delimiter or character location,
        change it in the calling script
        - the following code should be inserted into the field(s) to be masked - */

                /*replace 'location1,location2' with the locations where you want the delimiter
                        replace the 'delimiter' with the separating character you would like */
        // javascript:return mask(this.value,this,'location1,location2','delimiter')

        //-there is no limit to the amount of delimiters you can have added
function mask(str,textbox,loc,delim){
        var locs = loc.split(',');

        for (var i = 0; i <= locs.length; i++){
                for (var k = 0; k <= str.length; k++){
                         if (k == locs[i]){ //if k = indicated location
                                  if (str.substring(k, k+1) != delim){
                                    str = str.substring(0,k) + delim + str.substring(k,str.length)
                                  }
                         }
                }
         }

        for(var x = 0; x <= str.length; x++){
             //if not in indicated delim location
             if(!locs.inArray(x)){
             	if(isNaN(str.substring(x, x+1))){ //if indicated char is not a number
                	str = str.substring(0, x) + str.substring(x+1, str.length)
                }
             }

        }
        textbox.value = str
}