var last_opened;

var mcw;
var mlast_opened;

    window.addEvent('domready', function()
    {
    	
    	var slider = new Array();

		var st = $$(".cat_container");
		$$(".cat").each(function(element,index)
		{
				st[index].slide('hide');
  			slider[index] = new Fx.Slide(st[index]);
   			element.addEvent("click",function()
   			{
      			slider[index].slideIn();
      			if(slider[last_opened])
      				slider[last_opened].slideOut();		
   				last_opened = index;
   			});
		});
if($$(".mcat"))
{
		var mslider = new Array();
		var mcw = new Hash.Cookie("mopen_widget", {autoSave: true, duration: 7200, path: "/"});
		var mst = $$(".mcat_container");
		$$(".mcat").each(function(element,index)
		{
			if(mcw.get("mopened_widget")==index)
				mlast_opened = index;
			else
				mst[index].slide('hide');
  			mslider[index] = new Fx.Slide(mst[index]);
   			element.addEvent("click",function()
   			{
      			mslider[index].slideIn();
      			if(mslider[mlast_opened])
      				mslider[mlast_opened].slideOut();
   				mcw.set("mopened_widget",index);		
   				mlast_opened = index;
   			});
		});
}
	});

/* javascript:search_list( 1, 1,1 ) */
function search_list( z1, z2, z3 )
{

		/* alert("index.php?z1="+z1+"&z2="+z2+"&z3="+z3+"&mode=ajax"); */
		 advAJAX.get({
		 url: "index.php?z1="+z1+"&z2="+z2+"&z3="+z3+"&mode=ajax",
		 onLoading : function(obj) { if($('konf_prod')) $('konf_prod').innerHTML = "" },
		 onError : function(obj) {  if($('konf_prod')) $('konf_prod').innerHTML = "<span style='color: #ffffff'>Blad.</span>"; },
		 onSuccess : function(obj)
		 {
		 	if($('konf_prod'))
		 	{

			 	if(obj.responseText)
			 	{
		 			$('konf_prod').innerHTML =  obj.responseText;
		 			$('rs_bottom').setStyle('display', 'block');
					$('lp').setStyle('display', 'block');
					$('rs_bottom_btm').setStyle('display', 'block');
			 	}
			 	else
			 	{
					$('konf_prod').innerHTML =  "<div class='cat_item'><a href='#'>Brak wyników</a></div>";
		 			$('rs_bottom').setStyle('display', 'block');
					$('lp').setStyle('display', 'block');
					$('rs_bottom_btm').setStyle('display', 'block');
			 	}
			 }
		 }
		 });
}
function change_prod(id)
{
	if($('kat'+id))
		$('kat'+id).setStyle('color', '#f05223');
}

function clearText (field,what) {
    if(field.value==what)
      field.value = "";

}
function writeText (field,what) {
    if(field.value=="")
      field.value = what;

}
function sh( name, cent )
{
 var item = document.getElementById( name );
 if(item.style.display == 'block')
   item.style.display = 'none';
 else
   if(item.style.display = 'none')
     item.style.display = 'block';
 if(cent=="1")
 {
   window.scrollTo(0,0);
 }
}

function sl( name, evt )
{
  var html = " <table border='1' style='width: 317px;' class='dictionary_table'>                                                                              " +
"          <tbody>                                                                                                                                             " +
"                                                                                                                                                              " +
"             <tr>                                                                                                                                             " +
"                <td class='dictionary_title'>                                                                                                                 " +
"                   <div style='position: relative; float: left;' id='dictionary_tit'>Brak danych</div>                                                        " +
"                   <div style='position: relative; float: right; cursor: pointer;'>                                                                           " +
"                      <a style='color: #ffffff;' href='#' onclick='destroyDiv(\"dictionarybox\"); return false;'>X</a>                                                " +
"                   </div>                                                                                                                                     " +
"                </td>                                                                                                                                         " +
"             </tr>                                                                                                                                            " +
"                                                                                                                                                              " +
"             <tr>                                                                                                                                             " +
"                <td style='vertical-align: top;'>                                                                                                             " +
"                   <div style='display: table;' id='dictionary_desc'>Brak danych</div>                                                                        " +
"                   <div style='clear: both;'>                                                                                                                 " +
"                      <a href='/dictionary/' id='link_dict' style='font-weight: bold; float: right;' title='S&#322;ownik'>Przejd&#378; do s&#322;ownika</a>   " +
"                   </div>                                                                                                                                     " +
"                                                                                                                                                              " +
"                </td>                                                                                                                                         " +
"             </tr>                                                                                                                                            " +
"          </tbody>                                                                                                                                            " +
"       </table>                                                                                                                                               ";
    var item = creatediv('dictionarybox', html, 517);
//    var item = document.getElementById( 'dictionarybox' );
    if(evt.pageX)
    {
      var xpos = evt.pageX;
      var ypos = evt.pageY;
      ypos = ypos+30;
    }
    else
    {
      var xpos = evt.clientX;
      var ypos = (document.documentElement.scrollTop + evt.clientY);

    }

    xpos = xpos+5;

       item.style.position = 'absolute';
       item.style.left = xpos+"px";
      item.style.top = ypos+"px";
       item.style.display = 'block';
       document.getElementById( 'dictionary_tit' ).innerHTML = name;
       document.getElementById( 'link_dict' ).href = "dictionary/#"+name.replace(" ", "_");

 /*      url: "myadmin.php?act=&mode=ajax&param=",
       url: "index.php?mod=23&mode=ajax&var=" + name,    */
     //  alert("index.php?mod=23&mode=ajax&var=" + name);
      advAJAX.get({
       url: "index.php?mod=33&mode=ajax&var=" + name,
       onLoading : function(obj) { document.getElementById( 'dictionary_desc' ).innerHTML = '<div class="processing" style="background-image: url(./template/www/img/processing2.gif); position: relative; height: 50px; display: block; left: 0px; margin-left: 130px; margin-top: 35px;"><!-- --></div>'; },
       onError : function(obj) { document.getElementById( 'dictionary_desc' ).innerHTML = '<div class="error" style="left: 0px; margin-left: 150px;  display: block; margin-top: 35px;"><!-- --></div>';  },
    /*   onSuccess : function(obj) { document.getElementById( 'dictionary_desc' ).innerHTML = obj.responseText; alert(obj.responseText); document.getElementById( 'dictionary_desc' ).style.display= ""; }*/
       onSuccess : function(obj)
       {
         document.getElementById( 'dictionary_desc' ).innerHTML = obj.responseText;
       }
   });



}

