var bHasDOM = (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf["MSIE 5"] != -1);

function getElement(id) {
	if (bHasDOM) {
		return document.getElementById(id);
	} else {
		if (document.all) {
			return eval("document.all." + id + ".style");
		} else if (document.ids) {
			return eval("document.ids" + id + ".style");
		} else {
			return null;
		}
	}
}

var bScrolled = false;
var oS, iS_ot, iS_pt, iS_oh, iS_ph, iB_st, iB_ch, iB_oh;

function getScrollerIntoView() {
	//alert(getElement("scroller").style.offsetTop);
	/*if ((	getElement("scroller").style.pixelTop == "")
		|| ((parseInt(getElement("scroller").style.pixelTop) + getElement("scroller").style.pixelHeight*0.8) < document.body.scrollTop)
		|| ((parseInt(getElement("scroller").style.pixelTop) - getElement("scroller").style.pixelHeight*0.2) > document.body.scrollTop)
		) {
			getElement("scroller").style.pixelTop = ((document.body.scrollTop > getElement("header").style.pixelHeight) ? (document.body.scrollTop) : (getElement("header").style.pixelHeight));
	}*/
	if (!bScrolled) {
		oS = getElement("scroller");
		iS_ot = oS.offsetTop;
		iS_pt = iS_ot;
		oS.style.pixelTop = iS_pt;
		iS_oh = oS.offsetHeight;
		iS_ph = iS_oh;
		oS.style.pixelHeight = iS_ph;
		iB_st = document.body.scrollTop;
		iB_ch = document.body.clientHeight;
		iB_sh = document.body.scrollHeight;
		bScrolled = true;
	} else {
		iS_pt = oS.style.pixelTop;
		iS_ph = oS.style.pixelHeight;
		iB_st = document.body.scrollTop;
		iB_ch = document.body.clientHeight;
		iB_sh = document.body.scrollHeight;
	}
	/*alert(	"1: (" + iS_pt + " < " + iB_st + "): " + (iS_pt < iB_st)
		+ "\n2: ((" + iS_pt + " + " + iS_ph + ") < (" + iB_st + " + " + iB_ch + "))): " + ((iS_pt + iS_ph) < (iB_st + iB_ch))
		+ "\n(1: && 2:): " + ((iS_pt < iB_st) && ((iS_pt + iS_ph) < (iB_st + iB_ch)))
		);*/
	if ((iS_pt < iB_st) && ((iS_pt + iS_ph + 50) < (iB_st + iB_ch))) {
		oS.style.pixelTop = (iB_st > (iB_sh - iS_ph))?(iB_sh - iS_ph):(iB_st);
	}
	/*alert(	"1: (" + iS_pt + " > " + iB_st + "): " + (iS_pt > iB_st)
		+ "\n2: ((" + iS_pt + " + " + iS_ph + ") > (" + iB_st + " + " + iB_ch + "))): " + ((iS_pt + iS_ph) > (iB_st + iB_ch))
		+ "\n(1: && 2:): " + ((iS_pt > iB_st) && ((iS_pt + iS_ph) > (iB_st + iB_ch)))
		);*/
	if (((iS_pt - 50) > iB_st) && ((iS_pt + iS_ph - 100) > (iB_st + iB_ch))) {
		var iComputedTop = iB_st + iB_ch - iS_ph;
		oS.style.pixelTop = (iComputedTop < iS_ot)?(iS_ot):(iComputedTop);
	}
}

function writeMenu(sMenuData) {
	var aMenuData = eval(sMenuData);
	for (var i=0;i<aMenuData.length;i++) {
		document.write(	"<div class=choice>\
					<a\
					href=\"" + aMenuData[i][0] +"\"\
					title=\"" + aMenuData[i][1] + "\"\
					>"
						+ aMenuData[i][2] + "\
					</a>\
				</div>");
	}
}

function writeNavigation() {
	document.write("<div class=nav>");
	for (var i=0;i<aLinks.length;i++) {
		document.write(" [<a href=\"#" + aLinks[i][1] + "\">" + aLinks[i][0] + "</a>] ");
	}
	document.write("</div>");
}

function writeFooter() {
	document.write(sFooter);
}

function createAboutWindow() {
	var width = 550;
	var height = 450;
	var aboutWindow = window.open("about:blank", null, "left=" + ((screen.availWidth-width)/2) + ",top=" + ((screen.availHeight-height)/2) + ",width=" + width + ",height=" + height + ",directories=no,scrollbars=no");
	aboutWindow.document.open();
	aboutWindow.document.write(sAboutWindowDoc);
	aboutWindow.document.close();
}

function csFormatDate(date) {
var monthNames = ["ledna", "února", "března", "dubna", "května", "června", "července", "srpna", "září", "října", "listopadu", "prosince"];
return new String(date.getDate() + ". " + monthNames[date.getMonth()] + " " + date.getFullYear() + ", " + date.getHours() + ":" + (((m = date.getMinutes()).toString().length == 1)?"0":"") + m);
}

