
function open_login_window()
{
	window.open('login.mini.php', 'login', 'left=100,top=100,width=180,height=230,resizable=no,scrollbars=no,location=no,status=no,menubar=no');
}

// ------------

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

// ------------

function getXMLHTTP()
{
  var x = null;
  try {x = new ActiveXObject("Msxml2.XMLHTTP")}
  catch(e) {try {x = new ActiveXObject("Microsoft.XMLHTTP")}
  catch(e) {x = null}}
  if(!x && typeof XMLHttpRequest != "undefined") {x = new XMLHttpRequest();}
  return x;
}

function urlencode(s)
{
  return encodeURIComponentNew(s);
  /*
	if(encodeURIComponent) return encodeURIComponent(s);
  if(escape) return escape(s);
  return s;
  */
}

function CreateList(p, q, a, cb, dnrt)
{
	if(!p) return;

	p.innerHTML = '';

	if(a.length > 0)
	{
		ul = document.createElement('ul');

		for(var i = 0, j = a.length; i < j; i++)
		{
			li = document.createElement('li');
			li.innerHTML += eval(cb+'(\''+a[i]+'\')');
			ul.appendChild(li);
		}

		p.appendChild(ul);
	}

	if(p.innerHTML == '' && q.length > 0)
	{
		p.innerHTML = dnrt == null ? 'Nincs találat!' : dnrt;
		if(q.length == 1) p.innerHTML += ' (túl rövid a beírt szöveg)';
	}
}

function FindOption(sel, opt)
{
  for(var i = 0; i < sel.length; i++)
  	if(sel.options[i].value == opt.value && sel.options[i].text == opt.text)
  		return true;
  return false;
}

function CheckAllOptions(sel)
{
  for(var i = 0; i < sel.length; i++)
  	sel.options[i].selected = true;
}

function AddOption(sel, text, value)
{
	var o = document.createElement("OPTION");
	o.text = text;
	o.value = value;
	try {sel.add(o, null);}
	catch(e) {sel.add(o);}
}

function CopySelOption(dst, src)
{
  for(var i = 0; i < src.length; i++)
  {
  	if(src.options[i].selected && !FindOption(dst, src.options[i]))
  	{
  		AddOption(dst, src.options[i].text, src.options[i].value)
			break;
  	}
  }
}

function DelSelOption(sel)
{
  for(var i = sel.length-1; i >= 0; i--)
  {
  	if(sel.options[i].selected)
  	 	sel.remove(i);
  }
}

function DelOptions(sel)
{
	  for(var i = sel.length-1; i >= 0; i--)
			sel.remove(i);
}

// ------------

function ol(s,w)
{
	overlib(s,HAUTO,VAUTO,WIDTH,w);
}

function olw(s)
{
	overlib(s,WRAP,HAUTO,VAUTO);
}

function oltn(id,type,kod,idx)
{
	s = '<img width="128" src=\"getpicture.php?id='+id+'&type='+type+'&code='+kod+'&idx='+idx+'&tn=1\" />';
	overlib(s,WIDTH,128);
}

function showobj(x)
{
	if(x != null && x.className == "hidden") x.className = "shown";
}

function hideobj(x)
{                          
	if(x != null && x.className == "shown") x.className = "hidden";
}

function showid(name)
{
	showobj(document.getElementById(name));
}

function hideid(name)
{
	hideobj(document.getElementById(name));
}

function flip(name)
{
	x = document.getElementById(name);
	y = document.getElementById('img_'+name);
	if(y == null) y = document.images['img_'+name];

	if(x == null) return false;
	
//	x.style.display = x.style.display == "block" ? "none" : "block";

	var visible = false;

	if (x.className == "hidden") {
		if(y) y.src="images/buttons/folder_open.gif";
		// x.className = "shown";
		showobj(x);
		visible = true;
	} else {
		if(y) y.src="images/buttons/folder.gif";
		// x.className = "hidden";
		hideobj(x);
		visible = false;
	}

	 return visible;
}

function swto(id,i,s,e)
{
	for(j = s; j < e; j++)
	{
		if(i == j) flip(id + j);
		else hideid(id + j);
	}

	return false;
}

function swtonc(id,i,s,e)
{
	for(j = s; j < e; j++)
	{
		obj = document.getElementById(id + 'hdr' + j);
		
		if(i == j)
		{
			showid(id + j);
			if(obj) obj.style.fontWeight = 'bold';
			// if(obj) obj.style.borderBottomStyle = 'solid';
			// if(obj) obj.style.borderWidth = '1px';
		}
		else
		{
			hideid(id + j);
			if(obj) obj.style.fontWeight = 'normal';
			// if(obj) obj.style.borderBottomStyle = 'none';
			// if(obj) obj.style.borderWidth = '0px';
		}
	}
}

