var ajaxPending = false;

function showStatusWorking(strMessage) {
  var objDiv = document.getElementById("statusDiv");
  if (objDiv == null) {
    return;
  }
  $("#statusDiv").css("top", (getScrollXY()[1] + 50) + "px");
  $("#statusDiv").html("<div class='loadingspan'>" + strMessage + "</div>");
  $("#statusDiv").css("visibility", "visible");
  $("#statusDiv").show();
}

function showStatusComplete(strMessage) {
  var objDiv = document.getElementById("statusDiv");
  if (objDiv == null) {
    return;
  }
  $("#statusDiv").css("top", (getScrollXY()[1] + 50) + "px");
  $("#statusDiv").html("<div class='loadingspandone'>" + strMessage + "</div>");
  $("#statusDiv").css("visibility", "visible");
  $("#statusDiv").show();
  $("#statusDiv").fadeOut(6000);
}

function showStatusError(strMessage) {
  var objDiv = document.getElementById("statusDiv");
  if (objDiv == null) {
    return;
  }
  $("#statusDiv").css("top", (getScrollXY()[1] + 50) + "px");
  $("#statusDiv").html("<div class='loadingspanerror'>" + strMessage + "</div>");
  $("#statusDiv").css("visibility", "visible");
  $("#statusDiv").show();
  $("#statusDiv").fadeOut(6000);
}

function hideStatus() {
  var objDiv = document.getElementById("statusDiv");
  if (objDiv == null) {
    return;
  }
  $("#statusDiv").css("visibility", "hidden");
}

/**
 * Populate all loaded solutions into the select box with the given Id
 */
function populateSolutionsInSelect(sSelectId) {
    // Put all the solutions in the dropdown list
    var select = document.getElementById(sSelectId);
    for (var i = 0; i < solutions.length; i++) {
	select.options[select.options.length] = new Option(solutions[i].name, solutions[i].id);
    }
}

/**
 * Find the current window/document scrolled X, Y position.
 */
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

/**
 * A screen coordinate.
 */
function Coordinates(intX, intY) {
  this.x = intX;
  this.y = intY;
}

/**
 * Find an objects absolute X, Y screen coordinates.
 */
function findObjPosition(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return new Coordinates(curleft, curtop);
}

function kgToPounds(kg) {
    var pounds = kg * 2.2;
    return pounds.toFixed(0);
}
