

function loadingBarPage()
{ 
        document.getElementById("text").innerHTML = '<div style="text-align:center;z-index:20;position:fixed;margin:0 auto;margin-top:0px;width:402px;"><img style="margin-top:8px;padding:30px;background-color:white;" src="grafika/ajax-loader.gif"/></div>' + document.getElementById("text").innerHTML;
}

Walidator = function(){
   
  this.czyWypelnione = function(id,komunikat,dokadmam){
    var el = document.getElementById(id);
    var er = document.getElementById(id+'ERR');
    
    if(!el.value){
      er.innerHTML=komunikat;
      $('#'+id+'ERR').hide();
      $('#'+id+'ERR').fadeIn();
      er.style.display='inline-block';
      el.focus();
      window.scrollTo(0,dokadmam);   
      return false;
    }
    else{
      $('#'+id+'ERR').fadeOut();
      er.style.display='none';
      return true;
    }
  }
  
  this.czyPoprawnyTemat = function(id,komunikat){
    var el = document.getElementById(id);
    var er = document.getElementById(id+'ERR');
    var login = el.value;

    if(login == "Temat: ")
    {
      if(login.length < 8){
        er.innerHTML=komunikat;
        $('#'+id+'ERR').hide();
        $('#'+id+'ERR').fadeIn();
        er.style.display='inline-block';
              el.focus();
        return false;
      }
    }
    else{
      $('#'+id+'ERR').fadeOut();
      er.style.display='none';
      return true;
    }
  }  
  
  this.czyPoprawnaTresc = function(id,komunikat){
    var el = document.getElementById(id);
    var er = document.getElementById(id+'ERR');
    var login = el.value;

    if(login == "Treść pytania: ")
    {
      if(login.length < 16){
        er.innerHTML=komunikat;
        $('#'+id+'ERR').hide();
        $('#'+id+'ERR').fadeIn();
              el.focus();
        er.style.display='inline-block';
        return false;
      }
    }
    else{
      $('#'+id+'ERR').fadeOut();
      er.style.display='none';
      return true;
    }
  }
  
  this.czyPoprawnyMail = function(id,komunikat,dokadmam){
    var el = document.getElementById(id);
    var er = document.getElementById(id + 'ERR');
    var check = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

    if(!check.test(el.value)){
      er.innerHTML=komunikat;
      $('#'+id+'ERR').hide();
            el.focus();
      $('#'+id+'ERR').fadeIn();
      er.style.display='inline-block';
      window.scrollTo(0,dokadmam); 
      return false;
    }
    else {
      $('#'+id+'ERR').fadeOut();
      er.style.display='none';

      return true;
    }
  }
  
  this.zeruj = function(id){
    var er = document.getElementById(id + 'ERR');
      $("#"+id+"ERR").hide();
      er.innerHTML=''; 
  }
      
  this.zerujDiv = function(id,text){
    var er = document.getElementById(id);
      er.innerHTML=text; 
  }
  
  this.zerujInput = function(id){
    var er = document.getElementById(id);
      er.value=""; 
  }
  
  this.idGalerii;
}
walidator = new Walidator();

function wezStroneSukcesFadeNo() {
     var cel = document.getElementById('text');
     cel.innerHTML =  this.responseText;  
     
     var alltables=document.getElementsByName("tabelaButtony")
    
     for (var i=0; i<alltables.length; i++)
     {
          element=alltables[i];
          if (typeof element.onselectstart!="undefined") //IE route
            element.onselectstart=function(){return false}
          else //All other route (ie: Opera)
            element.onmousedown=function(){return false}
     }  
}

function wezStroneSukcesFadeNoAbs() {
     var cel = document.getElementById('text');
     cel.innerHTML =  this.responseText;  
     
     var alltables=document.getElementsByName("tabelaButtony")
    
     for (var i=0; i<alltables.length; i++)
     {
          element=alltables[i];
          if (typeof element.onselectstart!="undefined") //IE route
            element.onselectstart=function(){return false}
          else //All other route (ie: Opera)
            element.onmousedown=function(){return false}
     }  
     
     $("#trescAbstraktu").keyup(function()
     {
          var max = 2000
          var box=$(this).val();
          var main = box.length *100;
          var value= (main / max);
          var count= max - box.length;

          if(box.length <= max)
          {
               $('#count').html(count);
               $('#bar').animate(
               {
                    "width": value+'%',
               }, 1);
          }
          else
          {
               $(this).val($(this).val().substring(0,max - 1));
          }
          return false;
     });     

     $("#trescAbstraktuEN").keyup(function()
     {
          var max = 2000
          var box=$(this).val();
          var main = box.length *100;
          var value= (main / max);
          var count= max - box.length;

          if(box.length <= max)
          {
               $('#countEN').html(count);
               $('#barEN').animate(
               {
                    "width": value+'%',
               }, 1);
          }
          else
          {
               $(this).val($(this).val().substring(0,max - 1));
          }
          return false;
     });      
     
     $("#trescAbstraktu1").keyup(function()
     {
          var max = 2000
          var box=$(this).val();
          var main = box.length *100;
          var value= (main / max);
          var count= max - box.length;

          if(box.length <= max)
          {
               $('#count1').html(count);
               $('#bar1').animate(
               {
                    "width": value+'%',
               }, 1);
          }
          else
          {
               $(this).val($(this).val().substring(0,max - 1));
          }
          return false;
     });        
    // window.scrollTo(0,180);
}

