function changeMainCat(control)
{
	var selItem=control.options[control.selectedIndex];
	var name=selItem.id;
	var id=selItem.value;
	name=cleanForUrl(name);
	if(id==0) document.location=baseurl;
	else document.location=baseurl+'catalog/'+name+'-cat-'+id+'/pagina-1/';
}
function changeCat(control)
{
	var selParent=document.getElementById('main_cat_filter').options[document.getElementById('main_cat_filter').selectedIndex];
	var selItem=control.options[control.selectedIndex];
	var parentName=selParent.id;
	var name=selItem.id;
	var parentId=selParent.value;
	var id=selItem.value;
	name=cleanForUrl(name);
	parentName=cleanForUrl(parentName);
	
	if(id==0) document.location=baseurl+'catalog/'+parentName+'-cat-'+parentId+'/pagina-1/';
	else document.location=baseurl+'catalog/'+parentName+'-cat-'+parentId+'/'+name+'-cat-'+id+'/pagina-1/';
}
function changeSubCat(control)
{
	var selGrandParent=document.getElementById('main_cat_filter').options[document.getElementById('main_cat_filter').selectedIndex];
	var selParent=document.getElementById('cat_filter').options[document.getElementById('cat_filter').selectedIndex];
	var selItem=control.options[control.selectedIndex];
	var grandParentName=selGrandParent.id;
	var parentName=selParent.id;
	var name=selItem.id;
	var grandParentId=selGrandParent.value;
	var parentId=selParent.value;
	var id=selItem.value;
	name=cleanForUrl(name);
	parentName=cleanForUrl(parentName);
	grandParentName=cleanForUrl(grandParentName);
	
	if(id==0) 
		document.location=baseurl+'catalog/'+grandParentName+'-cat-'+grandParentId+'/'+parentName+'-cat-'+parentId+'/pagina-1/';
	else
		document.location=baseurl+'catalog/'+grandParentName+'-cat-'+grandParentId+'/'+parentName+'-cat-'+parentId+'/'+name+'-cat-'+id+'/pagina-1/';
}
function changeProducer(control)
{
	var selItem=control.options[control.selectedIndex];
	var name=selItem.id;
	name=cleanForUrl(name);
	var id=selItem.value;
	
	var location=document.location.href;
	location=location.replace(/\/[^\/]*-producator-[0-9]+\//,'/');
	if(id==0) document.location.href=location;
	else
	{
		location=location.replace(/pagina-([0-9]+)/,name+'-producator-'+id+'/pagina-1');
		document.location.href=location;
	}
}

function doSearchSubmit(text)
{
	if(text.length<3) 
	{
		alert('Completati numele produsului pe care doriti sa il gasiti!(minim 3 caractere)')
		return;
	}
	var location=baseurl+'produse/'+cleanForUrl(text)+'/pagina-1/';
	document.location=location;
}

function cleanForUrl(text)
{
	text=text.replace(/[^a-z0-9_\- ]/gi,'-');
	text=text.replace(/ /g,'+','g');
	return text;
}
