function ok_comp() {
	var compsel = document.getElementById('comp_no').selectedIndex;
	var comp_no = document.getElementById('comp_no').value;
	if (!compsel) {
		alert('Please select a competition from the list.');
		return;
	}
	else {
		document.getElementById('compform').submit();
	};
};

//-------------------------------------------------------------------------------------------//

function open_section(conts, loc_id) {
		var list = '<table border align="center">' + conts + '</table>';
		document.getElementById('searchdiv').innerHTML = list;
		var t =  document.getElementById('tdsearch').cells;
		for (i=0; i<t.length; i++) {
			if (t[i].innerHTML.substring(0,1) != 'F') {
				t[i].style.backgroundColor = '#f8f8f8';
			};
		};
		document.getElementById(loc_id).style.backgroundColor = 'gold';
	
};

//-------------------------------------------------------------------------------------------//

function open_section_ct(cts,ctis,ctcs) {
	var ctarr = new Array();
	var ctiarr = new Array();
	var ctcarr = new Array();
	ctarr = cts.split(',');
	ctiarr = ctis.split(',');
	ctcarr = ctcs.split(',');
	var cttable = '<p style="font-size:10px;margin:0px">&nbsp;</p><table border align="center"><tr>';
	cttable += '<th>Clue type</th><th>No. of comps</th></tr>';
	for(i=0; i<ctarr.length; i++) {
		cttable += '<tr><td><a href="listcompct.php?ctype=' + ctiarr[i] + '">' + ctarr[i] + '</a></td>';
		cttable += '<td style="text-align:right">' + ctcarr[i] + '</td></tr>';
	};
	cttable += '</table>';
	document.getElementById('searchdiv').innerHTML = cttable;
	var t = document.getElementById('tdsearch'); var c;
	for (i=0; i<t.rows.length; i++) {
		for (j=0; j<t.rows[i].cells.length; j++) {
			c = t.rows[i].cells[j];
			if (c.innerHTML.substring(0,1) != 'F') {
				c.style.backgroundColor = '#f8f8f8';
			};
		};
	};
	document.getElementById('tdtype').style.backgroundColor = 'gold';
};

//-------------------------------------------------------------------------------------------//

function open_section_year(ymin, ymax) {
	var yearlist = new Array();
	var link_to = 'listcomps.php?year=';
	for (i=ymin; i<=ymax; i++) {yearlist[i-ymin] = i};
	var yeartable = '<p style="font-size:10px;margin:0px">&nbsp;</p><table border align="center">';
	for (i=0; i<yearlist.length; i++) {
		if (i%9 == 0) {yeartable += '<tr>'}; 
		var y = String(yearlist[i]);
	  	yeartable += '<td>' + y.link(link_to + y).bold() + '</td>';
  		if (i%9 == 8) {yeartable += '</tr>'};
	};
	if (yeartable.lastIndexOf('</tr>') != yeartable.length - 5) {
		while (i%9 > 0) {i += 1; yeartable += '<td>&nbsp;</td>';};
		yeartable += '</tr>';
	};
	yeartable += '</table>';
	document.getElementById('searchdiv').innerHTML = yeartable;
	var t = document.getElementById('tdsearch'); var c;
	for (i=0; i<t.rows.length; i++) {
		for (j=0; j<t.rows[i].cells.length; j++) {
			c = t.rows[i].cells[j];
			if (c.innerHTML.substring(0,1) != 'F') {
				c.style.backgroundColor = '#f8f8f8';
			};
		};
	};
	document.getElementById('tdyear').style.backgroundColor = 'gold';
};


//-------------------------------------------------------------------------------------------//

