// format of game token: b+2digit year + 2digit match number
var lMinMatch = 1;
var lMaxMatch = 40;

var tMinMatch = 0;
var tMaxMatch = 0;

var cMinMatch = 1;
var cMaxMatch = 4;

var gMatch = 0;
var gType = ' ';


function makeLink(isNext) {
	var stem = '';
	if (gType == 'l')
		stem = 'league';
	else if (gType == 'c')
		stem = 'cup';
	else if (gType == 't')
		stem = 'totocup';
	if (isNext) {
		stem += (gMatch+1);
	}
	else {
		stem += (gMatch -1);
	}
	stem += '.htm';
	return stem;
}

function getCurrentMatch() {
	var theURLDelim = location.href.lastIndexOf('/');
	if (theURLDelim != -1) {
		theURLDelim++;
	}
	else {
		theURLDelim = 0;
	}
	var fName = location.href.substr(theURLDelim, location.href.length - theURLDelim);
	var theLen = 0;
	gType = fName.charAt(0);
	if (fName.indexOf("league") != -1) {
		theLen = 6;
	}
	else if (fName.indexOf("totocup") != -1) {
		theLen = 6;
	}
	else if (fName.indexOf("cup") != -1) {
		theLen = 3;
	}
	fName = fName.substring(theLen, fName.length - 4);
	if (fName != null)
	gMatch = parseInt(fName);
	return fName;
}

function writeNextLink() {
	if (gMatch == 0)
		getCurrentMatch();
	var theMax = eval(gType+'MaxMatch');
	var theMin = eval(gType + 'MinMatch');
	if (gMatch < theMax) {
		var theFile = makeLink(true);
		document.write('<a href='+theFile+'>'+gImgUp+'</a>');
		}
		else
			spacer(22, 22);
	}

function writePrevLink() {
	if (gMatch == 0)
		getCurrentMatch();
	var theMax = eval(gType+'MaxMatch');
	var theMin = eval(gType + 'MinMatch');
	if (gMatch > theMin) {
		var theFile = makeLink(false);
		document.write('<a href='+theFile+'>'+gImgDown+'</a>');
		}
		else {
			spacer(22, 22);
		}
}

function writeCards() {
	var i = 0;
	var nArgs = writeCards.arguments.length - 1;
	if (nArgs < 1) {
		return;
	}
	document.write("<table border=1 cellpadding=2 cellspacing=0><tr>");
	document.	write('<td bgcolor=black nowrap align=center colspan=2><font style="color: #ffffcc;" color="#ffffcc">םיסיטרכ</font></td><td></td></tr>');
	while (i < nArgs) {
		with (document) {
			write('<tr><td bgcolor="#ffff33" nowrap align=right>'+writeCards.arguments[i]+'</td><td><IMG SRC=');
			if (writeCards.arguments[i+1]) {
				write(getIconDir()+'symbols/yellowcard.gif');
			}
			else {
				write(getIconDir()+'symbols/redcard.gif');
			} 
			write(' WIDTH=16 HEIGHT=16 BORDER=0 HSPACE=0 VSPACE=0></td></tr>');
		}
		i += 2;
	}
	document.write("</tr></table><BR>");

}

function writeTeam(theTeam, theNumber, theColor) {
	document.write('<tr valign=middle bgcolor='+theColor+'><td align=center>'+theNumber+'</td>');
	document.write('<td align=right valign=middle>'+theTeam+'</td></tr>');
}

function writeScore(otherTeam, us, them, isHome) {
	with (document) {
		write("<table border=0 cellpadding=2 cellspacing=1>");
		if (isHome) {
			writeTeam('םילשורי ר"תיב', us, "yellow");
			writeTeam(otherTeam, them, "white");
		}
		else {
			writeTeam(otherTeam, them, "white");
			writeTeam('םילשורי ר"תיב', us, "yellow");
		}
		write('</table>');
	}
}

function writeScorers() {
	if (writeScorers.arguments.length > 0) {
		var i = 0; 
		document.write('<table border=1 cellpadding=2 cellspacing=0>');
		document.	write('<tr><td bgcolor=black nowrap align=center colspan=2><font style="color: #ffffcc;" color="#ffffcc">ר"תיבל םיעיקבמה</font></td></tr>');
		while (i < writeScorers.arguments.length) {
			with (document) {
				write('<tr><td bgcolor="#ffff33" nowrap align=left>');
				while ((i < writeScorers.arguments.length) && (! isNaN(writeScorers.arguments[i]))) {
//					alert("writing "+writeScorers.arguments[i] );
					write(writeScorers.arguments[i] + "' ");
					i++;
				}

			//	alert("writing "+writeScorers.arguments[i] );
				write('</td><td align=right nowrap bgcolor=#ffff66><b>'+writeScorers.arguments[i]+'</b></td></tr>');
				i++;
			}
		}
		document.write('</table>');
	}
}


