var DEBUG_AJAX = 0;

var q_loading_string = "Proszę czekać...";
var q_loading_gif = '<img src="images/ikony/wait.gif" />'


/**
* detekcja przegladarki
*/
function getBrowser()
{
  var ns4 = (document.layers)? true:false;
  var ns6 = (document.getElementById)? true:false;
  var ie4 = (document.all)? true:false;
  if (ie4)
  {
    if((navigator.userAgent.indexOf('MSIE 5')> 0)||(navigator.userAgent.indexOf('MSIE 6')> 0)||window.opera)
    {
      return('ie5');
    } else {
      return('ie4');
    }
    if (ns6)
    {
      ns6=false;
    }
  } 
  if (ns6) {
    return('ns6');
  } else {
    return('ns4');
  }
  
}

function divSlider(nrDiv)
{
   if (divSliderIdCurrent < (aDivs.length-1)) divSliderIdCurrent++;
   else divSliderIdCurrent = 0;
   
   if (nrDiv==2) nrDiv=0;
   curDiv = aDivs[nrDiv];
     
   if (divSliderIdCurrent%2) {
   	  new Effect.Fade(document.getElementById(curDiv), {duration:0.5});
	  //Element.hide(curDiv);
	  window.setTimeout("divSlider("+(nrDiv+1)+")",1000);
   } else {
   	   new Effect.Appear(document.getElementById(curDiv), {duration:1.0});
	   window.setTimeout("divSlider("+(nrDiv)+")",9000);
   }
 
}

function divSliderArray( nrDiv, arrName, pointer, postfix )
{
  if (pointer < (arrName.length-1)) {
    pointer++;
  } else {
    pointer = 0;
  }

  if ( nrDiv == arrName.length ) {
    nrDiv=0;
  }
  curDiv = arrName[nrDiv];
  if (!curDiv) return;

  if (pointer%2) {
    new Effect.Fade(document.getElementById(curDiv), {duration:0.5});
    window.setTimeout("divSliderArray("+(nrDiv+1)+",aOfertaDivs"+postfix+","+pointer+","+postfix+" )",1000);
  } else {
    new Effect.Appear(document.getElementById(curDiv), {duration:1.0});
    window.setTimeout("divSliderArray("+(nrDiv)+",aOfertaDivs"+postfix+","+pointer+","+postfix+" )", 5000);
  }
}

function FadeMessage(div) {
  if (document.getElementById(div)) { 
    wycentrujWarstwe(div,350,0);
    new Effect.Fade(document.getElementById(div), {duration:15});
  }
}

function CenterDiv(div) {
  if (document.getElementById(div)) { 
    wycentrujWarstwe(div,550,0);
  }
}

function blinkDiv(name,onOff,speed)
{
	if (!document.getElementById(name)) return false;
 	var objStyle = document.getElementById(name).style;
	if (objStyle) {
	   objStyle.display = 'block';
	}
  	
  	if (onOff == 'on') {
	   if (!speed) speed = 0.5;
  	   new Effect.Opacity(name, {duration:speed, from:0.0, to:1.0});return false;
  	} else if (speed>0) {
  	   new Effect.Opacity(name, {duration:speed, from:1.0, to:0.0});return false;
  	} else {
  	   new Element.hide(name);return false;
  	}
}

function pokaz(div,onOff)
{
 var obj = document.getElementById(div);
 if (!obj) return false;
 	 var objStyle = document.getElementById(div).style;
 	 if (objStyle) {
	    if (onOff=='off')
	 	   	objStyle.display = 'none';
		 else
		 	objStyle.display = 'block'; 
	 }
}