function open_section_name(alist, searchtype, tblwidth) {
	var a = '';
	var alphalist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	if (alist=='') {var alist1=alphalist;} else {var alist1 = alist;};
	var alphatable = '<p align="center">Select the first letter of the ';
	if (searchtype=='comp') {
		var link_to = 'listcompletter.php?letter=';
		var call_cell = 'tdword';
		alphatable += 'Clue Word';
	}
	else {
		var link_to = 'listcluers.php?letter=';
		var call_cell = 'tdcluer';
		alphatable += 'Surname';
	};
	alphatable += '<br />&nbsp;</p><table border align="center">';
	for (i=0; i<26; i++) {
		a = alphalist.substring(i,i+1);
		if (i%tblwidth == 0) {alphatable += '<tr>'};
		alphatable += '<td>';
		if (!alist1.match(a)) {alphatable += a}
		else {alphatable += a.link(link_to + a).bold()};
		alphatable += '</td>';
  		if (i%tblwidth == tblwidth - 1) {alphatable += '</tr>'};
	};
	if (alphatable.lastIndexOf('</tr>') != alphatable.length - 5) {
		while (i%tblwidth > 0) {i += 1; alphatable += '<td>&nbsp;</td>';};
		alphatable += '</tr>';
	};
	alphatable += '</table><br />&nbsp;';
	document.getElementById('searchdiv').innerHTML = alphatable;
	var t; var c;
	if(t = document.getElementById('tdsearch')) {
		for (i=0; i<t.rows.length; i++) {
			for (j=0; j<t.rows[i].cells.length; j++) {
				c = t.rows[i].cells[j];
				if (c.innerHTML.substring(0,1) != 'F') {
					c.style.backgroundColor = '#f8f8f8';
				};
			};
		};
		document.getElementById(call_cell).style.backgroundColor = 'gold';
	};
};

//-------------------------------------------------------------------------------------------//

function open_section_search(searchtype, cont, clueopt) {
	var searchform = '<p align="center">Enter the words to search for in ';
	if (searchtype=='comment') {
		var link_to = 'commentsearch.php';
		var call_cell = 'tdcomment';
		searchform += 'Comments';
	}
	else {
		var link_to = 'cluesearch.php';
		var call_cell = 'tdclue';
		searchform += 'Clues';
		var c0='checked '; var c1='';
		if(clueopt=='1') {c0=''; c1='checked ';};
	};
	searchform += ' and click Go.</p><form action="'+link_to+'" method="get">';
	searchform += '<table align="center" style="width:80%;border-width:1px"><tr>';
	searchform += '<td style="text-align:center;border-width:0">';
	searchform += '<input name="page" type="hidden" value="0" />';
	searchform += '<input name="search" type="text" style="width:80%" maxlength="150" value="' + cont + '" />&nbsp;';
	searchform += '<input type="submit" value="Go" />';
	searchform += '</td></tr>';
	if(searchtype=='clue') {
		searchform += '<tr><td style="text-align:center;border-width:0">Search in:&nbsp;&nbsp;';
		searchform += '<input name="clueopt" '+c0+'type="radio" value="0" />Clues&nbsp;';
		searchform += '&nbsp;<input name="clueopt" '+c1+'type="radio" value="1" />Explanations';
		searchform += '</td></tr>';
	};
	searchform += '</table></form>';
	searchform += '<p style="text-align:center">See the ';
	searchform += '<a href="about.php#search">About</a> page for information on keyword searches';
	searchform += '<br />&nbsp;</p>';
	document.getElementById('searchdiv').innerHTML = searchform;
	var t = document.getElementById('tdsearch'); var c;
	for (i=0; i<t.rows.length; i++) {
		for (j=0; j<t.rows[i].cells.length; j++) {
			c = t.rows[i].cells[j];
			if (c.innerHTML.substring(0,1) != 'F') {
				c.style.backgroundColor = '#f8f8f8';
			};
		};
	};
	document.getElementById(call_cell).style.backgroundColor = 'gold';
};

//-------------------------------------------------------------------------------------------//

function show_sol(sol_text) {
	if (!loc) {var loc=document.getElementById('Solbox')};
	if (loc.innerHTML == 'Solution') {
		loc.innerHTML = sol_text;
		loc.className = 'sideclue1';
	}
	else {
		loc.innerHTML = 'Solution';
		loc.className = 'sideclue0';
	};
};
