var Pocasi = {

   predpovedAktivni: 1,
   center: 1,

   zalozkaTop: function () {
      $('pzk-telo-top').style.display = 'block';
      $('pzk-telo-vse').style.display = 'none';
      $('pzk-zalozka-top').className = 'pkz-top-a';
      $('pzk-zalozka-vse').className = 'pkz-top-n';
   },
   
   zalozkaVse: function () {
      $('pzk-telo-top').style.display = 'none';
      $('pzk-telo-vse').style.display = 'block';
      $('pzk-zalozka-top').className = 'pkz-top-n';
      $('pzk-zalozka-vse').className = 'pkz-top-a';
   },
   
   pristup: function (typ, id) {
      var myAjax = new Ajax.Request(
         '/ajax/',
         {
            parameters: 'func=pocasiPristup&typ=' + typ + '&id=' + id,
            onComplete: function (r) {
            }
         }
      );
	},

   menuZobraz: function (id, stav) {
      if (stav == 1) {
         $('mkia' + id).style.display = 'none';
         $('mkin' + id).style.display = 'inline';
         $('mkc' + id).style.display = 'none';
		} else if (stav == 2) {
         $('mkin' + id).style.display = 'none';
         $('mkia' + id).style.display = 'inline';
         $('mkc' + id).style.display = 'block';
		}
   },

   predpovedOver: function (id) {
		for (i = 0; i <= 9; i++) {
		   if($('pr-top-' + i) != null) {
			   if (id == i) {
	            $('pr-top-' + i).style.display = 'block';
	            $('pr-obs-' + i).style.display = 'block';
				} else {
	            $('pr-top-' + i).style.display = 'none';
	            $('pr-obs-' + i).style.display = 'none';
				}
			}
		}
	},

   predpovedOut: function (id) {
		for (i = 0; i <= 9; i++) {
		   if($('pr-top-' + i) != null) {
			   if (Pocasi.predpovedAktivni == i) {
	            $('pr-top-' + i).style.display = 'block';
	            $('pr-obs-' + i).style.display = 'block';
				} else {
	            $('pr-top-' + i).style.display = 'none';
	            $('pr-obs-' + i).style.display = 'none';
				}
			}
		}
	},

   predpovedClick: function (id) {
      tmp = id - Pocasi.center;
      Pocasi.predpovedOver(id);
      Pocasi.predpovedAktivni = id;
      var max = parseInt($('predpoved-pocet').innerHTML);
		for (i = 0; i <= 9; i++) {
		   if($('pr-zal-' + i) != null) {
		      if (tmp == -1) {
               if (i == id) {
	            	$('pr-zal-' + i).className = 'pop-top-z-la';
					} else if (i == (id + 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-r';
					} else if (i == (id + 2)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-rn';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
				} else if (tmp == 0) {
               if (i == (id - 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-l';
					} else if (i == id) {
	            	$('pr-zal-' + i).className = 'pop-top-z-c';
					} else if (i == (id + 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-r';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
				} else if (tmp == 1) {
               if (i == (id - 2)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-rn';
					} else if (i == (id - 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-l';
					} else if (i == id) {
	            	$('pr-zal-' + i).className = 'pop-top-z-ra';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
				}
			}
		}
	},
	
   predpovedPosun: function (kam) {
      var max = parseInt($('predpoved-pocet').innerHTML);
		if (kam == 1) {
		   var nasledujici = Pocasi.predpovedAktivni - 1;
		} else {
	      var nasledujici = Pocasi.predpovedAktivni + 1;
		}
      if ((nasledujici < 0) || (nasledujici >= max)) {
      	return false;
		} else {
         Pocasi.zalozkaNastav(nasledujici, max);
         Pocasi.predpovedOver(nasledujici);
		}
	},
	
   zalozkaNastav: function (id, max) {
		for (i = 0; i <= 9; i++) {
		   if($('pr-zal-' + i) != null) {
		      if (id == 0) {
		      	//prvni
               if (i == 0) {
	            	$('pr-zal-' + i).className = 'pop-top-z-la';
					} else if (i == 1) {
	            	$('pr-zal-' + i).className = 'pop-top-z-r';
					} else if (i == 2) {
	            	$('pr-zal-' + i).className = 'pop-top-z-rn';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
					Pocasi.center = 1;
				} else if (id == (max - 1)) {
		      	//posledni
               if (i == (id - 2)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-rn';
					} else if (i == (id - 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-l';
					} else if (i == id) {
	            	$('pr-zal-' + i).className = 'pop-top-z-ra';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
					Pocasi.center = max - 2;
				} else {
					//vycentruju
               if (i == (id - 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-l';
					} else if (i == id) {
	            	$('pr-zal-' + i).className = 'pop-top-z-c';
					} else if (i == (id + 1)) {
	            	$('pr-zal-' + i).className = 'pop-top-z-r';
					} else {
					   $('pr-zal-' + i).className = 'pop-top-z-n';
					}
               Pocasi.center = id;
				}
			}
		}
		Pocasi.predpovedAktivni = id;
	},
	
   selectOblast: function (elm) {
      zemeId = elm.value;
      if (zemeId == 0) {
         $('poco').innerHTML = '';
         $('poco').disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pocasiHledatSelectOblast&zemeId=' + zemeId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('poco').length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('poco').options[i] = new Option(tmp[1], tmp[0]);
							}

							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('poco').remove(i);
								}
							}
	                  $('poco').disabled = false;
	 					}
	            }
	         }
	      );
		}
   }
}

var Mapa = {
	locN: '',
	locE: '',
	marker: null,
	map: '',
	zoom: 8,

   zobraz: function () {
		var latlng = new google.maps.LatLng(Mapa.locN, Mapa.locE);
    	var myOptions = {
      	zoom: Mapa.zoom,
      	center: latlng,
      	mapTypeId: google.maps.MapTypeId.HYBRID
    	};
    	Mapa.map = new google.maps.Map(document.getElementById("gmaps"), myOptions);
   },

   loc: function (locN, locE) {
      Mapa.locN = locN;
		Mapa.locE = locE;
   },

   icon: function (im, locN, locE) {
		var myLatLng = new google.maps.LatLng(locN, locE);
		var beachMarker = new google.maps.Marker({
			position: myLatLng,
			map: Mapa.map,
			icon: im
		});
   },
   
   setZoom: function (zoom) {
      Mapa.zoom = zoom;
   }

}

var Check = {

	emptyRegExp: new RegExp('^\s+$'),
   
   empty: function (str) {
      if (str == '') {
         return true;
      } else if (this.testRe(str, this.emptyRegExp)) {
         return true;
      } else {
         return false;
      }
   },
   
   testRe: function (str, regExp) {
      var retval = null == str.match(regExp) ? false : true;
      return retval;
   }
}

var ZajezdyHledat = {

   formPocet: 0,

   selectOblast: function (id, elm) {
      zemeId = elm.value;
      if (zemeId == 0) {
         $('o' + id).innerHTML = '';
         $('o' + id).disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=zajezdyHledatSelectOblast&zemeId=' + zemeId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('o' + id).length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('o' + id).options[i] = new Option(tmp[1], tmp[0]);
							}
							
							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('o' + id).remove(i);
								}
							}
	                  $('o' + id).disabled = false;
	 					}
	            }
	         }
	      );
		}
   },
   
   pridatZemi: function (oblast, kde) {
      id = $('hpd').innerHTML;
      zemeId = 0;
      if (oblast && $('z' + id) != null) {
			zemeId = $('z' + id).value;
		}
		if (ZajezdyHledat.formPocet == 0) {
         ZajezdyHledat.formPocet = id;
		}
		
		id++;
      var myAjax = new Ajax.Request(
         '/ajax/',
         {
            parameters: 'func=zajezdyHledatSelectNovaZeme&id=' + id + '&zemeId=' + zemeId + '&kde=' + kde,
            onComplete: function (r) {
               var status = r.getResponseHeader('X-Status');
               if ('ERROR' == status) {
                  alert(r.responseText);
               } else {
                  $('ddz').innerHTML = $('ddz').innerHTML + r.responseText;
                  $('hpd').innerHTML = id;
                  $('dz').value = id;
                  ZajezdyHledat.formPocet++;
				      if (ZajezdyHledat.formPocet > 1) {
							for (i = 1; i <= id; i++) {
								if ($('odo' + i) != null) {
									$('odo' + i).style.display = 'inline';
								}
								if ($('odz' + i) != null) {
									$('odz' + i).style.display = 'inline';
								}
							}
						}
 					}
            }
         }
      );
	},
	
	odebratZemi: function (id) {
		if (ZajezdyHledat.formPocet == 0) {
         ZajezdyHledat.formPocet = $('hpd').innerHTML;
		}

		if (ZajezdyHledat.formPocet > 1) {
			if ($('hfz' + id) != null) {
				$('hfz' + id).innerHTML = '';
				$('hfz' + id).className = '';
			}
			if ($('hfo' + id) != null) {
				$('hfo' + id).innerHTML = '';
				$('hfo' + id).className = '';
			}
			ZajezdyHledat.formPocet--;
		}
		if (ZajezdyHledat.formPocet <= 1) {
		   id = $('hpd').innerHTML;
			for (i = 1; i <= id; i++) {
				if ($('odo' + i) != null) {
					$('odo' + i).style.display = 'none';
				}
				if ($('odz' + i) != null) {
					$('odz' + i).style.display = 'none';
				}
			}
		}
	},
	
	selectCena: function (elm) {
      if (elm.value == 2) {
         $('cenazajezduod').style.display = 'inline';
         $('cenazajezdudo').style.display = 'inline';
		} else {
         $('cenazajezduod').style.display = 'none';
         $('cenazajezdudo').style.display = 'none';
		}
	}

}

