// 3C Javascript library
// Copyright (c) 3C Limited 2008,9 - All Rights Reserved

var inReq = 0;
var noLoading = 0;
xajax.callback.global.onRequest = function(oRequest) {
  if ((oRequest.functionName.xjxfun != 'freefaxLog') && (oRequest.functionName.xjxfun != 'ocrfaxLog') && (oRequest.functionName.xjxfun != 'siDebug')) {
    document.getElementById("loading").style.display='block';
  }
  inReq = inReq+1;
};
xajax.callback.global.onComplete = function() {
  document.getElementById("loading").style.display = 'none';
  inReq = inReq-1;
};
onNothing = function() {
};

// Function to set the size of the veil div
function getViewportHeight() {
  if (window.innerHeight!=window.undefined) return window.innerHeight;
  if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
  if (document.body) return document.body.clientHeight; 
  return window.undefined; 
}
function getViewportWidth() {
  var offset = 17;
  var width = null;
  if (window.innerWidth!=window.undefined) return window.innerWidth; 
  if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
  if (document.body) return document.body.clientWidth; 
}

function setVeilSize() {
  var theBody = document.getElementsByTagName("BODY")[0];
  var veil = document.getElementById("veil");
  var fullHeight = getViewportHeight();
  var fullWidth = getViewportWidth();

  // Determine what's bigger, scrollHeight or fullHeight / width
  if (fullHeight > theBody.scrollHeight) {
    popHeight = fullHeight;
  } else {
    popHeight = theBody.scrollHeight;
  }

  if (fullWidth > theBody.scrollWidth) {
    popWidth = fullWidth;
  } else {
    popWidth = theBody.scrollWidth;
  }
  veil.style.height = popHeight + "px";
  veil.style.width = popWidth + "px";
}

function ticker() {
  if (document.getElementById("ff_log")) {
    xajax_freefaxLog();
  }
  if (document.getElementById("of_log")) {
    xajax_ocrfaxLog();
  }
  setTimeout("ticker();", 60000);  /*!!! reduce for production */
}

function ticker2() {
  if (inReq == 0) {
    if (document.getElementById("si_dbg_log")) {
      xajax_siDebug(0);
    }
    if (document.getElementById("si_ivr_log")) {
      xajax_siDebug(1);
    }
  }
  setTimeout("ticker2();", 100);
}

function bsrc(a) {
  b = js_beautify(a);
  c = JSLINT(b);
}	

function toggleShow(div) {
  el = document.getElementById(div);
  eh = document.getElementById(div + "_sh");
  eh = eh.firstChild;
  if (el.style.display == "block") {
    el.style.display = "none";
    eh.innerHTML = "[ + ]";
  } else {
    el.style.display = "block";
    eh.innerHTML = "[ - ]";
  }
}