function router(path) 
{
	var baseHref = document.getElementsByTagName('base')[0].href;
	return baseHref + path + '.html';
}

$(document).ready(function () {

	$("a[rel='lightbox']").colorbox({transition:"fade"});

	$("#checkboxall").click(function()
			{
				var checkedStatus = this.checked;
				$("input[name='checkall[]']").each(function()
				{
					this.checked = checkedStatus;
				});	
			});

	$("#query").click(function()
			{
				$("#query").val('');
			});
	
	$("#deliveryType").change(function () {
		var deliveryType = $('#deliveryType').val();
		var userID = $('#userID').val();
		var cartID = $('#cartID').val();

		$.getJSON(router('offer/deliveryinfo/'+deliveryType+'/'+userID+'/'+cartID),
		        function(data){
				$("#deliverDescription").html(data.description);
				$("#deliverSelectedPrice").html(data.price);
				$("#deliverSelectedVAT").html(data.vat);
				$("#deliverSelectedTotal").html(data.total);
				$("#totalCost").html(data.all);
		        });
	});

	$("#paymentType").change(function () {
		var paymentType = $('#paymentType').val();
		
		$.getJSON(router('offer/paymentinfo/'+paymentType),
		        function(data){
				$("#paymentDescription").html(data.description);
		        });
		});

	/* Bind QTip */
	$('img[title]').qtip({ 
		style: 
		{ 
			fontSize: '11px', 
			lineHeight: '15px', 
			name: 'dark', 
			tip: true
		},
		position: 
		{
		 	corner: 
		 	{
		    	target: 'middleLeft',
		        tooltip: 'rightMiddle'
		    }
		}
	})

	/* Regieter & Profile helper */
	$("input[name='form[account_type]']").change(function() {
		if ($("input[name='form[account_type]']:checked").val() == '1')
		{
  			$("#fPersonPESEL").attr("disabled", "disabled");
  			$("#fCompanyNIP").removeAttr("disabled");
  			$("#fCompanyREGON").removeAttr("disabled");
  			$("#helpNAME").show();
  			$("#helpNIP").show();
  			$("#helpREGON").show();
  		} else
		{
  			$("#fCompanyNIP").attr("disabled", "disabled");
  			$("#fCompanyREGON").attr("disabled", "disabled");
  			$("#fPersonPESEL").removeAttr("disabled");;
  			$("#helpNAME").hide();
  			$("#helpNIP").hide();
  			$("#helpREGON").hide()
		}
	});

	$("input[name='form[post_enable]']").change(function() {
		if ($("input[name='form[post_enable]']:checked").val() == '1')
		{
			$("#postData").fadeIn();
		} else
		{
			$("#postData").fadeOut();
		}
	});	

});