var catid_selectata;
var catidx;


function normal_catmare(x)
{
	elcatmare=locate_el('catmare_'+x);
	
	if(elcatmare!=catid_selectata)
		{
			elcatmare.style.backgroundColor='#FFFFFF';
		}
	else
		{
			elcatmare.style.backgroundColor='#AAC9D9';
		}
}
function hover_catmare(x)
{
	elcatmare=locate_el('catmare_'+x);
	elcatmare.style.backgroundColor='#dddddd';
}

function expand_menu(x)
{
	if(catid_selectata)
		{
			catid_selectata.style.backgroundColor='#FFFFFF';
		}
	
	catidx=x;
	catid_selectata=locate_el('catmare_'+x);
	catid_selectata.style.backgroundColor='#AAC9D9';
	
	set_selected_category(x);
	
	
	elssubcontainer=locate_el('cat_sub_cont_'+x);
	if(elssubcontainer)
		{
			if(elssubcontainer.style.display=='block')
				{
						elssubcontainer.style.display='none';
				}
			else
				{
						elssubcontainer.style.display='block';
				}
		}
}

function normal_catsub(x)
{
	elcatmare=locate_el('catsub_'+x);
	if(elcatmare!=catid_selectata)
		{
			elcatmare.style.backgroundColor='#ffffff';
		}
	else
		{
			elcatmare.style.backgroundColor='#AAC9D9';
		}
}
function hover_catsub(x)
{
	elcatmare=locate_el('catsub_'+x);
	elcatmare.style.backgroundColor='#dddddd';
}

function expand_menu_sub(x)
{
	if(catid_selectata)
		{
			catid_selectata.style.backgroundColor='#FFFFFF';
		}
		
	catidx=x;
	catid_selectata=locate_el('catsub_'+x);
	catid_selectata.style.backgroundColor='#AAC9D9';
	
	set_selected_category(x);
	
	elssubcontainer=locate_el('cat_mic_cont_'+x);
	if(elssubcontainer)
		{
			if(elssubcontainer.style.display=='block')
				{
						elssubcontainer.style.display='none';
				}
			else
				{
						elssubcontainer.style.display='block';
				}
		}
}

function normal_catmic(x)
{
	elcatmare=locate_el('catmic_'+x);
	if(elcatmare!=catid_selectata)
		{
			elcatmare.style.backgroundColor='#ffffff';
		}
	else
		{
			elcatmare.style.backgroundColor='#AAC9D9';
		}
}
function hover_catmic(x)
{
	elcatmare=locate_el('catmic_'+x);
	elcatmare.style.backgroundColor='#dddddd';
}

function expand_menu_mic(x)
{

	if(catid_selectata)
		{
			catid_selectata.style.backgroundColor='#FFFFFF';
		}
		
	catidx=x;
	catid_selectata=locate_el('catmic_'+x);
	catid_selectata.style.backgroundColor='#AAC9D9';
	
	set_selected_category(x);
}


/************************ AJAX: */


function arata_lista_categorii()
{
	el_ajax_box=locate_el('ajax_box');
	el_over_ajax_box=locate_el('over_ajax_box');
	
	el_ajax_box.style.display='block';
	el_over_ajax_box.style.display='block';
	
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	var url="actions/reqbox_categorii.php";
	url=url+"?sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		arata_lista_categorii_fill(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
	
	
}

function arata_lista_categorii_fill(XHT) 
{ 
if (XHT.readyState!=4)
{
	
	showajaxloaderdum('over_ajax_box');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	elbox=locate_el('over_ajax_box');
	elbox.innerHTML=response;
	addcat_inlist("");
}
}


function ascunde_lista_categorii()
{
	el_ajax_box=locate_el('ajax_box');
	el_over_ajax_box=locate_el('over_ajax_box');
	
	el_ajax_box.style.display='none';
	el_over_ajax_box.style.display='none';
	
	load_categorii_now_added();
}





