function getXmlHttp()
  {
  var xmlHttp;
  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)
        {
        xmlHttp=0;
        }
      }
    }
	
	return xmlHttp;
}

/**********************/
//zobrazime kraje
/**********************/
function showKraje(stat,selected,label,nezalezi){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('kraje').innerHTML=xmlHttp.responseText;
		showOkresy(document.getElementById('kraj').value,-1,-1,label,nezalezi);
      }
    }

	xmlHttp.open("GET","ajax.php?class=getKraje&stat="+stat+"&sel="+selected+"&label="+label+"&nezalezi="+nezalezi,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime kraje
/**********************/
function showKrajeTrendy(stat,num){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('kraje'+num).innerHTML=xmlHttp.responseText;
      }
    }
	
	showOkresyTrendy(-1,num);
	xmlHttp.open("GET","ajax.php?class=getKrajeTrendy&stat="+stat+"&num="+num,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime okresy
/**********************/
function showOkresy(kraj,selected,obec,label,nezalezi){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('okresy').innerHTML=xmlHttp.responseText;
		showObce(document.getElementById('okres').value,-1,label,nezalezi);
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=getOkresy&kraj="+kraj+"&sel="+selected+"&obec="+obec+"&label="+label+"&nezalezi="+nezalezi,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime okresy
/**********************/
function showOkresyTrendy(kraj,num){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('okresy'+num).innerHTML=xmlHttp.responseText;
      }
    }
	
	showObceTrendy(-1,num);
	xmlHttp.open("GET","ajax.php?class=getOkresyTrendy&kraj="+kraj+"&num="+num,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime okresy
/**********************/
function showOkresyByStat(stat,selected){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('okresy').innerHTML=xmlHttp.responseText;
      }
    }
	xmlHttp.open("GET","ajax.php?class=getOkresy&stat="+stat+"&sel="+selected,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime obce
/**********************/
function showObce(okres,selected,label,nezalezi){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('obce').innerHTML=xmlHttp.responseText;
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=getObce&okres="+okres+"&sel="+selected+"&label="+label+"&nezalezi="+nezalezi,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime obce
/**********************/
function showObceTrendy(okres,num){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('obce'+num).innerHTML=xmlHttp.responseText;
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=getObceTrendy&okres="+okres+"&num="+num,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime top lokality
/**********************/
function showTopLokality(){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('topLok').innerHTML=xmlHttp.responseText;
      }
    }
	xmlHttp.open("GET","ajax.php?class=topLokality&tp="+document.getElementById('tp').value+"&pon="+document.getElementById('pon').value,true);
	xmlHttp.send(null);
	
}

/**********************/
//zobrazime parametre pri vyhladavani pre konkretny typ nehutelnosti
/**********************/
function showTypNehnutelnostiParam(selectedTyp,index){
		
	var xmlHttp=getXmlHttp();
	
	if(document.getElementById('tagsInput')){
		document.getElementById('tagsInput').value='';
	}
	
	if(document.getElementById('vybavenieSearchDiv')){
		document.getElementById('vybavenieSearchDiv').innerHTML='';
	}
	
	if(index==1){
		//pre index.php
		/**************/
		xmlHttp.onreadystatechange=function(){
		  if(xmlHttp.readyState==4){
			document.getElementById('typNehnutelnostiParams').innerHTML=xmlHttp.responseText;
		  }
		}
		xmlHttp.open("GET","ajax.php?class=typNehnutelnostiParam&index=1&tp="+selectedTyp.options[selectedTyp.selectedIndex].value,true);
	}else{
		//pre ine file-y
		/***************/
		showTypNehnutelnostiParamPopis(selectedTyp);
				
		xmlHttp.onreadystatechange=function(){
		  if(xmlHttp.readyState==4){
			document.getElementById('typNehnutelnostiParams').innerHTML=xmlHttp.responseText;
			
		  }
		}
		xmlHttp.open("GET","ajax.php?class=typNehnutelnostiParam&index=0&what=agent&tp="+selectedTyp.options[selectedTyp.selectedIndex].value,true);
	}
	
	
	xmlHttp.send(null);
	
}

function showTypNehnutelnostiParamPopis(selectedTyp){
	
	var xmlHttp=getXmlHttp();
	
	//pre ine file-y
	/***************/
	xmlHttp.onreadystatechange=function(){
	  if(xmlHttp.readyState==4){
		document.getElementById('param_desc_div').innerHTML=xmlHttp.responseText;
	  }
	}
	xmlHttp.open("GET","ajax.php?class=typNehnutelnostiParam&index=0&what=par_desc&tp="+selectedTyp.options[selectedTyp.selectedIndex].value,true);
	
	xmlHttp.send(null);
	
}

/**********************/
//pridame hlas RK a obnovime status
/**********************/
function podpor(rk){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('podporValue').innerHTML=xmlHttp.responseText;
		document.getElementById('podporDiv').style.cursor="default";
		document.getElementById('podporDiv').style.backgroundImage="url(img/podporene.jpg)";
		document.getElementById('podporDiv').onclick="";
      }
    }
	xmlHttp.open("GET","ajax.php?class=podpor&rk="+rk,true);
	xmlHttp.send(null);
	
}

