//metoda vygeneruje adresu pro polozku
function popup2(akce, jazyk, prefix, web_root, polozka,ohref)
{
	switch (akce)
	{
	  case "seo":
			xwidth=500;xheight=320;
			break;
	  case "edit":
			xwidth=500;xheight=400;
			break;

		default:
		  xwidth=500;xheight=200;
			break;
	}
	iMyWidth = (window.screen.width - xwidth ) / 2 ;
	iMyHeight = (window.screen.height - xheight ) / 2;
	shref=web_root+"core/menu/akce.php?action="+akce+"&polozka="+polozka+"&lang="+jazyk+"&web="+prefix+"&TB_iframe=true&width="+xwidth+"&height="+xheight;
	ohref.href=shref;
}

function smaz(polozka)
{
	return confirm(text_delete1+polozka+text_delete2);
}



//pole pro ulozeni id polozek kterym se nastavil onclick
var ax_sets=new Array();
//inicializace nacitani rozklikavacich polozek
function ax_init()
{
	var lis = document.getElementsByTagName("li"); //nactu si vsechny li
	for (var i = 0; i < lis.length; i++)
	{
	  var id_li=false;
		for( var x = 0; x < lis[i].attributes.length; x++ )//projdu li a najdu jen ty co maji id
			if( lis[i].attributes[x].nodeName.toLowerCase() == 'id' )
					id_li=lis[i].attributes[x].nodeValue;				//ulozim si id
		if (id_li!=false)										//pokud id neni nulove
		{
			var bSets=false;
			for( var x = 0; x < ax_sets.length; x++ )//projdu seznam abych zjistil zda uz jsem ji nenastavoval
				if (ax_sets[x]==id_li)
					bSets=true;
			if (bSets==false)
			{
				for( var x = 0; x < lis[i].childNodes.length; x++ ) //projdu deti a hledam tag A obsahujici tridu ax_item
				  if (lis[i].childNodes[x].nodeName.toLowerCase() == 'a')
				  {
					  if (cls.has(lis[i].childNodes[x],"ax_item"))		//zjistim jestli tag A obsahuje tridu ax_item (ty hledam)
					  {
							xFunction="return load(this,'"+id_li+"',1);";		//vytvorime funkci
							xFce=new Function(xFunction);									//vytvorime funkci
			        lis[i].childNodes[x].onclick = xFce;					//na onclick dame vytvorenou funkci
			        ax_sets[ax_sets.length]=id_li;
					  }
					  if (cls.has(lis[i].childNodes[x],"ax_item2"))		//zjistim jestli tag A obsahuje tridu ax_item (ty hledam)
					  {
							xFunction="return load(this,'"+id_li+"',0);";		//vytvorime funkci
							xFce=new Function(xFunction);									//vytvorime funkci
			        lis[i].childNodes[x].onclick = xFce;					//na onclick dame vytvorenou funkci
			        ax_sets[ax_sets.length]=id_li;
					  }
					}
			}
		}
	}
}

function TestAccesskey(idInput)
{
	var nasel=false;
	if (accesskey.length!=0)
	{
		oEl=document.getElementById(idInput);
		new_accesskey=oEl.value;
		for (i=0;i<accesskey.length;i++)
		{
			if (accesskey[i]==new_accesskey)
				nasel=true;
		}
	}
	if (nasel==true)
		alert(accesskey_text);
	return !nasel;
}

function BinSelAll(bSelect)
{
	oEls=document.getElementsByTagName("input");
	for (i=0;i<oEls.length;i++)
	{
		if (cls.has(oEls[i],'bin_chck'))
		{
			if (bSelect)
				oEls[i].checked=true;
			else
				oEls[i].checked=false;
		}
	}
}

