var showVat = true;
var fontSize = 0;
var scrollers = new Object;
var searchtimer;
//var currentScrollPage = 1;
//var scrollerMaxPages = 1;
//var currentScrollName = '';

function changeQuantity( id, amount ) {
	var qty = parseInt( $('#qty_' + id).attr('value') );
	qty += amount;
	if ( qty < 1 ) {
		qty = 1;
	}
	$('#qty_' + id).attr('value', qty );
}
function addToBasket( id ) {
	var productFormName = 'productForm';
	if( typeof id != 'undefined' ) {
		// product section addtobasket
		productFormName = 'productForm_' + id;
	}
	$.post( '/manage_basket.php', $('#' + productFormName ).serialize(),
		function( data ){
			if ( data.substr( 0, 6 ) == 'ERROR:' ) {
				alert( data.substr( 6 ) );
				return false;
			}
			// scroll to the top of the window
			window.scrollTo( 0, 0 );
			// update the basket contents
			$('#popupBasketPanel').remove();
			$('#navBasket').html( data );
			checkVATCookie();
			$('#popupBasketPanel').dialog("open");
		}
		, 'html' 
	);
	return false;
}

function doSearch() {
	if (( document.getElementById( 'searchText' ).value != '' ) && ( document.getElementById( 'searchText' ).value != '- Product search' )) {
		document.location = '/products/%20search::' + document.getElementById( 'searchText' ).value;
	} else {
		alert( "Please enter search text" );
	}
	return false;
}
function setCookie( name, value ) {
	document.cookie = name + '=' + value + ';path=/;';
}
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) {
		return null;
	}
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) {
		end = document.cookie.length;
	}
	return unescape( document.cookie.substring( len, end ) );
}
function checkVATCookie() {
	var cookieVal = getCookie( 'showVATInBasket' );
	// if val is true or not previously been set...
	if ( cookieVal == 'true' ) {
		updateVAT( true );
	} else {
		updateVAT( false );
	}
}
function showDocument( document ){
	window.open( '/popup/' + document , 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=500, height=500');
}
function updateVAT( vat ) {

	var incVATPoundsElements = $('.price_incVAT_pounds');
	var exVATPoundsElements = $('.price_exVAT_pounds');
	
	// hide the correct elements
	if ( typeof incVATPoundsElements != 'undefined' && incVATPoundsElements.length > 0 ) {
		incVATPoundsElements.css('display','none');
	}
	if ( typeof exVATPoundsElements != 'undefined' && exVATPoundsElements.length > 0 ) {
		exVATPoundsElements.css('display','none');
	}
	
	showVat = vat;
	
	// show the correct elements
	if( showVat ) {
		//alter the image
		$('#btnHeadVat').attr('src','/custom/images/btn-vat-on.gif');
		if ( typeof incVATPoundsElements != 'undefined' && incVATPoundsElements.length > 0 ) {
			incVATPoundsElements.css('display','inline');
		}
	} else {
		//alter the image
		$('#btnHeadVat').attr('src','/custom/images/btn-vat-off.gif');
		if ( typeof exVATPoundsElements != 'undefined' && exVATPoundsElements.length > 0 ) {
			exVATPoundsElements.css('display','inline');
		}
	}
	
	setCookie( 'showVATInBasket', showVat );
}
function switchVAT() {
	updateVAT(!showVat);
}
function changeFontSize(direction) {
	// update the fontSizer link to the new style sheet
	if(direction == 'up' && fontSize < 2){fontSize++;}
	if(direction == 'down' && fontSize > 0){fontSize--;}
	document.getElementById( 'fontSizer' ).href = '/custom/css/' + fontSize + '.css';
	setCookie( 'fontSize', fontSize );
}
function checkFontSize() {
	var cookieVal = getCookie( 'fontSize' );
	// if val is true or not previously been set...
	if ( parseInt( cookieVal ) >= 0 ) {
		// update the fontSizer link to the new style sheet
		fontSize = cookieVal;
		document.getElementById( 'fontSizer' ).href = '/custom/css/' + fontSize + '.css';	
	}
}
function showDelivery(delivery) {
	if(delivery) {
		$("#register_shipping_table").hide();
	}
	else {
		$("#register_shipping_table").show();
	}
}
function showZeroVAT(zerovat) {
	if(zerovat) {
		$("#register_zerovat_table").show();
	}
	else {
		$("#register_zerovat_table").hide();
		// also hide the 3rd party info if it isnt already
		$("#register_zerovat_3rdparty_table").hide();
	}
}
function showZeroVAT3rdParty(zerovat3rdParty) {
	if(zerovat3rdParty) {
		$("#register_zerovat_3rdparty_table").show();
	}
	else {
		$("#register_zerovat_3rdparty_table").hide();
	}
}
function showLogin() {
	$('#popupLoginPanel').dialog("open");
}
function logout() {
	document.getElementById('logoutForm').submit();
}
function showBasket() {
	$('#popupBasketPanel').dialog("open");
}
function hideBasket() {
	$('#popupBasketPanel').dialog("close");
}


$(document).ready(function(){
	checkVATCookie();
	checkFontSize();
	$('#popupLoginPanel').dialog({
			modal:		true,
			resizable:	false,
			width:		356,
			height:		194,
			draggable:	false,
			autoOpen: false
	});
	$('.homeProductContainer').mouseenter(function(){
		$(this).next('.homeProductFadeRight').show().next('.homeProductFadeBottom').show();
	});
	$('.homeProductContainer').mouseleave(function(){
		$(this).next('.homeProductFadeRight').hide().next('.homeProductFadeBottom').hide();
	});
	$('.otherProductContainer').mouseenter(function(){
		$(this).next('.otherProductFadeRight').show().next('.otherProductFadeBottom').show();
	});
	$('.otherProductContainer').mouseleave(function(){
		$(this).next('.otherProductFadeRight').hide().next('.otherProductFadeBottom').hide();
	});
});

function inputBoxFocus( input, defaultText, passwordField ) {
	if( typeof passwordField != 'undefined' ) {
		document.getElementById( passwordField ).style.display = '';
		document.getElementById( passwordField+'_text' ).style.display = 'none';
		document.getElementById( passwordField ).focus();
	} else {
		if( input.value == defaultText ) {
			input.value = '';
		}
	}
}

function inputBoxBlur( input, defaultText, passwordField ) {
	if( input.value == '' ) {
		if( typeof passwordField != 'undefined' ) {
			document.getElementById( passwordField ).style.display = 'none';
			document.getElementById( passwordField+'_text' ).style.display = '';
		} else {
			input.value = defaultText;
		}
	}
}

function validateLogin() {
	var validate = new validateForm();
	if( document.getElementById('clientLogin_username').value == '- Username' ) {
		validate.addCustomError( 'Username' );
	} else {
		validate.checkText( 'clientLogin_username', 'Username' );
	}
	validate.checkText( 'clientLogin_password', 'Password' );
	
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		return false;
	} 
	return true;
}
function showTab(tabnumber) {
	$('.productTabOn').removeClass('productTabOn');
	$('#productTab'+tabnumber).addClass('productTabOn');
	$('.productTabContent').hide();
	$('#productTabContent'+tabnumber).show();
}

