<!--

function get_subs(obj, level)
{
   var pid = document.getElementById("catlist");
   childs_length = pid.childNodes.length;
   this.level = parseInt(level);
   for(i=childs_length; i>this.level; i--)
   {
       var x = document.getElementById("divbox"+i);
       if(x)
	pid.removeChild(x);
   }
   this.level++;
   var curdiv = document.createElement("div");
   curdiv.id = "divbox"+this.level;
   pid.appendChild(curdiv);
   document.getElementById("sp"+level).innerHTML="поиск подкатегорий...";
   makeRequest(obj, this.level);

}

function makeRequest(obj, level) {

        var http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

	//определяет функцию для обработки события onchange
        http_request.onreadystatechange = function() { change_sub(http_request, obj, level); };
        url = '/get_categories.php?id='+obj.value
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function change_sub(http_request, obj, level) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
		str_resp = http_request.responseText;
  		if(str_resp != '')
                         {
		
 		//разделяет строку, полученную от ajax_combo_resp.php
		//ввиде id=name;id=name;...‚ на id=name для каждого элемента массива
		   arr_val_txt = str_resp.split(";");
		//определяет массивы arr_val‚ arr_txt для хранения 
		//id и name соотв.
		   var arr_val = new Array();
		   var arr_txt = new Array();
		   for(k=0; k<arr_val_txt.length; k++)
		   {
		       arr_q = arr_val_txt[k].split("=");
		       arr_val[k] = arr_q[0];
		       arr_txt[k] = arr_q[1];
		   }
		    
		   str_select = '<select id="cat'+level+'" name="cats[]" onchange="get_subs(this, '+level+')"><option value="0">выберите подкатегорию</option>';		   
                             for(k=0; k<arr_val.length; k++)
  		   {
		       str_select += '<option value="'+arr_val[k]+'">'+arr_txt[k]+'</option>';
		   }  
		   str_select += '</select> <span id="sp'+level+'"></span><br /><br />';
		   document.getElementById("divbox"+level).innerHTML = str_select;
		   document.getElementById("sp"+(parseInt(level)-1)).innerHTML = "";
		}
		else
		{
		     document.getElementById("catlist").removeChild(document.getElementById("divbox"+level));
		     document.getElementById("sp"+(parseInt(level)-1)).innerHTML = "";
		}


                
            } else {
                alert('There was a problem with the request.');
            }
        }

}


//--> 