fotaokno=null;
function fotka( url, nazwa, x, y, scroll ) {
	if (url==0)
	{
		return;
	}
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (noweokno)
	{
		fotaokno.close();
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		if (x1<0)
		{
			x1=0; scroll=1; x=screen.availWidth-50; y=y+40;
		}
		if (y1<0)
		{
			y1=0; scroll=1; y=screen.availHeight-50; x=x+40;
		}
		fotaokno = window.open('','fotogaleria','toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=1,left='+x1+',top='+y1+',width='+x+',height='+y);
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>'+nazwa+'</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	} else
	{
		fotaokno = window.open(url,'fotogaleria','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1');
		fotaokno.document.open();
		fotaokno.document.write ('<html>'); 
		fotaokno.document.write ('<head>'); 
		fotaokno.document.write ('<title>'+nazwa+'</title>'); 
		fotaokno.document.write ('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">'); 
		fotaokno.document.write ('</head>'); 
		fotaokno.document.write ('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
		fotaokno.document.write ('<p align="center"><a href="javascript:void(null)" onClick="window.close();"><img src="'+url+'" border="0"></a></p>'); 
		fotaokno.document.write ('</body>'); 
		fotaokno.document.write ('</html>'); 
		fotaokno.document.close();
		fotaokno.focus();
	}
}


function sprawdz_szukaj()
{
 if (document.forms['szukaj'].szukaj.value.length >= 2)
 {
  return true;
 } else
 {
  return false;
 }
}

function dodajDoUlubionych(adres,tytul)
{

	if (confirm("Dodać stronę do ulubionych?"))
	{
	  window.external.addFavorite(adres, tytul);
	}
}

function przeladuj( adres )
{
  window.document.location.href = adres;
}

// detekcja przegladarki
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5 = false;
if (ie4)
{
	if((navigator.userAgent.indexOf('MSIE 5')> 0)||(navigator.userAgent.indexOf('MSIE 6')> 0)||window.opera)
	{
		ie5=true;
	}
	if (ns6)
	{
		ns6=false;
	}
}


// wielkosc okienka przegladarki
function browsewidth()
{
	if (ns4 || ns6)
	{
        available_width=innerWidth;
    } else {
        available_width=document.body.clientWidth;
    }
	return available_width
}

function browseheight()
{
	if (ns4 || ns6)
	{
        available_height=innerHeight;
    } else {
        available_height=document.body.clientHeight;
    }
	return available_height
}

function wycentrujWarstwe(divv,wid,hei)
{
    // polozenie
  if (browsewidth()>=760)
  {
    x=((browsewidth()/2)-(wid/2));
  } else
  {
    x=300;
  }
  if (browseheight()>=500 && hei > 0)
  {
    y=((browseheight()/2)-(hei/2));
  } else
  {
    y=300;
  }

  // Netscape 4.x Code
  if (ns4)
  {
    objWarstwa = document.layers[divv];
  }
  // Netscape 6.x Code
  if (ns6)
  {
    objWarstwa = document.getElementById(divv).style;
  }
  // IE
  if (ie4 || ie5)
  {
    objWarstwa = eval(document.all[divv]);
    objWarstwa = objWarstwa.style;
  }

  if (x && y)
  {
    objWarstwa.left = x;
    objWarstwa.top = y;
    objWarstwa.width = wid;
    if (hei>0) {
      objWarstwa.height = hei;
    }
  }  
}

function wlaczWarstwe(divv,onoff,wid,hei)
{
    // polozenie
	if (browsewidth()>=760)
	{
		x=((browsewidth()/2)-(wid/2));
	} else
	{
		x=300;
	}
	if (browseheight()>=500)
	{
		y=((browseheight()/2)-(hei/2));
	} else
	{
		y=300;
	}
	if ( onoff == "on" )
	{
		warstwa( divv,'on',x,y,wid,hei );
	}
	if ( onoff == "off" || onoff == null )
	{
		warstwa(divv);
	}


}

function warstwa(nazwa,wlacz,pozx,pozy,wid,hei)
{
	// Netscape 4.x Code
	if (ns4)
	{
		objWarstwa = document.layers[nazwa];
	}
	// Netscape 6.x Code
	if (ns6)
	{
		objWarstwa = document.getElementById(nazwa).style;
	}
	// IE
	if (ie4 || ie5)
	{
		objWarstwa = eval(document.all[nazwa]);
		objWarstwa = objWarstwa.style;
	}

	if (pozx && pozy)
	{
		objWarstwa.left = pozx;
		objWarstwa.top = pozy;
		objWarstwa.width = wid;
		objWarstwa.height = hei;
	}

	if (objWarstwa && (wlacz == 'off' || wlacz == null))
	{
		if (ns4)
		{
			objWarstwa.visibility="hide";
		} else
		{
			objWarstwa.visibility="hidden";
		}
	}

	if (objWarstwa && (wlacz == 'on'))
	{
		if (ns4)
		{
			objWarstwa.visibility="show";
		} else
		{
			objWarstwa.visibility="visible";
		}
	}
}

noweokno=null;
function okno(url,nazwa,x,y,scroll,resize) {
	if (noweokno)
	{
		noweokno.close();
	}
	if (nazwa==null)
	{
		nazwa = '';
	}
	if (scroll==null)
	{
		scroll=0;
	}
	if (resize==null)
	{
		resize=0;
	}
	if (x!=null)
	{
		x1=((screen.availWidth/2)-(x/2)); y1=((screen.availHeight/2)-(y/2));
		noweokno=window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable='+resize+',left='+x1+',top='+y1+',width='+x+',height='+y);
	} else
	{
		window.open(url,nazwa,'toolbar=0,location=0,status=0,menubar=0,scrollbars='+scroll+',resizable=yes,left=0,top=0,width='+(screen.availWidth-40)+',height='+(screen.availHeight-40));
	}
}

function sprawdzZmianeHasla(f)
{
    achtung = "";
    error=false;
    testform = false;
    if (   f.username.value.length==0
        || f.old_password.value.length==0
        || f.new_password.value.length==0
        || f.new_password2.value.length==0
        )
        {
            error = true;
            achtung = "Nie wypełniono wszystkich pól !";
        } else
        {
            if ( f.new_password.value !=
                 f.new_password2.value )
                 {
                    error = true;
                    achtung = "Podane nowe hasło jest różne w dwóch polach !";
                 }
        }

    if (error)
    {
        alert(achtung);
    } else
    {
        var testform = window.confirm("Zapisać nowe hasło ?");
    }
    return testform;
}

function zmien_widok(div, td) {
    d = document.getElementById(div);
    if (d.style.display == 'none') {
        d.style.display = 'block';
        td.innerHTML    = "Schowaj parametry <<";
    } else {
        d.style.display = "none";
        td.innerHTML    = "Pokaż parametry >>";
    }
}

function UlubioneDoKoszyka(f) {
  fr = $(f);
  if (fr) {
    fr.fav_action.value = 'UlubioneDoKoszyka';
    fr.target = '';
    fr.submit();
  } else {
    alert('Problem...');
  }
}

function UlubionePDF(f) {
  fr = $(f);
  if (fr) {
    fr.fav_action.value = 'UlubionePDF';
    fr.target = '_blank';
    fr.submit();
  } else {
    alert('Problem...');
  }
}

function Porownaj(f) {
	  fr = $(f);
	  if (fr) {
		var ar = $$("input.favorite_checkbox:checked");
		if(ar.size() < 2) {
			alert('Musisz zaznaczyć dwa laptopy do porównania');
			return;
		}	
	    fr.fav_action.value = 'Porownaj';
	    fr.target = '_self';
	    fr.submit();
	  } else {
	    alert('Problem...');
	  }
	}

/**
  * @desc Funkcja sprawdza poprawnoć wpisu w polu (dozwolone sa tylko cyfry 0-9 i TYLKO JEDEN znak "."
  * @author Tomasz Szmandra (t.szmandra@lapsoft.pl)
  * @param object obiekt typu input text
  */
function maskaKwota(pole) {
    var myRegExp = /[^0-9,.-]/g;
    str = pole.value;
    str = str.replace(myRegExp,"");
    wart = str.replace(',', '.');
    tab = wart.split('.');
    wart = tab[0];
    if (tab.length > 1) {
      if (tab[1]!='undefined') {
        wart = wart + '.' + tab[1];
      }
    }

    var oEvent = window.event;

    // pomijamy zmiany dla klawisza TAB - bo tracil sie focus
    if (oEvent && ((oEvent.which && oEvent.which!=9 && oEvent.which!=16 && oEvent.which!=37 && oEvent.which!=39) ||
       (oEvent.keyCode && oEvent.keyCode!=9 && oEvent.keyCode!=16 && oEvent.keyCode!=37 && oEvent.keyCode!=39))) {
        pole.value = wart;
        pole.focus();

    } else if (ns4 || ns6) {
    	pole.value = wart;
      pole.focus();
    }
    pole.value = wart;
}

/**
* maskaOnlyDigits
*
* pozostawia w polu jedynie cyfry
*/
function  maskaInt(field) {
        var str, field;
        var myRegExp = /[^0-9]/g;
        str = field.value;
        str = str.replace(myRegExp,"");

        var oEvent = window.event;
        // pomijamy zmiany dla klawisza TAB - bo tracil sie focus
        if (oEvent && ((oEvent.which && oEvent.which!=9 && oEvent.which!=16 && oEvent.which!=37 && oEvent.which!=39) ||
           (oEvent.keyCode && oEvent.keyCode!=9 && oEvent.keyCode!=16 && oEvent.keyCode!=37 && oEvent.keyCode!=39))) {
          field.value = str;
          field.focus();

        }  else if (getBrowser()=='ns6') {
          field.value = str;
          field.focus();
        }
}

function changeCheckbox(ch) {
  var f = ch.checked;
  var d = document.getElementsByName('wybrane[]');
  if (d) {
    for(i=0; i<d.length; i++) {
      d[i].checked = f;
    }
  }  
}

function textChanger_cb(result) {
  result = (unescape(result.responseText));
  if (DEBUG_AJAX) alert(result);
  var result_array = result.split("~~|~~");
  if (DEBUG_AJAX) alert(result_array[0] +'\n' + result_array[1])
  if ( trim(result_array[0]) == 'Location' )
  {
    document.location = trim(result_array[1]);
  } else {
    elem = document.getElementById(result_array[1]);
    elem.innerHTML = result_array[0];
  }
  wlaczWarstwe("waitIcon","off");
}

function parseForm(cellID, inputID) {
  var temp = document.getElementById(inputID).value;
  var obj = /^(\s*)([\W\w]*)(\b\s*$)/;

  if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
  var obj = /  /g;
  while (temp.match(obj)) { temp = temp.replace(obj, " "); }
  if (temp == " ") { temp = ""; }
  if (! temp) {alert("This field must contain at least one non-whitespace character.");return;}

  var st = document.getElementById(inputID).value;

  var objChars = Array("%u2013","%u201E",'%u201D');
  var objChRep = Array("-","`","`");
  for (var i = 0; i < objChars.length; i++) {
    while (st.match(objChars[i]))
    {
      st = st.replace(objChars[i], objChRep[i]);
    }
  }
  st = escape(st.replace(/\+/g, "^plus^"));
  if (DEBUG_AJAX) alert(cellID);
  if (DEBUG_AJAX) alert(st);  
  tab = cellID.split("#^#");
	advAJAX.post({
		/*url : 'ajax.php?a=textChanger&id='+tab[0]+'&table='+tab[1]+'&column='+tab[2]+'&st='+st, */
    url : 'ajax.php',
    parameters:{
               a: 'textChanger',
               id: tab[0],
               table: tab[1],
               column: tab[2],
               st: st
    }, 
		onInitialization : function() {
      document.getElementById(cellID).innerHTML = "<span class=\"update\">Updating...</span>";
      document.getElementById(cellID).style.border = 'none'; 
		},
		onSuccess : function(obj) { 
      textChanger_cb(obj);
    },
		onError : function(obj) { 
		  document.getElementById(cellID).innerHTML = "Błąd AJAX-a"; 
		}
	});  
}

/**
	* Przekazanie danych do AJAX i dodanie pozycji do ulubionych
	*/
function parseFormAddFavorite(cellID, idT) { 
	advAJAX.get({
		url : 'ajax.php?a=AddFavorite&id='+idT,
		onInitialization : function() { 
      wlaczWarstwe("waitIcon","on",150,50);
		},
		onSuccess : function(obj) { 
      s_prepare(cellID, obj);
      wlaczWarstwe("waitIcon","off");
    },
		onError : function(obj) { 
		  wlaczWarstwe("waitIcon","off");
		  alert("Błąd AJAX-a"); 
		}
	});
}

function parseFormAddCompare(cellID, idT) { 
	advAJAX.get({
		url : 'ajax.php?a=AddCompare&id='+idT,
		onInitialization : function() { 
      wlaczWarstwe("waitIcon","on",150,50);
		},
		onSuccess : function(obj) { 
      s_prepare(cellID, obj);
      wlaczWarstwe("waitIcon","off");
    },
		onError : function(obj) { 
		  wlaczWarstwe("waitIcon","off");
		  alert("Błąd AJAX-a"); 
		}
	});
}

function parseFormDelCompare(cellID, idT) { 
	advAJAX.get({
		url : 'ajax.php?a=DelCompare&id='+idT,
		onInitialization : function() { 
      wlaczWarstwe("waitIcon","on",150,50);
		},
		onSuccess : function(obj) { 
      s_prepare(cellID, obj);
      wlaczWarstwe("waitIcon","off");
    },
		onError : function(obj) { 
		  wlaczWarstwe("waitIcon","off");
		  alert("Błąd AJAX-a"); 
		}
	});
}
    
/**
	* Przekazanie danych do AJAX
	*/
function parseFormUsunDoplateDodatki(cellID, idT) {
  if (confirm("Na pewno chcesz usunąć tą dopłatę ?\nUsuniesz ją globalnie dla wszystkich produktów !")) {
	  advAJAX.get({
		  url : 'ajax.php?a=UsunDoplateDodatki&id='+idT,
		  onInitialization : function() { 
        wlaczWarstwe("waitIcon","on",150,50);
		  },
		  onSuccess : function(obj) { 
        s_prepare(cellID, obj);
        elem = document.getElementById(cellID);
        elem.innerHTML = '';
        //elem.parentNode.deleteRow(elem.rowIndex);
        wlaczWarstwe("waitIcon","off");
      },
		  onError : function(obj) { 
		    wlaczWarstwe("waitIcon","off");
		    alert("Błąd AJAX-a"); 
		  }
	  });
  }
}

function parseFormZmienDoplate(cellID, idT, checked) {
  if (checked) {
    a = "ZaznaczDoplate";
  } else {
    a = "OdznaczDoplate";
  }
  advAJAX.get({
    url : 'ajax.php?a='+a+'&id='+idT,
    onInitialization : function() { 
      elem = document.getElementById(cellID);
      elem.innerHTML = q_loading_gif;    
      //wlaczWarstwe("waitIcon","on",150,50);
    },
    onSuccess : function(obj) { 
      s_prepare(cellID, obj);
      elem = document.getElementById(cellID);
      elem.innerHTML = '';
      //elem.parentNode.deleteRow(elem.rowIndex);
      //wlaczWarstwe("waitIcon","off");
    },
    onError : function(obj) { 
      elem = document.getElementById(cellID);
      elem.innerHTML = '';    
      //wlaczWarstwe("waitIcon","off");
      alert("Błąd AJAX-a"); 
    }
  });
}

function parseFormZmienTowaryIkonki(cellID, idT, checked) {
  if (checked) {
    a = "ZaznaczIkonke";
  } else {
    a = "OdznaczIkonke";
  }
  advAJAX.get({
    url : 'ajax.php?a='+a+'&id='+idT,
    onInitialization : function() { 
      elem = document.getElementById(cellID);
      elem.innerHTML = q_loading_gif;    
      //wlaczWarstwe("waitIcon","on",150,50);
    },
    onSuccess : function(obj) { 
      s_prepare(cellID, obj);
      elem = document.getElementById(cellID);
      elem.innerHTML = '';
      //elem.parentNode.deleteRow(elem.rowIndex);
      //wlaczWarstwe("waitIcon","off");
    },
    onError : function(obj) { 
      elem = document.getElementById(cellID);
      elem.innerHTML = '';    
      //wlaczWarstwe("waitIcon","off");
      alert("Błąd AJAX-a"); 
    }
  });
}
    
function changerID(cellID, cellInfo) {
  var tab = cellID.split("#^#");  
  var st = 0;
  if (tab.length < 4) {
    st = document.getElementById(cellID).value;
  } else {
    st = tab[3];
  }
  if (st>0) {
    advAJAX.get({
      url : 'ajax.php?a=idChanger&id='+tab[0]+'&table='+tab[1]+'&column='+tab[2]+'&st='+st,
      onInitialization : function() { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = 'Updating...';
      },
      onSuccess : function(obj) { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = obj.responseText;
      },
      onError : function(obj) { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = 'Błąd AJAX-a';    
      }
    });
  }
} 

function changerTextID(cellID, cellInfo) {
	  var tab = cellID.split("#^#");  
	  var st = "";
	  var elemSelect = document.getElementById(cellID);
	  for(i=0; i<elemSelect.length; i++) {
		  if (elemSelect[i].selected) {
			  st += ' '+elemSelect[i].value+',';
		  }
	  }
	    advAJAX.get({
	      url : 'ajax.php?a=textChanger&id='+tab[0]+'&table='+tab[1]+'&column='+tab[2]+'&st='+st,
	      onInitialization : function() { 
	        elem = document.getElementById(cellInfo);
	        elem.innerHTML = 'Updating...';
	      },
	      onSuccess : function(obj) { 
	        elem = document.getElementById(cellInfo);
	        elem.innerHTML = "Ok!";
	      },
	      onError : function(obj) { 
	        elem = document.getElementById(cellInfo);
	        elem.innerHTML = 'Błąd AJAX-a';    
	      }
	    });
	}

function changerMainArticleID(cellID, cellInfo, typ_podstrony) {
  var tab = cellID.split("#^#");  
  var st = 0;
  if (tab.length < 4) {
    st = document.getElementById(cellID).value;
  } else {
    st = tab[3];
  }
  if (st>0) {
    advAJAX.get({
      url : 'ajax.php?a=idChangerMainArticle&id='+tab[0]+'&table='+tab[1]+'&column='+tab[2]+'&tp='+typ_podstrony+'&st='+st+'&nazwa='+tab[4],
      onInitialization : function() { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = 'Updating...';
      },
      onSuccess : function(obj) { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = obj.responseText;
      },
      onError : function(obj) { 
        elem = document.getElementById(cellInfo);
        elem.innerHTML = 'Błąd AJAX-a';    
      }
    });
  }
}
    
    var editCellHeight = 0;
    function setEditCellHeight( el )
    {
    	editCellHeight = el+"px";
    }

    var ie4 = (document.all)? true:false;

    function editCell(id, cellSpan) {
        var inputWidth = ( document.getElementById(id).offsetWidth );
        var inputHeight = ( document.getElementById(id).style.height );

        if ( inputHeight == '' )
        {
        	if ( editCellHeight != '' )
        	{
        		inputHeight = editCellHeight;
        	} else {
        		inputHeight = "40px";
        	}
        }

        var oldCellSpan = cellSpan.innerHTML;

        //alert(oldCellSpan);
        oldCellSpan = escape(oldCellSpan);
        var objChars = Array('%0D%0A');
        var objChRep = Array("");
        for (var i = 0; i < objChars.length; i++) {
        	while (oldCellSpan.match(objChars[i]))
        	{

        		oldCellSpan = oldCellSpan.replace(objChars[i], objChRep[i]);
        	}
        }
        oldCellSpan = unescape(oldCellSpan);
        //alert(oldCellSpan);

        var objChars = Array("<br>\n","<BR>\n",'<BR>','<br>','&nbsp;');
        var objChRep = Array("\n","\n","\n","\n",'');
        for (var i = 0; i < objChars.length; i++) {
        	while (oldCellSpan.match(objChars[i]))
        	{

        		oldCellSpan = oldCellSpan.replace(objChars[i], objChRep[i]);
        	}
        }


        /*var objChars = Array("\n");
        if ( ie4 == false )
        {
        	var objMozilla = Array("\n");
        	for (var i = 0; i < objMozilla.length; i++) {
        		while (oldCellSpan.match(objMozilla[i])) { oldCellSpan = oldCellSpan.replace(objMozilla[i], ''); }
        	}
        }*/

        document.getElementById(id).innerHTML = "<form name=\"activeForm\" onsubmit=\"parseForm('"+id+"', '"+id+"input');return false;\" style=\"margin:0;padding:0px;\" action=\"\"><TEXTAREA ROWS=\"2\" class=\"editCell\" id=\""+id+"input\" size=\""+ inputWidth + "\" onblur=\"parseForm('"+id+"', '"+id+"input');return false;\" style=\"margin:0px;padding:0px;width:100%;height:"+inputHeight+"\"></TEXTAREA><br /><noscript><input value=\"OK\" type=\"submit\"></noscript></form>";
        document.getElementById(id+"input").value = oldCellSpan;
        document.getElementById(id+"input").select();
        document.getElementById(id+"input").focus();
        //document.getElementById(id).style.background = '#ffc';
        //document.getElementById(id).style.border = '1px solid #fc0';
    }

function bgSwitch(ac, td, col) {
  if (ac == 'on'){
    td.style.background = '#ffc';
  } else if (ac == 'off' && !col){
    td.style.background = '#E6E6E6';
  } else if (ac == 'off' && col){
    td.style.background = col;
  }
}
    
function s_prepare(d, obj) {
  var xmlDoc = obj.responseXML;
  if (DEBUG_AJAX) alert(obj.responseText);
  var amr = document.getElementById(d);
  var body = xmlDoc.getElementsByTagName("body");
  var script = xmlDoc.getElementsByTagName("script");
  
  if(body.length>0)
  {   
    var nodes = body[0].childNodes;
    for(var i=0;i<nodes.length;i++)
    {
      if (DEBUG_AJAX) alert(nodes[i].nodeType + ' ' + nodes[i].nodeName + ' ' +nodes[i].nodeValue); 
      if (nodes[i].nodeType==1 || nodes[i].nodeType==3 || nodes[i].nodeType==4) {
        amr.innerHTML = nodes[i].nodeValue;
      }                
    }
  }
  if(script.length>0)
  {
    var nodes = script[0].childNodes;
    for(var i=0;i<nodes.length;i++)
    {
      if (DEBUG_AJAX) alert(nodes[i].nodeType + ' ' + nodes[i].nodeName + ' ' +nodes[i].nodeValue); 
      if (nodes[i].nodeType==3) {
        eval(nodes[i].nodeValue);
      }                
    }
  }
}    

function submit_form(form_name, div) {
    if (!document.getElementById(form_name)) {
        alert('Brak formularza '+form_name);
        return false;
    };

    advAJAX.submit(document.getElementById(form_name), {
        headers : {
            "accept"          : "*/*",
            "accept-language" : "pl",
            "accept-charset"  : "ISO-8859-2,utf-8;q=0.7,*;q=0.7"
        },
	    onInitialization : function() { 
            document.getElementById(div).innerHTML = q_loading_string;
        },
	    onSuccess : function(obj) { 
            s_prepare(div, obj);
        },
	    onError : function(obj) { 
            document.getElementById(div).innerHTML = 'Błąd AJAX-a';
        }
    });
    return false;
}

// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function setFilterManagerSrc( div, adminFilter ) {
  document.getElementById(div).src = 'manager.filter.php?col='+adminFilter;
}