function doScroller(scrollName) {
	var innerHeight = $('#scroll_'+scrollName+'_Inner').innerHeight();
	var outerHeight = $('#scroll_'+scrollName+'_Outer').innerHeight();
	var scrollerMaxPages = innerHeight / outerHeight;
	var currentScrollPage = 1;
	scrollers[scrollName] = new Array();
	scrollers[scrollName]['maxPages'] = scrollerMaxPages;
	scrollers[scrollName]['currentPage'] = currentScrollPage;
	$('#scroll_'+scrollName+'_Outer').scrollTop((currentScrollPage * outerHeight) - outerHeight);
	var pageHTML = '';
	if(scrollerMaxPages > 1) {
		for(i=1;i<=scrollerMaxPages;i++) {
			pageHTML += '<a href="#" onclick="doScrollTo(\''+scrollName+'\','+i+'); return false;">'+i+'</a> ';
		}
		$('#scroll_'+scrollName+'_Pages').html(pageHTML);
	}
	else {
		$('#scroll_'+scrollName+'_Pages').html('');
	}
}
function scrollIncrease(scrollName) {
	var currentScrollPage = scrollers[scrollName]['currentPage'];
	var scrollerMaxPages = scrollers[scrollName]['maxPages'];
	if(currentScrollPage < scrollerMaxPages) {
		currentScrollPage++;
		var outerHeight = $('#scroll_'+scrollName+'_Outer').innerHeight();
		$('#scroll_'+scrollName+'_Outer').scrollTop((currentScrollPage * outerHeight) - outerHeight);
	}
	scrollers[scrollName]['currentPage'] = currentScrollPage;
}
function scrollDecrease(scrollName) {
	var currentScrollPage = scrollers[scrollName]['currentPage'];
	var scrollerMaxPages = scrollers[scrollName]['maxPages'];
	if(currentScrollPage > 1) {
		currentScrollPage--;
		var outerHeight = $('#scroll_'+scrollName+'_Outer').innerHeight();
		$('#scroll_'+scrollName+'_Outer').scrollTop((currentScrollPage * outerHeight) - outerHeight);
	}
	scrollers[scrollName]['currentPage'] = currentScrollPage;
}
function doScrollTo(scrollName,pageNum) {
	currentScrollPage = pageNum;
	var outerHeight = $('#scroll_'+scrollName+'_Outer').innerHeight();
	$('#scroll_'+scrollName+'_Outer').scrollTop((currentScrollPage * outerHeight) - outerHeight);
}

