
function fillOrderForm(data){
    var val = data.split("|");
    if(typeof(val[8])=="undefined") val[8] = "";
    document.forms.zamowienie.firma.value = val[1];
    //document.forms.zamowienie.imie.value = val[3];
    //document.forms.zamowienie.nazwisko.value = val[2];
    document.forms.zamowienie.ulica.value = val[4]+' '+val[5];
    document.forms.zamowienie.miasto.value = val[6];
    document.forms.zamowienie.kod.value = val[7];
    document.forms.zamowienie.mag.value = val[8];
}

function checkUncheckSome(controller,theElements) {
    var formElements = theElements.split(',');
    var theController = document.getElementById(controller);
    jQuery('ul#wrapper input').each(function(){
        theItem = document.getElementById(this.id);
        if(theItem){
            if(theItem.type){
                if(theItem.type == 'checkbox' && theItem.id != theController.id){
                    theItem.checked = theController.checked;
                }
            } 
            else {
                var nextArray = '';
                for(var x=0;x <theItem.childNodes.length;x++){
                    if(theItem.childNodes[x]){
                        if (theItem.childNodes[x].id){
                            nextArray += theItem.childNodes[x].id+',';
                        }
                    }
                }
                checkUncheckSome(controller,nextArray);
            }
        }
    });
}


function addToBasket(item, price, karton, paczka)
{
    num = 	eval("document.forms.bigForm.elements['ile'].value");
    num = (num==0) ? 1 : num;
    count = (paczka) ? karton*num : num;
    document.forms.oneForm.item.value=item;
    document.forms.oneForm.ile.value=count;
    document.forms.oneForm.cena.value=price;
	waluta = document.forms.oneForm.waluta.value;
	
	$.post("/isInBasket.php", $("form[name=oneForm]").serialize(), function(data){
		check = true;
		
		if(data.length) {
			if(confirm(data))
				check=false;
		} else 
			check=false;

		if(check==false)
		$.post("/koszyk.html", $("form[name=oneForm]").serialize(), function(data){
			if(isNaN(price))
				{
					alert("Dodano do koszyka produkt o kodzie: "+item+"\nIlość: "+count+"\nWartość: ?"+ " "+waluta);
				}
			else 
				{
					alert("Dodano do koszyka produkt o kodzie: "+item+"\nIlość: "+count+"\nWartość: "+count*price+" "+waluta);
				}
			jQuery.ajax({
				url: '/a_userMenu.php',
				type: 'GET',
				dataType: 'html',
				//timeout: 10000,
				success: function(html){
					$("#panel_klient", top.document).html(html);
				}
			});
		});
	});
		
}



function insRow()
{
    var x=document.getElementById('addProd').insertRow(1);
    var y=x.insertCell(0);
    var z=x.insertCell(1);
    var c=x.insertCell(2);
    y.innerHTML='<input type="text" class="reg" style="width: 140px;" name="item[]" maxlength="5" />';
    z.innerHTML='<input type="text" class="reg" style="width: 140px;" name="itemCount[]" maxlength="3" value="1" />';
    c.innerHTML='<input type="button" class="button" value="Usuń wiersz" onclick="deleteRow(this.parentNode.parentNode.rowIndex)" />';
    $('#scrollContent').jScrollPane();
}

function deleteRow(i)
{
    document.getElementById('addProd').deleteRow(i);
    $('#scrollContent').jScrollPane();
}

function show(layer)
{
    var timerId=setTimeout( function() { return layerOp(layer, 1) }, 200)
}

function hide(layer)
{
    var timerId=setTimeout( function() { return layerOp(layer, 0) }, 200)
}

function layerOp(szDivID, iState) 
{
    if(document.layers)           
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)          
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)        
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

function getCurrent(pic)
{
    return document.getElementById(pic).name;
}

function pic(imgName, img)
{
    if (document.images)
    {
        document.getElementById(imgName).name=img;        
        document.getElementById(imgName).src= 'photos/produkty/t/'+img+'.jpg';
    }
}

function midPhotoLink(img) 
{ 
    window.open('/popup.php?src=' + img, '', 'resizable=1,HEIGHT=200,WIDTH=200,LEFT=10,TOP=10');
}

function PopupRms(id) 
{ 
    window.open('rms.php?id=' + id, '', 'resizable=0,HEIGHT=220,WIDTH=400, scrollbars=yes,LEFT=10,TOP=10');
}

function PopupHelp()
{
    window.open('infosms.php', '', 'resizable=0,HEIGHT=210,WIDTH=400, scrollbars=no,LEFT=10,TOP=10');
}

function PopupPhoto(img) 
{ 
    window.open('popup_p.php?src=' + img, '', 'resizable=1,HEIGHT=100,WIDTH=100,LEFT=10,TOP=10');
}
 
function PopupWindow(target, width, height) 
{ 
    window.open(target, '', 'resizable=0,HEIGHT='+height+',WIDTH='+width+',LEFT=10,TOP=10');
} 

function gallery(id) 
{ 
    window.open('gallery.php?id=' + id, '', 'resizable=1,HEIGHT=680,WIDTH=740,LEFT=10,TOP=10');
}

function PopUpPP()
{
    window.open('/pp/pp.php','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,fullscreen=no,width=750,height=540,LEFT=10,TOP=10');
}

function selectMenu(target,selObj)
{
    eval(target+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}