function creatediv(id, html, width) {

   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);

   if (width) {
       newdiv.style.width = width;
   }





   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "";
   }

   document.body.appendChild(newdiv);
     return  newdiv;
}
function destroyDiv(id) {
   obj = document.getElementById(id);
   document.body.removeChild(obj);
}
function hl( name )
{
  var item = document.getElementById( name );
  item.style.display = 'none';
}
function showTab( tab )
{
  var t1 = document.getElementById( "tab1" );
  var t2 = document.getElementById( "tab2" );
  var t3 = document.getElementById( "tab3" );
  var t4 = document.getElementById( "tab4" );

  var p = document.getElementById( 'panel' );
  var p1 = document.getElementById( "panel1" );
  var p2 = document.getElementById( "panel2" );
  var p3 = document.getElementById( "panel3" );
  var p4 = document.getElementById( "panel4" );
  if(tab==1)
  {
    if(p1.innerHTML=="<div style=\"display: table;\"></div>")
       return false;

    t1.className = 'tab_a';
    t2.className = 'tab';
    t3.className = 'tab';
    t4.className = 'tab_p';
      p.innerHTML = p1.innerHTML;
  }
  if(tab==2)
  {
    if(p2.innerHTML=="<div style=\"display: table;\"></div>")
       return false;

    t1.className = 'tab';
    t2.className = 'tab_a';
    t3.className = 'tab';
    t4.className = 'tab_p';
    p.innerHTML = p2.innerHTML;
  }
  if(tab==3)
  {
    if(p3.innerHTML=="<div style=\"display: table;\"></div>")
       return false;
    t1.className = 'tab';
    t2.className = 'tab';
    t3.className = 'tab_a';
    t4.className = 'tab_p';
    p.innerHTML = p3.innerHTML;
  }
  if(tab==4)
  {
    if(p4.innerHTML=="<div style=\"display: table;\"></div>")
       return false;
    t1.className = 'tab';
    t2.className = 'tab';
    t3.className = 'tab';
    t4.className = 'tab_a';
    p.innerHTML = p4.innerHTML;
  }

}

function sendFormPolec()
{
   advAJAX.submit(document.getElementById('polecForm'), {
    onSuccess : function(obj) { document.getElementById( 'pContent' ).innerHTML = obj.responseText; },
    onLoading : function(obj) { document.getElementById( 'pContent' ).innerHTML = '<div class="wait"><!-- --></div>'; },
    onError : function(obj) { document.getElementById( 'pContent' ).innerHTML = '<div class="error"><!-- --></div>'; }
   });
}
function anon()
{
	var imie_label = $('imie_label');
	var nazwisko_label = $('nazwisko_label');
	var anon_checkbox = $('anon');
	if(anon_checkbox.checked==true)
	{
		imie_label.style.display='none';
		nazwisko_label.style.display='none';
	}
	else
	{
		imie_label.style.display='';
		nazwisko_label.style.display='';
	}
}

 function sendFormProblem()
{
   advAJAX.submit(document.getElementById('problemForm'), {
    onSuccess : function(obj) { document.getElementById( 'pContent1' ).innerHTML = obj.responseText; },
    onLoading : function(obj) { document.getElementById( 'pContent1' ).innerHTML = 'Proszę czekać trwa wysyłanie reklamacji'; },
    onError : function(obj) { document.getElementById( 'pContent1' ).innerHTML = 'Wystąpił błąd'; }
   });
}


function loadCountry(  target, param )
{
 advAJAX.get({
 url: "cart/"+param,
 onLoading : function(obj) { document.getElementById( target ).innerHTML = '<div class="pElemLight" style="display: table; height: 200px;"><div class="wait"><!-- --></div></div>'; },
 onError : function(obj) { document.getElementById( target ).innerHTML = '<div class="pElemLight" style="display: table; height: 200px;"><div class="error"><!-- --></div></div>'; },
 onSuccess : function(obj) { document.getElementById( target ).innerHTML = obj.responseText; }
 });
}

function showFullStepByStep()
{
   var _size = ',width=850,height=350';
   var _config = 'toolbar=no,location=no,directories=no,status=no,menubar=no' + _size + ',scrollbars=no,resizable=no';

   window.open ( window.location.href + '.steps', "" ,_config);
}
function showFullGW()
{
   var _size = ',width=850,height=450';
   var _config = 'toolbar=no,location=no,directories=no,status=no,menubar=no' + _size + ',scrollbars=no,resizable=no';

   window.open ( window.location.href + '.gw', "" ,_config);
}
function open_gal(id)
{
	id.each(function(item){ 
		if($('kategoria'+item))
			$('kategoria'+item).fireEvent('click');
	}
	);
}