//PAGINATION
jQuery.fn.paginate = function(opts) {
	opts = jQuery.extend({
		items_per_page: 10,
		current_page: 1, 
		prev_text: "&lt;",
		next_text: "&gt;",
		result_sizes: "10,20,30",
		filter_text: "",
		pagination_div: ".pagination",
		on_create: function(){},
		on_update: function(){}
	},opts||{});
	
	// hide all articles
	var items = this.find(".paginatedItem");
	items.each( function() {
		$(this).hide();
	});
	
	var self = this;
	if(opts.filter_text != "") {
		var items = this.find("."+opts.filter_text+".paginatedItem");
	}
	var total_items = items.length;
	var page_count = Math.ceil(total_items/opts.items_per_page);
	var current_page = opts.current_page;
	var items_per_page = opts.items_per_page;
	var	pagination_panels = this.find(opts.pagination_div);
	var on_create = opts.on_create;
	var on_update = opts.on_update;
	
	function createPagination() {
		//Page change function
		var pageChanger = function(page_id) {
			current_page = page_id;
			createPagination();
		}
		//Result size change function
		var sizeChanger = function(result_size) {
			items_per_page = result_size;
			page_count = Math.ceil(total_items/items_per_page);
			current_page = 1;
			createPagination();
		}
		
		//Show or hide items
		start_item = 1 + ((current_page-1) * items_per_page);
		current_item = 1;
		shown_items = 0;
		items.each( function() {
			if(current_item >= start_item && shown_items < items_per_page)
			{
				$(this).show();
				shown_items++;
			}
			else
			{
				$(this).hide();
			}
			current_item++;
		});
		
		//Update top
		pagination_panels.html("Page: ");	
		previous_page = current_page-1;
		next_page = current_page+1;
		
		//Add previous link
		pagination_panels.each(function(){
			if(current_page > 1) {
				previous_link = jQuery("<a href=\"\">"+opts.prev_text+"</a>");
				previous_link.bind("click", function (event){
					event.preventDefault();
					pageChanger(previous_page);
				});
				$(this).append(previous_link);
				$(this).append(" ");
			} else {
				$(this).append(opts.prev_text+" ");
			}
		});
		//Add page links
		pagination_panels.each(function(){
			for(i=1;i<=page_count;i++) {
				page_link = jQuery("<a href=\"\">"+i+"</a>");
				if(i == current_page) {
					page_link.addClass("current");
				}
				page_link.bind("click", function(event) {
					event.preventDefault();
					targtext = event.target.text || event.target.innerText;
					pageChanger(targtext);
				});
				$(this).append(page_link);
				$(this).append(" ");
			}
		});
		//Add next link
		pagination_panels.each(function(){
			if(current_page < page_count) {
				next_link = jQuery("<a href=\"\">"+opts.next_text+"</a>");
				next_link.bind("click", function(event) {
					event.preventDefault();
					pageChanger(next_page);
				});
				$(this).append(next_link);
				$(this).append(" ");
			} else {
				$(this).append(opts.next_text+" ");
			}
		});
		//Need to find a better way of doing this
		pagination_panels.append("<img class=\"spacer\" src=\"/custom/images/1x1t.gif\"/>");
		
		//Add result size options
		pagination_panels.append("Display: ");
		result_sizes = opts.result_sizes.split(",");
		pagination_panels.each(function(){
			for(j=0;j<result_sizes.length;j++) {
				result_link = jQuery("<a href=\"\">"+result_sizes[j]+"</a>");
				if(result_sizes[j] == items_per_page) {
					result_link.addClass("current");
				}
				result_link.bind("click", function(event) {
					event.preventDefault();
					targtext = event.target.text || event.target.innerText;
					sizeChanger(targtext);
				});
				$(this).append(result_link);
				$(this).append(" ");
			}
		});
		on_update();
	}
	
	if(total_items > 0) {
		createPagination();
		on_create();
		self.show();
	} else {
		self.hide();
	}
};
function hideHeaders(){
	$("#paginated").children().each(function(){
		if($(this).hasClass("manualSection")){
			if(!$(this).next().hasClass("paginatedItem")){
				$(this).hide();
			}
			else{
				if($(this).next().css("display") == 'none'){
					$(this).hide();
				}
				else{
					$(this).show();
				}
			}
		}
	});
}
function changeSortOrder( sort ) {
	if( sort != '' ) {
		document.location = sort;		
	}
}
function changeFilter(filterBox) {
	var filtertext = 'cat_'+$(filterBox).val();
	if(filtertext == 'cat_'){
		filtertext = '';
	}
	$("#paginated").paginate({
		items_per_page: 16,
		result_sizes: "16,32,48",
		pagination_div: ".newsPagination",
		filter_text: filtertext,
		on_update: function(){
			hideHeaders();
		}
	});
}

