// This is the js library of the CSP iframe synchronization.
// Set the onload handler of the csp report iframe to onLoad="ifs_setnp()"
// var needping counts all onload events from the iframe. We ping home to
// reset the server session timer and the browser logoff timer every 5 min if required.

function ifs_init(to,ru) {
  if (!document.getElementById)
    return;
  csp_ifs_logout_url = ru;
  csp_ifs_time = to;
  csp_lo_timer_id = setTimeout(function() { ifs_lo(csp_ifs_logout_url); }, csp_ifs_time);
  setInterval(function() { ifs_update(); }, 300000);
}
// ping home
function ifs_RSL(page,parm){
    parm = (parm != null)? parm : '';
    var i = new Image();
    var d = new Date();
    i.src = page + '?u=' + d.getTime() + '&p=' + parm;
} 
 
// reset BE session timer and  client lo_timer
// the ping returns 204 no content, but triggers the session timer
function ifs_doping (s) {
  ifs_RSL( '../ping204',s );
  clearTimeout(csp_lo_timer_id);
  csp_lo_timer_id = setTimeout(function() { ifs_lo(csp_ifs_logout_url); }, csp_ifs_time);
  //alert("IFC IFC " + s);
}
var needping = 0;
var csp_ifs_logout_url;
var csp_ifs_time;
var csp_lo_timer_id;


function ifs_setnp () {
  needping++;
}
function ifs_lo(ru) {
  if( needping >0 )
  {
  	//Do a ping:
    ifs_doping(needping);
  }
  else
  {
  	//Redirect :
	  window.location.href=ru;
  }
  needping = 0;
}

function ifs_update() {
  if( needping >0 )
  {
  	//Do a ping:
    ifs_doping(needping);
  }
  needping = 0;
}



