//wersja 2.3 (comp23)
//10:56 04-07-08 - łšczenie rezerwcji - func zmiRezSel(ph,action)
//10:30 04-07-08 - większe okno - sprawd cene /cP
//10:56 04-07-08 - rezSelPotw

    var agt=navigator.userAgent.toLowerCase();
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	var is_opera7 = (window.opera)?true:false;


    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

var _txt = {};

if(document.all && !document.getElementById) {

		// For IE5 and other
    document.getElementById = function(id) {
         return document.all[id];
    }
}

function el(i) {	return document.getElementById(i); }


function pobierz(nazwa) {
    if (document.cookie.length > 0) {
        startc = document.cookie.indexOf(nazwa + "=");
        if (startc != -1) {
            startc += nazwa.length + 1;
            endc = document.cookie.indexOf(";", startc);
            if (endc == -1) {
                endc = document.cookie.length;
            }
            return unescape(document.cookie.substring(startc,endc));
        }
    }
}

function rejestruj(nazwa, wartosc,dni) {
    var dzisiaj=new Date();
    var wygasnie=new Date();
    !dni ?dni=7 :"";

    wygasnie.setTime(dzisiaj.getTime()+1000*60*60*24*dni);
	document.cookie=nazwa+"="+escape(wartosc)+";expires="+wygasnie.toGMTString();
}

function onLoadFunc () {
}

function cP(kodkat,rabat) {
	
	
	vals = kodkat.split("-");
	p = kodkat.lastIndexOf("-");
	kod = kodkat.substr(0,p);
	if (rabat != 0)
		oW('sprawdz_cene.php?kodkat='+kod+'&ilosc='+document.getElementById('il'+rabat+'x'+kodkat).value,350,300,'yes');
	else
		oW('sprawdz_cene.php?kodkat='+kod+'&ilosc='+document.getElementById(kodkat).value,350,300,'yes');
	void(0);
}

function zC(kodkat,param) {
	
	vals = kodkat.split("-");
	p = kodkat.lastIndexOf("-");
	kod = kodkat.substr(0,p);
	ncenaz=prompt("Podaj nową cenę","");
	document.location.href= 'sklep.php?kodkat='+kod+'&ncenaz='+ncenaz+param
	void(0);
}

function oW (path,Xsiz,Ysiz,scrBar,popUnder,popName) {
	var przed = '';
	if (!(Xsiz > 0)) {
		Xsiz = 460;
		przed = 'zoom.php?img=';
	}
	if (!(Ysiz > 0)) { Ysiz = 350; }
	if (scrBar == '') { scrBar = 'no'; }
	var x;
	if (popName) winPName = popName;
	else winPName = 'fotozoom';
	x = window.open(przed+path, winPName, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrBar+',resizable=yes,fullscreen=no,channelmode=no,width='+Xsiz+',height='+Ysiz+',top=30,left=30');
	if (popUnder) {
		x.blur();
		window.focus();
	}
	else {
		x.focus();
	}
	void(0);
}

function oP (kodKat,popName) {
	//this.blur();
	this.href = "javascript:void(0);";
	oW('opis.php?popup=1&id='+kodKat,850,600,'yes',false,popName);
	//x.focus();
	void(0);
}
function oR (grRab) {
	oW('rabaty.php?grRab='+grRab,280,260,'yes');
	void(0);
}

var opcjeWyboru = ['grupy','producenci','szukaj'];

function getIFrameDoc (ifName) {
	IFrameObj = document.getElementById(ifName);
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument;
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = window.frames[ifName];
//		IFrameDoc = IFrameObj.document;
	}
	return IFrameDoc;
}
function scrollH (fname) {
	IFrameDoc = getIFrameDoc(fname);
	IFrameObj = document.getElementById(fname);
	return IFrameDoc.body.scrollHeight;
	alert (IFrameDoc.body.scrollHeight + ',' +IFrameDoc.scrollHeight + ',' +IFrameDoc.offsetHeight + ',' +IFrameDoc.body.offsetHeight);
	if (is_opera7) { return IFrameDoc.document.body.scrollHeight; }
	else if (is_ie5_5up) return IFrameDoc.body.scrollHeight;
	else if (is_ie5up) return IFrameDoc.document.body.scrollHeight;
	else return IFrameDoc.body.offsetHeight;
}

