/* Ziskat prehled regionu pro dany kraj */
function akpGetRegion(urlmodul){
   var url = urlmodul;
   var timeStamp = "casotisk=" + new Date().getTime();
   var urlPost = url + '?' + timeStamp;
   var postData = 'idcountry=' + $('id_country_h').get('value') + '&idregion=' + $('id_region_h').get('value') + '&idcity=' + $('id_city_h').get('value');

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

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

   // Info box
   ShowAppBox.showBox($('app_work'));

   var myAjax = new Request({method: 'post', url: urlPost,data:postData,onComplete: resultAkpGetRegion}).send();
}
/* Zachytit pozadavek */
function resultAkpGetRegion(){
   //alert(this.response.text);
   workAkpGetRegion(this.response.xml);
}
/* Zpracovat pozadavek */
function workAkpGetRegion(xmlDoc){
   // Info box
   ShowAppBox.showBox($('app_work'));

   // Indikace zda jsou regiony
   var isRegion = xmlDoc.getElementsByTagName("isregion")[0].firstChild.data;
   // Url
   var url = xmlDoc.getElementsByTagName("url")[0].firstChild.data;

   // Nastavit url formulari
   $('akp_form').setProperty('action',url);

   // Smazat select mest
   removeElement('id_city_h');

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

   // Vytvorit select
   var items = xmlDoc.getElementsByTagName('region');
   akceBuildSelect('id_region_h',items,'idreg');

}

/* Ziskat prehled mest pro dany region */
function akpGetCity(urlmodul){
   var url = urlmodul;
   var timeStamp = "casotisk=" + new Date().getTime();
   var urlPost = url + '?' + timeStamp;
   var postData = 'idcountry=' + $('id_country_h').get('value') + '&idregion=' + $('id_region_h').get('value') + '&idcity=' + $('id_city_h').get('value');

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

   var myAjax = new Request({method: 'post', url: urlPost,data:postData,onComplete: resultAkpGetCity}).send();
}
/* Zachytit pozadavek */
function resultAkpGetCity(){
   //alert(this.response.text);
   workAkpGetCity(this.response.xml);
}
/* Zpracovat pozadavek */
function workAkpGetCity(xmlDoc){
   // Indikace zda jsou regiony
   var isCity = xmlDoc.getElementsByTagName("iscity")[0].firstChild.data;
   // Url
   var url = xmlDoc.getElementsByTagName("url")[0].firstChild.data;

   // Nastavit url formulari
   $('akp_form').setProperty('action',url);

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

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

/* Vytvorit polozky selectu */
function akceBuildSelect(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);
   }
}

/* Ziskat prehled mest pro dany region */
function akpGetCityUrl(urlmodul){
   var url = urlmodul;
   var timeStamp = "casotisk=" + new Date().getTime();
   var urlPost = url + '?' + timeStamp;
   var postData = 'idcountry=' + $('id_country_h').get('value') + '&idregion=' + $('id_region_h').get('value') + '&idcity=' + $('id_city_h').get('value');

   var myAjax = new Request({method: 'post', url: urlPost,data:postData,onComplete: resultAkpGetCityUrl}).send();
}
/* Zachytit pozadavek */
function resultAkpGetCityUrl(){
   //alert(this.response.text);
   workAkpGetCityUrl(this.response.xml);
}
/* Zpracovat pozadavek */
function workAkpGetCityUrl(xmlDoc){
   // Url
   var url = xmlDoc.getElementsByTagName("url")[0].firstChild.data;

   // Nastavit url formulari
   $('akp_form').setProperty('action',url);
}

/* Opsat text */
function akpSetDate(){
   var date = $('datum_od_h').get('value');
   $('datum_do_h').setProperty('value',date);
}