var Kalendar = {
   popup: function () {
        Calendar.setup(
       {
         dateField: 'popupDateField',
         triggerElement: 'popupDateField'
       }
     )
	}
}

var Recenze = {

   selectOblast: function (elm) {
      zemeId = elm.value;
      if (zemeId == 0) {
         $('oblastId').innerHTML = '';
         $('oblastId').disabled = true;
         $('hotelId').innerHTML = '';
         $('hotelId').disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeSelectOblast&zemeId=' + zemeId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('oblastId').length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('oblastId').options[i] = new Option(tmp[1], tmp[0]);
							}
							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('oblastId').remove(i);
								}
							}
	                  $('oblastId').disabled = false;
	 					}
	            }
	         }
	      );
		}
   },

   selectHotel: function (elm) {
      oblastId = elm.value;
      if (oblastId == 0) {
         $('hotelId').innerHTML = '';
         $('hotelId').disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeSelectHotel&oblastId=' + oblastId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('hotelId').length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('hotelId').options[i] = new Option(tmp[1], tmp[0]);
							}
							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('hotelId').remove(i);
								}
							}
	                  $('hotelId').disabled = false;
	 					}
	            }
	         }
	      );
		}
   },
   
   novaOblastForm: function (zeme, elm) {
      zemeId = $(zeme).value;
		if (Check.empty(zemeId) || zemeId == 0) {
      	alert('Nejdříve vyberte zemi.');
		} else {
		   Loading.showFull('str-obal');
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeNovaOblastForm&zemeId=' + zemeId,
	            onComplete: function (r) {
	               Loading.hideFull('str-obal');
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  ret = r.responseText.split('|');
	                  AlertBox.show(ret[0], ret[1]);
	 					}
	            }
	         }
	      );
		}
	},
	

   novaOblastVlozit: function (elm) {
      zemeId = elm.zId.value;
      oblast = elm.oblast.value;
		if (Check.empty(zemeId) || zemeId == 0) {
      	$('ovberr').innerHTML = '<b>Chyba:</b> Nejdříve vyberte zemi.';
      	$('ovberr').style.display = 'block';
		} else if (Check.empty(oblast)) {
      	$('ovberr').innerHTML = '<b>Chyba:</b> Oblast nesmí zůstat prázdná.';
      	$('ovberr').style.display = 'block';
		} else {
      	elm.vlozit.disabled = true;
      	elm.vlozit.value = 'Ukládám...';
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeNovaOblastHodnota&zemeId=' + zemeId + '&oblast=' + oblast,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
				      	$('ovberr').innerHTML = r.responseText;
				      	$('ovberr').style.display = 'block';
				      	elm.vlozit.disabled = false;
				      	elm.vlozit.value = 'Vložit oblast';
	               } else {
	                  ret = r.responseText.split('|');
	                  if (ret[0] == 'hrdi') {
                        var pocet = $('oblastId').length;
                        for (var i = 0; i < pocet; i++) {
									if ($('oblastId').options[i].value == ret[1]) {
                              $('oblastId').options[i].selected = true;
									} else {
									   $('oblastId').options[i].selected = false;
									}
								}
								Recenze.selectHotel($('oblastId'));
								AlertBox.hide();
							} else if (ret[0] == 'nd') {
                        var pocet = $('oblastId').length;
                        for (var i = 0; i < pocet; i++) {
									$('oblastId').options[i].selected = false;
								}
								$('oblastId').options[pocet] = new Option(ret[2], ret[1]);
								$('oblastId').options[pocet].selected = true;
								AlertBox.hide();
								Recenze.novyHotelForm('oblastId');
							}
	 					}
	            }
	         }
	      );
      }
	},
	
   novyHotelForm: function (oblast) {
      oblastId = $(oblast).value;
		if (Check.empty(oblastId) || oblastId == 0) {
      	alert('Nejdříve vyberte oblast.');
		} else {
		   Loading.showFull('str-obal');
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeNovyHotelForm&oblastId=' + oblastId,
	            onComplete: function (r) {
	               Loading.hideFull('str-obal');
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  ret = r.responseText.split('|');
	                  AlertBox.show(ret[0], ret[1]);
	 					}
	            }
	         }
	      );
		}
	},
	
   novyHotelVlozit: function (elm) {
      oblastId = elm.oblastId.value;
      hotel = elm.hotel.value;
		if (Check.empty(oblastId) || oblastId == 0) {
      	$('ovberr').innerHTML = '<b>Chyba:</b> Nejdříve vyberte oblast.';
      	$('ovberr').style.display = 'block';
		} else if (Check.empty(hotel)) {
      	$('ovberr').innerHTML = '<b>Chyba:</b> Hotel nesmí zůstat prázdný.';
      	$('ovberr').style.display = 'block';
		} else {
      	elm.vlozit.disabled = true;
      	elm.vlozit.value = 'Ukládám...';
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeNovyHotelHodnota&oblastId=' + oblastId + '&hotel=' + hotel,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
				      	$('ovberr').innerHTML = r.responseText;
				      	$('ovberr').style.display = 'block';
				      	elm.vlozit.disabled = false;
				      	elm.vlozit.value = 'Vložit hotel';
	               } else {
	                  ret = r.responseText.split('|');
	                  if (ret[0] == 'hrdi') {
                        var pocet = $('hotelId').length;
                        for (var i = 0; i < pocet; i++) {
									if ($('hotelId').options[i].value == ret[1]) {
                              $('hotelId').options[i].selected = true;
									} else {
									   $('hotelId').options[i].selected = false;
									}
								}
								AlertBox.hide();
							} else if (ret[0] == 'nd') {
                        var pocet = $('hotelId').length;
                        for (var i = 0; i < pocet; i++) {
									$('hotelId').options[i].selected = false;
								}
								$('hotelId').options[pocet] = new Option(ret[2], ret[1]);
								$('hotelId').options[pocet].selected = true;
								$('hotelId').disabled = false;
								AlertBox.hide();
							}
	 					}
	            }
	         }
	      );
      }
	},
	
   novaPolozkaForm: function (typ, elm) {
	   Loading.showFull('str-obal');
      var myAjax = new Ajax.Request(
         '/ajax/',
         {
            parameters: 'func=pridatRecenzeNovaPolozkaForm&typ=' + typ + '&element=' + elm,
            onComplete: function (r) {
               Loading.hideFull('str-obal');
               var status = r.getResponseHeader('X-Status');
               if ('ERROR' == status) {
                  alert(r.responseText);
               } else {
                  ret = r.responseText.split('|');
                  AlertBox.show(ret[0], ret[1]);
 					}
            }
         }
      );
	},
	
   novaPolozkaVlozit: function (typ, elm, element) {
      nazev = elm.nazev.value;
		if (Check.empty(nazev)) {
      	$('ovberr').innerHTML = '<b>Chyba:</b> Název nesmí zůstat prázdný.';
      	$('ovberr').style.display = 'block';
		} else {
      	elm.vlozit.disabled = true;
      	elm.vlozit.value = 'Ukládám...';
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=pridatRecenzeNovaPolozkaHodnota&typ=' + typ + '&nazev=' + nazev,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
				      	$('ovberr').innerHTML = r.responseText;
				      	$('ovberr').style.display = 'block';
				      	elm.vlozit.disabled = false;
				      	elm.vlozit.value = 'Vložit';
	               } else {
	                  ret = r.responseText.split('|');
	                  if (ret[0] == 'hrdi') {
                        var pocet = $(element).length;
                        for (var i = 0; i < pocet; i++) {
									if ($(element).options[i].value == ret[1]) {
                              $(element).options[i].selected = true;
									} else {
									   $(element).options[i].selected = false;
									}
								}
								AlertBox.hide();
							} else if (ret[0] == 'nd') {
                        var pocet = $(element).length;
                        for (var i = 0; i < pocet; i++) {
									$(element).options[i].selected = false;
								}
								$(element).options[pocet] = new Option(ret[2], ret[1]);
								$(element).options[pocet].selected = true;
								$(element).disabled = false;
								AlertBox.hide();
							}
	 					}
	            }
	         }
	      );
      }
	},

   hodnoceniInfo: function (id, elm) {
      var hodn = parseInt(elm.value);
      var vysledek = '';
      if (hodn == 1) {
         vysledek = 'nedostatečné';
		} else if (hodn == 2) {
         vysledek = 'špatné';
		} else if (hodn == 3) {
         vysledek = 'průměrné';
		} else if (hodn == 4) {
         vysledek = 'velmi dobré';
		} else if (hodn == 5) {
         vysledek = 'perfektní';
		}
      $('zvoleno-' + id).innerHTML = vysledek;
	}
}

