  var overmenu = false;
  var lastmenu = "";
  document.onmouseover = hM;
  document.onclick = hideMenu;

  addLoadListener(loadPrograms);
  addLoadListener(loadPolls);

  function addLoadListener(fn)
{
  if(typeof window.addEventListener !='undefined')
  {
    window.addEventListener('load',fn,false);
  }
  else if(typeof document.addEventListener !='undefined')
  {
    document.addEventListener('load',fn,false);
  }
  else if(typeof window.attachEvent !='undefined')    
  {
    window.attachEvent('onload',fn);
  }
  else
  {
    var oldfn=window.onload
    if(typeof window.onload !='function')
	{
	  window.onload=fn;
	}
    else
	{
      window.onload=function(){oldfn();fn();}
    }
  }
} 



function loadPrograms(date)
{ 
  if (document.getElementById('programs') == null){
	  return;
  }
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/loadprograms.php?date=' + date, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('programs').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}


  function openWindow(URL, title, features){
  window.open(URL, title, features);
}

  function changeSubMenu(menuId){
	  element = document.getElementById('subMenu');
	  element.style.display = 'none';
	  switch (menuId){
		  case 4:{
			  position = findPos(document.getElementById('menu0' + menuId));
			  position[0] -= 155;
              element.style.left = position[0] + 'px';
              element.style.top = position[1] + 'px';
			  element.style.display = 'block';
			  element.innerHTML = "<font style=\"font-size: 11pt;\"><strong>RMDSZ</strong></font><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=52\" style=\"color: #ffffff; text-decoration: none;\">&#187; Bihar</a><br />";
			  element.innerHTML += "<font style=\"font-size: 11pt;\"><strong>Alpolg&aacute;rmester</strong></font><br />";
			  element.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=57\" style=\"color: #ffffff; text-decoration: none;\">&#187; V&aacute;rosfejleszt&eacute;s</a><br />";
			  element.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=58\" style=\"color: #ffffff; text-decoration: none;\">&#187; Szoci&aacute;lis / kult&uacute;ra</a><br />";
			  element.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=59\" style=\"color: #ffffff; text-decoration: none;\">&#187; Euror&eacute;gi&oacute;</a><br />";
		  }break;
		  case 5:{
			  position = findPos(document.getElementById('menu0' + menuId));
			  position[0] -= 155;
              element.style.left = position[0] + 'px';
              element.style.top = position[1] + 'px';
			  element.style.display = 'block';
			  element.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=62\" style=\"color: #ffffff; text-decoration: none;\">&#187; Ki mit tud</a><br />";
			  element.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=63\" style=\"color: #ffffff; text-decoration: none;\">&#187; Maj&aacute;lis</a><br />";
		  }break;
		  case 6:{
			  position = findPos(document.getElementById('menu0' + menuId));
			  position[0] -= 155;
              element.style.left = position[0] + 'px';
              element.style.top = position[1] + 'px';
			  element.style.display = 'block';
			  element.innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=page&menu_id=67\" style=\"color: #ffffff; text-decoration: none;\">&#187; Besz&eacute;dek</a><br />";
			  element.innerHTML += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"content.php?goto=video\" style=\"color: #ffffff; text-decoration: none;\">&#187; Vide&oacute;</a><br />";
		  }break;
	  }
  }

  function hM(){
  if (!overmenu){
    timeOn = setTimeout("hideMenu()", 100)
  }
}

  function hideMenu(){
    if (!overmenu){
        document.getElementById("subMenu").style.display = 'none';
    }
  }

  function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}

function loadPolls()
{
  if (document.getElementById('polls') == null){
	  return;
  }
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/loadpolls.php', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('polls').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}

function loadPolls2()
{
  if (document.getElementById('polls') == null){
	  return;
  }
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'includes/loadpolls.php?show_results=true', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('polls').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}

function takeVote(answerId){
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', 'system_components/vote.php?answer=' + answerId, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  loadPolls();
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true;
}

