/* 

===============VTELEVIZI.CZ==================
=
=     Odpocitavani
=     k nejblizsimu
=     poradu z oblibenych
=     v titulku stranky
=     (HTML title)
=
=============================================

*/

var prev_title = document.title;
var ghours = 99;
var gminutes = 59;

function call_display(alert_text, hours, minutes, reminder_id) {
/* zkontroluje, jestli zvoleny porad zacina driv, takze se ma odpocitavat k nemu*/
  
  if( (hours < ghours) || 
    (
  (hours == ghours) && (minutes < gminutes) 
  
  )
  ){
    display(alert_text, hours, minutes, 0, reminder_id);  
  } else {
 
  } 

}  

function remove_title() {
  
  document.title = prev_title;
  ghours = 99;
  gminutes = 59;
  
}


  
function display(alert_text, hours, minutes, minus, reminder_id){
  /* reminder_id je potreba na to, aby se ajaxem reklo, ze je pripomenuti splneno a neni potreba posilat mail */
  ghours = hours;
  gminutes = minutes;
  
  if(minus==1) {
  
    minutes++;
  
  } else 
  if(hours<=0 && minutes<=0) {
    minutes++;
    minus=1;
  } else 

  if (minutes<=0){
    minutes=59
    hours-=1
    
  } else if (hours<=-1){
    minutes=0
    hours+=1
    
  } else {
    minutes-=1
  }
  
  
  if(minutes<10) { minutes = "0" + minutes; }
  /* TADY SE NASTAVUJE CAS, KDY TO STARTUJE S ALERTBOXEM */
  if( (minutes==7) && (hours==0) && (minus==0) ) {
    
    window.focus();
    if(alert_text != '') { alert(alert_text); }
    //ajax rika, ze porad uz byl pripomenut
    $('#serverResponse').load('_mini/change_reminder_fulfilled.php?r_id=' + reminder_id);
   
  }
  
  if(minus == 0) {
    document.title = "(" + hours + ":" + minutes + "" + ") " + prev_title;
  } else {
    document.title = "(už " + hours + ":" + minutes + "" + ") " + prev_title;
  }
  
  setTimeout(function(){display(alert_text, hours, minutes, minus, reminder_id)},60000);

}