function setConfigManagerSrc( div ) {
  document.getElementById(div).src = 'manager.config.php';
}

function kopiujAdres(src, trg) {
  tab = new Array('nazwa', 'ulica', 'kod_pocztowy', 'miasto');
  for (i=0; i<tab.length; i++) {
    src_inp = document.getElementById(src + '__' + tab[i]);
    trg_inp = document.getElementById(trg + '__' + tab[i]);
    if (src_inp && trg_inp) {
      trg_inp.value = src_inp.value;
    }
  }
}

function poprawZamowienie() {
  f = document.zamowienie;
  if (f) {
    f.action = "index.php?order=1";
    f.submitform.click();
  }
}

function openURL(url, trg){ 
  if (trg == '_self') {
    document.location = url;
  } else {
    okno = window.open(url);
  }
}

function switchDiv(divId) {  
  var d = document.getElementById(divId);
  if (d) {
      if (d.style.display == 'none') {
      d.style.display = 'block';
    } else {
      d.style.display = 'none';
    }
  }
  for (i=1; i<=4; i++) {
    if (divId != "ikonki"+i) {
      d = document.getElementById("ikonki"+i);
      if (d) {    
        d.style.display = 'none';
      }
    }
  }
}

function ajaxTinyMCESave(editorID) {
  var ed = tinyMCE.get(editorID);
  tab = editorID.split("#^#");
  advAJAX.post({
    headers : {
        "accept"          : "*/*",
        "accept-language" : "pl",
        "accept-charset"  : "ISO-8859-2,utf-8;q=0.7,*;q=0.7"
    },
    url : 'ajax.php',
    parameters:{
               a: 'textChanger',
               id: tab[0],
               table: tab[1],
               column: tab[2],
               st: ed.getContent()
    }, 
    onInitialization : function() {
      ed.setProgressState(1);
    },
    onSuccess : function(obj) { 
      ed.setContent(obj.responseText);
      ed.setProgressState(0);
    },
    onError : function(obj) { 
      ed.setProgressState(0); 
      alert("Błąd AJAX-a"); 
    }
  });
  return false;  
}