var Loading = {
   moveLoadingTimer: null,
   loadingAlertTopC: null,
   
   showButton: function (elm) {
      $(elm).innerHTML = '<img src="http://www.cklub.cz/direct/imgn/ajax-loader-button.gif" style="margin-left:130px;">';
	},
	
	showFull: function (elm) {
	   if ($(elm) && $('loading-obal') && $('loading-obsah')) {
	      var bLeft, bTop, bWidth;
	      var alertCover = $('loading-obal');
	      var alertBox = $('loading-obsah');
	      Position.clone(elm, alertCover);
	      alertCover.style.width = bWidth = (parseInt(alertCover.style.width) + 1) + 'px';
	      alertCover.style.height = (parseInt(alertCover.style.height) + 1) + 'px';
	      alertCover.style.top = bTop = (parseInt(alertCover.style.top) - 1) + 'px';
	      alertCover.style.left = bLeft = (parseInt(alertCover.style.left) - 1) + 'px';
	      alertBox.style.top = ((parseInt(alertCover.style.height) / 2) - 15) + 'px';
	      alertBox.style.left = (((parseInt(bWidth) - 100) / 2) + parseInt(bLeft)) + 'px';
	      Element.show(alertCover);
	      Element.show(alertBox);
	      Loading.moveLoadingAlert(parseInt(bTop));
	   }
	},

	hideFull: function (elm) {
	   if ($(elm) && $('loading-obal') && $('loading-obsah')) {
	      Element.hide('loading-obsah');
	      Element.hide('loading-obal');
	      if (Loading.moveLoadingTimer != null) {
	         clearTimeout(Loading.moveLoadingTimer);
	      }
	   }
	},
	
   moveLoadingAlert: function (loadingAlertTopC) {
      var top = Loading.loadingAlertTopC || loadingAlertTopC;
      if(document.documentElement.scrollTop > 0) {
         $('loading-obal').style.top = (document.documentElement.scrollTop + top) + 'px';
      } else {
         $('loading-obal').style.top = top + 'px';
      }
      if (null == Loading.loadingAlertTopC) {
         Loading.loadingAlertTopC = top;
      }
      moveLoadingTimer = setTimeout(Loading.moveLoadingAlert, 20);
   }
}

