function insertIntoCart(pProductId, pAmount, pLink) {
	$.post('http://'+gHost+'/lt-cart-insert_item.html', {
		product_id: pProductId,
		amount: pAmount
	}, function(hhhtml) {
		window.location.href = pLink;
	});

	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);
		}
	}
}
