// From http://ajaxian.com/archives/ajax-activity-indicators-examples
Ajax.Responders.register({
	onCreate: function() {
		if($('indicator1') && Ajax.activeRequestCount> 0)
		Effect.Appear('indicator1',{duration: 0.5, queue: 'end'});
	},
	onComplete: function() {
		if($('indicator1') && Ajax.activeRequestCount == 0)
		Effect.Fade('indicator1',{duration: 0.5, queue: 'end'});
	}
});

function submitSearchForm() {
	new Ajax.Updater(
		'searchResultsPane',
		'/_ajax/searchResults.php?' + Form.serialize($('searchForm')),
		{
			asynchronous: true
		}
	);
}


function addFavorite(type_id, item_id) {
	new Ajax.Updater('foo','/_ajax/add_favorite.php?favorite_id=' + item_id + '&favorite_type_id=' + type_id, {asynchronous:true, evalScripts:true});
}

function addShoppingList(item_id) {
	new Ajax.Updater('foo','/_ajax/add_shoppingList.php?item_id=' + item_id, {asynchronous:true, evalScripts:true});
}

function removeShoppingList(item_id) {
	new Ajax.Updater('foo','/_ajax/remove_shoppingList.php?item_id=' + item_id, {asynchronous:true, evalScripts:true});
}

function removeFavorite(type_id, item_id) {
	new Ajax.Updater('foo','/_ajax/remove_favorite.php?favorite_id=' + item_id + '&favorite_type_id=' + type_id, {asynchronous:true, evalScripts:true});
}

// Google Charts API

var simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

function simpleEncode(valueArray,maxValue) {
	var chartData = ['s:'];

	for (var i = 0; i < valueArray.length; i++) {
		var currentValue = valueArray[i];
		if (!isNaN(currentValue) && currentValue >= 0) {
			chartData.push(simpleEncoding.charAt(Math.round((simpleEncoding.length-1) * currentValue / maxValue)));
		}
		else {
			chartData.push('_');
		}
	}

	return chartData.join('');
}