$addHandler(window, "load", initReserve);

var TODAY = new Date();

function initReserve() {
  faktura(0);
  var year = TODAY.getFullYear();
  var cal1 = Calendar.setup({
      firstDay: 1,
      inputField: "calendar",
      ifFormat: "%e. %B %Y",
      button: "calendar",
      weekNumbers: false,
      dateStatusFunc: disallowDate,
      onSelect: dateSelected,
      range: [year, year+3]
  });
}
function disallowDate(date, y, m, d) {
  return (date > TODAY) ? false : "disabled";
};
function dateSelected(cal) {
	var p = cal.params;
  if(cal.date < TODAY) {
    p.inputField.value = '';
    return false;
  }
	var update = (cal.dateClicked || p.electric);
	if (update && p.inputField) {
    $get('dateYMD').value = cal.date.print('%Y-%m-%d');
		p.inputField.value = cal.date.print(p.ifFormat);
		if (typeof p.inputField.onchange == "function")
			p.inputField.onchange();
	}
	if (update && p.displayArea)
		p.displayArea.innerHTML = cal.date.print(p.daFormat);
	if (update && typeof p.onUpdate == "function")
		p.onUpdate(cal);
	if (update && p.flat) {
		if (typeof p.flatCallback == "function")
			p.flatCallback(cal);
	}
	if (update && p.singleClick && cal.dateClicked)
		cal.callCloseHandler();
};
//dateYYYYMMDD

function validate(form) {
	if(!check(form.datum,ErrorText.Error + ErrorText.Enter1 + ErrorText.Datum)) return false;
	if(!check(form.noci,ErrorText.Error + ErrorText.Enter2 + ErrorText.Noci)) return false;
	if(!check(form.osob,ErrorText.Error + ErrorText.Enter2 + ErrorText.Osob)) return false;
	if(form.dvojluzkovy.value=="" && form.apartma.value=="") {
    alert(ErrorText.Error + ErrorText.Enter2 + ErrorText.Room2 + ErrorText.Or + ErrorText.Suite);
    return false;
  }
	if(!check(form.jmeno,ErrorText.Error + ErrorText.Enter1 + ErrorText.Name)) return false;
	if(!check(form.adresa,ErrorText.Error + ErrorText.Enter1 + ErrorText.Address)) return false;
	if (form.telefon.value=="" && form.email.value=="") {
		alert(ErrorText.Error + ErrorText.Enter1 + ErrorText.Tel);
		form.telefon.focus();
		return false;
	}
	if(form.platba[2].checked==true) {
		if(!check(form.firma,ErrorText.Error + ErrorText.Fak + ErrorText.Firma)) return false;
		if(!check(form.ICO,ErrorText.Error + ErrorText.Fak + ErrorText.ICO)) return false;
		if(!check(form.cislo_uctu,ErrorText.Error + ErrorText.Fak + ErrorText.Ucet)) return false;
		if(!check(form.banka,ErrorText.Error + ErrorText.Fak + ErrorText.Bank)) return false;
	}
}
function check(o,t) {
	if (o.value=="") {
		alert(t);
		o.focus();
		return false;
	} else {
		return true;
	}
}

function faktura(x) {
	$get('platba_fakturou').style.display=(x)?"":"none";
}

function luzko(x) {
	$get('typ'+x).style.visibility=(document.form.typ[x].checked)?"visible":"hidden";
}