function getHeight(il) {
	sm = document.getElementById('submenu');
	i = 0;
	l = sm.firstChild;
	tw = 0;
	tw = allHeight = l.firstChild.offsetHeight;
	while (l.nextSibling) {
		++i;
		if (il && i >= il) break;
		l = l.nextSibling;
		tw += ',' + l.firstChild.offsetHeight;
		allHeight += l.firstChild.offsetHeight;
		
	}
	//alert (allHeight+':'+tw+':'+il+':'+i);
	return;
}

function setHeightMenu(allHeight,il) {

	sm = document.getElementById('submenu');
	sm = document.getElementById('submenu');
	i = 0;
	l = sm.firstChild;
	tw = 0;
	tw = allHeight = l.firstChild.offsetHeight;
	while (l.nextSibling) {
		++i;
		if (il && i >= il) break;
		l = l.nextSibling;
		tw += ',' + l.firstChild.offsetHeight;
		allHeight += l.firstChild.offsetHeight;
		
	}

	
	//if (allHeight == undefined) allHeight = sm.scrollHeight;
	
	if (maxMenuHeight <= allHeight) {
		newHeight = maxMenuHeight;
		if (is_ie5up) { sm.style.overflowY = 'auto'; sm.style.overflowX = 'hidden'; }
		else sm.style.overflow = 'auto';
	}
	else {
		newHeight = allHeight;
		sm.style.overflow = 'hidden';
		if (is_ie5up) { sm.style.overflowY = 'hidden'; }
		sm.scrollTop = 0;
	}

	sm.style.height = newHeight + 'px';
	rejestruj('menuHeight', newHeight,0);

}

function setMenu(menu) {
	//this.blur();
	this.href = "javascript:void(0);";

	if (menu == 'szukaj') {
		document.getElementById('searchMenu').style.display = "";
		document.getElementById('submenu').style.display = "none";
	}
	else {
		document.getElementById('searchMenu').style.display = "none";
		document.getElementById('submenu').style.display = "";
		mhtml = '';

//		if (menu == 'producenci') for (a in producenciA) mhtml += '<li><a href="sklep.php?prod='+a+'">'+producenciA[a]+'</a></li>';
//		if (menu == 'grupy') for (a in grupyA) mhtml += '<li><a href="sklep.php?grupa='+a+'">'+grupyA[a]+'</a></li>';

		var tA = new Array();
		tA = (menu == 'grupy')?grupyA:producenciA;
		lpar = (menu == 'grupy')?'grupa':'prod';
		ulsub = document.getElementById('submenu');
		kids = ulsub.childNodes;
		ilol = kids.length;
		ilal = 0;
		for (a in tA) ++ilal;
		ilel = (ilal > ilol)?ilal:ilol;
		i = 0;
		for (a in tA) {
			if (i < ilol) {
				kids[i].firstChild.href = 'sklep.php?'+lpar+'='+a;
				kids[i].firstChild.firstChild.nodeValue = tA[a];
				kids[i].firstChild.style.visibility = 'visible';
			}
			else {
				item_li = document.createElement("li");
				item_li.innerHTML = '<a href="sklep.php?'+lpar+'='+a+'">'+tA[a]+'</a>';
				ulsub.appendChild(item_li);	
			}
			++i;
		}
 		for (var j = i; j < ilol; j++) {
			//kids[j].parentNode.removeChild(kids[j]);
			//kids[j].style.display = 'none';
			kids[j].style.visibility = 'hidden';
   		}
		//document.getElementById('submenu').innerHTML = mhtml;
		setHeightMenu(null,ilal);
		setHeightMenu(null,ilal);
	}
	for (a in opcjeWyboru) document.getElementById(opcjeWyboru[a]+'B').className = 'radioOff';
	document.getElementById(menu+'B').className = 'radioOn';
	document.getElementById(menu+'B').blur();
	rejestruj('menuActive', menu,0);
	void(0);
}

