jQuery(document).ready(function(){
  jQuery('#FacebookContainter .fb_logo').click(function(){
    jQuery(this).parent().find('.fb_wrapper').toggle('slow');
  }); 
});




function check_if_logged()
{
	
$.ajax({
  type: "POST",
  url: "/jquery.php",
  data: "o=check_logged",
 success: function(msg){
	 $("#zaloguj_menu_li").html(msg);
   }
 });
}





function wine_search()
{
	alert('enter');
	
	var nazwa=document.getElementById('wino_name').value;
	var type=document.getElementById('wine_type').value;
	var sub_type=document.getElementById('wine_sub_type').value;
	var region=document.getElementById('wine_region').value;
	var volume=document.getElementById('wine_volume').value;
	var year=document.getElementById('wine_year').value;
//	var price_from=document.getElementById('wine_year').value;
//	var price_to=document.getElementById('wine_year').value;
	var zapytanie='';
	
	if(nazwa!='')
		{
			zapytanie=zapytanie+" and name REGEXP '"+nazwa+"'";
		}
	if(type!='')
		{
			zapytanie=zapytanie+" and type='"+type+"'";
		}
	if(sub_type!='')
		{
			zapytanie=zapytanie+" and sub_type='"+sub_type+"'";
		}
	if(region!='')
		{
			zapytanie=zapytanie+" and region='"+region+"'";
		}
	if(volume!='')
		{
			zapytanie=zapytanie+" and volume='"+volume+"'";
		}
	if(year!='')
		{
			zapytanie=zapytanie+" and year='"+year+"'";
		}

		
		
	$.ajax({
  type: "POST",
  url: "jquery_menu.php",
  data: "o=search_wine&q="+zapytanie,
 success: function(msg){
	 
											  $("#display_group").html(msg);

	 $("#cat_name").html="Wyniki wyszukiwania";
   }
 });
}


function coffee_search()
{
	var nazwa=document.getElementById('kawa_name').value;
	var rodzaj=document.getElementById('coffee_type').value;
	var waga=document.getElementById('coffee_weight').value;
	var zapytanie='';
	
if(nazwa!='')
		{
			zapytanie=zapytanie+" and name REGEXP '"+nazwa+"'";
		}	

if(rodzaj!='')
		{
			zapytanie=zapytanie+" and type='"+rodzaj+"'";
		}

if(waga!='')
		{
			zapytanie=zapytanie+" and weight='"+waga+"'";
		}
		

//alert(zapytanie);
$.ajax({
  type: "POST",
  url: "jquery_menu.php",
  data: "o=search_coffee&q="+zapytanie,
 success: function(msg){
	 
											  $("#display_group").html(msg);

	 $("#cat_name").html="Wyniki wyszukiwania";
   }
 });


}





function validate_delivery_form()
{
var i=$("#mname").val();
var n=$("#msurname").val();
var u=$("#mstreet").val();
var m=$("#mcity").val();
var p=$("#mpost").val();
var t=$("#mphone").val();

var fv=$("#fvat").val();
var fc=$("#fcompany").val();
var fu=$("#fstreet").val();
var fm=$("#fcity").val();
var fp=$("#fpost").val();
var fn=$("#fnip").val();
var e=0;
var emsg='';


///zaczynamy tą mękę
if(i.length<2)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole imię";
		$("#mname").css('border','2px red solid');
	}
if(n.length<2)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole nazwisko";
		$("#msurname").css('border','2px red solid');
	}
if(u.length<2)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole ulica/nr domu/lokalu";
		$("#mstreet").css('border','2px red solid');
	}

if(m.length<2)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole miasto";
		$("#mcity").css('border','2px red solid');
	}

if(p.length!=6)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole kod pocztowy";
		$("#mpost").css('border','2px red solid');
	}

if(t.length!=11)
	{
		e=1;
		emsg=emsg+"\n Uzupełnij pole nr telefonu (format: XXX-XXX-XXX)";
		$("#mphone").css('border','2px red solid');
	}