function writePersInfo(aaData){
	document.write(	"<table\
			border=1px\
			frame=border\
			rules=all\
			cellspacing=0\
			cellpadding=2\
			class=personalInfo\
			>\
				<tr>\
					<th>\
						Jméno\
					</th>\
					<th>\
						E-mail\
					</th>\
					<th>\
						Telefon\
					</th>\
					<th>\
						Mobil\
					</th>\
					<th>\
						Adresa\
					</th>\
				</tr>");
	for (var i=0;i<aaData.length;i++) {
		document.write("<tr>");
		for (var j=0;j<5;j++) {
			document.write(	"<td>"
						+ aaData[i][j] + "\
					</td>");
		}
		document.write("</tr>");
	}
	document.write("</table>");
}

function writeDoc(sName) {
/*
In document head we have something like this:

<script>
	var docDir = "../docs/1997/klani/";
	document.write("<script src=\"" + docDir + "docInfo_cs.js\"><\/script>");
</script>

And then in body we call function writeDoc(sName):

<script>
	writeDoc("_1997_pozvanka_1")
</script>

We assume that all docs are gifs.
*/
	var aName = eval(sName);
	var src = docDir + sName + ".gif";
	var aDmns = aName[2].split("|");	//width, height, size in bytes
	var iWidth = parseInt(aDmns[0]);
	var iHeight = parseInt(aDmns[1]);
	var fSize = Math.round(parseFloat(aDmns[2])/102.4)/10;
	document.write(	"<div class=photo>\
				<img\
				src=" + src + "\
				title=\"" + aName[0] + "&#10;" + iWidth + "x" + iHeight +", " + fSize + " kB&#10;" + aName[1] + "&#10;&#10;Po kliknutí se otevře okno s obrázkem v původní velikosti.\"\
				class=doc\
				width=" + ((iWidth < (getElement("contents").clientWidth*0.5))?(iWidth):("50%")) + "\
				onClick='imagePopup(\"" + src + "\", \"" + aName[0] + "\", \"" + aName[1] + "\");'\
				onContextMenu='return false;'\
				></img>\
				<div\
				class=description\
				>"
					+ aName[0] + "\
					<br>"
					+ iWidth + "x" + iHeight + ", " + fSize + " kB\
					<br>" + aName[1] + "\
				</div>\
			</div>");
}

var iPopups = 0;

function imagePopup(src, sDescription, sCopyright) {
	var imageWindow = window.open("about:blank", "image" + iPopups++, "width=400,height=110,resizable=yes,scrollbars=yes,left=" + (screen.availWidth-400)/2 + ",top=" + (screen.availHeight-110)/2 + ",directories=no");
	imageWindow.document.open();
	imageWindow.document.write(	"<html>\
						<head>\
							<meta\
							http-equiv=\"Content-Type\"\
							content=\"text/html; charset=windows-1250\"\
							>\
							<title>"
								+ sDescription + " - po kliknutí na obrázek se okno zavře.\
							</title>\
							<meta\
							http-equiv=\"Content-Script-Type\"\
							content=\"text/javascript\"\
							>\
							<meta\
							http-equiv=\"Content-Style-Type\"\
							content=\"text/css\"\
							>\
							<link\
							rel=\"stylesheet\"\
							type=\"text/css\"\
							href=\"../style1-1.css\"\
							>\
							<script>\
								var bHasDOM = (parseInt(navigator.appVersion) >= 5 || navigator.appVersion.indexOf[\"MSIE 5\"] != -1);\
								function getElement(id) {\
									if (bHasDOM) {\
										return document.getElementById(id);\
									}\/* else {\
										if (document.all) {\
											return eval(\"document.all.\" + id + \".style\");\
										} else {\
											return eval(\"document.\" + id + \".style\");\
										}\
									}*\/\
								}\
							<\/script>\
							<script>\
								function img_onLoad() {\
									getElement(\"notice\").style.display=\"none\";\
									var img = getElement(\"img\");\
									window.moveTo((img.width < (screen.availWidth-50))?((screen.availWidth-(img.width+50))\/2):0,(img.height < (screen.availHeight-50))?((screen.availHeight-(img.height+50))\/2):0);\
									window.resizeTo((img.width < (screen.availWidth-50))?(img.width + 40):(screen.availWidth), (img.height < (screen.availHeight-50))?(img.height + 50):(screen.availHeight));\
									window.focus();\
								}\
							<\/script>\
						</head>\
						<body\
						class=document\
						style=\"margin: 0px;\"\
						onContextMenu='return false;'\
						onClick='self.close()';\
						>\
							<div\
							class=info\
							id=notice\
							>\
								Prosím počkejte, než se natáhne obrázek...\
							</div>\
							<table\
							border=0\
							align=center\
							valign=center\
							><tr><td>\
								<img\
								id=img\
								class=thumbimg\
								src=\"" + src + "\"\
								title=\"" + sDescription + "&#10;" + sCopyright + "&#10;&#10;Po kliknutí na obrázek se okno zavře.\"\
								style=\"cursor: hand;\"\
								onLoad='img_onLoad();'\
								onClick='self.close();'\
								onContextMenu='return false;'\
								></img>\
							</td></td></table>\
						</body>\
					</html>");
	imageWindow.document.close();
}