var AlertBox = {

   topOffset: 200,

   arrayPageSize: null,

   scrollTimer: null,

   show: function (title, text) {
      this.arrayPageSize = this.arrayPageSize || getPageSize();
      this.showOverlay();
      var elm = this.createNewElement();
      elm.style.top = this.topOffset + 'px';
      elm.style.left = ((this.arrayPageSize[0] - 592) / 2) + 'px';

      document.getElementsByClassName('ov-title', elm)[0].innerHTML = title;
      document.getElementsByClassName('content', elm)[0].innerHTML = text;

      this.scrollCheck();      Element.show(elm);
   },

   hide: function () {
      this.scrollCheckStop();
      Element.hide('ovbox');
      new Effect.Fade('overlay', { duration: 0});
   },

   scrollCheck: function () {

      var alertBoxElm = AlertBox.createNewElement();
      if(document.documentElement.scrollTop > 0) {
         alertBoxElm.style.top = (document.documentElement.scrollTop + AlertBox.topOffset) + 'px';
      } else {
         alertBoxElm.style.top = AlertBox.topOffset + 'px';
      }

      AlertBox.scrollTimer = setTimeout(AlertBox.scrollCheck, 200);
   },

   scrollCheckStop: function () {
     if (null != this.scrollTimeout) {
        clearTimeout(this.scrollTimeout);
     }
   },

   showOverlay: function () {
      var objBody = document.getElementsByTagName('body').item(0);

      var objOverlay = document.createElement('div');
      objOverlay.setAttribute('id','overlay');
      objOverlay.style.display = 'none';
      objOverlay.onclick = function() { AlertBox.hide(); }
      objBody.appendChild(objOverlay);

      $('overlay').style.width = this.arrayPageSize[0] + 'px';
      $('overlay').style.height = this.arrayPageSize[1] + 'px';

      new Effect.Appear('overlay', { duration: 0, from: 0.0, to: 0.8 });
   },

   createNewElement: function () {
      var elm = $('ovbox');
      if (!elm) {
         var newElm = Builder.node('div', {'id': 'ovbox', 'style': 'display: none; position: absolute; z-index: 91;'}, [
            Builder.node('div', {'className': 'header'}, ''),
            Builder.node('div', {'className': 'body'}, [
               Builder.node('h3', {'className': 'ov-title'}, 'titulek'),
               Builder.node('span', {'className': 'close'}, [
                  Builder.node('img', {'src': 'http://www.cklub.cz/direct/imgn/zavrit-n.png', 'width': '20', 'height': '20', 'alt': 'Zavřít okno', 'onclick': 'AlertBox.hide(); return false;', 'onmouseover': 'AlertBox.closeOver(this, \'zavrit-a\');', 'onmouseout': 'AlertBox.closeOver(this, \'zavrit-n\');'})
                  ]),
               Builder.node('div', {'className': 'content'}, '')
               ]),
            Builder.node('div', {'className': 'footer'}, '')
            ]
         );

         newElm.firstChild.innerHTML = '&nbsp;';
         newElm.lastChild.innerHTML = '&nbsp;';

         document.body.appendChild(newElm);
         return document.body.lastChild;
      } else {
         return elm;
      }
   },

   closeOver: function (elm, img) {
      elm.src = elm.src.replace(/zavrit\-[an]/, img);
   }
};

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

