var tokenShuffleData = null;

function tokenShuffleSetup() {
  	var f = document.forms['parameterForm'];
  	clearForm(f);
   	
  	var div = document.createElement('DIV');
  	f.appendChild(div);
   	
	var tb = createTable(div, 3);   	
	   	
  	tb.rows[0].appendChild(buildCell(1, buildLabel('Separator:')));
  	tb.rows[0].appendChild(buildCell(1, buildText('tokenShuffleSeparator')));
  	tb.rows[1].appendChild(buildCell(1, buildLabel('Output:')));
  	tb.rows[1].appendChild(buildCell(1, buildText('tokenShuffleOutput')));
  	tb.rows[2].appendChild(buildCell(1, buildRunButton(tokenShuffleRun)));
  	tb.rows[2].appendChild(buildCell(-1, buildButton('Help', tokenShuffleHelp),
  	                                     buildButton('Example 1', tokenShuffleExample1)));
	if (tokenShuffleData) {  		                                     
		tokenShuffleSet(tokenShuffleData);
	}
	
	return tokenShuffleTearDown;
}
   
function tokenShuffleTearDown() {
	tokenShuffleData = tokenShuffleGet();
}

function tokenShuffleGet() {
  	var o = new Object();
  	o.separator = document.forms['parameterForm'].tokenShuffleSeparator.value;
  	o.output = document.forms['parameterForm'].tokenShuffleOutput.value;
  	return o;
}

function tokenShuffleSet(o) {
  	document.forms['parameterForm'].tokenShuffleSeparator.value = o.separator;
  	document.forms['parameterForm'].tokenShuffleOutput.value = o.output;
}
   
function tokenShuffleRun() {
  	makeEditorRequest('tokenShuffle', tokenShuffleGet());
}
   
function tokenShuffleHelp() {
	window.frames['docFrame'].document.location = "html/tokenShuffle.html";
}
   
function tokenShuffleExample1() {
	document.forms['parameterForm'].tokenShuffleSeparator.value = '\\s+';
	document.forms['parameterForm'].tokenShuffleOutput.value = '$6 $1';
	window.frames['docFrame'].document.location = "html/tokenShuffleExample1.html";
	document.forms['inputForm'].inputText.value = 
	      'Canopus     Carina        230.0 ly  F0   -0.72\n' +
	      'Arcturus    Bootes         38.1 ly  K0   -0.06\n' +
	      'Vega        Lyra           26.9 ly  A0    0.04\n';
	
	document.forms['outputForm'].outputText.value = '';	
}   
