// JavaScript Document
var win = null;
var index = 1;
Window.keepMultiModalWindow=false;
function logowanie(akcja) {
  Dialog.confirm($('login').innerHTML, {className:"alphacube",
  width:500, id: "d" + index, okLabel: "loguj", cancelLabel: "anuluj", onOk:function(win)
  {
   new Ajax.Request('/login.php',
    {
     parameters: { login: $F('name'), pass: $F('pass') },
     onSuccess: function(transport)
      {
       var notice = $('login_error_msg1');
       if (transport.responseText == "OK")
        {
         if (akcja == 'zapisy')
         {
          window.location = "/zapisy/";
          return false;
         }
        }
       else
        {
         notice.innerHTML='Błędny login lub hasło !';
        }
       notice.show();
       Windows.focusedWindow.updateHeight();
       new Effect.Shake(Windows.focusedWindow.getId());
       return false;
      },
      onFailure: function()
       {
        alert("Błąd w połączeniu z serwerem!");
       }
     });
    }})
    index++;

   }
   
   function remind() {
	  Dialog.confirm($('remind').innerHTML, {className: "alphacube",  width:500, id: "d" + index, okLabel: "przypomnij", cancelLabel: "anuluj", onOk:function(win)
  {
   new Ajax.Request('/remind.php',
    {
     parameters: { nrtel: $F('nrtel')},
     onSuccess: function(transport)
      {
       var notice = $('login_error_msg2');
       if (transport.responseText == "OK")
        {
         // Windows.closeAllModalWindows();
         DialogBox('Dziękujemy za rejestrację. Otrzymasz jeszcze widomość SMS z powitaniem.');
         // notice.innerHTML='Hasło zostało wysłane na Twój telefon !';
         //setTimeout("Windows.closeAllModalWindows();", 3000);
        // window.location = "/zapisy/";
        
        return false;
        
         }
      
       else
        {
         notice.innerHTML='Podanego numeru nie ma w bazie !';
        }
       notice.show();
       Windows.focusedWindow.updateHeight();
       new Effect.Shake(Windows.focusedWindow.getId());
       return false;
      },
      onFailure: function()
       {
        alert("Błąd w połączeniu z serwerem!");
       }
     });
    }})
	  index++;
  }
   function register() {
   Dialog.confirm($('register').innerHTML, {className:"alphacube",
   width:500, id: "d" + index, okLabel: "rejestruj", cancelLabel: "anuluj", onOk:function(win)
   {
   new Ajax.Request('/register.php',
    {
     parameters: { tel: $F('tel'), pass1: $F('pass1'), pass2: $F('pass2'), imie: $F('imie'), nazwisko: $F('nazwisko'), polecajacy: $F('polecajacy')},
     onSuccess: function(transport)
      {
       var notice = $('login_error_msg3');
       if (transport.responseText == "OK")
        {
         DialogBox('Dziękujemy za rejestrację. Otrzymasz jeszcze widomość SMS z powitaniem.');
         return false;
        }
       else
        {
         notice.innerHTML=transport.responseText;
        }
       notice.show();
       Windows.focusedWindow.updateHeight();
       new Effect.Shake(Windows.focusedWindow.getId());
       return false;
      },
      onFailure: function()
       {
        alert("Błąd w połączeniu z serwerem!");
       }
     });
    }})
    index++;
   }
   function openDialog3() {
    Dialog.alert("Funkcja obecnie niedostępna. Prosimy spróbować za jakiś czas bądź skontaktować się z nami telefonicznie.",{className:"alphacube", width: 400, height:null})
  }
  
  function DialogBox(tekst) {
    Windows.closeAllModalWindows();
    Dialog.alert( tekst, {className:"alphacube", width: 400, height:null})
  }
  
  function dzien(day, month, year)
  {
   url = "/kalendarz.php?dzien=" + day + "&miesiac=" + month + "&rok=" + year;
   startGETRequest(url, onCompleteDzien, onEnd);	
  }
  function onCompleteDzien(text, xml)
  {
   if(text != "error")
   {
    document.getElementById('kalendarz').innerHTML = text;
   }
  }
  function rezerwacje(day, month, year)
  {
   url = "/wypis.php?dzien=" + day + "&miesiac=" + month + "&rok=" + year;
   startGETRequest(url, onCompleteZapis, onEnd);	
  }
  function onCompleteZapis(text, xml)
  {
   if(text != "error")
   {
    document.getElementById('zapis').innerHTML = text;
   }
  }
  function zapis_sesji(sesja, telefon, zabiegi)
  {
   url = "/zapis_sesji.php?sesja=" + sesja + "&telefon=" + telefon + "&zabiegi=" + zabiegi;
   startGETRequest(url, onCompleteZapisSesji, onEnd);	
  }
  function onCompleteZapisSesji(text, xml)
  {
   if(text != "error")
   {
    document.forms['payform'].submit();;
   }
  }
  function onEnd()
  {
  }
  var procentxxx=0;
  function tniemyCeny(procent)
  {
   var standard1 = document.getElementById('ijeden').value;
   var standard2 = document.getElementById('ipiec').value;
   var standard3 = document.getElementById('idziesiec').value;
   var standard4 = document.getElementById('ipietnascie').value;
   var standard5 = document.getElementById('idwadziescia').value;
   if (procent!=0)
   { var nowacena1 = standard1 - (standard1 * procent / 100);
     var nowacena2 = standard2 - (standard2 * procent / 100);
     var nowacena3 = standard3 - (standard3 * procent / 100);
     var nowacena4 = standard4 - (standard4 * procent / 100);
     var nowacena5 = standard5 - (standard5 * procent / 100);
   }
   else 
   {
     var nowacena1 = standard1;
     var nowacena2 = standard2;
     var nowacena3 = standard3;
     var nowacena4 = standard4;
     var nowacena5 = standard5;
   }
   document.getElementById('jeden').innerHTML=nowacena1;
   document.getElementById('piec').innerHTML=nowacena2;
   var oszczednosc1 = standard1 * 5 - nowacena2;
   document.getElementById('opiec').innerHTML=oszczednosc1;
   document.getElementById('dziesiec').innerHTML=nowacena3;
   var oszczednosc2 = standard1 * 10 - nowacena3;
   document.getElementById('odziesiec').innerHTML=oszczednosc2;
   document.getElementById('pietnascie').innerHTML=nowacena4;
   var oszczednosc3 = standard1 * 15 - nowacena4;
   document.getElementById('opietnascie').innerHTML=oszczednosc3;
   document.getElementById('dwadziescia').innerHTML=nowacena5;
   var oszczednosc4 = standard1 * 20 - nowacena5;
   document.getElementById('odwadziescia').innerHTML=oszczednosc4;
   procentxxx = procent;
  }
  
  function zakup(kasa, zabiegi) {
  document.forms['zakupik'].action = '/platnosci/';
  document.getElementById('ukryty').value=kasa;
  document.getElementById('zabiegi').value=zabiegi;
  document.forms['zakupik'].submit();
  }
