// ---------------------------------
function onFinishedPlaying()
{
	document.getElementById('reklama').style.visibility = 'hidden';
}
// ---------------------------------
function faktura()
{
	if (document.dane_klienta.fakt.checked == true )
	{
		document.dane_klienta.nazwa_firmy.disabled=false;
		document.dane_klienta.adres_firmy.disabled=false;
		document.dane_klienta.nip.disabled=false;
	}
	else
	{
	
		document.dane_klienta.nazwa_firmy.disabled=true;
		document.dane_klienta.adres_firmy.disabled=true;
		document.dane_klienta.nip.disabled=true;
	}
}
// ---------------------------------
function sort(type)
{
	document.szukanie.strona.value=1;
	document.szukanie.sort_method.value=type;
	document.szukanie.submit();
}
// ---------------------------------
function szukaj(p)
{
	document.szukanie.strona.value=p;
	document.szukanie.submit();
}				       
// ---------------------------------
function sub(co)
{
	document.b_form.b_akcja.value=co;
}				       

// ---------------------------------
function checkAll(ctrl) {
	form = ctrl.form
	for(i=0;i<form.elements.length;i++) {
		el = form.elements[i];
		if(el.type=="checkbox") el.checked=ctrl.checked;
	}
}

// ---------------------------------
  	function pos_o(elem) {
		
			var p,elem;
		
			p = {x: 0.0, y: 0.0};

			while(elem && elem != document.body) {
			
				p.x+=elem.offsetLeft;
			
				p.y+=elem.offsetTop;

			
				elem=elem.offsetParent;
		
			}

		
			return p;
	
	}

	function pos(elem) {
		var p,elem;
		
		p = {x: 0.0, y: 0.0};
		elem = document.getElementById(elem);
		while(elem && elem != document.body) {
			p.x+=elem.offsetLeft;
			p.y+=elem.offsetTop;

			elem=elem.offsetParent;
		}
		return p;
	}
// ---------------------------------



	function okienko_centered(link,sz,wy) {
		x = (screen.availWidth-sz-8)/2;
		y = ((screen.availHeight-wy-8)/2-30);
		win = window.open(link, "certyfikat", 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, fullscreen=no, channelmode=no, width='+sz+', height='+wy+', innerWidth='+sz+', innerHeight='+wy+', top='+y+', left='+x+', application=yes');		
		win.window.resizeTo(sz+8,wy+38);
		win.focus();
	}



// funkcje obslugi edytora 
	function command(tbTresc,cmd) {
		if(tbTresc.advEditMode) {
			alert('Wyłącz podgląd źródła');
			return;
		}
		tbTresc.focus()
		document.selection.createRange()
		if(arguments[2]) 
			document.execCommand(cmd,true,arguments[2]) 
		else 
			document.execCommand(cmd) 
		tbTresc.focus()
	}

	function actCut(tbTresc) { command(tbTresc,'Cut') }
	function actCopy(tbTresc) { command(tbTresc,'Copy') }
	function actPaste(tbTresc) { command(tbTresc,'Paste') }

	function actUndo(tbTresc) { command(tbTresc,'Undo') }

	function actBold(tbTresc) { command(tbTresc,'Bold') }
	function actItalic(tbTresc) { command(tbTresc,'Italic') }
	function actUnderline(tbTresc) { command(tbTresc,'Underline') }
	
	function actAlignLeft(tbTresc) { command(tbTresc,'JustifyLeft') }
	function actAlignCenter(tbTresc) { command(tbTresc,'JustifyCenter') }
	function actAlignRight(tbTresc) { command(tbTresc,'JustifyRight') }

	function actOrderedList(tbTresc) { command(tbTresc,'InsertOrderedList') }
	function actUnorderedList(tbTresc) { command(tbTresc,'InsertUnorderedList') }

	function actUnindent(tbTresc) { command(tbTresc,'Outdent') }
	function actIndent(tbTresc) { command(tbTresc,'Indent') }
	function actLink(tbTresc) { command(tbTresc,'Undrline') }

	function actChangeFont(tbTresc,font) { command(tbTresc,'fontname',font) }
	function actChangeFontSize(tbTresc,size) { command(tbTresc,'fontsize',size) }
	function actChangeFontColor(tbTresc,color) { command(tbTresc,'forecolor',color) }
	function actChangeBackColor(tbTresc,color) { command(tbTresc,'backcolor',color) }

	function actCreateLink(tbTresc) { command(tbTresc,'CreateLink') }

	function actChangeMode(tbTresc) {
		tbTresc.advEditMode = ! tbTresc.advEditMode;
		
		if(tbTresc.advEditMode) {
			tbTresc.innerText = tbTresc.innerHTML;
		} else {
			tbTresc.innerHTML = tbTresc.innerText;
		}
		
	}
	
	
// -----------------------------------------------------------------------

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		promocje_ov = newImage("images/promocje_ov.gif");
		regulamin_ov = newImage("images/regulamin_ov.gif");
		kontakt_ov = newImage("images/kontakt_ov.gif");
		konto_ov = newImage("images/konto_ov.gif");
		bestsellery_ov = newImage("images/bestsellery_ov.gif");
		pomoc_ov = newImage("images/pomoc_ov.gif");
		interiapl2_l = newImage("images/interiapl2_l.gif");
		interiapl2_r = newImage("images/interiapl2_r.gif");
		preloadFlag = true;
	}
}