if(fv==1)
	{
		
	if(fc.length<2)
	{
		e=1;
		emsg=emsg+"\n Faktura - uzupełnij nazwę firmy";
		$("#fcompany").css('border','2px red solid');
	}
	
	if(fu.length<2)
	{
		e=1;
		emsg=emsg+"\n Faktura - uzupełnij nazwę ulicy/numer domu/lokalu";
		$("#fstreet").css('border','2px red solid');
	}
	
	if(fp.length!=6)
	{
		e=1;
		emsg=emsg+"\n Faktura - uzupełnij pole kod pocztowy";
		$("#fpost").css('border','2px red solid');
	}
	
	if(fn.length!=13)
	{
		e=1;
		emsg=emsg+"\n Faktura - podaj poprawny numer NIP";
		$("#nip").css('border','2px red solid');
	}
	
		if(fn.length<2)
	{
		e=1;
		emsg=emsg+"\n Faktura - podaj poprawną nazwę miasta/miejscowości";
		$("#fcity").css('border','2px red solid');
	}
	
		
		
		
		
		
		
		
		
		
	}

	if(e==1)
		{
			alert("Proszę poprawić formularz "+emsg);
		}
		else
		{
			$("[name='Zamow']").attr('disabled',true);
			$("[name='Zamow']").after("<p>Zamówienie jest wysyłane do sklepu - prosimy czekać</p>");
			document.dostawa.submit();
		}	

}



function url(adres)
{
	location.href=adres;
}







function favourite(pid)
{
	$("#favourite_display").html("<div class='loading'>Trwa ładowanie wyników...</div>");
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=favourites&p="+pid,
   success: function(msg){
		$("#favourite_display").html(msg);
   }
 });
}

function load_login_form(final)
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=load_login_form",
   success: function(msg){
		$("#"+final).html(msg);
   }
 });
}

function load_new_client_form(final)
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=load_new_client_form",
   success: function(msg){
		$("#"+final).html(msg);
   }
 });
}



function erase_from_cart(pid)
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=erase_from_cart&oid="+pid,
   success: function(msg){
	   
	    update_side_cart('side_cart_header');
	   update_cart('koszyk_content');
	 	count_free_shipment('koszyk_darmowa_przesylka');
		
	   




   }
 });
}


function feed_form()
{
	$("#feed_form").css('height','400px');
	$("#feed_form").css('z-index','6000');
	$("#add_feedback").css('height','200px');
	$(".feed_reg").fadeIn('slow');

}

function change_password(token,email,pass)
{
	if(document.getElementById('pass').value==document.getElementById('repass').value)
		{
			$.ajax({
			   type: "POST",
			   url: "remind.php",
			   data: "option=changepass&email="+email+"&token="+token+"&pass="+document.getElementById('pass').value,
			   success: function(msg){
				  
				 document.getElementById('przypomnienie_hasla').innerHTML=msg;
			   }
			 });
		}
		else
		{
			alert('Hasla sie nie zgadzaja. Prosze upewnic sie, ze hasla sa takie same');
		}
}

function remind_password(pole)
{
	$.ajax({
   type: "POST",
   url: "remind.php",
   data: "option=remind&email="+$("#email").val(),
   success: function(msg){
     document.getElementById('przypomnienie_hasla').innerHTML=msg;
   }
 });
}

function hide_feed_form()
{
	$("#feed_form").css('height','130px');
	$("#feed_form").css('z-index','5');
	$("#add_feedback").css('height','70px');
	$(".feed_reg").fadeOut('slow');

}

