/* epg */

/* katadyn */

function switchKatadyn(flag){
	var KATADYNNode = document.getElementById("KATADYN");
	if (flag == "on"){
		KATADYNNode.style.display = "block";
	} else {
		KATADYNNode.style.display = "none";
	}
}

function getInfoSnezka(){
	var snezkaDaysNd = document.getElementById("snezkaDays");
	var snezkaHoursNd = document.getElementById("snezkaHours");
	var snezkaMinutesNd = document.getElementById("snezkaMinutes");
	var snezkaSecondsNd = document.getElementById("snezkaSeconds");
	var snezkaYearsNd = document.getElementById("snezkaYears");
	
	var dateAct = new Date();
	var dateActTime = dateAct.getTime();
	var totalMs = parseInt(snezkaTime) - parseInt(dateActTime);
	
	var snezkaYears = (totalMs/(86400000*365.2422)).toString().substring(0,7);	
	var snezkaDays = parseInt(totalMs/86400000);
		var residueSnezkaDays = totalMs % 86400000;
	var snezkaHours = parseInt(residueSnezkaDays/3600000);
		var residueSnezkaHours = residueSnezkaDays % 3600000;
	var snezkaMinutes = parseInt(residueSnezkaHours/60000);
		var residueSnezkaMinutes = residueSnezkaHours % 60000;
	var snezkaSeconds = parseInt(residueSnezkaMinutes/1000);		
	
	snezkaDaysNd.innerHTML = snezkaDays;
	snezkaHoursNd.innerHTML = snezkaHours;
	snezkaMinutesNd.innerHTML = snezkaMinutes;
	snezkaSecondsNd.innerHTML = snezkaSeconds;
	snezkaYearsNd.innerHTML = snezkaYears;
	
	timerSnezka = setTimeout("getInfoSnezka()",1000); 
}

function activateFlag(node,cc){
	node.src = "commonsources/flags/active/"+cc+".gif";
}

function deactivateFlag(node,cc){
	node.src = "commonsources/flags/passive/"+cc+".gif";
}

/* lod */
var isBtn_search_ftxActive = new Boolean(false);
var isBtn_search_hdrActive = new Boolean(false);

function checkLod(){
	searchedstringNd = document.getElementById("searchedstring");
	btn_search_ftxNd = document.getElementById("btn_search_ftx");	
	btn_search_hdrNd = document.getElementById("btn_search_hdr");
	ssLength = searchedstringNd.value.length;
	//alert(ssLength);
	if (ssLength < searchedStringMinAllowed){ 
		btn_search_ftxNd.src = "commonsources/buttons/passive/btn_search_ftx.gif";
		btn_search_hdrNd.src = "commonsources/buttons/active/btn_search_hdr.gif";
		isBtn_search_ftxActive = false;
		isBtn_search_hdrActive = true;
	} else {
		btn_search_ftxNd.src = "commonsources/buttons/active/btn_search_ftx.gif";
		btn_search_hdrNd.src = "commonsources/buttons/passive/btn_search_hdr.gif";
		isBtn_search_ftxActive = true;
		isBtn_search_hdrActive = false;		
	}
}

/* art */
	// article menu function
function changeVisibility(id){
	idNodeSubmenu = document.getElementById(id+"-M");
	idNodeImage = document.getElementById(id+"-I");
	nodeVisibility = idNodeSubmenu.style.display;
	//alert(nodeVisibility);
	if (nodeVisibility == 'block'){ 
		idNodeSubmenu.style.display = "none"; 
		idNodeImage.src = imgPlusUrl;
	}
	else {
		idNodeSubmenu.style.display = "block";
		idNodeImage.src = imgMinusUrl;
	}
}  

