/********************************************************************************************/
/* AHAH functions by Phil Ballard                                                           */
/* This code is intended for study purposes.                                                */
/* You may use these functions as you wish, for commercial or non-commercial applications,  */
/* but please note that the author offers no guarantees to their usefulness, suitability or */
/* correctness, and accepts no liability for any losses caused by their use.                */
/********************************************************************************************/

function call_php(url, callMessage, errorMessage)
{
	document.getElementById(elementy[0]).innerHTML = callMessage;
	try 
	{
		req = new XMLHttpRequest(); /* e.g. Firefox */
	}
	catch(e) 
	{
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
		} 
		catch (e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
			} 
			catch (E) 
			{
				req = false;
			} 
		} 
	}
	req.onreadystatechange = function() {responseAjax(elementy[0], errorMessage);};
	req.open("GET",url,true);
	req.send(null);
}

function get_width()
{
	if (parseInt(navigator.appVersion)>3) 
	{
	 if (navigator.appName=="Netscape") 
	 {
		winW = window.innerWidth;
//		winH = window.innerHeight;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) 
	 {
		winW = document.body.offsetWidth;
//		winH = document.body.offsetHeight;
	 }
	}
	return winW; 
}


function responseAjax(pageElement, errorMessage) 
{
	var output = '';
  if(req.readyState == 4) 
	{
  	if(req.status == 200) 
		{
			
			if (pageElement == 'list')
			{
				var el = document.getElementById? document.getElementById(pageElement): document.all[pageElement];
				el.innerHTML = req.responseText;
			}
			else
			{
				//output = req.responseText;
				var elOutput = req.responseText.split("|");
				var hideit = false;
				for(i=0;i<elementy.length;i++)
				{
					var el = document.getElementById? document.getElementById(elementy[i]): document.all[elementy[i]];
					el.innerHTML = elOutput[i];
					if (i!=0)
					{
						if (elOutput[i] != '' && elOutput[i] != undefined)
						{
							el.style.visibility = 'visible';
							hideit = true;
						}
						else
							el.style.visibility = 'hidden';
					}
						//document.getElementById(elementy[i]).innerHTML = elOutput[i];
				}
					if (hideit == true)
					{
						 document.getElementById('copyright').style.visibility = 'hidden';
						 document.getElementById('list').style.visibility = 'hidden';
					}
					else
					{
						 document.getElementById('copyright').style.visibility = 'visible';
						 wi = get_width();
						 if (wi < 900) wi = 900;
						 get_list('get_list.php?w= '+wi, 'Načítám data, chvíli strpení...', 'Error'); 
						 document.getElementById('list').style.visibility = 'visible';
					}
	    } 
    } 
		else 
      document.getElementById(elementy[0]).innerHTML = errorMessage+"\n"+output;
	}
}

function get_list(url2, callMessage, errorMessage) 
{
	document.getElementById('list').innerHTML = callMessage;
	try 
	{
		req = new XMLHttpRequest(); /* e.g. Firefox */
	}
	catch(e) 
	{
		try 
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
		} 
		catch (e) 
		{
			try 
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
			} 
			catch (E) 
			{
				req = false;
			} 
		} 
	}
	req.onreadystatechange = function() {responseAjax('list', errorMessage);};
	req.open("GET",url2,true);
	req.send(null);
}