function BinInfo(text,oSelect)
{
	if(oSelect.selectedIndex!=0)
	{
		var red=confirm(text);
		if (red==false)
		{
			oEl=document.getElementById('bin_massdel_sel');
			for( var i=0; i<oEl.length; i++ )
			{
				if (i==0)
					value=1;
				else
					value=0;
	      oEl.options[i].selected = value;
	    }
		}
		else
		{
			oElInp=document.getElementById('bin_js_upd');
			if (oElInp)
			{
				oEls=document.getElementsByTagName('input');
				oEls.value='';
				var value='';
				for( var i=0; i<oEls.length; i++ )
				{
					if (cls.has(oEls[i],'bin_chck') && oEls[i].checked)
					{
						if (value.length!=0)
							value+='~';
						value+=oEls[i].value;
					}
				}
				if (value.length>0)
				{
					oElInp.value=value;
					oForm=document.getElementById('bin_massdel');
					if (oForm)
						oForm.submit();
				}
			}
		}
	}
}

//ulozeni reference na XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject();

//pole pro ulozeni nacteni polozek
var ax_loaded=new Array();
// vraci XMLHttpRequest object
function createXmlHttpRequestObject()
{
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)

    alert("Error creating the XMLHttpRequest object.");
  else
    return xmlHttp;
}

//metoda resi nacitani polozek nebo zobrazeni a skryti polozek
function load(url,li_id,redirect)
{
	ajax_item = encodeURIComponent(li_id);			//zjstime id polozky
	use_redirect = encodeURIComponent(redirect);
	var bLoaded=false;													
	for (i=0;i<ax_loaded.length;i++)						//zjistime zda uz jsem podpolozky nacetl
	{
		if (ax_loaded[i]==ajax_item)
		  bLoaded=true;
	}
	if (bLoaded==false)													//neni jeste nacteno
	{
		process();																//nacteme pres ajax menu
    ax_loaded[ax_loaded.length]=ajax_item;		//ulozime si, ze jsme mame nacteno
	}
	else																				//uz jsme nacetli
	{
	  oEl=document.getElementById(ajax_item);		//nacteme polozku		
		for( var x = 0; x < oEl.childNodes.length; x++ ) //projdu deti
		{
		  if (oEl.childNodes[x].nodeName.toLowerCase() == 'ul')		//hledam tag s ul
		  {
			  if (cls.has(oEl.childNodes[x],"hidden"))		//je skryta?
					cls.remove(oEl.childNodes[x],"hidden");		//zobrazime podpolozky
				else
					cls.add(oEl.childNodes[x],"hidden");			//skryjeme podpolozky
			}
		}
	}
	return false;					//vracim false aby nedoslo ke kliknuti
}
// vytvarim asynchroni HTTP pozadavek pouzivajici the XMLHttpRequest objekt
function process()
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    // execute the quickstart.php page from the server
    xmlHttp.open("GET", "core/menu/ax_item.php?item=" + ajax_item + "&redirect=" + use_redirect, true);
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
 }
  else
    // if the connection is busy, try again after one second
    setTimeout('process()', 1000);
}

// executed automatically when a message is received from the server
function handleServerResponse()
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4)
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200)
    {
      // extract the XML retrieved from the server
      Response = xmlHttp.responseText;
      responseXml = xmlHttp.responseXML;
			xmlDoc = responseXml.documentElement;
			result = xmlDoc.firstChild.data;
      // obtain the document element (the root element) of the XML structure
      // update the client display using the data received from the server
			var SpanNode = document.createElement("span");
			SpanNode.innerHTML=result;
			if (Response.length!=0)
			{
				if (typeof(menu_index_root)!="undefined" && menu_index_root.length!=0)
				{
					oHref=SpanNode.childNodes[0].getElementsByTagName("a");
					if (oHref.length>0)
					{
						var re=new RegExp("index.php");
						for(i=0;i<oHref.length;i++)
							oHref[i].href=oHref[i].href.replace(re,menu_index_root);
					}
				}
      	document.getElementById(ajax_item).appendChild(SpanNode.childNodes[0]);
      	ax_init();
      }
    }
    // a HTTP status different than 200 signals an error
    else
    {
      alert("Je problen a pristupen na server: " + xmlHttp.statusText);
    }
  }
}

evt.add(window, "load", ax_init);
