function cartProductDelete( req, product_id, colour_id ) {
	
	try {
		var response = req.responseText;
	} catch( e ) {
		var response = '';
	}
	
	$( 'block_cart_price' ).innerHTML = response;
	$( 'type_cart_total_price' ).innerHTML = response;
	
	if ( response == '0.00' ) {
		// no more products - little css tweak
		$( 'type_cart_total_price' ).parentNode.parentNode.className = 'sum_div sum_div_no_border';
	}
	
	var nodeList = $( 'product_row_' + product_id + '_' + colour_id ).parentNode.childNodes;
	var row_regex = /^product_row_/;
	
	$( 'product_row_' + product_id + '_' + colour_id ).parentNode.removeChild( $( 'product_row_' + product_id + '_' + colour_id ) );
	
	for ( i in nodeList ) {
		if ( nodeList[i].id ) {
			if ( nodeList[i].id.match( row_regex ) ) {
				var last_row_element = nodeList[i];
			}
		}
	}
	
	last_row_element.className = 'last_row';
	last_row_element.onmouseover = function () { this.className='last_row_ov'; };
	last_row_element.onmousout = function () { this.className='last_row'; };
}

function cartViewUpdate( req, id ) {
	try {
		var response = req.responseText;
	} catch( e ) {
		var response = '|';
	}
	
	try {
		var parts = response.split( '|' );
		
		if ( parts.length == 3 ) {
			var quantity = parts[0];
			var all_price = parts[1];
			var price = parts[2];
		} else {
			var quantity = '';
			var all_price = '';
			var price = '';
		}
	} catch( e ) {
		var quantity = '';
		var all_price = '';
		var price = '';
	}
	
	$( id ).value = quantity;
	$( id + '_price' ).innerHTML = '<strong>' + price + '</strong>';
	$( 'block_cart_price' ).innerHTML = all_price;
	$( 'type_cart_total_price' ).innerHTML = all_price;
}

function cartBlockUpdate( req ) {
	
	try {
		var response = req.responseText;
	} catch( e ) {
		var response = '|';
	}
	
	try {
		var parts = response.split( '|' );
		if ( parts.length == 2 ) {
			var product = parts[0];
			var price = parts[1];
		} else {
			var product = '';
			var price = '';
		}
	} catch( e ) {
		var product = '';
		var price = '';
	}
	
	if ( $( 'block_cart_last_product' ) ) {
		$( 'block_cart_last_product' ).innerHTML = product;
	}
	if ( $( 'cart_info_block_text' ) ) {
		$( 'cart_info_block_text' ).innerHTML = product;
	}
	if ( $( 'block_cart_price' ) ) {
		$( 'block_cart_price' ).innerHTML = price;
	}
}

function cartBlockShowPreloaders() {
	cartAddPreloader( 'cart_info_block_text' );
	cartAddPreloader( 'block_cart_last_product' );
	cartAddPreloader( 'block_cart_price' );
}

function cartAddPreloader( id ) {
	$( id ).innerHTML = ' <img src="' + root_url + 'media/images/loading.gif" alt="" style="width:16px; height:8px; display:inline;" />';
}

function cartAddProduct( url, quantity, colour_id, function_before, function_on_success ) {
	
	// run function if needed
	try {
		eval( function_before );
	} catch( e ) {
	}
	
	if ( quantity != '' ) {
		
		var regex = /^[\+,-]+/;
		
		if ( !quantity.match( regex ) ) {
			try {
				var q = parseInt( quantity );
				
				if ( isNaN( q ) ) {
					q = 1;
				}
			} catch( e ) {
				var q = 1;
			}
			
			if ( q < 1 ) {
				q = 1;
			}
		} else {
			
			var q = quantity.replace( '+', '%2B' );
		}
		
		url += '&q=' + q;
	}
	
	if ( colour_id != '' ) {
		url += '&colour_id=' + colour_id;
	}
	
	// send ajax request
	var ajaxRequest = new Ajax.Request(
		url, {
			method: 'get',
			parameters: '',
			onSuccess: function ( req ) {
				try {
					eval( function_on_success );
				} catch( e ) {
				}
			}
		}
	);
}

function cartAddAllProducts( base_url, function_before, function_on_success ) {
	
	base_url += '&product_id=';
	
	for ( var i = 1; i <= products_on_page; i++ ) {
		
		if ( products[i] && $( 'product_quantity_' + products[i] ).value ) {
			
			if ( parseInt( $( 'product_quantity_' + products[i] ).value ) != 0 ) {
				
				var url = base_url + products[i];
				var quantity = $( 'product_quantity_' + products[i] ).value;
				var colour_id = '';
				
				if ( $( 'product_colour_' + products[i] ) ) {
					
					var colour_select = $( 'product_colour_' + products[i] );
					
					colour_id += colour_select.options[colour_select.selectedIndex].value;
				}
			}
			
			// reseting value of input field
			$( 'product_quantity_' + products[i] ).value = '';
			
			cartAddProduct( url, quantity, colour_id, function_before, function_on_success );
		}
	}
}

function setColourId ( select_id, input_id ) {
	
	if ( $( 'select_id' ) && $( 'input_id' ) ) {
		
		var colour_select = $( 'select_id' );
		
		$( 'input_id' ).value = colour_select.options[colour_select.selectedIndex].value;
	}
}