function add_new_feedback(d,pid)
{
	var txt=$("#add_feedback").val();
	var sig=$("#signature").val();
	var error=0;
	var emsg='';
	if(txt.length<10)
		{
			error=1;
			emsg='Opinia jest podejrzanie krótka. Powinna mieć min. 10 znaków';
		}
	if(sig.length<5)
		{
			error=1;
			emsg=emsg+'<br />'+'Nie podano podpisu';
		}
	if(error!=1)
		{
			
		$.ajax({
					   type: "POST",
					   url: "/jquery.php",
					   data: "o=insert_feedback&id="+pid+"&d="+d+"&content="+txt+"&signature="+sig,
					   success: function(msg){
						   hide_feed_form();
						   $("#feed_form").slideUp('slow',function ()
																		{
																		
																		$("#feed_form").html("<div align='center' class='feed_ok'><img src='/kawa_img/dziekujemy.png' alt='Dziękujemy' title='Dziękujemy za dodanie opinii' border='0' align='absmiddle /> Dziękujemy!<br />Opinia została poprawnie dodana i posłuży innym Użytkownikom przy dokonaniu właściwych wyborów.</div>");
																		});
						
						$("#feed_form").slideDown('slow');
					  						 }
									});
		}
		else
		{
			$("#info").html(emsg);
		}
}




function ssij(pid,d,lim)
{
	$("#feed_content").slideDown('slow').css('height','auto');
	
	$("#feedback_present").slideDown('slow').css('border','none');
//	$("#feed_content").css('height','300px');
	$("#feed_content").css('z-index','12');
	$("#feed_content").css('border','1px #FFCC33 solid');
	$("#feed_content").css('border-top','none');
	
		$.ajax({
					   type: "POST",
					   url: "/jquery.php",
					   data: "o=get_feedback&pid="+pid+"&d="+d+"&lim="+lim,
					   success: function(msg){
							$("#feed_content").html(msg);
					  						 }
									});
}
// Kawa ziarnista, kawa lavazza, kawa sklep - skrypty

var month = '*'; // 1 through 12 or '*' within the next month, '0' for the current month
var day = '+1';   // day of month or + day offset
var dow = 0;     // day of week sun=1 sat=7 or 0 for whatever day it falls on
var hour = 15;    // 0 through 23 for the hour of the day
var min = 30;    // 0 through 59 for minutes after the hour
var tz = 1;     // offset in hours from UTC to your timezone
var lab = 'odliczanie';  // id of the entry on the page where the counter is to be inserted

function start() {displayCountdown(setCountdown(month,day,hour,min,tz),lab);}
loaded(lab,start);
// Countdown Javascript
// copyright 20th April 2005, 1st November 2009 by Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
// you may change the start function if required
var pageLoaded = 0; window.onload = function() {pageLoaded = 1;}
function loaded(i,f) {if (document.getElementById && document.getElementById(i) != null) f(); else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100);
}
function setCountdown(month,day,hour,min,tz) {var m = month; if (month=='*') m = 0;  var c = setC(m,day,hour,tz); if (month == '*' && c < 0)  c = setC('*',day,hour,tz); return c;} function setC(month,day,hour,tz) {var toDate = new Date();if (day.substr(0,1) == '+') {var day1 = parseInt(day.substr(1));toDate.setDate(toDate.getDate()+day1);} else{toDate.setDate(day);}if (month == '*')toDate.setMonth(toDate.getMonth() + 1);else if (month > 0) { if (month <= toDate.getMonth())toDate.setFullYear(toDate.getFullYear() + 1);toDate.setMonth(month-1);}
if (dow >0) toDate.setDate(toDate.getDate()+(dow-1-toDate.getDay())%7);
toDate.setHours(hour);toDate.setMinutes(min-(tz*60));toDate.setSeconds(0);var fromDate = new Date();fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());var diffDate = new Date(0);diffDate.setMilliseconds(toDate - fromDate);return Math.floor(diffDate.valueOf()/1000);}
function displayCountdown(countdn,cd) {if (countdn < 0) document.getElementById(cd).innerHTML = ""; else {var secs = countdn % 60; if (secs < 10) secs = '0'+secs;var countdn1 = (countdn - secs) / 60;var mins = countdn1 % 60; if (mins < 10) mins = '0'+mins;countdn1 = (countdn1 - mins) / 60;var hours = countdn1 % 24;var days = (countdn1 - hours) / 24;
$("#godzina").html(hours+"<span class='clock'>h</span>");
$("#minuta").html(mins+"<span class='clock'>m</span>");
$("#sekunda").html(secs+"<span class='clock'>s</span>");


setTimeout('displayCountdown('+(countdn-1)+',\''+cd+'\');',999);}}


