/* t-pont kereso flash callback - - - - - - - - - - - - - - - - - - - - - - - */
function setRegion(regionID) {
    //alert("A meghívott régiókód: " + regionID);
    selectRegion(regionID);
}
/* t-pont kereso flash callback - - - - - - - - - - - - - - - - - - - - - - - */

matchCities = null;
selectNode = null;
selectedRegionID=null;

/**Select a a regio, and fill combobox with its cities*/
function selectRegion(regionID) {
    selectedRegionID = regionID;
    matchCities = cityHash.get(regionID);
    //convert TO DB numbering
    $('searchForm:selectedRegion').value=selectedRegionID+1;
    //deleted previous selection
    $('searchForm:selectedCity').value="";

    selectNode = document.getElementById("selectCityOption");

    var options = selectNode.getElementsByTagName('option');

    options = $A(options);

    setRegionOptions();

    displayCombo();

}

/**Display the combobox*/
 function displayCombo(){
     $('selectCityOption').setStyle({display: 'block'});
     $('searchForm:selectedCityOptionLabel').setStyle({display: 'block'});
 }
/**Set the selected city name*/
function  getSelectedElement(){
    var selectedIndex = $('selectCityOption').selectedIndex;
    var selectedElement = $('selectCityOption').options[selectedIndex];
//    alert(selectedElement.text);
    $('searchForm:selectedCity').value=selectedElement.text;

}

/**Fill combox with cities*/
 function setRegionOptions(){

 /** removes items */
 for(i = $('selectCityOption').options.length-1; i>=0;  i--){
      $('selectCityOption').options[i] = null;
   }

    /** builds new items  */
       for (i = 0; i < matchCities.length; i++) {
          var optn = document.createElement("OPTION");
	  var text = html_entity_decode(matchCities[i]);
          optn.value = text;
	  optn.text =  text;
	  //optn.setAttribute();
          $('selectCityOption').options.add(optn);
       }
     }

      function html_entity_decode(s) {
        var t = new Element('textarea',{'id':'temp'});
	t.innerHTML = s;
	var v = t.value;
	t = null;
	return v;
       }
