var objs = new Array();
var images_path = "images/";

// Vytvori cookie
function createCookie(name,value,days)
	{
	if (days)
		{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		}
	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";
	}

function readCookie(name)
	{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	//alert("C " + ca);

	for(var i=0; i< ca.length;i++)
		{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
		}
	return;
	}

function eraseCookie(name)
	{
	createCookie(name,"",-1);
	}

// Funkcie pre Calendar
var oldLink = null;
function setActiveStyleSheet(link, title)
	{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++)
		{
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title"))
			{
      		a.disabled = true;
	 	    if(a.getAttribute("title") == title) a.disabled = false;
		    }
		}

	if (oldLink) oldLink.style.fontWeight = 'normal';
	oldLink = link;
	link.style.fontWeight = 'bold';
	return false;
	}

function showCalendar(id, format, showsTime, showsOtherMonths)
	{
  	var el = document.getElementById(id);
  	if (_dynarch_popupCalendar != null)
		{
	    // we already have some calendar created
    	_dynarch_popupCalendar.hide();                 // so we hide it first.
		}
	else
		{
	    // first-time call, create the calendar.
    	var cal = new Calendar(1, null, selected, closeHandler);
	    // uncomment the following line to hide the week numbers
	    // cal.weekNumbers = false;
	    if (typeof showsTime == "string")
			{
			cal.showsTime = true;
			cal.time24 = (showsTime == "24");
		    }
		if (showsOtherMonths)
			{
      		cal.showsOtherMonths = true;
		    }
	    _dynarch_popupCalendar = cal;                  // remember it in the global var
	    cal.setRange(1900, 2070);        // min/max year allowed.
	    cal.create();
  		}

	_dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
	_dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
	_dynarch_popupCalendar.sel = el;                 // inform it what input field we use

	_dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  	return false;
	}

function selected(cal, date)
	{
	cal.sel.value = date; // just update the date in the input field.
	if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
	    cal.callCloseHandler();
	}

function closeHandler(cal)
	{
	cal.hide();
  	_dynarch_popupCalendar = null;
	}

// vrati objekt so zadanym id
function gId(name)
  {
  return document.getElementById(name);
  }

// HTTP Request
// -----------------------------------------------------------------------------
// nacita objekt podla browsera
function loadXMLObject()
	{
	var xmlhttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try
		{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
		{
		try
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		catch (E)
			{
			xmlhttp = false;
			}
		}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch (e)
		{
		xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest)
		{
		try
			{
			xmlhttp = window.createRequest();
			}
		catch (e)
			{
			xmlhttp=false;
			}
		}
	return xmlhttp;
	}

// zobere stranku
function getPage(link, funct, method, postMessage)
	{

	// sposob akym s aposle
	if(!method)
		method = "GET";

	if(!funct)
		{
		funct = "alert('xmlhttp.responseText = ' + xmlhttp.responseText);";
		}

	var xmlhttp = loadXMLObject();
	if(!xmlhttp)
		{
		alert('No object!');
		return;
		}

	xmlhttp.open(method, link, true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	// spracovanie odpovede
	xmlhttp.onreadystatechange = function()
		{
		if (xmlhttp.readyState==4)
			{
			// zavola sa dana funkcia
			eval(funct);
			}
		}

	xmlhttp.send(postMessage);
	}

//getPage('test2.php?load=allPage&type=3', 'handleFunc(xmlhttp)');
//getPage('test2.php?load=allPage&type=3', 'handleFunc2(xmlhttp)', 'POST', 'laoded=22');
//getPage('test2.php?load=allPage&type=3', 'document.getElementById(\'loadT\').innerHTML = xmlhttp.responseText;', 'GET');
//getPage('test2.php?load=nothin');


// nahra nejaky obsah (HTML) do nejakeho dalsieho objektu + loadne javascripty pre plnu funkcnost
function loadItem(id, content)
	{
	// loads content
	dv = document.createElement('div');
	dv.innerHTML = content;

	document.getElementById(id).innerHTML = "";
	document.getElementById(id).appendChild(dv);


	// for ie necessary to load JS explicitly
	var items = content.split(/<script.*>/);
	var js = '';
	// vybere vsetky JS a spusti ich
	for(var i in items)
		{
		if(i == 0)
			continue;

		if(typeof(items[i]) == 'string')
			{
			script = items[i].split(/<\/script.*>/);
			if(script.length > 1)
				{
				//alert(script[0]);
				try
					{
					window.eval(script[0]);

					var head = document.getElementsByTagName('head')[0];
					var scr = document.createElement('script');
					scr.type = 'text/javascript';
					scr.text = script[0];
					head.appendChild(scr);
					}
				catch(e)
					{
					alert(e.message);
					}
				}
			}
		}
	}


/**
 *
 **/
ids = new Array("prodBasic", "prodDesc", "prodParam", "prodPrice");
function switchBlockDisplay(id)
	{
	for(var i in ids)
		{
		if(gId(ids[i]))
			gId(ids[i]).style.display = 'none';
		}

	gId(id).style.display = '';
	}

/**
 *
 * @access public
 * @return void
 **/
function showImage(imgSrc)
	{
	if(!gId('galleryDiv'))
		{
		newDiv = document.createElement("div");
		newDiv.id = 'galleryDiv';
		newDiv.style.position = 'absolute';
		newDiv.style.padding = '5px';
		newDiv.style.background = 'white';
		newDiv.style.border = '1px solid black';
		newDiv.onclick = function(){showImage('');};
		newDiv.innerHTML = "<img id='galleryDivImg' src='' alt='' />";
		document.body.appendChild(newDiv);
		}

	gId('galleryDiv').style.left = xMousePos + 'px';
	gId('galleryDiv').style.top = yMousePos + 'px';
	gId('galleryDivImg').src = imgSrc;
	if(imgSrc.length > 0)
		gId('galleryDiv').style.display = '';
	else
		gId('galleryDiv').style.display = 'none';
	//alert('SHow: ' + imgSrc);
	}

function showText(text)
	{
	if(!gId('textDiv'))
		{
		newDiv = document.createElement("div");
		newDiv.id = 'textDiv';
		newDiv.style.position = 'absolute';
		newDiv.style.padding = '5px';
		newDiv.style.background = 'white';
		newDiv.style.border = '1px solid black';
		//newDiv.onclick = function(){showText('');};
		document.body.appendChild(newDiv);
		}
	gId('textDiv').style.left = xMousePos + 'px';
	gId('textDiv').style.top = yMousePos + 'px';
	gId('textDiv').innerHTML = text;
	if(text.length > 0)
		gId('textDiv').style.display = '';
	else
		gId('textDiv').style.display = 'none';
	}

//document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = captureMousePosition;

// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen

function captureMousePosition(e)
	{
    if (document.layers)
		{
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    	}
	else if (document.all)
		{
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
    	}
	else if (document.getElementById)
		{
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
	    }
	}

