var splitData = null;

function splitSetup() {
  	var f = document.forms['parameterForm'];
  	clearForm(f);
   	
  	var div = document.createElement('DIV');
  	f.appendChild(div);
   	   	
	var tb = createTable(div, 4);   	
	   	
	tb.rows[0].appendChild(buildCell(1, buildLabel('Insert line break:')));
	tb.rows[0].appendChild(buildCell(1, buildRadio('splitWhere', '-1', true),
													buildLabel('before  '),
													buildRadio('splitWhere', '1', false),
													buildLabel('after  '),
													buildRadio('splitWhere', '0', false),
													buildLabel('in place of')));
	tb.rows[1].appendChild(buildCell(1, buildLabel('')));
	tb.rows[1].appendChild(buildCell(1, buildRadio('splitCount', '1', true),
													buildLabel('the first group  '),
													buildRadio('splitCount', '0', false),
													buildLabel('all groups')));
  	tb.rows[2].appendChild(buildCell(1, buildLabel('matching:')));
  	tb.rows[2].appendChild(buildCell(1, buildText('splitMatch')));
  	tb.rows[3].appendChild(buildCell(1, buildRunButton(splitRun)));  	
  	tb.rows[3].appendChild(buildCell(-1, buildButton('Help', splitHelp),
  	                                     buildButton('Example 1', splitExample1),
  	                                     buildButton('Example 2', splitExample2)));
	if (splitData) {  		                                     
		splitSet(splitData);
	}
	
	return splitTearDown;
}
   
function splitTearDown() {
	splitData = splitGet();
}

function splitGet() {
  	var o = new Object();
  	o.where = getRadioChoice(document.forms['parameterForm'].splitWhere);
  	o.count = getRadioChoice(document.forms['parameterForm'].splitCount);
  	o.match = document.forms['parameterForm'].splitMatch.value;
  	return o;
}

function splitSet(o) {
  	setRadioChoice(document.forms['parameterForm'].splitWhere, o.where);
  	setRadioChoice(document.forms['parameterForm'].splitCount, o.count);
  	document.forms['parameterForm'].splitMatch.value = o.match;
}
   
function splitRun() {
  	makeEditorRequest('split', splitGet());
}
   
function splitHelp() {
	window.frames['docFrame'].document.location = "html/split.html";
}
   
function splitExample1() {
	document.forms['parameterForm'].splitWhere[2].checked = true;
	document.forms['parameterForm'].splitCount[1].checked = true;
	document.forms['parameterForm'].splitMatch.value = '([\\.,\\s]+)';
	window.frames['docFrame'].document.location = "html/splitExample1.html";
	document.forms['inputForm'].inputText.value = 'See the child. He is pale and thin, he wears a thin and ragged linen shirt.';
	document.forms['outputForm'].outputText.value = '';	
}   
   
function splitExample2() {
	document.forms['parameterForm'].splitWhere[0].checked = true;
	document.forms['parameterForm'].splitCount[1].checked = true;
	document.forms['parameterForm'].splitMatch.value = '(<td>)';
	window.frames['docFrame'].document.location = "html/splitExample2.html";
	document.forms['inputForm'].inputText.value = '<tr><td>Sirius</td><td>Canis Major</td><td>-1.42</td></tr>\n'
                                               + '<tr><td>Canopus</td><td>Carina</td><td>-0.72</td></tr>\n'
                                               + '<tr><td>Rigil Kent</td><td>Centaurus</td><td>-0.27</td></tr>\n'
                                               + '<tr><td>Arcturus</td><td>Bootes</td><td>-0.06</td></tr>\n'
                                               + '<tr><td>Vega</td><td>Lyra</td><td>0.04</td></tr>\n';
	document.forms['outputForm'].outputText.value = '';	
}   
   
  
   
