﻿// JScript source code
$(document).ready(function() {
	$("#page-content").hide().fadeIn(850);

	updateSummary($("input.quantity"));

	$(".inc").show().click(function() {
		var quantity = $(this).prev("input.quantity");
		var value = quantity.val();
		value++;
		quantity.val(value);
	});

	$(".dec").show().click(function() {
		var quantity = $(this).next("input.quantity");
		var value = quantity.val();
		value--;
		if (value < 0)
			value = 0;
		quantity.val(value);
	});

	// Ukrycie niepotrzebnych danych
	var nip = $("[name='customer.Nip']").val();
	if (nip != null && nip.length > 0) {
		$("[name='invoice'][value='True']").attr('checked', 1);
	}
	else {
		$("li.company").hide();
		$("input[name='invoice'][value='False']").attr('checked', 1);
	}

	$("[name='invoice'][value='False']").click(function() {
		$("li.company").hide();
	});
	$("[name='invoice'][value='True']").click(function() {
		$("li.company").show();

	});

	// Dodajemy obsluge promocji
	$(".summary").show();
	$(".inc").click(function() {
		var quantity = $(this).prev("input.quantity");
		updateSummary(quantity);
	});

	$(".dec").click(function() {
		var quantity = $(this).next("input.quantity");
		updateSummary(quantity);
	});
});

function updateSummary(quantity) {
	if (quantity != null) {
		var value = quantity.val();
		$(".summary li:first span").text((value * 999) / 100 + ' zł');
		$(".summary li:last span").text((Math.floor(value / 3) * 499) / 100 + ' zł');
	}
}