function wezStrone1Abstrakt(lokalizacja) {
    var req = mint.Request();
    req.evalScripts = true;
    req.OnSuccess = wezStroneSukcesFadeNoAbs;
    req.Send(lokalizacja);
    loadingBarPage();
}

function wezStrone1(lokalizacja) {
    var req = mint.Request();
    req.evalScripts = true;
    req.OnSuccess = wezStroneSukcesFadeNo;
    req.Send(lokalizacja);
    loadingBarPage();
}

function wezStrone(lokalizacja) {
    var req = mint.Request();
    req.evalScripts = true;
    req.OnSuccess = wezStroneSukcesFadeNo;
    req.Send(lokalizacja);
    loadingBarPage();
}            

function sprawdzCaptche(req) {
    var req1 = mint.Request();
    var cod = document.getElementById('code');
        
    req1.AddParam("code", cod.value);
    req1.Send("php/sprawdzCaptche.php", null);
        
    req1.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {
          req.SendForm("formularzPytania","php/dodajPytanieWykonaj.php");
      }
      else
      {
          var er = document.getElementById('codeERR');
          document.getElementById('siimage').src = 'php/captcha/securimage_show.php?sid=' + Math.random();
          er.innerHTML="Przepisz poprawnie kod z obrazka!";
          $('#codeERR').hide();
          $('#codeERR').fadeIn();
      }     
    }
}

function sprawdzCaptche1(req) {
    var req1 = mint.Request();
    var cod = document.getElementById('code');
        
    req1.AddParam("code", cod.value);
    req1.Send("php/sprawdzCaptche.php", null);
        
    req1.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {
          req.SendForm("formularzAbstraktuPL","php/dodajAbstraktWykonaj.php");
      }
      else
      {
          var er = document.getElementById('codeERR');
          document.getElementById('siimage').src = 'php/captcha/securimage_show.php?sid=' + Math.random();
          er.innerHTML="Przepisz poprawnie kod z obrazka!";
          $('#codeERR').hide();
          $('#codeERR').fadeIn();
      }     
    }
}

function sprawdzCaptche11(req) {
    var req1 = mint.Request();
    var cod = document.getElementById('code1');
        
    req1.AddParam("code1", cod.value);
    req1.Send("php/sprawdzCaptche1.php", null);
        
    req1.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {
          req.SendForm("formularzAbstraktuEN","php/dodajAbstraktWykonaj.php");
      }
      else
      {
          var er = document.getElementById('code1ERR');
          document.getElementById('siimage1').src = 'php/captcha/securimage_show.php?sid=' + Math.random();
          er.innerHTML="Incorrect code!";
          $('#code1ERR').hide();
          $('#code1ERR').fadeIn();
      }     
    }
}

function ustawPage1(numer,adres) {


    var req1 = mint.Request();
  
    req1.OnSuccess = function() 
    {
        wezStrone1(adres);
    }
    
    req1.AddParam("numer", numer);
    req1.Send("php/nextA.php", null);
}

function  ustawLBSukces()
{
    $('#confirmDivP').css({
      textAlign: 'center',
      fontFamily: 'Verdana, Geneva, Arial, Helvetica, sans-serif',
      fontWeight: 'bold',
      fontSize: '16px',
      color:'white',
      width: '300px',
      cursor:'default',
      height:'35px',
      paddingTop:'15px',
      border: '2px black groove',
      backgroundColor: 'green'
    });
}

function  ustawLBPorazka()
{
    $('#confirmDivP').css({
      textAlign: 'center',
      fontFamily: 'Verdana, Geneva, Arial, Helvetica, sans-serif',
      fontWeight: 'bold',
      fontSize: '16px',
      color:'white',
      width: '500px',
      cursor:'default',
      height:'35px',
      paddingTop:'15px',
      border: '2px black groove',
      backgroundColor: 'red'
    });
}