function validateForm() {
	
	// holds an array of errors to output
	var fieldErrorArray = new Array();
	
	// private accessor methods
	this.checkRadio = checkRadio;
	this.checkChecked = checkChecked;
	this.checkText = checkText;
	this.checkTextMinLength = checkTextMinLength;
	this.checkNumeric = checkNumeric;
	this.checkPrice = checkPrice;
	this.checkListBoxHasItems = checkListBoxHasItems;
	this.checkSelect = checkSelect;
	this.validateEmailAddress = validateEmailAddress;
	this.validatePostCode = validatePostCode;
	this.displayErrors = displayErrors;
	this.numberOfErrors = numberOfErrors;
	this.addCustomError = addCustomError;
	this.getErrors = getErrors;
	
	// returns the array of errors
	function getErrors() {
		return fieldErrorArray;
	}
	
	// checks that one has been checked (may need altering)
	function checkRadio( element, length, output ) {
	
		var hasChecked = false;
		for (i = 0; i < length; i++){
			if (document.getElementById( element + '[' + i + ']').checked) {
		      hasChecked = true;
		   }
		}
		if(!hasChecked){
			fieldErrorArray.push(output);
		}
	}
	
	function checkChecked( element, output, elementId ) {
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).removeClass( "red" );
		}
		
		if (!document.getElementById( element ).checked) {
			fieldErrorArray.push(output);
			if( typeof elementId != 'undefined' ) {
				$('#' + elementId ).addClass( "red" );
			}			
		}
	}
	
	// ensures text has been entered
	function checkText ( element, output, defaultText, elementId ) {
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).removeClass( "red" );
		}
		
		if (document.getElementById( element ).value == '') {
			fieldErrorArray.push(output);
			if( typeof elementId != 'undefined' ) {
				$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
			}
		} else if (( typeof defaultText != 'undefined' ) && defaultText != '') {
			if ( document.getElementById( element ).value == defaultText ) {
				fieldErrorArray.push(output);
				if( typeof elementId != 'undefined' ) {
					$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
				}
			}
		}
	}
	
	// ensures text of certain length has been entered
	function checkTextMinLength ( element, output, charLength ) {
		var checkString = document.getElementById( element ).value;
		if( checkString.length < charLength ){
			fieldErrorArray.push(output);
		}
	}
	
	function checkNumeric ( element, output ){
		var data = document.getElementById( element ).value;
		var ValidChars = "0123456789.";
		var IsNumber = true;
		var Char;
		if( data.length > 0 ) {
			for (i = 0; i < data.length && IsNumber == true; i++){ 
				Char = data.charAt(i); 
				if (ValidChars.indexOf(Char) == -1){
					// ok, its not valid, if its first position is a minus
					if( i == 0 && Char == '-' ) {
						// first character can be a "-" (minus)
					} else {
						IsNumber = false;
					}
				}
			}
			if( !IsNumber ){
				fieldErrorArray.push( output + ' must be a numeric value' );
			}
		} else {
			// no value entered
			fieldErrorArray.push( output );
		}
	}
	
	function checkPrice ( element, output  ){
		var data = document.getElementById( element ).value;
		var ValidChars = "0123456789.,";
		var IsNumber = true;
		var Char;
		if( data.length > 0 ) {
			for (i = 0; i < data.length && IsNumber == true; i++){ 
				Char = data.charAt(i); 
				if (ValidChars.indexOf(Char) == -1){
					IsNumber = false;
				}
			}
			if( !IsNumber ){
				fieldErrorArray.push( output + ' must be a price' );
			}
		} else {
			// no value entered
			fieldErrorArray.push( output );
		}
	}
	
	
	// checks for items in the passed listbox
	function checkListBoxHasItems ( element, output ) {
		if( document.getElementById( element ).length <= 0) {
			fieldErrorArray.push(output);
		}
	}
	
	// checks the value chosen is not the passed default value
	function checkSelect ( element, nothingValue, output, elementId ){
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).removeClass( "red" );
		}
	
		if( document.getElementById( element ).value == nothingValue ){
			fieldErrorArray.push(output);
			if( typeof elementId != 'undefined' ) {
				$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
			}
		}
	}
	
	// checks the value chosen is not the passed default value
	function validateEmailAddress ( emailAddress, output, elementId ){
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).removeClass( "red" );
		}
	
		if( document.getElementById( emailAddress ) )
			emailAddress = document.getElementById( emailAddress ).value;
		if( typeof( output ) == 'undefined' )
			output = 'Email address is invalid';
		var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if ( !filter.test( emailAddress )){
			fieldErrorArray.push( output );
			// set the necessary element to red
			if( typeof elementId != 'undefined' ) {
				$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
			}
		}
	}
	
	// checks the value chosen is not the passed default value
	function validatePostCode ( element, output, elementId ){
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).removeClass( "red" );
		}
	
		var filter  = /^[A-Za-z]{1,2}[0-9]{1}[A-Za-z0-9]{0,1}[ ]?[0-9]{1}[A-Za-z]{2}$/;
		if ( !filter.test( document.getElementById( element ).value ) ){
			fieldErrorArray.push( output );
			// set the necessary element to red
			if( typeof elementId != 'undefined' ) {
				$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
			}
		}
	}
	
	
	// add a custom error to the array
	function addCustomError( errorMessage, elementId ){
		// clear down any styles
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).removeClass( "red" );
		}
	
		fieldErrorArray.push( errorMessage );
		// set the necessary element to red
		if( typeof elementId != 'undefined' ) {
			$('#' + elementId ).parent().prev( 'th' ).addClass( "red" );
		}
	}
	
	// returns the number of errors found
	function numberOfErrors(){
		return fieldErrorArray.length;
	}
	
	// alerts all current errors to the user	
	function displayErrors(){
		var output = '';
		for(i=0;i<fieldErrorArray.length;i++){
			output += ' - ' +fieldErrorArray[i] + '\n';
		}
		alert('The following fields have not been completed:\n\n' + output);
	}
}

