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 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(), ctiarr = new Array(), ctcarr = new Array();
	var ctharr = new Array('Clue type','Comps');
	ctarr = cts.split(',');
	ctiarr = ctis.split(',');
	ctcarr = ctcs.split(',');
	var tgt = document.getElementById('searchdiv');
	while(tgt.hasChildNodes()) {
		tgt.removeChild(tgt.firstChild);
	};
	var p = document.createElement('p');
	p.style.fontSize='10px'; p.style.margin=0;
	var text = document.createTextNode('\u00A0');
	p.appendChild(text);
	var cttable = document.createElement('table');
	cttable.style.margin='auto';
	var r = cttable.insertRow(0);
	for(var i=0; i<2; i++) {
		var th = document.createElement('th');
		text = document.createTextNode(ctharr[i]);
		th.appendChild(text);
		r.appendChild(th);
	};
	for(i=0; i<ctarr.length; i++) {
		r = cttable.insertRow(i+1);
		var cell = r.insertCell(0);
		var a = document.createElement('a');
		a.href = 'listcompct.php?ctype=' + ctiarr[i];
		text = document.createTextNode(ctarr[i]);
		a.appendChild(text);
		cell.appendChild(a);
		cell = r.insertCell(1);
		cell.style.textAlign = 'right';
		text = document.createTextNode(ctcarr[i]);
		cell.appendChild(text);
	};
	tgt.appendChild(p);
	tgt.appendChild(cttable);
	var t = document.getElementById('tdsearch');
	for (i=0; i<t.rows.length; i++) {
		for (var j=0; j<t.rows[i].cells.length; j++) {
			var 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 tgt = document.getElementById('searchdiv');
	while(tgt.hasChildNodes()) {
		tgt.removeChild(tgt.firstChild);
	};
	var yearlist = new Array();
	var link_to = 'listcomps.php?year=';
	for (var i=ymin; i<=ymax; i++) {yearlist[i-ymin] = i};
	var yeartable = document.createElement('table');
	yeartable.style.margin='auto';
	var r = yeartable.insertRow(0);
	for (i=0; i<yearlist.length; i++) {
		if (r.cells.length == 9) {
			r = yeartable.insertRow(yeartable.rows.length)
		}; 
		var y = String(yearlist[i]);
	  	var cell = r.insertCell(r.cells.length);
		var a = document.createElement('a');
		a.href = link_to + y; 
		cell.appendChild(a);
		var text=document.createTextNode(y);
		a.appendChild(text);
	};
	while (r.cells.length < 9) {
		cell = r.insertCell(r.cells.length);
		text = document.createTextNode('\u00A0');
		cell.appendChild(text);
	};
	var p = document.createElement('p');
	p.style.fontSize='10px'; p.style.margin=0;
	text = document.createTextNode('\u00A0');
	p.appendChild(text);
	tgt.appendChild(p);
	tgt.appendChild(yeartable);
	var t = document.getElementById('tdsearch'); 
	for (i=0; i<t.rows.length; i++) {
		for (var j=0; j<t.rows[i].cells.length; j++) {
			var 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 tgt = document.getElementById('searchdiv');
	while(tgt.hasChildNodes()) {
		tgt.removeChild(tgt.firstChild);
	};
	var alphalist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	if(alist=='') {var alist1=alphalist;} else {var alist1 = alist;};
	var p = document.createElement('p'); 
	p.style.textAlign='center';
	var t = 'Select the first letter of the '
	if (searchtype=='comp') {
		var link_to = 'listcompletter.php?letter=';
		var call_cell = 'tdword';
		t += 'Clue Word';
	}
	else {
		var link_to = 'listcluers.php?letter=';
		var call_cell = 'tdcluer';
		t += 'Surname';
	};
	var text = document.createTextNode(t); 
	p.appendChild(text);
	var br = document.createElement('br'); 
	p.appendChild(br);
	text = document.createTextNode('\u00A0'); 
	p.appendChild(text);
	tgt.appendChild(p);
	alphatable = document.createElement('table');
	alphatable.style.margin='auto';
	var r = alphatable.insertRow(0);
	for (var i=0; i<26; i++) {
		if (r.cells.length == tblwidth) {
			r = alphatable.insertRow(alphatable.rows.length);
		};
		var cell = r.insertCell(r.cells.length);
		var aa = alphalist.substring(i,i+1);
		text = document.createTextNode(aa);
		if (!alist1.match(aa)) {
			cell.appendChild(text);
		}
		else {
			var a = document.createElement('a');
			a.href = link_to + aa;
			a.appendChild(text);
			cell.appendChild(a);
		};
	};
	while(r.cells.length < tblwidth) {
		cell = r.insertCell(r.cells.length);
		text = document.createTextNode('\u00A0');
		cell.appendChild(text);
	};
	tgt.appendChild(alphatable);
	br = document.createElement('br'); 
	tgt.appendChild(br);
	text = document.createTextNode('\u00A0'); 
	tgt.appendChild(text);
	var t;
	if(t = document.getElementById('tdsearch')) {
		for (i=0; i<t.rows.length; i++) {
			for (var j=0; j<t.rows[i].cells.length; j++) {
				var 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 tgt = document.getElementById('searchdiv');
	while(tgt.hasChildNodes()) {
		tgt.removeChild(tgt.firstChild);
	};
	var t = 'Enter the words to search for in ';
	if (searchtype == 'comment') {
		var link_to = 'commentsearch.php';
		var call_cell = 'tdcomment';
		t += 'Comments';
	}
	else {
		var link_to = 'cluesearch.php';
		var call_cell = 'tdclue';
		t += 'Clues';
		var c0='checked'; var c1='';
		if(clueopt=='1') {c0=''; c1='checked';};
	};
	t +=' and click Go.'
	var p = document.createElement('p'); 
	p.style.textAlign='center';
	var text = document.createTextNode(t);
	p.appendChild(text);
	tgt.appendChild(p);
	var searchform = document.createElement('form');
		searchform.action = link_to;
		searchform.method = 'get';
	var table = document.createElement('table');
		table.style.margin = 'auto';
		table.style.width = '80%';
		table.style.borderWidth = '1px';
	var r = table.insertRow(0);
	var cell = r.insertCell(0);
		cell.style.textAlign = 'center'
		cell.style.borderWidth = 0;
	var hid = document.createElement('input');
		hid.type = 'hidden';
		hid.name = 'page';
		hid.value = '0';
	cell.appendChild(hid);
	var txt = document.createElement('input');
		txt.type = 'text';
		txt.name = 'search';
		txt.value = cont;
		txt.style.width = '80%';
		txt.maxLength = '150';
	cell.appendChild(txt);
	text = document.createTextNode('\u00A0');
	cell.appendChild(text);
	var sub = document.createElement('input');
		sub.type = 'submit';
		sub.value = 'Go';
	cell.appendChild(sub);
	if(searchtype == 'clue') {
		r = table.insertRow(1);
		cell = r.insertCell(0);
			cell.style.textAlign = 'center'
			cell.style.borderWidth = 0;
		text = document.createTextNode('Search in:\u00A0\u00A0');
		cell.appendChild(text);
		var rad = document.createElement('input');
			rad.type = 'radio';
			rad.name = 'clueopt'
			rad.checked = c0;
			rad.value = 0;
		cell.appendChild(rad);
		text = document.createTextNode('Clues\u00A0\u00A0');
		cell.appendChild(text);
		var rad = document.createElement('input');
			rad.type = 'radio';
			rad.name = 'clueopt'
			rad.checked = c1;
			rad.value = 1;
		cell.appendChild(rad);
		text = document.createTextNode('Explanations');
		cell.appendChild(text);
	};
	searchform.appendChild(table);
	tgt.appendChild(searchform);
	var p = document.createElement('p'); 
		p.style.textAlign='center';
	text = document.createTextNode('See the ');
	p.appendChild(text);
	var a = document.createElement('a'); 
		a.href = 'about.php#search';
	text = document.createTextNode('About');
	a.appendChild(text);
	p.appendChild(a);
	text = document.createTextNode(' page for information on keyword searches');
	p.appendChild(text);
	var br = document.createElement('br'); 
	p.appendChild(br);
	text = document.createTextNode('\u00A0');
	p.appendChild(text);
	tgt.appendChild(p);
	var t = document.getElementById('tdsearch');
	for (var i=0; i<t.rows.length; i++) {
		for (var j=0; j<t.rows[i].cells.length; j++) {
			var 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) {
	var loc=document.getElementById('Solbox');
	if (loc.innerHTML == 'Solution') {
		loc.innerHTML = sol_text;
		loc.className = 'sideclue1';
	}
	else {
		loc.innerHTML = 'Solution';
		loc.className = 'sideclue0';
	};
};