/* tra */
function changeTab(tabSel,arrow){
	var tabSelResult = tabSel;
	if ((arrow == 'l' && actTab == 1) || (arrow == 'r' && actTab == sumchapters)) return;
	if (arrow == 'l') tabSelResult = actTab - 1;
	if (arrow == 'r') tabSelResult = actTab + 1;
		
	for(i=1; i<=sumchapters; i++){
		var tabCurrentNd = document.getElementById("tab_"+i);
		var chapterCurrentNd = document.getElementById("chapter_"+i);
		var iconLeftTNd = document.getElementById("iconLeft_t");
		var iconRightTNd = document.getElementById("iconRight_t");
		var iconLeftBNd = document.getElementById("iconLeft_b");
		var iconRightBNd = document.getElementById("iconRight_b");

		if(tabSelResult == i){
			tabCurrentNd.className = "tab1"; 
			chapterCurrentNd.style.display = "block";
		} else {
			tabCurrentNd.className = "tab0";			
			chapterCurrentNd.style.display = "none";
		}
	}
	actTab = tabSelResult;
	
	if(actTab == 1){ 
		iconLeftTNd.src = iconUrl+"nothing.gif";
		iconLeftBNd.src = iconUrl+"nothing.gif";
		iconLeftTNd.style.cursor = "";
		iconLeftBNd.style.cursor = "";
	} else {
		iconLeftTNd.src = iconUrl+"left.gif";
		iconLeftBNd.src = iconUrl+"left.gif";
		iconLeftTNd.style.cursor = "pointer";
		iconLeftBNd.style.cursor = "pointer";
	}
	if(actTab == sumchapters){ 
		iconRightTNd.src = iconUrl+"nothing.gif";
		iconRightBNd.src = iconUrl+"nothing.gif";
		iconRightTNd.style.cursor = "";
		iconRightBNd.style.cursor = "";		
	} else {
		iconRightTNd.src = iconUrl+"right.gif";
		iconRightBNd.src = iconUrl+"right.gif";
		iconRightTNd.style.cursor = "pointer";
		iconRightBNd.style.cursor = "pointer";		
	}
	//load images
	for (i in ilinkArr){
		if(ilinkArr[i][0] == tabSelResult){
			idImg = ilinkArr[i][1];
			imgNd = document.getElementById("imgsmall_"+idImg);
			imgNd.src = "sources/"+doctypeImg+"/"+yearImg+"/"+docidImg+"/images/small/"+idImg+".jpg"
		}
	}
}

	// chapter title hints
function showChapterTitle(tab,arrow){
	var tabResult = tab;
	if ((arrow == 'l' && actTab == 1) || (arrow == 'r' && actTab == sumchapters)) return;
	if (arrow == 'l') tabResult = actTab - 1;
	if (arrow == 'r') tabResult = actTab + 1;
	var chapterTitleActTNd = document.getElementById("chapterTitle_t");
	var chapterTitleActBNd = document.getElementById("chapterTitle_b");
	var chapterTitleTextAct = document.getElementById("chapterTitle_"+tabResult+"_text").innerHTML;
	chapterTitleActTNd.innerHTML = chapterTitleTextAct;
	chapterTitleActBNd.innerHTML = chapterTitleTextAct;
}

function hideChapterTitle(){
	var chapterTitleActTNd = document.getElementById("chapterTitle_t");
	var chapterTitleActBNd = document.getElementById("chapterTitle_b");
	chapterTitleActTNd.innerHTML = "";
	chapterTitleActBNd.innerHTML = "";	
}

/* gbk */
var isBtn_submitActive = new Boolean(false);

function checkGbk(){

	btn_submitNd = document.getElementById("btn_submit");
	author = document.getElementById("author").value;
	comment = document.getElementById("comment").value;
	email = document.getElementById("email").value;
	charsWritten = comment.length;
	charsLeft = maxGbkChars - charsWritten;
	
	isAuthor = (author.length == 0)?false:true;
	isComment = (comment.length <= minGbkChars)?false:true;
	isCommentOK = (charsLeft < 0)?false:true;
	//isSpam = (comment.indexOf("http") != -1)?true:false;
	isNotAllowedChars = ((author.indexOf("&") != -1) || (email.indexOf("&") != -1) || (comment.indexOf("&") != -1))?true:false;

	spamNd = document.getElementById("spam");
	//if(isSpam) alert(spamNd.innerHTML);
	notAllowedCharsNd = document.getElementById("notAllowedChars");
	if(isNotAllowedChars) alert(notAllowedCharsNd.innerHTML);	

	charsRemainingNd = document.getElementById("charsRemaining");
	if(charsLeft < 0) charsRemainingNd.className = "gb-info-minus"; 
		else charsRemainingNd.className = "gb-info-plus";
	charsRemainingNd.innerHTML = charsLeft;
	
	if(isAuthor && isComment && isCommentOK && !isNotAllowedChars){
		btn_submitNd.src = "commonsources/buttons/active/btn_submit.gif";
		isBtn_submitActive = true;
		utilCheckGbk("none","none","none","block");
	} else {
		btn_submitNd.src = "commonsources/buttons/passive/btn_submit.gif";
		isBtn_submitActive = false;
		if(!isAuthor) utilCheckGbk("block","block","","none");
			else utilCheckGbk("","none","","");
		if(!isComment) utilCheckGbk("block","","block","none");
			else utilCheckGbk("","","none","");	
		if(!isCommentOK) utilCheckGbk("","","","none");
	}
}