function triggerSearch() {
	// cancel the last search
	clearTimeout( searchtimer );
	// instead do one in 1/2 a second
	searchtimer = setTimeout( "quickSearch();", 500 );
}

function quickSearch()
{
	var limit = 4;
	var searchText = $('#searchText').val();
	// ensure we have at least 3 characters
	if( searchText != '- Product search' && searchText.length > 2 ) {
		// send the query
		var sUrl = "/xmlservice.php?service=quickSearch&query=" + searchText + "&limit=" + limit;
		$.ajax({
			type: "GET",
			url: sUrl,
			success: function( result ){
				// got results, set the ul list to empty
				$('#quickSearchResults').html('');
				if( result.ResultSet.Result ) {
					var recordCount = 0;
					for( var product in result.ResultSet.Result ) {
						recordCount++;
					}
					var html = '';
					if( recordCount > 0 ) {
						for( var product in result.ResultSet.Result ) {
							
							var imagePath = '/custom/images/noimage-50.gif';
							if(result.ResultSet.Result[product]['media']['0']) {
								if(result.ResultSet.Result[product]['media']['0']['preview_url']) {
									imagePath = result.ResultSet.Result[product]['media']['0']['preview_url'];
								}
							}
							
							html += '<div class="quickSearchResult">';
							html += '<div class="quickSearchImage"><a href="' + result.ResultSet.Result[product]['path'] + '" title="' + result.ResultSet.Result[product]['display'] + '"><img src="' + imagePath + '" alt="' + result.ResultSet.Result[product]['display'] + '"/></a></div>';
							html += '<div class="quickSearchName"><a class="quickSearchNameLink" href="' + result.ResultSet.Result[product]['path'] + '" title="' + result.ResultSet.Result[product]['display'] + '">' + result.ResultSet.Result[product]['display'] + '</a></div>';
							html += '<div class="quickSearchView"><a href="' + result.ResultSet.Result[product]['path'] + '" title="' + result.ResultSet.Result[product]['display'] + '"><img src="/custom/images/view-button.png" alt="View"/></a></div>';
							html += '<div class="clearer"></div>';
							html += '</div>';
						}
					}
					else {
						html += '<div class="quickSearchNothing">No products found!</div>';
					}
					$('#quickSearchResults').append( html );
					$('#quickSearchArrow').show();
					$('#quickSearchResults').show();
				}
			},
			error : function( result ){
			},
			dataType: "json"
		});
	}
}

