﻿function showProgress(id, absolute, replace) {
  if (absolute == true)
    showAbsoluteProgress(id);
  
  else showRelativeProgress(id, replace);
}

function showAbsoluteProgress(id) {
  var container = createProgressElement();
  var pos = getProgressPos(id);
  
  container.style.position = 'absolute';
  container.style.left = pos.x + 'px';
  container.style.top = pos.y + 'px';
  document.body.appendChild(container);
}

function getProgressPos(id) {
  var rect = getElementAbsoluteRectangle(id);
  
  return { 'x' : rect.x + 2, 'y' : rect.y + rect.height + 2 };
}

function showRelativeProgress(id, replace) {
  var container = elementById(id);
  
  if (replace == true)
    container.innerHTML = '';
    
  container.appendChild(createProgressElement());
}

function createProgressElement() {
  var container = document.createElement('div');
  
  container.setAttribute('id', 'loadingImg');
  setElementClassAttribute(container, 'progress');
  return container;
}

function hideProgress() {
  var container = elementById('loadingImg');
  
  if (container == null)
    return;
    
  document.body.removeChild(container);
}