function plugboard(n)
{
	var plugnum, re, otherletter;
	var arrusedletters = new Array();

	validate('plug'+n);

	var plug = document.getElementById('plug'+n).value.toUpperCase();

	if (plug != "") {
		// Check if letter has been used.
		if (ENIGMA.lastkeypressed >= 65 && ENIGMA.lastkeypressed <= 90 && ENIGMA.usedletters.indexOf(plug) > -1) {
			// If the input letter has already been used, ignore it and stop running the script.
			alert("You have already used the letter '"+plug+"' in a connection.\n"
					+ "Delete its current connection to form a new one.");
			document.getElementById('plug'+n).value = "";
			document.getElementById('plug'+n).focus();
			return false;
		} else {
			// Get the numerical value for the letter
			plugnum = ENIGMA.plaintext.indexOf(plug);

			// Fill out the paired letter field.
			//  Eg, if field 'A' is 'D', fill out field 'D' as 'A'
			document.getElementById('plug'+plugnum).value = ENIGMA.plaintext.charAt(n);

			ENIGMA.usedletters += plug + ENIGMA.plaintext.charAt(n) + " ";
		}
	} else {
		if (ENIGMA.lastkeypressed == 8 || ENIGMA.lastkeypressed == 46) {
			// Clear plugs on delete
			re = new RegExp("([A-Z]?)(" + ENIGMA.plaintext.charAt(n) + ")([A-Z]?)\\s", "g");
			arrusedletters = re.exec(ENIGMA.usedletters);
			otherletter = arrusedletters[1] + arrusedletters[3];

			plugnum = ENIGMA.plaintext.indexOf(otherletter);
			document.getElementById('plug'+plugnum).value = "";
		
			re = new RegExp("([A-Z]?)" + ENIGMA.plaintext.charAt(n) + "([A-Z]?)\\s", "g");
			ENIGMA.usedletters = ENIGMA.usedletters.replace(re, "");
		}
	}

	return true;
}
/* FUNCTION --------------------------------------------------------
	Validate and autofill the steckerbrett (plugboard)
   ----------------------------------------------------------------- */
FUNCTION
Validate and autofill the steckerbrett (plugboard)
FUNCTION Validate and autofill the steckerbrett ( plugboard )
function plugboard(n)
{
	var plugnum, re, otherletter;
	var arrusedletters = new Array();
	validate('plug'+n);
	var plug = document.getElementById('plug'+n).value.toUpperCase();
	if (plug != "") {
		if (ENIGMA.lastkeypressed >= 65 && ENIGMA.lastkeypressed <= 90 && ENIGMA.usedletters.indexOf(plug) > -1) {
			alert("You have already used the letter '"+plug+"' in a connection.\n"
					+ "Delete its current connection to form a new one.");
			document.getElementById('plug'+n).value = "";
			document.getElementById('plug'+n).focus();
			return false;
		} else {
			plugnum = ENIGMA.plaintext.indexOf(plug);
			document.getElementById('plug'+plugnum).value = ENIGMA.plaintext.charAt(n);
			ENIGMA.usedletters += plug + ENIGMA.plaintext.charAt(n) + " ";
		}
	} else {
		if (ENIGMA.lastkeypressed == 8 || ENIGMA.lastkeypressed == 46) {
			re = new RegExp("([A-Z]?)(" + ENIGMA.plaintext.charAt(n) + ")([A-Z]?)\\s", "g");
			arrusedletters = re.exec(ENIGMA.usedletters);
			otherletter = arrusedletters[1] + arrusedletters[3];
			plugnum = ENIGMA.plaintext.indexOf(otherletter);
			document.getElementById('plug'+plugnum).value = "";
			re = new RegExp("([A-Z]?)" + ENIGMA.plaintext.charAt(n) + "([A-Z]?)\\s", "g");
			ENIGMA.usedletters = ENIGMA.usedletters.replace(re, "");
		}
	}
	return true;
}
function plugboard ( n ) { var plugnum , re , otherletter ; var arrusedletters = new Array ( ) ; validate ( 'plug' + n ) ; var plug = document . getElementById ( 'plug' + n ) . value . toUpperCase ( ) ; if ( plug != "" ) { if ( ENIGMA . lastkeypressed >= 65 && ENIGMA . lastkeypressed <= 90 && ENIGMA . usedletters . indexOf ( plug ) > - 1 ) { alert ( "You have already used the letter '" + plug + "' in a connection.\n" + "Delete its current connection to form a new one." ) ; document . getElementById ( 'plug' + n ) . value = "" ; document . getElementById ( 'plug' + n ) . focus ( ) ; return false ; } else { plugnum = ENIGMA . plaintext . indexOf ( plug ) ; document . getElementById ( 'plug' + plugnum ) . value = ENIGMA . plaintext . charAt ( n ) ; ENIGMA . usedletters += plug + ENIGMA . plaintext . charAt ( n ) + " " ; } } else { if ( ENIGMA . lastkeypressed == 8 || ENIGMA . lastkeypressed == 46 ) { re = new RegExp ( "([A-Z]?)(" + ENIGMA . plaintext . charAt ( n ) + ")([A-Z]?)\\s" , "g" ) ; arrusedletters = re . exec ( ENIGMA . usedletters ) ; otherletter = arrusedletters [ 1 ] + arrusedletters [ 3 ] ; plugnum = ENIGMA . plaintext . indexOf ( otherletter ) ; document . getElementById ( 'plug' + plugnum ) . value = "" ; re = new RegExp ( "([A-Z]?)" + ENIGMA . plaintext . charAt ( n ) + "([A-Z]?)\\s" , "g" ) ; ENIGMA . usedletters = ENIGMA . usedletters . replace ( re , "" ) ; } } return true ; }
FUNCTION
Validate and autofill the steckerbrett (plugboard)
FUNCTION Validate and autofill the steckerbrett ( plugboard )
// Check if letter has been used. // If the input letter has already been used, ignore it and stop running the script. // Get the numerical value for the letter // Fill out the paired letter field. //  Eg, if field 'A' is 'D', fill out field 'D' as 'A' // Clear plugs on delete