/* Ziskat prehled regionu pro dany kraj */
function rnjGetRegion(urlmodul,idel){
   var url = urlmodul;
   var timeStamp = "casotisk=" + new Date().getTime();
   var urlPost = url + '?' + timeStamp;
   var postData = 'id=' + $(idel).getValue();

   // Disable select
   $('id_region').setProperty('disabled','disabled');

   var myAjax = new Ajax(urlPost, {method: 'post',postBody: postData,onComplete: resultRnjGetRegion }).request();
}
/* Zachytit pozadavek */
function resultRnjGetRegion(){
   //alert(this.response.text);
   workRnjGetRegion(this.response.xml);
}
/* Zpracovat pozadavek */
function workRnjGetRegion(xmlDoc){
   // Indikace zda jsou regiony
   var isRegion = xmlDoc.getElementsByTagName("isregion")[0].firstChild.data;

   // Enable select
   if(isRegion == 1) $('id_region').removeProperty('disabled');
   // Smazat select
   removeElement('id_region');

   // Vytvorit select
   var items = xmlDoc.getElementsByTagName('region');
   rnjBuildSelect('id_region',items,'idreg');
}

/* Ziskat prehled mest pro dany region */
function rnjGetCity(urlmodul,idel){
   var url = urlmodul;
   var timeStamp = "casotisk=" + new Date().getTime();
   var urlPost = url + '?' + timeStamp;
   var postData = 'id=' + $(idel).getValue();

   // Disable select
   $('id_city').setProperty('disabled','disabled');

   var myAjax = new Ajax(urlPost, {method: 'post',postBody: postData,onComplete: resultRnjGetCity }).request();
}
/* Zachytit pozadavek */
function resultRnjGetCity(){
   //alert(this.response.text);
   workRnjGetCity(this.response.xml);
}
/* Zpracovat pozadavek */
function workRnjGetCity(xmlDoc){
   // Indikace zda jsou regiony
   var isCity = xmlDoc.getElementsByTagName("iscity")[0].firstChild.data;

   // Enable select
   if(isCity == 1) $('id_city').removeProperty('disabled');
   // Smazat select
   removeElement('id_city');

   // Vytvorit select
   var items = xmlDoc.getElementsByTagName('city');
   rnjBuildSelect('id_city',items,'idcity');
}

/* Vytvorit polozky selectu */
function rnjBuildSelect(elementSelect,elementItem,idprefix){
   //projit polozky
   for(var i=0;i < elementItem.length;i++){
      var nameItem = getContent(getElByName(elementItem[i], 'name')[0]);
      var idItem = getContent(getElByName(elementItem[i], 'id')[0]);

      option = document.createElement("option");
      option.appendChild(document.createTextNode(nameItem));
      option.setAttribute("value",idItem);
      option.setAttribute("id",idprefix+idItem);
      //pridat option do selectu
      //var selectmark = document.getElementById(elementSelect);
      $(elementSelect).appendChild(option);
   }
}
/* Nastavit mesto */
function rnjSetCity(idel,idprefix){
   var regId = $(idel).getValue();
   if(regId != 0){
      var regText = $(idprefix+regId).getText();
      $('id_mesto').setProperty('value',regText);
   }
}
/* Nastavit aktivni polozku selectu */
function rnjSetSelAct(idel){
   $(idel).setProperty('selected','selected');
}