function set_selected_category(x)
{
	elcategorii=locate_el('categorii_hidden');
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	if(!catidx)
		{
				catidx="";
		}
	var url="actions/set_selected_category.php";
	url=url+"?id="+catidx;
	url=url+"&categorii="+elcategorii.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		show_selected_category(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
}

function show_selected_category(XHT) 
{ 
if (XHT.readyState!=4)
{
	
	showajaxloaderdum('catboxsel');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	
	elbox=locate_el('catboxsel');
	elbox.innerHTML=response;
	
}
}



function addcat_inlist(x)
{
	elcategorii=locate_el('categorii_hidden');
	el_cat_group=locate_el('cat_group');
	
	
	if(el_cat_group)
		{
			var cat_group_ar=el_cat_group.value.split('.');
		}
	else
		{
			var cat_group_ar=new Array();
		}
	
	if(elcategorii.value=="")
		{
			var ids=new Array();
		}
	else
		{
			var ids=elcategorii.value.split('.');
		}
	
	newval=new Array();
	j=0;
	for(i=0; i<ids.length; i++)
		{
			if(!in_array(ids[i], cat_group_ar))
				{
					newval[j]=ids[i];
					j++;
				}
		}
	
	if(x!="")
		{
			newval[newval.length]=x.toString();
		}
	
	newval2=new Array();
	j=0;
	var baga=1;
	for(i=0; i<newval.length; i++)
		{
			baga=1;
			for(k=0; k<j; k++)
				{
					if(newval2[k]==newval[i])
						{
							baga=0;
						}
				}
			if(baga)
				{
					newval2[j]=newval[i];
					j++;
				}
		}
	
	elcategorii.value=newval2.join('.');
	
	
	
	var ids=elcategorii.value.split('.');
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="actions/addcat_inlist.php";
	url=url+"?categorii="+elcategorii.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		show_added_categories(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
}


function remcat_inlist(x)
{
	
	
	elcategorii=locate_el('categorii_hidden');
	
	if(elcategorii.value=="")
		{
			var ids=new Array();
		}
	else
		{
			var ids=elcategorii.value.split('.');
		}
	
	newval=new Array();
	j=0;
	for(i=0; i<ids.length; i++)
		{
			if(ids[i]!=x)
				{
					newval[j]=ids[i];
					j++;
				}
		}
	
	elcategorii.value=newval.join('.');
	
	
	
	var ids=elcategorii.value.split('.');
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="actions/addcat_inlist.php";
	url=url+"?categorii="+elcategorii.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		show_added_categories(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
}

function show_added_categories(XHT) 
{ 
if (XHT.readyState!=4)
{
	
	showajaxloaderdum('catboxadded');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	
	elbox=locate_el('catboxadded');
	elbox.innerHTML=response;
	if(catidx)
		{
			set_selected_category(catidx);
		}
	else
		{
			set_selected_category("");
		}
}
}

function load_categorii_now_added()
{
	elcategorii=locate_el('categorii_hidden');

	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="actions/load_categorii_now_added.php";
	url=url+"?categorii="+elcategorii.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		show_categorii_now_added(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);	
}

function show_categorii_now_added(XHT) 
{ 
if (XHT.readyState!=4)
{
	showajaxloaderdum('categorii_now_added');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	
	elbox=locate_el('categorii_now_added');
	elbox.innerHTML=response;
}
}








function load_categorii_advs()
{
	elcategorii=locate_el('categorii_hidden');

	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	 
	var url="actions/load_categorii_advs.php";
	url=url+"?categorii="+elcategorii.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		show_categorii_advs(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);	
}

function show_categorii_advs(XHT) 
{ 
if (XHT.readyState!=4)
{
	showajaxloaderdum('categorii_now_added');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	
	elbox=locate_el('categorii_now_added');
	elbox.innerHTML=response;
}
}


function arata_lista_categorii_advs()
{
	el_categorii_hidden=locate_el('categorii_hidden');
	
	
	hide_select_advs();
	
	
	el_ajax_box=locate_el('ajax_box');
	el_over_ajax_box=locate_el('over_ajax_box');
	
	el_ajax_box.style.display='block';
	el_over_ajax_box.style.display='block';
	
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	var url="actions/reqbox_categorii_advs.php";
	url=url+"?categorii_acum="+el_categorii_hidden.value;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		arata_lista_categorii_advs_fill(XHT);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
	
	
}

function arata_lista_categorii_advs_fill(XHT) 
{ 
if (XHT.readyState!=4)
{
	
	showajaxloaderdum('over_ajax_box');
}
if (XHT.readyState==4)
{
	response=XHT.responseText;
	elbox=locate_el('over_ajax_box');
	elbox.innerHTML=response;
}
}


function ascunde_lista_categorii_advs()
{
	el_ajax_box=locate_el('ajax_box');
	el_over_ajax_box=locate_el('over_ajax_box');
	
	
	show_select_advs();
	
	el_ajax_box.style.display='none';
	el_over_ajax_box.style.display='none';
	
	load_categorii_advs();
}


function show_subcats(el, catid)
{
	el_categorii_hidden=locate_el('categorii_hidden');
	if(el.checked)
		{
			lista_categorii=el_categorii_hidden.value.split(".");
			n=lista_categorii.length;
			gasit=0;
			for(i=0; i<n; i++)
				{
					if(lista_categorii[i]==catid)
						{
							gasit=1;
						}
				}
			if(!gasit)
				{
					if(el_categorii_hidden.value=="")
						{
							el_categorii_hidden.value=catid;
						}
					else
						{
							el_categorii_hidden.value=el_categorii_hidden.value+"."+catid;
						}
				}
		}
	else
		{
			lista_categorii=el_categorii_hidden.value.split(".");
			n=lista_categorii.length;
			el_categorii_hidden.value="";
			for(i=0; i<n; i++)
				{
					if(lista_categorii[i]!=catid)
						{
							if(el_categorii_hidden.value=="")
								{
									el_categorii_hidden.value=lista_categorii[i];
								}
							else
								{
									el_categorii_hidden.value=el_categorii_hidden.value+"."+lista_categorii[i];
								}
						}
				}
		}
}