function changeSubCategories(elem, id, id2, url)
{
	var sel_val = elem.value;
	url = url + sel_val;
	request(url, id, id2, 'changeSubCategories');
}

function request(url, id, id2, action)
{
	var http_request;

	if (window.XMLHttpRequest)
	{ // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();
        
        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
	}
	else
	{
        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;
    }
	
	http_request.onreadystatechange = function() { onReadyStateChange(http_request, id, id2, action); };

	http_request.open('GET', url, true);
	http_request.send(null);
}

function onReadyStateChange(http_request, id, id2, action)
{
	var result;

    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
        	if(action == 'del') 
        	{
				document.getElementById('msg_cell').innerHTML = http_request.responseText;
			}
			else if(action == 'changeSubCategories')
			{
				result = http_request.responseXML;
				elems = result.getElementsByTagName("subCategoriesList").item(0).getElementsByTagName('subCategory');
				container = document.getElementById(id);
				container.innerHTML = '';
				
				if(elems.length > 1)
				{
					document.getElementById(id2).style.visibility = 'visible';

					for(var i = 0; i < elems.length; i++)
					{
						option = document.createElement('option');
						option.value = elems.item(i).getElementsByTagName('id').item(0).firstChild.data;
						option.innerHTML = elems.item(i).getElementsByTagName('name').item(0).firstChild.data;
						container.appendChild(option);
					}
				}
				else
				{
					document.getElementById(id2).style.visibility = 'hidden';
				}
			}
        }
        else
        {
            alert('There was a problem with the request.');
        }
    }
}