// ------------------------------------------------------------------------------

function ClickShowHideMenu(id) {
    this.box1Hover = true;
    this.box2Hover = true;

    this.init = function() {
        if (!document.getElementById(this.id)) {
            alert("Element '"+this.id+"' does not exist in this document. ClickShowHideMenu cannot be initialized");
            return;
        }
        this.parse(document.getElementById(this.id).childNodes, this.tree, this.id);
        this.load();
        if (window.attachEvent) {
            window.attachEvent("onunload", function(e) { self.save(); });
        } else if (window.addEventListener) {
            window.addEventListener("unload", function(e) { self.save(); }, false);
        }
    }

    this.parse = function(nodes, tree, id) {
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].nodeType != 1) {
                continue;
            }
            if (nodes[i].className) {
                if ("box1" == nodes[i].className.substr(0, 4)) {
                    nodes[i].id = id + "-" + tree.length;
                    tree[tree.length] = new Array();
                    eval('nodes[i].onmouseover = function() { self.box1over("'+nodes[i].id+'"); }');
                    eval('nodes[i].onmouseout = function() { self.box1out("'+nodes[i].id+'"); }');
                    eval('nodes[i].onclick = function() { self.box1click("'+nodes[i].id+'"); }');
                }
                if ("section" == nodes[i].className) {
                    id = id + "-" + (tree.length - 1);
                    nodes[i].id = id + "-section";
                    tree = tree[tree.length - 1];
                }
                if ("box2" == nodes[i].className.substr(0, 4)) {
                    nodes[i].id = id + "-" + tree.length;
                    tree[tree.length] = new Array();
                    eval('nodes[i].onmouseover = function() { self.box2over("'+nodes[i].id+'", "'+nodes[i].className+'"); }');
                    eval('nodes[i].onmouseout = function() { self.box2out("'+nodes[i].id+'", "'+nodes[i].className+'"); }');
                }
            }
            if (nodes[i].childNodes) {
                this.parse(nodes[i].childNodes, tree, id);
            }
        }
    }

    this.box1over = function(id) {
        if (!this.box1Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = (this.id_openbox == id ? "box1-open-hover" : "box1-hover");
    }

    this.box1out = function(id) {
        if (!this.box1Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = (this.id_openbox == id ? "box1-open" : "box1");
    }

    this.box1click = function(id) {
        if (!document.getElementById(id)) {
            return;
        }
        var id_openbox = this.id_openbox;
        if (this.id_openbox) {
            if (!document.getElementById(id + "-section")) {
                return;
            }
            this.hide();
            if (id_openbox == id) {
                if (this.box1hover) {
                    document.getElementById(id_openbox).className = "box1-hover";
                } else {
                    document.getElementById(id_openbox).className = "box1";
                }
            } else {
                document.getElementById(id_openbox).className = "box1";
            }
        }
        if (id_openbox != id) {
            this.show(id);
            var className = document.getElementById(id).className;
            if ("box1-hover" == className) {
                document.getElementById(id).className = "box1-open-hover";
            }
            if ("box1" == className) {
                document.getElementById(id).className = "box1-open";
            }
        }
    }

    this.box2over = function(id, className) {
        if (!this.box2Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = className + "-hover";
    }

    this.box2out = function(id, className) {
        if (!this.box2Hover) return;
        if (!document.getElementById(id)) return;
        document.getElementById(id).className = className;
    }

    this.show = function(id) {
        if (document.getElementById(id + "-section")) {
            document.getElementById(id + "-section").style.display = "block";
            this.id_openbox = id;
        }
    }

    this.hide = function() {
        document.getElementById(this.id_openbox + "-section").style.display = "none";
        this.id_openbox = "";
    }

    this.save = function() {
        if (this.id_openbox) {
            this.cookie.set(this.id, this.id_openbox);
        } else {
            this.cookie.del(this.id);
        }
    }

    this.load = function() {
        var id_openbox = this.cookie.get(this.id);
        if (id_openbox) {
            this.show(id_openbox);
            document.getElementById(id_openbox).className = "box1-open";
        }
    }

    function Cookie() {
        this.get = function(name) {
            var cookies = document.cookie.split(";");
            for (var i = 0; i < cookies.length; i++) {
                var a = cookies[i].split("=");
                if (a.length == 2) {
                    a[0] = a[0].trim();
                    a[1] = a[1].trim();
                    if (a[0] == name) {
                        return unescape(a[1]);
                    }
                }
            }
            return "";
        }
        this.set = function(name, value) {
            document.cookie = name + "=" + escape(value);
        }
        this.del = function(name) {
            document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
        }
    }

    var self = this;
    this.id = id;
    this.tree = new Array();
    this.cookie = new Cookie();
    this.id_openbox = "";
    this.init();
}

if (typeof String.prototype.trim == "undefined") {
    String.prototype.trim = function() {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}


// ---