function rozwin(cssClassName) {
	var ar = $$('span.'+cssClassName);
	ar.each(function(item) {
		item.show();
		item.up().show();
	});
	$(cssClassName+'_wiecej').hide();
	$(cssClassName+'_zwin').show();
	$(cssClassName.replace("_span","_div")).addClassName("choosecriteria");
}

function zwin(cssClassName) {
	var ar = $$('span.'+cssClassName);
	var index = 0;
	var max = 4;
	ar.each(function(item) {
		index++;
		if (index>max) {
			item.hide();
			if (index > 8) {
				item.up().hide();
			}
		}
	});
	$(cssClassName+'_wiecej').show();
	$(cssClassName+'_zwin').hide();	
	$(cssClassName.replace("_span","_div")).removeClassName("choosecriteria");
}

function criteriaFill(event) {
	var element = event.element();
	//alert(element.name);
	if (element.checked) {
		$('criteria_txt').insert(' <span id="crit_'+element.value+'">'+element.title+'</span>');
	} else {
		$('crit_'+element.value).remove();
	}
}

function compareShowAll() {
	var ar = $$('tr.compare');
	ar.each(function(item) {
		item.show();
	});
}

function compareShowDiff() {
	var ar = $$('tr.nodiff');
	ar.each(function(item) {
		item.hide();
	});
}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++) {
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
  }
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)
}

function popupNewsletter(myform)
{
    if (! window.focus) return true;
		var email = myform.email.value; 
    okno(myform.action + '?email=' + email,'newsletter',500,300,'yes','yes' );
    myform.target='newsletter';
    return false;
}