function  ustawLBPorazka1()
{
    $('#confirmDivP').css({
      textAlign: 'center',
      fontFamily: 'Verdana, Geneva, Arial, Helvetica, sans-serif',
      fontWeight: 'bold',
      fontSize: '16px',
      color:'white',
      width: '300px',
      cursor:'default',
      height:'35px',
      paddingTop:'15px',
      border: '2px black groove',
      backgroundColor: 'red'
    });
}


function wezConfirm() {
    document.getElementById('confirmDivP').innerHTML = document.getElementById('confirmDiv').innerHTML;
    $('#confirmDivP').css({
      textAlign: 'center',
      fontFamily: 'Verdana, Geneva, Arial, Helvetica, sans-serif',
      fontWeight: 'normal',
      color:'black',
      fontSize: '15px',
      width: '300px',
      cursor:'default',
      height:'130px',
      border: '2px black groove',
      backgroundColor: '#ADD8E6',
      display: 'block'
    });
    
    $('#confirmDivP').lightbox(false,0,false,false);
}

function wezConfirm2() {
    document.getElementById('confirmDivP').innerHTML = document.getElementById('confirmDiv2').innerHTML;
    $('#confirmDivP').css({
      textAlign: 'center',
      fontFamily: 'Verdana, Geneva, Arial, Helvetica, sans-serif',
      fontWeight: 'normal',
      color:'black',
      fontSize: '15px',
      width: '300px',
      cursor:'default',
      height:'130px',
      border: '2px black groove',
      backgroundColor: '#ADD8E6',
      display: 'block'
    });
    
    $('#confirmDivP').lightbox(false,0,false,false);
}

function wyslijPytanie(id) { 
    var er = document.getElementById('komunikat');  
    $('#komunikat').hide();

    walidator.zeruj('tematPytania');            
    walidator.zeruj('trescPytania');
    walidator.zeruj('imieNazwisko');
    walidator.zeruj('mail');
    walidator.zeruj('code'); 
    
    if(!walidator.czyPoprawnyTemat('tematPytania','Wpisz temat!')) return false;    
    if(!walidator.czyPoprawnaTresc('trescPytania','Wpisz pytanie!')) return false;
    if(!walidator.czyWypelnione('imieNazwisko','Uzupełnij swoje dane!')) return false;
    if(!walidator.czyWypelnione('mail','Brak podanego adresu e-mail!')) return false;   
    if(!walidator.czyPoprawnyMail('mail','Niepoprawna forma adresu e-mail!')) return false;           

    var req = mint.Request();
    var el = document.getElementById('captcha');
        
    if (el.style.display!='block')
    {
      el.style.display='block';
      return false;
    }
    else
    {   
      sprawdzCaptche(req);      
    }  
                 
    req.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {   
          wezStrone('php/oNas.php');
          document.getElementById('sukcesik').innerHTML = "Pytanie zostało wysłane!";
          $('#sukcesik').lightbox(false,3,false,false);
      }
      else
      {   
          document.getElementById('porazka').innerHTML = "Nie udało się wysłać pytania!";
          $('#porazka').lightbox(false,3,false,false);
      }    
        
    }
} 

