
var xTireOpt = 
{
	//active album_id
	album_id: 0,

	url_rel: '',
	url_rel_ajaxquery: '/x/',

	id_form: 'inptire',

	id_width: 'tirewidth',
	id_ratio: 'tireratio',
	id_diameter: 'tirediameter',
	id_season_t: 'tireseason_t',
	id_season_n: 'tireseason_n',

	init: function()
	{
		this.tURLGetRatio			= new Template(this.url_rel_ajaxquery+'?a=gettireratio&width=#{tirewidth}');
		this.tURLGetDiameter		= new Template(this.url_rel_ajaxquery+'?a=gettirediameter&width=#{tirewidth}&ratio=#{tireratio}');
	},

	getratio: function()
	{
		//Clear ratio and dimensions
		doit(0, this.id_form, this.id_ratio, 'clear', '', '');
		doit(0, this.id_form, this.id_diameter, 'clear', '', '');

		if ( $(this.id_width).value )
		{
			new Ajax.Request(this.tURLGetRatio.evaluate( {'tirewidth': $(this.id_width).value } ), 
			{
				method: 'post', 
				onSuccess: function(transport,json)
				{
					if (json)
					{
						var reply = transport.responseText.evalJSON();
						
						var data = reply.data.split(',');
						
						doit(0,this.id_form,this.id_ratio, 'add','','');
						for(i=0; i < data.length; i++)
						{
							doit(0,this.id_form,this.id_ratio, 'add',data[i],data[i]);
						} //for
					} //if
				}.bind(this) //function
			});
		} //if
	},

	getdiameter: function()
	{
		//Clear dimensions
		doit(0, this.id_form, this.id_diameter, 'clear', '', '');

		if ( $(this.id_width).value )
		{
			new Ajax.Request(this.tURLGetDiameter.evaluate( {'tirewidth': $(this.id_width).value, 'tireratio': $(this.id_ratio).value } ), 
			{
				method: 'post', 
				onSuccess: function(transport,json)
				{
					if (json)
					{
						var reply = transport.responseText.evalJSON();
						
						var data = reply.data.split(',');
						
						doit(0,this.id_form,this.id_diameter, 'add','','');
						for(i=0; i < data.length; i++)
						{
							doit(0,this.id_form,this.id_diameter, 'add',data[i],data[i]);
						} //for
					} //if
				}.bind(this) //function
			});
		} //if
	},
	
	navigate: function()
	{
		if ( $(this.id_diameter).value )
		{
			var href = location.href;
			
			var rx = new RegExp("(/CW(.+)?)$","gi");
			href = href.replace(rx,'');

			var cw = '/CW/T';

			var width = $(this.id_width).value;
			var ratio = $(this.id_ratio).value;
			var diameter = $(this.id_diameter).value;
			
			var season = ($(this.id_season_t).checked ? 'T' : ($(this.id_season_n).checked ? 'N' : '') );
			var season = ( $(this.id_season_t).checked && $(this.id_season_n).checked ? '' : season);

			cw += width+','+ratio+','+diameter+(season? ','+season : '') +'/';
			
			location.href = href+cw;
		}
	},

};