function utilCheckGbk(d_fk,d_a,d_c,d_fo){
	formKONd = document.getElementById("formKO");
	author_msgNd = document.getElementById("author_msg");
	comment_msgNd = document.getElementById("comment_msg");
	formOkNd = document.getElementById("formOK");
	
	if (d_fk != "") formKONd.style.display = d_fk;
	if (d_a != "") author_msgNd.style.display = d_a;
	if (d_c != "") comment_msgNd.style.display = d_c;
	if (d_fo != "") formOkNd.style.display = d_fo;
}
	// because of bad behavior of xhtml div
function utilIE(){
	//alert("ok");
	commentNd = document.getElementById("comment");
	commentNd.value = "";
}

/* tan */
	//call renamed functions above
function vloz(id){
	showTanText(id);
}

function smaz(){
	hideTanText();
}
	
function showTanText(id){
	var text = document.getElementById("pho_xxxxx_"+id+"_text").innerHTML;
	document.getElementById("tanText").innerHTML = text;
	addToSum('A',id);	
}

function hideTanText(){
	document.getElementById("tanText").innerHTML = "<br/>";
}

/*	//not implemented in new version
function showTanImageDetail(){
}
function hideTanImageDetail(){
}
*/
	//not implemented in new version
function ukaz(n){
}
function zrusMaly(){
}

/*
COMMON FUNCTIONS	
*/
	
/* form functions (lop,lod) */
	// fills name/surname based on actual combobox value
function fillPersonInfo(nd, role){
	personNameNd = document.getElementById("name_"+role);
	personSurnameNd = document.getElementById("surname_"+role);
	personImgNd = document.getElementById("img_"+role);
	personJsNameNd = document.getElementById("js_name_"+role+"_"+nd.value);	
	personJsSurameNd = document.getElementById("js_surname_"+role+"_"+nd.value);
	personJsVerbalIdNd = document.getElementById("js_verbalId_"+role+"_"+nd.value);
	imgName = (nd.value == "")?"questionmark":nd.value;
	// result
	personImgNd.src = "commonsources/personphotos/"+imgName+".jpg";
	personNameNd.value = personJsNameNd.innerHTML;
	personSurnameNd.value = personJsSurameNd.innerHTML;
}

	//resets combobox with persons' id
function resetPersonId(role){
	personIdNd = document.getElementById("id_"+role);
	if(personIdNd == null){
		//alert("ok");
		return;
	}
	personIdNd.options[0].selected = true;
}

	//submits form (no button of type submit)
function submitForm(action) {
	if (action == "FTX" && isBtn_search_ftxActive == false) return;
	if (action == "HDR" && isBtn_search_hdrActive == false) return;	
	if (action == "GBE" && isBtn_submitActive == false) return;
	formNd = document.getElementById("form");
	actionNd = document.getElementById("action");
	actionNd.value = action;
	if (action == "GBE"){
		uptoyouNd = document.getElementById("uptoyou");
		uptoyouNd.value = "cyketarusk";
		cookieidNd = document.getElementById("cookieid");
		cookieidNd.value = getCookieId();
	}
	formNd.submit();
}

/*
function test(){
	alert(document.getElementById("body").scrollTop);
}
*/
function hintClickable(node, mode, type){
	//type = bestimg mrg1, photo-img cp
	if (mode == "over"){
		if (type == "bestimg") node.className = "bestimg2 mrg1";
		if (type == "worldsm") node.className = "mainblock worldsm2";
		if (type == "iconLod") node.className = "icon-2";
		if (type == "icon") node.className = "icon2";
		if (type == "iconLop") node.className = "photo-img2 cp";		
	} 
	if (mode == "out"){
		if (type == "bestimg") node.className = "bestimg mrg1";
		if (type == "worldsm") node.className = "mainblock worldsm";
		if (type == "iconLod") node.className = "icon-0";
		if (type == "icon") node.className = "icon";		
		if (type == "iconLop") node.className = "photo-img cp";	
	} 
}
/* images functions (lop,art,tra,gan,epg) */
function showImageDetail(type,pagetype,doctype,year,docid,id){
	var ix;
	var iy;
	var src;
	var doctype;
	if (type == 'world'){
		ix = worldX;
		iy = worldY;
		src = "commonsources/basic/world_overview.png";
	} else {
		actDocid = docid;
		actId = id;
		doctype = (doctype == 'T')?'travelogues':'articles';
		ix = imgLargeX;
		iy = imgLargeY;
		src = "sources/"+doctype+"/"+year+"/"+docid+"/images/large/"+id+".jpg"
	}
	if (pagetype == 'lop'){
		x_formNd = document.getElementById("x_form");
		x_formNd.style.display = "none";
	}

	var bodyNd = document.getElementById("body");
	var imageDetailNd = document.getElementById("imageDetail");
	imageDetailNd.src = src;
	var fromTop = (type == 'world')?0:bodyNd.scrollTop;
	imageDetailNd.style.top = (fromTop + iy)+"px";
	imageDetailNd.style.left = ix + "px";
	imageDetailNd.style.display = "block";
}
	//hides large image and displays form in case of lop
