function setmainframemode(mode,recordid,curmode,submode)
{
   var frm = window.parent.frames;
   for (i=0; i < frm.length; i++)
   {
      if (frm[i].name=="mainFrame")
      {
         frm[i].currmode = mode;
         frm[i].recordid = recordid;
         frm[i].commmode = curmode;
         frm[i].submode = submode;
      }
   }
}

function setmainframerec(recordid)
{
   var frm = window.parent.frames;
   for (i=0; i < frm.length; i++)
   {
      if (frm[i].name=="mainFrame")
      {
         frm[i].recordid = recordid;
      }
   }
}

function addsendvalue()
{
	var		oVCenaPrzes=document.getElementById("oCenaPrzes");
	var		oVCenaTow=document.getElementById("oCenaTow");
	var		oVCenaRazem=document.getElementById("oCenaRazem");
	var		delName;
	var		delCena;
	var      addVal=0.0;
	var cashmethodVal = 0.0;
	
	for (idx=0;idx<document.getElementById("form1").delivery.length;idx++)
	{
   	if (document.getElementById("form1").delivery[idx].checked)
   	{
   	   if (parseFloat(document.getElementById("form1").delivery[idx].attributes.getNamedItem('maxcena').value)<0 || parseFloat(document.getElementById("form1").delivery[idx].attributes.getNamedItem('maxcena').value)>parseFloat(oVCenaTow.value))
   		 oVCenaPrzes.value = document.getElementById("form1").delivery[idx].attributes.getNamedItem('cena').value;
   		else
   		 oVCenaPrzes.value = 0.00;
   		delName=document.getElementById("del"+document.getElementById("form1").delivery[idx].value+"Name");
   		break;
   	}
	}
	if (document.getElementById("form1").addins.checked)
	{
	   if (document.getElementById("form1").addins.attributes.getNamedItem('maxcena').value<0 || document.getElementById("form1").addins.attributes.getNamedItem('maxcena').value>oVCenaTow.value)
		 addVal = document.getElementById("form1").addins.attributes.getNamedItem('cena').value;
	}
	
	if (document.getElementById("cashmethod").value == 3)
	{
		cashmethodVal = 7;
	}
	
	var floatBuf = parseFloat(oVCenaPrzes.value)+parseFloat(oVCenaTow.value)+parseFloat(addVal)+parseFloat(cashmethodVal);;
	oVCenaRazem.value = floatBuf.toFixed(2);
	oVCenaPrzes.childNodes.item(0).data = oVCenaPrzes.value + " PLN ("+delName.childNodes.item(0).data+")";
	oVCenaRazem.childNodes.item(0).data = oVCenaRazem.value + " PLN";
	oVCenaPrzes.childNodes.item(0).data = oVCenaPrzes.childNodes.item(0).data.replace('.',',')
	oVCenaRazem.childNodes.item(0).data = oVCenaRazem.childNodes.item(0).data.replace('.',',')
	return false;
}

function numonchange(line)
{
   var lineBuf = document.getElementById(line);
	bruttorefresh(lineBuf);
	recalculate();
}

function bruttorefresh(line)
{
	var	kod=document.getElementById(line.id+"[kod]");
	var	name=document.getElementById(line.id+"[name]");
	var	netto=document.getElementById(line.id+"[cenanetto]");
	var	vat=document.getElementById(line.id+"[vat]");
	var	brutto=document.getElementById(line.id+"[cenabrutto]");
	var	ilosc=document.getElementById(line.id+"[ilosc]");
	var	vartosc=document.getElementById(line.id+"[wartosc]");
	
   var floatBuf = parseFloat(brutto.childNodes.item(0).data.replace(',','.'))*parseFloat(ilosc.value.replace(',','.'));
	vartosc.childNodes.item(0).data = floatBuf.toFixed(2);
	vartosc.childNodes.item(0).data = vartosc.childNodes.item(0).data.replace('.',',');
}

