var mapid = "";

function CompanyResultList_Click()
{
	document.getElementById("infosection").innerHTML += "<div style='font-weight: bold; display: block; position: relative; margin-top: 10px; color: #666666' onClick='javascript: ComboChanged(\"cat3\");'><span style='cursor: pointer;'>Vissza a találatokhoz</span></div>";		
}

function ListItemSelected(id, pack)
{
	GetRemoteContentCompany("infosection", "infosection", "", "inforet.php", "id=" + id + "&pack=" + pack, "CompanyResultList_Click();");
}

function ComboChanged(comboname)
{
	var id = 0;
	var pack = -1;
	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&visibilityfilter=1&visibilitytable=creg_cats&visibilityfield=creg_cat__visible&visibilitylink1=creg_cat__id&visibilitylink2=creg_cat__id");
			}
			//GetRemoteContentCompany("resultsection", "resultcombo", "", "cmbret.php", "cmbid=resultcombo&parentid=" + comboValue + "&table=cregs&childfield=CONCAT(creg__id, ';', creg__pack)&childfieldalias=idpluspack&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&mapid=" + mapid);
		}
		RunSynchronized ("egykatbetolt(\"-1\")", "$(\"motor\")", 500, 20);
	} 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&visibilityfilter=1&visibilitytable=creg_cats&visibilityfield=creg_cat__visible&visibilitylink1=creg_cat__id&visibilitylink2=creg_cat__id");
			}
		} 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=CONCAT(creg__id, ';', creg__pack)&childfieldalias=idpluspack&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&mapid=" + mapid);
		egykatbetolt("-1");
	} 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;
		id = comboValue;
		/*if (selIndex == 0) {
			selIndex = document.getElementById("cat2").selectedIndex;
			comboValue = document.getElementById("cat2").options[selIndex].value;
		}*/
		if (selIndex != "0")
		{
			GetRemoteContentCompany("infosection", "infosection", "", "lstret.php", "id=" + id + "&parentid=" + comboValue + "&table=cregs&childfield=creg__id&parentfield=creg__cat_id&displayfield=creg__name&orderfield=creg__name&morefields=,creg__pack");
		} else {
			egykatbetolt("-1");
		}
		//GetRemoteContentCompany("resultsection", "resultcombo", "", "cmbret.php", "cmbid=resultcombo&parentid=" + comboValue + "&table=cregs&childfield=CONCAT(creg__id, ';', creg__pack)&childfieldalias=idpluspack&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') {
			comboValueArr = comboValue.split(";");
			var id = comboValueArr[0];
			var pack = comboValueArr[1];
			GetRemoteContentCompany("infosection", "infosection", "", "inforet.php", "id=" + id + "&pack=" + pack);
		}
	}*/
}
  
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, customfn)
{
	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) {
				//alert("blő!" + myelement_id + xmlHttp.responseText);
				if ((myelement_id == "cnameinfosection") || (myelement_id == "infosection")) {
					var responseTextFields = xmlHttp.responseText.split("~");
					var myid = responseTextFields[0];
					var mypack = responseTextFields[1];
					var mydata = responseTextFields[2];
					
					switch (mypack) 
					{
						case "0":
							RunSynchronized ("egycegbetolt('" + myid + "')", "$('motor')", 500, 20);
							break;
						case "1":
							RunSynchronized ("egycegbetolt('" + myid + "')", "$('motor')", 500, 20);
							break;
						case "2":
							RunSynchronized ("egylogobetolt('" + myid + "')", "$('motor')", 500, 20);
							break;
						case "999":
							RunSynchronized ("egykatbetolt('" + myid + "')", "$('motor')", 500, 20);
					}
					myelement.innerHTML = mydata;
				} else {
					myelement.innerHTML = xmlHttp.responseText;
				}
				
				if (customfn != null) {
					eval(customfn);
				}
				
				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;
	GetRemoteContentCompany("catsection1", "cat1", "", "cmbret.php", "cmbid=cat1&parentid=0&table=creg_cats&childfield=creg_cat__id&parentfield=creg_cat__parent&displayfield=creg_cat__name&orderfield=creg_cat__name&visibilityfilter=1&visibilitytable=creg_cats&visibilityfield=creg_cat__visible&visibilitylink1=creg_cat__id&visibilitylink2=creg_cat__id");
}

