$(document).ready(function(){
    /*$("input[name=payments]").click(function(){
        $('form#'+$(this).attr('name')).submit();
        
    });
    $("input[name=deliveries]").click(function(){
        $('form#'+$(this).attr('name')).submit();

    });*/
    $("input[name=faktura]").click(function(){
        if ($(this).is(":checked")==1) {
            $("th[name=delivery_company]").html($("th[name=delivery_company]").html()+"*");
            $("th[name=delivery_nip]").html($("th[name=delivery_nip]").html()+"*");
            
        }
        else
            {
                $("#delivery_company").val('');
                $("#delivery_nip").val('');
                $("th[name=delivery_company]").html($("input[name=source_delivery_company]").attr('value'));
                $("th[name=delivery_nip]").html($("input[name=source_delivery_nip]").attr('value'));
            }

    });


    $('td[name=product_name]').css('cursor','pointer');

    $('#contentBox .bg').click(function() {
        $('#contentBox').hide();
        $('#contentBox .content').html('');
        $('#contentBox .content').hide();
        $('#contentBox .bg').hide();
    });

    $('#contentBox .close').click(function() {
        $('#contentBox .bg').click();
    }); 

    $('#formularzZam').submit(function() {
       $('.product_table textarea').each(function(index) {
        //alert($(this).attr('name'));
      });

    });
});
   
   
$(function() {
    $("div#controller").jFlow({
            suffix: "",
            slides: "#slides",
            width: "352px",
            height: "150px"
        });
    $("div#controllerREC").jFlow({
            suffix: "REC",
            slides: "#slidesREC",
            width: "352px",
            height: "150px"
        });
                $("div#controllerFOT").jFlow({
                        suffix: "FOT",
                        slides: "#slidesFOT",
                        width: "600px",
                        height: "200px"
                    });
    $('img[alt=product_name]').tooltip({
	delay: 0,
	showURL: false,
        fade:150,
	bodyHandler: function() {
		if ($(this).attr('rel')!='0') return $("<img/>").attr("src", $(this).attr('rel'));
	}
    });



});
   
   
   

   
   
$(function() {
    $('a[@rel*=lightbox]').lightBox();

    for (i=0;i<=999;i++)
    {
        $('a[@rel*=lightbox'+i+']').lightBox();
    }
		
		
		
		
		$('input[@name^=quantsKoszyk]').keyup(function() { 
            $('input[@name^="'+$(this).attr('name')+'"]').val($(this).val());
            oneFieldUpdate($(this));


//			var data = '1=1';
//			$('#cart input[@name^=quantsKoszyk]').each(function() {
//				data += '&'+$(this).attr('name')+'='+$(this).val();
//			});
//			$('#cart textarea[@name^=notes]').each(function() {
//				data += '&'+$(this).attr('name')+'='+$(this).val();
//			});
//			updateCart(data);
		});
		
		$('textarea[@name^=notes]').change(function() {
            $('textarea[@name^="'+$(this).attr('name')+'"]').val($(this).val());
            oneFieldUpdate($(this));

//			$('input[@name^=quantsKoszyk]').keyup();
		});
		
});

function oneFieldUpdate(obj) {
    var data = '1=1';

    
    data += '&'+obj.attr('name')+'='+obj.val();

    updateCart(data);
}

function updateCart(data) {
	$.ajax({
		type: 'POST',
		url: 'include/ajax/cart.php',
		cache: false,
		data: data,
    beforeSend: function(html){
            $('#updateCart').fadeIn(200);
		},
		success: function(html){            
						$('body').append(html);
						$('#updateCart').fadeOut(1000);
                        //$('#updateCart').html('');
		}
	});
}



function contentBox(url) {
    //$('html, body').animate({scrollTop:0}, 'slow');
    var arrPageSizes = ___getPageSize();
    var arrPageScroll = ___getPageScroll();

    $('#contentBox .bg').css('width',arrPageSizes[0]);
    $('#contentBox .bg').css('height',arrPageSizes[1]);

    $('#contentBox').css('top',arrPageScroll[1] + (arrPageSizes[3] / 10));
    $('#contentBox .content').css('top',arrPageScroll[1] + (arrPageSizes[3] / 10));
    $('#contentBox .close').css('top',arrPageScroll[1] + (arrPageSizes[3] / 10)- 28);
    $('#contentBox .load').css('top',arrPageScroll[1] + (arrPageSizes[3] / 10)- 28);
    $('#contentBox .load').show();

    $('#contentBox').show();
    $('#contentBox .bg').show();
    $.ajax({
            type: 'POST',
            url: url,
            cache: false,
            error: function(html){
                //alert('error');
            },
            success: function(html){
                $('#contentBox .content').html(html);
                $("div#controllerFOT").jFlow({
                        suffix: "FOT",
                        slides: "#slidesFOT",
                        width: "600px",
                        height: "200px"
                    });
                $('a[@rel*=lightbox999]').lightBox();
                $('#contentBox .load').hide();                
                $('#contentBox .content').show();
            }
    });

    
}
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};

		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
function pokaz_ukryj(blok) {
			if (document.getElementById(blok).style.display=="block") {		  
				$(".submenu").css("display","none");
			} else {
				$(".submenu").css("display","none");
				document.getElementById(blok).style.display="block";
			}
}

function ukryj(blok) {
				document.getElementById(blok).style.display="none";
}
function print_site() {
		window.print()
  }
	
	
	

