

// JavaScript Document
// vypocet ceny pobytu v hotelu Antik****garni a hotelu Golden Cross - www.antikhotels.com
// author: (c)2008 www.mediapolis.cz
  
function count() {
var antik = new Array("1990","2490","2590","2990","2190","2690"); //SU, double bed room - low season, high season, middle season, 
var golden = new Array("1500","1500","2300","2300"); //SU, double bed room, apartment - low season, high season
var months = new Array("/1/","/2/","/3/","/4/","/5/","/6/","/7/","/8/","/9/","/10/","/11/","/12/"); // mesice pro vyhledani v arr a dep rezetezcich 
var monthDay = new Array("31","28","31","30","31","30","31","31","30","31","30","31"); //pocty dnu v kazdem z mesicu v roce
/* uprava poctu dnu v unoru v prechodnem roce */
  var today = new Date();
  var year = today.getYear();
  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { monthDay[1] = "29";}
/* konec prepoctu prechodneho roku*/  

var h = parseFloat(document.getElementById('hotel').value); //vybrany hotel
var r = parseFloat(document.getElementById('room').value); //vybrany pokoj
var arr = document.getElementById('arrival_date').value; //vybrane datum prijezdu
var dep = document.getElementById('departure_date').value; //vybrane datum odjezdu
var seasonprice = 0;
var seasonprice2 = 0;
var seasonprice3 = 0;
var startseason;
var nextseason;
var i = 0;

  for (i=0;i<12;i++) {

    if (h == 0 && r == 2) { //chybne vybrano apartment pro hotel Antik****garni
    alert("!!! incorrect room for Antik**** !!!");
    break;
    }
    if (arr == "dd/mm/yy" || dep == "dd/mm/yy" ) { //uzivatel zapomnel vybrat datum prijezdu/odjezdu
    alert("choose the arrival/departure date");
    break;
    }

  
    if ((arr.match(months[i]) != null) && (dep.match(months[i]) != null) ) { //termin pobytu je v ramci jednoho mesice
      if (h < 1) { 
        if (i <= 2 || i >= 10 ) {
          if (r == 0) {var seasonprice = antik[0];}
          if (r == 1) {var seasonprice = antik[1];}
        }
        if (i == 3 || i == 4 || i == 5 || i == 8 || i == 9) {
          if (r == 0) {var seasonprice = antik[2];}
          if (r == 1) {var seasonprice = antik[3];}
        }
        if (i == 6 || i == 7) {
          if (r == 0) {var seasonprice = antik[4];}
          if (r == 1) {var seasonprice = antik[5];}
        }
      }
      if (h > 0) {
        if (i == 0 || i == 1 || i == 2 || i == 10 || i == 11 || i == 6 || i == 7) { //low season
          if (r == 0) {var seasonprice = golden[0];}
          if (r == 1) {var seasonprice = golden[1];}
        }
        if (i == 3 || i == 4 || i == 5 || i == 8 || i == 9) { //high season
          if (r == 0) {var seasonprice = golden[2];}
          if (r == 1) {var seasonprice = golden[3];}
        }
      }
      var countdaysinMonth = (parseFloat(dep) - parseFloat(arr)); //pocet dnu
      document.getElementById('price').value = (countdaysinMonth * seasonprice + ",- CZK" ); //vypsani celkove ceny
      break;
    }

    if ((arr.match(months[i]) != null) && (dep.match(months[i + 1]) != null)) { //termin presahuje z jednoho mesice do nasledujiciho
      if (h < 1) {
        if (i <= 2 || i >= 10 ) {
          if (r == 0) {var seasonprice3 = antik[0];}
          if (r == 1) {var seasonprice3 = antik[1];}
        }
        if (i == 3 || i == 4 || i == 5 || i == 8 || i == 9) {
          if (r == 0) {var seasonprice3 = antik[2];}
          if (r == 1) {var seasonprice3 = antik[3];}
        }
        if (i == 6 || i == 7) {
          if (r == 0) {var seasonprice3 = antik[4];}
          if (r == 1) {var seasonprice3 = antik[5];}
        }
      }
      if (h > 0) {
        if (i == 0 || i == 1 || i == 2 || i == 10 || i == 11 || i == 6 || i == 7) { //low season
          if (r == 0) {var seasonprice3 = golden[0];}
          if (r == 1) {var seasonprice3 = golden[1];}
        }
        else { //high season
          if (r == 0) {var seasonprice3 = golden[2];}
          if (r == 1) {var seasonprice3 = golden[3];}
        }  
      }
      startseason = (monthDay[i] - parseFloat(arr)) * seasonprice3; //vypocet ceny z prvniho mesice pobytu
    
    if (dep.match(months[i + 1]) != null) {
      if ( h < 1) {
        if (i + 1 <= 2 || i + 1 >= 10) {
          if (r == 0) {var seasonprice2 = antik[0];}
          if (r == 1) {var seasonprice2 = antik[1];}
        }
        if (i + 1 == 3 || i + 1 == 4 || i + 1 == 5 || i + 1 == 8 || i + 1 == 9) {
          if (r == 0) {var seasonprice2 = antik[2];}
          if (r == 1) {var seasonprice2 = antik[3];}
        }
        if (i + 1 == 6 || i + 1 == 7) {
          if (r == 0) {var seasonprice2 = antik[4];}
          if (r == 1) {var seasonprice2 = antik[5];}
        }
      }
      if (h > 0) {
        if (i + 1 == 0 || i + 1 == 1 || i + 1 == 2 || i + 1 == 10 || i + 1 == 11 || i + 1 == 6 || i + 1 == 7) { //low season
          if (r == 0) {var seasonprice2 = golden[0];}
          if (r == 1) {var seasonprice2 = golden[1];}
        }
        else { //high season
          if (r == 0) {var seasonprice2 = golden[2];}
          if (r == 1) {var seasonprice2 = golden[3];}
        }
      }
      nextseason = parseFloat(dep) * seasonprice2; //vypocet ceny z nasledneho mesice
    }
    document.getElementById('price').value = (startseason + nextseason + ",- CZK" ); //vypsani celkove ceny
    }
 }
}