function hand(f)
{
	f.style.cursor='hand';
	if(f.style.cursor!='hand') f.style.cursor='pointer';
}

// -----------

var _elem;
var _posY = 0;
var _lasttop = 0;

function fixIE2()
{
    var root = document.documentElement?document.documentElement:document.body;
	var _top = root.scrollTop + 15;
	if(_top < _posY) _top = _posY;
//	if(_lasttop == _top) {window.setInterval("fixIE2()", 1000); return;}
	// var _inc = (_top - _lasttop) / 2;
	var _inc = (_top - _lasttop);
	_elem.style.top = (_lasttop += _inc) + "px";
//	window.setInterval("fixIE2()", 100);
//	window.setInterval("fixIE2()", 1000);
};

function fixIE()
{
	if(!document.all) return; // IE only
    _elem = document.getElementById('profile_index');
    if(!_elem) return;
    _elem.style.position="absolute";
    var root = document.documentElement?document.documentElement:document.body;
    _posY = _elem.offsetTop;
    _lasttop = _posY;
    root.onscroll = fixIE2;
//    window.setInterval("fixIE2()", 1000);
}

function resizeSymptoms()
{
	for(i = 0; ; i++)
	{
		obj = document.getElementById('sym' + i);
		if(!obj) break;
		obj.style.width = (obj.parentNode.offsetWidth-20) + 'px';
	}
}

function checknum(o)
{
	var anum = /(^$)|(^\d+$)|(^\d+\.\d+$)/;
	if(!anum.test(o.value))
		alert("!");
}

// ------------

function hgy(i)
{
	switch(i)
	{
	case 1: return '<b>OGYI</b> által kiadott helyettesítő gyógyszerek';
	case 2: return '<b>Hatóanyag és farmakológia</b> szerinti helyettesítő gyógyszerek';
	case 3: return '<b>Farmakológia</b> szerinti helyettesítő gyógyszerek';
	case 4: return '<b>Receptírás</b>';
	}
}

function olhgy(i)
{
	overlib(hgy(i),LEFT,VAUTO,WIDTH,200);
}

// ------------

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function StopDemo()
{
	var player = getFlashMovieObject('demo');
	if(player) player.StopPlay();
}

// ------------

function EmptyPassword()
{
	var login_password = document.getElementById('login_password');
	if(login_password) login_password.value = '';
}

// ------------

function chkreg()
{
	if(confirm('Ön már regisztrált felhasználónk?\n\nHa igen, válassza az OK gombot.'))
	{
		open_login_window();
	}
	else
	{
		window.location = "register.php";
	}
}

// ------------

function flipoldnewmenu()
{
	flip('oldmenu');

	var d = new Date;
	
	if(flip('newmenu'))
	{
		d.setDate(d.getDate() + 365);
		document.cookie = 'newmenu=1; expires=' + d.toGMTString( ) + '; path=/;';
	}
	else
	{
		d.setDate(d.getDate() - 1);
		document.cookie = 'newmenu=1; expires=' + d.toGMTString( ) + '; path=/;';
	}
}

function init(section, subsection)
{
	MM_preloadImages('images/top_news_over.jpg','images/top_search_over.jpg','images/top_information_over.jpg');
	
	setTimeout("EmptyPassword()", 100);
	
/*
	if(section == 'search' && subsection == 'profile')
	{
		fixIE();
	}
*/
	if(section == 'search' && subsection == '')
	{
    window.onresize = resizeSymptoms;
    resizeSymptoms();
	}
	else if(section == 'settings' && subsection == 'gyogyszerek')
	{
		if(window.HatoanyagInit) HatoanyagInit();
		if(window.PharmaInit) PharmaInit();
	}
	else if(section == 'gyogyszerek' && subsection == '')
	{
		if(window.GyogyszerekInit) GyogyszerekInit();
	}
	else if(section == 'gyogyszerek' && subsection == 'nev')
	{
		if(window.GyNevInit) GyNevInit();
	}
	else if(section == 'gyogyszeraropt' && subsection == '')
	{
		if(window.GyNevInit) GyNevInit();
	}
	
	else if(section == 'bno')
	{
		if(window.BNOInit) BNOInit();
	}
}