function select_fv()
{
	if($("#fvat").val()=1)
		{
			alert('1');
		}
		else
		{
			alert('0');
		}
}



function strpos (haystack, needle, offset) 
{
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}



function register_new_client(final1,final2)
{
	var n=$("#reg_name").val();
	var s=$("#reg_surname").val();
	var e=$("#reg_email").val();
	var p=$("#reg_password").val();
	var rp=$("#reg_repassword").val();
	var a=0;
	var nl=0;
	if(document.getElementById('agreement').checked==true)
		{
			a=1;
		}
		else
		{
			a=0;
		}
	if(document.getElementById('newsletter').checked==true)
		{
			nl=1;
		}
		else
		{
			nl=0;
		}
	
		
	$.ajax({		  	
	type: "POST",
	 url: "/jquery.php",
	data: "o=register_new_client&n="+n+"&s="+s+"&e="+e+"&p="+p+"&rp="+rp+"&a="+a+"&nl="+nl,
					   success: function(msg){
						  
						   
						   if(strpos(msg,'Oto',0)==0)
		   	{
			
			document.getElementById(final2).innerHTML=msg;
			document.getElementById(final1).innerHTML='';
				
			}
			else
			{
			
			document.getElementById(final1).innerHTML=msg;
			}
							
					  						 }
									});
	
	
	
}
		
		
			

	
	
		




function close_cart()
{
	$("#koszyk").fadeOut('slow');
}








function validate_email(email)
{
	$.ajax({
					   type: "POST",
					   url: "/jquery.php",
					   data: "o=validate_email&e="+email,
					   success: function(msg){
							return msg;
					  						 }
									});
}







function search_form()
{
var sf=document.getElementById('szukaj_string').value;
if(sf.length>3)
	{


							$.ajax({
					   type: "POST",
					   url: "/jquery.php",
					   data: "o=quick_search&q="+sf,
					   success: function(msg){
							document.getElementById('qsearch_result').innerHTML=msg;
					  						 }
									});

	}
}



function buy_option(element)
{
	//alert(element);
	$("#"+element).css('display','block');
}
function hide_option(element)
{
	//alert(element);
	$("#"+element).css('display','none');
}
function IsNumeric(sText)

