function show(nr){
	var div = document.getElementById("category"+nr);
	var cel = document.getElementById("categorycell"+nr);
	var status = div.style.display;
	//if(nr==794) { alert(status) ; }
	for(var i=0; i<catsarr.length; i++){

		if(catsarr[i] == nr){
			if(status == "none"){
				div.style.display = "block";
				cel.className = "category_cell_back_selected";
			}else{
				div.style.display = "none";
				cel.className = "category_cell_back";
			}
		}else{
			var divx = document.getElementById("category"+catsarr[i]);
			var celx = document.getElementById("categorycell"+catsarr[i]);

			if(divx)  { divx.style.display = "none"; }
			if(celx)  { celx.className = "category_cell_back"; }
		}

	}

}

function back_color_on(nr){
	var div = document.getElementById("category"+nr);
	var cel = document.getElementById("categorycell"+nr);
	var status = div.style.display;

	if(status == "none"){
		cel.className = "category_cell_back1";
	}
}

function back_color_off(nr){
	var div = document.getElementById("category"+nr);
	var cel = document.getElementById("categorycell"+nr);
	var status = div.style.display;

	if(status == "none"){
		cel.className = "category_cell_back";
	}
}

$(document).ready(function(){
	initDrops();
});


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function initDrops(){

	pags = window.location.href.replace('http://','').split('/');
	pags[0]='';
	pags[1]='';

	newUrlSuffix = '';
	for(i=2;i<pags.length;i++)
	{
		if(pags[i].split('pagina').length>1)
		{
			pags[i]='';
		}
		if(pags[i]!='')
		{
			newUrlSuffix = newUrlSuffix + '/' + pags[i]
		}
	}

	$('.products_list_pagination_links a').each(function(){
		var href = $(this).attr('href') + newUrlSuffix;
		$(this).attr('href', href);
	});


	$('.filter_cell_back').each(function(){

		//$(this).next('.filter_options_back').not('.open').hide(); // inchise implicit
		$(this).attr('rel','nofollow');
		$(this).click(function(){

			if($(this).next('.filter_options_back').is(':hidden'))
			{
				$(this).next('.filter_options_back').show();
			}
			else
			{
				$(this).next('.filter_options_back').hide();
			}
		});

	})

	$('form#form_filtre input:checkbox').each(function(){
		$(this).click(function(){

			//$('form#form_filtre input:checkbox').not(':checked').attr('disabled','disabled');

			$(this).parent().not('.multiselect').children().not($(this)).attr('checked','').attr('disabled','disabled');
			//$(this).has(':checked').attr('disabled','disabled');
			//$(this).attr('enabled','enabled');

			//alert($(this).attr('checked'));		return;
			if($(this).parent().hasClass('multiselect'))
			{
				$(this).parent().children().not($(this)).not(':checked').attr('checked','').attr('disabled','disabled');
			}


			manageFilterAction();

			if((($(this).attr('checked')=='false') || ($(this).attr('checked')=='')) )
			{
				if(($(this).parent().hasClass('multiselect')==false))
				{
					$(this).val(-1);
					$(this).attr('enabled','enabled');
					$(this).attr('checked','checked');
				}
				else
				{
					var oneChecked = '';

					$(this).parent().children().each(function(){

						if($(this).attr('checked'))
						{
							oneChecked = oneChecked +' ' + $(this).val();
						}
					});
					if(oneChecked=='')
					{
						$(this).val("-1");
						$(this).attr('enabled','enabled');
						$(this).attr('checked','checked');
					}
				}
			}

			$('form#form_filtre').submit();

		});
	});

	$('form#form_filtre button').each(function(){

		$(this).click(function(){
			if($(this).attr('name')!='option[]')
			{
				manageFilterAction();
			}
		});
	});

}


/**
 *
 * @access public
 * @return void
 **/
function manageFilterAction(){

			var url1='';
			$('form#form_filtre .multiselect  input:checkbox:checked').each(function(){
				if(url1=='')
				{
					url1=$(this).attr('title');
				}
				else
				{
					url1=url1+'-'+$(this).attr('title');
				}
			});

			var url2='';
			$('form#form_filtre input:checkbox:checked').each(function(){

				if($(this).parent().hasClass('multiselect')==false)
				{
					if(url2=='')
					{
						url2=$(this).attr('title');
					}
					else
					{
						url2=url2+'-'+$(this).attr('title');
					}
				}

			});


			if(url1!='') { url1='/brand-' + url1; }
			if(url2!='') { url1=url1+'/select-'+url2;	}
			var newaction = 'http://' +  ($('form#form_filtre').attr('title').replace('http://','') + url1).replace('//','/');

			$('form#form_filtre').attr('action', newaction);

}

function show_filter(){

}
