var mapid = "";
function ComboChanged(comboname)
{
	if (comboname == "cat1") {
		document.getElementById("cat2").options.length = 0;
		document.getElementById("cat3").options.length = 0;
		document.getElementById("resultcombo").options.length = 0;
		document.getElementById("cat2").disabled = true;
		document.getElementById("cat3").disabled = true;
		document.getElementById("resultcombo").disabled = true;
		document.getElementById("infosection").innerHTML = "";
		if (document.getElementById("cat1").selectedIndex >= 1) {
			selIndex = document.getElementById("cat1").selectedIndex;
			comboValue = document.getElementById("cat1").options[selIndex].value;
			if (comboValue > 0) {
				GetRemoteContentCompany("catsection2", "cat2", "", "cmbret.php", "cmbid=cat2&parentid=" + comboValue + "&table=creg_cats&childfield=creg_cat__id&parentfield=creg_cat__parent&displayfield=creg_cat__name&orderfield=creg_cat__name");
			}
			GetRemoteContentCompany("resultsection", "resultcombo", "", "cmbret.php", "cmbid=resultcombo&parentid=" + comboValue + "&table=cregs&childfield=creg__id&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&mapid=" + mapid);
		}
	} else if (comboname == "cat2") {
		document.getElementById("cat3").options.length = 0; 
		document.getElementById("cat3").disabled = true;
		document.getElementById("resultcombo").options.length = 0;
		document.getElementById("resultcombo").disabled = true;
		document.getElementById("infosection").innerHTML = "";
		if (document.getElementById("cat2").selectedIndex >= 1) {
			selIndex = document.getElementById("cat2").selectedIndex;
			comboValue = document.getElementById("cat2").options[selIndex].value;
			if (comboValue > 0) {
				GetRemoteContentCompany("catsection3", "cat3", "", "cmbret.php", "cmbid=cat3&parentid=" + comboValue + "&table=creg_cats&childfield=creg_cat__id&parentfield=creg_cat__parent&displayfield=creg_cat__name&orderfield=creg_cat__name");
			}
		} else {
			selIndex = document.getElementById("cat1").selectedIndex;
			comboValue = document.getElementById("cat1").options[selIndex].value;
		}
		GetRemoteContentCompany("resultsection", "resultcombo", "", "cmbret.php", "cmbid=resultcombo&parentid=" + comboValue + "&table=cregs&childfield=creg__id&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&mapid=" + mapid);
	} else if (comboname == "cat3") {
		document.getElementById("resultcombo").options.length = 0;
		document.getElementById("resultcombo").disabled = true;
		document.getElementById("infosection").innerHTML = "";
		selIndex = document.getElementById("cat3").selectedIndex;
		comboValue = document.getElementById("cat3").options[selIndex].value;
		if (selIndex == 0) {
			selIndex = document.getElementById("cat2").selectedIndex;
			comboValue = document.getElementById("cat2").options[selIndex].value;
		}
		GetRemoteContentCompany("resultsection", "resultcombo", "", "cmbret.php", "cmbid=resultcombo&parentid=" + comboValue + "&table=cregs&childfield=creg__id&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&mapid=" + mapid);
	} else if (comboname == "resultcombo") {
		document.getElementById("infosection").innerHTML = "";
		selIndex = document.getElementById("resultcombo").selectedIndex;
		comboValue = document.getElementById("resultcombo").options[selIndex].value;
		if (comboValue > 0) {
			GetRemoteContentCompany("infosection", "infosection", "", "inforet.php", "id=" + comboValue);
		}
	}
}
  
function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

function GetRemoteContentCompany(myelement_id, mysubelement_id, mysubelement2_id, myurl, params)
{
	var xmlHttp;
	var myelement = document.getElementById(myelement_id);
	try
    {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
  	catch (e)
    {    
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch (e)
      	{
			try
        	{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
      		catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
			if (xmlHttp.responseText.length > 0) {
				myelement.innerHTML = xmlHttp.responseText;
				var mysubelement = document.getElementById(mysubelement_id);
				if (mysubelement.length > 1) {
					mysubelement.disabled=false;
					if (mysubelement2_id != "") {
						var mysubelement2 = document.getElementById(mysubelement2_id);
					}
				} else {
					if (mysubelement.options != null) {
						mysubelement.options.length = 0;
						mysubelement.disabled=true;
					}
				}
			}
		}
      }
	xmlHttp.open("POST", myurl, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);  
}

function initCatSelectorComponent()
{
	document.getElementById("resultcombo").disabled = true;
	document.getElementById("cat1").selected = "0";
	document.getElementById("cat2").options.length = 0;
	document.getElementById("cat2").disabled = true;
	document.getElementById("cat3").options.length = 0;
	document.getElementById("cat3").disabled = true;
}