var Pristup = {

   zapis: function (typ, id) {
      var myAjax = new Ajax.Request(
         '/ajax/',
         {
            parameters: 'func=zapisPristup&typ=' + typ + '&id=' + id,
            onComplete: function (r) {
            }
         }
      );
	}
	
}

var Zalozky = {

   click: function (id, max, elmZalozka, elmObsah) {
		for (i = 1; i <= max; i++) {
		   if (($(elmZalozka + i) != null) && ($(elmObsah + i) != null)){
            if (i == id) {
	      		$(elmObsah + i).style.display = 'block';
		   		$(elmZalozka + i).className = 'hp-pkz-top-a';
				} else {
	      		$(elmObsah + i).style.display = 'none';
		   		$(elmZalozka + i).className = 'hp-pkz-top-n';
				}
			}
		}
	}
	
}

var UbytovaniHledat = {

   selectOblast: function (elm) {
      zemeId = elm.value;
      if (zemeId == 0) {
         $('oblastId').innerHTML = '';
         $('oblastId').disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=ubytovaniHledatSelectOblast&zemeId=' + zemeId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('oblastId').length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('oblastId').options[i] = new Option(tmp[1], tmp[0]);
							}

							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('oblastId').remove(i);
								}
							}
	                  $('oblastId').disabled = false;
	 					}
	            }
	         }
	      );
		}
      $('hotelId').innerHTML = '';
      $('hotelId').disabled = true;
   },
   
	selectHotel: function (elm) {
      oblastId = elm.value;
      if (oblastId == 0) {
         $('hotelId').innerHTML = '';
         $('hotelId').disabled = true;
		} else {
	      var myAjax = new Ajax.Request(
	         '/ajax/',
	         {
	            parameters: 'func=ubytovaniHledatSelectHotel&oblastId=' + oblastId,
	            onComplete: function (r) {
	               var status = r.getResponseHeader('X-Status');
	               if ('ERROR' == status) {
	                  alert(r.responseText);
	               } else {
	                  var predchozi = $('hotelId').length - 1;
	                  ret = r.responseText.split('|');
                     var pocet = ret.length;
                     for (var i = 0; i < pocet; i++) {
                        tmp = ret[i].split('€');
								$('hotelId').options[i] = new Option(tmp[1], tmp[0]);
							}

							if (predchozi > pocet) {
	                     for (var i = predchozi; i >= pocet; i--) {
									$('hotelId').remove(i);
								}
							}
	                  $('hotelId').disabled = false;
	 					}
	            }
	         }
	      );
		}
   }

}

