// Generated from /privilegeArea/proxy.phtml?showstub=true&amp;objectname=PrivilegeAreaWebController, DO NOT EDIT!
if(typeof(PrivilegeAreaWebController) == 'undefined')
	PrivilegeAreaWebController = new Object();

Object.extend(PrivilegeAreaWebController, 
{
	switchStep: function(currentStepContainerId,dir)
	{
		var currentStepContainer = $(currentStepContainerId);
		
		if (dir =='previous')
		{
			var previousContainer = currentStepContainer.previous();
			if (previousContainer)
			{
				$('title_'+ currentStepContainer.id).removeClassName('current_title_step');
				$('title_'+ previousContainer.id).addClassName('current_title_step');
				currentStepContainer.hide();
				previousContainer.show();
				console.debug(currentStepContainer.id, previousContainer.id);
			}
		}
		else
		{
			var nextContainer = currentStepContainer.next();
			if (nextContainer)
			{
				$('title_'+ currentStepContainer.id).removeClassName('current_title_step');
				$('title_'+ nextContainer.id).addClassName('current_title_step');
				currentStepContainer.hide();
				nextContainer.show();
				console.debug(currentStepContainer.id, nextContainer.id);
			}
			
		}
	},
	
	
	
	displayListFabricColors: function(type, fabricKey)
	{
   		var fabric = $('fabric_' + type + '_' + fabricKey);
		if ( fabric )
		{
			var list_fabriccolor = $$('div.list_fabriccolor_' + type);
			list_fabriccolor.each(function(e)
			{
				if (e.id == 'list_fabriccolor_' + type + '_' + fabricKey)
					e.show();
				else
					e.hide();
			});			
		}
	},
	loadFabricsColors: function (submodelKey, iso, lineKey, fabricOption, orderItemkey)
	{
		this._loadFabricWithAllColorData(submodelKey, iso, lineKey, fabricOption, orderItemkey, function(r, j)
		{
			j = this._getJSON(r, j);
			if (j && !j.failed && j.out) 
			{
				$('fabricsColorsContainer').update(j.out);
			}
		}.bind(this));
	},
	loadFabricsColors_old: function (submodelKey, iso, lineKey, fabricOption)
	{
		var fabricsColorsContainerTPL = $('fabricsColorsContainerTPL').innerHTML;
		var fabricColorsContainerTPL = ($$('span#fabricsColorsContainerTPL span.fabricColorsContainerTPL')[0]).innerHTML;
		$('fabricsColorsContainer').update( '' );
		this._loadFabricWithAllColorData(submodelKey, iso, lineKey, fabricOption, function(r, j)
		{
			j = this._getJSON(r, j);
			if(j && !j.failed && j.out)
			{
				var fabricsColors = $H(j.out);
				(fabricsColors).each(function(fabricColors) 
				{
					var typeKey = fabricColors[0];
					var tmp = fabricsColorsContainerTPL.interpolate({type:typeKey, typeName:fabricColors[1].typeData.typeName});
					$('fabricsColorsContainer').insert({bottom: tmp});
					($$('div#fabricsColorsContainer_' + typeKey + ' span.fabricColorsContainerTPL')[0]).remove();
					
					
					var data = $H(fabricColors[1].fabrics);
					tmp = '';
					(data).each(function(d) {
						var fabricKey = d[0];
						tmp = fabricColorsContainerTPL.interpolate({type:typeKey, typeName:fabricColors[1].typeData.typeName,fabricKey:fabricKey, fabricName:d[1].fabric.fabricName});
						$('fabricsColorsContainer_' + typeKey).insert({bottom: tmp});
						var colors = d[1].fabricColors;
						$('list_fabriccolor_' + typeKey + '_'+ fabricKey).innerHTML = '';
						tmp = '';
						for(var i=0;i<colors.length; i++)
							tmp += '<input class="radio_fabriccolor" type="radio" id="fabriccolor_'+ colors[i].colorKey +'" name="configuration[fabric][' + typeKey + '][color]" id="fabriccolor" value="'+ colors[i].colorKey +'"/><label for="fabric_'+ colors[i].colorKey +'">('+ colors[i].colorReference +')'+ colors[i].colorName +'</label><br />';
						$('list_fabriccolor_' + typeKey + '_'+ fabricKey).innerHTML = tmp;
					});

					
				});
			}
		}.bind(this));
	},
	
	initAutocompleterModel: function(callBack, autoCompletionFieldId, autoCompletionResultListFieldId, filters)
	{
		var autoComplete = new Ajax.Autocompleter(autoCompletionFieldId,autoCompletionResultListFieldId,'/privilegeArea/proxy.phtml?method=_modelAutoCompleter&autoCompletionFieldId=' + autoCompletionFieldId + '&iso=' + Globule.currentLanguage,{
			select: autoCompletionFieldId,
			paramName:autoCompletionFieldId,
			minChars: 1,
			afterUpdateElement : callBack,
			onSuccess: function(xmlHttp)
			{
				$(autoCompletionResultList).setStyle({
					width: $(autoCompletionFieldId).getWidth()
				});
			},
			parameters: filters
		});
		return autoComplete;
	},
	modelAutoCompleterCallBack: function(text, li)
	{
		$('modelKey').value = li.readAttribute('modelKey');
		$('submodelKey').value = li.readAttribute('submodelKey');
		text.value = li.innerHTML;
	},
	
	initAutocompleterResource: function(callBack, autoCompletionFieldId, autoCompletionResultListFieldId, filters)
	{
		var autoComplete = new Ajax.Autocompleter(autoCompletionFieldId,autoCompletionResultListFieldId,'/privilegeArea/proxy.phtml?method=_resourceAutoCompleter&autoCompletionFieldId=' + autoCompletionFieldId + '&iso=' + Globule.currentLanguage, {
			select: autoCompletionFieldId,
			paramName:autoCompletionFieldId,
			minChars: 1,
			afterUpdateElement : callBack,
			onSuccess: function(xmlHttp)
			{
				$(autoCompletionResultList).setStyle({
					width: $(autoCompletionFieldId).getWidth()
				});
			},
			parameters: filters
		});
		return autoComplete;
	},
	resourceAutoCompleterCallBack: function(text, li)
	{
		$('resourceKey').value = li.readAttribute('resourceKey');
		$('resourceType').value = li.readAttribute('resourceType');
		text.value = li.innerHTML;
	},
	
	// menu fabric, foot
	_menu: null,
	_clean: true,	
	initMenu: function()
    {
        this._menu = $('resources-menu');
        $A(this._menu.getElementsByTagName('a')).each(function(l)
        {
            if (l.href != '#')
				$(l).observe('click', this._openMenu.bind(this, l));
        }.bind(this));
    },	
	_openMenu: function(l, e)
    {
        if(l.next('ul') == null)
            return;

        if(l.hasClassName('current'))
        {
            l.removeClassName('current');
            this._clean = false;
            new Effect.BlindUp(l.next('ul'), {duration: .3, afterFinish: function(){this._clean = true;}.bind(this)});
        }
        else
        {
            l.addClassName('current');
            this._clean = false;
            new Effect.BlindDown(l.next('ul'), {duration: .3, afterFinish: function(){this._clean = true;}.bind(this)});
        }
        if(e)
            e.stop();
        return false;
    }
	
});