$(document).ready(function(){

	// polec znajomemu
	$("a.recommend").click(function(){
		$("form.recommend").toggle();
		return false;
	});

	// tabs
	$("a[rel='1']").parent().addClass("active");
	$(".productsSingle .tabs div.tab").hide();
	$(".productsSingle .tabs div.tab:first").show();
	
	$(".productsSingle .tabs .head li a").click(function(){
		$(".productsSingle .tabs .head li").removeClass("active");
		$(this).parent().addClass("active");
		var active = $(this).attr("rel");
		$(".productsSingle .tabs div.tab").hide();
		$("#tab-"+active).show();
		return false;
	});
	
	// target="_blank"
	$(".tBlank").click(function(){
		this.target='_blank';
	});
	
	// input value
	inputValue("#header form.searchTop input.query");
	inputValue("#header form.loginTop input.login");
	inputValue("#header form.loginTop input.haslo");
	inputValue("#sidebar form.newsletter input[name=newsletter], #content ul.newsletter input[name=newsletter]");
	
	// confirm remove
	$(".remove").click(function(){
		var text = "Czy na pewno usunąć produkt z koszyka?";
		var ask = confirm(text);
		if(!ask) return false;
		else return true;
	});
	
	// dane do faktury
	var invoice = document.getElementById('invoice');
	if(invoice) changeInvoice(invoice.checked);
	
	// zmiana ilosci produktow w widoku pojedynczego produktu
	function form_input_is_int(input){
		return !isNaN(input)&&parseInt(input)==input;
	}
	var price;
	$("#content .productsSingle .bottom .body .quantity input").keypress(function(){
		price = $("#content .productsSingle .bottom .body .price ").html();
		price = price.split(" ");
	});
	$("#content .productsSingle .bottom .body .quantity input").keyup(function(){
		if (form_input_is_int($(this).val()))
		{
			var priceTotal = parseInt($(this).val()) * parseFloat(price[0]);
			$("#content .productsSingle .bottom .body .priceTotal").html(Math.round(priceTotal*100)/100+" <span>PLN</span>");
		}
		else
			$("#content .productsSingle .bottom .body .priceTotal").html("Błąd");
	});

});

// input value
function inputValue(tag) {
	var inputTag = $(tag);
	var inputVal = inputTag.val();
	$(inputTag)
	.click(function() {
		if(this.value == inputVal) this.value='';	
	})
	.blur(function() {
		if(this.value.length == 0) this.value=inputVal;	
	});
}

// dane do faktury
function changeInvoice(invoice) {
	var invoiceData=document.getElementById('invoiceData');
	if(invoice == true)
		invoiceData.style.display='block';
	else
		invoiceData.style.display='none';
}

// przeliczanie w koszyku
function submitFormAction(form,action,value) {
	var formAction = document.getElementById('formAction');
	formAction.name = action;
	formAction.value = value;
	submitForm(form);
}

function submitForm(form) {
	document.getElementById(form).submit();
}

// sortowanie widoku
function UrlReplace(link,param1)
{
	link=link.replace('*param1*',param1);
	document.location=link;
}

/*
$(document).ready(function(){

    $(".color a").click(function(){
      $(".color a").removeClass("active");
      $(this).addClass("active");
      $("#colorName").val($(this).attr("id"));
    });
    
    $(".size a").click(function(){
      $(".size a").removeClass("active");
      $(this).addClass("active");
      $("#sizeName").val($(this).attr("id"));
    });

});


function changePhoto(big, zoom)
{
    $("#main .singleProduct .img td img").attr({src: big});
    $("#main .singleProduct .img td a").attr({href: zoom});
    return false;
}
*/
