


function toggle_notifications(){
  if(document.getElementById("notifications_text").style.display=="none"){
  document.getElementById("notifications_text").style.display="block";
  document.getElementById("close_div").style.display="block";
  document.getElementById("notification").style.background="#fff";
  document.getElementById("notification").style.width="175px";
  document.getElementById("notification").style.color="#000";
   
  if(document.getElementById("new_n_div").innerHTML!=""){
     reset_notifications();
     document.getElementById("new_n_div").innerHTML="";
  }

  }else{
  document.getElementById("notifications_text").style.display="none";
  document.getElementById("close_div").style.display="none";
  document.getElementById("notification").style.width="30px";
  document.getElementById("new_n_div").innerHTML="";

  }
}

function load_notifications(){
var updater=new Ajax.Request('/web/notifications.php',
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "failed to load";
       if(response!="failed to load"){
          document.getElementById("notifications_text").innerHTML=add_space(response);  
       }
       var new_n=0;
       new_n=document.getElementById("new_notify").value;
       if(new_n>0){
         if(document.getElementById("notifications_text").style.display=="none"){
         document.getElementById("new_n_div").innerHTML="&nbsp;"+new_n+" new notifications";
         document.getElementById("notification").style.width="175px";
         document.getElementById("notification").style.color="#fff";         
         document.getElementById("notification").style.background="#ff0000";
         }else{
           reset_notifications();
 
        }

       }else{
         if(document.getElementById("notifications_text").style.display=="block"){
          //document.getElementById("new_n_div").innerHTML="";
          //document.getElementById("notification").style.background="#fff";
          //document.getElementById("notification").style.color="#000";
          //document.getElementById("notification").style.width="30px";
         // document.getElementById("notifications_text").style.display="none";
          //document.getElementById("close_div").style.display="none";
         }else{
          document.getElementById("notifications_text").style.display="none";
          document.getElementById("close_div").style.display="none";
          document.getElementById("new_n_div").innerHTML="";
          document.getElementById("notification").style.background="#fff";
          document.getElementById("notification").style.color="#000";
          document.getElementById("notification").style.width="30px";
         }
        }    
    },
    onFailure: function(){  }
  });


}

function reset_notifications(){
var updater=new Ajax.Request('/web/notifications.php?mode=reset',
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "failed to load"; 
       var new_n=0;
    },
    onFailure: function(){  }
  });




}



var idleTime    = 60000;
var timeOutN     = "";
var reload_time=30;
var cur_time_n=0;

function start_timer_n(){
   if(cur_time_n<reload_time){
      cur_time_n++;
      //window.status=cur_time_n+" "+reload_time;
   }else{
      cur_time_n=0;
      if(document.getElementById("notifications_text").style.display=="none"){
        load_notifications();
      }
   }
  setTimeout("start_timer_n()",1000);
}

function init_n() {
    
    Event.observe(document.body, 'mouseover', resetId, true);
    setIdle();
   
}
function init() {
    
    Event.observe(document.body, 'mousemove', resetIdle, true);
   
    setIdle();
   
}

function onIdleFunction(){
   
    reload_time=30*60;
       
}

function resetId(){
    reload_time=31;
    window.clearTimeout( timeOutN );
    setIdle();
   
}

function setIdle(){
    
    timeOutN = window.setTimeout( "onIdleFunction()", idleTime );
   
}

