// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var Cache = {
	data : {},
	store : function(el, force) {
		var dom = $(el);
		var id = Element.identify(dom);
		if(!this.data[id] || force)
			this.data[id] = dom.innerHTML;
	},
	restore : function(el) {
		var dom = $(el);
		var id = Element.identify(dom);
		var content = this.data[id];
		if(content)
			dom.innerHTML = content;
	}
}
function show_loader(container_id, image ) 
{ 
	if (!image) image = 'snake';
	with($(container_id))
	{
		innerHTML = '<img src="/images/'+ image +'.gif" />';
		show();
	}
}
var Product = {
	product_id: null,
	updateTrackingOptions: function(variantID){
		this.hideAllTrackingOptions(variantID);
		this.showTrackingOptions(variantID);
	},
	
	hideAllTrackingOptions: function(variantID){
		$('inventory-controls-' + variantID).select('.inventory-option').each(function(control){
			Element.hide(control);
		});
		$('inventory-policy-' + variantID).hide();
	},
	
	showTrackingOptions: function(variantID){
		if ($('inventory-select-' + variantID).value != '') {
			$('inventory-policy-' + variantID).show();
			$($('inventory-select-' + variantID).value + "-inventory-" + variantID).show();
		}
	},
	remove:function(good_id) {
		var my_cat = $('good_' + good_id);
	   	
	    FTableManager.Remove(my_cat);
	}
}

var Tags = 
{
	select : function(control, tag_id, options) {
		var parent = $(control).parentNode;
		var hidden = $(parent).select('input[type=hidden]').first();
		if(!hidden) return;
		
		if(!options.multiple) {
			parent.select('a.selected').each(function(el){
				el.removeClassName('selected');
			});
			hidden.value = tag_id;
			control.addClassName('selected');
		} else {
			var value = (',' + hidden.value + ',').gsub(',', ' ');
			var key = ' ' + tag_id + ' ';
			if(value.include(key)) {
				hidden.value = value.replace(key, ' ').strip().gsub(' ', ',');
				control.removeClassName('selected');
			} else {
			 	hidden.value = (value + tag_id).strip().gsub(' ', ',');
				control.addClassName('selected');
			 }
		}
	}
}


