function insertIntoCart(productId, amountId) {
	$.post('cart/insert_item/', {
		product_id: productId,
		amount: $('#' + amountId).attr('value')
	}, function() {
		$('#cart-params').load('cart/info_block/');
		//$('#cart-popunder-' + productId).css('display', 'block');
		$('#cart-popunder-' + productId).fadeIn();
		$('#cart-popunder-' + productId).fadeOut(1500);
		$('#amount' + productId).attr('value', 0);
	});
}

function insertIntoCart2(productId) {
    pamount = $('#opt-1').attr('value');
    pcolor  = $('#opt-12').attr('value');
    psize   = $('#opt-11').attr('value');

    parameters = {product_id: productId, amount: pamount, color_id: pcolor, size_id: psize};

    $.ajax({
        url: 'cart/insert_item/',
        data: parameters,
        dataType: 'html',
        type: 'GET',
        timeout: 5000,
        error: function(xhr,err,e) {
            alert( "Error: " + err );
        },
        success: function(html){
            $('#cart-params').load('cart/info_block/');
        }
    });

    return false;
}


function is_numeric(string, positive_only) {
	pos_valid_chars = "1234567890.";
	all_valid_chars = "1234567890.-";

	dots = 0;

	if(string.length == 0)
		return false;

	for(i = 0; i < string.length && (dots <= 1); i++) {
		ch = string.charAt(i);

		if(ch == ".")
			dots++;

		// jeigu pirmas taskas iseinam
		if((i == 0) && (ch == '.'))
			return false;

		// jeigu daugiau kaip 1 taskas, iseinam
		if(dots > 1)
			return false;

		if(positive_only) {
			if(pos_valid_chars.indexOf(ch) == -1) {
				return false;
			}
		}
		else {
			// ziurim pirma skaiciu, nes tik jis gali buti "-"
			if(i == 0) {
				if(all_valid_chars.indexOf(ch) == -1) {
					return false;
				}
			}
			else {
				if(pos_valid_chars.indexOf(ch) == -1) {
					return false;
				}
			}
		}
	}

	return true;
}

function changeAmount(increase, elemId) {
	try {
		amount = $('#' + elemId).attr('value');
		if(!is_numeric(amount, true)) {
			$('#' + elemId).attr('value', 0)
			return;
		}
		else
			amount = parseInt(amount);
	}
	catch(exp) {
		$('#' + elemId).attr('value', 0)
		return;
	}

	if(increase) {
		amount++;
		$('#' + elemId).attr('value', amount);
	}
	else {
		if(amount > 0) {
			amount--;
			$('#' + elemId).attr('value', amount);
		}
	}
}