/**********************/
//vytvorime select pre mestsku cast
/**********************/
function showStvrt(town,stvrt){
	
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('stvrtDiv').innerHTML=xmlHttp.responseText;
		if(document.getElementById('stvrtDiv').innerHTML=='&nbsp;' || document.getElementById('stvrtDiv').innerHTML.length==1){
			document.getElementById('obecDiv').style.display="block";
		}else{
			document.getElementById('obecDiv').style.display="none";
		}
      }
    }
	
	
	xmlHttp.open("GET","ajax.php?class=getStvrt&twn="+town.value+"&selected="+stvrt,true);
	xmlHttp.send(null);
	
}

/**********************/
//vytvorime select pre sub kategoriu nehnutelnosti
/**********************/
function changeDruhNehn(typ,druh,energie,izieb,rozloha,poschodie,material,stav,err_energie,err_izieb,err_rozloha,err_posch,err_material){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('podDruhDiv').innerHTML=xmlHttp.responseText;
      }
    }
	
	var arr=typ.split("_");
	var pos=poschodie.split("/");
	
	if(!pos[1]){
		pos[1]="";	
	}

xmlHttp.open("GET","ajax.php?class=getDruhSubCat&ponukam="+arr[0]+"&typ="+arr[1]+"&druh="+druh.value+"&energie="+energie+"&izieb="+izieb+"&rozloha="+rozloha+"&poschodie="+pos[0]+"&poschodie_celkom="+pos[1]+"&material="+material+"&stav="+stav+"&err_izieb="+err_izieb+"&err_rozloha="+err_rozloha+"&err_poschodie="+err_posch+"&err_material="+err_material,true);
	xmlHttp.send(null);
	
}

function changeDruhyNehnutelnosti(typ){
	
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('druhNehnDiv').innerHTML=xmlHttp.responseText;
      }
    }
	
	var arr=typ.split("_");

	xmlHttp.open("GET","ajax.php?class=changeDruhySelect&typ="+arr[1],true);
	xmlHttp.send(null);
	
}

/**********************/
//vytvorime select pre sub kategoriu nehnutelnosti
/**********************/
function showVybavenieTags(druh){
	var xmlHttp=getXmlHttp();
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('loginForm5').innerHTML=xmlHttp.responseText;
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=getVybavenieByDruh&druh="+druh.value,true);
	xmlHttp.send(null);
	
}

/**********************/
//vytvorime select pre pridavanie tagov vo vyhladavani
/**********************/
function showAddTagsSelect(){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('tags').innerHTML=xmlHttp.responseText;
      }
    }
	xmlHttp.open("GET","ajax.php?class=getSearchTagsCombo&typNehnutelnosti="+document.getElementById('typNehnutelnosti').value+"&tagsInput="+document.getElementById('tagsInput').value,true);
	xmlHttp.send(null);
	
}

/**********************/
//vytvorime select pre pridavanie tagov vo vyhladavani
/**********************/
function addTag(id){
	
	if(id.value!=-1){
		
		var xmlHttp=getXmlHttp();
		
		xmlHttp.onreadystatechange=function(){
		  if(xmlHttp.readyState==4){
			var tags=document.getElementById('vybavenieSearchDiv').innerHTML;
			var preHeight=parseInt(document.getElementById('vybavenieSearchDiv').style.height);
			
			if(tags.length==0){
				document.getElementById('vybavenieSearchDiv').innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById('vybavenieSearchDiv').innerHTML=tags+'  '+xmlHttp.responseText;	
			}
			
			document.getElementById('searchBox').style.height=parseInt(document.getElementById('searchBox').style.height)+parseInt(document.getElementById('vybavenieSearchDiv').style.height)-preHeight;
		  }
		}
		
		xmlHttp.open("GET","ajax.php?class=addTag&tag="+id.value,true);
		xmlHttp.send(null);
		
		var tagsInput=document.getElementById('tagsInput').value;
		
		document.getElementById('tagsInput').value=tagsInput+id.value+',';
	
		
		var sel=id.selectedIndex;
		
		id.remove(sel);
		id.selectedIndex=0;
		
		document.getElementById('advanced').value="1";
		
	}
}

