// Elektronicky obchod
function format (expr, decplaces) {
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces) {
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function catItem(kod, id, rocnik, cena, nazov) {
	this.kod = kod
	this.id = id
	this.rocnik = rocnik
	this.cena = cena
	this.nazov = nazov
}

// Menu kategorii tovarov
function divObject(obj) {
        this.style = obj;
        this.document = obj.document;
}
function simpleArray() {
        this.item = 0;
}
function imgStoreItem(theName, theSrc, w, h) {
        this.name = theName;
        this.src = theSrc;
        this.obj = null;
        this.w = w;
        this.h = h;
        if (theBrowser.canCache) {
                this.obj = new Image(18, 18);
                this.obj.src = theSrc;
        }
}
function imgStoreObject() {
        this.count = -1;
        this.img = new imgStoreItem;
        this.find = imgStoreFind;
        this.add = imgStoreAdd;
        this.getSrc = imgStoreGetSrc;
        this.getTag = imgStoreGetTag;
}
function imgStoreFind(theName) {
        var foundItem = -1;
        for (var i = 0; i <= this.count; i++) {
                if (this.img[i].name == theName) {
                        foundItem = i;
                        break;
                }
        }
        return foundItem;
}
function imgStoreAdd(theName, theSrc, w, h) {
        if (theSrc) {
        var i = this.find(theName);
        if (i == -1) {
                this.img[++this.count] = new imgStoreItem(theName, theSrc, w, h);
        } else {
                this.img[i].name = theName;
                this.img[i].src = theSrc;
                this.img[i].w = w;
                this.img[i].h = h;
        }
        }
}
function imgStoreGetSrc(theName) {
        var i = this.find(theName);
        return (i == -1) ? '' : this.img[i].src;
}
function imgStoreGetTag(theName, iconID) {
        var i = this.find(theName);
        var Found = '';
        if (i >= 0) {
                with (this.img[i]) {
                        if (src != '') {
                                Found = '<img src=' + '"' + src +  '" width=' + w + ' height=' + h + ' border=0 align="top"';
                                if (iconID != '') {
                                        Found += ' name="' + iconID + '" ';
                                }
                        }
                }
                Found += '>';
        }
        return Found;
}
// The MenuItem object.  This contains the data and functions for drawing each item.
function MenuItem (id, type, text, url, status, item, parent) {
        this.id = id;
        this.type = type;
        this.text = text;
        this.url = url;
        this.status = status;
        this.target = "display";
        this.onClickFunc = "";
        this.nextItem = item;
        this.FirstChild = -1;
        this.parent = parent;
        this.isopen = false;
        this.isSelected = false;
        this.divObj = null;
        this.spanObj = null;
        this.draw = DrawItem;
        this.PMIconName = getPMIconName;
        this.setImg = setImage;
        this.setIsOpen = SetIsOpen;
        this.setSelected = SetSelected;
        this.mouseOver = mouseOver;
        this.mouseOut = mouseOut;
}
function DrawItem (indentStr) {
        var tmp = '="return parent.theMenu.entry[' + this.id + '].';
        var iconTag = imgStore.getTag(this.PMIconName(), 'plusMinusIcon' + this.id);
        var aLine = '<nobr>' + indentStr;
        if (this.FirstChild != -1) {
                aLine += '<A HREF="javascript:parent.theMenu.toggle(' + this.id + ')" name="plusMinus' + this.id + '" ';
                aLine += 'onMouseOver' + tmp + 'mouseOver(\'plusMinusIcon\');" ';
                aLine += 'onMouseOut' + tmp + 'mouseOut(\'plusMinusIcon\');">';
                aLine += iconTag + '</A>';
        } else {
                aLine += iconTag;
        }
//j.p - k odovzdávaným parametrom pridá kód používateľa
	if ( (this.type == 'Document') && (this.url.indexOf('zoznam', 0) >= 0) ) {
//jp2008		this.onClickFunc = 'this.href=this.href + "&uid=" + parent.text.cartFrame.cart.uid.value';
		this.onClickFunc = 'this.href=this.href + "&uid=" + parent.text.cartFrame.document.cart.uid.value';
		this.onClickFunc = 'addUid(this)';
	}
//
        var imgName = this.type + ((this.isSelected) ? 'Selected' : '');
	
        if (imgStore.getSrc(imgName) == '') {imgName = this.type;}
        var theEntry = imgStore.getTag(imgName, 'docIcon' + this.id) + this.text;
        aLine += '<SPAN CLASS="' + ((this.FirstChild != -1) ? 'node' : 'leaf') + '">'
//j.p - rozbalí sa folder aj po kliknutí na docIcon, resp. text
	if (this.type == 'Folder') {
                aLine += '<A HREF="javascript:parent.theMenu.toggle(' + this.id + ')" name="folder' + this.id + '" ';
                aLine += 'onMouseOver' + tmp + 'mouseOver(\'docIcon\');" ';
                aLine += 'onMouseOut' + tmp + 'mouseOut(\'docIcon\');" Title="' + this.status + '">';
                aLine += theEntry + '</A>';
	} else {
	        if ((this.url != '') || (theMenu.wizardInstalled)) {
        	        aLine += '<A HREF="';
                	aLine += (theMenu.wizardInstalled) ? 'javascript:void(0)"' : (this.url + '" TARGET="' + this.target +'" ');
	                aLine += 'onClick="parent.theMenu.itemClicked(' + this.id + ');';
        	        aLine += (this.onClickFunc != '') ? 'parent.' + this.onClickFunc + ';" ' : '" ';
                	aLine += 'onMouseOver' + tmp + 'mouseOver(\'docIcon\');" ';
	                aLine += 'onMouseOut' + tmp + 'mouseOut(\'docIcon\');" Title="' + this.status + '">';
        	        aLine += theEntry + '</A>';
	        } else {
//jp2008        	        aLine += theEntry;
        	        aLine += theEntry + '</A>';
	        }
	}
//
        aLine += '</SPAN></nobr><BR>';
        return aLine
}
function getPMIconName() {
        var iconName = 'icon' + ((this.FirstChild != -1) ? ((this.isopen == true) ? 'Minus' : 'Plus') : 'Join');
        iconName += (this.id == 0) ? ((this.nextItem == -1) ? 'Only' : 'Top') : ((this.nextItem == -1) ? 'Bottom' : '');
        return iconName;
}
function setImage(imgID, imgName) {
        var imgSrc = imgStore.getSrc(imgName);
        if (imgSrc != '') {
                if (theBrowser.hasDHTML) {
//                        if (this.divObj) { this.divObj.document.images[imgID].src = imgSrc; }
                        if (this.divObj) { self.menu.document.images[imgID].src = imgSrc; }
                } else {
                        if (theBrowser.canCache) {
                                if(self.menu) {
                                        if (self.menu.document.images[imgID]) {self.menu.document.images[imgID].src = imgSrc;}
                                }
                        }
                }
        }
}
function SetIsOpen (isOpen) {
        if (this.isopen != isOpen) {
                this.isopen = isOpen;
                this.setImg('plusMinusIcon' + this.id, this.PMIconName());
//j.p - zmení sa ikona foldera, open-close
		if (this.type == 'Folder') {
        		imgName = this.type + ((this.isopen == true) ? 'Open' : '');
	                this.setImg('docIcon' + this.id, imgName);
		}
//
                return true;
        } else { return false; }
}
function SetSelected (isSelected) {
        this.isSelected = isSelected;
        this.setImg('docIcon' + this.id, this.type + ((isSelected) ? 'Selected' : ''));
}
function mouseOver(imgName) {
        self.menu.status = '';  //Needed for setStatus to work on MSIE 3 - Go figure!?
        var newImg = '';
        if (imgName == 'plusMinusIcon') {
                newImg = this.PMIconName();
                setStatus('Click to ' + ((this.isopen == true) ? 'collapse.' : 'expand.'));
        } else {
                if (imgName == 'docIcon') {
                        newImg = this.type + ((this.isSelected) ? 'Selected' : '');
                        setStatus(this.status);
                }
        }
        if (theBrowser.canOnMouseOut) { this.setImg(imgName + this.id, newImg + 'MouseOver'); }
        return true;
}
function mouseOut(imgName) {
        clearStatus();
        var newImg = '';
        if (imgName == 'plusMinusIcon') {
                newImg = this.PMIconName();
        } else {
                if (imgName == 'docIcon') {
                var imgSrc = imgStore.getSrc(imgName);
                        newImg = this.type + ((this.isSelected) ? 'Selected' : '');
                        if (imgStore.getSrc(newImg) == '') { newImg = this.type; }
                }
        }
        if (theBrowser.canOnMouseOut) { this.setImg(imgName + this.id, newImg); }
        return true;
}
// The Menu object.  This is basically an array object although the data in it is a tree.
function Menu () {
        this.count = -1;
        this.autoScrolling = false;
        this.modalFolders = false;
        this.linkOnExpand = false;
        this.toggleOnLink = false;
        this.lastPMClicked = -1;
        this.selectedEntry = -1;
        this.menuTop = 20;
        this.entryHeight = 18;
        this.wizardInstalled = false;
        this.entry = new MenuItem;
        this.addMenu = AddMenu;
        this.addChild = AddChild;
        this.draw = MenuDraw;
        this.drawALevel = DrawALevel;
        this.refresh = refreshMenu;
        this.reload = reloadMenu;
        this.refreshDHTML = refreshMenuDHTML;
        this.itemClicked = itemClicked;
        this.setEntry = setEntry;
        this.setEntryByURL = setEntryByURL;
        this.setAll = setAll;
        this.openAll = openAll;
        this.closeAll = closeAll;
        this.findEntry = findEntry;
        this.toggle = toggle;
}
function AddMenu (addTo, type, text, url, status) {
        var theNI = -1;
        var theP = -1;
        if ((url == '') && (theBrowser.canJSVoid)) {url = 'javascript:void(0);';}
        if (addTo == -1) { addTo = this.count; }
        
        if (this.count++ != -1) {
                theNI = this.entry[addTo].nextItem;
                theP = this.entry[addTo].parent;
                this.entry[addTo].nextItem = this.count;
        }
        this.entry[this.count] = new MenuItem(this.count, type, text, url, status, theNI, theP);
        return this.count;
}
function AddChild (addTo, type, text, url, status) {
        if ((url == '') && (theBrowser.canJSVoid)) {url = 'javascript:void(0);';}
        if (this.count == -1) {
                this.addMenu (addTo, type, text, url, status);
        } else {
                if (addTo < 0) { addTo = this.count; }
                var childID = this.entry[addTo].FirstChild;
                if (childID < 0) {
                        this.count++;
                        this.entry[this.count] = new MenuItem(this.count, type, text, url, status, -1, addTo);  
                        this.entry[addTo].FirstChild = this.count;
                } else {
                        while (this.entry[childID].nextItem != -1) {
                                childID = this.entry[childID].nextItem;
                        }
                        this.addMenu (childID, type, text, url, status)
                }
        }
        return this.count;
}
function MenuDraw() {
        this.drawALevel(0, '', true);
        if (theBrowser.hasDHTML) {
                this.refreshDHTML();
        } else {
                if ((this.lastPMClicked > 0) && theBrowser.mustMoveAfterLoad) {
                        self.menu.location = self.menu.location.pathname + '#plusMinus' + this.lastPMClicked;
                        this.lastPMClicked = 0;
                }
        }
}
function DrawALevel(firstItem, indentStr, isVisible) {
        var currEntry = firstItem;
        var tempStr = "";
        var aLine = "";
        var e = null;
        while (currEntry > -1) {
                e = this.entry[currEntry];
                aLine = e.draw(indentStr);
                if (theBrowser.hasDHTML) {
                        var menuBottom = (this.count * this.entryHeight) + this.menuTop;
                        var divName = 'entryDIV' + currEntry
                        var spanName = 'entrySPAN' + currEntry
                        aLine = '<DIV ID="' + divName + '" CLASS="menuItem">' + aLine + '</DIV>';
                        self.menu.document.writeln (aLine);
//                        if (theBrowser.code == "MSIE") {
                        if ((theBrowser.code == "MSIE") || (theBrowser.code == "NS" && theBrowser.version >= 5)) {
//                                e.divObj = self.menu.document.all[divName];
                                e.divObj = self.menu.document.getElementById(divName);
                        } else {
                                e.divObj = new divObject(self.menu.document[divName]);
                        }
                        e.divObj.style.top = menuBottom
                } else {
                        self.menu.document.writeln (aLine);
                }
                if (e.FirstChild > -1) {
                        if ((theBrowser.hasDHTML) || (e.isopen && isVisible)) {
                                tempStr = (e.nextItem == -1) ? 'iconBlank' : 'iconLine';
                                this.drawALevel(e.FirstChild, indentStr + imgStore.getTag(tempStr, ''), (e.isopen && isVisible));
                        }
                }
                currEntry = e.nextItem;
        }
}
function refreshMenu(positionMenu) {
        if (theBrowser.hasDHTML) {
                this.refreshDHTML(positionMenu);
        } else {
                this.reload(positionMenu);
        }
}
function reloadMenu(positionMenu) {
        if (theBrowser.hasDHTML) {
                self.menu.location.reload();
        } else {
                var newLocation = self.menu.location.pathname;
                if (positionMenu) {
                        if (theBrowser.mustMoveAfterLoad == false) {
                                newLocation += "#plusMinus" + this.lastPMClicked;
                                this.lastPMClicked = 0;
                        }
                } else {
                        this.lastPMClicked = 0;
                }
                if (theBrowser.hasRentrantBug) {
                        setTimeout("self.menu.replace('" + newLocation + "');", 200);
                } else {
                        self.menu.replace(newLocation);
                }
        }
}
function refreshMenuDHTML(positionMenu) {
        var nextItemArray = new simpleArray
        var level = 1;
        var currEntry = 0;
        var isVisible = true;
        var lastVisibleLevel = 1;
        var yPos = this.menuTop;
        var e = null;
        var s = null;
        while (level > 0) {
                e = this.entry[currEntry];
                s = e.divObj.style
                if (isVisible) {
                        s.top = yPos;
                        s.visibility = 'visible';
                        yPos += theMenu.entryHeight;
                        lastVisibleLevel = level;
                } else {
                        s.visibility = 'hidden';
                }
                if (e.FirstChild > -1) {
                        isVisible = (e.isopen == true) && isVisible;
                        nextItemArray[level++] = e.nextItem;
                        currEntry = e.FirstChild;
                } else {
                        if (e.nextItem != -1) {
                                currEntry = e.nextItem;
                        } else {
                                while (level > 0) {
                                        if (nextItemArray[--level] != -1) {
                                                currEntry = nextItemArray[level];
                                                isVisible = (lastVisibleLevel >= level);
                                                break;
                                        }
                                }
                        }
                }
        }
        var pmc = this.lastPMClicked
        if (pmc >= 0) {
                e = this.entry[pmc];
                var srTop = e.divObj.style.top
                var srBot = (e.nextItem > 0) ? this.entry[e.nextItem].divObj.style.top : yPos;
                var curTop = self.menu.pageYOffset;
                var curBot = curTop + self.menu.innerHeight;
                if ((srBot > curBot) || (srTop < curTop)) {
                        var scrBy = srBot - curBot;
                        if (srTop < (curTop + scrBy)) { scrBy = srTop - curTop; }
                        self.menu.scrollBy(0, scrBy);
                }
        }
}
function itemClicked(entryNo) {
        var e = this.entry[entryNo]
        if ((e.url != '') && (e.url != 'javascript:void(0);')) {
                if (this.selectedEntry >= 0) {this.entry[this.selectedEntry].setSelected(false);}
                this.selectedEntry = entryNo;
                if (entryNo >= 0) {e.setSelected(true);}
//j.p.
            if ( (e.type == 'Document') && (e.url.indexOf('zoznam', 0) >= 0) ) {
//jp2008                e.url = e.url + '&uid=' + parent.text.cartFrame.cart.uid.value;
                e.url = e.url + '&uid=' + parent.text.cartFrame.document.cart.uid.value;
//jp2008                parent.text.controlFrame.control.data.value=e.url;
                parent.text.controlFrame.document.control.data.value=e.url;
            }
        }
        if (this.wizardInstalled) {
                self.text.menuItemClicked(entryNo);
        }
        if (this.toggleOnLink) {this.toggle(entryNo);}
}
function setEntry(entryNo, state) {
        var mc = false;
        var cl = ',' + entryNo + ',';
        var e = this.entry[entryNo];
        this.lastPMClicked = entryNo
        mc = e.setIsOpen(state) || mc;
        var p = e.parent;
        while (p >= 0) {
                cl += p + ',';
                e = this.entry[p];
                mc = (e.setIsOpen(true)) || mc;
                p = e.parent;
        }
        if (this.modalFolders) {
                for (var i = 0; i <= this.count; i++) {
                        if (cl.indexOf(',' + i + ',') < 0) {
                                mc = this.entry[i].setIsOpen(false) || mc;
                        }
                }
        }
        return mc;
}
function setEntryByURL(theURL, state) {
        var i = this.findEntry(theURL);
        if (i != -1) {
                if (this.entry[i].parent != -1) {return this.setEntry(this.entry[i].parent, state);}
        }
}
function setAll(state) {
        var hasChanged = false;
        with (parent.theMenu) {
                for (var i = 0; i <= count; i++) {
                        hasChanged = entry[i].setIsOpen(state) || hasChanged;
                }
                if (hasChanged) { refresh(false); }
        }
}
function openAll() { setAll(true); }
function closeAll() { setAll(false); }

function findEntry(theURL) {
        var res = -1
        for (var i = 0; i <= this.count; i++) {
                if (this.entry[i].url == theURL) {
                        res = i;
                        break;
                }
        }
        return res;
}

function toggle(entryNo) {
        var e = this.entry[entryNo]
//        var chg = this.setEntry(entryNo, e.isopen ^ 1);
        var chg = this.setEntry(entryNo, !e.isopen);
        if (this.linkOnExpand && e.isopen && (e.url != '')) {
                if (myOpener != null) {
                        myOpener.text.location = e.url;
                } else {
                        self.text.location = e.url;
                }
                this.itemClicked(entryNo);
        }
        if (chg) {this.refresh(this.autoScrolling && (this.lastPMClicked > 0));}
}
// Other functions
function browserInfo() {
        this.code = 'unknown';
        this.version = 0;
        this.platform = 'Win';
        
        var i = navigator.userAgent.indexOf('MSIE');
        if (i>=0 && this.code=='unknown') {
                this.code = 'MSIE';
                this.version = parseFloat(navigator.userAgent.substring(i+5, i+9));
        }
        i = navigator.userAgent.indexOf('Mozilla/')
        if (i>=0 && this.code=='unknown') {
                this.code = 'NS';
                this.version = parseFloat(navigator.userAgent.substring(i+8, i+12));
        }
//jp2008
        i = navigator.userAgent.indexOf('Opera/')
        if (i>=0 && this.code=='unknown') {
                this.code = 'NS';
                this.version = parseFloat(navigator.userAgent.substring(i+6, i+10));
        }

        if (navigator.userAgent.indexOf('Mac') >= 0) {this.platform = 'Mac';}
        if (navigator.userAgent.indexOf('OS/2') >= 0) {this.platform = 'OS/2';}
        if (navigator.userAgent.indexOf('X11') >= 0) {this.platform = 'UNIX';}
        
        this.canCache = ((this.code == 'NS') && (this.version >= 3)) || ((this.code == 'MSIE') && (this.version >= 4)) ;
        this.canOnMouseOut = ((this.code == 'NS') && (this.version >= 3));
        this.hasRentrantBug = ((this.code == 'NS') && (this.version == 2.01) && (this.platform != 'Win'));
        this.canJSVoid = !(((this.code == 'NS') && (this.version < 3)) || ((this.code == 'MSIE') && (this.version < 4)));
        this.mustMoveAfterLoad = ((this.code == 'NS') && (this.version >= 3));
        this.hasDHTML = ((this.code == 'NS') && (this.version >= 4)) || ((this.code == 'MSIE') && (this.version >= 4));
}
function setStatus(theText) {
        var theWindow = window;
        if (getMode() == 'Floating') {theWindow = myOpener;}
        theWindow.status = theText;
        if (theBrowser.canOnMouseOut == false) {
                clearTimeout(statusTimeout);
                statusTimeout = setTimeout('clearStatus()', 5000);}
        return true;
}
function clearStatus() {
        var theWindow = window;
        if (getMode() == 'Floating') {theWindow = myOpener;}
        if (theWindow != null) {theWindow.status = '';}
}
function unloadFloating() {
        if (myOpener != null) {
                if (theBrowser.code == 'MSIE') {
                        myOpener.setTimeout('menuClosed();', 10);
                } else {
                        myOpener.menuClosed();
                }
        }
}
function getMode() {
        var cookieText = document.cookie;
        var theResult = "Frames";
        if (cookieText.length > 0) {
                if (cookieText.indexOf("mode=Floating") >= 0) {
                        theResult = "Floating";
                } else {
                        if (cookieText.indexOf("mode=NoFrames") >= 0) {
                                theResult = "NoFrames";
                        }
                }
        }
        return theResult;
}
function initOutlineIcons() {
//        var ip = 'images/menu/';
        var ip = 'images/';
//        ip += (theBrowser.platform == 'Mac') ? 'mac/' : ((theBrowser.platform == 'OS/2') ? 'os2/' : 'win/')
        
        imgStore.add('iconPlusTop', ip + 'plustop.gif', 18, 18);
        imgStore.add('iconPlus', ip + 'plus.gif', 18, 18);
        imgStore.add('iconPlusBottom', ip + 'plusbottom.gif', 18, 18);
        imgStore.add('iconPlusOnly', ip + 'plusonly.gif', 18, 18);
        imgStore.add('iconMinusTop', ip + 'minustop.gif', 18, 18);
        imgStore.add('iconMinus', ip + 'minus.gif', 18, 18);
        imgStore.add('iconMinusBottom', ip + 'minusbottom.gif', 18, 18);
        imgStore.add('iconMinusOnly', ip + 'minusonly.gif', 18, 18);
        imgStore.add('iconLine', ip + 'line.gif', 18, 18);
        imgStore.add('iconBlank', ip + 'blank.gif', 18, 18);
        imgStore.add('iconJoinTop', ip + 'jointop.gif', 18, 18);
        imgStore.add('iconJoin', ip + 'join.gif', 18, 18);
        imgStore.add('iconJoinBottom', ip + 'joinbottom.gif', 18, 18);

        //Add folder and document images to the imgStore.
        imgStore.add('Root', ip + 'root.gif', 1, 1);
        imgStore.add('Folder', ip + 'folder_closed.gif', 18, 18);
        imgStore.add('FolderOpen', ip + 'folder_open.gif', 18, 18);
        imgStore.add('Document', ip + 'document.gif', 18, 18);
        imgStore.add('Home', ip + 'home.gif', 18, 18);
//        var di = ip + ((theBrowser.code == 'NS') ? 'document2.gif' : 'document.gif');
//        imgStore.add('Document', di, 18, 18);
}

