
function AddProductToCart(module, id, quantity) {
	
	var params = '';
	params += "id="+id;
	params += "&quantity="+quantity;
	params += "&module="+module;
	mSplash.show('Pracuję...');
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_add_product', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				RefreshCart(module);
				mSplash.hide();
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				mSplash.hide();
				alert('Nie dodano, odswiez');
			}
		},
		error: function() {
			mSplash.hide();
			alert('Nie dodano, blad');
		}
	});
	return true;
}
function RefreshCart(module) {
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_refresh', 
		data: 'module='+module,
		dataType: "html", 
		success: function(xml) {
			$('#box_checkout').html(xml);
		},
		error: function() {
			alert('Blad odswiezania');
		}
	});
	return true;
}
function RefreshCart2(module) {
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_refresh2', 
		data: 'module='+module,
		dataType: "html", 
		success: function(xml) {
			$('#cart').html(xml);
		},
		error: function() {
			alert('Blad odswiezania');
		}
	});
	return true;
}
function RemoveItemFromCart(module, no) {
	var params = '';
	params += "no="+no;
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_remove_item', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				RefreshCart(module);
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				alert('Nie usunieto, odswiez');
			}
		},
		error: function() {
			alert('Nie usunieto, blad');
		}
	});
}
function RemoveItemFromCart2(module, no) {
	var params = '';
	params += "no="+no;
	mSplash.show('Pracuję...');
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_remove_item', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				RefreshCart(module);
				RefreshCart2(module);
				mSplash.hide();
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				mSplash.hide();
				alert('Nie usunieto, odswiez');
			}
		},
		error: function() {
			mSplash.hide();
			alert('Nie usunieto, blad');
		}
	});
}
function RemoveProductFromCart() {
	var params = '';
	params += "id="+encodeURIComponent($('#rproduct_id').val());
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_remove_product', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				alert('Usunieto, odswiez strone');
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				alert('Nie usunieto, odswiez');
			}
		},
		error: function() {
			alert('Nie usunieto, blad');
		}
	});
}
function ChangeProductQuantityInCart(module,id,quantity,no) {
	
	if (quantity < 1 ){
		RemoveItemFromCart2(module,no);
		return true;
	}
	
	var params = '';
	params += "id="+id;
	params += "&quantity="+quantity;
	params += "&module="+module;
	mSplash.show('Pracuję...');
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_change_product_quantity', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				RefreshCart(module);
				RefreshCart2(module);
				mSplash.hide();
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				mSplash.hide();
				alert('Blad, odswiez');
			}
		},
		error: function() {
			mSplash.hide();
			alert('Blad, blad');
		}
	});
}
function ChangeDeliveryInCart(module, id) {
	var params = '';
	params += "id="+id;
	params += "&module="+module;
	mSplash.show('Pracuję...');
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_change_delivery', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				RefreshCart(module);
				RefreshCart2(module);
				mSplash.hide();
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				mSplash.hide();
				alert('Nie dodano, odswiez');
			}
		},
		error: function() {
			mSplash.hide();
			alert('Nie dodano, blad');
		}
	});
}
function ChangeVATInCart() {
	var params = '';
	params += "value="+encodeURIComponent($('#vat').val());
	$.ajax({
		type: "POST",
		url: BASE_URL+'action.php?action=cart_change_vat', 
		data: params,
		dataType: "xml", 
		success: function(xml) {
			if ($('status', xml).text()=='1') {
				alert('Dodano, odswiez strone');
			} else {
				var error = $('error', xml).text();
				var error_str = $('error_code', xml).text();
				alert('Nie dodano, odswiez');
			}
		},
		error: function() {
			alert('Nie dodano, blad');
		}
	});
}

function CheckOrderForm() {
		
	if (
		(document.getElementById('order_ship1').checked)
		&& (
			($('#order_ship_address_line1').val().match(/^( )*$/)) 
			|| ($('#order_ship_city').val().match(/^( )*$/))
			|| ($('#order_ship_postcode').val().match(/^( )*$/)) 
			|| ($('#order_ship_country').val().match(/^( )*$/)) 
			)
	) {
		alert('Wypełnij wymagane pola');
		return false;
	}
	
	return true;
	
}

function changeOrderShip() {
	if (document.getElementById('order_ship0').checked)
		document.getElementById('order_shipping').style.display='none';
	if (document.getElementById('order_ship1').checked)
		document.getElementById('order_shipping').style.display='block';
}