function switchMenu(menu) {
	if (menu == 'myMenu' && document.getElementById('myMenuOpcje')) {
		document.getElementById('myMenuOpcje').style.display = "";
		document.getElementById('zakupyOpcje').style.display = "none";
		document.getElementById('submenu').style.display = "none";
		document.getElementById('searchMenu').style.display = "none";
	}
	else {
		document.getElementById('zakupyOpcje').style.display = "";
		if (document.getElementById('myMenuOpcje')) document.getElementById('myMenuOpcje').style.display = "none";
		menuActive = pobierz('menuActive');
		if (menuActive == 'szukaj') document.getElementById('searchMenu').style.display = "";
		else {
			document.getElementById('submenu').style.display = "";
			setHeightMenu();
		}
	}
	rejestruj('opcjaActive', menu,0);
}
function init() {
	
	if (typeof komunikat!="undefined") {
		if (komunikat != '') alert (komunikat);
	}
	if (document.getElementById('searchMenu').style.display != 'none') document.getElementById('fraza').focus();

}

function cq (kod,zm) {
		var tmpIl = eval( "document.grupa[\"il["+kod+"]\"].value;");
		++tmpIl;
		--tmpIl;
		reszta = tmpIl%zm;
		if ((zm > 0) && (tmpIl < 999999) ) {
			eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl + zm - reszta;");
		}
		else if ((zm < 0) && (tmpIl > 0)){
			if ( reszta > 0 ) { eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl - reszta;"); }
			else {	eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl + zm;"); }
		}

}

function rq (kod,zm) {
		var tmpIl = eval( "document.grupa[\"il["+kod+"]\"].value;");
		++tmpIl;
		--tmpIl;
		reszta = tmpIl%zm;
		if (!(tmpIl >= 0)) {
			alert ("Wprowadzono nie poprawną wartoś!");
			eval( "document.grupa[\"il["+kod+"]\"].value = 0;");
		}
		else if (reszta > 0) {
			alert ("Ilość musi być wielokrotnością liczby "+zm);
			eval( "document.grupa[\"il["+kod+"]\"].value = tmpIl - reszta;");
		}

}

function nm () {
 	alert ('Wybranego towaru nie ma w tej chwili w magazynie');
}

function ukryjBraki(ch) {
	var c = (ch.checked)?0:1;
	rejestruj('braki',c,7);
	document.location.href = document.location.toString() + '&ubraki=1';
	//document.location.reload();
}

function shTable(ide) {
	if (document.getElementById(ide).style.display == 'none' || document.getElementById(ide).style.display != '') {
		document.getElementById(ide).style.display='';
	}
	else {
		 document.getElementById(ide).style.display='none';
	}
}



function pobierzRezSel (co) {
	idopery = '';
 	i = 0;
	il = 0;  
        huj = '';
	while (document.getElementById('sr'+i) ) {
		if (document.getElementById('sr'+i).checked) {
			idopery += huj + document.getElementById('sr'+i).value ;
			++il;  huj=',';
		}
		++i;

	}  
	if (co == 'ilosc') return il;
	if (co == 'idopery') return idopery;
}

function potwRezSel(ph) {    

	il = pobierzRezSel('ilosc');
	idopery = pobierzRezSel('idopery');

	if (  idopery != '') {
		fp = '';
		if (document.getElementById('fp')) {
			if (document.getElementById('fp').value == 0) {
				alert ('Proszę wybrać formę płatności');
				document.getElementById('fp').focus();
				void(0);
			}
			else  {
				document.location= ph + 'fakturuj.php?action=potwSelected&fp=' + document.getElementById('fp').value + '&idopr='+idopery;
			}
		}
		else if (document.getElementById('fp0')) {
  			i = 0;
			fp = '';
			while (document.getElementById('fp'+i) ) {
				if (document.getElementById('fp'+i).name) {
					fp += 'fp['+ document.getElementById('fp'+i).name +']='+document.getElementById('fp'+i).value + '&';
				}
			++i;
			}
			document.location= ph + 'fakturuj.php?action=potwSelected&' +  fp + 'idopr='+idopery;
		}
		else {
			document.location= ph + 'fakturuj.php?action=potwSelected&idopr='+idopery;
		}
	}
	else {
		alert ('Nie wybrano żadnej rezerwacji');
		void (0);
	}


}     
function rezSelPotw () {

 	i = 0;
	p = 0;
	while (document.getElementById('sr'+i) ) {
		if (document.getElementById('sr'+i).checked) {
			if (document.getElementById('potwierdzona'+i) && document.getElementById('potwierdzona'+i).value == 1) ++p;
		}
		++i;
	}
	if (p > 0) return true;
	else return false;
}

function zmiRezSel(ph,action,rmode) {
	il = pobierzRezSel('ilosc');
	idopery = pobierzRezSel('idopery');
	czySaPotw = rezSelPotw();
	if (rmode == 'zam') co = 'zamówienia';
	else co = 'rezerwacje';

	if (  idopery != '') {

		if (action == 'polacz' && il < 2) { alert('Proszę wybrać przynajmniej dwie rezerwacje!'); }
		if (action == 'zatwierdz' && il > 1 && rmode == 'zam') { alert('Proszę wybrać tylko jedno zamówienie!'); }
		else if ((action == 'usun' && confirm('Wybrano ' + il + ' '+co+'.\nNa pewno chcesz je usunąć?')) || (action == 'polacz' && confirm('Wybrano ' + il + ' rezerwcje.\nNa pewno chcesz je połączyć?')) || (action != 'polacz' && action != 'usun'))
		{
			if (czySaPotw && action == 'usun' && rmode != 'zam') alert('Uwaga! Rezerwacje potwierdzone nie zostaną usunięte!');
			if (czySaPotw && action == 'polacz') alert('Uwaga! Rezerwacje potwierdzone nie zostaną połączone!');
			document.grupa.idopery.value = idopery;
			document.grupa.akcja.value = action;
			if (rmode == 'zam') document.grupa.action = 'zamowienia.php';
			else document.grupa.action = ph + 'rezerwacje.php';
			document.grupa.submit();
		}
	}
	else {
		alert ('Proszę zaznaczyć '+co);
		void (0);
	}


}
function smA(opt) {

	document.getElementById('searchMenu').action = (opt.value == 'kxi')?((loginType == 'IP')?'ip_rachunki.php':'kosz.php'):'sklep.php';
}

function saveZest() {
	document.getElementById('savedesc').style.display = 'block';
	void(0);
}

function delZest(zid) {
	if (confirm("Na pewno usunąć zestaw?")) {
		document.location.href= "zestawy.php?zestid="+zid+"&akcja=del";
	}
	else void(0);
}


function flash(name,src,x,y,ver,opcja,opcja2) {
	

	if (is_ie) { b = 'ie' }
	
	else if (is_gecko) { b = 'gecko' }
	else if (is_opera) { b = 'opera' }

	if (opcja == 'w3c' || (opcja == 'jsOpti' && b != 'ie')) {
		document.write ('<object class="dynflash" id="'+name+'" type="application/x-shockwave-flash" data="'+src+'" width="'+x+'" height="'+y+'" >');
		document.write ('<param name="movie" value="'+src+'" >');
	if (opcja2 == 'opaque') document.write ('<param name="wmode" value="opaque">');
		document.write ('<param name="swliveconnect" value="true">');
		document.write ('</object>');
	}
	else if (opcja == 'fsc' || (opcja == 'jsOpti' && b == 'ie') || (opcja == 'transparent' && b == 'ie')) {

		document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write ('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+',0,0,0"');
		document.write ('width='+x+' height='+y+' id="'+name+'">');
		document.write ('<param name=movie value="'+src+'">');
		document.write ('<param name=quality value=high>');

		if (opcja == 'transparent') document.write ('<param name="wmode" value="transparent">');
		if (opcja2 == 'opaque') document.write ('<param name="wmode" value="opaque">');

		document.write ('<param name="swliveconnect" value="true">');
		document.write ('<embed src="'+src+'" quality="high" width="'+x+'" height="'+y+'"');
		document.write (' type="application/x-shockwave-flash"');
		if (opcja2 == 'opaque') document.write (' wmode="opaque"');
		document.write (' pluginspage="http://www.macromedia.com/downloads/"');
		document.write (' name="'+name+'" swliveconnect="true">');
		document.write ('</embed>');
		document.write ('</object>');
	}
}


function number_format(a, b, c, d) {
 if (b == null) b = 2;
 if (c == null) c = ',';
 if (d == null) d = ' ';
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}
