/*--------------------------*/
/*		   Category			*/
/*--------------------------*/

/**
 * toggle section defined by its id
 */
function toggleSection(id_section)
{
	$(id_section).toggle();
}

/** 
 * toggle all sections except price and general
 */
function toggleAllSection(css_selector)
{
	var elements = $$(css_selector);
	for( i=0; i < elements.length ; i++ )
	{
		toggleSection( elements[i].id );
	}
}

/*------------------------------*/
/*	ChangeWorkingCultureHelper	*/
/*------------------------------*/
/**
 * Close all the WorkingCulture selector
 * 
 * @param id_zone string the current workingCulture selector
 * @param culture the new selected culture
 * @return
 */
function toggleAllWorkingCulture(culture)
{
	selectors = $$(".presta_workingCultureSelector dt a");
	
	for(var i = 0; i < selectors.length ; i++)
	{
		selectors[i].innerHTML = culture;
	}

	$$("dd.working_culture_list").invoke("hide");
}


/**
 * Default function for the helper who change the display in function of the working culture
 * 
 * @param a_culture array all authorized culture
 * @param newCulture string the new selected culture
 * @return
 */
function changeWorkingCulture( a_culture, newCulture )
{ 				
	for (var j = 0; j < a_culture.length; j++)
	{	
		$$(".presta_pageContentByCulture[culture="+a_culture[j]+"]").each(function(el){
			if (a_culture[j] != newCulture)
			{
				el.hide();
			}
			else
			{
				el.show();
			}
		});
	}
}


/**
 * hide all input or container with culture whiwh is not the current
 * 
 * @param culture String - the current culture
 * @param parents Array - list of id where to search
 * 
 * @deprecated - use workingCultureManager 
 */
function initWorkingCultureContent(culture, parents)
{
	for( var i=0; i<parents.length ; i++ )
	{
		if( $(parents[i]) )
		{
			var wcContainers = $(parents[i]).getElementsByClassName("presta_pageContentByCulture");
			
			for( var j=0; j<wcContainers.length ; j++ )
			{
				if( wcContainers[j].getAttribute('culture') !== culture )
				{
					wcContainers[j].hide();
				}
				else
				{
					wcContainers[j].show();
				}
			}
		}
	}
}


/**
 * Simili-Singleton of culture manager
 */
wCM = new function workingCultureManager(){
	
	var current;
	
	this.getCurrent = function(){
		return current;
	};
	
	this.changeWorkingCulture = function(culture){
		current = culture;
		$$(".presta_pageContentByCulture").each(function(item){
			if(item.getAttribute("culture") == current){
				item.show();
			} else {
				item.hide();
			}
		});
	};
	
	/**
	 * Close the WorkingCulture selector & define the current culture
	 * 
	 * @param id_zone string the current workingCulture selector
	 * @param culture the new selected culture
	 */
	this.toggleAllWorkingCulture = function(culture){
		$$(".presta_workingCultureSelector dt a").each(function(item){
			item.innerHTML = culture;
		});
		$$("dd.working_culture_list").invoke("hide");
		this.changeWorkingCulture(culture);
	};
	
};


/*--------------------------*/
/*		   Page				*/
/*--------------------------*/

//Switch content between truncat_text and complet_text
function switchPageContentDisplay(id_zone)
{
	$('truncate_text_'+id_zone).toggle();
	$('complet_text_'+id_zone).toggle();
}
