var _klucz =" ";
var _styl = 1;
var xmlHttp = createXmlHttpRequestObject();
var Domena = "http://www.zamownocleg.pl";


function kalendarz(){
//document.write('<input type="hidden" id="mies" OnChange="process()" value="0"/>');
//document.write('<input type="hidden" name="klucz" id="key" value="'+_klucz+'" />');
//document.write('<div Id="cal"></div>');
document.write('<div ><a href="'+Domena+'" target="blank">');
document.write('<img src="'+Domena+'/_kalendarz/gfx/nocleg_gory_nad_morzem_zamownocleg.gif" alt="system rezerwacji noclegów" border="0" />');
document.write('</a></div>');
document.write('<iframe name="zamownocleg" src="'+Domena+'/_kalendarz/index.php?key='+_klucz+'" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" width="137" height="206" noresize /></iframe>');
document.write('<BR><img src="'+Domena+'/_kalendarz/gfx/legenda.gif" alt="kolor czerwony - dni zajęte" border="0" height="76" width="137" />');
}

function process()
{
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    //http://localhost/_kalendarz/
    name = encodeURIComponent(document.getElementById("mies").value);
    _klucz = encodeURIComponent(document.getElementById("key").value);
    xmlHttp.open("GET", "kalendarz.php?ile="+name+"&tm="+JSClock()+"&key="+_klucz+"&styl="+_styl, true);
    xmlHttp.onreadystatechange = handleServerResponse;
    //xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(null);
  }
  else
    setTimeout('process()', 1000);
}


function rezerwacjaWpis()
{
        ADRES = location.toString();
        z = ADRES.indexOf("/", 10);
        domenawpis = ADRES.substring(0,z);


  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
     
    //http://localhost/_kalendarz/
   mc = document.getElementById("mies").value;
    _klucz = encodeURIComponent(document.getElementById("key").value);
    xmlHttp.open("GET", domenawpis+"/_kalendarz/kalendarz_portal.php?ile="+mc+"&tm="+JSClock()+"&key="+_klucz+"&styl=1", true);
      
    xmlHttp.onreadystatechange = handleServerResponse2;
   
    //xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(null);
  }
  else
    setTimeout('rezerwacjaWpis()', 1000);
}


function createXmlHttpRequestObject() 
{
  // przechowa odwoBanie do obiektu XMLHttpRequest
  var xmlHttp;
  // powinno dziaBa dla wszystkich przegldarek z wyjtkiem IE6 i starszych
  try
  {
    // próbuje stworzy obiekt XMLHttpRequest
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    // zakBadajc, 9ze IE6 lub starsza
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
      "MSXML2.XMLHTTP.5.0",
      "MSXML2.XMLHTTP.4.0",
      "MSXML2.XMLHTTP.3.0",
      "MSXML2.XMLHTTP",
      "Microsoft.XMLHTTP");
    // sprawdza ka9zdy prog id a9z który[ zadziaBa
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        // próbuje stworzy obiekt XMLHttpRequest
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // zwraca stworzony obiekt albo wy[wietla komunikat o bBdzie
  if (!xmlHttp)
    alert("BBd podczas tworzenia obiektu XMLHttpRequest.");
  else 
    return xmlHttp;
}



function handleServerResponse() 
{
  if (xmlHttp.readyState == 4) 
  {
    if (xmlHttp.status == 200)
    {
      xmlResponse = xmlHttp.responseXML;
      xmlDocumentElement = xmlResponse.documentElement;
      helloMessage = xmlDocumentElement.firstChild.data;
    document.getElementById("cal").innerHTML =  helloMessage ;
      // ponawia sekwencj
    //  setTimeout('process()', 1000);
    }
    // dla statusu protokoBu HTTP innego ni9z 200 zgBasza bBd
    else
    {
      //alert("WystpiB bBd podczas uzyskiwania dostpu do serwera zamownocleg.pl");
    }
  }
}



function handleServerResponse2()
{

  if (xmlHttp.readyState == 4) 
  {
  
    if (xmlHttp.status == 200)
    {
      xmlResponse = xmlHttp.responseXML;
      xmlDocumentElement = xmlResponse.documentElement;
      helloMessage = xmlDocumentElement.firstChild.data;
    document.getElementById("cal").innerHTML =  helloMessage ;
      // ponawia sekwencj
    // setTimeout('rezerwacjaWpis()', 1000);
    }
    // dla statusu protokoBu HTTP innego ni9z 200 zgBasza bBd
    else
    {
      //alert("WystpiB bBd podczas uzyskiwania dostpu do serwera zamownocleg.pl");
    }
  }
}

function ile(liczba){
        document.getElementById("mies").value =  liczba ;
        process();
}
function ilep(liczba){
        document.getElementById("mies").value =  liczba ;
        rezerwacjaWpis();
}
function JSClock() {
   var time = new Date()
   var hour = time.getHours()
   var minute = time.getMinutes()
   var second = time.getSeconds()
   var temp = "" + ((hour > 12) ? hour - 12 : hour)
   if (hour == 0)
      temp = "12";
   temp += ((minute < 10) ? "0" : "") + minute
   temp += ((second < 10) ? "0" : "") + second
   //temp += (hour >= 12) ? " P.M." : " A.M."
   return temp
}

function zamownoclegRezerwacjaForm(URL){
window.open(URL,"REZERWACJA","scrollbars=1,left=10,top=10,screenX=10,screenY=10,width=600,height=500");
}