function writePhoto(sName) {
/*
In document head we have something like this:

<script>
	var photoDir = "../photo/2000/2000-06-17/";
	document.write("<script src=\"" + photoDir + "photoInfo_cs.js\"><\/script>");
</script>

And then in body we call function writePhoto(aName):

<script>
	writePhoto("_01");
</script>

We assume that all photos are jpegs.
*/
	var aName = eval(sName);
	var src = photoDir + sName + ".jpg";
	var aDmns = aName[2].split("|");	//width, height, size in bytes
	var iWidth = parseInt(aDmns[0]);
	var iHeight = parseInt(aDmns[1]);
	var fSize = Math.round(parseFloat(aDmns[2])/102.4)/10;
	document.write(	"<div\
			class=photo\
			>\
				<img\
				src=\"" + src + "\"\
				title=\"" + aName[0] + "&#10;" + iWidth + "x" + iHeight + ", " + fSize + " kB&#10;" + aName[1] + "&#10;&#10;Po kliknutí se otevře okno s obrázkem v původní velikosti.\"\
				class=75\
				onClick='imagePopup(\"" + src + "\", \"" + aName[0] + "\", \"" + aName[1] + "\");'\
				onContextMenu='return false;'\
				></img>\
				<div\
				class=description\
				>"
					+ aName[0] + "\
					<br>"
					+ iWidth + "x" + iHeight + ", " + fSize + " kB\
					<br>"
					+ aName[1] + "\
				</div>\
			</div>");
}

function writeThumbnails(sNames) {
	var aNames = sNames.split(",");
	var iLength = aNames.length;
	//var imgPreload = new Array(iLength);
	document.write("<div class=thumbnails>");
	for (var i=0;i<iLength;i++) {
		writeThumbnail(aNames[i]);
	}
	document.write("</div>");
}

function writeThumbnail(sName) {
	var aData = eval(sName);
	var sTSrc = photoDir + "t" + sName + ".jpg";
	var sSrc = photoDir + sName + ".jpg";
	//imgPreload[i] = new Image();
	//imgPreload[i].src = sSrc;
	var aDmns = aData[2].split("|");	//width, height, size in bytes
	var iWidth = parseInt(aDmns[0]);
	var iHeight = parseInt(aDmns[1]);
	var fSize = Math.round(parseFloat(aDmns[2])/102.4)/10;	
	document.write(	"<div\
			class=thumbnail\
			>\
				<img\
				class=thumbimg\
				src=" + sTSrc + "\
				title=\"" + aData[0] + "&#10;" + iWidth + "x" + iHeight +", " + fSize + " kB&#10;" + aData[1] + "&#10;&#10;Po kliknutí se otevře okno s obrázkem v původní velikosti.\"\
				onClick='imagePopup(\"" + sSrc + "\", \"" + aData[0] + "\" , \"" + aData[1] + "\");'\
				onContextMenu='return false;'\
				></img>\
				<div\
				class=description\
				>"
					+ aData[0] + "\
					<br>"
					+ iWidth + "x" + iHeight + ", " + fSize + " kB\
					<br>"
					+ aData[1] + "\
				</div>\
			</div>");
}

function writeResultTable() {
	document.write(	"<div\
			class=center\
			>\
				<table\
				border=1\
				frame=border\
				rules=all\
				cellspacing=0\
				>\
					<thead>\
						<tr>\
							<th\
							rowspan=2\
							>\
								Pořadí\
							</th>\
							<th\
							rowspan=2\
							>\
								Jméno\
							</th>\
							<th\
							colspan=4\
							>\
								Čtyřboj společnosti C.S.H.\
							</th>\
							<th\
							rowspan=2\
							>\
								Celkem\
								<br>\
								bodů/" + iMaxPoints + "\
							</th>\
						</tr>\
						<tr>\
							<th>\
								1\
							</th>\
							<th>\
								2\
							</th>\
							<th>\
								3\
							</th>\
							<th>\
								4\
							</th>\
						</tr>\
					</thead>\
				<tbody>");
	for (var i=0;i<aResultData.length;i++) {
		document.write("<tr>");
			for (var j=0;j<=6;j++) {
				document.write(	"<td"
						+ ((j==0)?(" align=right"):("")) + "\
						>"
							+ aResultData[i][j] + ((j==0)?("."):("")) + "\
						</td>");
			}
		document.write("</tr>");
	}
	document.write(	"</tbody></table></div>");
}