{
   var ValidChars = "0123456789,";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


function wine_search()
{
	
	var nazwa=document.getElementById('wino_name').value;
	var type=document.getElementById('wine_type').value;
	var sub_type=document.getElementById('wine_sub_type').value;
	var region=document.getElementById('wine_region').value;
	var volume=document.getElementById('wine_volume').value;
	var year=document.getElementById('wine_year').value;
	var price_from=document.getElementById('price_from').value;
	var price_to=document.getElementById('price_to').value;
//	var price_from=document.getElementById('wine_year').value;
//	var price_to=document.getElementById('wine_year').value;
	var zapytanie='';
	
	if(nazwa!='')
		{
			zapytanie=zapytanie+" and name REGEXP '"+nazwa+"'";
		}
	if(type!='')
		{
			zapytanie=zapytanie+" and type='"+type+"'";
		}
	if(sub_type!='')
		{
			zapytanie=zapytanie+" and sub_type='"+sub_type+"'";
		}
	if(region!='')
		{
			zapytanie=zapytanie+" and region='"+region+"'";
		}
	if(volume!='')
		{
			zapytanie=zapytanie+" and volume='"+volume+"'";
		}
	if(year!='')
		{
			zapytanie=zapytanie+" and year='"+year+"'";
		}
	
	if(price_from!='')
		{
			if(IsNumeric(price_from)==true)
				{
					zapytanie=zapytanie+" and cena>'"+price_from+"'";
				}
		}
	
	if(price_to!='')
		{
			if(IsNumeric(price_to)==true)
			{
			zapytanie=zapytanie+" and cena<'"+price_to+"'";
			}
		}
		
		
	$.ajax({
  type: "POST",
  url: "jquery_menu.php",
  data: "o=search_wine&q="+zapytanie,
 success: function(msg){
	 
											  $("#display_group").html(msg);

	 $("#cat_name").html="Wyniki wyszukiwania";
   }
 });
}


function coffee_search()
{
	var nazwa=document.getElementById('kawa_name').value;
	var rodzaj=document.getElementById('coffee_type').value;
	var waga=document.getElementById('coffee_weight').value;
	var cena_od=document.getElementById('price_from').value;
	var cena_do=document.getElementById('price_to').value;
	var zapytanie='';
	
if(nazwa!='')
		{
			zapytanie=zapytanie+" and name REGEXP '"+nazwa+"'";
		}	

if(rodzaj!='')
		{
			zapytanie=zapytanie+" and type='"+rodzaj+"'";
		}

if(waga!='')
		{
			zapytanie=zapytanie+" and weight='"+waga+"'";
		}
		
if(cena_od!='')
		{
			zapytanie=zapytanie+" and cena>='"+cena_od+"'";
		}
if(cena_do!='')
		{
			zapytanie=zapytanie+" and cena<='"+cena_do+"'";
		}

//alert(zapytanie);
$.ajax({
  type: "POST",
  url: "jquery_menu.php",
  data: "o=search_coffee&q="+zapytanie,
 success: function(msg){
	 
											  $("#display_group").html(msg);

	 $("#cat_name").html="Wyniki wyszukiwania";
   }
 });


}








function side_btn_active(input)
{

	document.getElementById(input).style.marginLeft='-158px';
}

function side_btn_unactive(input)
{
	document.getElementById(input).style.marginLeft='-140px';
}

function loading(div)
{
	document.getElementById(div).innerHTML='<li></li>';
}

function submenu(input,opcja)
{

if(document.getElementById(input).style.display='none')
	{
	
			if(document.getElementById(input).textContent=='')
			{
			document.getElementById(input).innerHTML='<img src="/kawa_img/loading.gif" style="margin-top:25px;" alt="Pobieranie danych" title="Pobieranie danych" />';
			}
			get_menu_content(opcja,input);
			$("#"+input).fadeIn('fast', function () {});
			//document.getElementById(input).style.display='block';
			
	}
		
}

function submenuhide(input)
{
	//$("#"+input).fadeOut('slow', function () {});
	
	if(document.getElementById(input).style.display='block')
							   {
	document.getElementById(input).style.display='none';
							   }

}


function change_delivery(final)
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=change_delivery&del="+$("#delivery").val(),
   success: function(msg){
	
		document.getElementById(final).innerHTML=msg;
   }
 });
}


function get_menu_content(opcja,final)
{
	$.ajax({
   type: "POST",
   url: "jquery_menu.php",
   data: "o="+opcja,
   success: function(msg){
	   $("#"+final).append(msg);
   }
 });
}

function count_free_shipment(final)
{
	$.ajax({
   type: "POST",
   url: "jquery.php",
   data: "o=count_free_shipment",
   success: function(msg){
	   document.getElementById(final).innerHTML=msg;
   }
 });
}


function art_slide(page)
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=art_slide&page="+page,
   success: function(msg){
		$("#kawa_artykuly").fadeOut('fast', function ()
													  	{	  document.getElementById('kawa_artykuly').innerHTML=msg;
															$("#kawa_artykuly").fadeIn('fast');
														});

	  }
 });
}






function product_picture(final)
{
	document.getElementById('test').innerHTML=final;
	$("#"+final).removeClass('menu_product_picture');
	$("#"+final).addClass('show_picture');
																			
}

/* Koszyk */

