/* The scripts on this page was produced by mordechai Sandhaus - 52action.net,
 and is copyrighted . If you like this script, we encourage you to use it,
 provided that  include this note, and link to 52action.net. */
 
/* 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 (str.substring(k, k+1) != delim){
	   if (event.keyCode != 8){ //backspace
	    str = str.substring(0,k) + delim + str.substring(k,str.length);
       }
	  }
	 }
	}
 }
textbox.value = str
}