function hideSearch() {
	$('#quickSearchArrow').fadeOut('slow');
	$('#quickSearchResults').fadeOut('slow');
}

function showRegister() {
	$('#stage1Crumb').removeClass('basketCrumbCurrent');
	$('#stage1Crumb').addClass('basketCrumbAvailable');
	$('#stage2Crumb').removeClass('basketCrumbUnavailable');
	$('#stage2Crumb').addClass('basketCrumbCurrent');
	$('#checkoutLoginPanel').hide();
	$('#checkoutRegisterPanel').hide();
	$('.quantityEditable').hide();
	$('.quantityStatic').show();
	$('.checkoutLastCell').html('&nbsp;');
	$('.checkoutLastCell').css('width','auto');
	$('#registerBox').show();
}

function changeQuantityInMiniBasket( itemId, val, action ) {
	if (val == 0 || val == null) {
		document.getElementById('minibasket_quantity_' + itemId).value = 0;
	} else {
		document.getElementById('minibasket_quantity_' + itemId).value = parseInt( document.getElementById('minibasket_quantity_' + itemId).value ) + val;
	}
	$.post( '/manage_basket.php?CMSCatalogueBasket[remove_from_cart]=1', $("#miniBasketForm").serialize(),function( data ){
		$('#popupBasketPanel').remove();
		$('#navBasket').html( data );
		checkVATCookie();
		$('#popupBasketPanel').dialog("open");
	},'html');
}