function hideImageDetail(pagetype){
	var imageDetailNd = document.getElementById("imageDetail");
	imageDetailNd.style.display = "none";
	if (pagetype == "lop"){
		x_formNd = document.getElementById("x_form");
		x_formNd.style.display = "block";
	}
	hidePhotoText();
}


function showPhotoText(e,docid,id){
	docid = (docid == "")?actDocid:docid;
	id = (id == "")?actId:id;

	var text = document.getElementById("pho_"+docid+"_"+id+"_text").innerHTML;
	var floatingTextNd = document.getElementById("floatingText");
	var bodyNd = document.getElementById("body");
	
	var top;
	var left;
		if (isNS || isFF) {
			top = e.pageY;
			left = e.pageX;
		} else {
			top = e.clientY;
			left = e.clientX;
		}


	floatingTextNd.innerHTML = text;
	floatingTextNd.style.top = (isNS || isFF)?(textTopAccomodate + top)+"px":(bodyNd.scrollTop + top + textTopAccomodate);
	floatingTextNd.style.left = (left + textLeftAccomodate)+"px";
	floatingTextNd.style.display = "block";		
}

function hidePhotoText(){
	var floatingTextNd = document.getElementById("floatingText");
	floatingTextNd.style.display = "none";
}

function resetSelCrit(pagetype){
	for (i in formFields){
		if(formFields[i][1].indexOf(pagetype) != -1){
			//alert(formFields[i][0]);
			var fieldId = formFields[i][0];
			if(formFields[i][2] == "I"){
				fieldNd = document.getElementById(fieldId);
				fieldNd.value = "";
			}
			if(formFields[i][2] == "L"){
				fieldNd = document.getElementById(fieldId);
				fieldNd[0].selected = true;
			}
			if(formFields[i][2] == "C"){
				fieldNd = document.getElementById(fieldId);
				fieldNd.checked = false;
			}
			if(formFields[i][2] == "O"){
				role = formFields[i][3];
				imgNd = document.getElementById("img_"+role);
				verbalId1Nd = document.getElementById("verbalId1_"+role);
				verbalId2Nd = document.getElementById("verbalId2_"+role);
				if (imgNd != null){
					imgNd.style.display = "none";
					verbalId1Nd.style.display = "none";
					verbalId2Nd.style.display = "none";
				}
			}
		}
	}
	if(pagetype == "lod") checkLod();
}

function showNote(id){
	note1Nd = document.getElementById(id);
	note2Node = document.getElementById(id+"K");
	note1Nd.style.display = "none";
	note2Node.style.display = "inline";	
}

function hideNote(id){
	note1Nd = document.getElementById(id);
	note2Node = document.getElementById(id+"K");
	note1Nd.style.display = "inline";
	note2Node.style.display = "none";		
}

function changeAnimChoice(docid){
	tanNd = document.getElementById("tan_"+docid);
	ganNd = document.getElementById("gan_"+docid);
	tanDisplay = (tanNd.style.display == "block")?"none":"block";
	ganDisplay = (ganNd.style.display == "block")?"none":"block";
	tanNd.style.display = tanDisplay;
	ganNd.style.display = ganDisplay;
	timerAnimChoice = setTimeout("changeAnimChoice('"+docid+"')",changeAnimChoiceInterval); 
}

/* loc*/
function openGlink(base, id, type, markers, language, doctype, year, docid){
	var locWidth;
	var locHeight;
	if (type == "V") locHeight = "500";
		else locHeight = "400";
	window.open(base+""+language+"/loc/"+doctype+"/"+year+"/"+docid+".xhtml?id="+id+"&type="+type+"&markers="+markers+"","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=500, height="+locHeight+", top=30, left=30");
}

/* stat */
function openStatChart(base,language,type,queryID,dateLimit){
	if (isIE != true){
		alert("Switch to Internet explorer to see charts! This browser has problem with loading statistical data.");
		return;
	}
	window.open(base+""+language+"/statistika-webu/grafy/"+type+"/graf-"+queryID+"-"+dateLimit+".xhtml","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=565, height=420, top=30, left=30");
}

/* standings */
function openStandings(base,docid,dateLimit){
	window.open(base+"/statistikaCestopisu-"+docid+"-"+dateLimit+".xhtml","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=800, height=600, top=30, left=30");
}