function PoliczRate(koszyk, wariantSklepu) {
  window.open('https://www.eraty.pl/symulator/oblicz.php?numerSklepu=24416114&wariantSklepu='+wariantSklepu+'&typProduktu=0&wartoscTowarow='+koszyk, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function nowe_okno() {
  window.open('https://www.zagiel.com.pl/kalkulator/jak_kupic.html', 'nowe_okno', 'width=600,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

Cufon.replace('h2');  

$(document).ready(function(){
  
  // widoki
  var cookieName = 'widoki';
  var cookieOptions = { path: '/', expires: 30 };  
  
  var widok = $.cookie(cookieName);
  if(widok=="simply"){     
     // $(".itemList div.plus_minus").hide();
      $(".itemList div.product_opinion").hide();
      $("li#simply a").addClass('active');      
  }
  else{    
      $("li#detail a").addClass('active');
  }


   $("li#simply a").click(function () {
     // $("div.plus_minus").hide();
      $("div.product_opinion").hide();
      
      $("li#detail a").removeClass('active');
      $(this).addClass('active');
      
      $.cookie(cookieName, "simply", cookieOptions);
      return false;
  });
  
   $("li#detail a").click(function () {
     // $(".itemList div.plus_minus").show();
      $(".itemList div.product_opinion").show();
      
      $("li#simply a").removeClass('active');
      $(this).addClass('active');
      
      $.cookie(cookieName, "detail", cookieOptions);
      
      return false;
  });
  
  
  var cookieNamePorownaj = 'porownaj';
  var cookieOptionsPorownaj = { path: '/', expires: 30 };  
  
  var widok = $.cookie(cookieName);
  var menuArray = new Array();
  
  var itemObjectList = ($.evalJSON($.cookie(cookieNamePorownaj))); 
  if (itemObjectList!= undefined){
    for(var i=0; i < itemObjectList.length; i++){
      if(!itemObjectList[i].checkedItem){
        $("#product_"+itemObjectList[i].idItem).hide();
      }
      else{
        $("#checkboxPorownaj_"+itemObjectList[i].idItem).attr('checked', true);
      }
    }
  }
  
  
  $("a.porownaj_btn").click(function () {
    if($("input[name*='checkboxPorownaj']:checked").length)
    {
      $('.itemList').hide();
      $("input[name*='checkboxPorownaj']").each(function(index) {
      
        var item = new Object();
        item.idItem = $(this).val();
        item.checkedItem = $(this).is(":checked");
        
        if($(this).is(":checked"))
        {
          var id = $(this).val();
          $("#product_"+id).show();
        }
        menuArray[index] = item;
      });
        
      $.cookie(cookieNamePorownaj, $.toJSON(menuArray), cookieOptionsPorownaj);
    }
    else{
      alert("Brak zaznaczonych produktów.");
    }
    return false;
  });
  
  
  
  
  
    // ------------ load fancybox
  $("a.fancy").fancybox({
	 overlayOpacity: 0.8
	});
	
	
  $("#changeAviableLanguage").change(function () {
    var type = $("#changeAviableLanguage").val();
    var url = $("#currentUrl").val();        
    if(type!="wybierz"){
      window.location.href = url+',lang-'+type+'.html';
    }
    else{
      window.location.href = url+'.html';
    }
    
  });
  
    // check delivery form     
    $(".moviesList").jCarouselLite({
        speed: 1000,
        visible: 3,
        scroll: 1,
        btnNext: ".moveRight",
        btnPrev: ".moveLeft",
        vertical: false,
        circular:false
    });
    
    // form raty zagiel
   $(".lastStepShop").submit(function () {
     if($("#formZagielReguly:checked").length>0){
      return true;
     } 
     else {
      alert ("Zanim złożysz zamówienie, zapoznaj sie z procedura udzielenia kredytu ratalnego eRaty Żagiel.");
      return false;
    }
  });
  $("#formularz_eRaty").submit(); 
  
  
  // check delivery form    
  $("#sendContactForm").validate({
    rules: {
    	    formName: {
    				required: true
    			},
    			formSurname: {
    				required: true
    			},
    			formMesage: {
    				required: true
    			},
    			
    			formEmail: {
    				required: true,
    				email: true
    			}
    		}
	   });  
	  
    // send firend 
		$('#windowOpen').bind('click',function(){
		
        $(this).attr('href', 'javascript:void(0);');
    
				if($('#windowPopup').css('display') == 'none') {
            $.get('ajaxResponse.php?action=sendFriend', '', function(data){
                $("#windowContent").html(data);
                $("#windowPopup").animate({ 
                                  width: "210px",
                                  height: "200px",
                                  opacity: 0.95
                                  }, 1500 );
            });
				}
		});
		$('#windowClose').bind('click',function(){
			   $("#windowPopup").animate({ 
              width: "10px",
              height: "10px",
              opacity: 0.3
            }, 1500,	'', function(){ $("#windowPopup").hide();}
          )
		});
	   
});