function recalculate()
{
	var		aRowsArray = document.getElementById("tableprodukt");
	var		oVCenaTow=document.getElementById("oCenaTow");
	var		oTWartosc=document.getElementById("tWartosc");
	var		oVCenaPrzes=document.getElementById("oCenaPrzes");
	var		oVCenaRazem=document.getElementById("oCenaRazem");
	var		oTIlosc=document.getElementById("tIlosc");
	var		nbrow=0;
	var      floatBuf=0.0;
	var      idx=0;
	
	oVCenaTow.value=0;
	for (idx=0;idx<aRowsArray.rows.length;idx++)
	{
		if (aRowsArray.rows.item(idx).attributes.getNamedItem('prodrow') && aRowsArray.rows.item(idx).attributes.getNamedItem('prodrow').value)
		{
		   bruttorefresh(aRowsArray.rows.item(idx));
		   floatBuf = parseFloat(oVCenaTow.value) + parseFloat(getbruttoval(aRowsArray.rows.item(idx)).replace(',','.'));
			oVCenaTow.value=floatBuf.toFixed(2);
			nbrow++;
		}
	}
	oTIlosc.childNodes.item(0).data = nbrow;
	oVCenaTow.childNodes.item(0).data = oVCenaTow.value + " PLN";
	oVCenaTow.childNodes.item(0).data = oVCenaTow.childNodes.item(0).data.replace('.',',');
	oTWartosc.childNodes.item(0).data = oVCenaTow.childNodes.item(0).data.replace('.',',');
	if (nbrow>0)
	{
	    floatBuf = parseFloat(oVCenaPrzes.value)+parseFloat(oVCenaTow.value);
		oVCenaRazem.value = floatBuf.toFixed(2);
		oVCenaRazem.childNodes.item(0).data = oVCenaRazem.value + " PLN";
   	addsendvalue();
	}
	else
	{
	   var buffItem = document.getElementById("tablekoszyk");
		nbrow = buffItem.rows.length;
		for (idx=nbrow;idx>0;idx--)
		{
			buffItem.deleteRow(idx-1);
		}
	}
}

function getbruttoval(line)
{
	var	brutto=document.getElementById(line.id+"[wartosc]");
	return brutto.childNodes.item(0).data;
}

function refreshvalue(table)
{
   var tableBuf = document.getElementById(table);
   
	document.getElementById("form1").action = "./index.php?mode=koszyk&action=refresh&lastitem="+tableBuf.rows.item(tableBuf.rows.length-1).attributes.getNamedItem('numberidx').value;
	document.getElementById("form1").submit();
	return false;
}

function goandrefreshvalue(table)
{
   var tableBuf = document.getElementById(table);
   
	document.getElementById("form1").action = "./index.php?mode=koszyk_dane_bilingowe&action=refresh&lastitem="+tableBuf.rows.item(tableBuf.rows.length-1).attributes.getNamedItem('numberidx').value;
	document.getElementById("form1").submit();
	return false;
}

function skasuj(table,line)
{
   var tableBuf = document.getElementById(table);
   var lineBuf = document.getElementById(line);
   
	tableBuf.deleteRow(lineBuf.rowIndex);
	recalculate();
	if (tableBuf.rows.length>0 && tableBuf.rows.item(tableBuf.rows.length-1).attributes.getNamedItem('numberidx'))
	  document.getElementById("form1").action = "./index.php?mode=koszyk&action=refresh&lastitem="+tableBuf.rows.item(tableBuf.rows.length-1).attributes.getNamedItem('numberidx').value;
	else
  	  document.getElementById("form1").action = "./index.php?mode=koszyk&action=removeall";
	document.getElementById("form1").submit();
	return false;
}

function kontynuuj(adres)
{
	document.location = adres;
	return false;
}

function correctform(form)
{
   for(i = 0; i < document.childNodes.length; i++)
   {
      if (document.childNodes.item(i).requisite==1 && document.childNodes.item(i).value=="")
      {
         return false;
      }
   }
   return true;
}

