// keresések
function searching() {
	// keresés a felső sávból
	document.getElementById("queryform").action="/portal.aspx/search/query";
	document.getElementById("queryform").target="_self";
	var q = document.getElementById("userq").value;
	if (q == '') {
		alert("Nincs megadva keresőfeltétel.");
		return false;
	}
	if (1 >= q.length) {
		alert("Túl rövid a keresőfeltétel.");
		return false;
	}
	if (q.search(/^[\*\?]*$/) == 0) {
		alert("Túl általános a keresőfeltétel.");
		return false;
	}
	if (document.getElementById("siteweb2").checked == true) {
		document.getElementById("queryform").action="http://www.google.hu/search";
		document.getElementById("queryform").target="_blank";
		document.getElementById("qvalue").value = q;
		return true;
	}
	var terms = q.split(" ");
	var sum = "";
	for (var i=0; i!= terms.length; i++) sum += "[stem:" + terms[i] + "]";	
	var sq = '[rank,100:[domain:[and:[and:' + q + '][field,visible:[<=:' + LAW + ']]]][sum:' + sum + ']]';
	document.getElementById("qvalue").value = sq;
	return true;
}
// keresések vége
// útvonal sáv
var docpathname = "";
var docpathtitle = "";
function writepath(npth, tpth) {
	// útvonalsáv
	docpathname = npth;
	docpathtitle = tpth;
	var v = '<a href="javascript:loadtoclist()" class="talloz" title="Listaszerű tallózás megjelenítése (és elrejtése)">Tallózás...</a><a href="javascript:loadtree()" class="fagomb" title="Tartalomfa megjelenítése (és elrejtése)">Fa...</a> ';
	v += '<span id="pathroot"></span><div id="toclistroot" style="display:none"></div>';
	document.write(v);
	fillpath(npth, tpth);
}
function fillpath(npth, tpth) {
	var o = document.getElementById("pathroot");
	if (!(o)) return;
	var snp = ('/' + npth).split("/");
	var stp = tpth.split("|");
	var i;
	var cp = '';
	var v = '';
	for(i = 0; i < stp.length; i++) {
		cp += '/' + snp[i];
		v += '<a href="/portal.aspx/list' + cp.substring(1) + '" onclick="pathlink(this)">' + stp[i] + '</a>'
		// if (i < stp.length - 1) v += ' · ';
		if (i < stp.length - 1) v += ' » ';
	}
	o.innerHTML = v;
}
function pathlink(o) {
	// link from toclist?
	var tl = document.getElementById("toclistroot");
	if (tl) if (tl.treeorlist) if (tl.treeorlist == "list") {
		o.href += "?toclist";
	}
}
// útvonal sáv vége
// toclist
function loadtoclist() {
	var o = document.getElementById("toclistroot");
	if (o.treeorlist == "list") {
		o.innerHTML = "";
		o.style.display = "none";
		o.treeorlist = "";
		return;
	}
	o.innerHTML = "";
	o.treeorlist = "list";
	o.innerHTML = '<table class="toclisttable" cellspacing="0" cellpadding="0"><tr id="toclisttr"><td></td></tr></table>';
	o.style.display = "";
	atocrow = document.getElementById("toclisttr");
	var p = new Object();
	p.path = "";
	p.nme = "";
	var i = docpathtitle.indexOf("|");
	if (i == -1) i = docpathtitle.length;
	p.title = docpathtitle.substring(0, i);
	p.titlepath = p.title;
	p.level = -1;
	loadlist(p);
	synctoclist(docpathname);
}
var atocrow;
function loadlist(n) {
	// loading nodes of n
	var st = loadUrl("/portal.aspx/toc/node?p=" + n.path);
	if (st == "0") {
		alert("Nincs kapcsolat a kiszolgálóval.\nA lista nem tölthető le.");
		return;
	}
	var t = st.split("|");
	var i = 0;
	// html specific
	while (atocrow.cells.length > n.level + 2) {
		atocrow.deleteCell(atocrow.cells.length - 1);
	}
	while (atocrow.cells.length < n.level + 2) {
		atocrow.insertCell(-1);
	}
	atocrow.cells[n.level + 1].innerHTML = '<div class="toclistblock"></div>';
	atocrow.cells[n.level + 1].vAlign = "top";
	// html specific end
	for(i = 1; i < t.length - 1; i+=4) {
		addlist(n, t[i + 0], t[i + 1], t[i + 3]);
	}
}
function addlist(p, nme, title, childcount) {
	// add new node to p node
	var n = document.createElement("div");
	nme = nme.replace(/\//gi, '');
	n.nme = nme;
	if (p.path.length == 0) {
		n.path = nme;
		n.titlepath = p.titlepath + '|' + title;
	} else {
		n.path = p.path + '/' + nme;
		n.titlepath = p.titlepath + '|' + title;
	}
	n.title = title;
	n.childcount = childcount;
	n.level = p.level + 1;
	// html specific
	n.className = "toclistrow";
	//n.noWrap = true;
	var ih = "";
	var i = 0;
	if (childcount > 0) {
		ih += '<a href="#" onclick="dolist(this);return false;">' + title + ' ></a>';
	} else {
		ih += '<a href="/portal.aspx/list/' + n.path + '" onclick="toclistlink(this)">' + title + '</a>';
	}
	n.innerHTML = ih;
	n = atocrow.cells[n.level].lastChild.appendChild(n);
	//n = p.lastChild.appendChild(n);
	return n;
}
function toclistlink(o) {
	// link from toclist
	var tl = document.getElementById("toclistroot");
	if (tl) if (tl.treeorlist) if (tl.treeorlist == "list") {
		o.href += "?toclist";
	}	
}
function dolist(o) {
	// loading this list
	var p = o.parentNode;
	if (p.childcount > 0) {
		loadlist(p);
	}
	var i = 0;
	var os = atocrow.cells[p.level].lastChild.childNodes;
	for (i = 0; i < os.length; i++) {
		if (os[i].path == p.path) {
			os[i].className = "toclistrowsel";
		} else {
			os[i].className = "toclistrow";
		}
	}
	fillpath(p.path, p.titlepath);
}
function synctoclist(current_document) {
	// selecting current_document node in toclist, loading if necessary
	var d = utf8Decode(unescape(current_document));
	var ps = d.split("/");
	var i;
	var j;
	var os;
	var o;
	for(i = 0; i < ps.length; i++) {
		if (ps[i].length == 0) {
			break;
		}
		os = atocrow.cells[i].lastChild.childNodes;
		for(j = 0; j < os.length; j++) {
			if (os[j].nme == ps[i]) break;
		}
		if (j >= os.length) {
			alert("Nincs ilyen útvonal:" + ps[i] + "\n" + d);
			break;
		} else {
			dolist(os[j].firstChild);
		}
	}
}
// toclist vége
// felső sáv
function selbasket(o) {
	// kosár váltása
	document.location = "/portal.aspx/basket/show/" + o.options[o.selectedIndex].value;
	o.selectedIndex = 0;
}
function doctooldisplay(onoff) {
	var st = document.getElementById("searchtools");
	var dt = document.getElementById("doctools");
	var ht = document.getElementById("highlighttools");
	if (onoff == true) {
		st.style.display = "";
		ht.style.display = "none";
		dt.style.display = "";
	} else {
		st.style.display = "";
		dt.style.display = "none";
		ht.style.display = "";
	}
}
function searchtooldisplay(onoff) {
	var st = document.getElementById("searchtools");
	var ht = document.getElementById("highlighttools");
	var dt = document.getElementById("doctools");
	if (onoff == true) {
		st.style.display = "";
		ht.style.display = "none";
	} else {
		dt.style.display = "none";
		st.style.display = "none";
		ht.style.display = "none";
	}
}
function prevmatch() {
	showmatch(-1);
	return false;
}
function nextmatch() {
	showmatch(1);
	return false;
}
function showmatch(v) {
	if (showmatch) {
		showmatch(v);
	}
}
function clearmatch(v) {
	if (clearmatch) {
		clearmatch();
	}
}
function prevdoc() {
	showdoc("prev");
	return false;
}
function nextdoc() {
	showdoc("next");
	return false;
}
function showdoc(v) {
	if (currdoc)
		if (currdoc != '')
			if (document.location.href.indexOf("q=") != -1) {
				var i = document.location.href.indexOf("?");
				todourl = "/portal.aspx/document/prevnexthit" + document.location.href.substr(i) + "&prevornext=" + v + "&currdoc=" + currdoc;
				setTimeout("dourl()", 10);
			}
}
var todourl = "";
function dourl() {
	if (todourl == "") return;
	window.location.href = todourl;
}
function prevtoc() {
	showtoc("prev");
	return false;
}
function nexttoc() {
	showtoc("next");
	return false;
}
function showtoc(v) {
	if (currdoc)
		if (currdoc != '') {
			var i = document.location.href.indexOf("?");
			todourl = "/portal.aspx/document/prevnext?prevornext=" + v + "&currdoc=" + currdoc;
			setTimeout("dourl()", 10);
			return false;
		}
}
// felső sáv vége
// tartalomjegyzék
// tree
// build functions
function loadNode(n) {
// loading nodes of n
var st = loadUrl("/portal.aspx/toc/node?p=" + n.path);
if (st == "0") {
	alert("Nincs kapcsolat a kiszolgálóval.\nA tartalomjegyzék nem tölthető le.");
	return;
}
var t = st.split("|");
var i = 0;
for(i = 1; i < t.length - 1; i+=4) {
	addNode(n, t[i + 0], t[i + 1], t[i + 3]);
}
n.loaded = true;
}
function addNode(p, nme, title, childcount) {
// add new node to p node
var n = document.createElement("div");
nme = nme.replace(/\//gi, '');
n.nme = nme;
if (p.path.length == 0) {
	n.path = nme;
	n.titlepath = title;
} else {
	n.path = p.path + '/' + nme;
	n.titlepath = p.titlepath + '/' + title;
}
n.title = title;
n.childcount = childcount;
n.level = p.level + 1;
n.loaded = false;
n.checked = p.checked;
// html specific
n.className = "treerow";
n.noWrap = true;
var ih = "";
var i = 0;
if (n.level == 1) {
	ih += '<span></span>';
}
for(i = 1; i < n.level; i++) {
	ih += '&#160;&#160;&#160;&#160;&#160;&#160;&#160;';
}
if (childcount > 0) {
	ih += '<a href="#" onclick="doPlusMinus(this, 0);return false;" class="treepm">&#160;+&#160;</a>';
} else {
	ih += '<span style="margin-left: 14px" >&#160;</span>';
}
ic = "(&#160;&#160;)";
if (n.checked == true) ic = "(×)";
ih += '<a href="#" onclick="doCheck(this);return false;" class="treecheck">' + ic + '</a>';
ih += '<a onclick="nodeClick(this)" href="/portal.aspx/list/' + n.path + '" class="treelink" onmouseover="nodeover(this)" onmouseout="nodeout(this)">' + title + '</a>';
ih += '<br/><div style="display:none"></div>';
n.innerHTML = ih;
n = p.lastChild.appendChild(n);
return n;
}
// tree operation functions
function doPlusMinus(o, onoff) {
// making plusminus operation
var p = o.parentNode;
if (p.childcount > 0) {
	if (p.loaded == false) {
		loadNode(p);
		p = o.parentNode;
	}
	// láthatóság
	var l = p.lastChild;
	var i = 0;
	var a = p.childNodes[1];
	if (l.style.display == 'none' || onoff == 'on') {
		l.style.display = 'block';
		a.innerHTML = "&#160;−&#160;";
	} else {
		l.style.display = 'none';
		a.innerHTML = "&#160;+&#160;";
	}
}
}
// checkboxes function
var chkshow = false;
function chkboxs(b) {
// setting visibility of checkboxes on/off
var ss = document.styleSheets[0];
var r;
if (IE) {
	r = ss.rules[0].style;
} else {
	r = ss.cssRules[0].style;
}
if (b == true) {
	r.display = "";
} else {
	r.display = "none";
}
chkshow = b;
}
function doCheck(o) {
// making checkbox check on/off
var p = o.parentNode;
var cc = p.checked;
var tc = !cc;
var pc = false;
if (p.path.length > 0) {
	pc = p.parentNode.parentNode.checked;
}
if (pc) return;
checkNode(p, tc);
}
function checkNode(n, onoff) {
var i;
n.checked = onoff;
var a = n.childNodes[2];
if (onoff) {
	a.innerHTML = "(×)";
} else {
	a.innerHTML = "(&#160;&#160;)";
}
var cs = n.lastChild.childNodes;
for (i = 0; i < cs.length; i++) {
	checkNode(cs[i], onoff);
}
}
// nxt functions
function synchronize(current_document) {
// selecting current_document node in tree, loading if necessary
var d = utf8Decode(unescape(current_document));
var ps = d.split("/");
var i;
var j;
var o = document.getElementById('treeroot').lastChild.lastChild;
var os;
for(i = 0; i < ps.length; i++) {
	if (ps[i].length == 0) {
		setSel(o);
		break;
	}
	doPlusMinus(o.lastChild, 'on');
	os = o.lastChild.childNodes;
	for(j = 0; j < os.length; j++) {
		if (os[j].nme == ps[i]) break;
	}
	if (j >= os.length) {
		alert("Nincs ilyen útvonal:" + ps[i] + "\n" + d);
		break;
	} else {
		o = os[j];
		if (i == ps.length - 1) {
			setSel(o);
		}
	}
}
}
// selection functions
var sel = null;
var seltimer;
var selobj;
function nodeover(o) {
	selobj = o.parentNode;
	seltimer = setTimeout("setSel(selobj)", 1000);
}
function nodeout(o) {
	clearTimeout(seltimer);
}
function setSel(o) {
if (sel != null) {
	sel.className = 'treelink';
}
sel = o.childNodes[3];
sel.className = 'treelinksel';
sel.focus();
}
function nodeClick(o) {
setSel(o.parentNode);
}
// nxt domain
function getDomain() {
// returning domain path from checked nodes
var d = getDomainR(document.getElementById('root').lastChild.lastChild);
return d;
}
function getDomainR(o) {
var v = "";
if (o.checked == true) {
	v += o.nme;
} else if (o.haschildren == 'yes' && o.loaded == true) {
	var v2 = '';
	var v3 = '';
	var o2 = o.lastChild.firstChild;
	while(true) {
		v3 = getDomainR(o2);
		if (v3.length != 0) {
			if (v2.length != 0) v2 += ',';
			v2 += v3;
		}
		o2 = o2.nextSibling;
		if (!(o2)) break;
	}
	if (v2.length != 0) {
		if (o.nme.length != 0) {
			v += o.nme + "(" + v2 + ")";
		} else {
			v += v2;
		}
	}
}
return v;
}
// converter functions
function utf8Decode(str) {
	var out = "";
	for (var i = 0; i < str.length; ) {
		var c = str.charCodeAt(i);
		if (c <	0x80) { 
			out	+= String.fromCharCode(c);
			i++;
		}
		else if (c < 0xE0) {
			out += String.fromCharCode((str.charCodeAt(i) - 0xC0) * 0x40 + (str.charCodeAt(i + 1) - 0x80));
			i += 2;
		} else {
			out += String.fromCharCode((str.charCodeAt(i) - 0xE0) * 0x1000 + (str.charCodeAt(i + 1) - 0x80) * 0x40 + (str.charCodeAt(i + 2) - 0x80));
			i += 3;
		}
	}
	return out;
}
function utf8Encode(str) {
	var	out	= "";
	for(var	i =	0; i < str.length; i++) { 
		var	c =	str.charCodeAt(i);
		if (c <	0x80) {
			out	+= String.fromCharCode(c);
		} 
		else if	(c < 0x800)	{
			out	+= String.fromCharCode(0xC0	+ (c / 0x40));
			out	+= String.fromCharCode(0x80	+ (c % 0x40));
		}
		else {
			out	+= String.fromCharCode(0xE0	+ (c / 0x1000));  // c >> 12
			c =	c %	0x1000;
			out	+= String.fromCharCode(0x80	+ (c / 0x40));	 //	c >> 6
			out	+= String.fromCharCode(0x80	+ (c % 0x40));
		}
	}
	return out;
}
// general functions
function loadtree() {
// creating and loading root nodes
	var o = document.getElementById('toclistroot');
	if (!(o)) return;
	if (o.treeorlist == "tree") {
		o.innerHTML = "";
		o.style.display = "none";
		o.treeorlist = "";
		return;
	}
	o.treeorlist = "tree";
	o.style.display = "";
	o.innerHTML = '<table class="treeroot" cellspacing="0" cellpadding="0"><tr><td id="treeroot"><div style="display:block"></div></td></tr></table>';
	o = document.getElementById('treeroot');
	o.level = 0;
	o.path = "";
	o.nme = "";
	o.checked = false;
	o.childcount = 1;
	var i = docpathtitle.indexOf("|");
	if (i == -1) i = docpathtitle.length;
	var n = addNode(o, "", docpathtitle.substring(0, i), 1)
	doPlusMinus(n.lastChild, 'on');
	/*var i = 0;
	var bs = n.lastChild.childNodes;
	for(i = 0; i < bs.length; i++) {
		doPlusMinus(bs[i].lastChild, 'on');
	} */
	synchronize(docpathname);
}
// IO functions
var IE = (navigator.appName.indexOf("Microsoft") != -1);
function loadUrl(url) {
// xmlhttp request
var xmlhttp;
try {
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
	} else {
		if (window.ActiveXObject) {
			// code for IE
			IE = true;
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (xmlhttp) {
				xmlhttp.open("GET",url,false);
				xmlhttp.send();
			}
		}
	}
	if (xmlhttp) {
		return xmlhttp.responseText;
	}
} catch(e) {
}
return "0";
}
// tartalomjegyzék vége
// tartalomlista
// lista
function turn(i, onoff) {
	var o = document.getElementById(i);
	if (o) {
		if (onoff == "onoff") {
			if (o.className == "off") {
				onoff = "on";
			} else {
				onoff = "off";
			}
		}
		o.className = onoff;
	}
}
function writepager(cn, pn, ipp) {
	var i;
	if (ipp >= cn) return;
	var s = '<select name="pn" onchange="choosepage(this)">';
	var o = "<option value=", o2 = ">", o3 = "</option>";
	for(i = 1; cn >= i; i+=ipp) {
		s += o + '"' + i + '"' + ((pn > i-1 && i + ipp > pn)?' selected="true"':'') + o2 + i + " - " + ((cn > i + ipp - 2)?i + ipp - 1:cn) + o3;
	}
	s += "</select>";
	if (pn>ipp) {
		s = '<a href="javasc' + 'ript://" onclick="pageback(this)"><img src="/templates/szkkstyle/arrow_left.gif" /></a> ' + s;
	} else {
		s = '<img src="/templates/szkkstyle/arrow_left_off.gif" /> ' + s;
	}
	if (pn + ipp > cn) {
		s = s + ' <img src="/templates/szkkstyle/arrow_right_off.gif" />';
	} else {
		s = s + ' <a href="javasc' + 'ript://" onclick="pagenext(this)"><img src="/templates/szkkstyle/arrow_right.gif" /></a>';
	}
	document.write(s);
}
var selobj;
function choosepage(o) {
	if (!(o)) o = selobj;
	var pn = o.options[o.selectedIndex].value;
	var s = window.location.search + "";
	var i = s.indexOf("&pn="), j;
	if (0 > i) if (s.indexOf("?pn=") == 0) i = 0;
	if (i > -1) {
		i += 4;
		j = s.indexOf("&", i);
		if (j == -1) j = s.length;
		s = s.substring(0, i) + pn + s.substring(j);
	} else {
		if (s == "") {
			s = "pn=" + pn;
		} else {
			s += "&pn=" + pn;
		}
	}
	window.location.search = s;
}
function choosesort(o) {
	var od = o.selectedIndex;
	var s = window.location.search + "";
	var i = s.indexOf("&od="), j;
	if (0 > i) if (s.indexOf("?od=") == 0) i = 0;
	if (i > -1) {
		i += 4;
		j = s.indexOf("&", i);
		if (j == -1) j = s.length;
		s = s.substring(0, i) + od + s.substring(j);
	} else {
		if (s == "") {
			s = "od=" + od;
		} else {
			s += "&od=" + od;
		}
	}
	window.location.search = s;		
}
function choosehitsort(o) {
	if (top.isTop) {
		top.sfdata.SortBy = o.selectedIndex;
	}
	var od = o.options[o.selectedIndex].value;
	var s = window.location.search + "";
	var i = s.indexOf("&s="), j;
	if (0 > i) if (s.indexOf("?s=") == 0) i = 0;
	if (i > -1) {
		i += 3;
		j = s.indexOf("&", i);
		if (j == -1) j = s.length;
		s = s.substring(0, i) + od + s.substring(j);
	} else {
		if (s == "") {
			s = "s=" + od;
		} else {
			s += "&s=" + od;
		}
	}
	window.location.search = s;		
}
function pagenext(o) {
	var s = o.previousSibling.previousSibling;
	s.selectedIndex += 1;
	selobj = s;
	setTimeout("choosepage()", 20);
}
function pageback(o) {
	var s = o.nextSibling.nextSibling;
	s.selectedIndex -= 1;
	selobj = s;
	setTimeout("choosepage()", 20);
}
// lista vége
// hasonlók sávja
function showid(id) {
	var o = document.getElementById(id);
	if (!(o)) return;
	o.style.display = '';
}
function hideid(id) {
	var o = document.getElementById(id);
	if (!(o)) return;
	o.style.display = 'none';
}
function filltablesimilar() {
	setTimeout("filltablesimilarreal()", 100);	
	if (location.search == "?toclist") loadtoclist();
}
function filltablesimilarreal() {
	var o = document.getElementById("tablesimilar");
	if (o) {
		o.innerHTML = '<table cellspacing="0" cellpadding="0"><tr><td valign="top" width="20px" class="tdelso"><div class="list4"><b>HASONLÓK</b><br/><a href="/portal.aspx/search/query?q=&pcd=' + currdoc + '&ncd=&m=100&title=similardoc" style="font-size:9pt;font-weight:normal">Teljes&#160;lista...</a></div></td>' + 
		loadUrl("/portal.aspx/search/similar?pcd=" + currdoc + "&quantity=100") + '</tr></table>';
	}
	if (currmsg.substr(0, 5) == "ERROR") alert(currmsg);
}
// menü, amely valójában az up1.xsl-ben található
function menu(){
// ezen függvényt felülírja az up1.xsl-ben lévő függvény. Már ha az betöltődik...
}