function kup_teraz(d,pid)
{
$("#koszyk").html('<div align="center" style="margin-top:40px; font-weight:bold;">Wczytywanie koszyka - momencik</div>');
$("#koszyk").fadeIn('20');
$.ajax({
   type: "POST",
   url: "cart.php",
   data: "o=preadd"+"&d="+d+"&pid="+pid,
   success: function(msg){
	   $("#koszyk").html(msg);

	   document.getElementById('koszyk_quantity').focus();
   }
 });
}


function old18()
{
$.ajax({
   type: "POST",
   url: "cart.php",
   data: "o=old18",
   success: function(msg){
	   location.reload();
	  
   }
 });	
	
}


function kup_teraz18(d,pid)
{
$("#koszyk").html('<div align="center" style="margin-top:40px; font-weight:bold;">Wczytywanie koszyka - momencik</div>');
$("#koszyk").fadeIn('20');
$.ajax({
   type: "POST",
   url: "cart.php",
   data: "o=preadd"+"&d="+d+"&pid="+pid+"&old=yes",
   success: function(msg){
	   $("#koszyk").html(msg);

	   document.getElementById('koszyk_quantity').focus();
   }
 });
}



function buy_without_reg()
{
	$.ajax({
   type: "POST",
   url: "/jquery.php",
   data: "o=buy_without_reg",
   success: function(msg){
	 $.fancybox.close();
	document.getElementById('koszyk_ajax').innerHTML=msg;
self.scrollTo(0,100);
	document.getElementById('mname').focus();
	
   }
 });
}


function update_side_cart(final)
{
 $.ajax({
	   type: "POST",
	   url: "cart.php",
	   data: "o=calculate_cart",
	   success: function(msg2){
		   $("#"+final).html(msg2);
			  }
			 });	
check_if_logged();
}



function send_message(final)
{
 $.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: "o=send_message&t="+$("#message_content").val()+"&r="+$("#reply").val()+"&s="+$("#subject").val(),
	   success: function(msg){
		   $("#"+final).slideDown('slow').html(msg);
		  // alert($("#subject").val());
			  }
			 });	

}

function zaloguj_mnie2()
{

$.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: "o=logmein2&e="+$("#log_email").val()+"&p="+$("#log_password").val(),
	   success: function(msg){
		 $("#logmein").html(msg);  
	
	   }
});
}

function zaloguj_mnie(final1,final2)
{
var error=0;
if($("#log_email").val()=='')
	{
		error=1;
	}

if($("#log_password").val()=='')
	{
		error=1;
	}


if(error!=1)
{

$.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: "o=logmein&e="+$("#log_email").val()+"&p="+$("#log_password").val(),
	   success: function(msg2){
		   if(strpos(msg2,'zalogowany',0)!=0)
		   	{
			document.getElementById(final2).innerHTML=msg2;	
			document.getElementById('zaloguj_menu_li').innerHTML="<a href='/wyloguj'>Wyloguj mnie</a>";
				$(".fancy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
		'autoScale'     : true,
		'autoDimensions': true

			});
			}
			else
			{
			document.getElementById(final1).innerHTML=msg2;
			}
		   
		   
		   
		   

			  }
			 });	
}
else
{
	document.getElementById('log_email').focus();
}


}




function update_cart(final)
{
	
	 $.ajax({
	   type: "POST",
	   url: "cart.php",
	   data: "o=update_cart",
	   success: function(msg){
		   $("#"+final).slideUp(800,
								function()
									{
									document.getElementById(final).innerHTML=msg;
									$("#"+final).slideDown('slow');
									});
		   	count_free_shipment('koszyk_darmowa_przesylka');
			  }
	
			 });	
}



function update_quantity(oid)
{
	 $.ajax({
	   type: "POST",
	   url: "cart.php",
	   data: "o=change_quantity&oid="+oid+"&q="+$("#quantity"+oid).val(),
	   success: function(msg2){
		   update_side_cart('side_cart_header');
		   update_cart('koszyk_content');
			  }
			 });	
 	count_free_shipment('koszyk_darmowa_przesylka');
}


	

