    function generate_code(flag){
	head = document.choose_code.heading[0].checked;
	t_width = document.choose_code.width.value;
	if(t_width == '' || t_width < 1){
		alert('Please specify a width for your table');
		return;
	}
	w_units = document.choose_code.units.value;
	if (w_units == 'pixels'){
		w_units = '';
	}else{
		w_units = '%';
	}
	no_cols = document.choose_code.columns.value;
	if(no_cols == '' || no_cols < 1){
		alert('Please specify how many columns for your table');
		return;
	}
	no_rows = document.choose_code.rows.value;
	if(no_rows == '' || no_rows < 1){
		alert('Please specify how many rows for your table');
		return;
	}
	pad = document.choose_code.padding.value;
	if (pad == '') pad = '0';
	space = document.choose_code.spacing.value;
	if (space == '') space = '0';
	bord = document.choose_code.border[0].checked;
	bord_w = document.choose_code.border_width.value;
	if (bord_w == '') bord_w = '0';
	table_heading = '';
	bor = '';
	if(bord == true){
		bor += ' border="'+bord_w+'"';
	}
	if(head == true){
		table_heading += '<tr>';
		for (count = 1; count <= no_cols; count++){
			table_heading += '<th>heading '+count+'</th>';
		}
		table_heading += '</tr>';
	}
	table_row = '';
	cell = 1;
	for (rowcount = 1; rowcount <= no_rows; rowcount++){
		table_row += '<tr>';
		for (cellcount = 1; cellcount <= no_cols; cellcount++){
			table_row += '<td>cell '+cell+'</td>';
			cell++;
		}
		table_row += '</tr>';
	}

	list_code = '<table width="'+t_width+w_units+'"'+bor+' cellspacing="'+space+'" cellpadding="'+pad+'">';
	list_code +=table_heading+'\n';
	list_code +=table_row+'\n';
	list_code +='</table>';

	if (flag == 'preview'){
		//cellheight = eval((pad*2)*1+(space)*1+(bord_w)*1+16);
		cellheight = eval((pad*2)*1+(space)*1+16);

		if(head == true){
			no_rows ++;
		}

		height = (no_rows*cellheight)+(bord_w*2)+40;

		set_height('legend',height,'100%');
		document.getElementById('legend').innerHTML = '<table width="100%"><tr><td><b>How your table will appear on your page</b></td><td align="right"><a href="javascript://" onclick="close_preview()">Close Preview</a></td></tr></table>'+list_code;

	}else{
		document.code.result.value = list_code;	
	}
}
