function build_selector_tari(def)
{
	var sel = document.getElementById("RCSTara");
	var ajax = new AjaxQuery();
	ajax.addEvent(	"loaded", 
					function(tari)
					{
						for(i in sel.options)
						{
							sel.remove(i);
						}
						var tari = tari.split("&");
						tari.pop();
						for(i in tari)
						{
							var o = document.createElement("option")
							var val = tari[i].split("=");
							sel.appendChild(o);
							o.value = val[0];
							o.text = val[1];
							if(def && RCDTara && RCDTara == val[0]) o.selected = true; 
						}
						build_selector_regiuni(def);
					}
				);
	sectiune = document.getElementById('RCSSection').value
	ajax.load("include/ajax_get_tari.php?s="+sectiune);
}
//------------------------------------------------------------------------------
function build_selector_regiuni(def)
{
	var tara_obj = document.getElementById("RCSTara");
	var sel = document.getElementById("RCSRegiune");
	if(tara_obj.options.length == 0)	
	{
		for(i in sel.options)
		{
			sel.remove(i);
		}
		build_selector_orase();
		return 0;
	}
	var tara = tara_obj.options[tara_obj.selectedIndex].value;
	
	var ajax = new AjaxQuery();
	ajax.addEvent(	"loaded", 
					function(regiuni)
					{
						for(i in sel.options)
						{
							sel.remove(i);
						}
						var regiuni = regiuni.split("&");
						regiuni.pop();
						for(i in regiuni)
						{
							o = document.createElement("option")
							var val = regiuni[i].split("=");
							sel.appendChild(o);
							o.value = val[0];
							o.text = val[1];		
							if(def && RCDRegiune && RCDRegiune == val[0]) o.selected = true; 
						}
						build_selector_orase(def);
					}
				);
	ajax.load("include/ajax_get_regiuni.php?id="+tara);
}
//------------------------------------------------------------------------------
function build_selector_orase(def)
{
	var regiune_obj = document.getElementById("RCSRegiune");
	var sel = document.getElementById("RCSOras");
	if(regiune_obj.options.length == 0) 
	{
		for(i in sel.options)
		{
			sel.remove(i);
		}
		return 0;
	}
	var regiune = regiune_obj.options[regiune_obj.selectedIndex].value;

	var ajax = new AjaxQuery();
	ajax.addEvent(	"loaded", 
					function(orase)
					{
						for(i in sel.options)
						{
							sel.remove(i);
						}
						var orase = orase.split("&");
						orase.pop();
						for(i in orase)
						{
							o = document.createElement("option")
							var val = orase[i].split("=");
							sel.appendChild(o);
							o.value = val[0];
							o.text = val[1];	
							if(def && RCDOras && RCDOras == val[0]) o.selected = true; 
						}
					}
				);
	ajax.load("include/ajax_get_orase.php?id="+regiune);
}
//----------------------------------------------
if(window.onload) 
{
	oldaction = window.onload;
	window.onload = function()
	{
		oldaction();
		if(RCDSectiune)
		{
			RCSectiune = document.getElementById("RCSSection");
			for(i=0; i<RCSectiune.options.length; i++)
			{
				if(RCSectiune.options[i].value == RCDSectiune) RCSectiune.options[i].selected = true;
			}
		}
		build_selector_tari(true);
	}
}