/**********************/
//vytvorime select pre pridavanie tagov vo vyhladavani
/**********************/
function addTagInDetail(id){
	
	if(id.value!=-1){
		
		var xmlHttp=getXmlHttp();
		
		xmlHttp.onreadystatechange=function(){
		  if(xmlHttp.readyState==4){
			var tags=document.getElementById('vybavenieSearchDiv').innerHTML;
			
			if(tags.length==0){
				document.getElementById('vybavenieSearchDiv').innerHTML=xmlHttp.responseText;
			}else{
				document.getElementById('vybavenieSearchDiv').innerHTML=tags+'  '+xmlHttp.responseText;	
			}
			
		  }
		}
		
		xmlHttp.open("GET","ajax.php?class=addTag&tag="+id.value,true);
		xmlHttp.send(null);
		
		var tagsInput=document.getElementById('tagsInput').value;
		
		document.getElementById('tagsInput').value=tagsInput+id.value+',';
	
		
		var sel=id.selectedIndex;
		
		id.remove(sel);
		id.selectedIndex=0;
				
	}
}

/**********************/
//naplnime zoznam hladanych tagov
/**********************/
function addTagFromGet(value){

	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	var tags=document.getElementById('vybavenieSearchDiv').innerHTML;

		if(tags.length==0){
			document.getElementById('vybavenieSearchDiv').innerHTML=xmlHttp.responseText;
		}else{
			document.getElementById('vybavenieSearchDiv').innerHTML=tags+'  '+xmlHttp.responseText;	
		}
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=addTag&tag="+value,true);
	xmlHttp.send(null);
	
	document.getElementById('advanced').value="1";
	
	refreshAutocompleterParamsValues();
	
}

/**********************/
//naplnime zoznam hladanych tagov
/**********************/
function addTagFromGetDetail(value){
	
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	var tags=document.getElementById('vybavenieSearchDiv').innerHTML;

		if(tags.length==0){
			document.getElementById('vybavenieSearchDiv').innerHTML=xmlHttp.responseText;
		}else{
			document.getElementById('vybavenieSearchDiv').innerHTML=tags+'  '+xmlHttp.responseText;	
		}
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=addTag&tag="+value,true);
	xmlHttp.send(null);
	
	if(document.getElementById('tagsInput').value.length>0){
		document.getElementById('tagsInput').value=document.getElementById('tagsInput').value+','+value;
	}else{
		document.getElementById('tagsInput').value=value;	
	}
	
	
}

/******************************/
// zobrazime total cenu za objednavku
/******************************/
function showCena(value,get,usr){
	
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('totalCost').innerHTML=xmlHttp.responseText;
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=totalCost&months="+value.value+"&new="+get+"&usr="+usr,true);
	xmlHttp.send(null);
	
}

/******************************/
// zobrazime typ ceny o vyhladavani
/******************************/
function changeDruhCeny(typ,cat,selected){

	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('druhCeny').innerHTML=xmlHttp.responseText;
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=getDruhCeny&typ="+typ+"&cat="+cat.value+"&selected="+selected,true);
	xmlHttp.send(null);
	
}

/******************************/
// zmenime stat
/******************************/
function setStat(stat,label,nezalezi){

	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('staty_container').innerHTML=xmlHttp.responseText;
		
		showKraje(stat,-1,label,nezalezi);
		document.getElementById('stat').value=stat;
		
		refreshAutocompleterParamsValues();
		
      }
    }
	
	xmlHttp.open("GET","ajax.php?class=setStat&stat="+stat+"&nezalezi="+nezalezi,true);
	xmlHttp.send(null);

	
}

/**********************/
// vlozime do mojho vyberu
/**********************/
function addToMojVyber(id,text,cena,linka){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('moj_vyber').innerHTML=xmlHttp.responseText;
      }
    }

	xmlHttp.open("GET","ajax.php?class=addToMojVyber&id="+id+"&text="+text+"&cena="+cena+"&link="+linka,true);
	xmlHttp.send(null);
	
}

/**********************/
// vlozime do mojho vyberu
/**********************/
function remFromMojVyber(id){
	var xmlHttp=getXmlHttp();
	
	xmlHttp.onreadystatechange=function(){
      if(xmlHttp.readyState==4){
	  	document.getElementById('moj_vyber').innerHTML=xmlHttp.responseText;
      }
    }
	
	Effect.toggle(id,'blind',{duration:0.4});
	xmlHttp.open("GET","ajax.php?class=remFromMojVyber&id="+id,true);
	xmlHttp.send(null);
	
}