function wyslijAbstrakt() { 
    var er = document.getElementById('komunikat');  
    $('#komunikat').hide();

    walidator.zeruj('imieNazwisko');            
    walidator.zeruj('mail');
    walidator.zeruj('telefon');
    walidator.zeruj('opiekun');
    walidator.zeruj('opiekunEN');
    walidator.zeruj('nazwaJednostki');
    walidator.zeruj('nazwaJednostkiEN');
    walidator.zeruj('uczelniaMedyczna');
    walidator.zeruj('uczelniaMedycznaEN');
    walidator.zeruj('tytul');
    walidator.zeruj('tytulEN');
    walidator.zeruj('trescAbstraktu');
    walidator.zeruj('trescAbstraktuEN');
    walidator.zeruj('code'); 
    
    if(!walidator.czyWypelnione('imieNazwisko','<b>Uzupełnij swoje dane!</b>',220)) return false;
    if(!walidator.czyWypelnione('mail','Uzupełnij pole <b>E-mail!</b>',650)) return false;
    if(!walidator.czyPoprawnyMail('mail','Niepoprawna forma adresu <b>E-mail!</b>',650)) return false; 
    if(!walidator.czyWypelnione('telefon','Uzupełnij pole <b>Telefon!</b>',670)) return false;
    if(!walidator.czyWypelnione('opiekun','Uzupełnij pole <b>Opiekun!</b>',720)) return false;
    if(!walidator.czyWypelnione('opiekunEN','Uzupełnij pole <b>Tutor!</b>',800)) return false;
    if(!walidator.czyWypelnione('nazwaJednostki','Uzupełnij pole <b>Nazwa Jednostki Dydaktycznej!</b>',940)) return false;
    if(!walidator.czyWypelnione('nazwaJednostkiEN','Uzupełnij pole <b>Clinic!</b>',970)) return false;
    if(!walidator.czyWypelnione('uczelniaMedyczna','Uzupełnij pole <b>Uczelnia Medyczna!</b>',1050)) return false;
    if(!walidator.czyWypelnione('uczelniaMedycznaEN','Uzupełnij pole <b>Medical School!</b>',1100)) return false;
    if(!walidator.czyWypelnione('tytul','Uzupełnij pole <b>Tytuł!',1200)) return false;
    if(!walidator.czyWypelnione('tytulEN','Uzupełnij pole <b>Title!',1550)) return false;
    if(!walidator.czyWypelnione('trescAbstraktu','Uzupełnij pole <b>Treść Abstraktu!</b>',1690)) return false;      
    if(!walidator.czyWypelnione('trescAbstraktuEN','Uzupełnij pole <b>Abstract in English!</b>',2090)) return false;      

    var req = mint.Request();
    var el = document.getElementById('captcha');
        
    if (el.style.display!='block')
    {
      el.style.display='block';
      return false;
    }
    else
    { 
      window.scrollTo(0,2090);
      sprawdzCaptche1(req);      
    }  
                 
    req.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {  
          wezStrone('php/aktualnosci.php');
          document.getElementById('sukcesik').innerHTML = "Abstrakt został wysłany!";
          $('#sukcesik').lightbox(false,3,false,false);
      }
      else
      {   
       //   wezStrone('php/aktualnosci.php');
          document.getElementById('porazka').innerHTML = "Nie udało się wysłać abstraktu!";
          $('#porazka').lightbox(false,3,false,false);
      }    
        
    }
} 

function wyslijAbstrakt1() { 
    var er = document.getElementById('komunikat');  
    $('#komunikat').hide();

    walidator.zeruj('imieNazwisko1');            
    walidator.zeruj('mail1');
    walidator.zeruj('telefon1');
    walidator.zeruj('opiekun1');
    walidator.zeruj('nazwaJednostki1');
    walidator.zeruj('uczelniaMedyczna1');
    walidator.zeruj('tytul1');
    walidator.zeruj('trescAbstraktu1');
    walidator.zeruj('code1'); 
    
    if(!walidator.czyWypelnione('imieNazwisko1','<span style="font-weight:bold;">Required field!</span>',220)) return false;
    if(!walidator.czyWypelnione('mail1','<span style="font-weight:bold;">Required field!</span>',650)) return false;
    if(!walidator.czyPoprawnyMail('mail1','<span style="font-weight:bold;">Incorrect e-mail!</span>',650)) return false; 
    if(!walidator.czyWypelnione('telefon1','<span style="font-weight:bold;">Required field!</span>',670)) return false;
    if(!walidator.czyWypelnione('opiekun1','<span style="font-weight:bold;">Required field!</span>',720)) return false;
    if(!walidator.czyWypelnione('nazwaJednostki1','<span style="font-weight:bold;">Required field!</span>',760)) return false;
    if(!walidator.czyWypelnione('uczelniaMedyczna1','<span style="font-weight:bold;">Required field!</span>',850)) return false;
    if(!walidator.czyWypelnione('tytul1','<span style="font-weight:bold;">Required field!</span>',890)) return false;
    if(!walidator.czyWypelnione('trescAbstraktu1','<span style="font-weight:bold;">Required field!</span>',1300)) return false;      

    var req = mint.Request();
    var el = document.getElementById('captcha1');
        
    if (el.style.display!='block')
    {
      el.style.display='block';
      return false;
    }
    else
    { 
      window.scrollTo(0,1300);
      sprawdzCaptche11(req);      
    }  
                 
    req.OnSuccess = function() 
    {
      jakis = this.responseText;
      if(jakis.length>0) jakis = jakis.substring(jakis.length-1, jakis.length);
      
      if(jakis == "1")
      {   
          wezStrone('php/aktualnosci.php');
          document.getElementById('sukcesik').innerHTML = "Abstract was send!";
          $('#sukcesik').lightbox(false,3,false,false);
      }
      else
      {   
        //  wezStrone('php/aktualnosci.php');
          document.getElementById('porazka').innerHTML = "Try send it later or contact with us!";
          $('#porazka').lightbox(false,3,false,false);
      }    
        
    }
} 

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function 

