function showimg(imgname) {
	window.open (imgname,"imagewindow","status=1");

}

function displayImage(imgname) {
	div = document.getElementById("display");
	div.innerHTML = "<img src='"+imgname+"'/><a href=\"javascript:showHide('display')\">Close Window</a>";
	
	//photo = new Image();
	//photo.src="./gallery/tournaments/20080905001.jpg";
	
	//div.appendChild(photo);
	
	//photo = document.getElementById("photo");
	//photo.src = "./gallery/tournaments/20080905001.jpg";
	
	showHide("display");
}

function report(repname) {
	window.open (repname,"reportwindow","status=0,scrollbars=1,width=500,height=600");
}

function showHide(elementId) {
	el = document.getElementById(elementId);
	
	if (el.style.display != 'block') {
		el.style.display = 'block';
		return;
	}
	
	if (el.style.display != 'none') {
		el.style.display = 'none';
		return;
	}
}

function showEl(elementId) {
	el = document.getElementById(elementId);
	if (el.style.display != 'block') {
		el.style.display = 'block';
		return;
	}
}

function addFixtureRow(tableId) {

	tbl = document.getElementById(tableId);
	
	var lastRow = tbl.rows.length;
	var row = tbl.insertRow(lastRow);
	
	// date cell
	var cell = row.insertCell(0);
	var textNode = document.createTextNode('0');
	cell.appendChild(textNode);
	
	// opposition cell
	cell = row.insertCell(1);
	textNode = document.createTextNode('1');
	cell.appendChild(textNode);

	// venue cell
	cell = row.insertCell(2);
	textNode = document.createTextNode('2');
	cell.appendChild(textNode);

	// wdl cell
	cell = row.insertCell(3);
	textNode = document.createTextNode('3');
	cell.appendChild(textNode);

	// score cell
	cell = row.insertCell(4);
	textNode = document.createTextNode('4');
	cell.appendChild(textNode);

	// report cell
	cell = row.insertCell(5);
	textNode = document.createTextNode('5');
	cell.appendChild(textNode);

	// scorer cell
	cell = row.insertCell(6);
	textNode = document.createTextNode('6');
	cell.appendChild(textNode);

}

function addFixture() {
	form = document.getElementById("fixform").reset();
	showEl("addFixture");
}

function addScore() {
	form = document.getElementById("scoreform").reset();
	showEl("addScore");
}

function editFixture(rowId,fixId) {
	tbl = document.getElementById("fixtab");
	form = document.getElementById("fixform");
	form.reset();
	
	// get data to show in form
	var row = tbl.rows[rowId];
	
	form.fix_id.value = fixId;
	form.fix_date.value = row.cells[0].firstChild.firstChild.nodeValue;
	form.fix_opponent.value = row.cells[1].firstChild.nodeValue;
	if (row.cells[1].className == 'left') form.fix_type.selectedIndex = 0;
	if (row.cells[1].className == 'cup') form.fix_type.selectedIndex = 1;
	if (row.cells[1].className == 'friendly') form.fix_type.selectedIndex = 2;
	if (row.cells[2].firstChild != null) {
		if (row.cells[2].firstChild.nodeValue == 'Home') form.fix_venue.selectedIndex = 1;
		if (row.cells[2].firstChild.nodeValue == 'Away') form.fix_venue.selectedIndex = 2;
	}
	if (row.cells[3].firstChild != null) {
		if (row.cells[3].firstChild.nodeValue == 'W') form.fix_wdl.selectedIndex = 1;
		if (row.cells[3].firstChild.nodeValue == 'D') form.fix_wdl.selectedIndex = 2;
		if (row.cells[3].firstChild.nodeValue == 'L') form.fix_wdl.selectedIndex = 3;
	}
	if (row.cells[10].firstChild != null) form.fix_report.value = row.cells[10].firstChild.nodeValue;
	if (row.cells[6].firstChild != null) form.fix_scorers.value = row.cells[6].firstChild.nodeValue;
	if (row.cells[7].firstChild != null) form.fix_comment.value = row.cells[7].firstChild.nodeValue;
	if (row.cells[8].firstChild != null) form.fix_score.value = row.cells[8].firstChild.nodeValue;
	if (row.cells[9].firstChild != null) form.fix_score_opp.value = row.cells[9].firstChild.nodeValue;
	
	showEl("addFixture");
}

function editScore(rowId,scoreId) {
	tbl = document.getElementById("scoretab");
	form = document.getElementById("editform");
	form.reset();
	
	var row = tbl.rows[rowId];
	
	form.e_id.value = scoreId;
	
	form.e_W.value = row.cells[3].firstChild.nodeValue;
	form.e_D.value = row.cells[4].firstChild.nodeValue;
	form.e_L.value = row.cells[5].firstChild.nodeValue;
	form.e_F.value = row.cells[6].firstChild.nodeValue;
	form.e_A.value = row.cells[7].firstChild.nodeValue;
	form.e_PD.value = row.cells[10].firstChild.nodeValue;
	
	lbl = document.getElementById("teamname");
	//tn = document.createTextNode(row.cells[1].firstChild.nodeValue);
	lbl.firstChild.nodeValue = row.cells[1].firstChild.firstChild.nodeValue;
	
	showEl("editScore");
}