currentSelection = 0;

function writeTable(selectedIdx){

	$('#selectedData').html(createTableData(selectedIdx));

// set current wrapper height from initial load and set the new wrapper height
	currWrapper = $('#wrapper').height();

// set heading as title picture + menu div + footer
	heading = $('#logo').height() + $('#menu').height() + $('#footer').height();
	
	selectHeading = 250;

	divHeight = $('#divSelector').height() + selectHeading;  

	if (divHeight + heading > currWrapper) {
		$('#wrapper').height(divHeight + heading);  
	}

}


function createTableData(selectedIdx){

	if (selectedIdx <= 0 ){
		
		return("<center><h2>Please make a selection</h2></center>");

	} else {

		htmlText = "<div id=divSelector><table width=600 align=center border=1 cellspacing=0>";

		htmlText += dataList[0];

		htmlText += dataList[selectedIdx];

		htmlText += "<\/table><\/div>";

		currentSelection = selectedIdx;

		return(htmlText);

	}
	
}

function writeOption(){

	htmlOut = '<form id="selectValues" name="SelectList"><select name="selector" onChange="writeTable(selectedIndex)"><OPTION VALUE=" " SELECTED>Please Select';
	for (i=1; i<selectionList.length; i++){
		htmlOut += "<option value=" + i + ">" + selectionList[i];
	}

	htmlOut += "</select></form>";
	$('#selection').html(htmlOut);

}

function printSelected(){

	if (currentSelection == 0) {alert("Please make a selection") } else {

		pbprint = window.open('','pbprintwindow','toolbar=yes,location=yes,scrollbars=no,width=800,height=600')

		pbprint.document.write("<html><head>")

		pbprint.document.write("<style>body.mainBody {font-size:0.8em;font-family: Verdana, Arial, sans-serif;margin-left:50px;margin-right:50px;background:white;color:black;}.cellLeft {text-align: left;padding-left:3px;}td, th{font-weight: normal;font-size:12px;text-align: center;}<\/style>")

		pbprint.document.write("<\/head><body class=mainbody onload=window.print()>")

		pbprint.document.write("<center><b><h2>Bourne End Swimming Club<\/h2><\/b><\/center><br\/><br\/>")

		pbprint.document.write("<center><b><div>" + selectionList[currentSelection] + "<\/div><\/b><\/center><br\/><br\/>")

		pbprint.document.write("<table align=center border=1 bordercolorlight=black bordercolordark=black cellspacing=0>")

		pbprint.document.write(" " + dataList[0] + dataList[currentSelection])

		pbprint.document.write("<\/table>")

		pbprint.document.write("<br\/><center><\a href=javascript:window.close()>CLOSE<\/a><\/center>")

		pbprint.document.write("<\/body><\/html>")

		pbprint.document.close()

 	}

}