function userlogin(actions, setmain)
{
	var itemBuf=document.getElementById('loginlogin');
	
	if (itemBuf==null)
	  return false;
   if (itemBuf.value=="")
      return false;
	itemBuf=document.getElementById("loginpassword");
	if (itemBuf==null)
	  return false;
   if (itemBuf.value=="")
      return false;
      
	itemBuf=document.getElementById("form1");
   itemBuf.action = "./index.php?mode=login&action="+actions+"&setmain="+setmain;
	itemBuf.submit();
	return true;
}

function gotoproducent()
{
   document.getElementById("form1").action="./index.php?mode=producent_full_root&recordId="+document.getElementById("form1").prodsel.value;
   document.getElementById("form1").submit();
   return true;
}

function gotosearch()
{
   document.getElementById("form1").action="./index.php?mode=search_full_lista";
   document.getElementById("form1").submit();
   return true;
}

function searchenter(elem)
{
   var fireEvent = (navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&
		             (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
   if (fireEvent && event.keyCode=='13')
   {
      document.getElementById("form1").action="./index.php?mode=search_full_lista";
      document.getElementById("form1").submit();
      return true;
   }
}

function katalogsubmit()
{
   document.getElementById("form1").action="./index.php?mode=zamow_katalog_action";
   document.getElementById("form1").submit();
   return true;
}

function refreshtoolbars(doc)
{
   var idx;
   
   if (doc.buttons)
   {
      for (idx=1;idx<=doc.buttons.length;idx++)
      {
         if (doc.buttons[idx])
            doc.buttons[idx].normalize();
      }
   }
}

function refreshtoolbar(currmode,submode)
{
   var frm = window.parent.frames;
   for (i=0; i < frm.length; i++)
   {
      if (frm[i].name=="topFrame")
      {  
         var doc = frm[i].document;

         var docElem = null;
         switch (currmode)
         {
            case "faktury":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "faktura":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = false;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "stany":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
               {
               	if(submode=="wysylka")
                  	docElem.attributes.getNamedItem('active').value=1;
						else
                  	docElem.attributes.getNamedItem('active').value=0;
               }
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               break;
            case "stan":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "produkty":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "produkt":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
               {
                  if (submode=='edit')
                     docElem.attributes.getNamedItem('active').value=1;
                  else
                     docElem.attributes.getNamedItem('active').value=0;
               }
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "kategorie":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "kategoria":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "aukcje":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "aukcja":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "wyprzedaze":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "wyprzedaz":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "customers":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "customer":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               //doc.getElementById("delete").attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "katalogi":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            case "katalog":
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               //doc.getElementById("delete").attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
            default:
               docElem = doc.getElementById("back");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("next");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("new");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("edit");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("preview");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("save");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("delete");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("print");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("search");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=1;
               docElem = doc.getElementById("expand");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("raise");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("printoption");
               if (docElem!=null)
                  doc.getElementById("printoption").disabled = true;
               docElem = doc.getElementById("moveto");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               docElem = doc.getElementById("importdb");
               if (docElem!=null)
                  docElem.attributes.getNamedItem('active').value=0;
               break;
         }
         refreshtoolbars(frm[i]);
      }
   }
}

function changepicture(controlname,picturename,fullpic)
{
	imagePrev = eval( "document." + controlname );
	imagePrev.previmage = fullpic;
   imagePrev.src=picturename;
}

function showfullimage(control)
{
   if (control.previmage!=null && control.previmage!="")
   {
      window.open('./index.php?mode=picprev&srcfile='+control.previmage,'Leomark','height=450,width=450,resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes');
   }
}

function searchedit()
{
   var fireEvent = (navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&
		             (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
   if (fireEvent && event.keyCode=='13')
   {
      searchitem();
   }
}
function searchitem()
{
   if (searchval.value!="")
   {
      alert(searchval.value);
      var oRange = document.body.createTextRange();
         // record the current position in a bookmark
      //var sBookMark = oRange.getBookmark();  
         // true - case-insensitive and partial word match
      oRange.findText(searchval.value);
         // reset the range using the bookmark
      //oRange.moveToBookmark(sBookMark);
   }
   return false;
}