function kup(d,pid)
{
	$.ajax({
   type: "POST",
   url: "cart.php",
   data: "o=add"+"&d="+d+"&pid="+pid+"&q="+$("#koszyk_quantity").val(),
   success: function(msg){
	   $("#input_table").slideUp('fast',function () {
												  $("#input_table").html(msg);
												  $("#input_table").slideDown('fast');
												  });
	
	update_side_cart('side_cart_header');
	
		  /* poszukujemy podobnych */
		  $.ajax({
	   type: "POST",
	   url: "cart.php",
	   data: "o=suggest"+"&d="+d+"&pid="+pid,
	   success: function(msg2){
		   $("#koszyk_propozycje").html(msg2).slideDown('fast');
			  }
			 });
		  /* koniec */
	   
   }
 });	
	
}

function pages(d)
{
	$.ajax({
						   type: "POST",
						   url: "/jquery.php",
						   data: "o=pages&d="+d,
						   success: function(msg){
							   
							 $("#p1").html(msg); 
							 $("#p2").html(msg);
						   }
							});	
	
	
}

function clear_default()
{
	var n=$("#szukaj_string").val();
	if(n=='Wpisz czego szukasz')
		{
		document.getElementById('szukaj_string').value='';
		}
}


function filter(typ)
{
$("#group_disp").html("<div class='loading'>Trwa ładowanie wyników...</div>");
var order=$("#order_by").val();
switch(typ)
	{
		case 'wino': 
						var wt=$("#wine_type").val();
						var wr=$("#wine_region").val();
						var wv=$("#wine_volume").val();
						var wst=$("#wine_sub_type").val();
						var wy=$("#wine_year").val();
						
						$.ajax({
						   type: "POST",
						   url: "/jquery.php",
						   data: "o=filter&d=wino&wt="+wt+"&wr="+wr+"&wv="+wv+"&wst="+wst+"&wy="+wy+"&order="+order,
						   success: function(msg){
							 $("#group_disp").html(msg); 
							 $("#cat_name").html("Wyniki wyszukiwania");
							 pages('wino');
						
						   }
							});		
						
						
						
						
						
						break;
		case 'kawa': var ct=$("#coffee_type").val();
					var cw=$("#coffee_weight").val();
					var po=$("#order_by").val();
					$.ajax({
						   type: "POST",
						   url: "/jquery.php",
						   data: "o=filter&d=kawa&ct="+ct+"&cw="+cw+"&order="+order,
						   success: function(msg){
							 $("#group_disp").html(msg);  
							 $("#cat_name").html("Wyniki wyszukiwania");
							 pages('kawa');
						
						   }
							});		
					
					break;
	}
	
	
	
	
	
}



function next_page(p,d,final)
{
	
//	aktualizuj_koszyk(final);
	$("#"+final).html("<div class='loading'>Ładowanie wyników...</div>");
	



	$.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: 'o=next_page&page='+p+"&d="+d,
	   success: function(msg){
		   $("#"+final).fadeOut('fast', function ()
												  {
												  document.getElementById(final).innerHTML=msg;	  
												  }
												  );
		  	$("#"+final).fadeIn('fast');
	   }
	 });	
	
	
}

function view_order_details(oid)
{
	  document.getElementById('view_order_details').innerHTML="<div align='center'>Pobieram dane... Prosze chwileczke poczekac</div>";
	 $.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: "o=view_order_details&oid="+oid,
	   success: function(msg){
		  
		   document.getElementById('view_order_details').innerHTML=msg;
		   }
			 });	
	
	$(".fancy").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});

}


function view_order_history()
{
	
	  document.getElementById('view_order_details').innerHTML="<div align='center'>Pobieram dane... Prosze chwileczke poczekac</div>";
	 $.ajax({
	   type: "POST",
	   url: "/jquery.php",
	   data: "o=view_order_history",
	   success: function(msg){
		  document.getElementById('view_order_details').innerHTML=msg;   

			  }
			 });	
 
}	