function upravEmail (email) {
   var adresa = email.replace(/\(te[cč]ka\)/gi, '.').replace(/\(zavin[aá][cč]\)/gi, '@');
   location.href = 'mailto:' + adresa;
}

var Diskuze = {

   odpoved: function (id) {
      var obsah = $('pt' + id).innerHTML;
      var jmeno = $('jm' + id).innerHTML;
		ifr = document.getElementById('text_ifr');
		volanyIframe = (ifr.contentWindow? ifr.contentWindow.document: ifr.contentDocument);
		obsahIframe = volanyIframe.getElementById("tinymce");
		if (obsahIframe.innerHTML == '<p><br mce_bogus="1"></p>') {
         obsahIframe.innerHTML = '[bq=' + jmeno + ';' + id + ']' + obsah + '[/bq]' + '<p><br mce_bogus="1"></p>';
		} else {
		   obsahIframe.innerHTML = obsahIframe.innerHTML + '[bq=' + jmeno + ';' + id + ']' + obsah + '[/bq]' + '<p><br mce_bogus="1"></p>';
		}
      location.href = '#odpoved';
	},
	
   ochrana: function (blok, id, vlozit) {
      $(blok).style.visibility = 'hidden';
      $(blok).style.position = 'absolute';
      $(id).value = vlozit;
	}

}

var Cookies = {

   vymaz: function (name, elm, path, domain) {
   	var datum= new Date();
		datum.setTime(datum.getTime() - 1000 * 60 * 60 * 24);
      document.cookie = name + "=x;expires=" + datum.toGMTString() + ";path=" + path + ";domain=" + domain;
      $(elm).innerHTML = 'vymazáno';
   }

}